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

📄 bitmap.c

📁 ARM9-2410教学实验系统下Linux下minigui程序
💻 C
📖 第 1 页 / 共 3 页
字号:
                int x;                x = 0;                /* This can be greatly optimized with loop */                /* unrolling; omitted to save space. */                while (x < dst->bmWidth) {                    *(unsigned *) (dp2 + x * 4) =                        *(unsigned *) (dp1 + (sx >> 16) * 4);                    sx += xfactor;                    x++;                }                dp2 += dst->bmPitch;                y++;                while (y < dst->bmHeight) {                    int l;                    int syint = sy >> 16;                    sy += yfactor;                    if ((sy >> 16) != syint)                        break;                    /* Copy identical lines. */                    l = dp2 - dp2old;                    memcpy(dp2, dp2old, l);                    dp2old = dp2;                    dp2 += l;                    y++;                }                dp1 = src->bmBits + (sy >> 16) * src->bmPitch;            }        }    break;    }    return TRUE;}gal_pixel GUIAPI GetPixelInBitmap (const BITMAP* bmp, int x, int y){    BYTE* dst;    if (x < 0 || y < 0 || x >= bmp->bmWidth || y >= bmp->bmHeight)        return 0;    dst = bmp->bmBits + y * bmp->bmPitch + x * bmp->bmBytesPerPixel;    return _mem_get_pixel (dst, bmp->bmBytesPerPixel);}BOOL GUIAPI SetPixelInBitmap (const BITMAP* bmp, int x, int y, gal_pixel pixel){    BYTE* dst;    if (x < 0 || y < 0 || x >= bmp->bmWidth || y >= bmp->bmHeight)        return FALSE;    dst = bmp->bmBits + y * bmp->bmPitch + x * bmp->bmBytesPerPixel;    _mem_set_pixel (dst, bmp->bmBytesPerPixel, pixel);    return TRUE;}// This function expand monochorate bitmap.void GUIAPI ExpandMonoBitmap (HDC hdc, BYTE* bits, Uint32 pitch, const BYTE* my_bits, Uint32 my_pitch,                Uint32 w, Uint32 h, DWORD flags, Uint32 bg, Uint32 fg){    Uint32 x, y;    BYTE *dst, *dst_line;    const BYTE *src, *src_line;    Uint32 pixel;    int bpp = GAL_BytesPerPixel (dc_HDC2PDC (hdc)->surface);    BYTE byte = 0;    dst_line = bits;    if (flags & MYBMP_FLOW_UP)        src_line = my_bits + my_pitch * (h - 1);    else        src_line = my_bits;    // expand bits here.    for (y = 0; y < h; y++) {        src = src_line;        dst = dst_line;        for (x = 0; x < w; x++) {            if (x % 8 == 0)                byte = *src++;            if ((byte & (128 >> (x % 8))))   /* pixel */                pixel = fg;            else                pixel = bg;            dst = _mem_set_pixel (dst, bpp, pixel);        }                if (flags & MYBMP_FLOW_UP)            src_line -= my_pitch;        else            src_line += my_pitch;        dst_line += 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, BYTE* bits, Uint32 pitch, const BYTE* my_bits, Uint32 my_pitch,                Uint32 w, Uint32 h, DWORD flags, const RGB* pal){    PDC pdc;    Uint32 x, y;    BYTE *dst, *dst_line;    const BYTE *src, *src_line;    int index, bpp;    Uint32 pixel;    BYTE byte = 0;    pdc = dc_HDC2PDC(hdc);    bpp = GAL_BytesPerPixel (pdc->surface);    dst_line = bits;    if (flags & MYBMP_FLOW_UP)        src_line = my_bits + my_pitch * (h - 1);    else        src_line = my_bits;    for (y = 0; y < h; y++) {        src = src_line;        dst = dst_line;        for (x = 0; x < w; x++) {            if (x % 2 == 0) {                byte = *src++;                index = (byte >> 4) & 0x0f;            }            else                index = byte & 0x0f;            if (pal)                pixel = GAL_MapRGB (pdc->surface->format, pal[index].r, pal[index].g, pal[index].b);            else                pixel = GAL_MapRGB (pdc->surface->format,                                 WindowsStdColor[index].r, WindowsStdColor[index].g, WindowsStdColor[index].b);            dst = _mem_set_pixel (dst, bpp, pixel);        }        if (flags & MYBMP_FLOW_UP)            src_line -= my_pitch;        else            src_line += my_pitch;        dst_line += pitch;    }}// This function expands 256-color bitmap.void GUIAPI Expand256CBitmap (HDC hdc, BYTE* bits, Uint32 pitch, const BYTE* my_bits, Uint32 my_pitch,                Uint32 w, Uint32 h, DWORD flags, const RGB* pal){    PDC pdc;    Uint32 x, y;    int bpp;    BYTE *dst, *dst_line;    const BYTE *src, *src_line;    Uint32 pixel;    BYTE byte;    pdc = dc_HDC2PDC(hdc);    bpp = GAL_BytesPerPixel (pdc->surface);    dst_line = bits;    if (flags & MYBMP_FLOW_UP)        src_line = my_bits + my_pitch * (h - 1);    else        src_line = my_bits;    for (y = 0; y < h; y++) {        src = src_line;        dst = dst_line;        for (x = 0; x < w; x++) {            byte = *src++;            if (pal)                pixel = GAL_MapRGB (pdc->surface->format, pal[byte].r, pal[byte].g, pal[byte].b);            else                pixel = GAL_MapRGB (pdc->surface->format, byte, byte, byte);            dst = _mem_set_pixel (dst, bpp, pixel);        }        if (flags & MYBMP_FLOW_UP)            src_line -= my_pitch;        else            src_line += my_pitch;        dst_line += pitch;    }}// This function compile a RGBA bitmapvoid GUIAPI CompileRGBABitmap (HDC hdc, BYTE* bits, Uint32 pitch, const BYTE* my_bits, Uint32 my_pitch,                Uint32 w, Uint32 h, DWORD flags, void* pixel_format){    PDC pdc;    Uint32 x, y;    int bpp;    BYTE *dst, *dst_line;    const BYTE *src, *src_line;    Uint32 pixel;    GAL_Color rgb;    pdc = dc_HDC2PDC(hdc);    bpp = GAL_BytesPerPixel (pdc->surface);    dst_line = bits;    if (flags & MYBMP_FLOW_UP)        src_line = my_bits + my_pitch * (h - 1);    else        src_line = my_bits;    // expand bits here.    for (y = 0; y < h; y++) {        src = src_line;        dst = dst_line;        for (x = 0; x < w; x++) {            if ((flags & MYBMP_TYPE_MASK) == MYBMP_TYPE_BGR) {                rgb.b = *src++;                rgb.g = *src++;                rgb.r = *src++;            }            else {                rgb.r = *src++;                rgb.g = *src++;                rgb.b = *src++;            }            if (flags & MYBMP_RGBSIZE_4) {                if (flags & MYBMP_ALPHA) {                    rgb.a = *src;                    pixel = GAL_MapRGBA ((GAL_PixelFormat*) pixel_format, rgb.r, rgb.g, rgb.b, rgb.a);                }                else {                    pixel = GAL_MapRGB (pdc->surface->format, rgb.r, rgb.g, rgb.b);                }                src++;            }            else {                pixel = GAL_MapRGB (pdc->surface->format, rgb.r, rgb.g, rgb.b);            }                        dst = _mem_set_pixel (dst, bpp, pixel);        }        if (flags & MYBMP_FLOW_UP)            src_line -= my_pitch;        else            src_line += my_pitch;        dst_line += pitch;    }}// This function replaces one color with specified color.void GUIAPI ReplaceBitmapColor (HDC hdc, BITMAP* bmp, gal_pixel iOColor, gal_pixel iNColor){    PDC pdc;    int w, h, i;    BYTE* line, *bits;    int bpp;    pdc = dc_HDC2PDC (hdc);    bpp = GAL_BytesPerPixel (pdc->surface);    h = bmp->bmHeight;    w = bmp->bmWidth;    line = bmp->bmBits;    switch (bpp) {        case 1:            while (h--) {                bits = line;                for (i = 0; i < w; i++) {                    if (*bits == iOColor)                        *bits = iNColor;                    bits++;                }                line += bmp->bmPitch;            }            break;        case 2:            while (h--) {                bits = line;                for (i = 0; i < w; i++) {                    if( *(Uint16 *) bits == iOColor)                        *(Uint16 *) bits = iNColor;                    bits += 2;                }                line += bmp->bmPitch;            }            break;        case 3:             while (h--) {                bits = line;                for (i = 0; i < w; i++) {                    if ((*(Uint16 *) bits == iOColor)                            && (*(bits + 2) == (iOColor >> 16)) )                    {                        *(Uint16 *) bits = iNColor;                        *(bits + 2) = iNColor >> 16;                    }                    bits += 3;                }                line += bmp->bmPitch;            }            break;        case 4:                while (h--) {                bits = line;                for (i = 0; i < w; i++) {                    if( *(Uint32 *) bits == iOColor )                        *(Uint32 *) bits = iNColor;                    bits += 4;                }                line += bmp->bmPitch;            }            break;    }}

⌨️ 快捷键说明

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