?? bitmap-comm.c
字號:
#include "readbmp.h"// This function expand monochorate bitmap.void GUIAPI ExpandMonoBitmap (HDC hdc, int w, int h, const BYTE* bits, int bits_flow, int pitch, BYTE* bitmap, int bg, int fg){ int x, y; const BYTE* buf; int b = 0; int bpp; bpp = GAL_BytesPerPixel (dc_HDC2PDC(hdc)->gc); if (bits_flow == MYBMP_FLOW_UP) buf = bits + pitch * h; else buf = bits; // expand bits here. for (y = 0; y < h; y++) { if (bits_flow == MYBMP_FLOW_UP) buf -= pitch; bits = buf; for (x = 0; x < w; x++) { if (x % 8 == 0) b = *bits++; if ((b & (128 >> (x % 8)))) /* pixel */ switch (bpp) { case 1: *bitmap = fg; bitmap++; break; case 2: *(Uint16 *) bitmap = fg; bitmap += 2; break; case 3: *(Uint16 *) bitmap = fg; *(bitmap + 2) = fg >> 16; bitmap += 3; break; case 4: *(Uint32 *) bitmap = fg; bitmap += 4; } else /* background pixel */ switch (bpp) { case 1: *bitmap = bg; bitmap++; break; case 2: *(Uint16 *) bitmap = bg; bitmap += 2; break; case 3: *(Uint16 *) bitmap = bg; *(bitmap + 2) = bg; bitmap += 3; break; case 4: *(Uint32 *) bitmap = bg; bitmap += 4; } } if (bits_flow != MYBMP_FLOW_UP) buf += pitch; }}static const RGB WindowsStdColor [] = { {0x00, 0x00, 0x00}, // black --0 {0x80, 0x00, 0x00}, // dark red --1 {0x00, 0x80, 0x00}, // dark green --2 {0x80, 0x80, 0x00}, // dark yellow --3 {0x00, 0x00, 0x80}, // dark blue --4 {0x80, 0x00, 0x80}, // dark magenta --5 {0x00, 0x80, 0x80}, // dark cyan --6 {0xC0, 0xC0, 0xC0}, // light gray --7 {0x80, 0x80, 0x80}, // dark gray --8 {0xFF, 0x00, 0x00}, // red --9 {0x00, 0xFF, 0x00}, // green --10 {0xFF, 0xFF, 0x00}, // yellow --11 {0x00, 0x00, 0xFF}, // blue --12 {0xFF, 0x00, 0xFF}, // magenta --13 {0x00, 0xFF, 0xFF}, // cyan --14 {0xFF, 0xFF, 0xFF}, // light white --15};// This function expand 16-color bitmap.void GUIAPI Expand16CBitmap (HDC hdc, int w, int h, const BYTE* bits, int bits_flow, int pitch, BYTE* bitmap, const RGB* pal){ PDC pdc; int x, y; const BYTE* buf; int b = 0; int c; int bpp; pdc = dc_HDC2PDC(hdc); bpp = GAL_BytesPerPixel (pdc->gc); if (bits_flow == MYBMP_FLOW_UP) buf = bits + pitch * h; else buf = bits; // expand bits here. for (y = 0; y < h; y++) { if (bits_flow == MYBMP_FLOW_UP) buf -= pitch; bits = buf; for (x = 0; x < w; x++) { if (x % 2 == 0) b = *bits++; if (x % 2 == 0) c = (b >> 4) & 0x0f; else c = b & 0x0f; if (pal) c = GAL_MapColor (pdc->gc, (GAL_Color*)(pal + c)); else c = GAL_MapColor (pdc->gc, (GAL_Color*)(WindowsStdColor + c)); switch (bpp) { case 1: *bitmap = c; bitmap++; break; case 2: *(Uint16 *) bitmap = c; bitmap += 2; break; case 3: *(Uint16 *) bitmap = c; *(bitmap + 2) = c >> 16; bitmap += 3; break; case 4: *(Uint32 *) bitmap = c; bitmap += 4; } } if (bits_flow != MYBMP_FLOW_UP) buf += pitch; }}// This function expands 256-color bitmap.void GUIAPI Expand256CBitmap (HDC hdc, int w, int h, const BYTE* bits, int bits_flow, int pitch, BYTE* bitmap, const RGB* pal){ PDC pdc; int x, y; const BYTE* buf; int c; int bpp; pdc = dc_HDC2PDC (hdc); bpp = GAL_BytesPerPixel (pdc->gc); if (bits_flow == MYBMP_FLOW_UP) buf = bits + pitch * h; else buf = bits; // expand bits here. for (y = 0; y < h; y++) { if (bits_flow == MYBMP_FLOW_UP) buf -= pitch; bits = buf; for (x = 0; x < w; x++) { c = *bits++; c = GAL_MapColor (pdc->gc, (GAL_Color*)(pal + c)); switch (bpp) { case 1: *bitmap = c; bitmap++; break; case 2: *(Uint16 *) bitmap = c; bitmap += 2; break; case 3: *(Uint16 *) bitmap = c; *(bitmap + 2) = c >> 16; bitmap += 3; break; case 4: *(Uint32 *) bitmap = c; bitmap += 4; } } if (bits_flow != MYBMP_FLOW_UP) buf += pitch; }}// This function compile a RGB bitmapvoid GUIAPI CompileRGBBitmap (HDC hdc, int w, int h, const BYTE* bits, int bits_flow, int pitch, BYTE* bitmap, int rgb_order){ PDC pdc; int x, y; const BYTE* buf; int c; GAL_Color rgb; int bpp; pdc = dc_HDC2PDC (hdc); bpp = GAL_BytesPerPixel (pdc->gc); if (bits_flow == MYBMP_FLOW_UP) buf = bits + pitch * h; else buf = bits; // expand bits here. for (y = 0; y < h; y++) { if (bits_flow == MYBMP_FLOW_UP) buf -= pitch; bits = buf; for (x = 0; x < w; x++) { if (rgb_order == MYBMP_TYPE_BGR) { rgb.b = *bits++; rgb.g = *bits++; rgb.r = *bits++; } else { rgb.r = *bits++; rgb.g = *bits++; rgb.b = *bits++; } c = GAL_MapColor (pdc->gc, &rgb); switch (bpp) { case 1: *bitmap = c; bitmap++; break; case 2: *(Uint16 *) bitmap = c; bitmap += 2; break; case 3: *(Uint16 *) bitmap = c; *(bitmap + 2) = c >> 16; bitmap += 3; break; case 4: *(Uint32 *) bitmap = c; bitmap += 4; } } if (bits_flow != MYBMP_FLOW_UP) buf += pitch; }}// This function replaces one color with specified color.void GUIAPI ReplaceBitmapColor (HDC hdc, PBITMAP pBitmap, gal_pixel iOColor, gal_pixel iNColor){ PDC pdc; int i, size; BYTE* bitmap; int bpp; pdc = dc_HDC2PDC (hdc); bpp = GAL_BytesPerPixel (pdc->gc); size = pBitmap->bmPitch * pBitmap->bmHeight; bitmap = pBitmap->bmBits; switch (bpp) { case 1: for(i=0; i<size; i++) { if( *bitmap == iOColor) *bitmap = iNColor; bitmap++; } break; case 2: for(i=0; i<size; i+=2) { if( *(Uint16 *) bitmap == iOColor) *(Uint16 *) bitmap = iNColor; bitmap += 2; } break; case 3: for(i=0; i<size; i+=3) { if( (*(Uint16 *) bitmap == iOColor) && (*(bitmap + 2) == (iOColor >> 16)) ) { *(Uint16 *) bitmap = iNColor; *(bitmap + 2) = iNColor >> 16; } bitmap += 3; } break; case 4: for(i=0; i<size; i+=4) { if( *(Uint32 *) bitmap == iOColor ) *(Uint32 *) bitmap = iNColor; bitmap += 4; } break; }}void GUIAPI DrawHVDotLine (HDC hdc, int x, int y, int w_h, BOOL H_V){ PDC pdc; BYTE* bitmap, *vbuff; int i, bpp, size; if (w_h < 1) return; pdc = dc_HDC2PDC (hdc); bpp = GAL_BytesPerPixel (pdc->gc); size = w_h * bpp;#ifdef HAVE_ALLOCA if (!(bitmap = alloca (size)))#else if (!(bitmap = malloc (size)))#endif return; vbuff = bitmap; switch (bpp) { case 1: for (i = 0; i < size; i += 2) { *vbuff = (BYTE)(pdc->pencolor); vbuff++; *vbuff = (BYTE)(pdc->brushcolor); vbuff++; } break; case 2: for (i = 0; i < size; i += 4) { *(Uint16 *) vbuff = (Uint16)(pdc->pencolor); vbuff += 2; *(Uint16 *) vbuff = (Uint16)(pdc->brushcolor); vbuff += 2; } break; case 3:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -