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

📄 qtimage.cpp

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * @(#)QtImage.cpp	1.24 06/10/10 *  * Copyright  1990-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER *  * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation.  *  * 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 version 2 for more details (a copy is * included at /legal/license.txt).  *  * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA  *  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions.  */#include <stdlib.h>#include <string.h>#include <assert.h>#include "java_awt_QtImage.h"#include "java_awt_AlphaComposite.h"#include "QtInterface.h"#include "QtBackEnd.h"#include "QtApplication.h"/*#ifdef QWS#include "QPatchedPixmap.h"#endif*/extern "C" {   long getImageDataPtr(JNIEnv *env, jobject qtimage);}JNIEXPORT void JNICALLJava_java_awt_QtImage_initIDs (JNIEnv * env, jclass cls){	GET_FIELD_ID (QtImage_widthFID, "width", "I");	GET_FIELD_ID (QtImage_heightFID, "height", "I");	GET_FIELD_ID (QtImage_psdFID, "psd", "I");	FIND_CLASS ("java/awt/image/ColorModel");	GET_METHOD_ID (java_awt_image_ColorModel_getRGBMID, "getRGB", "(I)I");	FIND_CLASS ("java/awt/image/IndexColorModel");	GET_FIELD_ID (java_awt_image_IndexColorModel_rgbFID, "rgb", "[I");	FIND_CLASS ("java/awt/image/DirectColorModel");	GET_FIELD_ID (java_awt_image_DirectColorModel_red_maskFID, "red_mask", "I");	GET_FIELD_ID (java_awt_image_DirectColorModel_red_offsetFID, "red_offset", "I");	GET_FIELD_ID (java_awt_image_DirectColorModel_red_scaleFID, "red_scale", "I");	GET_FIELD_ID (java_awt_image_DirectColorModel_green_maskFID, "green_mask", "I");	GET_FIELD_ID (java_awt_image_DirectColorModel_green_offsetFID, "green_offset", "I");	GET_FIELD_ID (java_awt_image_DirectColorModel_green_scaleFID, "green_scale", "I");	GET_FIELD_ID (java_awt_image_DirectColorModel_blue_maskFID, "blue_mask", "I");	GET_FIELD_ID (java_awt_image_DirectColorModel_blue_offsetFID, "blue_offset", "I");	GET_FIELD_ID (java_awt_image_DirectColorModel_blue_scaleFID, "blue_scale", "I");	GET_FIELD_ID (java_awt_image_DirectColorModel_alpha_maskFID, "alpha_mask", "I");	GET_FIELD_ID (java_awt_image_DirectColorModel_alpha_offsetFID, "alpha_offset", "I");	GET_FIELD_ID (java_awt_image_DirectColorModel_alpha_scaleFID, "alpha_scale", "I");}JNIEXPORT void JNICALLJava_java_awt_QtImage_imageCompleteLoadBuffer (JNIEnv * env, jclass cls, jint qtImageDesc, jboolean dispose){	if(qtImageDesc<=0) return;		assert(QtImageDescPool[qtImageDesc].loadBuffer!=NULL);    AWT_QT_LOCK;	((QPixmap *)QtImageDescPool[qtImageDesc].qpd)->convertFromImage(*(QtImageDescPool[qtImageDesc].loadBuffer),                Qt::ThresholdDither | Qt::ThresholdAlphaDither |                 Qt::AvoidDither);											QtImageDescPool[qtImageDesc].mask = ((QPixmap *)QtImageDescPool[qtImageDesc].qpd)->mask();		if(QtImageDescPool[qtImageDesc].mask == NULL)	{			int width = QtImageDescPool[qtImageDesc].width;		int height = QtImageDescPool[qtImageDesc].height;		QBitmap bm(width, height);				QPainter qp(&bm);		qp.fillRect(0, 0, width, height, Qt::color1);				((QPixmap *)QtImageDescPool[qtImageDesc].qpd)->setMask(bm);		QtImageDescPool[qtImageDesc].mask = ((QBitmap *)QtImageDescPool[qtImageDesc].qpd)->mask();	}		if(dispose == JNI_TRUE) {		delete QtImageDescPool[qtImageDesc].loadBuffer;		QtImageDescPool[qtImageDesc].loadBuffer = NULL;	}    AWT_QT_UNLOCK;}JNIEXPORT void JNICALLJava_java_awt_QtImage_pSetColorModelBytePixels (JNIEnv * env,jclass cls,jint qtImageDesc,jint x, jint y, jint w, jint h,jobject colorModel,jbyteArray pixels, jint offset, jint scansize){	jint m, n;					 /* x, y position in pixel array - same variable names as Javadoc comment for setIntPixels. */	unsigned char pixel;	unsigned char lastPixel;	jint index = offset;	jbyte *pixelArray = NULL;	unsigned long rgb=0;		pixelArray = env->GetByteArrayElements (pixels, NULL);	if (pixelArray == NULL)		return;	/* Make sure first time round the loop we actually get the Microwindows pixel value. */	lastPixel = ~(pixelArray[index]);    AWT_QT_LOCK;	QImage *qi = QtImageDescPool[qtImageDesc].loadBuffer;    assert(qi != NULL);		/* For each pixel in the supplied pixel array look up its rgb value from the colorModel. */	for (n = 0; n < h; n++)	{		for (m = 0; m < w; m++)		{			/* Get the pixel at m, n. */			pixel = (unsigned char) pixelArray[index++];			if (lastPixel != pixel)			{				rgb = (unsigned long)					env->CallIntMethod (colorModel, QtCachedIDs.java_awt_image_ColorModel_getRGBMID,					(jint) pixel);				if (env->ExceptionCheck()) {                    goto exit_method;				}				/* Remember last pixel value for optimisation purposes. */				lastPixel = pixel;							}			qi->setPixel(m+x, n+y, rgb);		}		index += (scansize-m);	} exit_method:    AWT_QT_UNLOCK;	env->ReleaseByteArrayElements (pixels, pixelArray, JNI_ABORT);}JNIEXPORT void JNICALLJava_java_awt_QtImage_pSetColorModelIntPixels (JNIEnv * env,jclass cls,jint qtImageDesc,jint x, jint y, jint w, jint h,jobject colorModel,jintArray pixels, jint offset, jint scansize){	unsigned long pixel;	unsigned long lastPixel;	jint index = offset;	jint *pixelArray = NULL;	int n, m;	unsigned long rgb = 0;	pixelArray = env->GetIntArrayElements (pixels, NULL);	if (pixelArray == NULL)		return;	/* Make sure first time round the loop we actually get the Microwindows pixel value. */	lastPixel = ~(pixelArray[index]);    AWT_QT_LOCK;	QImage *qi = QtImageDescPool[qtImageDesc].loadBuffer;    assert(qi != NULL);	/* For each pixel in the supplied pixel array look up its rgb value from the colorModel. */	for (n = 0; n < h; n++)	{		for (m = 0; m < w; m++)		{			/* Get the pixel at m, n. */			pixel = (unsigned long) pixelArray[index++];			if (lastPixel != pixel)			{				rgb = (unsigned long)					env->CallIntMethod (colorModel, QtCachedIDs.java_awt_image_ColorModel_getRGBMID,					pixel);				if (env->ExceptionCheck()) {                    goto exit_method;				}				/* Remember last pixel value for optimisation purposes. */				lastPixel = pixel;			}			qi->setPixel(m+x, n+y, rgb);		}		index += (scansize-m);	} exit_method:    AWT_QT_UNLOCK;	env->ReleaseIntArrayElements (pixels, pixelArray, JNI_ABORT);}JNIEXPORT void JNICALLJava_java_awt_QtImage_pSetIndexColorModelBytePixels (JNIEnv * env,                                                     jclass cls,                                                     jint qtImageDesc,                                                     jint x, jint y,                                                      jint w, jint h,                                                     jobject colorModel,                                                     jbyteArray pixels,                                                      jint offset,                                                      jint scansize){	jintArray rgbs;	jint *rgbArray;				 /* Array of RGB values retrieved from IndexColorModel. */	jint m, n;					 /* x, y position in pixel array - same variable names as Javadoc comment for setIntPixels. */	unsigned char pixel;	jint index = offset;	jbyte *pixelArray = NULL;	rgbs = (jintArray)env->GetObjectField (colorModel, QtCachedIDs.java_awt_image_IndexColorModel_rgbFID);	rgbArray = env->GetIntArrayElements (rgbs, NULL);	if (rgbArray == NULL)		return;	pixelArray = env->GetByteArrayElements (pixels, NULL);	if (pixelArray == NULL) {		env->ReleaseIntArrayElements (rgbs, rgbArray, JNI_ABORT);		return;	}    AWT_QT_LOCK;	QImage *qi = QtImageDescPool[qtImageDesc].loadBuffer;    assert(qi != NULL);	/* For each pixel in the supplied pixel array look up its rgb value from the colorModel. */	for (n = 0; n < h; n++)	{		for (m = 0; m < w; m++)		{			/* Get the pixel at m, n. */			pixel = (unsigned char) pixelArray[index++];			/* Get and store red, green, blue values. */			qi->setPixel(m+x, n+y, (unsigned long)rgbArray[pixel]);		}		index += (scansize-m);	}    AWT_QT_UNLOCK;		if (pixelArray != NULL)		env->ReleaseByteArrayElements (pixels, pixelArray, JNI_ABORT);	env->ReleaseIntArrayElements (rgbs, rgbArray, JNI_ABORT);}JNIEXPORT void JNICALLJava_java_awt_QtImage_pSetIndexColorModelIntPixels (JNIEnv * env,                                                    jclass cls,                                                    jint qtImageDesc,                                                    jint x, jint y,                                                     jint w, jint h,                                                    jobject colorModel,                                                    jintArray pixels,                                                     jint offset,                                                     jint scansize){	jintArray rgbs;	jint *rgbArray;				 /* Array of RGB values retrieved from IndexColorModel. */	jint m, n;					 /* x, y position in pixel array - same variable names as Javadoc comment for setIntPixels. */	unsigned long pixel;	jint *pixelArray = NULL;	jint index = offset;	rgbs = (jintArray)env->GetObjectField (colorModel, QtCachedIDs.java_awt_image_IndexColorModel_rgbFID);	rgbArray = env->GetIntArrayElements (rgbs, NULL);	if (rgbArray == NULL)		return;	pixelArray = env->GetIntArrayElements (pixels, NULL);	if (pixelArray == NULL) {		env->ReleaseIntArrayElements (rgbs, rgbArray, JNI_ABORT);		return;	}    AWT_QT_LOCK;	QImage *qi = QtImageDescPool[qtImageDesc].loadBuffer;    assert(qi != NULL);	/* For each pixel in the supplied pixel array look up its rgb value from the colorModel. */	for (n = 0; n < h; n++)	{		for (m = 0; m < w; m++)		{			/* Get the pixel at m, n. */			pixel = (unsigned long) pixelArray[index++];			/* Get and store red, green, blue values. */			qi->setPixel(m+x, n+y, (unsigned long)rgbArray[pixel]);		}		index += (scansize-m);	}    AWT_QT_UNLOCK;	if (pixelArray != NULL)		env->ReleaseIntArrayElements (pixels, pixelArray, JNI_ABORT);	env->ReleaseIntArrayElements (rgbs, rgbArray, JNI_ABORT);}JNIEXPORT void JNICALLJava_java_awt_QtImage_pSetDirectColorModelPixels (JNIEnv * env,												  jclass cls,												  jint qtImageDesc,												  jint x, jint y,                                                   jint w, jint h,												  jobject colorModel,												  jintArray pixels,                                                   jint offset,                                                   jint scansize,                                                   jint totalMask){		jint *pixelArray = env->GetIntArrayElements (pixels, NULL);		if (pixelArray == NULL) return;	    AWT_QT_LOCK;	QImage *qi = QtImageDescPool[qtImageDesc].loadBuffer;    assert(qi != NULL);		/* For each pixel in the supplied pixel array calculate its rgb value      * from the colorModel. */		if(((unsigned long)totalMask) == 0xFFFFFFFF) {		int widthlinesize = w * sizeof(QRgb);		QRgb *pa = ((QRgb *)pixelArray) + offset + scansize * (h - 1);		for(int i=h-1;i>=0;i--) {			memcpy((QRgb*)qi->scanLine(i+y)+x, pa, widthlinesize);			pa -= scansize;		}    }    else {        /* x, y position in pixel array - same variable names as Javadoc          * comment for setIntPixels. */        jint m, n;					 		           jint index = offset;        unsigned long rgb = 0;        unsigned long pixel;        unsigned long lastPixel;		           unsigned long alpha, red, green, blue;		           unsigned long red_mask = (unsigned long)env->GetIntField (colorModel,                 QtCachedIDs.java_awt_image_DirectColorModel_red_maskFID);		           unsigned long green_mask = (unsigned long)env->GetIntField (colorModel,                 QtCachedIDs.java_awt_image_DirectColorModel_green_maskFID);		           unsigned long blue_mask = (unsigned long) env->GetIntField (colorModel,                 QtCachedIDs.java_awt_image_DirectColorModel_blue_maskFID);		           unsigned long alpha_mask = (unsigned long)env->GetIntField(colorModel,                 QtCachedIDs.java_awt_image_DirectColorModel_alpha_maskFID);		           unsigned long red_offset = (unsigned long)env->GetIntField (colorModel,                 QtCachedIDs.java_awt_image_DirectColorModel_red_offsetFID);        unsigned long red_scale = (unsigned long) env->GetIntField (colorModel,				 QtCachedIDs.java_awt_image_DirectColorModel_red_scaleFID);		           unsigned long green_offset = (unsigned long)env->GetIntField(                 colorModel,                 QtCachedIDs.java_awt_image_DirectColorModel_green_offsetFID);        unsigned long green_scale = (unsigned long) env->GetIntField (                 colorModel,                 QtCachedIDs.java_awt_image_DirectColorModel_green_scaleFID);		           unsigned long blue_offset = (unsigned long) env->GetIntField (                 colorModel,                 QtCachedIDs.java_awt_image_DirectColorModel_blue_offsetFID);        unsigned long blue_scale = (unsigned long) env->GetIntField (                 colorModel,                 QtCachedIDs.java_awt_image_DirectColorModel_blue_scaleFID);		           unsigned long alpha_offset = (unsigned long) env->GetIntField (                 colorModel,                 QtCachedIDs.java_awt_image_DirectColorModel_alpha_offsetFID);        unsigned long alpha_scale = (unsigned long) env->GetIntField (                 colorModel,                 QtCachedIDs.java_awt_image_DirectColorModel_alpha_scaleFID);		           /* Make sure first time round the loop we actually get the          * pixel value. */		           lastPixel = ~(pixelArray[index]);		           for (n = 0; n < h; n++) {            for (m = 0; m < w; m++) {                /* Get the pixel at m, n. */				                   pixel = (unsigned long) pixelArray[index++];				                   /* If pixel value is not the same as the last one then get                  * red, green, blue and set the foreground for drawing the                  * point in the image. */				                   if (pixel != lastPixel) {                    red = ((pixel & red_mask) >> red_offset);					                    if (red_scale != 0)                        red = red * 255 / red_scale;					                       green = ((pixel & green_mask) >> green_offset);					                       if (green_scale != 0)                        green = green * 255 / green_scale;					                       blue = ((pixel & blue_mask) >> blue_offset);					                       if (blue_scale != 0)                        blue = blue * 255 / blue_scale;

⌨️ 快捷键说明

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