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来 ...
随机推荐
- python3.6连接oracle数据库
下载cx_Oracle模块模块: https://pypi.python.org/pypi/cx_Oracle/5.2.1#downloads 这里下载的是源码进行安装 [root@oracle or ...
- KnockoutJs学习笔记(九)
由于component binding部分的内容更为复杂一些,所以这部分我暂时跳过,先学习click binding部分. click binding不仅可以作用于button.input.a等元素, ...
- Jenkins 发布.NetCore 项目
安装最新Jenkins及安装好相关git插件 启动jenkins服务,访问8080端口 这里就发布一个IdentityServer4程序 配置相关参数 设置Git源码管理配置 构建执行window 批 ...
- P1387 最大正方形 图DP
题目描述 在一个n*m的只包含0和1的矩阵里找出一个不包含0的最大正方形,输出边长. 输入输出格式 输入格式: 输入文件第一行为两个整数n,m(1<=n,m<=100),接下来n行,每行m ...
- 010 innerHtml的使用
1.程序 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...
- python基础下的数据结构与算法之顺序表
一.什么是顺序表: 线性表的两种基本的实现模型: 1.将表中元素顺序地存放在一大块连续的存储区里,这样实现的表称为顺序表(或连续表).在这种实现中,元素间的顺序关系由它们的存储顺序自然表示. 2.将表 ...
- java中的二进制运算简单理解
package test9; public class StreamTest { public static void main(String[] args) { int a = 15;// 0b11 ...
- python中关于if-else使用性能的一点感悟
今天做leetcode第7题关于数字倒序的问题,分别使用如下程序:(72ms) class Solution: def reverse(self, x): """ :ty ...
- 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem A. Alien Visit 计算几何
Problem A. Alien Visit 题目连接: http://codeforces.com/gym/100714 Description Witness: "First, I sa ...
- tomcat开启SSL8443端口的方法
参考文献: http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html http://blog.sina.com.cn/s/blog_682b5aa1 ...