⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bitmap.c

📁 关于rcp2c_v3.rar协议在LINUX下的实现程序
💻 C
📖 第 1 页 / 共 5 页
字号:
 * @param cBitsAlign the os-dependant byte alignment definition.
 */
static void
BMP_SetBits2bpp(int cx,
                PILRC_BYTE * pb,
                int x,
                int y,
                int bits,
                int cBitsAlign)
{
  int cbRow;

  cbRow = BMP_CbRow(cx, 2, cBitsAlign);
  pb += cbRow * y + (x >> 2);
  *pb |= (bits << ((3 - (x & 3)) * 2));
}

/**
 * Get bits from a 4bpp bitmap 
 *
 * @param pbmi       bitmap information
 * @param cx         the width of the bitmap.
 * @param pb         a reference to the bitmap resource. 
 * @param x          the x-coordinate of the pixel to process.
 * @param y          the y-coordinate of the pixel to process.
 * @param cBitsAlign the os-dependant byte alignment definition.
 * @param a          alpha channel of pixel
 * @param r          red channel of pixel
 * @param g          green channel of pixel
 * @param b          blue channel of pixel
 * @return zero if the bit not set, non-zero otherwise.
 * @return the bit representation for the (x,y) pixel.
 */
static int
BMP_GetBits4bpp(BITMAPINFO * pbmi,
                int cx,
                PILRC_BYTE * pb,
                int x,
                int y,
                int cBitsAlign,
                int *a,
                int *r,
                int *g,
                int *b)
{
  int cbRow;
  int w;

  cbRow = BMP_CbRow(cx, 4, cBitsAlign);
  pb += cbRow * y + (x >> 1);

  w = ((x & 1) != 0) ? (*pb & 0x0f) : ((*pb & 0xf0) >> 4);

  // return the values we need
  *a = 0;
  *r = pbmi->bmiColors[w].rgbRed;
  *g = pbmi->bmiColors[w].rgbGreen;
  *b = pbmi->bmiColors[w].rgbBlue;

  return w;
}

/**
 * Set bits in a 4bpp bitmap 
 *
 * @param cx         the width of the bitmap.
 * @param pb         a reference to the bitmap resource. 
 * @param x          the x-coordinate of the pixel to process.
 * @param y          the y-coordinate of the pixel to process.
 * @param bits       the bits to set (0..15).
 * @param cBitsAlign the os-dependant byte alignment definition.
 */
static void
BMP_SetBits4bpp(int cx,
                PILRC_BYTE * pb,
                int x,
                int y,
                int bits,
                int cBitsAlign)
{
  int cbRow;

  cbRow = BMP_CbRow(cx, 4, cBitsAlign);
  pb += cbRow * y + (x >> 1);
  *pb |= ((x & 1) != 0) ? bits : (bits << 4);
}

/**
 * Get bits from a 8bpp bitmap 
 *
 * @param pbmi       bitmap information
 * @param cx         the width of the bitmap.
 * @param pb         a reference to the bitmap resource. 
 * @param x          the x-coordinate of the pixel to process.
 * @param y          the y-coordinate of the pixel to process.
 * @param cBitsAlign the os-dependant byte alignment definition.
 * @param a          alpha channel of pixel
 * @param r          red channel of pixel
 * @param g          green channel of pixel
 * @param b          blue channel of pixel
 * @return the bit representation for the (x,y) pixel.
 */
static int
BMP_GetBits8bpp(BITMAPINFO * pbmi,
                int cx,
                PILRC_BYTE * pb,
                int x,
                int y,
                int cBitsAlign,
                int *a,
                int *r,
                int *g,
                int *b)
{
  int cbRow;
  int w;

  cbRow = BMP_CbRow(cx, 8, cBitsAlign);
  pb += cbRow * y + x;

  w = *pb;

  // return the values we need
  *a = 0;
  *r = pbmi->bmiColors[w].rgbRed;
  *g = pbmi->bmiColors[w].rgbGreen;
  *b = pbmi->bmiColors[w].rgbBlue;

  return w;
}

/**
 * Set bits in a 8bpp bitmap 
 *
 * @param cx         the width of the bitmap.
 * @param pb         a reference to the bitmap resource. 
 * @param x          the x-coordinate of the pixel to process.
 * @param y          the y-coordinate of the pixel to process.
 * @param bits       the bits to set (0..255).
 * @param cBitsAlign the os-dependant byte alignment definition.
 */
static void
BMP_SetBits8bpp(int cx,
                PILRC_BYTE * pb,
                int x,
                int y,
                int bits,
                int cBitsAlign)
{
  int cbRow;

  cbRow = BMP_CbRow(cx, 8, cBitsAlign);
  pb += cbRow * y + x;
  *pb = bits;
}

/**
 * Set bits in a 16bpp bitmap 
 *
 * @param cx         the width of the bitmap.
 * @param pb         a reference to the bitmap resource. 
 * @param x          the x-coordinate of the pixel to process.
 * @param y          the y-coordinate of the pixel to process.
 * @param bits       the bits to set (0..65535).
 * @param cBitsAlign the os-dependant byte alignment definition.
 */
static void
BMP_SetBits16bpp(int cx,
                 PILRC_BYTE * pb,
                 int x,
                 int y,
                 int bits,
                 int cBitsAlign)
{
  int cbRow;

  cbRow = BMP_CbRow(cx, 16, cBitsAlign);
  pb += cbRow * y + (x * 2);
  *pb = (PILRC_BYTE) ((bits & 0xFF00) >> 8);     // 5-6-5 (r-g-b) bit
  // layout
  *(pb + 1) = (PILRC_BYTE) (bits & 0xFF);
}

/**
 * Set bits in a 24bpp bitmap 
 *
 * @param cx         the width of the bitmap.
 * @param pb         a reference to the bitmap resource. 
 * @param x          the x-coordinate of the pixel to process.
 * @param y          the y-coordinate of the pixel to process.
 * @param bits       the bits to set (0..65535).
 * @param cBitsAlign the os-dependant byte alignment definition.
 */
static void
BMP_SetBits24bpp(int cx,
                 PILRC_BYTE * pb,
                 int x,
                 int y,
                 int bits,
                 int cBitsAlign)
{
  int cbRow;

  cbRow = BMP_CbRow(cx, 24, cBitsAlign);
  pb += cbRow * y + (x * 3);
  *pb = (PILRC_BYTE) ((bits & 0xFF0000) >> 16);  // red
  *pb++ = (PILRC_BYTE) ((bits & 0x00FF00) >> 8); // green
  *pb++ = (PILRC_BYTE) (bits & 0xFF);            // blue
}

/**
 * Set bits in a 32bpp bitmap 
 *
 * @param cx         the width of the bitmap.
 * @param pb         a reference to the bitmap resource. 
 * @param x          the x-coordinate of the pixel to process.
 * @param y          the y-coordinate of the pixel to process.
 * @param bits       the bits to set (0..65535).
 * @param cBitsAlign the os-dependant byte alignment definition.
 */
static void
BMP_SetBits32bpp(int cx,
                 PILRC_BYTE * pb,
                 int x,
                 int y,
                 int bits,
                 int cBitsAlign)
{
  int cbRow;

  cbRow = BMP_CbRow(cx, 32, cBitsAlign);
  pb += cbRow * y + (x * 4);
  *pb = (PILRC_BYTE) ((bits & 0xFF000000) >> 24);       // alpha
  *pb++ = (PILRC_BYTE) ((bits & 0x00FF0000) >> 16);     // red
  *pb++ = (PILRC_BYTE) ((bits & 0x0000FF00) >> 8);      // green
  *pb++ = (PILRC_BYTE) (bits & 0xFF);            // blue
}

/**
 * Get bits from a 16bpp bitmap 
 *
 * @param pbmi       bitmap information
 * @param cx         the width of the bitmap.
 * @param pb         a reference to the bitmap resource. 
 * @param x          the x-coordinate of the pixel to process.
 * @param y          the y-coordinate of the pixel to process.
 * @param cBitsAlign the os-dependant byte alignment definition.
 * @param a          alpha channel of pixel
 * @param r          red channel of pixel
 * @param g          green channel of pixel
 * @param b          blue channel of pixel
 * @return the bit representation for the (x,y) pixel.
 */
static int
BMP_GetBits16bpp(BITMAPINFO * pbmi,
                 int cx,
                 PILRC_BYTE * pb,
                 int x,
                 int y,
                 int cBitsAlign,
                 int *a,
                 int *r,
                 int *g,
                 int *b)
{
  int cbRow;
  int w;

  cbRow = BMP_CbRow(cx, 16, cBitsAlign);
  pb += cbRow * y + (x * 2);

  // get the pixel
  w = (*(pb + 1) << 8) | *pb;                    // MAY BE BUGGY!!!!

  // return the values we need
  *a = 0;
  *r = (((w & 0xF800) >> 8) | ((w & 0x3800) >> 11));
  *g = (((w & 0x07E0) >> 3) | ((w & 0x0060) >> 5));
  *b = (((w & 0x001F) >> 3) | (w & 0x0007));

  return -1;                                     // no index, direct color
}

/**
 * Get bits from a 24bpp bitmap 
 *
 * @param pbmi       bitmap information
 * @param cx         the width of the bitmap.
 * @param pb         a reference to the bitmap resource. 
 * @param x          the x-coordinate of the pixel to process.
 * @param y          the y-coordinate of the pixel to process.
 * @param cBitsAlign the os-dependant byte alignment definition.
 * @param a          alpha channel of pixel
 * @param r          red channel of pixel
 * @param g          green channel of pixel
 * @param b          blue channel of pixel
 * @return the bit representation for the (x,y) pixel.
 */
static int
BMP_GetBits24bpp(BITMAPINFO * pbmi,
                 int cx,
                 PILRC_BYTE * pb,
                 int x,
                 int y,
                 int cBitsAlign,
                 int *a,
                 int *r,
                 int *g,
                 int *b)
{
  int cbRow;

  cbRow = BMP_CbRow(cx, 24, cBitsAlign);
  pb += cbRow * y + (x * 3);

  // return the values we need
  *a = 0;
  *r = *(pb + 2);
  *g = *(pb + 1);
  *b = *pb;

  return -1;                                     // no index, direct color
}

/**
 * Get bits from a 32bpp bitmap 
 *
 * @param pbmi       bitmap information
 * @param cx         the width of the bitmap.
 * @param pb         a reference to the bitmap resource. 
 * @param x          the x-coordinate of the pixel to process.
 * @param y          the y-coordinate of the pixel to process.
 * @param cBitsAlign the os-dependant byte alignment definition.
 * @param a          alpha channel of pixel
 * @param r          red channel of pixel
 * @param g          green channel of pixel
 * @param b          blue channel of pixel
 * @return the bit representation for the (x,y) pixel.
 */
static int
BMP_GetBits32bpp(BITMAPINFO * pbmi,
                 int cx,
                 PILRC_BYTE * pb,
                 int x,
                 int y,
                 int cBitsAlign,
                 int *a,
                 int *r,
                 int *g,
                 int *b)
{
  int cbRow;

  cbRow = BMP_CbRow(cx, 32, cBitsAlign);
  pb += cbRow * y + (x * 4);

  // return the values we need
  *a = *(pb + 1);
  *r = *pb;
  *g = *(pb + 3);
  *b = *(pb + 2);                                // MAY BE BUGGY!!!!

  return -1;                                     // no index, direct color
}

/**
 * Convert a Microsoft Windows BMP file to Palm Computing resource data.
 *
 * @param rcbmp      a reference to the Palm Computing resource data.
 * @param pbResData  a reference to the bitmap resource. 
 * @param bitmaptype the type of bitmap (B+W, Grey, Grey16 or Color)?
 * @param colortable does a color table need to be generated? 
 * @param transparencyData anything we need to know about transparency
 */
static void
BMP_ConvertWindowsBitmap(RCBITMAP * rcbmp,
                         PILRC_BYTE * pbResData,
                         int bitmaptype,
                         BOOL colortable,
                         int *transparencyData)
{
  PILRC_BYTE *pbSrc;
  int i, x, y, dx, dy, colorDat;
  int cbRow, cbHeader, cbits, cbitsPel, numClrs;
  BITMAPINFO *pbmi;
  BITMAPINFOHEADER bmi;
  int (*getBits) (BITMAPINFO *,
                  int,
                  PILRC_BYTE *,
                  int,
                  int,
                  int,
                  int *,
                  int *,
                  int *,
                  int *) = NULL;
  int dstPalette[256][3] = { {0, 0, 0} };
  int dstPaletteSize = 0;

  pbmi = (BITMAPINFO *) (pbResData + sizeof(BITMAPFILEHEADER));
  memcpy(&bmi, pbmi, sizeof(BITMAPINFOHEADER));

  cbHeader = LLoadX86(bmi.biSize);
  dx = LLoadX86(bmi.biWidth);
  dy = LLoadX86(bmi.biHeight);
  cbits = WLoadX86(bmi.biBitCount);
  numClrs = LLoadX86(bmi.biClrUsed);
  if (numClrs == 0)
    numClrs = 1 << cbits;                        // MSPaint DONT set this
  if (numClrs > 256)
    numClrs = 0;                                 // direct color FIX
  pbSrc = ((PILRC_BYTE *) pbmi) + cbHeader + (sizeof(RGBQUAD) * numClrs);
  cbitsPel = -1;
  colorDat = 0;

  // check the format of the bitmap
  switch (cbits)
  {
    case 1:
      getBits = BMP_GetBits1bpp;
      break;

    case 4:
      getBits = BMP_GetBits4bpp;
      break;

    case 8:
      getBits = BMP_GetBits8bpp;
      break;

    case 16:
      getBits = BMP_GetBits16bpp;
      break;

    case 24:
      getBits = BMP_GetBits24bpp;
      break;

    case 32:
      getBits = BMP_GetBits32bpp;
      break;

    default:
      ErrorLine
        ("Bitmap not monochrome, 16, 256, 16bit, 24bit or 32bit color");
      break;
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -