#if WORDS_BIGENDIAN == 1
-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));
float scale;
FILE *fdest;
size_t res;
+ fails = 1;
fdest = fopen(outfile, "wb");
if (!fdest) {
unsigned char *table_R, *table_G, *table_B;
unsigned int j, PAD = 0;
- int x, y, index;
+ unsigned int x, y;
+ int index;
int gray_scale = 1;
int has_color;
DWORD W, H;
/* 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;
index = 0;
- for(y = 0; y < (int)H; y++)
+ for(y = 0; y < H; y++)
{
unsigned char *scanline = RGB + (3 * (unsigned int)W + PAD) * ((unsigned int)H - 1 - (unsigned int)y);
- for(x = 0; x < (int)W; x++)
+ for(x = 0; x < W; x++)
{
unsigned char *pixel = &scanline[3 * x];
image->comps[0].data[index] = pixel[2]; /* R */
/* 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;
{
unsigned char *pix, *beyond;
int *gray, *red, *green, *blue;
- unsigned int x, y, max;
- int i, c, c1;
+ unsigned int max;
+ int c, c1;
unsigned char uc;
if (Info_h.biClrUsed == 0)
/* 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)
-static inline 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 < 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);
{
if(image->comps[compno].sgnd == 1)
{
- union { signed short val; signed char vals[2]; } uc;
+ union { signed short val; signed char vals[2]; } uc16;
mask = (1 << image->comps[compno].prec) - 1;
ptr = image->comps[compno].data;
for (line = 0; line < h; line++) {
for(row = 0; row < w; row++) {
curr = *ptr;
if(curr > 32767 ) curr = 32767; else if( curr < -32768) curr = -32768;
- uc.val = (signed short)(curr & mask);
- res = fwrite(uc.vals, 1, 2, rawFile);
+ uc16.val = (signed short)(curr & mask);
+ res = fwrite(uc16.vals, 1, 2, rawFile);
if( res < 2 ) {
fprintf(stderr, "failed to write 2 byte for %s\n", outfile);
goto fin;
}
else if(image->comps[compno].sgnd == 0)
{
- union { unsigned short val; unsigned char vals[2]; } uc;
+ union { unsigned short val; unsigned char vals[2]; } uc16;
mask = (1 << image->comps[compno].prec) - 1;
ptr = image->comps[compno].data;
for (line = 0; line < h; line++) {
for(row = 0; row < w; row++) {
curr = *ptr;
if(curr > 65536 ) curr = 65536; else if( curr < 0) curr = 0;
- uc.val = (unsigned short)(curr & mask);
- res = fwrite(uc.vals, 1, 2, rawFile);
+ uc16.val = (unsigned short)(curr & mask);
+ res = fwrite(uc16.vals, 1, 2, rawFile);
if( res < 2 ) {
fprintf(stderr, "failed to write 2 byte for %s\n", outfile);
goto fin;