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

📄 jpgapi.c

📁 SAMSUNG S3C6410 CPU BSP for winmobile6
💻 C
📖 第 1 页 / 共 5 页
字号:

	// check validation of input datasize
	if(jCtx->encParam->width*jCtx->encParam->height*2 != jCtx->encParam->dataSize){
		RETAILMSG(1, (TEXT("API :: data size and width/height doesn't match\r\n")));
		return JPEG_FAIL;
	}
	
	// scale down YUV data for thumbnail encoding
	if((Exif != NULL) && (jCtx->thumbnailFlag == TRUE)){
		if((jCtx->encParam->width % jCtx->thumbEncParam->width != 0) 
			|| (jCtx->encParam->height % jCtx->thumbEncParam->height != 0)){
			RETAILMSG(1, (TEXT("API :: Main JPEG  have to be multiple of  Thumbnail resolution \r\n")));
			return FALSE;
		}

		jCtx->thumbEncParam->dataSize = jCtx->thumbEncParam->width*jCtx->thumbEncParam->height*2;

		ret = DeviceIoControl(openHandle, IOCTL_JPG_GET_THUMB_FRMBUF, NULL, 
					0, &(jCtx->InThumbBuf), sizeof(jCtx->InThumbBuf), NULL, NULL);

		if(ret == 0){
			RETAILMSG(1, (TEXT("API :: IOCTL_JPG_GET_THUMB_FRMBUF failed\r\n")));
			return JPEG_FAIL;
		}

		printD("API :: jCtx->InThumbBuf(addr : %x callerProcessID : 0x%x)\n", jCtx->InThumbBuf, (HANDLE)GetCurrentProcessId());
	
		scalDownYUV422(jCtx->InBuf, jCtx->encParam->width, jCtx->encParam->height, 
						jCtx->InThumbBuf, jCtx->thumbEncParam->width, jCtx->thumbEncParam->height);

	}

	// encode main image
	ret = DeviceIoControl(openHandle, IOCTL_JPG_ENCODE, NULL, 
						0, NULL, 0, (PDWORD)jCtx->encParam, NULL);
	if(ret == 0){
			RETAILMSG(1, (TEXT("API :: IOCTL_JPG_ENCODE failed\r\n")));
			return JPEG_FAIL;
	}

	// if user want to make Exif file
	if(Exif){
		jCtx->ExifInfo = Exif;

		// encode thumbnail image
		if(jCtx->thumbnailFlag){			
			if((ret = makeThumbImage(openHandle)) != JPEG_OK)
				return JPEG_FAIL;

			bufSize = EXIF_FILE_SIZE + jCtx->thumbEncParam->fileSize;
		}else 
			bufSize = EXIF_FILE_SIZE;

		if(jCtx->encParam->fileSize + bufSize > MAX_FILE_SIZE){
			printf("API : Exif Error - out of buffer\n");
			return JPEG_FAIL;
		}

		ExifBuf = (char *)malloc(bufSize);
		printD("ExifBuf (addr : %x)\n", ExifBuf);
		memset(ExifBuf, 0x20, bufSize);

		// make Exif file including thumbnail image
		if((result = makeExifFile(ExifBuf, &ExifLen)) != JPEG_OK){
			free(ExifBuf);
			return JPEG_FAIL;
		}

		printD("ExifLen : %d jCtx->encParam->fileSize : %d \n", ExifLen, jCtx->encParam->fileSize);
		ret = DeviceIoControl(openHandle, IOCTL_JPG_GET_STRBUF, NULL, 
					0, &(jCtx->OutBuf), sizeof(jCtx->OutBuf), NULL, NULL);
		if(ret == 0){
			RETAILMSG(1, (TEXT("API :: IOCTL_JPG_GET_STRBUF failed\r\n")));
			return JPEG_FAIL;
		}

		printD("API :: jCtx->OutBuf(addr : %x callerProcessID : 0x%x)\n", jCtx->OutBuf, (HANDLE)GetCurrentProcessId());
	
		// merge Exif file with encoded JPEG file header
		memmove(&jCtx->OutBuf[ExifLen+2], &jCtx->OutBuf[2], jCtx->encParam->fileSize - 2); 
		memcpy(&jCtx->OutBuf[2], ExifBuf, ExifLen);
		jCtx->encParam->fileSize += ExifLen;
		free(ExifBuf);
	}
	
	return JPEG_OK;
}

/*----------------------------------------------------------------------------
*Function: SsbSipJPEGGetDecodeInBuf

*Parameters: 		*openHandle : openhandle from SsbSipJPEGDecodeInit
					size : input stream(YUV/RGB) size
*Return Value:		virtual address of Decoder input buffer
*Implementation Notes: allocate decoder input buffer 
-----------------------------------------------------------------------------*/
void *SsbSipJPEGGetDecodeInBuf(void *openHandle, long size)
{
	int ret;

	if(size < 0 || size > MAX_FILE_SIZE){
		RETAILMSG(1, (TEXT("API :: Invalid Decoder input buffer size\r\n")));
		return NULL;
	}

	jCtx->decParam->fileSize = size;
	
	ret = DeviceIoControl(openHandle, IOCTL_JPG_GET_STRBUF, NULL, 
					0, &(jCtx->InBuf), sizeof(jCtx->InBuf), NULL, NULL);
	if(ret == 0){
			RETAILMSG(1, (TEXT("API :: IOCTL_JPG_GET_STRBUF failed\r\n")));
			return NULL;
	}

	printD("API :: jCtx->InBuf(addr : %x size: %d callerProcessID : 0x%x)\n", jCtx->InBuf, size, (HANDLE)GetCurrentProcessId());
	return (jCtx->InBuf);
}

/*----------------------------------------------------------------------------
*Function: SsbSipJPEGGetDecodeOutBuf

*Parameters: 		*openHandle : openhandle from SsbSipJPEGDecodeInit
					size : output JPEG file size
*Return Value:		virtual address of Decoder output buffer
*Implementation Notes: return decoder output buffer 
-----------------------------------------------------------------------------*/
void *SsbSipJPEGGetDecodeOutBuf (void *openHandle, long *size)
{
	int ret;

	ret = DeviceIoControl(openHandle, IOCTL_JPG_GET_FRMBUF, NULL, 
							0, &(jCtx->OutBuf), sizeof(jCtx->OutBuf), NULL, NULL);

	if(ret == 0){
			RETAILMSG(1, (TEXT("API :: GetDecodeOutBuf failed\r\n")));
			return NULL;
	}

	printD("API :: DecodeOutBuf : 0x%x size : %d\n", jCtx->OutBuf, jCtx->decParam->dataSize);
	*size = jCtx->decParam->dataSize;
	return (jCtx->OutBuf);
}

/*----------------------------------------------------------------------------
*Function: SsbSipJPEGGetEncodeInBuf

*Parameters: 		*openHandle : openhandle from SsbSipJPEGEncodeInit
					size : input JPEG file size
*Return Value:		virtual address of Encoder input buffer
*Implementation Notes: allocate encoder input buffer 
-----------------------------------------------------------------------------*/
void *SsbSipJPEGGetEncodeInBuf(void *openHandle, long size)
{	
	int ret;

	if(size < 0 || size > MAX_YUV_SIZE){
		RETAILMSG(1, (TEXT("API :: Invalid Encoder input buffer size(%d)\r\n"), size));
		return NULL;
	}

	jCtx->encParam->dataSize = size;

	ret = DeviceIoControl(openHandle, IOCTL_JPG_GET_FRMBUF, NULL, 
							0, &(jCtx->InBuf), sizeof(jCtx->InBuf), NULL, NULL);

	if(ret == 0){
			RETAILMSG(1, (TEXT("API :: GetDecodeOutBuf failed\r\n")));
			return NULL;
	}

	printD("API :: EncodeInBuf : 0x%x size : %d\n", jCtx->InBuf, jCtx->encParam->dataSize);
	return (jCtx->InBuf);
}

/*----------------------------------------------------------------------------
*Function: SsbSipJPEGGetEncodeOutBuf

*Parameters: 		*openHandle : openhandle from SsbSipJPEGEncodeInit
					*size : output stream(YUV/RGB) size
*Return Value:		virtual address of Encoder output buffer
*Implementation Notes: return encoder output buffer 
-----------------------------------------------------------------------------*/
void *SsbSipJPEGGetEncodeOutBuf (void *openHandle, long *size)
{
	int ret;

	*size = jCtx->encParam->fileSize;

	ret = DeviceIoControl(openHandle, IOCTL_JPG_GET_STRBUF, NULL, 
					0, &(jCtx->OutBuf), sizeof(jCtx->OutBuf), NULL, NULL);
	if(ret == 0){
			RETAILMSG(1, (TEXT("API :: IOCTL_JPG_GET_STRBUF failed\r\n")));
			return NULL;
	}

	printD("API :: jCtx->OutBuf(addr : %x size: %d callerProcessID : 0x%x)\n", jCtx->OutBuf, *size, (HANDLE)GetCurrentProcessId());
	
	return (jCtx->OutBuf);
}


/*----------------------------------------------------------------------------
*Function: SsbSipJPEGGetConfig

*Parameters: 		type : config type to get
					*value : config value to get
*Return Value:		JPEG_ERRORTYPE
*Implementation Notes: return JPEG config value to user 
-----------------------------------------------------------------------------*/
JPEG_ERRORTYPE SsbSipJPEGGetConfig (JPEGConf type, INT32 *value)
{
	JPEG_ERRORTYPE result = JPEG_OK;

	switch(type){
		case JPEG_GET_DECODE_WIDTH: *value = (INT32)jCtx->decParam->width; break;
		case JPEG_GET_DECODE_HEIGHT: *value = (INT32)jCtx->decParam->height; break;
		case JPEG_GET_SAMPING_MODE: *value = (INT32)jCtx->decParam->sampleMode; break;
		default : printD("Invalid Config type\n"); result = JPEG_FAIL;
	}

	return result;
}

/*----------------------------------------------------------------------------
*Function: SsbSipJPEGSetConfig

*Parameters: 		type : config type to set
					*value : config value to set
*Return Value:		JPEG_ERRORTYPE
*Implementation Notes: set JPEG config value from user 
-----------------------------------------------------------------------------*/
JPEG_ERRORTYPE SsbSipJPEGSetConfig (JPEGConf type, INT32 value)
{
	JPEG_ERRORTYPE result = JPEG_OK;

	printD("API :: SsbSipJPEGSetConfig(%d : %d)\n", type, value);

	switch(type){
		case JPEG_SET_ENCODE_WIDTH: 
			{
				if(value < 0 || value > MAX_JPG_WIDTH){
					RETAILMSG(1, (TEXT("API :: Invalid width\r\n")));
					result = JPEG_FAIL;
				}else
					jCtx->encParam->width = value; 
				break;
			}
		case JPEG_SET_ENCODE_HEIGHT: 
			{
				if(value < 0 || value > MAX_JPG_HEIGHT){
					RETAILMSG(1, (TEXT("API :: Invalid height\r\n")));
					result = JPEG_FAIL;
				}else
					jCtx->encParam->height = value;
				break;
			}	
		case JPEG_SET_ENCODE_QUALITY:
			{
				if(value < JPG_QUALITY_LEVEL_1 || value > JPG_QUALITY_LEVEL_4){
					RETAILMSG(1, (TEXT("API :: Invalid Quality value\r\n")));
					result = JPEG_FAIL;
				}else
					jCtx->encParam->quality = value;
				break;
			}
		case JPEG_SET_ENCODE_THUMBNAIL: 
			{
				if((value != TRUE) && (value != FALSE)){
					RETAILMSG(1, (TEXT("API :: Invalid thumbnailFlag\r\n")));
					result = JPEG_FAIL;
				}else
					jCtx->thumbnailFlag = value;
				break;
			}
		case JPEG_SET_SAMPING_MODE: 
			{
				if(value != JPG_420 && value != JPG_422){
					RETAILMSG(1, (TEXT("API :: Invalid sampleMode\r\n")));
					result = JPEG_FAIL;
				}
				else{
					jCtx->encParam->sampleMode = value;
					jCtx->thumbEncParam->sampleMode = value;
				}
				break;
			}
		case JPEG_SET_THUMBNAIL_WIDTH: 
			{
				if(value < 0 || value > MAX_JPG_THUMBNAIL_WIDTH){
					RETAILMSG(1, (TEXT("API :: Invalid thumbWidth\r\n")));
					result = JPEG_FAIL;
				}else
					jCtx->thumbEncParam->width = value;
				break;
			}
		case JPEG_SET_THUMBNAIL_HEIGHT: 
			{
				if(value < 0 || value > MAX_JPG_THUMBNAIL_HEIGHT){
					RETAILMSG(1, (TEXT("API :: Invalid thumbHeight\r\n")));
					result = JPEG_FAIL;
				}else
					jCtx->thumbEncParam->height = value;
				break;
			}
		default : printD("Invalid Config type\n"); result = JPEG_FAIL;
	}
	return result;
}

/*----------------------------------------------------------------------------
*Function: SsbSipJPEGDecodeDeInit

*Parameters: 		*openHandle : openhandle from SsbSipJPEGDecodeInit
*Return Value:		JPEG_ERRORTYPE
*Implementation Notes: Deinitialize JPEG Decoder Device Driver 
-----------------------------------------------------------------------------*/
JPEG_ERRORTYPE SsbSipJPEGDecodeDeInit (void *openHandle)
{
	CloseHandle(openHandle);

	if(jCtx->decParam != NULL)
		free(jCtx->decParam);

	free(jCtx);

	return JPEG_OK;
}

/*----------------------------------------------------------------------------
*Function: SsbSipJPEGEncodeDeInit

*Parameters: 		*openHandle : openhandle from SsbSipJPEGEncodeInit
*Return Value:		True/False
*Implementation Notes: Deinitialize JPEG Encoder Device Driver 
-----------------------------------------------------------------------------*/
JPEG_ERRORTYPE SsbSipJPEGEncodeDeInit (void *openHandle)
{
	CloseHandle(openHandle);

	if(jCtx->encParam != NULL)
		free(jCtx->decParam);

	if(jCtx->thumbEncParam != NULL)
		free(jCtx->thumbEncParam);

	if(jCtx->ExifInfo != NULL)
		free(jCtx->ExifInfo);

	free(jCtx);
	return JPEG_OK;
}
/*----------------------------------------------------------------------------
*Function: SsbSipJPEGDisplay

*Parameters: 		*openHandle : openhandle from SsbSipJPEGEncodeInit
*Return Value:		True/False
*Implementation Notes: Deinitialize JPEG Encoder Device Driver 
-----------------------------------------------------------------------------*/
void *SsbSipJPEGGetDecodeOutPhyBuf(void *openHandle)
{
	HANDLE	hJpegDrv = INVALID_HANDLE_VALUE;
	char	*phy_addr_frame;

	hJpegDrv = DeviceIoControl(openHandle, IOCTL_JPG_GET_PHY_FRMBUF, NULL, 0, &phy_addr_frame, sizeof(phy_addr_frame), NULL, NULL);
	if(hJpegDrv == INVALID_HANDLE_VALUE){
			RETAILMSG(1, (TEXT("API :: IOCTL_JPG_GET_PHY_FRMBUF failed\r\n")));
			return NULL;
	}

	printD("phy_addr_frame : 0x%x\n", phy_addr_frame);
	return phy_addr_frame;
}

/*----------------------------------------------------------------------------
*Function: SsbSipJPEGGetRGBBuf

*Parameters: 		*openHandle : openhandle from SsbSipJPEGEncodeInit
*Return Value:		True/False
*Implementation Notes: Deinitialize JPEG Encoder Device Driver 
-----------------------------------------------------------------------------*/
void *SsbSipJPEGGetRGBBuf(void *openHandle, INT32 width, INT32 height)
{
	HANDLE	hJpegDrv = INVALID_HANDLE_VALUE;
	char	*addr_rgb;
	INT32	RGBSize;

	RGBSize = width*height*2;

⌨️ 快捷键说明

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