📄 jpgapi.c
字号:
dstBuf[iXdst++] = srcBuf[iXsrc++];
dstBuf[iXdst++] = srcBuf[iXsrc++];
dstBuf[iXdst++] = srcBuf[iXsrc++];
dstBuf[iXdst++] = srcBuf[iXsrc++];
}else iXsrc++;
}
}
}
}
/*----------------------------------------------------------------------------
*Function: SsbSipJPEGEncodeExe
*Parameters: *openHandle : openhandle from SsbSipJPEGEncodeInit
*Exif : Exif file parameter
*Return Value: JPEG_ERRORTYPE
*Implementation Notes: Encode JPEG file
-----------------------------------------------------------------------------*/
JPEG_ERRORTYPE SsbSipJPEGEncodeExe(void *openHandle, ExifFileInfo *Exif)
{
char *outBuf = NULL;
char *ExifBuf;
UINT ExifLen;
UINT bufSize;
JPEG_ERRORTYPE result;
int ret;
// check MUC validation with width & hegiht & sampling mode
if((result = MCUCheck(jCtx->encParam->sampleMode, jCtx->encParam->width, jCtx->encParam->height)) != JPEG_OK){
RETAILMSG(1, (TEXT("API :: width/height doesn't match with MCU\r\n")));
return JPEG_FAIL;
}
// 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -