From 2f75846baf50a6b6d34b69c34c095a3b8414ad43 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Wed, 25 Jan 2006 15:45:01 +0000 Subject: [PATCH] fixed a problem in convert.c when multiple comments --- ChangeLog | 1 + codec/convert.c | 96 ++++++++++++++----------------------------------- 2 files changed, 28 insertions(+), 69 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7cf68883..02dd7de8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ What's New for OpenJPEG + : added January 25, 2006 +* [Antonin Descampe] fixed a problem in convert.c when multiple comments + [Antonin Descampe] added cmake files to the project ! [Antonin Descampe] fix.c : replaced "WIN32" by "_MSC_VER" for int64 + [Antonin Descampe] added "OPJ_EXPORT" in openjpeg.h to generate shared lib with win32 diff --git a/codec/convert.c b/codec/convert.c index 82e1da67..ae46390f 100644 --- a/codec/convert.c +++ b/codec/convert.c @@ -844,8 +844,7 @@ opj_image_t* pnmtoimage(char *filename, opj_cparameters_t *parameters) { opj_image_cmptparm_t cmptparm[3]; /* maximum of 3 components */ opj_image_t * image = NULL; char value; - char comment[256]; - + f = fopen(filename, "rb"); if (!f) { fprintf(stderr, "\033[0;33mFailed to open %s for reading !!\033[0;39m\n", filename); @@ -856,74 +855,33 @@ opj_image_t* pnmtoimage(char *filename, opj_cparameters_t *parameters) { return 0; value = fgetc(f); - switch(value) { - case '2': /* greyscale image type */ - case '5': - { - numcomps = 1; - color_space = CLRSPC_GRAY; - - fgetc(f); - - if (fgetc(f) == '#') { - /* skip comments */ - fseek(f, 0, SEEK_SET); - if (value == '2') { - fscanf(f, "P2\n"); - } else if (value == '5') { - fscanf(f, "P5\n"); - } - fgets(comment, 256, f); - fscanf(f, "%d %d\n255", &w, &h); - } else { - fseek(f, 0, SEEK_SET); - if (value == '2') { - fscanf(f, "P2\n%d %d\n255", &w, &h); - } else if (value == '5') { - fscanf(f, "P5\n%d %d\n255", &w, &h); - } - } - - fgetc(f); /* */ + switch(value) { + case '2': /* greyscale image type */ + case '5': + numcomps = 1; + color_space = CLRSPC_GRAY; + break; + + case '3': /* RGB image type */ + case '6': + numcomps = 3; + color_space = CLRSPC_SRGB; + break; + + default: + fclose(f); + return NULL; } - break; - - case '3': /* RGB image type */ - case '6': - { - numcomps = 3; - color_space = CLRSPC_SRGB; - - fgetc(f); - - if (fgetc(f) == '#') { - /* skip comments */ - fseek(f, 0, SEEK_SET); - if (value == '3') { - fscanf(f, "P3\n"); - } else if (value == '6') { - fscanf(f, "P6\n"); - } - fgets(comment, 256, f); - fscanf(f, "%d %d\n255", &w, &h); - } else { - fseek(f, 0, SEEK_SET); - if (value == '3') { - fscanf(f, "P3\n%d %d\n255", &w, &h); - } else if (value == '6') { - fscanf(f, "P6\n%d %d\n255", &w, &h); - } - } - - fgetc(f); /* */ - } - break; - - default: - fclose(f); - return NULL; - } - + + fgetc(f); + + /* skip comments */ + while(fgetc(f) == '#') while(fgetc(f) != '\n'); + + fseek(f, -1, SEEK_CUR); + fscanf(f, "%d %d\n255", &w, &h); + fgetc(f); /* */ + /* initialize image components */ memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t)); for(i = 0; i < numcomps; i++) {