我试图使用ijg的libjpeg将RGB图像压缩成JPEG。最后,我们的想法是使用图像传感器获取图像,并在ARM Cortex M3控制器上将数据压缩为JPEG;然而,为了测试目的,我使用了使用GIMP转换成RGB .data文件的BMP文件。
我已经能够成功地使用控制器和libjpeg将RGB数据压缩成SD卡上的JPEG图像,但是我使用这种方法在图像上看到了一条扭曲的线条,我不知道是什么原因造成的,以及如何修复它。
以下是压缩的JPEG图像:http://i.imgur.com/kFBEhEs.jpg
以下是BMP图像的来源:http://i.imgur.com/jenHG0b.png
下面是相关的代码片段:
static uint8_t* _pucImageSrc ;
static uint8_t* _pucImageDst ;
static uint8_t*_pucCapturedBuf;
uint8_t _compress_image_jpg(SJPEGTest *pImage, sdCardDataHandler *datahandler){
SJpegData sJpegData;
_pucImageDst=malloc(datahandler->sourceSize);
_pucCapturedBuf = datahandler->sourcePtr;
pImage->dwTimeC=getTicks();
JpegData_Init( &sJpegData ) ;
JpegData_SetSource( &sJpegData, _pucCapturedBuf, datahandler->sourceSize) ;
JpegData_SetDestination( &sJpegData, _pucImageDst, datahandler->sourceSize ) ;
JpegData_SetDimensions( &sJpegData, 512, 384, 3 ) ;
JpegData_SetParameters( &sJpegData, 25, JPG_DATA_RGB, JPG_METHOD_IFAST ) ;
if ( ijg_compress( &sJpegData ) == 0 ){
pImage->dwTimeC=1+getTicks()-pImage->dwTimeC;
pImage->dwFinalLength=sJpegData.dwDstLength;
pImage->dwTimeD=getTicks();
} else {
return JPEG_CONVERSION_ERRORED;
}
datahandler->destSize = sJpegData.dwDstLength;
datahandler->destPtr = _pucImageDst;
return JPEG_CONVERSION_COMPLETE;
}
extern uint32_t ijg_compress( SJpegData* pData ){
struct jpeg_compress_struct cinfo ;
struct my_error_mgr jerr ;
JSAMPROW row_pointer ; /* pointer to a single row */
assert( pData != NULL ) ;
cinfo.err = jpeg_std_error( &jerr.pub ) ;
if(setjmp(jerr.setjmp_buffer)){
jpeg_destroy_compress(&cinfo);
return 1;
}
jpeg_create_compress( &cinfo ) ;
jpeg_mem_dest( &cinfo, &(pData->pucDst), (unsigned long*)&(pData->dwDstLength) ) ;
cinfo.image_width = pData->dwWidth ;
cinfo.image_height = pData->dwHeight ;
cinfo.input_components = pData->dwBPP ;
cinfo.in_color_space = pData->eInput ;
jpeg_set_defaults( &cinfo ) ;
cinfo.dct_method = pData->eMethod ;
jpeg_set_quality( &cinfo, pData->dwQuality, true ) ;
jpeg_start_compress( &cinfo, true ) ;
while ( cinfo.next_scanline < cinfo.image_height )
{
row_pointer = (JSAMPROW) &pData->pucSrc[cinfo.next_scanline*cinfo.image_width*cinfo.input_components] ;
jpeg_write_scanlines( &cinfo, &row_pointer, 1 ) ;
}
jpeg_finish_compress( &cinfo ) ;
jpeg_destroy_compress(&cinfo);
return 0 ;
}发布于 2017-10-11 20:21:47
在不得不将libjpeg移植到一个没有安装特定库的新控制器之后,我能够确定这个问题。有些内存没有被正确释放--这是因为我曾经用membag_free()替换了空闲()调用,然后返回到空闲(),但缺少了一个调用。哈!谢谢你的帮助!
https://stackoverflow.com/questions/45983535
复制相似问题