Bug fixed in pgx-file reading

This commit is contained in:
Antonin Descampe 2004-07-30 09:22:22 +00:00
parent 9fa68ca811
commit 2e2ba14c53
1 changed files with 96 additions and 80 deletions

View File

@ -556,8 +556,10 @@ int pgxtoimage(char *filename, j2k_image_t * img, int tdy,
FILE *f;
int w, h, prec;
int i, compno, bandno;
char str[256], endian[16];
char sign;
char str[256];
char endian1,endian2,sign;
char signtmp[32];
char temp[32];
int bigendian;
j2k_comp_t *comp;
@ -569,19 +571,36 @@ int pgxtoimage(char *filename, j2k_image_t * img, int tdy,
char tmp[16];
int max = 0;
int Y1;
comp = &img->comps[compno];
sprintf(str, "%s", filename);
f = fopen(str, "rb");
if (!f) {
fprintf(stderr, "Failed to open %s for reading !\n", str);
return 0;
}
if (fscanf(f, "PG %s %c %d %d %d", endian, &sign, &prec, &w, &h) == 5) {
fseek(f, 0, SEEK_SET);
fscanf(f, "PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d",temp,&endian1,&endian2,signtmp,&prec,temp,&w,temp,&h);
i=0;
sign='+';
while (signtmp[i]!='\0') {
if (signtmp[i]=='-') sign='-';
i++;
}
fgetc(f);
if (!strcmp(endian, "ML"))
if (endian1=='M' && endian2=='L')
bigendian = 1;
else
else if (endian2=='M' && endian1=='L')
bigendian = 0;
else {
fprintf(stderr, "Bad pgx header, please check input file\n", str);
return 0;
}
if (compno == 0) {
img->x0 = Dim[0];
img->y0 = Dim[1];
@ -654,9 +673,6 @@ int pgxtoimage(char *filename, j2k_image_t * img, int tdy,
max = v;
fprintf(src, "%d ", v);
}
} else {
return 0;
}
fclose(f);
fclose(src);
comp->bpp = int_floorlog2(max) + 1;