unsigned char id_len, /*cmap_type,*/ image_type;
unsigned char pixel_depth, image_desc;
unsigned short /*cmap_index,*/ cmap_len, cmap_entry_size;
unsigned char id_len, /*cmap_type,*/ image_type;
unsigned char pixel_depth, image_desc;
unsigned short /*cmap_index,*/ cmap_len, cmap_entry_size;
if ( fread(tga, TGA_HEADER_SIZE, 1, fp) != 1 )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0 ;
}
if ( fread(tga, TGA_HEADER_SIZE, 1, fp) != 1 )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return 0 ;
}
- id_len = (unsigned char)tga[0];
- /*cmap_type = (unsigned char)tga[1];*/
- image_type = (unsigned char)tga[2];
- /*cmap_index = get_ushort(*(unsigned short*)(&tga[3]));*/
- cmap_len = get_ushort(*(unsigned short*)(&tga[5]));
- cmap_entry_size = (unsigned char)tga[7];
+ id_len = tga[0];
+ /*cmap_type = tga[1];*/
+ image_type = tga[2];
+ /*cmap_index = get_ushort(&tga[3]);*/
+ cmap_len = get_ushort(&tga[5]);
+ cmap_entry_size = tga[7];
- image_w = get_ushort(*(unsigned short*)(&tga[12]));
- image_h = get_ushort(*(unsigned short*)(&tga[14]));
- pixel_depth = (unsigned char)tga[16];
- image_desc = (unsigned char)tga[17];
-
- free(tga);
+ image_w = get_ushort(&tga[12]);
+ image_h = get_ushort(&tga[14]);
+ pixel_depth = tga[16];
+ image_desc = tga[17];
if ( !fread(id, id_len, 1, fp) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
if ( !fread(id, id_len, 1, fp) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
- if (!tga_readheader(f, &pixel_bit_depth, &image_width, &image_height, &flip_image))
+ if (!tga_readheader(f, &pixel_bit_depth, &image_width, &image_height, &flip_image)) {
+ fclose(f);
/* initialize image components */
memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t));
/* initialize image components */
memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t));
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
{
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(&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(&r, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
{
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(&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(&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;
}
if ( !fread(&a, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
if ((image->comps[0].dx != image->comps[i+1].dx)
||(image->comps[0].dy != image->comps[i+1].dy)
||(image->comps[0].prec != image->comps[i+1].prec)) {
if ((image->comps[0].dx != image->comps[i+1].dx)
||(image->comps[0].dy != image->comps[i+1].dy)
||(image->comps[0].prec != image->comps[i+1].prec)) {
fseek(f, 0, SEEK_SET);
if( fscanf(f, "PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d",temp,&endian1,&endian2,signtmp,&prec,temp,&w,temp,&h) != 9){
fseek(f, 0, SEEK_SET);
if( fscanf(f, "PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d",temp,&endian1,&endian2,signtmp,&prec,temp,&w,temp,&h) != 9){
opj_image_comp_t *comp = &image->comps[compno];
char bname[256]; /* buffer for name */
char *name = bname; /* pointer */
opj_image_comp_t *comp = &image->comps[compno];
char bname[256]; /* buffer for name */
char *name = bname; /* pointer */
/* `pgx` was recognized but there is no dot at expected position */
fprintf(stderr, "ERROR -> Impossible happen." );
goto fin;
/* `pgx` was recognized but there is no dot at expected position */
fprintf(stderr, "ERROR -> Impossible happen." );
goto fin;
/* FIXME: clamp func is being called within a loop */
const int val = clamp(image->comps[compno].data[i],
(int)comp->prec, (int)comp->sgnd);
for (j = nbytes - 1; j >= 0; j--)
/* FIXME: clamp func is being called within a loop */
const int val = clamp(image->comps[compno].data[i],
(int)comp->prec, (int)comp->sgnd);
for (j = nbytes - 1; j >= 0; j--)
int v = (int)(val >> (j * 8));
unsigned char byte = (unsigned char)v;
res = fwrite(&byte, 1, 1, fdest);
if( res < 1 )
int v = (int)(val >> (j * 8));
unsigned char byte = (unsigned char)v;
res = fwrite(&byte, 1, 1, fdest);
if( res < 1 )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
"MAXVAL %d\nTUPLTYPE %s\nENDHDR\n", opj_version(),
wr, hr, ncomp, max, tt);
alpha = image->comps[ncomp - 1].data;
"MAXVAL %d\nTUPLTYPE %s\nENDHDR\n", opj_version(),
wr, hr, ncomp, max, tt);
alpha = image->comps[ncomp - 1].data;
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
v = *blue + adjustB; ++blue;
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
v = *blue + adjustB; ++blue;
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
- fprintf(fdest, "%c", (unsigned char)v);
- v = *blue++;
- if(v > 255) v = 255; else if(v < 0) v = 0;
+ fprintf(fdest, "%c", (unsigned char)v);
+ v = *blue++;
+ if(v > 255) v = 255; else if(v < 0) v = 0;
fprintf(stderr," is written to the file\n");
}
destname = (char*)malloc(strlen(outfile) + 8);
fprintf(stderr," is written to the file\n");
}
destname = (char*)malloc(strlen(outfile) + 8);
- if (ncomp > 1)
- {
- /*sprintf(destname, "%d.%s", compno, outfile);*/
- const size_t olen = strlen(outfile);
- const size_t dotpos = olen - 4;
-
- strncpy(destname, outfile, dotpos);
- sprintf(destname+dotpos, "_%d.pgm", compno);
- }
+ if (ncomp > 1)
+ {
+ /*sprintf(destname, "%d.%s", compno, outfile);*/
+ const size_t olen = strlen(outfile);
+ const size_t dotpos = olen - 4;
+
+ strncpy(destname, outfile, dotpos);
+ sprintf(destname+dotpos, "_%u.pgm", compno);
+ }
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
/* netpbm: */
fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v);
if (!cmptparm) {
fprintf(stderr, "Failed to allocate image components parameters !!\n");
fprintf(stderr,"Aborting\n");
if (!cmptparm) {
fprintf(stderr, "Failed to allocate image components parameters !!\n");
fprintf(stderr,"Aborting\n");
for (i = 0; i < nloop; i++) {
if (!fread(&value, 1, 1, f)) {
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
for (i = 0; i < nloop; i++) {
if (!fread(&value, 1, 1, f)) {
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
for (i = 0; i < nloop; i++) {
unsigned char temp1;
unsigned char temp2;
if (!fread(&temp1, 1, 1, f)) {
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
for (i = 0; i < nloop; i++) {
unsigned char temp1;
unsigned char temp2;
if (!fread(&temp1, 1, 1, f)) {
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
return NULL;
}
if (!fread(&temp2, 1, 1, f)) {
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
return NULL;
}
if (!fread(&temp2, 1, 1, f)) {
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
- fprintf(stdout,"Component %d characteristics: %dx%dx%d %s\n", compno, image->comps[compno].w,
+ fprintf(stdout,"Component %u characteristics: %dx%dx%d %s\n", compno, image->comps[compno].w,
image->comps[compno].h, image->comps[compno].prec, image->comps[compno].sgnd==1 ? "signed": "unsigned");
w = (int)image->comps[compno].w;
image->comps[compno].h, image->comps[compno].prec, image->comps[compno].sgnd==1 ? "signed": "unsigned");
w = (int)image->comps[compno].w;