日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

libjpeg的问题

發(fā)布時(shí)間:2025/7/14 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 libjpeg的问题 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

游戲項(xiàng)目是基于cocos2d-x開(kāi)發(fā)的,但線上發(fā)現(xiàn)一個(gè)bug就是玩家在設(shè)置完自定義頭像后直接閃退。凡是在設(shè)置該玩家頭像的地方,游戲就直接閃退。最終定位到的問(wèn)題是圖片數(shù)據(jù)源有問(wèn)題,我的機(jī)器是win7,圖片能預(yù)覽,但同事xp系統(tǒng)該圖片是無(wú)法預(yù)覽的,默認(rèn)的系統(tǒng)自帶的圖片查看工具也無(wú)法顯示圖片。

把圖片拉到sublime text中,查看文件二進(jìn)制,發(fā)現(xiàn)它并非一個(gè)完整的jpeg格式

沒(méi)有jpeg格式的結(jié)束標(biāo)識(shí)0xff? 0xd9

?

我在windows下調(diào)試代碼,發(fā)現(xiàn)是在CCImageCommon_cpp.h中的_initWithJpgData方法調(diào)用jpeg_finish_decompress函數(shù)時(shí)程序直接退出了

bool CCImage::_initWithJpgData(void * data, int nSize, bool bNeedDecode /*= false*/)
{
??? int nRandomBytes = 0;
??? if (bNeedDecode) nRandomBytes = RANDOM_BYTES;

??? if (bNeedDecode)
??? {
??????? data = (unsigned?char *)data + nRandomBytes;
??????? nSize = nSize - nRandomBytes;
??? }

??? /* these are standard libjpeg structures for reading(decompression) */
??? struct jpeg_decompress_struct cinfo;
??? struct jpeg_error_mgr jerr;
??? /* libjpeg data structure for storing one row, that is, scanline of an image */
??? JSAMPROW row_pointer[1] = {0};
??? unsigned?long location = 0;
??? unsigned?int i = 0;

??? bool bRet = false;
??? do?
??? {
??????? /* here we set up the standard libjpeg error handler */
??????? cinfo.err = jpeg_std_error( &jerr );

??????? /* setup decompression process and source, then read JPEG header */
??????? jpeg_create_decompress( &cinfo );

??????? jpeg_mem_src( &cinfo, (unsigned?char *) data, nSize );

??????? /* reading the image header which contains image information */
??????? jpeg_read_header( &cinfo, true );

??????? // we only support RGB or grayscale
??????? if (cinfo.jpeg_color_space != JCS_RGB)
??????? {
??????????? if (cinfo.jpeg_color_space == JCS_GRAYSCALE || cinfo.jpeg_color_space == JCS_YCbCr)
??????????? {
??????????????? cinfo.out_color_space = JCS_RGB;
??????????? }
??????? }
??????? else
??????? {
??????????? break;
??????? }

??????? /* Start decompression jpeg here */
??????? jpeg_start_decompress( &cinfo );

??????? /* init image info */
??????? m_nWidth? = (short)(cinfo.image_width);
??????? m_nHeight = (short)(cinfo.image_height);
??????? m_bHasAlpha = false;
??????? m_bPreMulti = false;
??????? m_nBitsPerComponent = 8;
??????? row_pointer[0] = new?unsigned?char[cinfo.output_width*cinfo.output_components];
??????? CC_BREAK_IF(! row_pointer[0]);

??????? m_pData = new?unsigned?char[cinfo.output_width*cinfo.output_height*cinfo.output_components];
??????? CC_BREAK_IF(! m_pData);

??????? /* now actually read the jpeg into the raw buffer */
??????? /* read one scan line at a time */
??????? while( cinfo.output_scanline < cinfo.image_height )
??????? {
??????????? jpeg_read_scanlines( &cinfo, row_pointer, 1 );
??????????? for( i=0; i<cinfo.image_width*cinfo.output_components;i++)
??????????? {
??????????????? m_pData[location++] = row_pointer[0][i];
??????????? }
??????? }

??????? jpeg_finish_decompress( &cinfo );
??????? jpeg_destroy_decompress( &cinfo );
??????? /* wrap up decompression, destroy objects, free pointers and close open files */???????
??????? bRet = true;
??? } while (0);

??? CC_SAFE_DELETE_ARRAY(row_pointer[0]);
??? return bRet;
}

后面我用jpegtran(https://github.com/imagemin/jpegtran-bin)工具復(fù)制有問(wèn)題的圖片時(shí), 也提示錯(cuò)誤了

?

參考文章:

[1] 小議libjpeg解壓損壞文件時(shí)的錯(cuò)誤處理

[2] JPEG File Layout and Format

解決方案可以參考這篇文章:libjpeg解壓損壞文件時(shí)的錯(cuò)誤處理

轉(zhuǎn)載于:https://www.cnblogs.com/meteoric_cry/p/3998425.html

總結(jié)

以上是生活随笔為你收集整理的libjpeg的问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。