From: Niels K. B. J. <nk...@us...> - 2006-01-23 10:36:53
|
Update of /cvsroot/ufraw/ufraw In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3523 Modified Files: dcraw.c Log Message: DCRaw modified 8.01 (1.311). Index: dcraw.c =================================================================== RCS file: /cvsroot/ufraw/ufraw/dcraw.c,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** dcraw.c 23 Jan 2006 06:38:10 -0000 1.53 --- dcraw.c 23 Jan 2006 10:36:45 -0000 1.54 *************** *** 95,115 **** short order; char *ifname, make[64], model[72], model2[64], *meta_data, cdesc[5]; /*UF*/ ! float flash_used, canon_ev, iso_speed, shutter, aperture, focal_len; ! time_t timestamp; ! unsigned shot_order, kodak_cbpp; int profile_offset, profile_length; int thumb_offset, thumb_length, thumb_width, thumb_height, thumb_misc; ! int data_offset, meta_offset, meta_length, nikon_curve_offset; int tiff_nifds, tiff_flip, tiff_bps, tiff_compress; ! int raw_height, raw_width, top_margin, left_margin; int height, width, fuji_width, colors, tiff_samples; /*UF*/ ! int black, maximum, clip_max, clip_color=1; /*UF*/ int iheight, iwidth, shrink, flip, xmag, ymag; /*UF*/ ! int dng_version, is_foveon, raw_color, use_gamma; /*UF*/ ! int zero_after_ff; ! unsigned filters; /*UF*/ ushort (*image)[4], white[8][8], curve[0x1000], cr2_slice[3]; /*UF*/ float bright=1, red_scale=1, blue_scale=1, sigma_d=0, sigma_r=0; /*UF*/ ! int four_color_rgb=0, document_mode=0; int verbose=0, use_auto_wb=0, use_camera_wb=0, output_color=1; /*UF*/ int fuji_layout, fuji_secondary, use_secondary=0; /*UF*/ --- 95,113 ---- short order; char *ifname, make[64], model[72], model2[64], *meta_data, cdesc[5]; /*UF*/ ! float flash_used, canon_ev, iso_speed, shutter, aperture, focal_len; /*UF*/ ! time_t timestamp; /*UF*/ ! unsigned shot_order, kodak_cbpp, filters; /*UF*/ int profile_offset, profile_length; int thumb_offset, thumb_length, thumb_width, thumb_height, thumb_misc; ! int data_offset, meta_offset, meta_length, nikon_curve_offset; /*UF*/ int tiff_nifds, tiff_flip, tiff_bps, tiff_compress; ! int raw_height, raw_width, top_margin, left_margin; /*UF*/ int height, width, fuji_width, colors, tiff_samples; /*UF*/ ! int black, maximum, clip_max, raw_color, use_gamma; /*UF*/ int iheight, iwidth, shrink, flip, xmag, ymag; /*UF*/ ! int zero_after_ff, is_raw, dng_version, is_foveon; /*UF*/ ushort (*image)[4], white[8][8], curve[0x1000], cr2_slice[3]; /*UF*/ float bright=1, red_scale=1, blue_scale=1, sigma_d=0, sigma_r=0; /*UF*/ ! int four_color_rgb=0, document_mode=0, clip_color=1; /*UF*/ int verbose=0, use_auto_wb=0, use_camera_wb=0, output_color=1; /*UF*/ int fuji_layout, fuji_secondary, use_secondary=0; /*UF*/ *************** *** 652,655 **** --- 650,654 ---- uchar c; + crw_init_tables (tiff_compress); pixel = calloc (raw_width*8, sizeof *pixel); merror (pixel, "canon_compressed_load_raw()"); *************** *** 2032,2036 **** void CLASS foveon_thumb (FILE *tfp) { ! int width, height, bwide, row, col, bit=-1, c, i; char *buf; struct decode *dindex; --- 2031,2035 ---- void CLASS foveon_thumb (FILE *tfp) { ! int bwide, row, col, bit=-1, c, i; char *buf; struct decode *dindex; *************** *** 2038,2051 **** unsigned bitbuf=0; ! width = get4(); ! height = get4(); ! bwide = get4(); ! fprintf (tfp, "P6\n%d %d\n255\n", width, height); if (bwide > 0) { buf = malloc (bwide); merror (buf, "foveon_thumb()"); ! for (row=0; row < height; row++) { fread (buf, 1, bwide, ifp); ! fwrite (buf, 3, width, tfp); } free (buf); --- 2037,2048 ---- unsigned bitbuf=0; ! bwide = get4(); ! fprintf (tfp, "P6\n%d %d\n255\n", thumb_width, thumb_height); if (bwide > 0) { buf = malloc (bwide); merror (buf, "foveon_thumb()"); ! for (row=0; row < thumb_height; row++) { fread (buf, 1, bwide, ifp); ! fwrite (buf, 3, thumb_width, tfp); } free (buf); *************** *** 2054,2061 **** foveon_decoder (256, 0); ! for (row=0; row < height; row++) { memset (pred, 0, sizeof pred); if (!bit) get4(); ! for (col=bit=0; col < width; col++) FORC3 { for (dindex=first_decode; dindex->branch[0]; ) { --- 2051,2058 ---- foveon_decoder (256, 0); ! for (row=0; row < thumb_height; row++) { memset (pred, 0, sizeof pred); if (!bit) get4(); ! for (col=bit=0; col < thumb_width; col++) FORC3 { for (dindex=first_decode; dindex->branch[0]; ) { *************** *** 2853,2881 **** void CLASS scale_colors() { ! int row, col, c, val, shift=0; ! int min[4], max[4], count[4]; ! double sum[4], dmin; maximum -= black; if (use_auto_wb || (use_camera_wb && camera_red == -1)) { FORC4 min[c] = INT_MAX; ! FORC4 max[c] = count[c] = sum[c] = 0; ! for (row=0; row < height; row++) ! for (col=0; col < width; col++) ! FORC4 { ! val = image[row*width+col][c]; ! if (!val) continue; ! if (min[c] > val) min[c] = val; ! if (max[c] < val) max[c] = val; ! val -= black; ! if (val > maximum-25) continue; ! if (val < 0) val = 0; ! sum[c] += val; ! count[c]++; ! } ! FORC4 if (sum[c]) pre_mul[c] = count[c] / sum[c]; } if (use_camera_wb && camera_red != -1) { ! FORC4 count[c] = sum[c] = 0; for (row=0; row < 8; row++) for (col=0; col < 8; col++) { --- 2850,2886 ---- void CLASS scale_colors() { ! int row, col, x, y, c, val, shift=0; ! int min[4], max[4], sum[8]; ! double dsum[8], dmin; maximum -= black; if (use_auto_wb || (use_camera_wb && camera_red == -1)) { FORC4 min[c] = INT_MAX; ! FORC4 max[c] = 0; ! memset (dsum, 0, sizeof dsum); ! for (row=0; row < height-7; row++) ! for (col=0; col < width-7; col++) { ! memset (sum, 0, sizeof sum); ! for (y=row; y < row+7; y++) ! for (x=col; x < col+7; x++) ! FORC4 { ! val = image[y*width+x][c]; ! if (!val) continue; ! if (min[c] > val) min[c] = val; ! if (max[c] < val) max[c] = val; ! val -= black; ! if (val > maximum-25) goto skip_block; ! if (val < 0) val = 0; ! sum[c] += val; ! sum[c+4]++; ! } ! for (c=0; c < 8; c++) dsum[c] += sum[c]; ! skip_block: ! continue; ! } ! FORC4 if (dsum[c]) pre_mul[c] = dsum[c+4] / dsum[c]; } if (use_camera_wb && camera_red != -1) { ! memset (sum, 0, sizeof sum); for (row=0; row < 8; row++) for (col=0; col < 8; col++) { *************** *** 2883,2890 **** if ((val = white[row][col] - black) > 0) sum[c] += val; ! count[c]++; } if (sum[0] && sum[1] && sum[2] && sum[3]) ! FORC4 pre_mul[c] = count[c] / sum[c]; else if (camera_red && camera_blue) memcpy (pre_mul, cam_mul, sizeof pre_mul); --- 2888,2895 ---- if ((val = white[row][col] - black) > 0) sum[c] += val; ! sum[c+4]++; } if (sum[0] && sum[1] && sum[2] && sum[3]) ! FORC4 pre_mul[c] = (float) sum[c+4] / sum[c]; else if (camera_red && camera_blue) memcpy (pre_mul, cam_mul, sizeof pre_mul); *************** *** 3433,3436 **** --- 3438,3446 ---- if (tag == 2 && strstr(make,"NIKON")) iso_speed = (get2(),get2()); + if (tag == 4 && len == 27) { + iso_speed = 50 * pow (2, (get4(),get2())/32.0 - 4); + aperture = (get2(), pow (2, get2()/64.0)); + shutter = pow (2, ((short) get2())/-32.0); + } if (tag == 8 && type == 4) shot_order = get4(); *************** *** 3744,3748 **** !strncmp(software,"Bibble",6) || !strcmp (software,"Digital Photo Professional")) ! make[0] = 0; break; case 306: /* DateTime */ --- 3754,3758 ---- !strncmp(software,"Bibble",6) || !strcmp (software,"Digital Photo Professional")) ! is_raw = 0; break; case 306: /* DateTime */ *************** *** 4002,4008 **** } if (((strstr(make,"Minolta") || strstr(make,"MINOLTA")) && tiff_bps == 8) || (!strcmp(make,"SONY") && tiff_bps != 14) || (tiff_samples == 3 && data_offset == 8)) ! if (!dng_version) make[0] = 0; for (i=0; i < tiff_nifds; i++) if (i != raw && tiff_ifd[i].samples == max_samp && --- 4012,4019 ---- } if (((strstr(make,"Minolta") || strstr(make,"MINOLTA")) && tiff_bps == 8) + || (!strncmp(make,"NIKON",5) && filters == UINT_MAX) || (!strcmp(make,"SONY") && tiff_bps != 14) || (tiff_samples == 3 && data_offset == 8)) ! if (!dng_version) is_raw = 0; for (i=0; i < tiff_nifds; i++) if (i != raw && tiff_ifd[i].samples == max_samp && *************** *** 4103,4106 **** --- 4114,4118 ---- parse_tiff (12); thumb_offset = 0; + is_raw = 1; fclose (ifp); } *************** *** 4171,4175 **** iso_speed = 50 * pow (2, get2()/32.0 - 4); aperture = (get2(), pow (2, get2()/64.0)); ! shutter = pow (2, ((short) get2())/-32.0); wbi = (get2(),get2()); if (wbi > 17) wbi = 0; --- 4183,4187 ---- iso_speed = 50 * pow (2, get2()/32.0 - 4); aperture = (get2(), pow (2, get2()/64.0)); ! shutter = pow (2, ((short) get2())/-32.0); wbi = (get2(),get2()); if (wbi > 17) wbi = 0; *************** *** 4251,4255 **** if (type == 0x1835) { /* Get the decoder table */ fseek (ifp, aoff, SEEK_SET); ! crw_init_tables (get4()); } if (type == 0x2007) { /* Found the JPEG thumbnail */ --- 4263,4267 ---- if (type == 0x1835) { /* Get the decoder table */ fseek (ifp, aoff, SEEK_SET); ! tiff_compress = get4(); } if (type == 0x2007) { /* Found the JPEG thumbnail */ *************** *** 4387,4399 **** int CLASS parse_jpeg (int offset) { ! int len, save, hlen; fseek (ifp, offset, SEEK_SET); if (fgetc(ifp) != 0xff || fgetc(ifp) != 0xd8) return 0; ! while (fgetc(ifp) == 0xff && fgetc(ifp) >> 4 != 0xd) { order = 0x4d4d; len = get2() - 2; save = ftell(ifp); order = get2(); hlen = get4(); --- 4399,4416 ---- int CLASS parse_jpeg (int offset) { ! int len, save, hlen, mark; fseek (ifp, offset, SEEK_SET); if (fgetc(ifp) != 0xff || fgetc(ifp) != 0xd8) return 0; ! while (fgetc(ifp) == 0xff && (mark = fgetc(ifp)) != 0xda) { order = 0x4d4d; len = get2() - 2; save = ftell(ifp); + if (mark == 0xc0 || mark == 0xc3) { + fgetc(ifp); + raw_height = get2(); + raw_width = get2(); + } order = get2(); hlen = get4(); *************** *** 4502,4506 **** } if (++img == 2 && !thumb_length) { ! thumb_offset = off+16; write_thumb = foveon_thumb; } --- 4519,4525 ---- } if (++img == 2 && !thumb_length) { ! thumb_offset = off+24; ! thumb_width = wide; ! thumb_height = high; write_thumb = foveon_thumb; } *************** *** 4845,4848 **** --- 4864,4868 ---- char head[32], *cp; unsigned hlen, fsize, i, c, is_canon; + struct jhead jh; static const struct { int fsize; *************** *** 4892,4897 **** "MINOLTA", "Minolta", "Konica", "CASIO", "Sinar", "Phase One" }; - /* What format is this file? Set make[] if we recognize it. */ - tiff_flip = flip = filters = -1; /* 0 is valid, so -1 is unknown */ raw_height = raw_width = fuji_width = cr2_slice[0] = 0; --- 4912,4915 ---- *************** *** 4906,4910 **** kodak_cbpp = zero_after_ff = dng_version = fuji_secondary = 0; timestamp = shot_order = tiff_samples = black = is_foveon = 0; ! raw_color = use_gamma = xmag = ymag = 1; for (i=0; i < 4; i++) { cam_mul[i] = i == 1; --- 4924,4928 ---- kodak_cbpp = zero_after_ff = dng_version = fuji_secondary = 0; timestamp = shot_order = tiff_samples = black = is_foveon = 0; ! is_raw = raw_color = use_gamma = xmag = ymag = 1; for (i=0; i < 4; i++) { cam_mul[i] = i == 1; *************** *** 4934,4939 **** } else { parse_tiff(0); - if (!dng_version && !strncmp(make,"NIKON",5) && filters == UINT_MAX) - make[0] = 0; } } else if (!memcmp (head,"\xff\xd8\xff\xe1",4) && --- 4952,4955 ---- *************** *** 5012,5019 **** parse_mos(3472); if (make[0] == 0) parse_smal (0, fsize); ! if (make[0] == 0) { ! parse_jpeg(0); ! make[0] = 0; ! } for (i=0; i < sizeof corp / sizeof *corp; i++) if (strstr (make, corp[i])) /* Simplify company names */ --- 5028,5033 ---- parse_mos(3472); if (make[0] == 0) parse_smal (0, fsize); ! if (make[0] == 0) parse_jpeg (is_raw = 0); ! for (i=0; i < sizeof corp / sizeof *corp; i++) if (strstr (make, corp[i])) /* Simplify company names */ *************** *** 5029,5033 **** memmove (model, model+i, 64-i); make[63] = model[63] = model2[63] = 0; ! if (make[0] == 0) return; if ((raw_height | raw_width) < 0) --- 5043,5047 ---- memmove (model, model+i, 64-i); make[63] = model[63] = model2[63] = 0; ! if (!is_raw) return; if ((raw_height | raw_width) < 0) *************** *** 5742,5746 **** --- 5756,5774 ---- if (filters == UINT_MAX) filters = 0x94949494; if (raw_color) adobe_coeff(); + if (thumb_offset && !thumb_height) { + fseek (ifp, thumb_offset, SEEK_SET); + if (ljpeg_start (&jh, 1)) { + thumb_width = jh.wide; + thumb_height = jh.high; + } + } dng_skip: + if (!load_raw || !height) is_raw = 0; + #ifdef NO_JPEG + if (load_raw == kodak_jpeg_load_raw) { + fprintf (stderr, "%s: You must link dcraw.c with libjpeg!!\n", ifname); + is_raw = 0; + } + #endif if (flip == -1) flip = tiff_flip; if (flip == -1) flip = 0; *************** *** 6050,6054 **** { fprintf (stderr, ! "\nRaw Photo Decoder \"dcraw\" v8.00" "\nby Dave Coffin, dcoffin a cybercom o net" "\n\nUsage: %s [options] file1 file2 ...\n" --- 6078,6082 ---- { fprintf (stderr, ! "\nRaw Photo Decoder \"dcraw\" v8.01" "\nby Dave Coffin, dcoffin a cybercom o net" "\n\nUsage: %s [options] file1 file2 ...\n" *************** *** 6168,6172 **** continue; } ! identify(); if (timestamp_only) { if ((status = !timestamp)) --- 6196,6200 ---- continue; } ! status = (identify(),!is_raw); if (timestamp_only) { if ((status = !timestamp)) *************** *** 6198,6217 **** } } ! if ((status = !make[0])) { ! fprintf (stderr, "%s: unsupported file format.\n", ifname); ! goto next; ! } else if ((status = !load_raw || !height)) { ! fprintf (stderr, "%s: Cannot decode %s %s images.\n", ! ifname, make, model); ! goto next; ! #ifdef NO_JPEG ! } else if (load_raw == kodak_jpeg_load_raw) { ! fprintf (stderr, "%s: dcraw was not linked with libjpeg.\n", ifname); ! goto next; ! #endif ! } else if (load_raw == kodak_ycbcr_load_raw) { height += height & 1; width += width & 1; } if (user_flip >= 0) flip = user_flip; --- 6226,6252 ---- } } ! if (load_raw == kodak_ycbcr_load_raw) { height += height & 1; width += width & 1; } + if (identify_only && verbose && make[0]) { + printf ("\nFilename: %s\n", ifname); + printf ("Timestamp: %s", ctime(×tamp)); + printf ("Camera: %s %s\n", make, model); + printf ("ISO speed: %d\n", (int) iso_speed); + printf ("Shutter: "); + if (shutter > 0 && shutter < 1) + shutter = (printf ("1/"), 1 / shutter); + printf ("%0.1f sec\n", shutter); + printf ("Aperture: f/%0.1f\n", aperture); + printf ("Focal Length: %d mm\n", (int) focal_len); + printf ("Embedded ICC profile: %s\n", profile_length ? "yes":"no"); + printf ("Decodable with dcraw: %s\n", is_raw ? "yes":"no"); + if (thumb_offset) + printf ("Thumb size: %4d x %d\n", thumb_width, thumb_height); + printf ("Full size: %4d x %d\n", raw_width, raw_height); + } else if (!is_raw) + fprintf (stderr, "Cannot decode %s\n", ifname); + if (!is_raw) goto next; if (user_flip >= 0) flip = user_flip; *************** *** 6226,6239 **** if (identify_only) { if (verbose) { ! printf ("Filename: %s\n", ifname); ! printf ("Timestamp: %s", ctime(×tamp)); ! printf ("Camera: %s %s\n", make, model); ! printf ("ISO speed: %d\n", (int) iso_speed); ! printf ("Shutter: "); ! if (shutter > 0 && shutter < 1) ! shutter = (printf ("1/"), 1 / shutter); ! printf ("%0.1f sec\n", shutter); ! printf ("Aperture: f/%0.1f\n", aperture); ! printf ("Focal Length: %d mm\n", (int) focal_len); printf ("Raw colors: %d", colors); if (filters) { --- 6261,6277 ---- if (identify_only) { if (verbose) { ! if (fuji_width && use_fuji_rotate) { ! fuji_width = (fuji_width - 1 + shrink) >> shrink; ! iwidth = fuji_width / sqrt(0.5); ! iheight = (iheight - fuji_width) / sqrt(0.5); ! } ! if (write_fun == write_ppm) { ! iheight *= ymag; ! iwidth *= xmag; ! } ! if (flip & 4) ! SWAP (iheight, iwidth); ! printf ("Image size: %4d x %d\n", width, height); ! printf ("Output size: %4d x %d\n", iwidth, iheight); printf ("Raw colors: %d", colors); if (filters) { *************** *** 6249,6266 **** FORCC printf (" %f", cam_mul[c]); } ! printf ("\nRaw size: %d x %d\n", raw_width, raw_height); ! printf ("Image size: %d x %d\n", width, height); ! if (fuji_width && use_fuji_rotate) { ! fuji_width = (fuji_width - 1 + shrink) >> shrink; ! iwidth = fuji_width / sqrt(0.5); ! iheight = (iheight - fuji_width) / sqrt(0.5); ! } ! if (write_fun == write_ppm) { ! iheight *= ymag; ! iwidth *= xmag; ! } ! if (flip & 4) ! SWAP (iheight, iwidth); ! printf ("Output size: %d x %d\n\n", iwidth, iheight); } else printf ("%s is a %s %s image.\n", ifname, make, model); --- 6287,6291 ---- FORCC printf (" %f", cam_mul[c]); } ! putchar ('\n'); } else printf ("%s is a %s %s image.\n", ifname, make, model); |