int i, j,k;
ICON_INFO *info;
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE * input_file;
JDIMENSION num_scanlines;
int row_stride;
JSAMPARRAY buffer;
unsigned char * dst_buffer;
unsigned short *dst;
unsigned char * src;
/*jpeg decode for logo*/
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
/* init icon */
info = icon_info;
j = sizeof(icon_info)/sizeof(icon_info[0]);
printf("=======j=%d=====\n",j);
for (i = 0; i < j; i++, info++)
{
printf("=======i=%d=====\n",i);
printf(info->name);
if ((input_file = fopen(info->name, "rb")) == NULL) {
fprintf(stderr, "can't open %s\n",info->name);
exit(EXIT_FAILURE);
}
/* Specify data source for decompression */
jpeg_stdio_src(&cinfo, input_file);
printf("************1\n");
/* Read file header, set default decompression parameters */
(void) jpeg_read_header(&cinfo, TRUE);
printf("************2\n");
/* Start decompressor */
(void) jpeg_start_decompress(&cinfo);
printf("************3\n");
printf("cinfo.output_width:%d\n",cinfo.output_width);
printf("cinfo.output_height:%d\n",cinfo.output_height);
printf("cinfo.output_components:%d\n",cinfo.output_components);
dst_buffer = malloc(cinfo.output_width*cinfo.output_height*(cinfo.output_components + 1));
if(NULL == dst_buffer) {
printf("failed to malloc for icon_logo.jpg \n");
return -1;
}
dst = (unsigned short *)dst_buffer;
icon_tbl[i] = (int)dst_buffer;
row_stride = cinfo.output_width * cinfo.output_components;
buffer = (*cinfo.mem->alloc_sarray)
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
/* Process data */
while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg_read_scanlines(&cinfo, buffer, 1);
//argb8888
src = (unsigned char *)buffer[0];
for(k=0; k<cinfo.output_width; k++) {
*dst_buffer = *(src + 2);
*(dst_buffer + 1) = *(src + 1);
*(dst_buffer + 2) = *src;
src += 3;
dst_buffer +=3;
*dst_buffer++ = 0xE0;
}
#endif
}
/*end jpeg decode */
}
(void) jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
出错是在