?? bitmap-comm.c
字號:
#include "readbmp.h"// This function expand monochorate bitmap.void GUIAPI ExpandMonoBitmap (HDC hdc, int w, int h, const BYTE* my_bits, int my_pitch, int bits_flow, BYTE* bitmap, int pitch, int bg, int fg){ int x, y; const BYTE* buf; BYTE* dst_line; int b = 0; int bpp; bpp = GAL_BytesPerPixel (dc_HDC2PDC(hdc)->gc); if (bits_flow == MYBMP_FLOW_UP) buf = my_bits + my_pitch * h; else buf = my_bits; // expand my_bits here. for (y = 0; y < h; y++) { dst_line = bitmap; if (bits_flow == MYBMP_FLOW_UP) buf -= my_pitch; my_bits = buf; for (x = 0; x < w; x++) { if (x % 8 == 0) b = *my_bits++; if ((b & (128 >> (x % 8)))) /* pixel */ switch (bpp) { case 1: *dst_line = fg; dst_line++; break; case 2: *(Uint16 *) dst_line = fg; dst_line += 2; break; case 3: *(Uint16 *) dst_line = fg; *(dst_line + 2) = fg >> 16; dst_line += 3; break; case 4: *(Uint32 *) dst_line = fg; dst_line += 4; } else /* background pixel */ switch (bpp) { case 1: *dst_line = bg; dst_line++; break; case 2: *(Uint16 *) dst_line = bg; dst_line += 2; break; case 3: *(Uint16 *) dst_line = bg; *(dst_line + 2) = bg; dst_line += 3; break; case 4: *(Uint32 *) dst_line = bg; dst_line += 4; } } if (bits_flow != MYBMP_FLOW_UP) buf += my_pitch; bitmap += 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* my_bits, int my_pitch, int bits_flow, BYTE* bitmap, int pitch, const RGB* pal){ PDC pdc; int x, y; const BYTE* buf; BYTE* dst_line; int b = 0; int c; int bpp; pdc = dc_HDC2PDC(hdc); bpp = GAL_BytesPerPixel (pdc->gc); if (bits_flow == MYBMP_FLOW_UP) buf = my_bits + my_pitch * h; else buf = my_bits; // expand my_bits here. for (y = 0; y < h; y++) { dst_line = bitmap; if (bits_flow == MYBMP_FLOW_UP) buf -= my_pitch; my_bits = buf; for (x = 0; x < w; x++) { if (x % 2 == 0) b = *my_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: *dst_line = c; dst_line++; break; case 2: *(Uint16 *) dst_line = c; dst_line += 2; break; case 3: *(Uint16 *) dst_line = c; *(dst_line + 2) = c >> 16; dst_line += 3; break; case 4: *(Uint32 *) dst_line = c; dst_line += 4; } } if (bits_flow != MYBMP_FLOW_UP) buf += my_pitch; bitmap += pitch; }}// This function expands 256-color bitmap.void GUIAPI Expand256CBitmap (HDC hdc, int w, int h, const BYTE* my_bits, int my_pitch, int bits_flow, BYTE* bitmap, int pitch, const RGB* pal){ PDC pdc; int x, y; const BYTE* buf; BYTE* dst_line; int c; int bpp; pdc = dc_HDC2PDC (hdc); bpp = GAL_BytesPerPixel (pdc->gc); if (bits_flow == MYBMP_FLOW_UP) buf = my_bits + my_pitch * h; else buf = my_bits; // expand my_bits here. for (y = 0; y < h; y++) { dst_line = bitmap; if (bits_flow == MYBMP_FLOW_UP) buf -= my_pitch; my_bits = buf; for (x = 0; x < w; x++) { c = *my_bits++; c = GAL_MapColor (pdc->gc, (GAL_Color*)(pal + c)); switch (bpp) { case 1: *dst_line = c; dst_line++; break; case 2: *(Uint16 *) dst_line = c; dst_line += 2; break; case 3: *(Uint16 *) dst_line = c; *(dst_line + 2) = c >> 16; dst_line += 3; break; case 4: *(Uint32 *) dst_line = c; dst_line += 4; } } if (bits_flow != MYBMP_FLOW_UP) buf += my_pitch; bitmap += pitch; }}// This function compile a RGB bitmapvoid GUIAPI CompileRGBBitmap (HDC hdc, int w, int h, const BYTE* my_bits, int my_pitch, int bits_flow, BYTE* bitmap, int pitch, int rgb_order){ PDC pdc; int x, y; const BYTE* buf; BYTE* dst_line; int c; GAL_Color rgb; int bpp; pdc = dc_HDC2PDC (hdc); bpp = GAL_BytesPerPixel (pdc->gc); if (bits_flow == MYBMP_FLOW_UP) buf = my_bits + my_pitch * h; else buf = my_bits; // expand my_bits here. for (y = 0; y < h; y++) { dst_line = bitmap; if (bits_flow == MYBMP_FLOW_UP) buf -= my_pitch; my_bits = buf; for (x = 0; x < w; x++) { if (rgb_order == MYBMP_TYPE_BGR) { rgb.b = *my_bits++; rgb.g = *my_bits++; rgb.r = *my_bits++; } else { rgb.r = *my_bits++; rgb.g = *my_bits++; rgb.b = *my_bits++; } c = GAL_MapColor (pdc->gc, &rgb); switch (bpp) { case 1: *dst_line = c; dst_line++; break; case 2: *(Uint16 *) dst_line = c; dst_line += 2; break; case 3: *(Uint16 *) dst_line = c; *(dst_line + 2) = c >> 16; dst_line += 3; break; case 4: *(Uint32 *) dst_line = c; dst_line += 4; } } if (bits_flow != MYBMP_FLOW_UP) buf += my_pitch; bitmap += 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;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -