Linux下jpeg解码方法
2011-01-06 22:47
357 查看
if ((infile = fopen(jpg_filename, "rb")) == NULL)
{
fprintf(stderr, "open %s failed/n", jpg_filename);
return(-1);
}
/*
init jpeg decompress object error handler
*/
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
/*
* bind jpeg decompress object to infile
*/
jpeg_stdio_src(&cinfo, infile);
/*
* read jpeg header
*/
jpeg_read_header(&cinfo, TRUE);
/*
* decompress process.
* note: after jpeg_start_decompress() is called
* the dimension infomation will be known,
* so allocate memory buffer for scanline immediately
*/
jpeg_start_decompress(&cinfo);
if ((cinfo.output_width > 320) ||
(cinfo.output_height > 240)) {
printf("too large JPEG file,cannot display/n");
return (-1);
}
buffer = (unsigned char *) malloc(cinfo.output_height * cinfo.output_width * cinfo.output_components);
buffer_tmp = buffer;
y = 0;
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, &buffer_tmp, 1);
buffer_tmp += cinfo.output_width *cinfo.output_components;
// next scanlin
//printf("read %d/n",y++);
}
/*
* finish decompress, destroy decompress object
*/
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
/*
* release memory buffer
*/
//free(buffer);
/*
* close jpeg inputing file
*/
fclose(infile);
return buffer;
{
fprintf(stderr, "open %s failed/n", jpg_filename);
return(-1);
}
/*
init jpeg decompress object error handler
*/
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
/*
* bind jpeg decompress object to infile
*/
jpeg_stdio_src(&cinfo, infile);
/*
* read jpeg header
*/
jpeg_read_header(&cinfo, TRUE);
/*
* decompress process.
* note: after jpeg_start_decompress() is called
* the dimension infomation will be known,
* so allocate memory buffer for scanline immediately
*/
jpeg_start_decompress(&cinfo);
if ((cinfo.output_width > 320) ||
(cinfo.output_height > 240)) {
printf("too large JPEG file,cannot display/n");
return (-1);
}
buffer = (unsigned char *) malloc(cinfo.output_height * cinfo.output_width * cinfo.output_components);
buffer_tmp = buffer;
y = 0;
while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, &buffer_tmp, 1);
buffer_tmp += cinfo.output_width *cinfo.output_components;
// next scanlin
//printf("read %d/n",y++);
}
/*
* finish decompress, destroy decompress object
*/
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
/*
* release memory buffer
*/
//free(buffer);
/*
* close jpeg inputing file
*/
fclose(infile);
return buffer;
相关文章推荐
- 【Linux开发】为qt-embedded添加jpeg库的交叉编译方法for arm
- 【Linux】 ubuntu 12.04 iNode Client找不到库libjpeg和libtiff的解决方法
- Linux下安装配置apache,mysql,php并支持gd,jpeg,png,freetype的方法
- 【Linux】 ubuntu 12.04 iNode Client找不到库libjpeg和libtiff的解决方法
- 嵌入式 linux 移植修改后的libjpeg 实现内存中解码
- linux下的jpeg解码库使用
- 在终端下正确关闭Linux计算机的方法介绍
- Linux下tar.xz结尾的文件的解压方法
- 成为Linux内核高手的四个方法
- Linux 技巧:让进程在后台可靠运行的几种方法
- Linux下掛載硬盤的方法
- linux查看分区命令和根分区扩容方法
- Linux系统下解压缩*.tar.xz方法
- linux下运行Qt出现cannot find -lGL和collect2: ld returned 1 exit status解决方法
- Linux启动网卡时出现RTNETLINK answers: File exists错误解决方法
- fackbook的Fresco的多种图片加载方法以及解码过程
- 用vi在linux下查看16进制文件的方法
- 关于linux服务的管理方法
- 【Linux学习】linux下 各种解压文件使用方法
- Symbian学习笔记(5):加载JPEG图像的方法