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

📄 images.c

📁 SUN官方的资料
💻 C
📖 第 1 页 / 共 3 页
字号:
                 * there's no "nice" pattern that we can take advantage of so                 * test each pixel                 */                for (i = 0; i < 8; i++) {                    if (data & (1 << (7-i))) {                        XDRAWPOINT(i);                    }                }            }        }    }    XPutImage(display, d, gc, dest, 0, 0, dest_x, dest_y, width, height);    XDestroyImage(dest);}#define TRANSPARENCYMASK 0x00#define FULLALPHACHANNEL 0x01#define TRANSPARENCY_SETUP_SOURCE_MASK()\tMode = TRANSPARENCYMASK;\maskPtr = mask;\inByteMaskIndex = 0;#define	TRANSPARENCY_SETUP_SOURCE_FULL_ALPHACHANNEL_MASK()\tMode = FULLALPHACHANNEL;\maskPtr = mask;#define TRANSPARENCY_GET_SOURCE_DATA(data, x, y)\if(TRANSPARENCYMASK == tMode) {\tMaskByte = ((y * imageWidth)+ x) / 8;\inByteMaskIndex = ((y * imageWidth)+ x) - (tMaskByte * 8);\if (0x01 && (*(maskPtr+tMaskByte) >> inByteMaskIndex)) {\  data = 0xFF;\} else {\  data = 0x00;\}\} else if(FULLALPHACHANNEL == tMode) { \tMaskByte = ((y * imageWidth)+ x);\data = *(maskPtr+tMaskByte);\}voidmyPutImageAlpha(Display *display, Drawable d, GC gc, XImage *image, 		unsigned char *mask,                int src_x, int src_y, 		int dest_x, int dest_y, 		unsigned int width, unsigned int height,		int transform,		int useBitMask){    int srcX;    int srcY;    int xStart;    int yStart;    int xIncr;    int yIncr;    int destX;    int destY;    int yCounter;    int xCounter;    unsigned char data;    unsigned char *maskPtr;    unsigned int index;    XColor srcPixel, destPixel;    unsigned int inByteMaskIndex;    /* used by the TRANSPARENCY_ macros */    int tMode;    int tMaskByte = 0;    int imageWidth = image->width;    XImage *dest = NULL;    if ( !(transform & TRANSFORM_INVERTED_AXES)) {      dest = XGetImage(display, d, dest_x, dest_y, width, height, 0xff, ZPixmap);    } else {      dest = XGetImage(display, d, dest_x, dest_y, height, width, 0xff, ZPixmap);    }    if (dest == NULL || mask == NULL) {      if (transform == 0x0) {        XPutImage(display, d, gc, image, src_x, src_y, dest_x, dest_y,                  width, height);	if (dest != NULL) {	    XDestroyImage(dest);	}        return;      }    }    index = 0;    maskPtr = mask;    if (transform & TRANSFORM_Y_FLIP) {      yStart = height-1;      yIncr = -1;    } else {      yStart = 0;      yIncr = +1;    }    if (transform & TRANSFORM_X_FLIP) {      xStart = width-1;      xIncr = -1;    } else {      xStart = 0;      xIncr = +1;    }    if ((USE_BIT_MASK == useBitMask) && (mask != NULL)) {        TRANSPARENCY_SETUP_SOURCE_MASK();	    } else {      if(mask != NULL) {      /*is this a full alpha channel? if so, then setup our       transparency value reader to read full alpha values.*/	TRANSPARENCY_SETUP_SOURCE_FULL_ALPHACHANNEL_MASK();      }          }    /* increment srcX,Y regular. increment destX,Y according to transform.       this makes handling of mask and alpha values easier */    for (srcY = src_y, destY = yStart, yCounter = 0; 	 yCounter < height; 	 srcY++, destY+=yIncr, yCounter++) {      for (srcX = src_x, destX = xStart, xCounter = 0; 	   xCounter < width; 	   srcX++, destX+=xIncr, xCounter++) {	    /* if the mask is null, act as if we have mask values 	       of full opacity,	       otherwise, get the mask value. */            if ((NO_BIT_MASK == useBitMask) && (NULL == mask)) {	        data = 0xff;            } else {	      TRANSPARENCY_GET_SOURCE_DATA(data, srcX, srcY);	    }            if (data == 0xff) {                /*                 * fully opaque                  */	      if ( !(transform & TRANSFORM_INVERTED_AXES)) {                XPutPixel(dest, destX, destY, XGetPixel(image, srcX, srcY));	      } else {                XPutPixel(dest, destY, destX, XGetPixel(image, srcX, srcY));	      }            } else if (data != 0x00) {                /*                 * not transparent so we need to blend the image pixel with                 * the one on the screen                 */                getPixelParts(XGetPixel(image, srcX, srcY), &srcPixel);		if ( !(transform & TRANSFORM_INVERTED_AXES)) {		  getPixelParts(XGetPixel(dest, destX, destY), &destPixel);		} else {		  getPixelParts(XGetPixel(dest, destY, destX), &destPixel);		}                srcPixel.red   += ((destPixel.red   * (0xff - data)) / 0xff);                srcPixel.green += ((destPixel.green * (0xff - data)) / 0xff);                srcPixel.blue  += ((destPixel.blue  * (0xff - data)) / 0xff);                if (srcPixel.red > 0xff) {                    srcPixel.red = 0xff;                }                if (srcPixel.green > 0xff) {                    srcPixel.green = 0xff;                }                if (srcPixel.blue > 0xff) {                    srcPixel.blue = 0xff;                }		if ( !(transform & TRANSFORM_INVERTED_AXES)) {		  XPutPixel(dest, destX, destY, 			    getPixelValue(srcPixel.red, 					  srcPixel.green, 					  srcPixel.blue)); 		} else {		  XPutPixel(dest, destY, destX,			    getPixelValue(srcPixel.red, 					  srcPixel.green, 					  srcPixel.blue)); 		}            }         }    }        /*     * draw the newly rendered image     */    if (!(transform & TRANSFORM_INVERTED_AXES)) {        XPutImage(display, d, gc, dest, 0, 0, dest_x, dest_y, width, height);    } else {        XPutImage(display, d, gc, dest, 0, 0, dest_x, dest_y, height, width);    }    if (dest != NULL) {        XDestroyImage(dest);    }}/* * Draw the specified region of the given image data, * locating its anchor point at x, y */voidLCDUIdrawRegionTransform(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) {    Drawable drawable = setupGC(gc, 0, clip, dst, 0);    XImage *image;    myBitmapStruct *p = (myBitmapStruct *)img;    if (img == NULL) return;    image = &p->image;    if (p->mutable) {        image = XGetImage(display, p->pixmap, x_src, y_src,                            srcWidth, srcHeight, AllPlanes, ZPixmap);        x_src = y_src = 0;    }    switch (p->prop) {        case HAS_ALPHA: /* notice that this falls through to HAS_MASK                             * when USE_ALPHA_BLEND == 0                              */#if USE_ALPHA_BLEND             myPutImageAlpha(display, drawable, gc, image, p->imageMask,                 x_src, y_src, x_dest, y_dest, srcWidth, srcHeight,                transform, NO_BIT_MASK);            break;#endif        case HAS_MASK:            if (0 == transform) {                myPutImageMask(display, drawable, gc, image, p->imageMask,                     x_src, y_src, x_dest, y_dest, srcWidth, srcHeight);            } else {                /* use my putImageAlpha - this also does transforms                   and processes mask info too!	*/                myPutImageAlpha(display, drawable, gc, image, p->imageMask,                    x_src, y_src, x_dest, y_dest, srcWidth, srcHeight,                    transform, USE_BIT_MASK);            }            break;        default:            if (0 == transform && isRegion == KNI_FALSE) {                /* XPutImage is possibly faster than us processing                    transformation information and then drawing pixels                    individually*/                XPutImage(display, drawable, gc, image,                    x_src, y_src, x_dest, y_dest, srcWidth, srcHeight);            } else {                /*use my putImageAlpha - this also does transforms.*/                myPutImageAlpha(display, drawable, gc, image, NULL,                     x_src, y_src, x_dest, y_dest, srcWidth, srcHeight,                    transform, NO_BIT_MASK);           }           break;    }    if (!doubleBuffer && (drawable == paintDrawable)) {        refreshPaintWindow(x_dest, y_dest,                            x_dest + srcWidth/2, y_dest + srcHeight);    }    if (p->mutable) {        XDestroyImage(image);    }}/* * Copy the specified region of the given graphics object 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) {    Drawable drawable = setupGC(gc, 0, clip, dst, 0);    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;    }    XCopyArea(display, drawable, drawable, gc, x_src, y_src,	      width, height, x_dest, y_dest);}/* * Draw the given image data input as an array of 0xAARRGGBB integers, * locating its anchor point at x, y */void LCDUIdrawRGB(jshort *clip, void *dst,		  jint **rgbData, jint offset, jint scanlen, jint x, jint y, 		  jint width, jint height, jboolean processAlpha) {    jint i;    jint j;    jint argb;    jint alpha;    jint r;    jint g;    jint b;    XColor destPixel;    Drawable drawable = setupGC(gc, 0, clip, dst, 0);    XImage *dest = NULL;    dest = XGetImage(display, drawable, x, y, width, height, 			      AllPlanes, ZPixmap);    if (dest == NULL) {	fprintf(stderr, "drawRGB dest is null - abort drawRGB\n");	return;    }    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 		 */	      XPutPixel(dest, i, j, getPixelValue(r,g,b));            } else if (alpha != 0x00) {	                      unsigned long argbdest;                /*                 * not transparent so we need to blend the image pixel with                 * the one on the screen                 */		argbdest = XGetPixel(dest, i, j);		destPixel.blue  = (argbdest >> 16) & 0xff;		destPixel.green = (argbdest >> 8) & 0xff;		destPixel.red   = argbdest & 0xff;		                r += ((destPixel.red   * (0xff - alpha)) / 0xff);                g += ((destPixel.green * (0xff - alpha)) / 0xff);                b += ((destPixel.blue  * (0xff - alpha)) / 0xff);		                if (r > 0xff) {                    r = 0xff;                }		                if (g > 0xff) {                    g = 0xff;                }		                if (b > 0xff) {                    b = 0xff;                }                XPutPixel(dest, i, j,                           getPixelValue(r,                                         g,                                         b)); 	    }	}    }    /*     * draw the newly rendered image     */    XPutImage(display, drawable, gc, dest, 0, 0, x, y, width, height);    XDestroyImage(dest);    if (!doubleBuffer && (drawable == paintDrawable)) {        refreshPaintWindow(x, y, x + width, y + height);    }}voidLCDUIdestroyNativeImage(void* imagePtr) {    myBitmapStruct *imgData = (myBitmapStruct *)imagePtr;    if (imgData != NULL) {        if (imgData->pixmap != None) {            XFreePixmap(display, imgData->pixmap);        }        if (imgData->image.data) {            midpFree(imgData->image.data);        }        if (imgData->imageMask) {            midpFree(imgData->imageMask);        }	midpFree(imagePtr);    }}

⌨️ 快捷键说明

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