Definition in file jpeg_decoder.h.
Go to the source code of this file.
Functions | |
Bool | jpeg_lib_decode (int offset) |
void * | jpeg_lib_decode_ex (int offset, U16 *width, U16 *height) |
void | jpeg_lib_exit (void) |
Bool | jpeg_lib_init (void) |
Bool jpeg_lib_decode | ( | int | offset | ) |
Definition at line 293 of file EXAMPLE/jdatasrc.c.
References jpeg_lib::cinfo, jpeg_decompress_struct::dct_method, jpeg_decompress_struct::do_fancy_upsampling, jpeg_decompress_struct::image_height, jpeg_decompress_struct::image_width, JCS_RGB565, JDCT_FASTEST, jpeg_abort_decompress(), jpeg_finish_decompress(), JPEG_HEADER_OK, jpeg_lib_data, jpeg_out_buffer_pos, jpeg_read_header(), jpeg_read_scanlines(), jpeg_stdio_src(), max_lines, jpeg_decompress_struct::out_color_space, jpeg_decompress_struct::output_height, jpeg_lib::output_image, jpeg_decompress_struct::output_scanline, jpeg_decompress_struct::output_width, jpeg_decompress_struct::scale_denom, stream_close(), stream_open(), stream_seek(), and TRUE.
Referenced by jpeg_lib_decode_ex().
00294 { 00295 struct jpeg_decompress_struct *cinfo = (struct jpeg_decompress_struct *) jpeg_lib_data.cinfo; 00296 struct extended_error_mgr *jerr = (struct extended_error_mgr *) cinfo->err; 00297 uint16_t max_lines = 1; 00298 uint16_t scale_denom; 00299 uint16_t max_width, max_height; 00300 00301 max_width = cinfo->output_width; 00302 max_height = cinfo->output_height; 00303 00304 // set output image position for the JPEG library 00305 jpeg_out_buffer_pos = (uint16_t *) jpeg_lib_data.output_image; 00306 00307 //file_ptr = 0; 00308 stream_open(); // file_open(FOPEN_MODE_R); 00309 if(offset) 00310 stream_seek(offset); // file_seek(offset, FS_SEEK_SET); 00311 00312 // set file to read from 00313 jpeg_stdio_src(cinfo, 0); 00314 00315 /* Establish the setjmp return context for my_error_exit to use. */ 00316 if (setjmp(jerr->setjmp_buffer)) 00317 { 00318 /* If we get here, the JPEG code has signaled an error. 00319 * We need to clean up the JPEG object, close the input file, and return. 00320 */ 00321 jpeg_abort_decompress(cinfo); 00322 stream_close(); // file_close(); 00323 return false; 00324 } 00325 // read the file header 00326 if(JPEG_HEADER_OK != jpeg_read_header(cinfo, TRUE)) 00327 { 00328 jpeg_abort_decompress(cinfo); 00329 stream_close(); // file_close(); 00330 return false; 00331 } 00332 00333 // set decompression configuration 00334 scale_denom = 0; 00335 00336 // set correct scaling to fit the reserved space 00337 while(((cinfo->image_width >> scale_denom) > max_width) 00338 || ((cinfo->image_height >> scale_denom) > max_height)) 00339 { 00340 scale_denom++; 00341 } 00342 scale_denom = 1 << scale_denom; 00343 // any scaling above 1/8 is not possible 00344 if(scale_denom > 8) 00345 { 00346 stream_close(); // file_close(); 00347 return false; 00348 } 00349 00350 cinfo->scale_denom = scale_denom; 00351 00352 00353 cinfo->dct_method = JDCT_FASTEST; 00354 cinfo->do_fancy_upsampling = false; 00355 cinfo->out_color_space = JCS_RGB565; 00356 00357 // submit the requested decompression parameters 00358 // this call will also adjust invalid settings 00359 if( jpeg_start_decompress(cinfo) == false) 00360 { 00361 jpeg_abort_decompress(cinfo); 00362 stream_close(); // file_close(); 00363 return false; 00364 } 00365 00366 // read scanlines 00367 // 00368 while(cinfo->output_scanline < cinfo->output_height) 00369 { 00370 // get decoded scanlines 00371 jpeg_read_scanlines(cinfo, NULL, max_lines); 00372 } 00373 00374 jpeg_finish_decompress(cinfo); 00375 00376 stream_close(); // file_close(); 00377 return true; 00378 }
void* jpeg_lib_decode_ex | ( | int | offset, | |
U16 * | width, | |||
U16 * | height | |||
) |
Definition at line 276 of file EXAMPLE/jdatasrc.c.
References jpeg_lib::cinfo, jpeg_lib_data, jpeg_lib_decode(), jpeg_decompress_struct::output_height, jpeg_lib::output_image, and jpeg_decompress_struct::output_width.
Referenced by main().
00277 { 00278 struct jpeg_decompress_struct *cinfo = (struct jpeg_decompress_struct *) 00279 jpeg_lib_data.cinfo; 00280 00281 cinfo->output_width = *width; 00282 cinfo->output_height = *height; 00283 00284 if (!jpeg_lib_decode(offset)) 00285 return NULL; 00286 00287 *width = cinfo->output_width; 00288 *height = cinfo->output_height; 00289 00290 return (void *) jpeg_lib_data.output_image; 00291 }
void jpeg_lib_exit | ( | void | ) |
Definition at line 417 of file EXAMPLE/jdatasrc.c.
References jpeg_lib::cinfo, free(), jpeg_destroy_decompress(), jpeg_lib_data, and jpeg_lib::output_image.
Referenced by main().
00418 { 00419 if(jpeg_lib_data.output_image) 00420 free(jpeg_lib_data.output_image); 00421 00422 if(jpeg_lib_data.cinfo->err) 00423 free(jpeg_lib_data.cinfo->err); 00424 00425 if(jpeg_lib_data.cinfo) 00426 { 00427 // release internal memory 00428 jpeg_destroy_decompress(jpeg_lib_data.cinfo); 00429 free(jpeg_lib_data.cinfo); 00430 } 00431 }
Bool jpeg_lib_init | ( | void | ) |
Definition at line 382 of file EXAMPLE/jdatasrc.c.
References jpeg_lib::cinfo, extended_error_exit(), free(), jpeg_create_decompress, JPEG_DECODER_MAX_IMAGE_HEIGHT, JPEG_DECODER_MAX_IMAGE_WIDTH, JPEG_DECODER_PIXEL_SIZE_IN_BYTES, jpeg_lib_data, jpeg_std_error(), malloc(), and jpeg_lib::output_image.
Referenced by main().
00383 { 00384 // allocate the decompression structure 00385 jpeg_lib_data.cinfo = malloc(sizeof(struct jpeg_decompress_struct )); 00386 00387 if(!jpeg_lib_data.cinfo) 00388 return false; 00389 00390 jpeg_lib_data.cinfo->err = (struct jpeg_error_mgr *) malloc(sizeof(struct extended_error_mgr)); 00391 00392 if(!jpeg_lib_data.cinfo->err) 00393 { 00394 free(jpeg_lib_data.cinfo); 00395 return false; 00396 } 00397 // allocate the buffer for the decompressed image 00398 jpeg_lib_data.output_image = malloc( 00399 JPEG_DECODER_MAX_IMAGE_WIDTH * JPEG_DECODER_MAX_IMAGE_HEIGHT * JPEG_DECODER_PIXEL_SIZE_IN_BYTES); 00400 00401 if(!jpeg_lib_data.output_image) 00402 { 00403 free(jpeg_lib_data.cinfo->err); 00404 free(jpeg_lib_data.cinfo); 00405 return false; 00406 } 00407 // initialize error handler 00408 jpeg_std_error(jpeg_lib_data.cinfo->err); 00409 jpeg_lib_data.cinfo->err->error_exit = extended_error_exit; 00410 00411 // initialize the decompression struct 00412 jpeg_create_decompress(jpeg_lib_data.cinfo); 00413 00414 return true; 00415 }