libjpeg的问题
游戏项目是基于cocos2d-x开发的,但线上发现一个bug就是玩家在设置完自定义头像后直接闪退。凡是在设置该玩家头像的地方,游戏就直接闪退。最终定位到的问题是图片数据源有问题,我的机器是win7,图片能预览,但同事xp系统该图片是无法预览的,默认的系统自带的图片查看工具也无法显示图片。

把图片拉到sublime text中,查看文件二进制,发现它并非一个完整的jpeg格式

没有jpeg格式的结束标识0xff 0xd9
我在windows下调试代码,发现是在CCImageCommon_cpp.h中的_initWithJpgData方法调用jpeg_finish_decompress函数时程序直接退出了
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)工具复制有问题的图片时, 也提示错误了

参考文章:
[2] JPEG File Layout and Format
解决方案可以参考这篇文章:libjpeg解压损坏文件时的错误处理
libjpeg的问题的更多相关文章
- libjpeg 编译makfile
一.准备 首先需要下载libjpeg库,网址在这里:http://www.ijg.org/ 如果不想编译就在这下载吧:http://pan.baidu.com/s/1hqeTDre 二.编译 1. 解 ...
- 编译libjpeg库
最近在写车牌识别软件,需要用到BMP转成JPG的功能,自然就想到借助libjpeg来实现 OS: win7 64位 编译器: VS2008 1. 下载源代码下载地址:http://www.ijg.or ...
- 嵌入式 linux 移植修改后的libjpeg 实现内存中解码
1.修改libjpeg源码,使之实现内存解码. 修改libjpeg中读取或者输出jpeg文件的函数接口文件jdatadst.c和jdatasrc.c见下面这篇帖子. http://blog.163.c ...
- libjpeg 交叉编译动态库和静态库
1.下载libjpeg库,解压之 得到了jpeg6b和libtool-2.2.4两个文件夹. 2.编译安装libtool工具. 这是配置libtool,这里需要注意:configure 参 ...
- linux x64下编译libjpeg,libpng,zlib
libJpeg编译: 下载libjpeg源码:http://www.ijg.org/,下载jpegsrc.v9a.tar.gz 解压源码,命令:tar -zxvf jpegsrc.v9a,源码文件夹为 ...
- imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 1 extraneous bytes be
imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 1 extraneous bytes be ...
- VS2010编译libjpeg
环境:win7旗舰版 x64 VS2010 下载源代码下载地址:http://www.ijg.org/,选择windows format file 解压源代码,修改源代码中jconfig.vc为jco ...
- 【转】VS2013编译libjpeg库
原文地址:http://blog.csdn.net/weixinhum/article/details/42718959 现在,很多图像处理工具和开源库都给出了图像解码的函数接口,然而有时这些接口并不 ...
- imod报错:error while loading shared libraries: libjpeg.so.62的解决办法
the file libjpeg.so.62(in /usr/lib/libjpeg.so.62)belongs to the package libjpeg62so try to reinstall ...
- <转>libjpeg解码内存中的jpeg数据
转自http://my.unix-center.net/~Simon_fu/?p=565 熟悉libjpeg的朋友都知道libjpeg是一个开源的库.Linux和Android都是用libjpeg来 ...
随机推荐
- 解决Eclipse启动报错【Failed to create the Java Virtual Machine】
电脑:2G内存,WIN7 32位. 启动adt-bundle-windows-x86-20140702\eclipse\eclipse.exe时,报错[Failed to create the Jav ...
- 主动学习——active learning
阅读目录 1. 写在前面 2. 什么是active learning? 3. active learning的基本思想 4. active learning与半监督学习的不同 5. 参考文献 1. ...
- P2782 友好城市
P2782 友好城市一道伪装得很好的dp,一开始没想出来,不相交就是所有的都在右边,也就是对于当前的城市i和它的友好城市的坐标都在城市j和它的友好城市的右边,这样就转化成了求最长上升子序列,f[i]表 ...
- 基于jquery的垂直滚动触发器,多参数可设置。
最近闲来无事,多封装些功能性组件.后期会有更多放出来,大家可以多关注一下. 先上参数: type:"show", 默认为“show”,“show”意为当能够在可 ...
- httpclient初步封装
Http通信方式:HttpURLConnection和HttpClient HttpURLConnection是java的标准类,什么都没封装,用起来太原始,不方便HttpClient就是一个增强版的 ...
- SQL2008配置管理工具服务显示远程过程调用失败
问题: 打开SQL2008配置管理工具,发现SQL服务名称里什么也没有,只有一个提示: 解决办法: 这是由于电脑中安装有Visual Stuido, 它内含一个本地SQL数据库服务:Microso ...
- python面向对象魔术方法补充
一.描述符 在 面向对象 编程中 定义一个(没有定义方法)类:class person , 在这个类里面,有name,age, heigth, weight,等等属性, 这个类就可以看作一个对 per ...
- 【BZOJ 4059】 (分治暴力|扫描线+线段树)
4059: [Cerc2012]Non-boring sequences Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 632 Solved: 22 ...
- luoguP4705 玩游戏 分治FFT
\[ \begin{aligned} Ans(k) &= \sum \limits_{i = 1}^n \sum \limits_{j = 1}^m \sum \limits_{t = 0}^ ...
- 8.5 正睿暑期集训营 Day2
目录 2018.8.5 正睿暑期集训营 Day2 总结 A.占领地区(前缀和) B.配对(组合) C 导数卷积(NTT) 考试代码 T1 T2 T3 2018.8.5 正睿暑期集训营 Day2 时间: ...