From 528ab2d612845d92ac5ae1e3b1d11349b89eff06 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Fri, 22 May 2015 15:42:42 +0000 Subject: cleanup git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2511 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/other/cameratopam/camera.c | 4 +- converter/other/cameratopam/ljpeg.c | 225 ++++++++++++++++++----------------- converter/other/cameratopam/ljpeg.h | 9 +- 3 files changed, 127 insertions(+), 111 deletions(-) (limited to 'converter/other/cameratopam') diff --git a/converter/other/cameratopam/camera.c b/converter/other/cameratopam/camera.c index d318e379..a1adba95 100644 --- a/converter/other/cameratopam/camera.c +++ b/converter/other/cameratopam/camera.c @@ -108,7 +108,7 @@ adobe_dng_load_raw_lj(Image const image) { twide = raw_width-tcol; for (jrow=0; jrow < jh.high; jrow++) { - ljpeg_row (&jh); + ljpeg_row(ifp, &jh); for (rp=jh.row, jcol=0; jcol < twide; jcol++) adobeCopyPixel(image, trow+jrow, tcol+jcol, &rp, use_secondary); @@ -170,7 +170,7 @@ nikon_compressed_load_raw(Image const image) { for (row=0; row < height; row++) for (col=0; col < raw_width; col++) { - diff = ljpeg_diff (first_decode); + diff = ljpeg_diff (ifp, first_decode); if (col < 2) { i = 2*(row & 1) + (col & 1); vpred[i] += diff; diff --git a/converter/other/cameratopam/ljpeg.c b/converter/other/cameratopam/ljpeg.c index 29e4ff98..a0e109b0 100644 --- a/converter/other/cameratopam/ljpeg.c +++ b/converter/other/cameratopam/ljpeg.c @@ -20,123 +20,136 @@ */ int -ljpeg_start (FILE * ifp, struct jhead *jh) -{ - int i, tag, len; - unsigned char data[256], *dp; - - init_decoder(); - for (i=0; i < 4; i++) - jh->huff[i] = free_decode; - fread (data, 2, 1, ifp); - if (data[0] != 0xff || data[1] != 0xd8) return 0; - do { - fread (data, 2, 2, ifp); - tag = data[0] << 8 | data[1]; - len = (data[2] << 8 | data[3]) - 2; - if (tag <= 0xff00 || len > 255) return 0; - fread (data, 1, len, ifp); - switch (tag) { - case 0xffc3: - jh->bits = data[0]; - jh->high = data[1] << 8 | data[2]; - jh->wide = data[3] << 8 | data[4]; - jh->clrs = data[5]; - break; - case 0xffc4: - for (dp = data; dp < data+len && *dp < 4; ) { - jh->huff[*dp] = free_decode; - dp = make_decoder (++dp, 0); - } - } - } while (tag != 0xffda); - jh->row = calloc (jh->wide*jh->clrs, 2); - if (jh->row == NULL) - pm_error("Out of memory in ljpeg_start()"); - for (i=0; i < 4; i++) - jh->vpred[i] = 1 << (jh->bits-1); - zero_after_ff = 1; - getbits(ifp, -1); - return 1; +ljpeg_start(FILE * const ifP, + struct jhead * const jhP) { + + int i, tag, len; + unsigned char data[256], *dp; + + init_decoder(); + for (i=0; i < 4; i++) + jhP->huff[i] = free_decode; + fread (data, 2, 1, ifP); + if (data[0] != 0xff || data[1] != 0xd8) return 0; + do { + fread (data, 2, 2, ifP); + tag = data[0] << 8 | data[1]; + len = (data[2] << 8 | data[3]) - 2; + if (tag <= 0xff00 || len > 255) return 0; + fread (data, 1, len, ifP); + switch (tag) { + case 0xffc3: + jhP->bits = data[0]; + jhP->high = data[1] << 8 | data[2]; + jhP->wide = data[3] << 8 | data[4]; + jhP->clrs = data[5]; + break; + case 0xffc4: + for (dp = data; dp < data+len && *dp < 4; ) { + jhP->huff[*dp] = free_decode; + dp = make_decoder (++dp, 0); + } + } + } while (tag != 0xffda); + jhP->row = calloc (jhP->wide*jhP->clrs, 2); + if (jhP->row == NULL) + pm_error("Out of memory in ljpeg_start()"); + for (i=0; i < 4; i++) + jhP->vpred[i] = 1 << (jhP->bits-1); + zero_after_ff = 1; + getbits(ifP, -1); + return 1; } + + int -ljpeg_diff (struct decode *dindex) -{ - int len, diff; - - while (dindex->branch[0]) - dindex = dindex->branch[getbits(ifp, 1)]; - diff = getbits(ifp, len = dindex->leaf); - if ((diff & (1 << (len-1))) == 0) - diff -= (1 << len) - 1; - return diff; +ljpeg_diff(FILE * const ifP, + struct decode * const dindexHeadP) { + + int len; + int diff; + struct decode * dindexP; + + for (dindexP = dindexHeadP; dindexP->branch[0]; ) + dindexP = dindexP->branch[getbits(ifP, 1)]; + + diff = getbits(ifP, len = dindexP->leaf); + + if ((diff & (1 << (len-1))) == 0) + diff -= (1 << len) - 1; + + return diff; } + + void -ljpeg_row (struct jhead *jh) -{ - int col, c, diff; - unsigned short *outp=jh->row; - - for (col=0; col < jh->wide; col++) - for (c=0; c < jh->clrs; c++) { - diff = ljpeg_diff (jh->huff[c]); - *outp = col ? outp[-jh->clrs]+diff : (jh->vpred[c] += diff); - outp++; - } +ljpeg_row(FILE * const ifP, + struct jhead * const jhP) { + + int col, c, diff; + unsigned short *outp=jhP->row; + + for (col=0; col < jhP->wide; col++) + for (c=0; c < jhP->clrs; c++) { + diff = ljpeg_diff(ifP, jhP->huff[c]); + *outp = col ? outp[-jhP->clrs]+diff : (jhP->vpred[c] += diff); + outp++; + } } + void -lossless_jpeg_load_raw(Image const image) { - - int jwide, jrow, jcol, val, jidx, i, row, col; - struct jhead jh; - int min=INT_MAX; - - if (!ljpeg_start (ifp, &jh)) return; - jwide = jh.wide * jh.clrs; - - for (jrow=0; jrow < jh.high; jrow++) { - ljpeg_row (&jh); - for (jcol=0; jcol < jwide; jcol++) { - val = curve[jh.row[jcol]]; - jidx = jrow*jwide + jcol; - if (raw_width == 5108) { - i = jidx / (1680*jh.high); - if (i < 2) { - row = jidx / 1680 % jh.high; - col = jidx % 1680 + i*1680; - } else { - jidx -= 2*1680*jh.high; - row = jidx / 1748; - col = jidx % 1748 + 2*1680; - } - } else if (raw_width == 3516) { - row = jidx / 1758; - col = jidx % 1758; - if (row >= raw_height) { - row -= raw_height; - col += 1758; - } - } else { - row = jidx / raw_width; - col = jidx % raw_width; - } - if ((unsigned) (row-top_margin) >= height) continue; - if ((unsigned) (col-left_margin) < width) { - BAYER(row-top_margin,col-left_margin) = val; - if (min > val) min = val; - } else - black += val; +lossless_jpeg_load_raw(Image const image) { + + int jwide, jrow, jcol, val, jidx, i, row, col; + struct jhead jh; + int min=INT_MAX; + + if (!ljpeg_start (ifp, &jh)) return; + jwide = jh.wide * jh.clrs; + + for (jrow=0; jrow < jh.high; jrow++) { + ljpeg_row (ifp, &jh); + for (jcol=0; jcol < jwide; jcol++) { + val = curve[jh.row[jcol]]; + jidx = jrow*jwide + jcol; + if (raw_width == 5108) { + i = jidx / (1680*jh.high); + if (i < 2) { + row = jidx / 1680 % jh.high; + col = jidx % 1680 + i*1680; + } else { + jidx -= 2*1680*jh.high; + row = jidx / 1748; + col = jidx % 1748 + 2*1680; + } + } else if (raw_width == 3516) { + row = jidx / 1758; + col = jidx % 1758; + if (row >= raw_height) { + row -= raw_height; + col += 1758; + } + } else { + row = jidx / raw_width; + col = jidx % raw_width; + } + if ((unsigned) (row-top_margin) >= height) continue; + if ((unsigned) (col-left_margin) < width) { + BAYER(row-top_margin,col-left_margin) = val; + if (min > val) min = val; + } else + black += val; + } } - } - free (jh.row); - if (raw_width > width) - black /= (raw_width - width) * height; - if (!strcasecmp(make,"KODAK")) - black = min; + free (jh.row); + if (raw_width > width) + black /= (raw_width - width) * height; + if (!strcasecmp(make,"KODAK")) + black = min; } diff --git a/converter/other/cameratopam/ljpeg.h b/converter/other/cameratopam/ljpeg.h index cfd68eb4..9d9d8ee9 100644 --- a/converter/other/cameratopam/ljpeg.h +++ b/converter/other/cameratopam/ljpeg.h @@ -9,10 +9,13 @@ struct jhead { LoadRawFn lossless_jpeg_load_raw; int -ljpeg_start (FILE * ifp, struct jhead *jh); +ljpeg_start (FILE * const ifP, + struct jhead * const jhP); int -ljpeg_diff (struct decode *dindex); +ljpeg_diff (FILE * const ifP, + struct decode * const dindexP); void -ljpeg_row (struct jhead *jh); +ljpeg_row(FILE * const ifP, + struct jhead * const jhP); -- cgit 1.4.1