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

📄 gxapi_graphics_kni.c

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 C
📖 第 1 页 / 共 3 页
字号:
                  gx_draw_chars(GET_PIXEL(thisObject),                          clip,                          GET_IMAGEDATA_PTR_FROM_GRAPHICS(thisObject),                          GET_LINESTYLE(thisObject),                          face, style, size, x, y, anchor,                          &(JavaCharArray(ch)[offset]),                          length);        }    }    KNI_EndHandles();    KNI_ReturnVoid();}/** * Draws the specified pixels from the given data array. The array * consists of values in the form of 0xAARRGGBB. * <p> * Java declaration: * <pre> *     drawRGB([IIIIIIIZ)V * </pre> * * @param rgbData The array of argb pixels to draw * @param offset Zero-based index of first argb pixel to be drawn * @param scanlen Number of intervening pixels between pixels in *                the same column but in adjacent rows * @param x The x coordinate of the upper left corner of the *          region to draw * @param y The y coordinate of the upper left corner of the *          region to draw * @param width The width of the target region * @param height The height of the target region * @param processAlpha If <tt>true</tt>, alpha channel bytes will *                     be used, otherwise, alpha channel bytes will *                     be ignored */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(javax_microedition_lcdui_Graphics_drawRGB) {    jboolean processAlpha = KNI_GetParameterAsBoolean(8);    jint height = KNI_GetParameterAsInt(7);    jint width = KNI_GetParameterAsInt(6);    jint y = KNI_GetParameterAsInt(5);    jint x = KNI_GetParameterAsInt(4);    jint scanlen = KNI_GetParameterAsInt(3);    jint offset = KNI_GetParameterAsInt(2);    jint buflen;    jint *rgbBuffer;    long min, max, l_scanlen, l_height, l_tmpexp;        KNI_StartHandles(2);    KNI_DeclareHandle(rgbData);    KNI_DeclareHandle(thisObject);    KNI_GetParameterAsObject(1, rgbData);    KNI_GetThisPointer(thisObject);    if (GRAPHICS_OP_IS_ALLOWED(thisObject)) {        if (KNI_IsNullHandle(rgbData)) {            KNI_ThrowNew(midpNullPointerException, NULL);        } else {	            buflen = KNI_GetArrayLength(rgbData);	            /* According to the spec., this function can be             * defined as operation P(a,b) = rgbData[ offset +             * (a-x) + (b-y)* scanlength] where x <= a < x + width             * AND y <= b < y + height.             *             * We do not need to check every index value and its             * corresponding array access violation. We only need             * to check for the min/max case. Detail explanation             * can be found in the design doc.             *             * - To translate "<" to "<=", we minus one from height             * and width (the ceiling operation), for all cases             * except when height or width is zero.             * - To avoid overflow (or underflow), we cast the             * variables scanlen and height to long first */            l_scanlen = (long) scanlen;            l_height  = (long) height - 1;            l_tmpexp  = (height == 0) ? 0 : l_height * l_scanlen ;	            /* Find the max/min of the index for rgbData array */            max = offset + ((width==0) ? 0 : (width-1))                 + ((scanlen<0) ? 0 : l_tmpexp);            min = offset + ((scanlen<0) ? l_tmpexp : 0);	            if ((max >= buflen) || (min < 0) || (max < 0) || (min >= buflen)) {                KNI_ThrowNew(midpArrayIndexOutOfBoundsException, NULL);            } else {	                  if ((0 == scanlen ||                      0 == width   ||                      0 == height)) {	                        /* Valid values, but nothing to render. */	                    } else {                    jshort clip[4]; /* Defined in Graphics.java as 4 shorts */                                rgbBuffer = JavaIntArray(rgbData);                                TRANSLATE(thisObject, x, y);                    GET_CLIP(thisObject, clip);                                gx_draw_rgb(clip,                        GET_IMAGEDATA_PTR_FROM_GRAPHICS(thisObject),                         rgbBuffer, offset, scanlen, x, y, width,                         height, processAlpha);                }            }        }    }        KNI_EndHandles();    KNI_ReturnVoid();}/** * Copies the specified region of the current <tt>Graphics</tt> object * to the specified destination within the same <tt>Graphics</tt> object. * <p> * Java declaration: * <pre> *     doCopyArea(IIIIII)V * </pre> * * @param x_src The x coordinate of the upper-left corner of the *              source region * @param y_src The y coordinate of the upper-left corner of the *              source region * @param width The width of the source region * @param height The height of the source region * @param x_dest The x coordinate of the upper-left corner of the *               destination region * @param y_dest The y coordinate of the upper-left corner of the *               destination region * @param anchor The anchor point for positioning the copied region */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(javax_microedition_lcdui_Graphics_doCopyArea) {    int anchor = KNI_GetParameterAsInt(7);    int y_dest = KNI_GetParameterAsInt(6);     int x_dest = KNI_GetParameterAsInt(5);    int height = KNI_GetParameterAsInt(4);    int width  = KNI_GetParameterAsInt(3);    int y_src  = KNI_GetParameterAsInt(2);    int x_src  = KNI_GetParameterAsInt(1);    jshort gfx_width = 0;    jshort gfx_height = 0;    KNI_StartHandles(1);     KNI_DeclareHandle(thisObject);    KNI_GetThisPointer(thisObject);    if (GRAPHICS_OP_IS_ALLOWED(thisObject)) {        gfx_width  = (int)GXAPI_GET_GRAPHICS_PTR(thisObject)->maxWidth;        gfx_height = (int)GXAPI_GET_GRAPHICS_PTR(thisObject)->maxHeight;        TRANSLATE(thisObject, x_src, y_src);               if((height < 0) || (width < 0) || (x_src < 0) || (y_src < 0) ||           ((x_src + width) > gfx_width) || ((y_src + height) > gfx_height)) {            KNI_ThrowNew(midpIllegalArgumentException, NULL);        } else {	            TRANSLATE(thisObject, x_dest, y_dest);	            if (normalize_anchor(&x_dest, &y_dest, width, height, anchor)) {                jshort clip[4]; /* Defined in Graphics.java as 4 shorts */                GET_CLIP(thisObject, clip);                gx_copy_area(clip,                             GET_IMAGEDATA_PTR_FROM_GRAPHICS(thisObject),                             x_src, y_src, width, height,                              x_dest, y_dest);            }        }    }    KNI_EndHandles();    KNI_ReturnVoid();}/** * Gets a specific pixel value. * <p> * Java declaration: * <pre> *     getPixel(IIZ)I * </pre> * * @param rgb compact rgb representation * @param gray gray scale * @param isGray use gray scale */KNIEXPORT KNI_RETURNTYPE_INTKNIDECL(javax_microedition_lcdui_Graphics_getPixel) {    int isGray = KNI_GetParameterAsBoolean(3);    int   gray = KNI_GetParameterAsInt(2);    int    rgb = KNI_GetParameterAsInt(1);    KNI_ReturnInt(gx_get_pixel(rgb, gray, isGray));}/** * Maps the specified RGB value to the actual RGB value displayed * on device. * <p> * Java declaration: * <pre> *     getDisplayColor(I)I * </pre> * * @param color The RGB value to get the display mapping * @return The RGB value used to display this color on device */KNIEXPORT KNI_RETURNTYPE_INTKNIDECL(javax_microedition_lcdui_Graphics_getDisplayColor) {    int color = KNI_GetParameterAsInt(1);    KNI_ReturnInt(gx_get_displaycolor(color));}/** * Draws the specified image by using the anchor point. * The image can be drawn in different positions relative to * the anchor point by passing the appropriate position constants. * See <a href="#anchor">anchor points</a>. * * <p>If the source image contains transparent pixels, the corresponding * pixels in the destination image must be left untouched.  If the source * image contains partially transparent pixels, a compositing operation * must be performed with the destination pixels, leaving all pixels of * the destination image fully opaque.</p> * * <p>If <code>img</code> is the same as the destination of the Graphics * object, the result is undefined.  For copying areas within an * <code>Image</code>, {@link #copyArea copyArea} should be used instead. * </p> * * @param img the specified Image to be drawn * @param x the x coordinate of the anchor point * @param y the y coordinate of the anchor point * @param anchor the anchor point for positioning the image * @throws IllegalArgumentException if <code>anchor</code> * is not a legal value * @throws NullPointerException if <code>g</code> is <code>null</code> * @see Image */KNIEXPORT KNI_RETURNTYPE_BOOLEANKNIDECL(javax_microedition_lcdui_Graphics_render) {    jboolean success = KNI_TRUE;    int anchor = KNI_GetParameterAsInt(4);    int y      = KNI_GetParameterAsInt(3);    int x      = KNI_GetParameterAsInt(2);    KNI_StartHandles(3);    KNI_DeclareHandle(img);    KNI_DeclareHandle(g);    KNI_DeclareHandle(gImg);    KNI_GetParameterAsObject(1, img);    KNI_GetThisPointer(g);    if (GRAPHICS_OP_IS_ALLOWED(g)) {        /* null checking is handled by the Java layer, but test just in case */        if (KNI_IsNullHandle(img)) {            success = KNI_FALSE; //KNI_ThrowNew(midpNullPointerException, NULL);        } else {  	    const java_imagedata * srcImageDataPtr =	      IMGAPI_GET_IMAGE_PTR(img)->imageData;            IMGAPI_GET_IMAGE_PTR(gImg) =	      (struct Java_javax_microedition_lcdui_Image *)	      (GXAPI_GET_GRAPHICS_PTR(g)->img);            if (KNI_IsSameObject(gImg, img) || !check_anchor(anchor,0)) {                success = KNI_FALSE; //KNI_ThrowNew(midpIllegalArgumentException, NULL);            } else if (!normalize_anchor(&x, &y, srcImageDataPtr->width, 					       srcImageDataPtr->height, 					       anchor)) {                success = KNI_FALSE;//KNI_ThrowNew(midpIllegalArgumentException, NULL);            } else {	        jshort clip[4]; /* Defined in Graphics.java as 4 shorts */	        const java_imagedata * dstMutableImageDataPtr = 		  GET_IMAGEDATA_PTR_FROM_GRAPHICS(g);                TRANSLATE(g, x, y);		GET_CLIP(g, clip);		gx_render_image(srcImageDataPtr, dstMutableImageDataPtr,				clip, x, y);            }        }    }    KNI_EndHandles();    KNI_ReturnBoolean(success);}/** * Renders the given region of the given  <tt>Image</tt> onto the * this <tt>Graphics</tt> object. * <p> * Java declaration: * <pre> *     renderRegion(Ljavax/microedition/lcdui/Image;IIIIIIII)V * </pre> * * @param img The <tt>Image</tt> object to be drawn * @param x_src The x coordinate of the upper-left corner of the *              source region * @param y_src The y coordinate of the upper-left corner of the *              source region * @param width The width of the source region * @param height The height of the source region * @param transform The transform to apply to the selected region. * @param x_dest The x coordinate of the destination anchor point * @param y_dest The y coordinate of the destination anchor point * @param anchor The anchor point for positioning the destination *               <tt>Image</tt> */KNIEXPORT KNI_RETURNTYPE_BOOLEANKNIDECL(javax_microedition_lcdui_Graphics_renderRegion) {    int anchor    = KNI_GetParameterAsInt(9);    int y_dest    = KNI_GetParameterAsInt(8);    int x_dest    = KNI_GetParameterAsInt(7);    int transform = KNI_GetParameterAsInt(6);    int height    = KNI_GetParameterAsInt(5);    int width     = KNI_GetParameterAsInt(4);    int y_src     = KNI_GetParameterAsInt(3);    int x_src     = KNI_GetParameterAsInt(2);    jboolean success = KNI_TRUE;    KNI_StartHandles(3);    KNI_DeclareHandle(img);    KNI_DeclareHandle(g);    KNI_DeclareHandle(gImg);    KNI_GetParameterAsObject(1, img);    KNI_GetThisPointer(g);        if (GRAPHICS_OP_IS_ALLOWED(g)) {      if (KNI_IsNullHandle(img)) {        /* null checking is performed in the Java code, but check just in case */        success = KNI_FALSE; //KNI_ThrowNew(midpNullPointerException, NULL);      } else if ((transform < 0) || (transform > 7)) {        success = KNI_FALSE; //KNI_ThrowNew(midpIllegalArgumentException, NULL);      } else if (!normalize_anchor(&x_dest, &y_dest, width, height, anchor)) {        success = KNI_FALSE; //KNI_ThrowNew(midpIllegalArgumentException, NULL);      } else {	const java_imagedata * srcImageDataPtr = 	  IMGAPI_GET_IMAGE_PTR(img)->imageData;        jint img_width = srcImageDataPtr->width;        jint img_height = srcImageDataPtr->height;        IMGAPI_GET_IMAGE_PTR(gImg) = 	  (struct Java_javax_microedition_lcdui_Image *)	                      (GXAPI_GET_GRAPHICS_PTR(g)->img);        if (KNI_IsSameObject(gImg, img) ||            (height < 0) || (width < 0) || (x_src < 0) || (y_src < 0) ||           ((x_src + width) > img_width) ||            ((y_src + height) > img_height)) {          success = KNI_FALSE; //KNI_ThrowNew(midpIllegalArgumentException, NULL);        } else {	  jshort clip[4]; /* Defined in Graphics.java as 4 shorts */	  const java_imagedata * dstMutableImageDataPtr = 	    GET_IMAGEDATA_PTR_FROM_GRAPHICS(g);	  TRANSLATE(g, x_dest, y_dest);	  GET_CLIP(g, clip);	  gx_render_imageregion(srcImageDataPtr, dstMutableImageDataPtr,				clip, 				x_src, y_src, 				width, height,				x_dest, y_dest, 				transform);        }      }    }    KNI_EndHandles();    KNI_ReturnBoolean(success);}

⌨️ 快捷键说明

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