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

📄 bitmap.c

📁 ARM9-2410教学实验系统下Linux下minigui程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ** $Id: bitmap.c,v 1.41 2003/09/17 03:36:26 weiym Exp $**** Bitmap operations of GDI.**** Copyright (C) 2003 Feynman Software** Copyright (C) 2001 ~ 2002 Wei Yongming.**** Current maintainer: Wei Yongming.**** Create date: 2000/06/12, derived from original gdi.c*//*** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU General Public License as published by** the Free Software Foundation; either version 2 of the License, or** (at your option) any later version.**** This program is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the** GNU General Public License for more details.**** You should have received a copy of the GNU General Public License** along with this program; if not, write to the Free Software** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*//*** TODO:*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "cliprect.h"#include "gal.h"#include "internals.h"#include "ctrlclass.h"#include "dc.h"#include "pixel_ops.h"#include "cursor.h"/****************************** Bitmap Support *******************************/void _dc_fillbox_clip (PDC pdc, const GAL_Rect* rect){    PCLIPRECT cliprect;    RECT eff_rc;    cliprect = pdc->ecrgn.head;    if (pdc->rop == ROP_SET) {        while (cliprect) {            if (IntersectRect (&eff_rc, &pdc->rc_output, &cliprect->rc)) {                SET_GAL_CLIPRECT (pdc, eff_rc);                GAL_FillRect (pdc->surface, rect, pdc->cur_pixel);            }            cliprect = cliprect->next;        }    }    else {        pdc->step = 1;        while (cliprect) {            if (IntersectRect (&eff_rc, &pdc->rc_output, &cliprect->rc)) {                int _w = RECTW(eff_rc), _h = RECTH(eff_rc);                pdc->move_to (pdc, eff_rc.left, eff_rc.top);                while (_h--) {                    pdc->draw_hline (pdc, _w);                    pdc->cur_dst += pdc->surface->pitch;                }            }            cliprect = cliprect->next;        }    }}void _dc_fillbox_bmp_clip (PDC pdc, const GAL_Rect* rect, BITMAP* bmp){    PCLIPRECT cliprect;    RECT eff_rc;    cliprect = pdc->ecrgn.head;    if (pdc->rop == ROP_SET) {        while (cliprect) {            if (IntersectRect (&eff_rc, &pdc->rc_output, &cliprect->rc)) {                SET_GAL_CLIPRECT (pdc, eff_rc);                GAL_PutBox (pdc->surface, rect, bmp);            }            cliprect = cliprect->next;        }    }    else {        BYTE* row;        int _w, _h;        pdc->step = 1;        while (cliprect) {            if (IntersectRect (&eff_rc, &pdc->rc_output, &cliprect->rc)) {                pdc->move_to (pdc, eff_rc.left, eff_rc.top);                row = bmp->bmBits + bmp->bmPitch * (eff_rc.top - rect->y)                        + bmp->bmBytesPerPixel * (eff_rc.left - rect->x);                _h = RECTH(eff_rc); _w = RECTW(eff_rc);                while (_h--) {                    pdc->put_hline (pdc, row, _w);                    row += bmp->bmPitch;                    _dc_step_y (pdc, 1);                }            }            cliprect = cliprect->next;        }    }}void GUIAPI FillBox (HDC hdc, int x, int y, int w, int h){    PDC pdc;    GAL_Rect rect;    if (w == 0 || h == 0)        return;    if (!(pdc = check_ecrgn (hdc)))        return;    if (w < 0) w = RECTW (pdc->DevRC);    if (h < 0) h = RECTH (pdc->DevRC);    /* Transfer logical to device to screen here. */    w += x; h += y;    coor_LP2SP (pdc, &x, &y);    coor_LP2SP (pdc, &w, &h);    SetRect (&pdc->rc_output, x, y, w, h);    NormalizeRect (&pdc->rc_output);    w = RECTW (pdc->rc_output); h = RECTH (pdc->rc_output);    rect.x = x; rect.y = y; rect.w = w; rect.h = h;    pdc->cur_pixel = pdc->brushcolor;    pdc->cur_ban = NULL;    pdc->step = 1;    ENTER_DRAWING (pdc);    _dc_fillbox_clip (pdc, &rect);        LEAVE_DRAWING (pdc);    UNLOCK_GCRINFO (pdc);}BOOL GUIAPI GetBitmapFromDC (HDC hdc, int x, int y, int w, int h, BITMAP* bmp){    PDC pdc;    GAL_Rect rect;    int ret;    pdc = dc_HDC2PDC (hdc);    if (dc_IsGeneralDC (pdc)) {        LOCK (&pdc->pGCRInfo->lock);        dc_GenerateECRgn (pdc, FALSE);    }    w += x; h += y;    coor_LP2SP (pdc, &x, &y);    coor_LP2SP (pdc, &w, &h);    SetRect (&pdc->rc_output, x, y, w, h);    NormalizeRect (&pdc->rc_output);    w = RECTW (pdc->rc_output); h = RECTH (pdc->rc_output);    rect.x = x; rect.y = y; rect.w = w; rect.h = h;    ENTER_DRAWING_NOCHECK (pdc);    ret = GAL_GetBox (pdc->surface, &rect, bmp);    LEAVE_DRAWING_NOCHECK (pdc);    UNLOCK_GCRINFO (pdc);    if (ret) return FALSE;    return TRUE;}BOOL GUIAPI FillBoxWithBitmap (HDC hdc, int x, int y, int w, int h, const BITMAP* bmp){    PDC pdc;    BITMAP scaled;    int sw = bmp->bmWidth, sh = bmp->bmHeight;    GAL_Rect rect;    if (bmp->bmWidth <= 0 || bmp->bmHeight <= 0 || bmp->bmBits == NULL)        return FALSE;    if (!(pdc = check_ecrgn (hdc)))        return TRUE;    if (w <= 0) w = sw;    if (h <= 0) h = sh;    // Transfer logical to device to screen here.    w += x; h += y;    coor_LP2SP (pdc, &x, &y);    coor_LP2SP (pdc, &w, &h);    SetRect (&pdc->rc_output, x, y, w, h);    NormalizeRect (&pdc->rc_output);    w = RECTW (pdc->rc_output); h = RECTH (pdc->rc_output);    rect.x = x; rect.y = y; rect.w = w; rect.h = h;    if (w == sw && h == sh)        scaled = *bmp;    else {        scaled = *bmp;        scaled.bmWidth = w;        scaled.bmHeight = h;        if ((scaled.bmBits = malloc (GAL_GetBoxSize (pdc->surface, w, h, &scaled.bmPitch))) == NULL)            goto error_ret;        ScaleBitmap (&scaled, bmp);    }    pdc->step = 1;    pdc->cur_ban = NULL;    pdc->cur_pixel = pdc->brushcolor;    pdc->skip_pixel = scaled.bmColorKey;    ENTER_DRAWING (pdc);    _dc_fillbox_bmp_clip (pdc, &rect, &scaled);    LEAVE_DRAWING (pdc);    if (w != sw || h != sh)        free (scaled.bmBits);error_ret:    UNLOCK_GCRINFO (pdc);    if (!scaled.bmBits)        return FALSE;    return TRUE;}BOOL GUIAPI FillBoxWithBitmapPart (HDC hdc, int x, int y, int w, int h,                int bw, int bh, const BITMAP* bmp, int xo, int yo){    PDC pdc;    BYTE* my_bits;    BITMAP scaled;    GAL_Rect rect;    if (bmp->bmWidth <= 0 || bmp->bmHeight <= 0 || bmp->bmBits == NULL)        return FALSE;    if (!(pdc = check_ecrgn (hdc)))        return TRUE;    // Transfer logical to device to screen here.    w += x; h += y;    coor_LP2SP(pdc, &x, &y);    coor_LP2SP(pdc, &w, &h);    SetRect (&pdc->rc_output, x, y, w, h);    NormalizeRect (&pdc->rc_output);    w = RECTW (pdc->rc_output); h = RECTH (pdc->rc_output);    rect.x = x; rect.y = y; rect.w = w; rect.h = h;    if (bw <= 0) bw = bmp->bmWidth;    if (bh <= 0) bh = bmp->bmHeight;    if (bw == bmp->bmWidth && bh == bmp->bmHeight) {        scaled = *bmp;        my_bits = NULL;    }    else {        scaled = *bmp;        scaled.bmWidth = bw;        scaled.bmHeight = bh;        if ((my_bits = malloc (GAL_GetBoxSize (pdc->surface, bw, bh, &scaled.bmPitch))) == NULL)            goto error_ret;        scaled.bmBits = my_bits;        ScaleBitmap (&scaled, bmp);    }    if (xo != 0 || yo != 0) {        scaled.bmBits += scaled.bmPitch * yo + xo * GAL_BytesPerPixel (pdc->surface);    }    pdc->step = 1;    pdc->cur_ban = NULL;    pdc->cur_pixel = pdc->brushcolor;    pdc->skip_pixel = scaled.bmColorKey;    ENTER_DRAWING (pdc);    _dc_fillbox_bmp_clip (pdc, &rect, &scaled);    LEAVE_DRAWING (pdc);    if (bw != bmp->bmWidth || bh != bmp->bmWidth)        free (my_bits);error_ret:    UNLOCK_GCRINFO (pdc);    if (!my_bits)        return FALSE;    return TRUE;}void GUIAPI BitBlt (HDC hsdc, int sx, int sy, int sw, int sh,                   HDC hddc, int dx, int dy, DWORD dwRop){    PCLIPRECT cliprect;    PDC psdc, pddc;    RECT srcOutput, dstOutput;    GAL_Rect dst, src;    RECT eff_rc;    psdc = dc_HDC2PDC (hsdc);    if (!(pddc = check_ecrgn (hddc)))        return;    if (sw <= 0 || sh <= 0) {        sw = RECTW (psdc->DevRC);        sh = RECTH (psdc->DevRC);    }    // Transfer logical to device to screen here.    sw += sx; sh += sy;    coor_LP2SP (psdc, &sx, &sy);    coor_LP2SP (psdc, &sw, &sh);    SetRect (&srcOutput, sx, sy, sw, sh);    NormalizeRect (&srcOutput);    (sw > sx) ? (sw -= sx) : (sw = sx - sw);    (sh > sy) ? (sh -= sy) : (sh = sy - sh);    coor_LP2SP (pddc, &dx, &dy);

⌨️ 快捷键说明

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