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

📄 images.c

📁 用于移动设备上的java虚拟机源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * @(#)images.c	1.55 02/10/24 @(#) * * Copyright (c) 1999-2002 Sun Microsystems, Inc.  All rights reserved. * PROPRIETARY/CONFIDENTIAL * Use is subject to license terms. */#include <stdio.h>#include <kni.h>#include <defaultLCDUI.h>#include <nativeGUI.h>#include <imageDecode.h>#include <midpMalloc.h>#include <images.h>typedef struct _mbs {    HBITMAP        bitmap;    HBITMAP        mask;    int            width;    int            height;    int            mutable;    unsigned char *image;      /* 4 bytes per pixel - rgba order */    unsigned char *imageMask;    char           prop;} myBitmapStruct;typedef struct _imgDst {    imageDstData    super;    myBitmapStruct* bitmap;    int             cmap[256];    unsigned char   tmap[256];    jboolean        mutable;    jboolean        hasColormap;    jboolean        hasTransMap;} _imageDstData, *_imageDstPtr;/* * Draw the given image data, locating its anchor point at x, y */void LCDUIdrawRegionTransform(jshort *clip, void *dst, void *img,                         jint x_dest, jint y_dest, jint anchor,                         jint x_src, jint y_src,                         jint srcWidth, jint srcHeight,                          jint transform, jboolean isRegion) {    myBitmapStruct     *p = (myBitmapStruct *)img;    HDC            hdcMem;    HBITMAP          hbmp;    int             pixel = 0;              /* makes GRAPHICS_SETUP happy */    int            dotted = 0;              /* ditto */    /* FIXME; Can we just use this instead? Then we don't have to define     *  'pixel' or 'dotted' and we don't generate pens & brushes */    /*     * HDC hdc;     * hdc = getBitmapDC(dst);     * setupClip(hdc, dst, clip);     */    GRAPHICS_SETUP(KNI_FALSE);    if (img == NULL) {        return;    }    hdcMem = CreateCompatibleDC(hdc);    CHECK_RETURN(SelectObject(hdcMem, p->bitmap));    if (transform != 0) {        customAlphaBlend(hdc, x_dest, y_dest,            hdcMem, x_src, y_src, srcWidth, srcHeight,            transform, (p->prop == HAS_ALPHA                         || p->prop == HAS_MASK) ?                         KNI_TRUE : KNI_FALSE);    } else {        switch (p->prop) {            case HAS_ALPHA: /* notice this falls to HAS_MASK                                  * when USE_ALPHA_BLEND == 0                              */#if USE_ALPHA_BLEND                customAlphaBlend(hdc, x_dest, y_dest,                       hdcMem, x_src, y_src, srcWidth, srcHeight,                                 transform, KNI_TRUE);                break;#endif            case HAS_MASK:                {                    POINT pt[3] = {{x_dest, y_dest},                                    {x_dest + srcWidth, y_dest},                                    {x_dest, y_dest + srcHeight}};                        PlgBlt(hdc, (LPPOINT)&pt, hdcMem,                            x_src, y_src, srcWidth, srcHeight, p->mask, 0, 0);                }                break;            default:                BitBlt(hdc, x_dest, y_dest, srcWidth, srcHeight,                     hdcMem, x_src, y_src, SRCCOPY);                break;        }    }    DeleteDC(hdcMem);    GRAPHICS_CLEANUP();    if (!doubleBuffer && (dst == NULL)) {        if(transform & TRANSFORM_INVERTED_AXES) {            refreshPaintWindow(y_dest, x_dest,                                y_dest + srcHeight, x_dest + srcWidth);        } else {            refreshPaintWindow(x_dest, y_dest,                                x_dest + srcWidth, y_dest + srcHeight);        }     }}/*  * Draw an image represented as an ARGB array to the screen. * If processAlpha is true, blend source pixel with the existing * pixel at the destination location. */void LCDUIdrawRGB(jshort *clip, void *dst,                  jint **rgbData, jint offset, jint scanlen, jint x, jint y,                   jint width, jint height, jboolean processAlpha) {        int             pixel = 0;              /* makes GRAPHICS_SETUP happy */    int            dotted = 0;              /* ditto */    int i, j, argb, alpha, r, g, b, c;    int imageLen;    unsigned char *destBits;    unsigned char *destPtr;    HDC            hdcMem;    HBITMAP        destHBmp;    BITMAPINFO     bi;    HGDIOBJ        oobj;        GRAPHICS_SETUP(KNI_FALSE);        imageLen = width * height << 2;        hdcMem = CreateCompatibleDC(hdc);        bi.bmiHeader.biSize          = sizeof(bi.bmiHeader);    bi.bmiHeader.biWidth         = width;    bi.bmiHeader.biHeight        = -height;    bi.bmiHeader.biPlanes        = 1;    bi.bmiHeader.biBitCount      = 32;     bi.bmiHeader.biCompression   = BI_RGB;    bi.bmiHeader.biSizeImage     = imageLen;    bi.bmiHeader.biXPelsPerMeter = 0;    bi.bmiHeader.biYPelsPerMeter = 0;    bi.bmiHeader.biClrUsed       = 0;    bi.bmiHeader.biClrImportant  = 0;                destHBmp = CreateDIBSection (hdcMem, &bi, DIB_RGB_COLORS,                                  &destBits, NULL, 0);    if (destBits != NULL) {        oobj = SelectObject(hdcMem, destHBmp);                /*         * grab the screen contents into a bitmap         * the same size as our source image         */        DB(BitBlt(hdcMem, 0, 0, width, height, hdc, x, y, SRCCOPY));                SelectObject(hdcMem, oobj);                for (j = 0; j < height; j++) {            for (i = 0; i < width; i++) {                argb = (*rgbData)[offset + (j * scanlen)+ i];                alpha = (argb >> 24) & 0xff;                r = (argb >> 16) & 0xff;                g = (argb >> 8) & 0xff;                b = argb & 0xff;                                if (alpha == 0xff || processAlpha == KNI_FALSE) {                    /* fully opaque - copy pix from rgb array to DIB */                    destPtr = destBits + ((j * width + i) << 2);                    *destPtr++ = b; /* dest pixels seem to be in BGRA order */                    *destPtr++ = g;                      *destPtr++ = r;                       } else if (alpha != 0x00) {                    /* blend the pixel with the one from the DIB and                       send the result to the DIB */                    destPtr = destBits + ((j * width + i) << 2);                                        c = b + ((*destPtr * (0xff - alpha)) / 0xff);                    if (c > 0xff) c = 0xff;                    *destPtr++ = (unsigned char)c;                                        c = g + ((*destPtr * (0xff - alpha)) / 0xff);                    if (c > 0xff) c = 0xff;                    *destPtr++ = (unsigned char)c;                                        c = r + ((*destPtr * (0xff - alpha)) / 0xff);                    if (c > 0xff) c = 0xff;                    *destPtr++ = (unsigned char)c;                }            }        }            SetDIBitsToDevice(hdc, x, y, width, height, 0, 0, 0, height,                           destBits, &bi, DIB_RGB_COLORS);    }    /* Delete the DIB */    DeleteObject(destHBmp);    DeleteDC(hdcMem);    DeleteObject(oobj);        GRAPHICS_CLEANUP();        if (!doubleBuffer && (dst == NULL)) {        refreshPaintWindow(x, y, x + width, y + height);    }    }/* * Copy the specified region of the given image data to a new * destination, locating its anchor point at x, y. */void LCDUIcopyArea(short *clip, void *dst, int x_src, int y_src,               int width, int height, int x_dest, int y_dest,               int anchor) {    HDC hdcMem;    HBITMAP hbmp;    int pixel = 0;    int dotted = 0;    GRAPHICS_SETUP(KNI_TRUE);    switch (anchor & (LEFT | RIGHT | HCENTER)) {    default:    case LEFT:        break;            case RIGHT:        x_dest -= width;        break;            case HCENTER:        x_dest -= width >> 1;        break;    }        switch (anchor & (TOP | BOTTOM | VCENTER)) {    default:    case TOP:        break;            case BOTTOM:        y_dest -= height;        break;            case VCENTER:        y_dest -= height >> 1;        break;    }        BitBlt(hdc, x_dest, y_dest, width, height, hdc, x_src, y_src, SRCCOPY);    GRAPHICS_CLEANUP();}/* * Given an RGB pixel (color) in 0x00RRGGBB format, return the  * actual color displayed in 0x00RRGGBB format. */intLCDUIgetDisplayColor(int color){    int cr;  /* in 0x00BBGGRR format */    int r, g, b;    cr = makeImagePixel(color);    r = GetRValue(cr);    g = GetGValue(cr);    b = GetBValue(cr);    return ((r << 16) | (g << 8) | b) & 0xffffff;}    static intmakeImagePixel(int rgb) {    int r = (rgb >> 16) & 0xff;    int g = (rgb >> 8)  & 0xff;    int b = (rgb >> 0)  & 0xff;    return LCDUIgetPixel(rgb, (r*76 + g*150 + b*29) >> 8, (numColors < 256));}/*  * fill rgbBuffer with pixels in 0xAARRGGBB format  * assume that (*rgbBuffer) can move, as it is on the java heap * * implements this function: *   rgbData[offset + (a - x) + (b - y) * scanlength] = P(a, b) *       for *   x <= a < x + width *   y <= b < y + height */void LCDUIgetRGB(int** rgbBuffer, int offset, int scanLength,            int x, int y, int width, int height, void *img){    int curX;     int curY;    int curOffset = offset; /* current offset in output array */    int argb;    unsigned char r;    unsigned char g;    unsigned char b;    unsigned char alpha;    char alphaFlag = 0;    /* zero if we don't need to process                               alpha channel values */    unsigned char *pel;        myBitmapStruct *p = (myBitmapStruct *)img;    if (img == NULL) return;    if (p->prop == HAS_ALPHA)        alphaFlag = 1;    for (curY = y; curY < y + height; curY++) {        for (curX = x; curX < x + width; curX++) {            pel= p->image + ((curY * p->width + curX) << 2);                        /*             * image components in bgra order?             */            b = *pel++;            g = *pel++;            r = *pel++;            alpha = 255;  /* assume opaque */            if (alphaFlag) {                alpha = *pel;            }             argb = (alpha << 24) | (r << 16) | (g << 8) | b;                        (*rgbBuffer)[curOffset] = argb;            curOffset++;        }        curOffset += (scanLength - width);    }}static voidsetImageColormap(imageDstPtr self, long *map, int length){    _imageDstPtr p = (_imageDstPtr)self;    memcpy(p->cmap, map, length * sizeof(long));     p->hasColormap = KNI_TRUE;}static voidsetImageTransparencyMap(imageDstPtr self, unsigned char *map, int length, int palLength){    _imageDstPtr p = (_imageDstPtr)self;    if (palLength >= 0 ) {         /* we must have a palette, so assume that everything is opaque */        memset(p->tmap, 0xFF, palLength);    }    memcpy(p->tmap, map, length);     p->hasTransMap = KNI_TRUE;}static voidsetImageSize(imageDstPtr self, int width, int height) {    _imageDstPtr   p = (_imageDstPtr)self;    int            x, y;    HDC          hdc;     BITMAPINFO    bi;    hdc = GetDC(hMainWindow);    p->bitmap->width   = width;    p->bitmap->height  = height;    p->bitmap->mutable = p->mutable;        /* to do transparency and alphablending we need to have a 32bpp image     * regardless of the surface to which we will be drawing. this means     * that we must create our own bitmap and fill it in appropriately.     */    bi.bmiHeader.biSize          = sizeof(bi.bmiHeader);    bi.bmiHeader.biWidth         =  p->bitmap->width;    bi.bmiHeader.biHeight        = -p->bitmap->height;    bi.bmiHeader.biPlanes        = 1;    bi.bmiHeader.biCompression   = BI_RGB;    bi.bmiHeader.biSizeImage     = 0;    bi.bmiHeader.biBitCount      = 32;    bi.bmiHeader.biXPelsPerMeter = 0;    bi.bmiHeader.biYPelsPerMeter = 0;    bi.bmiHeader.biClrUsed       = 0;    bi.bmiHeader.biClrImportant  = 0;    p->bitmap->bitmap = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS,                                          &p->bitmap->image, NULL, 0);    p->bitmap->mask              = NULL;    p->bitmap->imageMask         = NULL;    p->bitmap->prop              = HAS_SOLID;

⌨️ 快捷键说明

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