Changeset 3165 for libpipi/trunk


Ignore:
Timestamp:
Oct 31, 2008, 4:24:27 PM (12 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Added setjmp/longjmp support to jpeg loader.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/codec/modular/jpeg.c

    r3088 r3165  
    1919
    2020#include "../modular.h"
     21#include <setjmp.h>
    2122
    2223static int pipi_free_jpeg(pipi_image_t *img);
    2324
    2425
     26
     27
     28struct my_error_mgr {
     29    struct jpeg_error_mgr pub;
     30    jmp_buf setjmp_buffer;
     31};
     32
     33typedef struct my_error_mgr * my_error_ptr;
     34
    2535static void format_msg(j_common_ptr cinfo, char *buf)
    2636{
     
    3141static void error_msg(j_common_ptr cinfo)
    3242{
     43    my_error_ptr myerr = (my_error_ptr) cinfo->err;
    3344    cinfo->client_data = (void*)0x1;
     45    longjmp(myerr->setjmp_buffer, 1);
    3446}
    3547static void output_msg(j_common_ptr cinfo)
     
    4052{
    4153    struct jpeg_decompress_struct cinfo;
    42     struct jpeg_error_mgr jerr;
     54    struct my_error_mgr jerr;
    4355    unsigned char *image = NULL, *scanline = NULL;
    4456    pipi_image_t *img = NULL;
     
    4860    if(!fp) goto end;
    4961
    50     /* Set callbacks */
    51     cinfo.err = jpeg_std_error(&jerr);
    52     jerr.error_exit = error_msg;
    53     jerr.emit_message = emit_msg;
    54     jerr.output_message = output_msg;
    55     jerr.format_message = format_msg;
     62
     63    if (setjmp(jerr.setjmp_buffer)) {
     64        goto end;
     65    }
     66    cinfo.err = jpeg_std_error(&jerr.pub);
     67    jerr.pub.error_exit = error_msg;
     68    jerr.pub.emit_message = emit_msg;
     69    jerr.pub.output_message = output_msg;
     70    jerr.pub.format_message = format_msg;
    5671
    5772    /* Initialize libjpeg */
     
    125140
    126141    struct jpeg_compress_struct cinfo;
    127     struct jpeg_error_mgr jerr;
     142    struct my_error_mgr jerr;
    128143    unsigned char *data = NULL;
    129144    unsigned char *line = NULL;
     
    145160        return 0;
    146161    }
    147 
    148     jerr.error_exit = error_msg;
    149     jerr.emit_message = emit_msg;
    150     jerr.output_message = output_msg;
    151 
    152     cinfo.err = jpeg_std_error(&(jerr));
     162   
     163    if (setjmp(jerr.setjmp_buffer)) {
     164        goto end;
     165    }
     166   
     167    jerr.pub.error_exit = error_msg;
     168    jerr.pub.emit_message = emit_msg;
     169    jerr.pub.output_message = output_msg;
     170
     171    cinfo.err = jpeg_std_error(&(jerr.pub));
    153172
    154173    jpeg_create_compress(&cinfo);
     
    182201
    183202    jpeg_finish_compress(&cinfo);
     203end:
    184204    jpeg_destroy_compress(&cinfo);
    185205    free(line);
Note: See TracChangeset for help on using the changeset viewer.