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

📄 bitmap.c

📁 在ecos 下mingui 的移植开发
💻 C
📖 第 1 页 / 共 2 页
字号:
        }    }    // Transfer logical to device to screen here.    sw += sx; sh += sy;    coor_LP2SP(psdc, &sx, &sy);    coor_LP2SP(psdc, &sw, &sh);    sw -= sx; sh -= sy;    coor_LP2SP(pddc, &dx, &dy);    rcOutput.left = dx;    rcOutput.top  = dy;    rcOutput.right = dx + sw;    rcOutput.bottom = dy + sh;    NormalizeRect(&rcOutput);        pthread_mutex_lock (&gdilock);    ShowCursorForGDI(FALSE, &g_rcScr);    // set graphics context.    GAL_SetGC (pddc->gc);    pClipRect = pddc->ecrgn.head;    while(pClipRect)    {        if (DoesIntersect (&rcOutput, &pClipRect->rc)) {            GAL_SetClipping(pddc->gc, pClipRect->rc.left, pClipRect->rc.top,                    pClipRect->rc.right - 1, pClipRect->rc.bottom - 1);            GAL_CrossBlit (psdc->gc, sx, sy, sw, sh, pddc->gc, dx, dy);        }        pClipRect = pClipRect->next;    }    ShowCursorForGDI(TRUE, &g_rcScr);    pthread_mutex_unlock(&gdilock);    if (dc_IsGeneralHDC(hddc)) pthread_mutex_unlock (&pddc->pGCRInfo->lock);}void GUIAPI StretchBlt (HDC hsdc, int sx, int sy, int sw, int sh,                       HDC hddc, int dx, int dy, int dw, int dh, DWORD dwRop){    PCLIPRECT pClipRect;    PDC psdc, pddc;    void* srcBitmap = NULL;     void* scaledBitmap = NULL;    RECT rcOutput;    psdc = dc_HDC2PDC(hsdc);    pddc = dc_HDC2PDC(hddc);    if (dc_IsGeneralHDC(hddc)) {        pthread_mutex_lock (&pddc->pGCRInfo->lock);        if (!dc_GenerateECRgn (pddc, FALSE)) {            pthread_mutex_unlock (&pddc->pGCRInfo->lock);            return;        }    }    // Transfer logical to device to screen here.    sw += sx; sh += sy;    coor_LP2SP(psdc, &sx, &sy);    coor_LP2SP(psdc, &sw, &sh);    sw -= sx; sh -= sy;    dw += dx; dh += dy;    coor_LP2SP(pddc, &dx, &dy);    coor_LP2SP(pddc, &dw, &dh);    rcOutput.left = dx;    rcOutput.top = dy;    rcOutput.right = dw;    rcOutput.bottom = dh;    NormalizeRect (&rcOutput);    dw -= dx; dh -= dy;    pthread_mutex_lock (&gdilock);    if (!dc_IsMemHDC(hddc)) ShowCursorForGDI(FALSE, &g_rcScr);    GAL_SetGC (psdc->gc);    if ((srcBitmap = malloc (sw * sh * GAL_BytesPerPixel (psdc->gc))) == NULL ||         (scaledBitmap = malloc (dw * dh * GAL_BytesPerPixel (psdc->gc))) == NULL)        goto free_ret;    GAL_GetBox (psdc->gc, sx, sy, sw, sh, srcBitmap);    GAL_ScaleBox (psdc->gc, sw, sh, srcBitmap, dw, dh, scaledBitmap);    GAL_SetGC (pddc->gc);    pClipRect = pddc->ecrgn.head;    while(pClipRect)    {        if (DoesIntersect (&rcOutput, &pClipRect->rc)) {            GAL_SetClipping (pddc->gc, pClipRect->rc.left, pClipRect->rc.top,                    pClipRect->rc.right - 1, pClipRect->rc.bottom - 1);            GAL_PutBox (pddc->gc, dx, dy, dw, dh, scaledBitmap);        }        pClipRect = pClipRect->next;    }free_ret:    if (!dc_IsMemHDC(hddc)) ShowCursorForGDI (TRUE, &g_rcScr);    pthread_mutex_unlock (&gdilock);    if (dc_IsGeneralHDC(hddc)) pthread_mutex_unlock (&pddc->pGCRInfo->lock);    free (srcBitmap);    free (scaledBitmap);}// 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 == BMP_FLOW_UP)        buf = bits + pitch * h;    else        buf = bits;    // expand bits here.    for (y = 0; y < h; y++) {        if (bits_flow == BMP_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:                    *(ushort *) bitmap = fg;                    bitmap += 2;                    break;                case 3:                    *(ushort *) bitmap = fg;                    *(bitmap + 2) = fg >> 16;                    bitmap += 3;                    break;                case 4:                    *(uint *) bitmap = fg;                    bitmap += 4;                }             else              /* background pixel */                switch (bpp) {                case 1:                    *bitmap = bg;                    bitmap++;                    break;                case 2:                    *(ushort *) bitmap = bg;                    bitmap += 2;                    break;                case 3:                    *(ushort *) bitmap = bg;                    *(bitmap + 2) = bg;                    bitmap += 3;                    break;                case 4:                    *(uint *) bitmap = bg;                    bitmap += 4;                }        }                if (bits_flow != BMP_FLOW_UP)            buf += pitch;    }}// 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, 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 == BMP_FLOW_UP)        buf = bits + pitch * h;    else        buf = bits;    // expand bits here.    for (y = 0; y < h; y++)    {        if (bits_flow == BMP_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 = SysPixelIndex [c];            switch (bpp) {                case 1:                    *bitmap = c;                    bitmap++;                    break;                case 2:                    *(ushort *) bitmap = c;                    bitmap += 2;                    break;                case 3:                    *(ushort *) bitmap = c;                    *(bitmap + 2) = c >> 16;                    bitmap += 3;                    break;                case 4:                    *(uint *) bitmap = c;                    bitmap += 4;            }        }        if (bits_flow != BMP_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, 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 == BMP_FLOW_UP)        buf = bits + pitch * h;    else        buf = bits;    // expand bits here.    for (y = 0; y < h; y++)    {        if (bits_flow == BMP_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:                    *(ushort *) bitmap = c;                    bitmap += 2;                    break;                case 3:                    *(ushort *) bitmap = c;                    *(bitmap + 2) = c >> 16;                    bitmap += 3;                    break;                case 4:                    *(uint *) bitmap = c;                    bitmap += 4;            }        }        if (bits_flow != BMP_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 == BMP_FLOW_UP)        buf = bits + pitch * h;    else        buf = bits;    // expand bits here.    for (y = 0; y < h; y++)    {        if (bits_flow == BMP_FLOW_UP)            buf -= pitch;        bits = buf;        for (x = 0; x < w; x++) {            if (rgb_order == RGB_ORDER_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:                    *(ushort *) bitmap = c;                    bitmap += 2;                    break;                case 3:                    *(ushort *) bitmap = c;                    *(bitmap + 2) = c >> 16;                    bitmap += 3;                    break;                case 4:                    *(uint *) bitmap = c;                    bitmap += 4;            }        }        if (bits_flow != BMP_FLOW_UP)            buf += pitch;    }}// This function replaces one color with specified color.void GUIAPI ReplaceBitmapColor (HDC hdc, PBITMAP pBitmap, int iOColor, int iNColor){    PDC pdc;    int i, size;    BYTE* bitmap;       int bpp;    pdc = dc_HDC2PDC (hdc);    bpp = GAL_BytesPerPixel (pdc->gc);    size = pBitmap->bmWidth*pBitmap->bmHeight*bpp;    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( *(ushort *) bitmap == iOColor)                    *(ushort *) bitmap = iNColor;                bitmap += 2;            }            break;        case 3:             for(i=0; i<size; i+=3) {                if( (*(ushort *) bitmap == iOColor)                    && (*(bitmap + 2) == (iOColor >> 16)) )                {                    *(ushort *) bitmap = iNColor;                    *(bitmap + 2) = iNColor >> 16;                }                bitmap += 3;            }            break;        case 4:                for(i=0; i<size; i+=4) {                if( *(uint *) bitmap == iOColor )                    *(uint *) bitmap = iNColor;                bitmap += 4;            }            break;    }}

⌨️ 快捷键说明

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