correct some warnings detected under unix platform

This commit is contained in:
Mickael Savinaud 2011-07-27 16:37:57 +00:00
parent f88a57e5d7
commit c2b0a8101b
7 changed files with 296 additions and 169 deletions

View File

@ -7,6 +7,7 @@ What's New for OpenJPEG
July 27, 2011
! [mickael] added new decoding/dump tests based on data found in input/nonregresion repository (remove JPEG2000_CONFORMANCE_DATA_ROOT variable, add REF_DECODER_BIN_PATH variable for the encoder test suite). Remove definitively old tests.
! [mickael] correct some warnings detected under unix platform
July 26, 2011
! [mickael] delete double semi-colon at end of line which generate crash on win platform

View File

@ -102,7 +102,11 @@ int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
return 0;
// Read TGA header
fread((unsigned char*)&tga, sizeof(tga_header), 1, fp);
if ( fread((unsigned char*)&tga, sizeof(tga_header), 1, fp) != 1 )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0 ;
}
*bits_per_pixel = tga.pixel_depth;
@ -113,7 +117,12 @@ int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
if (tga.id_length)
{
unsigned char *id = (unsigned char *) malloc(tga.id_length);
fread(id, tga.id_length, 1, fp);
if ( !fread(id, tga.id_length, 1, fp) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
free(id);
return 0 ;
}
free(id);
}
@ -246,9 +255,25 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
for (x=0;x<image_width;x++)
{
unsigned char r,g,b;
fread(&b, 1, 1, f);
fread(&g, 1, 1, f);
fread(&r, 1, 1, f);
if( !fread(&b, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
return NULL;
}
if ( !fread(&g, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
return NULL;
}
if ( !fread(&r, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
return NULL;
}
image->comps[0].data[index]=r;
image->comps[1].data[index]=g;
@ -261,10 +286,30 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
for (x=0;x<image_width;x++)
{
unsigned char r,g,b,a;
fread(&b, 1, 1, f);
fread(&g, 1, 1, f);
fread(&r, 1, 1, f);
fread(&a, 1, 1, f);
if ( !fread(&b, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
return NULL;
}
if ( !fread(&g, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
return NULL;
}
if ( !fread(&r, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
return NULL;
}
if ( !fread(&a, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
return NULL;
}
image->comps[0].data[index]=r;
image->comps[1].data[index]=g;
@ -408,10 +453,8 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
unsigned int j, PAD = 0;
int x, y, index;
int gray_scale = 1, not_end_file = 1;
int gray_scale = 1;
int has_color;
unsigned int line = 0, col = 0;
unsigned char v, v2;
DWORD W, H;
IN = fopen(filename, "rb");
@ -558,7 +601,13 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
RGB = (unsigned char *)
malloc((3 * W + PAD) * H * sizeof(unsigned char));
fread(RGB, sizeof(unsigned char), (3 * W + PAD) * H, IN);
if ( fread(RGB, sizeof(unsigned char), (3 * W + PAD) * H, IN) != (3 * W + PAD) * H )
{
free(RGB);
opj_image_destroy(image);
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return NULL;
}
index = 0;
@ -641,7 +690,16 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
RGB = (unsigned char *) malloc(W * H * sizeof(unsigned char));
fread(RGB, sizeof(unsigned char), W * H, IN);
if ( fread(RGB, sizeof(unsigned char), W * H, IN) != W * H )
{
free(table_R);
free(table_G);
free(table_B);
free(RGB);
opj_image_destroy(image);
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return NULL;
}
if (gray_scale)
{
index = 0;
@ -682,14 +740,15 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
if (Info_h.biBitCount == 8 && Info_h.biCompression == 1)//RLE8
{
unsigned char *pix, *beyond;
unsigned int *gray, *red, *green, *blue;
int *gray, *red, *green, *blue;
unsigned int x, y, max;
int i, c, c1;
unsigned char uc;
if(Info_h.biClrUsed == 0) Info_h.biClrUsed = 256;
else
if(Info_h.biClrUsed > 256) Info_h.biClrUsed = 256;
if (Info_h.biClrUsed == 0)
Info_h.biClrUsed = 256;
else if (Info_h.biClrUsed > 256)
Info_h.biClrUsed = 256;
table_R = (unsigned char *) malloc(256 * sizeof(unsigned char));
table_G = (unsigned char *) malloc(256 * sizeof(unsigned char));
@ -702,17 +761,17 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
table_G[j] = getc(IN);
table_R[j] = getc(IN);
getc(IN);
has_color +=
!(table_R[j] == table_G[j] && table_R[j] == table_B[j]);
has_color += !(table_R[j] == table_G[j] && table_R[j] == table_B[j]);
}
if(has_color) gray_scale = 0;
if (has_color)
gray_scale = 0;
numcomps = gray_scale ? 1 : 3;
color_space = gray_scale ? CLRSPC_GRAY : CLRSPC_SRGB;
/* initialize image components */
memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t));
for(i = 0; i < numcomps; i++)
for (i = 0; i < numcomps; i++)
{
cmptparm[i].prec = 8;
cmptparm[i].bpp = 8;
@ -724,18 +783,22 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
}
/* create the image */
image = opj_image_create(numcomps, &cmptparm[0], color_space);
if(!image)
if (!image)
{
fclose(IN);
free(table_R); free(table_G); free(table_B);
free(table_R);
free(table_G);
free(table_B);
return NULL;
}
/* set image offset and reference grid */
image->x0 = parameters->image_offset_x0;
image->y0 = parameters->image_offset_y0;
image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w - 1) * subsampling_dx + 1;
image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h - 1) * subsampling_dy + 1;
image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w
- 1) * subsampling_dx + 1;
image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h
- 1) * subsampling_dy + 1;
/* set image data */
@ -745,12 +808,12 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
W = Info_h.biWidth;
H = Info_h.biHeight;
RGB = (unsigned char *)calloc(1, W * H * sizeof(unsigned char));
RGB = (unsigned char *) calloc(1, W * H * sizeof(unsigned char));
beyond = RGB + W * H;
pix = beyond - W;
x = y = 0;
while(y < H)
while (y < H)
{
c = getc(IN);
@ -765,29 +828,31 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
{
c = getc(IN);
if(c == 0x00) /* EOL */
if (c == 0x00) /* EOL */
{
x = 0; ++y; pix = RGB + x + (H - y - 1) * W;
x = 0;
++y;
pix = RGB + x + (H - y - 1) * W;
}
else
if(c == 0x01) /* EOP */
else if (c == 0x01) /* EOP */
break;
else
if(c == 0x02) /* MOVE by dxdy */
else if (c == 0x02) /* MOVE by dxdy */
{
c = getc(IN); x += c;
c = getc(IN); y += c;
c = getc(IN);
x += c;
c = getc(IN);
y += c;
pix = RGB + (H - y - 1) * W + x;
}
else /* 03 .. 255 */
{
i = 0;
for(; i < c && x < W && pix < beyond; i++, x++, pix++)
for (; i < c && x < W && pix < beyond; i++, x++, pix++)
{
c1 = getc(IN);
*pix = c1;
}
if(c & 1) /* skip padding byte */
if (c & 1) /* skip padding byte */
getc(IN);
}
}
@ -795,13 +860,11 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
if (gray_scale)
{
int *gray;
gray = image->comps[0].data;
pix = RGB;
max = W * H;
while(max--)
while (max--)
{
uc = *pix++;
@ -810,7 +873,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
}
else
{
int *red, *green, *blue;
//int *red, *green, *blue;
red = image->comps[0].data;
green = image->comps[1].data;
@ -818,7 +881,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
pix = RGB;
max = W * H;
while(max--)
while (max--)
{
uc = *pix++;
@ -828,7 +891,9 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
}
}
free(RGB);
free(table_R); free(table_G); free(table_B);
free(table_R);
free(table_G);
free(table_B);
}/* RLE8 */
else
{
@ -1007,7 +1072,6 @@ int imagetobmp(opj_image_t * image, const char *outfile) {
}
for (i = 0; i < w * h; i++) {
unsigned char rc;
int r;
r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
@ -1038,15 +1102,27 @@ PGX IMAGE FORMAT
unsigned char readuchar(FILE * f)
{
unsigned char c1;
fread(&c1, 1, 1, f);
if ( !fread(&c1, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0;
}
return c1;
}
unsigned short readushort(FILE * f, int bigendian)
{
unsigned char c1, c2;
fread(&c1, 1, 1, f);
fread(&c2, 1, 1, f);
if ( !fread(&c1, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0;
}
if ( !fread(&c2, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0;
}
if (bigendian)
return (c1 << 8) + c2;
else
@ -1056,10 +1132,26 @@ unsigned short readushort(FILE * f, int bigendian)
unsigned int readuint(FILE * f, int bigendian)
{
unsigned char c1, c2, c3, c4;
fread(&c1, 1, 1, f);
fread(&c2, 1, 1, f);
fread(&c3, 1, 1, f);
fread(&c4, 1, 1, f);
if ( !fread(&c1, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0;
}
if ( !fread(&c2, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0;
}
if ( !fread(&c3, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0;
}
if ( !fread(&c4, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0;
}
if (bigendian)
return (c1 << 24) + (c2 << 16) + (c3 << 8) + c4;
else
@ -1097,6 +1189,7 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) {
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') {
@ -1308,7 +1401,14 @@ static void read_pnm_header(FILE *reader, struct pnm_header *ph)
char idf[256], type[256];
char line[256];
fgets(line, 250, reader);
char* return_value_fgets = fgets(line, 250, reader);
if (!strcmp(return_value_fgets,line))
{
fprintf(stderr,"\nWARNING: fgets return a value different that the first argument");
free(return_value_fgets);
return;
}
free(return_value_fgets);
if(line[0] != 'P')
{
@ -1563,7 +1663,8 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) {
for(compno = 0; compno < numcomps; compno++)
{
index = 0;
fscanf(fp, "%u", &index);
if (fscanf(fp, "%u", &index) != 1)
fprintf(stderr, "\nWARNING: fscanf return a number of element different from the expected.\n");
image->comps[compno].data[i] = (index * 255)/header_info.maxval;
}
@ -1584,14 +1685,16 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) {
{
for(compno = 0; compno < numcomps; compno++)
{
fread(&c0, 1, 1, fp);
if ( !fread(&c0, 1, 1, fp) )
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
if(one)
{
image->comps[compno].data[i] = c0;
}
else
{
fread(&c1, 1, 1, fp);
if ( !fread(&c1, 1, 1, fp) )
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
/* netpbm: */
image->comps[compno].data[i] = ((c0<<8) | c1);
}
@ -1605,7 +1708,8 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) {
{
unsigned int index;
fscanf(fp, "%u", &index);
if ( fscanf(fp, "%u", &index) != 1)
fprintf(stderr, "\nWARNING: fscanf return a number of element different from the expected.\n");
image->comps[0].data[i] = (index?0:255);
}
@ -1640,7 +1744,8 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) {
for(i = 0; i < w * h; ++i)
{
fread(&uc, 1, 1, fp);
if ( !fread(&uc, 1, 1, fp) )
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
image->comps[0].data[i] = (uc & 1)?0:255;
}
}

View File

@ -1482,7 +1482,7 @@ int main(int argc, char **argv) {
opj_image_t *image = NULL;
int i,num_images;
int imageno;
dircnt_t *dirptr;
dircnt_t *dirptr = NULL;
raw_cparameters_t raw_cp;
opj_codestream_info_t cstr_info; /* Codestream information structure */
char indexfilename[OPJ_PATH_LEN]; /* index file name */

View File

@ -412,7 +412,13 @@ int main(int argc, char *argv[])
file_length = ftell(fsrc);
fseek(fsrc, 0, SEEK_SET);
src = (unsigned char *) malloc(file_length);
fread(src, 1, file_length, fsrc);
if (fread(src, 1, file_length, fsrc) != file_length)
{
free(src);
fclose(fsrc);
fprintf(stderr, "\nERROR: fread return a number of element different from the expected.\n");
return 1;
}
fclose(fsrc);
/* decode the code-stream */

View File

@ -521,7 +521,7 @@ int main(int argc, char **argv) {
int file_length;
int num_images;
int i,imageno;
dircnt_t *dirptr;
dircnt_t *dirptr = NULL;
opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */
opj_cio_t *cio = NULL;
opj_codestream_info_t cstr_info; /* Codestream information structure */
@ -595,7 +595,13 @@ int main(int argc, char **argv) {
file_length = ftell(fsrc);
fseek(fsrc, 0, SEEK_SET);
src = (unsigned char *) malloc(file_length);
fread(src, 1, file_length, fsrc);
if (fread(src, 1, file_length, fsrc) != file_length)
{
free(src);
fclose(fsrc);
fprintf(stderr, "\nERROR: fread return a number of element different from the expected.\n");
return 1;
}
fclose(fsrc);
/* decode the code-stream */

View File

@ -164,6 +164,7 @@ int main(int argc, char **argv)
size_t nbytes = 2048;
int CRLF_shift=1;
char *strbase, *strtest, *strbase_d, *strtest_d;
char *return_value_fgets;
printf("Files differ at line %lu:\n", l);
fseek(fbase,pos,SEEK_SET);
@ -179,8 +180,17 @@ int main(int argc, char **argv)
strbase = (char *) malloc(nbytes + 1);
strtest = (char *) malloc(nbytes + 1);
fgets(strbase, nbytes, fbase);
fgets(strtest, nbytes, ftest);
return_value_fgets = fgets(strbase, nbytes, fbase);
if (!strcmp(return_value_fgets,strbase))
fprintf(stderr,"\nWARNING: fgets return a value different that the first argument");
free(return_value_fgets);
return_value_fgets = fgets(strtest, nbytes, ftest);
if (!strcmp(return_value_fgets,strtest))
fprintf(stderr,"\nWARNING: fgets return a value different that the first argument");
free(return_value_fgets);
strbase_d = (char *) malloc(strlen(strbase)+1);
strtest_d = (char *) malloc(strlen(strtest)+1);
strncpy(strbase_d, strbase, strlen(strbase)-1);

View File

@ -15,7 +15,6 @@ FILE(GLOB_RECURSE OPJ_DATA_NR_LIST
FOREACH(filepath ${OPJ_DATA_NR_LIST})
GET_FILENAME_COMPONENT(filename ${filepath} NAME)
GET_FILENAME_COMPONENT(filenameSub ${filename} NAME_WE)
message("${filenameSub}")
ADD_TEST(NR-${filename}-dump
${EXECUTABLE_OUTPUT_PATH}/j2k_dump