diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2020-06-28 17:52:14 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2020-06-28 17:52:14 +0000 |
commit | 1cd3ef0dd6c2236d0b329879bacd9360d01c88a1 (patch) | |
tree | a60016b5dd48fbf681ebfb43a6ca0d7e20a391d8 /converter/other | |
parent | cbbf595776cee6b8d8a24becf49ee6468eeba712 (diff) | |
download | netpbm-mirror-1cd3ef0dd6c2236d0b329879bacd9360d01c88a1.tar.gz netpbm-mirror-1cd3ef0dd6c2236d0b329879bacd9360d01c88a1.tar.xz netpbm-mirror-1cd3ef0dd6c2236d0b329879bacd9360d01c88a1.zip |
Promote Development to Advaanced - Release 10.91
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@3877 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other')
-rwxr-xr-x | converter/other/anytopnm | 2 | ||||
-rw-r--r-- | converter/other/cameratopam/Makefile | 2 | ||||
-rw-r--r-- | converter/other/cameratopam/camera.c | 245 | ||||
-rw-r--r-- | converter/other/cameratopam/canon.c | 24 | ||||
-rw-r--r-- | converter/other/cameratopam/foveon.c | 102 | ||||
-rw-r--r-- | converter/other/cameratopam/identify.c | 49 | ||||
-rw-r--r-- | converter/other/cameratopam/ljpeg.c | 16 | ||||
-rw-r--r-- | converter/other/cameratopam/stdio_nofail.c | 120 | ||||
-rw-r--r-- | converter/other/cameratopam/stdio_nofail.h | 29 | ||||
-rw-r--r-- | converter/other/cameratopam/util.c | 34 | ||||
-rw-r--r-- | converter/other/fiasco/input/read.c | 2 | ||||
-rw-r--r-- | converter/other/fiasco/lib/image.c | 58 | ||||
-rw-r--r-- | converter/other/fiasco/lib/image.h | 2 | ||||
-rw-r--r-- | converter/other/fiasco/lib/macros.h | 2 | ||||
-rw-r--r-- | converter/other/tifftopnm.c | 10 | ||||
-rw-r--r-- | converter/other/winicontopam.c | 82 | ||||
-rw-r--r-- | converter/other/xwdtopnm.c | 2 |
17 files changed, 483 insertions, 298 deletions
diff --git a/converter/other/anytopnm b/converter/other/anytopnm index 5409bccd..94838556 100755 --- a/converter/other/anytopnm +++ b/converter/other/anytopnm @@ -538,7 +538,7 @@ else fi tempdir=$(mktemp -d "${TMPDIR:-/tmp}/anytopnm.XXXXXXXX") || - ( echo "Could not create temporary file. Exiting." 1>&2; exit 1; ) + { echo "Could not create temporary file. Exiting." 1>&2; exit 1; } trap 'rm -rf $tempdir' 0 # Take out all spaces diff --git a/converter/other/cameratopam/Makefile b/converter/other/cameratopam/Makefile index d6207aea..bb4c4cde 100644 --- a/converter/other/cameratopam/Makefile +++ b/converter/other/cameratopam/Makefile @@ -20,7 +20,7 @@ include $(BUILDDIR)/config.mk all: cameratopam ADDL_OBJECTS = util.o identify.o camera.o foveon.o decode.o \ - canon.o ljpeg.o dng.o + canon.o ljpeg.o dng.o stdio_nofail.o OBJECTS = cameratopam.o $(ADDL_OBJECTS) diff --git a/converter/other/cameratopam/camera.c b/converter/other/cameratopam/camera.c index 439c9413..4610462c 100644 --- a/converter/other/cameratopam/camera.c +++ b/converter/other/cameratopam/camera.c @@ -24,6 +24,7 @@ #include "bayer.h" #include "ljpeg.h" #include "dng.h" +#include "stdio_nofail.h" #include "camera.h" @@ -94,8 +95,8 @@ adobe_dng_load_raw_lj(Image const image) { unsigned short *rp; while (1) { - save = ftell(ifp); - fseek (ifp, get4(ifp), SEEK_SET); + save = ftell_nofail(ifp); + fseek_nofail (ifp, get4(ifp), SEEK_SET); if (!ljpeg_start (ifp, &jh)) break; if (trow >= raw_height) break; if (jh.high > raw_height-trow) @@ -113,7 +114,7 @@ adobe_dng_load_raw_lj(Image const image) { adobeCopyPixel(image, trow+jrow, tcol+jcol, &rp, use_secondary); } - fseek (ifp, save+4, SEEK_SET); + fseek_nofail (ifp, save+4, SEEK_SET); if ((tcol += twide) >= raw_width) { tcol = 0; trow += jh.high; @@ -157,14 +158,14 @@ nikon_compressed_load_raw(Image const image) { init_decoder(); make_decoder (nikon_tree, 0); - fseek (ifp, nikon_curve_offset, SEEK_SET); + fseek_nofail (ifp, nikon_curve_offset, SEEK_SET); read_shorts (ifp, vpred, 4); csize = get2(ifp); curve = calloc (csize, sizeof *curve); merror (curve, "nikon_compressed_load_raw()"); read_shorts (ifp, curve, csize); - fseek (ifp, data_offset, SEEK_SET); + fseek_nofail (ifp, data_offset, SEEK_SET); getbits(ifp, -1); for (row=0; row < height; row++) @@ -197,8 +198,8 @@ nikon_load_raw(Image const image) { if (model[0] == 'E') { row = irow * 2 % height + irow / (height/2); if (row == 1 && atoi(model+1) < 5000) { - fseek (ifp, 0, SEEK_END); - fseek (ifp, ftell(ifp)/2, SEEK_SET); + fseek_nofail (ifp, 0, SEEK_END); + fseek_nofail (ifp, ftell_nofail(ifp)/2, SEEK_SET); getbits(ifp, -1); } } @@ -227,8 +228,8 @@ nikon_is_compressed() return 0; if (strcmp(model,"D100")) return 1; - fseek (ifp, data_offset, SEEK_SET); - fread (test, 1, 256, ifp); + fseek_nofail (ifp, data_offset, SEEK_SET); + fread_nofail (test, 1, 256, ifp); for (i=15; i < 256; i+=16) if (test[i]) return 1; return 0; @@ -244,9 +245,9 @@ nikon_e990() const unsigned char often[] = { 0x00, 0x55, 0xaa, 0xff }; memset (histo, 0, sizeof histo); - fseek (ifp, 2064*1540*3/4, SEEK_SET); + fseek_nofail (ifp, 2064*1540*3/4, SEEK_SET); for (i=0; i < 2000; i++) - histo[fgetc(ifp)]++; + histo[fgetc_nofail(ifp)]++; for (i=0; i < 4; i++) if (histo[often[i]] > 400) return 1; @@ -262,9 +263,9 @@ nikon_e2100() unsigned char t[12]; int i; - fseek (ifp, 0, SEEK_SET); + fseek_nofail (ifp, 0, SEEK_SET); for (i=0; i < 1024; i++) { - fread (t, 1, 12, ifp); + fread_nofail (t, 1, 12, ifp); if (((t[2] & t[4] & t[7] & t[9]) >> 4 & t[1] & t[6] & t[8] & t[11] & 3) != 3) return 0; @@ -281,8 +282,8 @@ pentax_optio33() int i, sum[] = { 0, 0 }; unsigned char tail[952]; - fseek (ifp, -sizeof tail, SEEK_END); - fread (tail, 1, sizeof tail, ifp); + fseek_nofail (ifp, -sizeof tail, SEEK_END); + fread_nofail (tail, 1, sizeof tail, ifp); for (i=0; i < sizeof tail; i++) sum[(i>>2) & 1] += tail[i]; return sum[0] < sum[1]*4; @@ -297,8 +298,8 @@ minolta_z2() int i; char tail[424]; - fseek (ifp, -sizeof tail, SEEK_END); - fread (tail, 1, sizeof tail, ifp); + fseek_nofail (ifp, -sizeof tail, SEEK_END); + fread_nofail (tail, 1, sizeof tail, ifp); for (i=0; i < sizeof tail; i++) if (tail[i]) return 1; return 0; @@ -313,10 +314,10 @@ nikon_e2100_load_raw(Image const image) { for (row=0; row <= height; row+=2) { if (row == height) { - fseek (ifp, ((width==1616) << 13) - (-ftell(ifp) & -2048), SEEK_SET); + fseek_nofail (ifp, ((width==1616) << 13) - (-ftell_nofail(ifp) & -2048), SEEK_SET); row = 1; } - fread (data, 1, width*3/2, ifp); + fread_nofail (data, 1, width*3/2, ifp); for (dp=data, pix=pixel; pix < pixel+width; dp+=12, pix+=8) { pix[0] = (dp[2] >> 4) + (dp[ 3] << 4); pix[1] = (dp[2] << 8) + dp[ 1]; @@ -356,7 +357,7 @@ fuji_s2_load_raw(Image const image) { unsigned short pixel[2944]; int row, col, r, c; - fseek (ifp, (2944*24+32)*2, SEEK_CUR); + fseek_nofail (ifp, (2944*24+32)*2, SEEK_CUR); for (row=0; row < 2144; row++) { read_shorts(ifp, pixel, 2944); for (col=0; col < 2880; col++) { @@ -372,7 +373,7 @@ fuji_s3_load_raw(Image const image) { unsigned short pixel[4352]; int row, col, r, c; - fseek (ifp, (4352*2+32)*2, SEEK_CUR); + fseek_nofail (ifp, (4352*2+32)*2, SEEK_CUR); for (row=0; row < 1440; row++) { read_shorts(ifp, pixel, 4352); for (col=0; col < 4288; col++) { @@ -408,7 +409,7 @@ fuji_common_load_raw(Image const image, void fuji_s5000_load_raw(Image const image) { - fseek (ifp, (1472*4+24)*2, SEEK_CUR); + fseek_nofail (ifp, (1472*4+24)*2, SEEK_CUR); fuji_common_load_raw(image, 1472, 1423, 2152); } @@ -449,7 +450,7 @@ rollei_load_raw(Image const image) { unsigned iten=0, isix, i, buffer=0, row, col, todo[16]; isix = raw_width * raw_height * 5 / 8; - while (fread (pixel, 1, 10, ifp) == 10) { + while (fread_or_eof_nofail (pixel, 1, 10, ifp) == 10) { for (i=0; i < 10; i+=2) { todo[i] = iten++; todo[i+1] = pixel[i] << 8 | pixel[i+1]; @@ -474,11 +475,11 @@ phase_one_load_raw(Image const image) { int row, col, a, b; unsigned short *pixel, akey, bkey; - fseek (ifp, 8, SEEK_CUR); - fseek (ifp, get4(ifp) + 296, SEEK_CUR); + fseek_nofail (ifp, 8, SEEK_CUR); + fseek_nofail (ifp, get4(ifp) + 296, SEEK_CUR); akey = get2(ifp); bkey = get2(ifp); - fseek (ifp, data_offset + 12 + top_margin*raw_width*2, SEEK_SET); + fseek_nofail (ifp, data_offset + 12 + top_margin*raw_width*2, SEEK_SET); pixel = calloc (raw_width, sizeof *pixel); merror (pixel, "phase_one_load_raw()"); for (row=0; row < height; row++) { @@ -501,7 +502,7 @@ ixpress_load_raw(Image const image) { int row, col; order = 0x4949; - fseek (ifp, 304 + 6*2*4090, SEEK_SET); + fseek_nofail (ifp, 304 + 6*2*4090, SEEK_SET); for (row=height; --row >= 0; ) { read_shorts(ifp, pixel, 4090); for (col=0; col < width; col++) @@ -567,7 +568,7 @@ olympus_e300_load_raw(Image const image) { merror (data, "olympus_e300_load_raw()"); pixel = (unsigned short *) (data + dwide); for (row=0; row < height; row++) { - fread (data, 1, dwide, ifp); + fread_nofail (data, 1, dwide, ifp); for (dp=data, pix=pixel; pix < pixel+raw_width; dp+=3, pix+=2) { if (((dp-data) & 15) == 15) dp++; pix[0] = dp[1] << 8 | dp[0]; @@ -586,7 +587,7 @@ olympus_cseries_load_raw(Image const image) { for (irow=0; irow < height; irow++) { row = irow * 2 % height + irow / (height/2); if (row < 2) { - fseek (ifp, data_offset - row*(-width*height*3/4 & -2048), SEEK_SET); + fseek_nofail (ifp, data_offset - row*(-width*height*3/4 & -2048), SEEK_SET); getbits(ifp, -1); } for (col=0; col < width; col++) @@ -602,7 +603,7 @@ eight_bit_load_raw(Image const image) { pixel = calloc (raw_width, sizeof *pixel); merror (pixel, "eight_bit_load_raw()"); for (row=0; row < height; row++) { - fread (pixel, 1, raw_width, ifp); + fread_nofail (pixel, 1, raw_width, ifp); for (col=0; col < width; col++) BAYER(row,col) = pixel[col]; } @@ -617,7 +618,7 @@ casio_qv5700_load_raw(Image const image) { int row, col; for (row=0; row < height; row++) { - fread (data, 1, 3232, ifp); + fread_nofail (data, 1, 3232, ifp); for (dp=data, pix=pixel; dp < data+3220; dp+=5, pix+=4) { pix[0] = (dp[0] << 2) + (dp[1] >> 6); pix[1] = (dp[1] << 4) + (dp[2] >> 4); @@ -783,7 +784,7 @@ fill_input_buffer (j_decompress_ptr cinfo) static char jpeg_buffer[4096]; size_t nbytes; - nbytes = fread (jpeg_buffer, 1, 4096, ifp); + nbytes = fread_or_eof_nofail (jpeg_buffer, 1, 4096, ifp); swab (jpeg_buffer, jpeg_buffer, nbytes); cinfo->src->next_input_byte = jpeg_buffer; cinfo->src->bytes_in_buffer = nbytes; @@ -840,7 +841,7 @@ kodak_dc120_load_raw(Image const image) int row, shift, col; for (row=0; row < height; row++) { - fread (pixel, 848, 1, ifp); + fread_nofail (pixel, 848, 1, ifp); shift = row * mul[row & 3] + add[row & 3]; for (col=0; col < width; col++) BAYER(row,col) = (unsigned short) pixel[(col + shift) % 848]; @@ -878,7 +879,7 @@ kodak_easy_load_raw(Image const image) pixel = calloc (raw_width, sizeof *pixel); merror (pixel, "kodak_easy_load_raw()"); for (row=0; row < height; row++) { - fread (pixel, 1, raw_width, ifp); + fread_nofail (pixel, 1, raw_width, ifp); for (col=0; col < raw_width; col++) { icol = col - left_margin; if (icol < width) @@ -912,21 +913,21 @@ kodak_compressed_load_raw(Image const image) if ((col & 255) == 0) { /* Get the bit-lengths of the */ len = width - col; /* next 256 pixel values */ if (len > 256) len = 256; - save = ftell(ifp); + save = ftell_nofail(ifp); for (israw=i=0; i < len; i+=2) { - c = fgetc(ifp); + c = fgetc_nofail(ifp); if ((blen[i+0] = c & 15) > 12 || (blen[i+1] = c >> 4) > 12 ) israw = 1; } bitbuf = bits = pred[0] = pred[1] = 0; if (len % 8 == 4) { - bitbuf = fgetc(ifp) << 8; - bitbuf += fgetc(ifp); + bitbuf = fgetc_nofail(ifp) << 8; + bitbuf += fgetc_nofail(ifp); bits = 16; } if (israw) - fseek (ifp, save, SEEK_SET); + fseek_nofail (ifp, save, SEEK_SET); } if (israw) { /* If the data is not compressed */ switch (col & 7) { @@ -944,7 +945,7 @@ kodak_compressed_load_raw(Image const image) len = blen[col & 255]; /* Number of bits for this pixel */ if (bits < len) { /* Got enough bits in the buffer? */ for (i=0; i < 32; i+=8) - bitbuf += (INT64) fgetc(ifp) << (bits+(i^8)); + bitbuf += (INT64) fgetc_nofail(ifp) << (bits+(i^8)); bits += 32; } diff = bitbuf & (0xffff >> (16-len)); /* Pull bits from buffer */ @@ -976,14 +977,14 @@ kodak_yuv_load_raw(Image const image) len = (width - col + 1) * 3 & -4; if (len > 384) len = 384; for (i=0; i < len; ) { - c = fgetc(ifp); + c = fgetc_nofail(ifp); blen[i++] = c & 15; blen[i++] = c >> 4; } li = bitbuf = bits = y[1] = y[3] = cb = cr = 0; if (len % 8 == 4) { - bitbuf = fgetc(ifp) << 8; - bitbuf += fgetc(ifp); + bitbuf = fgetc_nofail(ifp) << 8; + bitbuf += fgetc_nofail(ifp); bits = 16; } } @@ -991,7 +992,7 @@ kodak_yuv_load_raw(Image const image) len = blen[li++]; if (bits < len) { for (i=0; i < 32; i+=8) - bitbuf += (INT64) fgetc(ifp) << (bits+(i^8)); + bitbuf += (INT64) fgetc_nofail(ifp) << (bits+(i^8)); bits += 32; } diff = bitbuf & (0xffff >> (16-len)); @@ -1062,20 +1063,20 @@ sony_load_raw(Image const image) struct pixel * pixelrow; unsigned i, key, row, col; - fseek (ifp, 200896, SEEK_SET); - fseek (ifp, (unsigned) fgetc(ifp)*4 - 1, SEEK_CUR); + fseek_nofail (ifp, 200896, SEEK_SET); + fseek_nofail (ifp, (unsigned) fgetc_nofail(ifp)*4 - 1, SEEK_CUR); order = 0x4d4d; key = get4(ifp); - fseek (ifp, 164600, SEEK_SET); - fread (head, 1, 40, ifp); + fseek_nofail (ifp, 164600, SEEK_SET); + fread_nofail (head, 1, 40, ifp); sony_decrypt ((void *) head, 10, 1, key); for (i=26; i-- > 22; ) key = key << 8 | head[i]; - fseek (ifp, data_offset, SEEK_SET); + fseek_nofail (ifp, data_offset, SEEK_SET); MALLOCARRAY(pixelrow, raw_width); merror (pixelrow, "sony_load_raw()"); for (row=0; row < height; row++) { - fread (pixelrow, 2, raw_width, ifp); + fread_nofail (pixelrow, 2, raw_width, ifp); sony_decrypt ((void *) pixelrow, raw_width/2, !row, key); for (col=9; col < left_margin; col++) black += pixelrow[col].bytes[0] * 256 + pixelrow[col].bytes[1]; @@ -1095,14 +1096,14 @@ parse_minolta(FILE * const ifp) { int save, tag, len, offset, high=0, wide=0; - fseek (ifp, 4, SEEK_SET); + fseek_nofail (ifp, 4, SEEK_SET); offset = get4(ifp) + 8; - while ((save=ftell(ifp)) < offset) { + while ((save=ftell_nofail(ifp)) < offset) { tag = get4(ifp); len = get4(ifp); switch (tag) { case 0x505244: /* PRD */ - fseek (ifp, 8, SEEK_CUR); + fseek_nofail (ifp, 8, SEEK_CUR); high = get2(ifp); wide = get2(ifp); break; @@ -1114,9 +1115,9 @@ parse_minolta(FILE * const ifp) camera_blue = get2(ifp) / camera_blue; break; case 0x545457: /* TTW */ - parse_tiff(ifp, ftell(ifp)); + parse_tiff(ifp, ftell_nofail(ifp)); } - fseek (ifp, save+len+8, SEEK_SET); + fseek_nofail (ifp, save+len+8, SEEK_SET); } raw_height = high; raw_width = wide; @@ -1168,24 +1169,24 @@ parse_ciff(FILE * const ifp, strcmp(model,"Canon PowerShot S70") && strcmp(model,"Canon PowerShot Pro1")) key[0] = key[1] = 0; - fseek (ifp, offset+length-4, SEEK_SET); + fseek_nofail (ifp, offset+length-4, SEEK_SET); tboff = get4(ifp) + offset; - fseek (ifp, tboff, SEEK_SET); + fseek_nofail (ifp, tboff, SEEK_SET); nrecs = get2(ifp); for (i = 0; i < nrecs; i++) { type = get2(ifp); len = get4(ifp); roff = get4(ifp); aoff = offset + roff; - save = ftell(ifp); + save = ftell_nofail(ifp); if (type == 0x080a) { /* Get the camera make and model */ - fseek (ifp, aoff, SEEK_SET); - fread (make, 64, 1, ifp); - fseek (ifp, aoff+strlen(make)+1, SEEK_SET); - fread (model, 64, 1, ifp); + fseek_nofail (ifp, aoff, SEEK_SET); + fread_nofail (make, 64, 1, ifp); + fseek_nofail (ifp, aoff+strlen(make)+1, SEEK_SET); + fread_nofail (model, 64, 1, ifp); } if (type == 0x102a) { /* Find the White Balance index */ - fseek (ifp, aoff+14, SEEK_SET); /* 0=auto, 1=daylight, 2=cloudy ... */ + fseek_nofail (ifp, aoff+14, SEEK_SET); /* 0=auto, 1=daylight, 2=cloudy ... */ wbi = get2(ifp); if (((!strcmp(model,"Canon EOS DIGITAL REBEL") || !strcmp(model,"Canon EOS 300D DIGITAL"))) && wbi == 6) @@ -1194,19 +1195,19 @@ parse_ciff(FILE * const ifp, if (type == 0x102c) { /* Get white balance (G2) */ if (!strcmp(model,"Canon PowerShot G1") || !strcmp(model,"Canon PowerShot Pro90 IS")) { - fseek (ifp, aoff+120, SEEK_SET); + fseek_nofail (ifp, aoff+120, SEEK_SET); white[0][1] = get2(ifp); white[0][0] = get2(ifp); white[1][0] = get2(ifp); white[1][1] = get2(ifp); } else { - fseek (ifp, aoff+100, SEEK_SET); + fseek_nofail (ifp, aoff+100, SEEK_SET); goto common; } } if (type == 0x0032) { /* Get white balance (D30 & G3) */ if (!strcmp(model,"Canon EOS D30")) { - fseek (ifp, aoff+72, SEEK_SET); + fseek_nofail (ifp, aoff+72, SEEK_SET); common: camera_red = get2(ifp) ^ key[0]; camera_red =(get2(ifp) ^ key[1]) / camera_red; @@ -1214,13 +1215,13 @@ common: camera_blue /= get2(ifp) ^ key[1]; } else if (!strcmp(model,"Canon PowerShot G6") || !strcmp(model,"Canon PowerShot S70")) { - fseek (ifp, aoff+96 + remap_s70[wbi]*8, SEEK_SET); + fseek_nofail (ifp, aoff+96 + remap_s70[wbi]*8, SEEK_SET); goto common; } else if (!strcmp(model,"Canon PowerShot Pro1")) { - fseek (ifp, aoff+96 + wbi*8, SEEK_SET); + fseek_nofail (ifp, aoff+96 + wbi*8, SEEK_SET); goto common; } else { - fseek (ifp, aoff+80 + (wbi < 6 ? remap[wbi]*8 : 0), SEEK_SET); + fseek_nofail (ifp, aoff+80 + (wbi < 6 ? remap[wbi]*8 : 0), SEEK_SET); if (!camera_red) goto common; } @@ -1228,38 +1229,38 @@ common: if (type == 0x10a9) { /* Get white balance (D60) */ if (!strcmp(model,"Canon EOS 10D")) wbi = remap_10d[wbi]; - fseek (ifp, aoff+2 + wbi*8, SEEK_SET); + fseek_nofail (ifp, aoff+2 + wbi*8, SEEK_SET); camera_red = get2(ifp); camera_red /= get2(ifp); camera_blue = get2(ifp); camera_blue = get2(ifp) / camera_blue; } if (type == 0x1030 && (wbi == 6 || wbi == 15)) { - fseek (ifp, aoff, SEEK_SET); /* Get white sample */ + fseek_nofail (ifp, aoff, SEEK_SET); /* Get white sample */ ciff_block_1030(); } if (type == 0x1031) { /* Get the raw width and height */ - fseek (ifp, aoff+2, SEEK_SET); + fseek_nofail (ifp, aoff+2, SEEK_SET); raw_width = get2(ifp); raw_height = get2(ifp); } if (type == 0x180e) { /* Get the timestamp */ - fseek (ifp, aoff, SEEK_SET); + fseek_nofail (ifp, aoff, SEEK_SET); timestamp = get4(ifp); } if (type == 0x580e) timestamp = len; if (type == 0x1810) { /* Get the rotation */ - fseek (ifp, aoff+12, SEEK_SET); + fseek_nofail (ifp, aoff+12, SEEK_SET); flip = get4(ifp); } if (type == 0x1835) { /* Get the decoder table */ - fseek (ifp, aoff, SEEK_SET); + fseek_nofail (ifp, aoff, SEEK_SET); crw_init_tables (get4(ifp)); } if (type >> 8 == 0x28 || type >> 8 == 0x30) /* Get sub-tables */ parse_ciff(ifp, aoff, len); - fseek (ifp, save, SEEK_SET); + fseek_nofail (ifp, save, SEEK_SET); } if (wbi == 0 && !strcmp(model,"Canon EOS D30")) camera_red = -1; /* Use my auto WB for this photo */ @@ -1273,9 +1274,9 @@ parse_rollei(FILE * const ifp) struct tm t; time_t ts; - fseek (ifp, 0, SEEK_SET); + fseek_nofail (ifp, 0, SEEK_SET); do { - fgets (line, 128, ifp); + fgets_nofail (line, 128, ifp); if ((val = strchr(line,'='))) *val++ = 0; else @@ -1314,13 +1315,13 @@ parse_mos(FILE * const ifp, char data[40]; int skip, from, i, neut[4]; - fseek (ifp, offset, SEEK_SET); + fseek_nofail (ifp, offset, SEEK_SET); while (1) { - fread (data, 1, 8, ifp); + fread_nofail (data, 1, 8, ifp); if (strcmp(data,"PKTS")) break; - fread (data, 1, 40, ifp); + fread_nofail (data, 1, 40, ifp); skip = get4(ifp); - from = ftell(ifp); + from = ftell_nofail(ifp); if (!strcmp(data,"NeutObj_neutrals")) { for (i=0; i < 4; i++) fscanf (ifp, "%d", neut+i); @@ -1328,7 +1329,7 @@ parse_mos(FILE * const ifp, camera_blue = (float) neut[2] / neut[3]; } parse_mos(ifp, from); - fseek (ifp, skip+from, SEEK_SET); + fseek_nofail (ifp, skip+from, SEEK_SET); } } @@ -1369,43 +1370,43 @@ parse_makernote(FILE * const ifp) its own byte-order!), or it might just be a table. */ sorder = order; - fread (buf, 1, 10, ifp); + fread_nofail (buf, 1, 10, ifp); if (!strncmp (buf,"KC" ,2) || /* these aren't TIFF format */ !strncmp (buf,"MLY",3)) return; if (!strcmp (buf,"Nikon")) { - base = ftell(ifp); + base = ftell_nofail(ifp); order = get2(ifp); if (get2(ifp) != 42) goto quit; offset = get4(ifp); - fseek (ifp, offset-8, SEEK_CUR); + fseek_nofail (ifp, offset-8, SEEK_CUR); } else if (!strncmp (buf,"FUJIFILM",8) || !strcmp (buf,"Panasonic")) { order = 0x4949; - fseek (ifp, 2, SEEK_CUR); + fseek_nofail (ifp, 2, SEEK_CUR); } else if (!strcmp (buf,"OLYMP") || !strcmp (buf,"LEICA") || !strcmp (buf,"EPSON")) - fseek (ifp, -2, SEEK_CUR); + fseek_nofail (ifp, -2, SEEK_CUR); else if (!strcmp (buf,"AOC") || !strcmp (buf,"QVC")) - fseek (ifp, -4, SEEK_CUR); - else fseek (ifp, -10, SEEK_CUR); + fseek_nofail (ifp, -4, SEEK_CUR); + else fseek_nofail (ifp, -10, SEEK_CUR); entries = get2(ifp); while (entries--) { tag = get2(ifp); type = get2(ifp); len = get4(ifp); - save = ftell(ifp); + save = ftell_nofail(ifp); if (len * size[type < 13 ? type:0] > 4) - fseek (ifp, get4(ifp)+base, SEEK_SET); + fseek_nofail (ifp, get4(ifp)+base, SEEK_SET); if (tag == 0xc && len == 4) { camera_red = getrat(); camera_blue = getrat(); } if (tag == 0x14 && len == 2560 && type == 7) { - fseek (ifp, 1248, SEEK_CUR); + fseek_nofail (ifp, 1248, SEEK_CUR); goto get2_256; } if (strstr(make,"PENTAX")) { @@ -1413,19 +1414,19 @@ parse_makernote(FILE * const ifp) if (tag == 0x1c) tag = 0x1017; } if (tag == 0x8c) - nikon_curve_offset = ftell(ifp) + 2112; + nikon_curve_offset = ftell_nofail(ifp) + 2112; if (tag == 0x96) - nikon_curve_offset = ftell(ifp) + 2; + nikon_curve_offset = ftell_nofail(ifp) + 2; if (tag == 0x97) { if (!strcmp(model,"NIKON D100 ")) { - fseek (ifp, 72, SEEK_CUR); + fseek_nofail (ifp, 72, SEEK_CUR); camera_red = get2(ifp) / 256.0; camera_blue = get2(ifp) / 256.0; } else if (!strcmp(model,"NIKON D2H")) { - fseek (ifp, 10, SEEK_CUR); + fseek_nofail (ifp, 10, SEEK_CUR); goto get2_rggb; } else if (!strcmp(model,"NIKON D70")) { - fseek (ifp, 20, SEEK_CUR); + fseek_nofail (ifp, 20, SEEK_CUR); camera_red = get2(ifp); camera_red /= get2(ifp); camera_blue = get2(ifp); @@ -1449,12 +1450,12 @@ parse_makernote(FILE * const ifp) black = (get4(ifp)+get4(ifp)+get4(ifp)+get4(ifp))/4; } if (tag == 0xe80 && len == 256 && type == 7) { - fseek (ifp, 48, SEEK_CUR); + fseek_nofail (ifp, 48, SEEK_CUR); camera_red = get2(ifp) * 508 * 1.078 / 0x10000; camera_blue = get2(ifp) * 382 * 1.173 / 0x10000; } if (tag == 0xf00 && len == 614 && type == 7) { - fseek (ifp, 188, SEEK_CUR); + fseek_nofail (ifp, 188, SEEK_CUR); goto get2_256; } if (tag == 0x1017) @@ -1468,14 +1469,14 @@ get2_256: camera_blue = get2(ifp) / 256.0; } if (tag == 0x4001) { - fseek (ifp, strstr(model,"EOS-1D") ? 68:50, SEEK_CUR); + fseek_nofail (ifp, strstr(model,"EOS-1D") ? 68:50, SEEK_CUR); get2_rggb: camera_red = get2(ifp); camera_red /= get2(ifp); camera_blue = get2(ifp); camera_blue = get2(ifp) / camera_blue; } - fseek (ifp, save+4, SEEK_SET); + fseek_nofail (ifp, save+4, SEEK_SET); } quit: order = sorder; @@ -1514,8 +1515,8 @@ parse_exif(FILE * const ifp, int base) /* type = */ get2(ifp); len = get4(ifp); val = get4(ifp); - save = ftell(ifp); - fseek (ifp, base+val, SEEK_SET); + save = ftell_nofail(ifp); + fseek_nofail (ifp, base+val, SEEK_SET); if (tag == 0x9003 || tag == 0x9004) get_timestamp(ifp); if (tag == 0x927c) { @@ -1524,7 +1525,7 @@ parse_exif(FILE * const ifp, int base) else parse_makernote(ifp); } - fseek (ifp, save, SEEK_SET); + fseek_nofail (ifp, save, SEEK_SET); } } @@ -1550,10 +1551,10 @@ parse_tiff_ifd(FILE * const ifp, int base, int level) tag = get2(ifp); type = get2(ifp); len = get4(ifp); - save = ftell(ifp); + save = ftell_nofail(ifp); if (tag > 50700 && tag < 50800) done = 1; if (len * size[type < 13 ? type:0] > 4) - fseek (ifp, get4(ifp)+base, SEEK_SET); + fseek_nofail (ifp, get4(ifp)+base, SEEK_SET); switch (tag) { case 0x11: camera_red = get4(ifp) / 256.0; @@ -1580,10 +1581,10 @@ parse_tiff_ifd(FILE * const ifp, int base, int level) kodak_data_compression = get2(ifp); break; case 0x10f: /* Make */ - fgets (make, 64, ifp); + fgets_nofail (make, 64, ifp); break; case 0x110: /* Model */ - fgets (model, 64, ifp); + fgets_nofail (model, 64, ifp); break; case 0x111: /* StripOffset */ data_offset = get4(ifp); @@ -1595,7 +1596,7 @@ parse_tiff_ifd(FILE * const ifp, int base, int level) tiff_samples = get2(ifp); break; case 0x131: /* Software tag */ - fgets (software, 64, ifp); + fgets_nofail (software, 64, ifp); if (!strncmp(software,"Adobe",5)) make[0] = 0; break; @@ -1604,7 +1605,7 @@ parse_tiff_ifd(FILE * const ifp, int base, int level) break; case 0x144: /* TileOffsets */ if (level) { - data_offset = ftell(ifp); + data_offset = ftell_nofail(ifp); } else { strcpy (make, "Leaf"); data_offset = get4(ifp); @@ -1614,18 +1615,18 @@ parse_tiff_ifd(FILE * const ifp, int base, int level) if (len > 2 && !is_dng && !strcmp(make,"Kodak")) len = 2; while (len--) { - i = ftell(ifp); - fseek (ifp, get4(ifp)+base, SEEK_SET); + i = ftell_nofail(ifp); + fseek_nofail (ifp, get4(ifp)+base, SEEK_SET); if (parse_tiff_ifd(ifp, base, level+1)) break; - fseek (ifp, i+4, SEEK_SET); + fseek_nofail (ifp, i+4, SEEK_SET); } break; case 33405: /* Model2 */ - fgets (model2, 64, ifp); + fgets_nofail (model2, 64, ifp); break; case 33422: /* CFAPattern */ if ((plen=len) > 16) plen = 16; - fread (cfa_pat, 1, plen, ifp); + fread_nofail (cfa_pat, 1, plen, ifp); for (colors=cfa=i=0; i < plen; i++) { colors += !(cfa & (1 << cfa_pat[i])); cfa |= 1 << cfa_pat[i]; @@ -1634,7 +1635,7 @@ parse_tiff_ifd(FILE * const ifp, int base, int level) if (cfa == 072) memcpy (cfa_pc,"\005\003\004\001",4); /* GMCY */ goto guess_cfa_pc; case 34665: /* EXIF tag */ - fseek (ifp, get4(ifp)+base, SEEK_SET); + fseek_nofail (ifp, get4(ifp)+base, SEEK_SET); parse_exif(ifp, base); break; case 50706: /* DNGVersion */ @@ -1644,7 +1645,7 @@ parse_tiff_ifd(FILE * const ifp, int base, int level) case 50710: /* CFAPlaneColor */ if (len > 4) len = 4; colors = len; - fread (cfa_pc, 1, colors, ifp); + fread_nofail (cfa_pc, 1, colors, ifp); guess_cfa_pc: FORC4 tab[cfa_pc[c]] = c; for (i=16; i--; ) @@ -1701,7 +1702,7 @@ guess_cfa_pc: xyz[1] = getrat(); xyz[2] = 1 - xyz[0] - xyz[1]; } - fseek (ifp, save+4, SEEK_SET); + fseek_nofail (ifp, save+4, SEEK_SET); } for (i=0; i < colors; i++) FORC4 cc[i][c] *= ab[i]; @@ -1729,16 +1730,16 @@ parse_tiff(FILE * const ifp, int base) { int doff; - fseek (ifp, base, SEEK_SET); + fseek_nofail (ifp, base, SEEK_SET); order = get2(ifp); if (order != 0x4949 && order != 0x4d4d) return; get2(ifp); while ((doff = get4(ifp))) { - fseek (ifp, doff+base, SEEK_SET); + fseek_nofail (ifp, doff+base, SEEK_SET); if (parse_tiff_ifd(ifp, base, 0)) break; } if (!is_dng && !strncmp(make,"Kodak",5)) { - fseek (ifp, 12+base, SEEK_SET); + fseek_nofail (ifp, 12+base, SEEK_SET); parse_tiff_ifd(ifp, base, 2); } } diff --git a/converter/other/cameratopam/canon.c b/converter/other/cameratopam/canon.c index 96a6210b..cbf5ece0 100644 --- a/converter/other/cameratopam/canon.c +++ b/converter/other/cameratopam/canon.c @@ -6,9 +6,10 @@ #include "decode.h" #include "bayer.h" #include "canon.h" +#include "stdio_nofail.h" -void +void canon_600_load_raw(Image const image) { unsigned char data[1120], *dp; unsigned short pixel[896], *pix; @@ -16,7 +17,7 @@ canon_600_load_raw(Image const image) { for (irow=orow=0; irow < height; irow++) { - fread (data, 1120, 1, ifp); + fread_nofail (data, 1120, 1, ifp); for (dp=data, pix=pixel; dp < data+1120; dp+=10, pix+=8) { pix[0] = (dp[0] << 2) + (dp[1] >> 6 ); @@ -48,7 +49,7 @@ canon_a5_load_raw(Image const image) { int row, col; for (row=0; row < height; row++) { - fread (data, raw_width * 10 / 8, 1, ifp); + fread_nofail (data, raw_width * 10 / 8, 1, ifp); for (dp=data, pix=pixel; pix < pixel+raw_width; dp+=10, pix+=8) { pix[0] = (dp[1] << 2) + (dp[0] >> 6); @@ -84,8 +85,8 @@ canon_has_lowbits() unsigned char test[0x4000]; int ret=1, i; - fseek (ifp, 0, SEEK_SET); - fread (test, 1, sizeof test, ifp); + fseek_nofail (ifp, 0, SEEK_SET); + fread_nofail (test, 1, sizeof test, ifp); for (i=540; i < sizeof test - 1; i++) if (test[i] == 0xff) { if (test[i+1]) return 1; @@ -96,7 +97,7 @@ canon_has_lowbits() -void +void canon_compressed_load_raw(Image const image) { unsigned short *pixel, *prow; int lowbits, i, row, r, col, save, val; @@ -110,7 +111,7 @@ canon_compressed_load_raw(Image const image) { pm_error("Unable to allocate space for %u pixels", raw_width*8); lowbits = canon_has_lowbits(); if (!lowbits) maximum = 0x3ff; - fseek (ifp, 540 + lowbits*raw_height*raw_width/4, SEEK_SET); + fseek_nofail (ifp, 540 + lowbits*raw_height*raw_width/4, SEEK_SET); zero_after_ff = 1; getbits(ifp, -1); for (row = 0; row < raw_height; row += 8) { @@ -141,17 +142,17 @@ canon_compressed_load_raw(Image const image) { } } if (lowbits) { - save = ftell(ifp); - fseek (ifp, 26 + row*raw_width/4, SEEK_SET); + save = ftell_nofail(ifp); + fseek_nofail (ifp, 26 + row*raw_width/4, SEEK_SET); for (prow=pixel, i=0; i < raw_width*2; i++) { - c = fgetc(ifp); + c = fgetc_nofail(ifp); for (r=0; r < 8; r+=2, prow++) { val = (*prow << 2) + ((c >> r) & 3); if (raw_width == 2672 && val < 512) val += 2; *prow = val; } } - fseek (ifp, save, SEEK_SET); + fseek_nofail (ifp, save, SEEK_SET); } for (r=0; r < 8; r++) { irow = row - top_margin + r; @@ -169,4 +170,3 @@ canon_compressed_load_raw(Image const image) { if (raw_width > width) black /= (raw_width - width) * height; } - diff --git a/converter/other/cameratopam/foveon.c b/converter/other/cameratopam/foveon.c index 992f3883..5a26777b 100644 --- a/converter/other/cameratopam/foveon.c +++ b/converter/other/cameratopam/foveon.c @@ -2,7 +2,6 @@ #define _XOPEN_SOURCE 500 /* get M_PI in math.h */ -#include <stdio.h> #include <assert.h> #include <string.h> #include <float.h> @@ -13,6 +12,7 @@ #include "global_variables.h" #include "decode.h" #include "foveon.h" +#include "stdio_nofail.h" #if HAVE_INT64 typedef int64_t INT64; @@ -32,13 +32,13 @@ -static char * -foveon_gets(int const offset, - char * const str, +static char * +foveon_gets(int const offset, + char * const str, int const len) { unsigned int i; - fseek (ifp, offset, SEEK_SET); + fseek_nofail (ifp, offset, SEEK_SET); for (i=0; i < len-1; ++i) { /* It certains seems wrong that we're reading a 16 bit integer and assigning it to char, but that's what Dcraw does. @@ -55,7 +55,7 @@ foveon_gets(int const offset, -void +void parse_foveon(FILE * const ifp) { long fliplong; long pos; @@ -63,14 +63,14 @@ parse_foveon(FILE * const ifp) { long junk; long entries; - fseek (ifp, 36, SEEK_SET); + fseek_nofail (ifp, 36, SEEK_SET); pm_readlittlelong(ifp, &fliplong); flip = fliplong; - fseek (ifp, -4, SEEK_END); + fseek_nofail (ifp, -4, SEEK_END); pm_readlittlelong(ifp, &pos); - fseek (ifp, pos, SEEK_SET); + fseek_nofail (ifp, pos, SEEK_SET); pm_readlittlelong(ifp, &magic); - if (magic != 0x64434553) + if (magic != 0x64434553) return; /* SECd */ pm_readlittlelong(ifp, &junk); pm_readlittlelong(ifp, &entries); @@ -85,17 +85,17 @@ parse_foveon(FILE * const ifp) { pm_readlittlelong(ifp, &off); pm_readlittlelong(ifp, &len); pm_readlittlelong(ifp, &tag); - - save = ftell(ifp); - fseek (ifp, off, SEEK_SET); + + save = ftell_nofail(ifp); + fseek_nofail (ifp, off, SEEK_SET); pm_readlittlelong(ifp, &sec_); if (sec_ != (0x20434553 | (tag << 24))) return; switch (tag) { case 0x47414d49: /* IMAG */ - if (data_offset) + if (data_offset) break; data_offset = off + 28; - fseek (ifp, 12, SEEK_CUR); + fseek_nofail (ifp, 12, SEEK_CUR); { long wlong, hlong; pm_readlittlelong(ifp, &wlong); @@ -113,7 +113,7 @@ parse_foveon(FILE * const ifp) { case 0x504f5250: /* PROP */ pm_readlittlelong(ifp, &junk); pm_readlittlelong(ifp, &pent); - fseek (ifp, 12, SEEK_CUR); + fseek_nofail (ifp, 12, SEEK_CUR); off += pent*8 + 24; if (pent > 256) pent=256; for (i=0; i < pent*2; i++) { @@ -133,14 +133,14 @@ parse_foveon(FILE * const ifp) { timestamp = atoi (foveon_gets (poff[i][1], name, 64)); } } - fseek (ifp, save, SEEK_SET); + fseek_nofail (ifp, save, SEEK_SET); } is_foveon = 1; } -void +void foveon_coeff(int * const useCoeffP, float coeff[3][4]) { @@ -159,8 +159,8 @@ foveon_coeff(int * const useCoeffP, -static void -foveon_decoder (unsigned int const huff[1024], +static void +foveon_decoder (unsigned int const huff[1024], unsigned int const code) { struct decode *cur; @@ -180,7 +180,7 @@ foveon_decoder (unsigned int const huff[1024], } } } - if ((len = code >> 27) > 26) + if ((len = code >> 27) > 26) return; code2 = (len+1) << 27 | (code & 0x3ffffff) << 1; @@ -192,14 +192,14 @@ foveon_decoder (unsigned int const huff[1024], -static void +static void foveon_load_camf() { unsigned int i, val; long key; - fseek (ifp, meta_offset, SEEK_SET); + fseek_nofail (ifp, meta_offset, SEEK_SET); pm_readlittlelong(ifp, &key); - fread (meta_data, 1, meta_length, ifp); + fread_nofail (meta_data, 1, meta_length, ifp); for (i=0; i < meta_length; i++) { key = (key * 1597 + 51749) % 244944; assert(have64BitArithmetic); @@ -210,7 +210,7 @@ foveon_load_camf() { -void +void foveon_load_raw(Image const image) { struct decode *dindex; @@ -234,14 +234,14 @@ foveon_load_raw(Image const image) { for (row=0; row < height; row++) { long junk; memset (pred, 0, sizeof pred); - if (!bit) + if (!bit) pm_readlittlelong(ifp, &junk); for (col=bit=0; col < width; col++) { FORC3 { for (dindex=first_decode; dindex->branch[0]; ) { if ((bit = (bit-1) & 31) == 31) for (i=0; i < 4; i++) - bitbuf = (bitbuf << 8) + fgetc(ifp); + bitbuf = (bitbuf << 8) + fgetc_nofail(ifp); dindex = dindex->branch[bitbuf >> bit & 1]; } pred[c] += diff[dindex->leaf]; @@ -262,8 +262,8 @@ sget4(char const s[]) { -static char * -foveon_camf_param (const char * const block, +static char * +foveon_camf_param (const char * const block, const char * const param) { unsigned idx, num; char *pos, *cp, *dp; @@ -287,8 +287,8 @@ foveon_camf_param (const char * const block, -static void * -foveon_camf_matrix (int dim[3], +static void * +foveon_camf_matrix (int dim[3], const char * const name) { unsigned i, idx, type, ndim, size, *mat; @@ -325,9 +325,9 @@ foveon_camf_matrix (int dim[3], -static int -foveon_fixed (void * const ptr, - int const size, +static int +foveon_fixed (void * const ptr, + int const size, const char * const name) { void *dp; int dim[3]; @@ -345,7 +345,7 @@ static float foveon_avg (unsigned short *pix, int range[2], float cfilt) float val, min=FLT_MAX, max=-FLT_MAX, sum=0; for (i=range[0]; i <= range[1]; i++) { - sum += val = + sum += val = (short)pix[i*4] + ((short)pix[i*4]-(short)pix[(i-1)*4]) * cfilt; if (min > val) min = val; if (max < val) max = val; @@ -390,11 +390,11 @@ static int foveon_apply_curve (short *curve, int i) return i < 0 ? -(unsigned short)curve[1-i] : (unsigned short)curve[1+i]; } -void +void foveon_interpolate(Image const image, float coeff[3][4]) { - static const short hood[] = { + static const short hood[] = { -1,-1, -1,0, -1,1, 0,-1, 0,1, 1,-1, 1,0, 1,1 }; short *pix, prev[3], *curve[8], (*shrink)[3]; float cfilt=0.8, ddft[3][3][2], ppm[3][3][3]; @@ -441,7 +441,7 @@ foveon_interpolate(Image const image, for (i=0; i < 3; i++) FORC3 diag[c][i] = LAST(1,1)*LAST(2,2) - LAST(1,2)*LAST(2,1); #undef LAST - FORC3 div[c] = + FORC3 div[c] = diag[c][0]*0.3127 + diag[c][1]*0.329 + diag[c][2]*0.3583; } num = 0; @@ -494,11 +494,11 @@ foveon_interpolate(Image const image, for (row=1; row < height-1; row++) { FORC3 if (last[1][c] > last[0][c]) { if (last[1][c] > last[2][c]) - black[row][c] = + black[row][c] = (last[0][c] > last[2][c]) ? last[0][c]:last[2][c]; } else if (last[1][c] < last[2][c]) - black[row][c] = + black[row][c] = (last[0][c] < last[2][c]) ? last[0][c]:last[2][c]; memmove (last, last+1, 2*sizeof last[0]); memcpy (last[2], black[row+1], sizeof last[2]); @@ -547,8 +547,8 @@ foveon_interpolate(Image const image, diff = pix[c] - prev[c]; prev[c] = pix[c]; ipix[c] = pix[c] + floor ((diff + (diff*diff >> 14)) * cfilt - - ddft[0][c][1] - - ddft[0][c][0] + - ddft[0][c][1] + - ddft[0][c][0] * ((float) col/width - 0.5) - black[row][c] ); } @@ -563,7 +563,7 @@ foveon_interpolate(Image const image, val += ppm[c][i][j] * work[i][j]; ipix[c] = floor ((ipix[c] + floor(val)) * ( sgrow[col/sgx ][c] * (sgx - col%sgx) + - sgrow[col/sgx+1][c] * (col%sgx) ) / sgx / + sgrow[col/sgx+1][c] * (col%sgx) ) / sgx / div[c]); if (ipix[c] > 32000) ipix[c] = 32000; pix[c] = ipix[c]; @@ -584,7 +584,7 @@ foveon_interpolate(Image const image, memset (fsum, 0, sizeof fsum); for (sum=j=0; j < 8; j++) if (badpix[i] & (1 << j)) { - FORC3 fsum[c] += + FORC3 fsum[c] += image[(row+hood[j*2])*width+col+hood[j*2+1]][c]; sum++; } @@ -665,8 +665,8 @@ foveon_interpolate(Image const image, pix = (short*)image[row*width+2]; for (col=2; col < width-2; col++) { FORC3 dev[c] = -foveon_apply_curve (curve[7], pix[c] - - ((smrow[1][col][c] + - 2*smrow[2][col][c] + + ((smrow[1][col][c] + + 2*smrow[2][col][c] + smrow[3][col][c]) >> 2)); sum = (dev[0] + dev[1] + dev[2]) >> 3; FORC3 pix[c] += dev[c] - sum; @@ -695,7 +695,7 @@ foveon_interpolate(Image const image, if (sum < 0) sum = 0; j = total[3] > 375 ? (sum << 16) / total[3] : sum * 174; FORC3 pix[c] += foveon_apply_curve (curve[6], - ((j*total[c] + 0x8000) >> 16) + ((j*total[c] + 0x8000) >> 16) - pix[c]); pix += 4; } @@ -732,7 +732,7 @@ foveon_interpolate(Image const image, shrink[row*(width/4)+col][c] = ipix[c] >> 4; else shrink[row*(width/4)+col][c] = - (shrink[(row+1)*(width/4)+col][c]*1840 + + (shrink[(row+1)*(width/4)+col][c]*1840 + ipix[c]*141 + 2048) >> 12; } } @@ -742,7 +742,7 @@ foveon_interpolate(Image const image, if ((row & 3) == 0) for (col = width & ~3 ; col--; ) FORC3 smrow[0][col][c] = ipix[c] = - (shrink[(row/4)*(width/4)+col/4][c]*1485 + + (shrink[(row/4)*(width/4)+col/4][c]*1485 + ipix[c]*6707 + 4096) >> 13; /* Then smooth left-to-right */ @@ -757,7 +757,7 @@ foveon_interpolate(Image const image, else for (col=0; col < (width & ~3); col++) FORC3 smrow[2][col][c] = - (smrow[2][col][c]*6707 + smrow[1][col][c]*1485 + 4096) + (smrow[2][col][c]*6707 + smrow[1][col][c]*1485 + 4096) >> 13; /* Adjust the chroma toward the smooth values */ @@ -770,7 +770,7 @@ foveon_interpolate(Image const image, for (sum=c=0; c < 3; c++) { ipix[c] = foveon_apply_curve( curve[c+3], - ((smrow[2][col][c] * j + 0x8000) >> 16) - + ((smrow[2][col][c] * j + 0x8000) >> 16) - image[row*width+col][c]); sum += ipix[c]; } diff --git a/converter/other/cameratopam/identify.c b/converter/other/cameratopam/identify.c index 26fa329e..e5df6b22 100644 --- a/converter/other/cameratopam/identify.c +++ b/converter/other/cameratopam/identify.c @@ -13,6 +13,7 @@ #include "dng.h" #include "ljpeg.h" #include "camera.h" +#include "stdio_nofail.h" #include "identify.h" @@ -38,7 +39,7 @@ static const char *memmem_internal (const char *haystack, size_t haystacklen, -static void +static void adobeCoeff(const char * const make, const char * const model) { /* @@ -47,7 +48,7 @@ adobeCoeff(const char * const make, struct CoeffTableEntry { const char * prefix; short trans[12]; - }; + }; static struct CoeffTableEntry const table[] = { { "Canon EOS D2000C", @@ -331,17 +332,17 @@ identify(FILE * const ifp, order = get2(ifp); hlen = get4(ifp); - fseek (ifp, 0, SEEK_SET); - fread (head, 1, 32, ifp); - fseek (ifp, 0, SEEK_END); - fsize = ftell(ifp); + fseek_nofail (ifp, 0, SEEK_SET); + fread_nofail (head, 1, 32, ifp); + fseek_nofail (ifp, 0, SEEK_END); + fsize = ftell_nofail(ifp); if ((c = (char*)memmem_internal(head, 32, "MMMMRawT", 8))) { strcpy (make, "Phase One"); data_offset = c - head; - fseek (ifp, data_offset + 8, SEEK_SET); - fseek (ifp, get4(ifp) + 136, SEEK_CUR); + fseek_nofail (ifp, data_offset + 8, SEEK_SET); + fseek_nofail (ifp, get4(ifp) + 136, SEEK_CUR); raw_width = get4(ifp); - fseek (ifp, 12, SEEK_CUR); + fseek_nofail (ifp, 12, SEEK_CUR); raw_height = get4(ifp); } else if (order == 0x4949 || order == 0x4d4d) { if (!memcmp (head+6, "HEAPCCDR", 8)) { @@ -356,14 +357,14 @@ identify(FILE * const ifp, parse_minolta(ifp); else if (!memcmp (head, "\xff\xd8\xff\xe1", 4) && !memcmp (head+6, "Exif", 4)) { - fseek (ifp, 4, SEEK_SET); - fseek (ifp, 4 + get2(ifp), SEEK_SET); - if (fgetc(ifp) != 0xff) + fseek_nofail (ifp, 4, SEEK_SET); + fseek_nofail (ifp, 4 + get2(ifp), SEEK_SET); + if (fgetc_nofail(ifp) != 0xff) parse_tiff(ifp, 12); } else if (!memcmp (head, "BM", 2)) { data_offset = 0x1000; order = 0x4949; - fseek (ifp, 38, SEEK_SET); + fseek_nofail (ifp, 38, SEEK_SET); if (get4(ifp) == 2834 && get4(ifp) == 2834) { strcpy (model, "BMQ"); flip = 3; @@ -374,7 +375,7 @@ identify(FILE * const ifp, nucore: strcpy (make, "Nucore"); order = 0x4949; - fseek (ifp, 10, SEEK_SET); + fseek_nofail (ifp, 10, SEEK_SET); data_offset += get4(ifp); get4(ifp); raw_width = get4(ifp); @@ -386,16 +387,16 @@ identify(FILE * const ifp, } else if (!memcmp (head+25, "ARECOYK", 7)) { strcpy (make, "Contax"); strcpy (model,"N Digital"); - fseek (ifp, 60, SEEK_SET); + fseek_nofail (ifp, 60, SEEK_SET); camera_red = get4(ifp); camera_red /= get4(ifp); camera_blue = get4(ifp); camera_blue = get4(ifp) / camera_blue; } else if (!memcmp (head, "FUJIFILM", 8)) { long data_offset_long; - fseek (ifp, 84, SEEK_SET); + fseek_nofail (ifp, 84, SEEK_SET); parse_tiff(ifp, get4(ifp)+12); - fseek (ifp, 100, SEEK_SET); + fseek_nofail (ifp, 100, SEEK_SET); pm_readbiglong(ifp, &data_offset_long); data_offset = data_offset_long; } else if (!memcmp (head, "DSC-Image", 9)) @@ -737,13 +738,13 @@ identify(FILE * const ifp, width = 2312; raw_width = 2336; data_offset = 4034; - fseek (ifp, 2032, SEEK_SET); + fseek_nofail (ifp, 2032, SEEK_SET); goto konica_400z; } else if (!strcmp(model,"Digital Camera KD-510Z")) { data_offset = 4032; pre_mul[0] = 1.297; pre_mul[2] = 1.438; - fseek (ifp, 2032, SEEK_SET); + fseek_nofail (ifp, 2032, SEEK_SET); goto konica_510z; } else if (!strcasecmp(make,"MINOLTA")) { load_raw = unpacked_load_raw; @@ -767,19 +768,19 @@ identify(FILE * const ifp, data_offset = 5056; pre_mul[0] = 1.602; pre_mul[2] = 1.441; - fseek (ifp, 2078, SEEK_SET); + fseek_nofail (ifp, 2078, SEEK_SET); height = 1716; width = 2304; } else if (model[8] == '5') { data_offset = 4016; - fseek (ifp, 1936, SEEK_SET); + fseek_nofail (ifp, 1936, SEEK_SET); konica_510z: height = 1956; width = 2607; raw_width = 2624; } else if (model[8] == '6') { data_offset = 4032; - fseek (ifp, 2030, SEEK_SET); + fseek_nofail (ifp, 2030, SEEK_SET); height = 2136; width = 2848; } @@ -885,7 +886,7 @@ identify(FILE * const ifp, pre_mul[0] = 1.963; pre_mul[2] = 1.430; } else if (!strcmp(make,"Sinar") && !memcmp(head,"8BPS",4)) { - fseek (ifp, 14, SEEK_SET); + fseek_nofail (ifp, 14, SEEK_SET); height = get4(ifp); width = get4(ifp); filters = 0x61616161; @@ -1199,7 +1200,7 @@ dng_skip: for (i=0; i < 3; i++) coeff[i][3] = coeff[i][1] /= 2; } - fseek (ifp, data_offset, SEEK_SET); + fseek_nofail (ifp, data_offset, SEEK_SET); *loadRawFnP = load_raw; diff --git a/converter/other/cameratopam/ljpeg.c b/converter/other/cameratopam/ljpeg.c index 331d258c..35f50f4b 100644 --- a/converter/other/cameratopam/ljpeg.c +++ b/converter/other/cameratopam/ljpeg.c @@ -2,7 +2,6 @@ #define _BSD_SOURCE /* Make sure string.h containst strcasecmp() */ #include <stdlib.h> #include <string.h> -#include <stdio.h> #include <limits.h> #include "pm.h" @@ -11,6 +10,7 @@ #include "util.h" #include "decode.h" #include "bayer.h" +#include "stdio_nofail.h" #include "ljpeg.h" @@ -20,7 +20,7 @@ enough to decode Canon, Kodak and Adobe DNG images. */ -int +int ljpeg_start(FILE * const ifP, struct jhead * const jhP) { @@ -30,12 +30,12 @@ ljpeg_start(FILE * const ifP, init_decoder(); for (i=0; i < 4; i++) jhP->huff[i] = free_decode; - fread (data, 2, 1, ifP); + fread_nofail (data, 2, 1, ifP); if (data[0] != 0xff || data[1] != 0xd8) return 0; do { unsigned int len; - fread (data, 2, 2, ifP); + fread_nofail (data, 2, 2, ifP); tag = data[0] << 8 | data[1]; len = data[2] << 8 | data[3]; @@ -45,7 +45,7 @@ ljpeg_start(FILE * const ifP, unsigned int const dataLen = len - 2; if (tag <= 0xff00 || dataLen > 255) return 0; - fread (data, 1, dataLen, ifP); + fread_nofail (data, 1, dataLen, ifP); switch (tag) { case 0xffc3: jhP->bits = data[0]; @@ -73,7 +73,7 @@ ljpeg_start(FILE * const ifP, -int +int ljpeg_diff(FILE * const ifP, struct decode * const dindexHeadP) { @@ -111,7 +111,7 @@ ljpeg_row(FILE * const ifP, -void +void lossless_jpeg_load_raw(Image const image) { int jwide, jrow, jcol, val, jidx, i, row, col; @@ -161,5 +161,3 @@ lossless_jpeg_load_raw(Image const image) { if (!strcasecmp(make,"KODAK")) black = min; } - - diff --git a/converter/other/cameratopam/stdio_nofail.c b/converter/other/cameratopam/stdio_nofail.c new file mode 100644 index 00000000..97a8796d --- /dev/null +++ b/converter/other/cameratopam/stdio_nofail.c @@ -0,0 +1,120 @@ +#include <stdio.h> +#include <string.h> +#include <errno.h> + +#include <netpbm/pm.h> + +#include "stdio_nofail.h" + + + +size_t +fread_or_eof_nofail(void * const ptr, + size_t const size, + size_t const nmemb, + FILE * const streamP) { + + size_t rc; + + rc = fread(ptr, size, nmemb, streamP); + + if (rc < nmemb) { + if (!feof(streamP)) + pm_error("File read failed. Errno=%d (%s)", + errno, strerror(errno)); + } + return rc; +} + + + +void +fread_nofail(void * const ptr, + size_t const size, + size_t const nmemb, + FILE * const streamP) { + + size_t rc; + + rc = fread(ptr, size, nmemb, streamP); + + if (rc < nmemb) { + if (feof(streamP)) + pm_error("File read failed. Premature end of file"); + else + pm_error("File read failed. Errno=%d (%s)", + errno, strerror(errno)); + } +} + + + +int +fgetc_nofail(FILE * streamP) { + + int rc; + + rc = fgetc(streamP); + + if (rc == EOF) { + if (feof(streamP)) + pm_error("File read failed. Premature end of file"); + else + pm_error("File read failed. Errno=%d (%s)", + errno, strerror(errno)); + } + return rc; +} + + + +int +fseek_nofail(FILE * const streamP, + long const offset, + int const whence) { + + int rc; + + rc = fseek(streamP, offset, whence); + + if (rc < 0) + pm_error("File seek failed. Errno=%d (%s)", errno, strerror(errno)); + + return rc; +} + + + +long +ftell_nofail(FILE * const streamP) { + + long rc; + + rc = ftell(streamP); + + if (rc < 0) + pm_error("File position query failed. Errno=%d (%s)", + errno, strerror(errno)); + + return rc; +} + + + +char * +fgets_nofail(char * const s, + int const size, + FILE * const streamP) { + + char * rc; + + rc = fgets(s, size, streamP); + + if (ferror(streamP)) + pm_error("File read failed. Errno=%d (%s)", errno, strerror(errno)); + + return rc; +} + + + diff --git a/converter/other/cameratopam/stdio_nofail.h b/converter/other/cameratopam/stdio_nofail.h new file mode 100644 index 00000000..8f45b537 --- /dev/null +++ b/converter/other/cameratopam/stdio_nofail.h @@ -0,0 +1,29 @@ +#include <stdio.h> + +size_t +fread_or_eof_nofail(void * const ptr, + size_t const size, + size_t const nmemb, + FILE * const streamP); + +void +fread_nofail(void * const ptr, + size_t const size, + size_t const nmemb, + FILE * const streamP); + +int +fgetc_nofail(FILE * const streamP); + +int +fseek_nofail(FILE * const streamP, + long const offset, + int const whence); + +long +ftell_nofail(FILE * const streamP); + +char * +fgets_nofail(char * const s, + int const size, + FILE * const streamP); diff --git a/converter/other/cameratopam/util.c b/converter/other/cameratopam/util.c index b3ccf7e9..ede5ef69 100644 --- a/converter/other/cameratopam/util.c +++ b/converter/other/cameratopam/util.c @@ -1,10 +1,12 @@ #define _XOPEN_SOURCE /* Make sure unistd.h contains swab() */ #include <unistd.h> -#include <stdio.h> -#include "pm.h" +#include "netpbm/pm.h" +#include "netpbm/mallocvar.h" + #include "global_variables.h" #include "util.h" +#include "stdio_nofail.h" #ifndef LONG_BITS #define LONG_BITS (8 * sizeof(long)) @@ -18,7 +20,7 @@ get2(FILE * const ifp) { unsigned char a, b; - a = fgetc(ifp); b = fgetc(ifp); + a = fgetc_nofail(ifp); b = fgetc_nofail(ifp); if (order == 0x4949) /* "II" means little-endian */ return a | b << 8; @@ -34,8 +36,8 @@ get4(FILE * const ifp) { unsigned char a, b, c, d; - a = fgetc(ifp); b = fgetc(ifp); - c = fgetc(ifp); d = fgetc(ifp); + a = fgetc_nofail(ifp); b = fgetc_nofail(ifp); + c = fgetc_nofail(ifp); d = fgetc_nofail(ifp); if (order == 0x4949) return a | b << 8 | c << 16 | d << 24; @@ -49,9 +51,21 @@ get4(FILE * const ifp) void read_shorts (FILE * const ifp, unsigned short *pixel, int count) { - fread (pixel, 2, count, ifp); - if ((order == 0x4949) == (BYTE_ORDER == BIG_ENDIAN)) - swab (pixel, pixel, count*2); + unsigned short * buffer; + + MALLOCARRAY(buffer, count); + + if (!buffer) + pm_error("Failed to allocate a buffer for reading %u short " + "integers from file", count); + else { + fread_nofail(buffer, 2, count, ifp); + + if ((order == 0x4949) == (BYTE_ORDER == BIG_ENDIAN)) + swab(buffer, pixel, count*2); + + free(buffer); + } } /* @@ -73,10 +87,10 @@ getbits (FILE * const ifp, int nbits) vbits -= nbits; } while (vbits < LONG_BITS - 7) { - c = fgetc(ifp); + c = fgetc_nofail(ifp); bitbuf = (bitbuf << 8) + c; if (c == 0xff && zero_after_ff) - fgetc(ifp); + fgetc_nofail(ifp); vbits += 8; } return ret; diff --git a/converter/other/fiasco/input/read.c b/converter/other/fiasco/input/read.c index b4fcefc5..c3aa77a8 100644 --- a/converter/other/fiasco/input/read.c +++ b/converter/other/fiasco/input/read.c @@ -261,7 +261,7 @@ read_basis (const char *filename, wfa_t *wfa) if (fscanf (input, MAXSTRLEN_SCANF, magic) != 1) error ("Format error: ASCII FIASCO initial basis file %s", filename); - else if (strneq (FIASCO_BASIS_MAGIC, magic)) + else if (!streq (FIASCO_BASIS_MAGIC, magic)) error ("Input file %s is not an ASCII FIASCO initial basis!", filename); } diff --git a/converter/other/fiasco/lib/image.c b/converter/other/fiasco/lib/image.c index a700fe88..705a56aa 100644 --- a/converter/other/fiasco/lib/image.c +++ b/converter/other/fiasco/lib/image.c @@ -2,7 +2,7 @@ * image.c: Input and output of PNM images. * * Written by: Ullrich Hafner - * + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -31,7 +31,7 @@ /***************************************************************************** prototypes - + *****************************************************************************/ static void @@ -40,7 +40,7 @@ init_chroma_tables (void); /***************************************************************************** local variables - + *****************************************************************************/ static int *Cr_r_tab = NULL; static int *Cr_g_tab = NULL; @@ -50,7 +50,7 @@ static int *Cb_b_tab = NULL; /***************************************************************************** public code - + *****************************************************************************/ static fiasco_image_t * @@ -197,7 +197,7 @@ cast_image (fiasco_image_t *image) image_t *this = (image_t *) image->private; if (this) { - if (!streq (this->id, "IFIASCO")) + if (!STRSEQ(this->id, "IFIASCO")) { set_error (_("Parameter `image' doesn't match required type.")); return NULL; @@ -240,7 +240,7 @@ alloc_image (unsigned width, unsigned height, bool_t color, format_e format) image->color = color; image->format = format; image->reference_count = 1; - + STRSCPY(image->id, "IFIASCO"); for (band = first_band (color); band <= last_band (color); band++) @@ -249,7 +249,7 @@ alloc_image (unsigned width, unsigned height, bool_t color, format_e format) sizeof (word_t)); else image->pixels [band] = Calloc (width * height, sizeof (word_t)); - + return image; } @@ -266,7 +266,7 @@ clone_image (image_t *image) image_t *new = alloc_image (image->width, image->height, image->color, image->format); color_e band; - + for (band = first_band (new->color); band <= last_band (new->color); band++) if (new->format == FORMAT_4_2_0 && band != Y) { @@ -314,7 +314,7 @@ free_image (image_t *image) } -static void +static void read_image_data(image_t * const image, FILE *input, const bool_t color, const int width, const int height, const xelval maxval, const int format) { @@ -336,27 +336,27 @@ read_image_data(image_t * const image, FILE *input, const bool_t color, xelrow = pnm_allocrow(width); - i = 0; + i = 0; for (row = 0; row < height; row++) { int col; pnm_readpnmrow(input, xelrow, width, maxval, format); for (col = 0; col < width; col++) { if (color) { - image->pixels[Y][i] = - coeff_lu_r * PPM_GETR(xelrow[col]) + image->pixels[Y][i] = + coeff_lu_r * PPM_GETR(xelrow[col]) + coeff_lu_g * PPM_GETG(xelrow[col]) + coeff_lu_b * PPM_GETB(xelrow[col]) - 2048; - image->pixels[Cb][i] = - coeff_cb_r * PPM_GETR(xelrow[col]) + image->pixels[Cb][i] = + coeff_cb_r * PPM_GETR(xelrow[col]) + coeff_cb_g * PPM_GETG(xelrow[col]) + coeff_cb_b * PPM_GETB(xelrow[col]); - image->pixels[Cr][i] = - coeff_cr_r * PPM_GETR(xelrow[col]) + image->pixels[Cr][i] = + coeff_cr_r * PPM_GETR(xelrow[col]) + coeff_cr_g * PPM_GETG(xelrow[col]) + coeff_cr_b * PPM_GETB(xelrow[col]); i++; - } else + } else image->pixels[GRAY][i++] = PNM_GET1(xelrow[col]) * 4095 / maxval - 2048; } @@ -434,7 +434,7 @@ void write_image (const char *image_name, const image_t *image) /* * Write given 'image' data to the file 'image_name'. - * + * * No return value. */ { @@ -446,13 +446,13 @@ write_image (const char *image_name, const image_t *image) unsigned *gray_clip; /* clipping table */ assert (image && image_name); - + if (image->format == FORMAT_4_2_0) { warning ("We cannot write images in 4:2:0 format."); return; } - + if (image_name == NULL) output = stdout; else if (streq(image_name, "-")) @@ -466,7 +466,7 @@ write_image (const char *image_name, const image_t *image) init_chroma_tables (); format = image->color ? PPM_TYPE : PGM_TYPE; - + pnm_writepnminit(output, image->width, image->height, 255, format, 0); xelrow = pnm_allocrow(image->width); @@ -481,18 +481,18 @@ write_image (const char *image_name, const image_t *image) cbval = image->pixels[Cb][i] / 16; crval = image->pixels[Cr][i] / 16; - PPM_ASSIGN(xelrow[col], + PPM_ASSIGN(xelrow[col], gray_clip[yval + Cr_r_tab[crval]], gray_clip[yval + Cr_g_tab[crval] + Cb_g_tab [cbval]], gray_clip[yval + Cb_b_tab[cbval]]); } else /* The 16 below should be 4095/255 = 16.0588 */ - PNM_ASSIGN1(xelrow[col], + PNM_ASSIGN1(xelrow[col], gray_clip[image->pixels[GRAY][i]/16+128]); i++; } - pnm_writepnmrow(output, xelrow, + pnm_writepnmrow(output, xelrow, image->width, 255, format, 0); } pnm_freerow(xelrow); @@ -511,7 +511,7 @@ same_image_type (const image_t *img1, const image_t *img2) */ { assert (img1 && img2); - + return ((img1->width == img2->width) && (img1->height == img2->height) && (img1->color == img2->color) @@ -521,7 +521,7 @@ same_image_type (const image_t *img1, const image_t *img2) /***************************************************************************** private code - + *****************************************************************************/ static void @@ -547,21 +547,21 @@ init_chroma_tables (void) Cr_r_tab[i] = 1.4022 * crval + 0.5; Cr_g_tab[i] = -0.7145 * crval + 0.5; - Cb_g_tab[i] = -0.3456 * cbval + 0.5; + Cb_g_tab[i] = -0.3456 * cbval + 0.5; Cb_b_tab[i] = 1.7710 * cbval + 0.5; } for (i = 0; i < 256; i++) { Cr_r_tab[i] = Cr_r_tab[256]; Cr_g_tab[i] = Cr_g_tab[256]; - Cb_g_tab[i] = Cb_g_tab[256]; + Cb_g_tab[i] = Cb_g_tab[256]; Cb_b_tab[i] = Cb_b_tab[256]; } for (i = 512; i < 768; i++) { Cr_r_tab[i] = Cr_r_tab[511]; Cr_g_tab[i] = Cr_g_tab[511]; - Cb_g_tab[i] = Cb_g_tab[511]; + Cb_g_tab[i] = Cb_g_tab[511]; Cb_b_tab[i] = Cb_b_tab[511]; } diff --git a/converter/other/fiasco/lib/image.h b/converter/other/fiasco/lib/image.h index a87a3c05..c3c5f0df 100644 --- a/converter/other/fiasco/lib/image.h +++ b/converter/other/fiasco/lib/image.h @@ -29,7 +29,7 @@ typedef struct image * Image data */ { - char id [7]; + char id [8]; /* NUL-terminated "IFIASCO" */ unsigned reference_count; unsigned width; /* Width of the image */ unsigned height; /* Height of the image */ diff --git a/converter/other/fiasco/lib/macros.h b/converter/other/fiasco/lib/macros.h index 0bc80e7c..2f404a74 100644 --- a/converter/other/fiasco/lib/macros.h +++ b/converter/other/fiasco/lib/macros.h @@ -34,8 +34,6 @@ *****************************************************************************/ -#define streq(str1, str2) (strcmp ((str1), (str2)) == 0) -#define strneq(str1, str2) (strcmp ((str1), (str2)) != 0) #define square(x) ((x) * (x)) #define first_band(color) ((unsigned) ((color) ? Y : GRAY)) #define last_band(color) ((unsigned) ((color) ? Cr : GRAY)) diff --git a/converter/other/tifftopnm.c b/converter/other/tifftopnm.c index 05493e73..0c301a4a 100644 --- a/converter/other/tifftopnm.c +++ b/converter/other/tifftopnm.c @@ -1357,10 +1357,10 @@ convertRasterByRows(pnmOut * const pnmOutP, represented as single array element, so it's easy to work with. */ xel * xelrow; - /* The ppm-format row of the image row we are presently converting */ + /* The ppm-format row of the image row we are currently converting */ gray * alpharow; /* The pgm-format row representing the alpha values for the image - row we are presently converting. + row we are currently converting. */ unsigned int row; @@ -1465,11 +1465,11 @@ convertTiffRaster(uint32 * const raster, -----------------------------------------------------------------------------*/ xel * xelrow; /* The ppm-format row of the image row we are - presently converting + currently converting */ gray * alpharow; /* The pgm-format row representing the alpha values - for the image row we are presently converting. + for the image row we are currently converting. */ unsigned int row; @@ -1478,7 +1478,7 @@ convertTiffRaster(uint32 * const raster, for (row = 0; row < rows; ++row) { uint32 * rp; - /* Address of pixel in 'raster' we are presently converting */ + /* Address of pixel in 'raster' we are currently converting */ unsigned int col; /* Start at beginning of row: */ diff --git a/converter/other/winicontopam.c b/converter/other/winicontopam.c index 2ddf56b1..70729cce 100644 --- a/converter/other/winicontopam.c +++ b/converter/other/winicontopam.c @@ -1,3 +1,25 @@ +/*============================================================================= + winicontopam +=============================================================================== + Convert from Windows icon format to PAM +=============================================================================*/ + +/* + Here are some references for the Windows icon format: + + ICO (file format) - Wikipedia + https://en.wikipedia.org/wiki/ICO_(file_format) + + ICO - Just Solve the File Format Problem + http://fileformats.archiveteam.org/wiki/ICO + (Has links to example icon file collections) + + GFF Format Summary: Microsoft Windows Cursor and Icon + https://web.archive.org/web/20050421161512/http:/www.oreilly.com/www/centers/gff/formats/miccur/index.htm + + +*/ + #include <assert.h> #include <stdio.h> #include <string.h> @@ -25,7 +47,7 @@ static bool verbose; struct CmdlineInfo { - + const char * inputFileName; unsigned int allimages; unsigned int imageSpec; @@ -78,7 +100,7 @@ parseCommandLine(int argc, const char **argv, pm_error("Too many arguments. The only possible " "non-option argument is the input file name"); } - + free(option_def); } @@ -93,7 +115,7 @@ struct File { FILE * fileP; const char * name; pm_filepos pos; - + }; @@ -122,7 +144,7 @@ static uint32_t u32_le(const unsigned char * const buf, size_t const offset) { - return + return ((uint32_t)buf[offset + 0] << 0) + ((uint32_t)buf[offset + 1] << 8) + ((uint32_t)buf[offset + 2] << 16) + @@ -135,7 +157,7 @@ static uint32_t s32_le(const unsigned char * const buf, size_t const offset) { - return + return ((uint32_t)buf[offset + 0] << 0) + ((uint32_t)buf[offset + 1] << 8) + ((uint32_t)buf[offset + 2] << 16) + @@ -156,8 +178,8 @@ u8_be(const unsigned char * const buf, static uint32_t u32_be(const unsigned char * const buf, size_t const offset) { - - return + + return ((uint32_t)buf[offset + 0] << 24) + ((uint32_t)buf[offset + 1] << 16) + ((uint32_t)buf[offset + 2] << 8) + @@ -225,7 +247,7 @@ dumpIconDir(const struct IconDir * const dirP) { } } - + static struct IconDir * readIconDir(struct File * const fP, @@ -271,7 +293,7 @@ readIconDir(struct File * const fP, pm_readcharu(fP->fileP, &heightField); dirEntryP->height = (heightField == 0 ? 256 : heightField); - + pm_readcharu(fP->fileP, &dirEntryP->color_count); pm_readcharu(fP->fileP, &dirEntryP->zero); @@ -290,7 +312,7 @@ readIconDir(struct File * const fP, } /* The following is paranoia code only: - + I've never seen a windows icon file in the wild with having the entries in the directory stored in a different order than the images themselves. However, the file format allows for it ... @@ -301,7 +323,7 @@ readIconDir(struct File * const fP, pm_message("%s icon directory (%u image%s):", fP->name, dirP->count, dirP->count == 1 ? "" : "s"); - + for (imageIndex = 0; imageIndex < dirP->count; ++imageIndex) { const struct IconDirEntry * const dirEntryP = &dirP->entries[imageIndex]; @@ -355,7 +377,7 @@ readImage(struct File * const fP, /* Don't try to read an image that is smaller than the BITMAPINFOHEADER of BMP images (40 bytes). - + PNG compressed images can't be smaller than that either, as the PNG header plus the mandantory IHDR and IEND chunks already take 8 + 25 + 12 = 35 bytes, and there is to be a IDAT chunk too. @@ -369,7 +391,7 @@ readImage(struct File * const fP, dirEntryP->index); /* The following is paranoia code only: - + I've never seen a windows icon file in the wild with gaps between the images, but the file format allows for it, and Microsoft expects the user to fseek() to the start of each image. @@ -472,11 +494,11 @@ readXorPalette(struct BitmapInfoHeader * const hdrP, uint32_t bytesPerRow; const unsigned char * bitmapCursor; uint32_t sizeRemaining; - + uint8_t (*getIdx) (const unsigned char * bitmap, uint32_t rowOffset, int16_t col); - + if (hdrP->compression_method != BI_RGB) pm_error("image %2u: invalid compression method %u.", index, hdrP->compression_method); @@ -518,7 +540,7 @@ readXorPalette(struct BitmapInfoHeader * const hdrP, if (sizeRemaining < paletteSize) pm_error("image %2u: " "reading palette: image truncated.", index); - + palette = (const PaletteEntry *) bitmapCursor; if (needHeaderDump) @@ -562,7 +584,7 @@ readXorPalette(struct BitmapInfoHeader * const hdrP, /* The palette is an array of little-endian 32-bit values, where the RGB value is encoded as follows: - + red: bits 2^16..2^23 green: bits 2^8 ..2^15 blue: bits 2^0 ..2^7 @@ -823,7 +845,7 @@ readAnd(struct BitmapInfoHeader * const hdrP, if (offset + bytesPerRow <= sizeRemaining) { unsigned int col; - + for (col = 0; col < hdrP->bm_width; ++col) { tuples[row][col][plane] = ((u8_le(bitmap, offset + col/8) @@ -952,7 +974,7 @@ reportImage(unsigned int const imageIndex, struct BitmapInfoHeader const hdr, bool const haveAlpha) { - const char * const style = + const char * const style = haveAlpha ? "RGB +alpha" : hdr.bits_per_pixel < 16 ? "RGB/palette" : "RGB" @@ -973,7 +995,7 @@ convertBmp(const unsigned char * const image, struct IconDirEntry * const dirEntryP, bool const needHeaderDump, bool const wantAndMaskPlane) { - + struct BitmapInfoHeader hdr; uint32_t offset; bool haveAlpha; @@ -1024,7 +1046,7 @@ convertBmp(const unsigned char * const image, tuples = pnm_allocpamarray(&outpam); - readXorMask(&hdr, &image[offset], + readXorMask(&hdr, &image[offset], dirEntryP->size - offset, tuples, dirEntryP->index, needHeaderDump, &haveAlpha, &xorByteCt); @@ -1070,7 +1092,7 @@ convertBmp(const unsigned char * const image, static void reportPngInfo(const unsigned char * const image, struct IconDirEntry * const dirEntryP) { - + struct PngIhdr ihdr; ihdr.length = u32_be (image, sizeof(pngHeader) +0); @@ -1148,14 +1170,16 @@ convertPng(const unsigned char * const image, FILE * const ofP, struct IconDirEntry * const dirEntryP) { - struct bufferDesc imageBuffer; + pm_bufferDesc imageBuffer; reportPngInfo(image, dirEntryP); - imageBuffer.size = dirEntryP->size; - imageBuffer.buffer = (unsigned char *)image; + imageBuffer.size = dirEntryP->size; + imageBuffer.buffer = (unsigned char *)image; + imageBuffer.bytesTransferredP = NULL; + + fflush(stdout); - fflush (stdout); pm_system_lp("pngtopam", pm_feed_from_memory, &imageBuffer, NULL /* stdout accepter */, NULL, "pngtopam", "-alphapam", NULL); @@ -1174,7 +1198,7 @@ bestImage(struct IconDir * const dirP) { bestPixelCt = 0; /* initial value */ bestColorCt = 0; /* initial value */ best = 0; /* initial value */ - + for (imageIndex = 0; dirP->count > imageIndex; ++imageIndex) { struct IconDirEntry * const dirEntryP = &dirP->entries[imageIndex]; @@ -1183,7 +1207,7 @@ bestImage(struct IconDir * const dirP) { uint32_t colorCt; /* 32-bit icons have 24 bit color information only. - + Since NT 5.1 (aka WinXP), it is allowed to place 8-bit transparency information in the remaining bits (to check, you have to read all these bits in the image!), so I prefer @@ -1273,7 +1297,7 @@ main (int argc, const char *argv []) { convertImage(&ico, &dirP->entries[bestImage(dirP)], stdout, cmdline.headerdump, cmdline.andmasks); } - + freeIconDir(dirP); if (ico.fileP != stdin) diff --git a/converter/other/xwdtopnm.c b/converter/other/xwdtopnm.c index a74da341..a99768b8 100644 --- a/converter/other/xwdtopnm.c +++ b/converter/other/xwdtopnm.c @@ -999,7 +999,7 @@ pixelReader_getbits(pixelReader * const rdrP, -----------------------------------------------------------------------------*/ unsigned long pixel; /* Accumulator for the value we ultimately return. We shift in - bits from the right end. The number of bits presently in the + bits from the right end. The number of bits currently in the accumulator is rdrP->bitsPerPixel - nBitsStillNeeded . */ |