fixed a problem in convert.c when multiple comments

This commit is contained in:
Antonin Descampe 2006-01-25 15:45:01 +00:00
parent ec2b3b3b3f
commit 2f75846baf
2 changed files with 28 additions and 69 deletions

View File

@ -6,6 +6,7 @@ What's New for OpenJPEG
+ : added + : added
January 25, 2006 January 25, 2006
* [Antonin Descampe] fixed a problem in convert.c when multiple comments
+ [Antonin Descampe] added cmake files to the project + [Antonin Descampe] added cmake files to the project
! [Antonin Descampe] fix.c : replaced "WIN32" by "_MSC_VER" for int64 ! [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 + [Antonin Descampe] added "OPJ_EXPORT" in openjpeg.h to generate shared lib with win32

View File

@ -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_cmptparm_t cmptparm[3]; /* maximum of 3 components */
opj_image_t * image = NULL; opj_image_t * image = NULL;
char value; char value;
char comment[256];
f = fopen(filename, "rb"); f = fopen(filename, "rb");
if (!f) { if (!f) {
fprintf(stderr, "\033[0;33mFailed to open %s for reading !!\033[0;39m\n", filename); 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; return 0;
value = fgetc(f); value = fgetc(f);
switch(value) { switch(value) {
case '2': /* greyscale image type */ case '2': /* greyscale image type */
case '5': case '5':
{ numcomps = 1;
numcomps = 1; color_space = CLRSPC_GRAY;
color_space = CLRSPC_GRAY; break;
fgetc(f); case '3': /* RGB image type */
case '6':
if (fgetc(f) == '#') { numcomps = 3;
/* skip comments */ color_space = CLRSPC_SRGB;
fseek(f, 0, SEEK_SET); break;
if (value == '2') {
fscanf(f, "P2\n"); default:
} else if (value == '5') { fclose(f);
fscanf(f, "P5\n"); return NULL;
}
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); /* <cr><lf> */
} }
break;
fgetc(f);
case '3': /* RGB image type */
case '6': /* skip comments */
{ while(fgetc(f) == '#') while(fgetc(f) != '\n');
numcomps = 3;
color_space = CLRSPC_SRGB; fseek(f, -1, SEEK_CUR);
fscanf(f, "%d %d\n255", &w, &h);
fgetc(f); fgetc(f); /* <cr><lf> */
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); /* <cr><lf> */
}
break;
default:
fclose(f);
return NULL;
}
/* initialize image components */ /* initialize image components */
memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t)); memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t));
for(i = 0; i < numcomps; i++) { for(i = 0; i < numcomps; i++) {