static unsigned short get_ushort(unsigned short val) {
-#ifdef WORDS_BIGENDIAN
+#ifdef OPJ_BIG_ENDIAN
return( ((val & 0xff) << 8) + (val >> 8) );
#else
return( val );
return 1;
}
-#if WORDS_BIGENDIAN == 1
+#ifdef OPJ_BIG_ENDIAN
-static inline int16_t swap16(int16_t x)
+static INLINE int16_t swap16(int16_t x)
{
return((((u_int16_t)x & 0x00ffU) << 8) |
(((u_int16_t)x & 0xff00U) >> 8));
image_w = (unsigned short)width;
image_h = (unsigned short) height;
-#if WORDS_BIGENDIAN == 0
+#ifndef OPJ_BIG_ENDIAN
if(fwrite(&image_w, 2, 1, fp) != 1) goto fails;
if(fwrite(&image_h, 2, 1, fp) != 1) goto fails;
#else
float scale;
FILE *fdest;
size_t res;
+ fails = 1;
fdest = fopen(outfile, "wb");
if (!fdest) {
/* Place the cursor at the beginning of the image information */
fseek(IN, 0, SEEK_SET);
- fseek(IN, File_h.bfOffBits, SEEK_SET);
+ fseek(IN, (long)File_h.bfOffBits, SEEK_SET);
W = Info_h.biWidth;
H = Info_h.biHeight;
/* Place the cursor at the beginning of the image information */
fseek(IN, 0, SEEK_SET);
- fseek(IN, File_h.bfOffBits, SEEK_SET);
+ fseek(IN, (long)File_h.bfOffBits, SEEK_SET);
W = Info_h.biWidth;
H = Info_h.biHeight;
/* Place the cursor at the beginning of the image information */
fseek(IN, 0, SEEK_SET);
- fseek(IN, File_h.bfOffBits, SEEK_SET);
+ fseek(IN, (long)File_h.bfOffBits, SEEK_SET);
W = Info_h.biWidth;
H = Info_h.biHeight;
#define CLAMP(x,a,b) x < a ? a : (x > b ? b : x)
-#ifdef _MSC_VER
-#define STIN static __inline
-#else
-#define STIN static inline
-#endif
-
-STIN int clamp( const int value, const int prec, const int sgnd )
+static INLINE int clamp( const int value, const int prec, const int sgnd )
{
if( sgnd )
{
}
if(ph->depth < 1 || ph->depth > 4) return;
- if(ph->width && ph->height && ph->depth & ph->maxval && ttype)
+ if(ph->width && ph->height && ph->depth && ph->maxval && ttype)
ph->ok = 1;
}
else
{
for(compno = 0; compno < numcomps; compno++)
{
- if ( !fread(&c0, 1, 1, fp) )
- fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
+ if ( !fread(&c0, 1, 1, fp) )
+ {
+ fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
+ opj_image_destroy(image);
+ return NULL;
+ }
if(one)
{
image->comps[compno].data[i] = c0;
for (compno = 0; compno < ncomp; compno++)
{
- if (ncomp > 1)
- sprintf(destname, "%d.%s", compno, outfile);
+ 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);
+ }
else
sprintf(destname, "%s", outfile);
opj_image_cmptparm_t cmptparm[4];
int sub_dx, sub_dy;
unsigned int nr_comp;
- int *r, *g, *b, *a;
+ int *r, *g, *b, *a = NULL;
unsigned char sigbuf[8];
if((reader = fopen(read_idf, "rb")) == NULL)
png_read_image(png, rows);
- memset(&cmptparm, 0, 4 * sizeof(opj_image_cmptparm_t));
+ memset(cmptparm, 0, sizeof(cmptparm));
sub_dx = params->subsampling_dx; sub_dy = params->subsampling_dy;
r = image->comps[0].data;
g = image->comps[1].data;
b = image->comps[2].data;
- a = image->comps[3].data;
+ if(has_alpha) a = image->comps[3].data;
for(i = 0; i < height; ++i)
{