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

📄 m3gimage2d.c

📁 java 1.1 gemini 08_16
💻 C
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************
 *  Modification Notice:
 *  --------------------------
 *  This software is modified by MediaTek Inc. and the information contained
 *  herein is confidential. The software may not be copied and the information
 *  contained herein may not be used or disclosed except with the written
 *  permission of MediaTek Inc. (C) 2001
 *
 *******************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 *  CompositingMode.c
 *
 * Project:
 * --------
 *   Maui_Software
 *
 * Description:
 * ------------
 *   
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/

/*************************************************************************
 * Include Header Files
 *************************************************************************/
#include "m3g.h"

#ifdef SUPPORT_JSR_184
#include "imagedecode.h"
#include "defaultLCDUI.h"
#include "images.h"

extern BYTEARRAY canvas;

#define DRV_RGBA_TO_HW(r, g, b, a) ((kal_uint16)(((((kal_uint8)r)>>4)<<12) | ((((kal_uint8)g)>>4)<<8) | \
	((((kal_uint8)b)>>4)<<4) | (((kal_uint8)a)>>4)))

extern FILE* debugg_fp;
extern void _m3d_Graphics3D_release_texobj(st_m3g_image2d* image);

/*************************************************************************
 * Function Definition
 *************************************************************************/
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_m3g_Image2D_create()
{
	st_m3g_image2d* handle = NULL;
	jint format = KNI_GetParameterAsInt(1);
	jint width = KNI_GetParameterAsInt(2);
	jint height = KNI_GetParameterAsInt(3);

	KNI_StartHandles(1);
	KNI_DeclareHandle(data_handle);
	KNI_GetParameterAsObject(4, data_handle);

	if(width<=0 || height<=0 || format<M3G_IMAGE2D_ALPHA || format>M3G_IMAGE2D_RGBA) {
		KNI_ThrowNew("java/lang/IllegalArgumentException", "invalid argument");
		goto _return;
	}

	if(*data_handle == NULL) {
		KNI_ThrowNew("java/lang/NullPointerException", "NULL target");
	} else {
#if FAST_KNI && defined(CLDCHI)
		jbyte_array* data = (jbyte_array*)*data_handle;
		kal_uint32 pixel_bytes = 3;
		kal_uint8 pixel_type = M3G_IMAGE2D_PIXEL_UNSIGNED_BYTES;
		jbyte_array* dst; 

		switch(format) {
		case M3G_IMAGE2D_ALPHA:
		case M3G_IMAGE2D_LUMINANCE:
			pixel_bytes = 1;
			break;
		case M3G_IMAGE2D_LUMINANCE_ALPHA:
			pixel_bytes = 2;
			break;
		case M3G_IMAGE2D_RGB:
			pixel_bytes = 3;
			break;
		case M3G_IMAGE2D_RGBA:
			pixel_bytes = 4;
		default:
			break;
		}

		if(((jbyte_array*)*data_handle)->length < width*height*pixel_bytes) {
			KNI_ThrowNew("java/lang/IllegalArgumentException", "invalid data");
			goto _return;
		}

		dst = (jbyte_array*)instantiateArrayKNI(PrimitiveArrayClasses[T_BYTE], width*height*pixel_bytes);

		if(dst == NULL) {
			KNI_ThrowNew("java/lang/OutOfMemoryError", "heap memory not available");
			goto _return;
		}

		/* instantiateArrayKNI will trigger gc, update src data pointer again */
		data = (jbyte_array*)*data_handle;

		memcpy(dst->elements, data->elements, width*height*pixel_bytes);
		data = (jbyte_array*)dst;

		ENTER_M3D_CS;
		handle = M3G_Image2D_new((kal_uint8)format, pixel_type, 
								 (kal_uint32)width, (kal_uint32)height, 
								 (kal_uint8*)data, KAL_FALSE, M3G_IMAGE2D_PIXEL_BYTEARRAYHANDLE);
		LEAVE_M3D_CS;

		if(handle == NULL) {
			KNI_ThrowNew("java/lang/OutOfMemoryError", "memory not available");
		} else {
			/* Add pixels to global root which protected by gc */
			if (handle->pixels) { 
				ADD_TO_GLOBAL_ROOT(handle->pixels);
			}
		}
#else
	ASSERT(0);
#endif /* FAST_KNI */
	}

_return:
	KNI_EndHandles();
	KNI_ReturnInt((jint)handle);		
}
	
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_m3g_Image2D_createMutableImpl()
{
	st_m3g_image2d* handle = NULL;
	jint format = KNI_GetParameterAsInt(1);
	jint width = KNI_GetParameterAsInt(2);
	jint height = KNI_GetParameterAsInt(3);

	/* only RGB and RGBA can be as rendering target */
	if(width<=0 || height<=0 || format<M3G_IMAGE2D_ALPHA || format>M3G_IMAGE2D_RGBA) {
		KNI_ThrowNew("java/lang/IllegalArgumentException", "invalid argument");
		goto _return;
	} else {
#if FAST_KNI && defined(CLDCHI)
		kal_uint8 pixel_type = M3G_IMAGE2D_PIXEL_UNSIGNED_BYTES;
		kal_uint8 pixel_bytes = 1;
		void* dst = NULL;

		switch (format) {
		case M3G_IMAGE2D_ALPHA:
		case M3G_IMAGE2D_LUMINANCE:
			break;
		case M3G_IMAGE2D_LUMINANCE_ALPHA:
			pixel_bytes = 2;
			break;
		case M3G_IMAGE2D_RGB:
			pixel_type = M3G_IMAGE2D_PIXEL_UNSIGNED_SHORT_5_6_5;
			pixel_bytes = 2;
			break;
		case M3G_IMAGE2D_RGBA:
			pixel_type = M3G_IMAGE2D_PIXEL_UNSIGNED_BYTES;
			pixel_bytes = 4;
			break;
		default:
			break;
		}

		dst = (void*)instantiateArrayKNI(PrimitiveArrayClasses[T_BYTE], width*height*pixel_bytes);

		if(dst == NULL) {
			KNI_ThrowNew("java/lang/OutOfMemoryError", "heap memory not available");
			goto _return;
		}
		memset(((jbyte_array*)dst)->elements, 0xff, width*height*pixel_bytes);

		ENTER_M3D_CS;
		handle = M3G_Image2D_new((kal_uint8)format, pixel_type, (kal_uint32)width, (kal_uint32)height, 
								 (kal_uint8*)dst, KAL_TRUE, M3G_IMAGE2D_PIXEL_BYTEARRAYHANDLE);
		LEAVE_M3D_CS;

		if(handle == NULL) {
			KNI_ThrowNew("java/lang/OutOfMemoryError", "memory not available");
		} else {
			/* Add pixels to global root which protected by gc */
			if (handle->pixels) {
				ADD_TO_GLOBAL_ROOT(handle->pixels);
			}
		}
#else
	ASSERT(0);
#endif /* FAST_KNI */
	}

_return:
	KNI_ReturnInt((jint)handle);
}

KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_m3g_Image2D_createImmutableImpl()
{
	st_m3g_image2d* handle = NULL;
	jint format = KNI_GetParameterAsInt(2);
	int i, j;

	KNI_StartHandles(1);
	KNI_DeclareHandle(object_handle);
	KNI_GetParameterAsObject(1, object_handle);

	if(format<M3G_IMAGE2D_ALPHA || format>M3G_IMAGE2D_RGBA) {
		KNI_ThrowNew("java/lang/IllegalArgumentException", "invalid argument");
		goto _return;
	} else if (*object_handle != NULL) {
#if FAST_KNI && defined(CLDCHI)
		void* dst = ((image_class)*object_handle)->imgData;
		void* imgdest = dst;
		int width = ((image_class)*object_handle)->width;
		int height = ((image_class)*object_handle)->height;

		pImageGC gc = (pImageGC)((dst==NULL)?(((BYTEARRAY)canvas)->bdata):(((BYTEARRAY)dst)->bdata));
		kal_uint16* img_data = (kal_uint16*)((dst==NULL)? gc->u.datap:gc->u.data);
		kal_uint8 flag_handle = dst==NULL ? KAL_FALSE : KAL_TRUE;
		kal_uint8 pixel_type = M3G_IMAGE2D_PIXEL_UNSIGNED_SHORT_5_6_5;
		kal_uint8 handle_type = M3G_IMAGE2D_PIXEL_POINTER;

		/* Need to do some conversion */
		switch(format) {
		case M3G_IMAGE2D_ALPHA:
		case M3G_IMAGE2D_LUMINANCE:
		case M3G_IMAGE2D_LUMINANCE_ALPHA:
			{
				kal_uint8 pixel_bytes = 1;
				int pixel, *pixel_ptr = &pixel;
				pixel_type = M3G_IMAGE2D_PIXEL_UNSIGNED_BYTES;
				flag_handle = KAL_TRUE;
				handle_type = M3G_IMAGE2D_PIXEL_BYTEARRAYHANDLE;

				if(format == M3G_IMAGE2D_LUMINANCE_ALPHA) pixel_bytes = 2;

				imgdest = (void*)instantiateArrayKNI(PrimitiveArrayClasses[T_BYTE], width*height*pixel_bytes);

				if(imgdest == NULL) {
					KNI_ThrowNew("java/lang/OutOfMemoryError", "heap memory not available");
					goto _return;
				}

				/* instantiateArrayKNI will trigger gc, update src again */
				dst = imgdest;
				imgdest = ((image_class)*object_handle)->imgData;

				for(i=0; i<height; i++) {
					for(j=0; j<width; j++) {
						LCDUIgetRGB(&pixel_ptr, 0, width, j, i, 1, 1, imgdest);

						if(format == M3G_IMAGE2D_ALPHA || format == M3G_IMAGE2D_LUMINANCE) {
							((jbyte_array*)dst)->elements[i*width + j] = (kal_uint8)(((((pixel>>16)&0xFF) * 77) + 
																					  (((pixel>>8)&0xFF) * 154) + 
																					  (((pixel>>0)&0xFF) * 25)) >> 8);
						} else {
							((jbyte_array*)dst)->elements[2*(i*width + j)] = (kal_uint8)(((((pixel>>16)&0xFF) * 77) + 
																					  (((pixel>>8)&0xFF) * 154) + 

⌨️ 快捷键说明

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