From 4d515bb7ba93b462bc7871b38cdceec988c1e733 Mon Sep 17 00:00:00 2001 From: Good Guy Date: Mon, 5 Jun 2017 16:14:57 -0600 Subject: [PATCH] rework dcraw.c to c++, fix for filelist segv --- cinelerra-5.1/cinelerra/Makefile | 6 +- cinelerra-5.1/cinelerra/{dcraw.c => dcraw.C} | 193 +++----- cinelerra-5.1/cinelerra/dcraw.h | 454 +++++++++++-------- cinelerra-5.1/cinelerra/filecr2.C | 47 +- cinelerra-5.1/cinelerra/filecr2.h | 1 - cinelerra-5.1/cinelerra/filelist.C | 30 +- 6 files changed, 380 insertions(+), 351 deletions(-) rename cinelerra-5.1/cinelerra/{dcraw.c => dcraw.C} (98%) diff --git a/cinelerra-5.1/cinelerra/Makefile b/cinelerra-5.1/cinelerra/Makefile index bfb27354..512fe837 100644 --- a/cinelerra-5.1/cinelerra/Makefile +++ b/cinelerra-5.1/cinelerra/Makefile @@ -445,9 +445,9 @@ $(OBJDIR)/%.o: %.C $(OBJDIR)/sha1.o: sha1.C sha1.h $(CXX) `cat $(OBJDIR)/c_flags` -O3 -c $< -o $@ -$(DCRAW): dcraw.c - $(GCC) `cat $(OBJDIR)/c_flags` $(if $(findstring -ggdb,$(CFLAGS)),,-O4) -c -o $*.o \ - -Wno-misleading-indentation -Wno-sign-compare -Wno-narrowing dcraw.c +$(DCRAW): dcraw.C + $(CXX) `cat $(OBJDIR)/c_flags` $(if $(findstring -ggdb,$(CFLAGS)),,-O4) -DNODEPS -DLOCALTIME \ + -Wno-misleading-indentation -Wno-sign-compare -Wno-narrowing dcraw.C -c -o $*.o $(THEME_DATA): cd $(OBJDIR) && \ diff --git a/cinelerra-5.1/cinelerra/dcraw.c b/cinelerra-5.1/cinelerra/dcraw.C similarity index 98% rename from cinelerra-5.1/cinelerra/dcraw.c rename to cinelerra-5.1/cinelerra/dcraw.C index b78bba04..108042ad 100644 --- a/cinelerra-5.1/cinelerra/dcraw.c +++ b/cinelerra-5.1/cinelerra/dcraw.C @@ -42,10 +42,6 @@ #include #include -// CINELERRA -#define NODEPS -#define LOCALTIME - #if defined(DJGPP) || defined(__MINGW32__) #define fseeko fseek #define ftello ftell @@ -68,8 +64,9 @@ typedef unsigned __int64 UINT64; #include #include #include -typedef long long INT64; -typedef unsigned long long UINT64; +#include +typedef int64_t INT64; +typedef uint64_t UINT64; #endif #ifdef NODEPS @@ -93,12 +90,7 @@ typedef unsigned long long UINT64; #define _(String) (String) #endif -#if !defined(uchar) -#define uchar unsigned char -#endif -#if !defined(ushort) -#define ushort unsigned short -#endif +#include "dcraw.h" /* All global variables are defined here, and all functions that @@ -106,80 +98,6 @@ typedef unsigned long long UINT64; C++ class cannot have non-const static local variables. */ -// CINELERRA -char dcraw_info[1024]; -float **dcraw_data; -int dcraw_alpha; -float dcraw_matrix[9]; - -// CINELERRA -#define CLASS -struct jhead; -struct tiff_tag; -struct tiff_hdr; - -#include "dcraw.h" - -// CINELERRA -static FILE *ifp, *ofp; -static short order; -static const char *ifname; -static char *meta_data, xtrans[6][6], xtrans_abs[6][6]; -static char cdesc[5], desc[512], make[64], model[64], model2[64], artist[64]; -static float flash_used, canon_ev, iso_speed, shutter, aperture, focal_len; -static time_t timestamp; -static off_t strip_offset, data_offset; -static off_t thumb_offset, meta_offset, profile_offset; -static unsigned shot_order, kodak_cbpp, exif_cfa, unique_id; -static unsigned thumb_length, meta_length, profile_length; -static unsigned thumb_misc, *oprof, fuji_layout; -static unsigned tiff_nifds, tiff_samples, tiff_bps, tiff_compress; -static unsigned black, maximum, mix_green, raw_color, zero_is_bad; -static unsigned zero_after_ff, is_raw, dng_version, is_foveon, data_error; -static unsigned tile_width, tile_length, gpsdata[32], load_flags; -static unsigned flip, tiff_flip, filters, colors; -static ushort raw_height, raw_width, height, width, top_margin, left_margin; -static ushort shrink, iheight, iwidth, fuji_width, thumb_width, thumb_height; -static ushort *raw_image, (*image)[4], cblack[4102]; -static ushort white[8][8], curve[0x10000], cr2_slice[3], sraw_mul[4]; - -static unsigned shot_select=0, multi_out=0; -static double pixel_aspect, aber[4]={1,1,1,1}, gamm[6]={ 0.45,4.5,0,0,0,0 }; -static float bright=1, user_mul[4]={0,0,0,0}, threshold=0; -static int mask[8][4]; -static int half_size=0, four_color_rgb=0, document_mode=0, highlight=0; -static int verbose=0, use_auto_wb=0, use_camera_wb=0, use_camera_matrix=1; -static int output_color=1, output_bps=8, output_tiff=0, med_passes=0; -static int no_auto_bright=0; -static unsigned greybox[4] = { 0, 0, UINT_MAX, UINT_MAX }; -static float cam_mul[4], pre_mul[4], cmatrix[3][4], rgb_cam[3][4]; -static const double xyz_rgb[3][3] = { /* XYZ from RGB */ - { 0.412453, 0.357580, 0.180423 }, - { 0.212671, 0.715160, 0.072169 }, - { 0.019334, 0.119193, 0.950227 } }; -static const float d65_white[3] = { 0.950456, 1, 1.088754 }; -static int histogram[4][0x2000]; -static void (*write_thumb)(), (*write_fun)(); -static void (*load_raw)(), (*thumb_load_raw)(); -static jmp_buf failure; - -static struct decode { - struct decode *branch[2]; - int leaf; -} first_decode[2048], /* *second_decode, CINELERRA */ *free_decode; - -static struct tiff_ifd { - int width, height, bps, comp, phint, offset, flip, samples, bytes; - int tile_width, tile_length; - float shutter; -} tiff_ifd[10]; - -static struct ph1 { - int format, key_off, tag_21a; - int black, split_col, black_col, split_row, black_row; - float tag_210; -} ph1; - #define FORC(cnt) for (c=0; c < cnt; c++) #define FORC3 FORC(3) #define FORC4 FORC(4) @@ -269,8 +187,7 @@ int CLASS fcol (int row, int col) return FC(row,col); } -// CINELERRA -static void reset() +void CLASS reset() { // uninitialized #define ZERO(var) memset(&var, 0, sizeof var); @@ -380,6 +297,14 @@ static void reset() no_auto_bright = 0; greybox[0] = 0; greybox[1] = 0; greybox[2] = UINT_MAX; greybox[3] = UINT_MAX; +// local static + gbh_bitbuf = 0; gbh_vbits = 0; gbh_reset = 0; + ph1_bitbuf = 0; ph1_vbits = 0; + ZERO(ljpeg_cs); + ZERO(sony_pad); sony_p = 0; + ZERO(fov_huff); + ZERO(clb_cbrt); ZERO(clb_xyz_cam); + ZERO(pana_buf); pana_vbits = 0; } #if 0 @@ -418,7 +343,7 @@ void CLASS derror() if (feof(ifp)) fprintf (stderr,_("Unexpected end of file\n")); else - fprintf (stderr,_("Corrupt data near 0x%llx\n"), (INT64) ftello(ifp)); + fprintf (stderr,_("Corrupt data near 0x%jx\n"), (INT64) ftello(ifp)); } data_error++; } @@ -723,14 +648,15 @@ int CLASS canon_s2is() unsigned CLASS getbithuff (int nbits, ushort *huff) { - static unsigned bitbuf=0; - static int vbits=0, reset=0; unsigned c; + unsigned bitbuf; + int vbits, reset; if (nbits > 25) return 0; if (nbits < 0) - return bitbuf = vbits = reset = 0; - if (nbits == 0 || vbits < 0) return 0; + return gbh_bitbuf = gbh_vbits = gbh_reset = 0; + if (nbits == 0 || gbh_vbits < 0) return 0; + bitbuf = gbh_bitbuf; vbits = gbh_vbits; reset = gbh_reset; while (!reset && vbits < nbits && (c = fgetc(ifp)) != EOF && !(reset = zero_after_ff && c == 0xff && fgetc(ifp))) { bitbuf = (bitbuf << 8) + (uchar) c; @@ -743,6 +669,7 @@ unsigned CLASS getbithuff (int nbits, ushort *huff) } else vbits -= nbits; if (vbits < 0) derror(); + gbh_bitbuf = bitbuf; gbh_vbits = vbits; gbh_reset = reset; return c; } @@ -1129,7 +1056,7 @@ void CLASS canon_sraw_load_raw() ip = (short (*)[4]) image; rp = ip[0]; for (row=0; row < height; row++, ip+=width) { - if (row & (jh.sraw >> 1)) { //CINELERRA + if (row & (jh.sraw >> 1)) { for (col=0; col < width; col+=2) for (c=1; c < 3; c++) if (row == height-1) @@ -1186,8 +1113,7 @@ void CLASS adobe_copy_pixel (unsigned row, unsigned col, ushort **rp) void CLASS ljpeg_idct (struct jhead *jh) { int c, i, j, len, skip, coef; - float work[3][8][8]; - static float cs[106] = { 0 }; + float work[3][8][8], *cs = ljpeg_cs; static const uchar zigzag[80] = { 0, 1, 8,16, 9, 2, 3,10,17,24,32,25,18,11, 4, 5,12,19,26,33, 40,48,41,34,27,20,13, 6, 7,14,21,28,35,42,49,56,57,50,43,36, @@ -1472,8 +1398,6 @@ int CLASS minolta_z2() return nz > 20; } -void CLASS jpeg_thumb(); - void CLASS ppm_thumb() { char *thumb; @@ -1836,23 +1760,25 @@ void CLASS phase_one_load_raw() unsigned CLASS ph1_bithuff (int nbits, ushort *huff) { - static UINT64 bitbuf=0; - static int vbits=0; + UINT64 bitbuf; + int vbits; unsigned c; if (nbits == -1) - return bitbuf = vbits = 0; + return ph1_bitbuf = ph1_vbits = 0; if (nbits == 0) return 0; + bitbuf = ph1_bitbuf; vbits = ph1_vbits; if (vbits < nbits) { bitbuf = bitbuf << 32 | get4(); vbits += 32; } c = bitbuf << (64-vbits) >> (64-nbits); if (huff) { - vbits -= huff[c] >> 8; - return (uchar) huff[c]; + nbits = huff[c] >> 8; + c = (uchar) huff[c]; } vbits -= nbits; + ph1_bitbuf = bitbuf; ph1_vbits = vbits; return c; } #define ph1_bits(n) ph1_bithuff(n,0) @@ -2137,17 +2063,18 @@ void CLASS canon_rmf_load_raw() unsigned CLASS pana_bits (int nbits) { - static uchar buf[0x4000]; - static int vbits; + uchar *buf = pana_buf; + int vbits = pana_vbits; int byte; - if (!nbits) return vbits=0; + if (!nbits) return pana_vbits=0; if (!vbits) { fread (buf+load_flags, 1, 0x4000-load_flags, ifp); fread (buf, 1, load_flags, ifp); } vbits = (vbits - nbits) & 0x1ffff; byte = vbits >> 3 ^ 0x3ff0; + pana_vbits = vbits; return (buf[byte] | buf[byte+1] << 8) >> (vbits & 7) & ~(-1 << nbits); } @@ -2783,8 +2710,7 @@ void CLASS kodak_thumb_load_raw() void CLASS sony_decrypt (unsigned *data, int len, int start, int key) { - static unsigned pad[128], p; - + unsigned p = sony_p, *pad = sony_pad;; if (start) { for (p=0; p < 4; p++) pad[p] = key = key * 48828125 + 1; @@ -2796,6 +2722,7 @@ void CLASS sony_decrypt (unsigned *data, int len, int start, int key) } while (len-- && p++) *data++ ^= pad[(p-1) & 127] = pad[p & 127] ^ pad[(p+64) & 127]; + sony_p = p; } void CLASS sony_load_raw() @@ -2983,7 +2910,6 @@ void CLASS samsung3_load_raw() /* Kudos to Rich Taylor for figuring out SMaL's compression algorithm. */ void CLASS smal_decode_segment (unsigned seg[2][2], int holes) { -// CINELERRA uchar hist[3][18] = { { 7, 7, 0, 0, 63, 55, 47, 39, 31, 23, 15, 7, 0 }, { 7, 7, 0, 0, 63, 55, 47, 39, 31, 23, 15, 7, 0 }, @@ -3172,7 +3098,7 @@ void CLASS redcine_load_raw() void CLASS foveon_decoder (unsigned size, unsigned code) { - static unsigned huff[1024]; + unsigned *huff = fov_huff; struct decode *cur; int i, len; @@ -4555,7 +4481,7 @@ void CLASS lin_interpolate() */ void CLASS vng_interpolate() { - static const signed char *cp, terms[] = { + static const signed char terms[] = { -2,-2,+0,-1,0,0x01, -2,-2,+0,+0,1,0x01, -2,-1,-1,+0,0,0x01, -2,-1,+0,-1,0,0x02, -2,-1,+0,+0,0,0x03, -2,-1,+0,+1,1,0x01, -2,+0,+0,-1,0,0x06, -2,+0,+0,+0,1,0x02, -2,+0,+0,+1,0,0x03, @@ -4579,6 +4505,7 @@ void CLASS vng_interpolate() +1,-1,+1,+1,0,0x88, +1,+0,+1,+2,0,0x08, +1,+0,+2,-1,0,0x40, +1,+0,+2,+1,0,0x10 }, chood[] = { -1,-1, -1,0, -1,+1, 0,+1, +1,+1, +1,0, +1,-1, 0,-1 }; + const signed char *cp; ushort (*brow[5])[4], *pix; int prow=8, pcol=2, *ip, *code[16][16], gval[8], gmin, gmax, sum[4]; int row, col, x, y, x1, x2, y1, y2, t, weight, grads, color, diag; @@ -4688,6 +4615,7 @@ void CLASS ppg_interpolate() int dir[5] = { 1, width, -1, -width, 1 }; int row, col, diff[2], guess[2], c, d, i; ushort (*pix)[4]; + diff[0] = diff[1] = 0; border_interpolate(3); if (verbose) fprintf (stderr,_("PPG interpolation...\n")); @@ -4738,7 +4666,7 @@ void CLASS cielab (ushort rgb[3], short lab[3]) { int c, i, j, k; float r, xyz[3]; - static float cbrt[0x10000], xyz_cam[3][4]; + float *cbrt = clb_cbrt, (*xyz_cam)[4] = clb_xyz_cam; if (!rgb) { for (i=0; i < 0x10000; i++) { @@ -5274,8 +5202,6 @@ void CLASS parse_thumb_note (int base, unsigned toff, unsigned tlen) } } -int CLASS parse_tiff_ifd (int base); - void CLASS parse_makernote (int base, int uptag) { static const uchar xlat[2][256] = { @@ -5802,9 +5728,6 @@ void CLASS parse_kodak_ifd (int base) } } -void CLASS parse_minolta (int base); -int CLASS parse_tiff (int base); - int CLASS parse_tiff_ifd (int base) { unsigned entries, tag, type, len, plen=16, save; @@ -9546,9 +9469,9 @@ notraw: case 90: flp = 6; } if( (flp & 4) ) - sprintf(dcraw_info, "%d %d", height, width); + sprintf(info, "%d %d", height, width); else - sprintf(dcraw_info, "%d %d", width, height); } + sprintf(info, "%d %d", width, height); } } #ifndef NO_LCMS @@ -9716,7 +9639,7 @@ void CLASS convert_to_rgb() k = 0; for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) - dcraw_matrix[k++] = rgb_cam[i][j]; + matrix[k++] = rgb_cam[i][j]; } } @@ -9867,7 +9790,7 @@ void CLASS tiff_head (struct tiff_hdr *th, int full) strncpy (th->desc, desc, 512); strncpy (th->make, make, 64); strncpy (th->model, model, 64); - strcpy (th->soft, "dcraw v"DCRAW_VERSION); + strcpy (th->soft, "dcraw v" DCRAW_VERSION); t = localtime (×tamp); sprintf (th->date, "%04d:%02d:%02d %02d:%02d:%02d", t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); @@ -10007,11 +9930,11 @@ void CLASS write_cinelerra() rstep = flip_index(1, 0) - flip_index(0, width); if( document_mode ) { for( row=0; row*load_raw)(); if (document_mode == 3) { top_margin = left_margin = fuji_width = 0; height = raw_height; @@ -10457,7 +10381,7 @@ thumbnail: } if (verbose) fprintf (stderr,_("Writing data to %s ...\n"), ofname); - (*write_fun)(); + (this->*write_fun)(); fclose(ifp); if (ofp != stdout) fclose(ofp); cleanup: @@ -10472,3 +10396,16 @@ cleanup: } return status; } + +DCRaw::DCRaw() +{ + ZERO(info); + data = 0; + alpha = 0; + ZERO(matrix); +} + +DCRaw::~DCRaw() +{ +} + diff --git a/cinelerra-5.1/cinelerra/dcraw.h b/cinelerra-5.1/cinelerra/dcraw.h index df53ff2b..5101b853 100644 --- a/cinelerra-5.1/cinelerra/dcraw.h +++ b/cinelerra-5.1/cinelerra/dcraw.h @@ -1,188 +1,286 @@ - /* CINELERRA dcraw.c */ -static int CLASS fcol(int row,int col); + +#include +#include +#include + +#define CLASS DCRaw:: + +#if !defined(uchar) +#define uchar unsigned char +#endif +#if !defined(ushort) +#define ushort unsigned short +#endif + +class DCRaw { + int fcol(int row,int col); #if 0 -static char *my_memmem(char *haystack,size_t haystacklen,char *needle,size_t needlelen); -static char *my_strcasestr(char *haystack,const char *needle); + char *my_memmem(char *haystack,size_t haystacklen,char *needle,size_t needlelen); + char *my_strcasestr(char *haystack,const char *needle); #endif -static void CLASS merror(void *ptr,const char *where); -static void CLASS derror(void); -static ushort CLASS sget2(uchar *s); -static ushort CLASS get2(void); -static unsigned CLASS sget4(uchar *s); -static unsigned CLASS get4(void); -static unsigned CLASS getint(int type); -static float CLASS int_to_float(int i); -static double CLASS getreal(int type); -static void CLASS read_shorts(ushort *pixel,int count); -static void CLASS cubic_spline(const int *x_,const int *y_,const int len); -static void CLASS canon_600_fixed_wb(int temp); -static int CLASS canon_600_color(int ratio[2],int mar); -static void CLASS canon_600_auto_wb(void); -static void CLASS canon_600_coeff(void); -static void CLASS canon_600_load_raw(void); -static void CLASS canon_600_correct(void); -static int CLASS canon_s2is(void); -static unsigned CLASS getbithuff(int nbits,ushort *huff); -static ushort *CLASS make_decoder_ref(const uchar **source); -static ushort *CLASS make_decoder(const uchar *source); -static void CLASS crw_init_tables(unsigned table,ushort *huff[2]); -static int CLASS canon_has_lowbits(void); -static void CLASS canon_load_raw(void); -static int CLASS ljpeg_start(struct jhead *jh,int info_only); -static void CLASS ljpeg_end(struct jhead *jh); -static int CLASS ljpeg_diff(ushort *huff); -static ushort *CLASS ljpeg_row(int jrow,struct jhead *jh); -static void CLASS lossless_jpeg_load_raw(void); -static void CLASS canon_sraw_load_raw(void); -static void CLASS adobe_copy_pixel(unsigned row,unsigned col,ushort **rp); -static void CLASS ljpeg_idct(struct jhead *jh); -static void CLASS lossless_dng_load_raw(void); -static void CLASS packed_dng_load_raw(void); -static void CLASS pentax_load_raw(void); -static void CLASS nikon_load_raw(void); -static void CLASS nikon_yuv_load_raw(void); -static int CLASS nikon_e995(void); -static int CLASS nikon_e2100(void); -static void CLASS nikon_3700(void); -static int CLASS minolta_z2(void); -static void CLASS ppm_thumb(void); -static void CLASS ppm16_thumb(void); -static void CLASS layer_thumb(void); -static void CLASS rollei_thumb(void); -static void CLASS rollei_load_raw(void); -static int CLASS raw(unsigned row,unsigned col); -static void CLASS phase_one_flat_field(int is_float,int nc); -static void CLASS phase_one_correct(void); -static void CLASS phase_one_load_raw(void); -static unsigned CLASS ph1_bithuff(int nbits,ushort *huff); -static void CLASS phase_one_load_raw_c(void); -static void CLASS hasselblad_load_raw(void); -static void CLASS leaf_hdr_load_raw(void); -static void CLASS unpacked_load_raw(void); -static void CLASS sinar_4shot_load_raw(void); -static void CLASS imacon_full_load_raw(void); -static void CLASS packed_load_raw(void); -static void CLASS nokia_load_raw(void); -static void CLASS canon_rmf_load_raw(void); -static unsigned CLASS pana_bits(int nbits); -static void CLASS panasonic_load_raw(void); -static void CLASS olympus_load_raw(void); -static void CLASS minolta_rd175_load_raw(void); -static void CLASS quicktake_100_load_raw(void); -static void CLASS kodak_radc_load_raw(void); -static void CLASS kodak_jpeg_load_raw(void); -static void CLASS lossy_dng_load_raw(void); + void merror(void *ptr,const char *where); + void derror(void); + ushort sget2(uchar *s); + ushort get2(void); + unsigned sget4(uchar *s); + unsigned get4(void); + unsigned getint(int type); + float int_to_float(int i); + double getreal(int type); + void read_shorts(ushort *pixel,int count); + void cubic_spline(const int *x_,const int *y_,const int len); + void canon_600_fixed_wb(int temp); + int canon_600_color(int ratio[2],int mar); + void canon_600_auto_wb(void); + void canon_600_coeff(void); + void canon_600_load_raw(void); + void canon_600_correct(void); + int canon_s2is(void); + unsigned getbithuff(int nbits,ushort *huff); + ushort *make_decoder_ref(const uchar **source); + ushort *make_decoder(const uchar *source); + void crw_init_tables(unsigned table,ushort *huff[2]); + int canon_has_lowbits(void); + void canon_load_raw(void); + int ljpeg_start(struct jhead *jh,int info_only); + void ljpeg_end(struct jhead *jh); + int ljpeg_diff(ushort *huff); + ushort *ljpeg_row(int jrow,struct jhead *jh); + void lossless_jpeg_load_raw(void); + void canon_sraw_load_raw(void); + void adobe_copy_pixel(unsigned row,unsigned col,ushort **rp); + void ljpeg_idct(struct jhead *jh); + void lossless_dng_load_raw(void); + void packed_dng_load_raw(void); + void pentax_load_raw(void); + void nikon_load_raw(void); + void nikon_yuv_load_raw(void); + int nikon_e995(void); + int nikon_e2100(void); + void nikon_3700(void); + int minolta_z2(void); + void ppm_thumb(void); + void ppm16_thumb(void); + void layer_thumb(void); + void rollei_thumb(void); + void rollei_load_raw(void); + int raw(unsigned row,unsigned col); + void phase_one_flat_field(int is_float,int nc); + void phase_one_correct(void); + void phase_one_load_raw(void); + unsigned ph1_bithuff(int nbits,ushort *huff); + void phase_one_load_raw_c(void); + void hasselblad_load_raw(void); + void leaf_hdr_load_raw(void); + void unpacked_load_raw(void); + void sinar_4shot_load_raw(void); + void imacon_full_load_raw(void); + void packed_load_raw(void); + void nokia_load_raw(void); + void canon_rmf_load_raw(void); + unsigned pana_bits(int nbits); + void panasonic_load_raw(void); + void olympus_load_raw(void); + void minolta_rd175_load_raw(void); + void quicktake_100_load_raw(void); + void kodak_radc_load_raw(void); + void kodak_jpeg_load_raw(void); + void lossy_dng_load_raw(void); #ifndef NO_JPEG -static int boolean fill_input_buffer(j_decompress_ptr cinfo); + boolean fill_input_buffer(j_decompress_ptr cinfo); #endif -static void CLASS kodak_jpeg_load_raw(void); -static void CLASS lossy_dng_load_raw(void); -static void CLASS kodak_dc120_load_raw(void); -static void CLASS eight_bit_load_raw(void); -static void CLASS kodak_c330_load_raw(void); -static void CLASS kodak_c603_load_raw(void); -static void CLASS kodak_262_load_raw(void); -static int CLASS kodak_65000_decode(short *out,int bsize); -static void CLASS kodak_65000_load_raw(void); -static void CLASS kodak_ycbcr_load_raw(void); -static void CLASS kodak_rgb_load_raw(void); -static void CLASS kodak_thumb_load_raw(void); -static void CLASS sony_decrypt(unsigned *data,int len,int start,int key); -static void CLASS sony_load_raw(void); -static void CLASS sony_arw_load_raw(void); -static void CLASS sony_arw2_load_raw(void); -static void CLASS samsung_load_raw(void); -static void CLASS samsung2_load_raw(void); -static void CLASS samsung3_load_raw(void); -static void CLASS smal_decode_segment(unsigned seg[2][2],int holes); -static void CLASS smal_v6_load_raw(void); -static int CLASS median4(int *p); -static void CLASS fill_holes(int holes); -static void CLASS smal_v9_load_raw(void); -static void CLASS redcine_load_raw(void); -static void CLASS foveon_decoder(unsigned size,unsigned code); -static void CLASS foveon_thumb(void); -static void CLASS foveon_sd_load_raw(void); -static void CLASS foveon_huff(ushort *huff); -static void CLASS foveon_dp_load_raw(void); -static void CLASS foveon_load_camf(void); -static const char *CLASS foveon_camf_param(const char *block,const char *param); -static void *CLASS foveon_camf_matrix(unsigned dim[3],const char *name); -static int CLASS foveon_fixed(void *ptr,int size,const char *name); -static float CLASS foveon_avg(short *pix,int range[2],float cfilt); -static short *CLASS foveon_make_curve(double max,double mul,double filt); -static void CLASS foveon_make_curves(short **curvep,float dq[3],float div[3],float filt); -static int CLASS foveon_apply_curve(short *curve,int i); -static void CLASS foveon_interpolate(void); -static void CLASS crop_masked_pixels(void); -static void CLASS remove_zeroes(void); -static void CLASS bad_pixels(const char *cfname); -static void CLASS subtract(const char *fname); -static void CLASS gamma_curve(double pwr,double ts,int mode,int imax); -static void CLASS pseudoinverse (double (*in)[3],double (*out)[3],int size); -static void CLASS cam_xyz_coeff(float rgb_cam[3][4],double cam_xyz[4][3]); + void kodak_dc120_load_raw(void); + void eight_bit_load_raw(void); + void kodak_c330_load_raw(void); + void kodak_c603_load_raw(void); + void kodak_262_load_raw(void); + int kodak_65000_decode(short *out,int bsize); + void kodak_65000_load_raw(void); + void kodak_ycbcr_load_raw(void); + void kodak_rgb_load_raw(void); + void kodak_thumb_load_raw(void); + void sony_decrypt(unsigned *data,int len,int start,int key); + void sony_load_raw(void); + void sony_arw_load_raw(void); + void sony_arw2_load_raw(void); + void samsung_load_raw(void); + void samsung2_load_raw(void); + void samsung3_load_raw(void); + void smal_decode_segment(unsigned seg[2][2],int holes); + void smal_v6_load_raw(void); + int median4(int *p); + void fill_holes(int holes); + void smal_v9_load_raw(void); + void redcine_load_raw(void); + void foveon_decoder(unsigned size,unsigned code); + void foveon_thumb(void); + void foveon_sd_load_raw(void); + void foveon_huff(ushort *huff); + void foveon_dp_load_raw(void); + void foveon_load_camf(void); + const char *foveon_camf_param(const char *block,const char *param); + void *foveon_camf_matrix(unsigned dim[3],const char *name); + int foveon_fixed(void *ptr,int size,const char *name); + float foveon_avg(short *pix,int range[2],float cfilt); + short *foveon_make_curve(double max,double mul,double filt); + void foveon_make_curves(short **curvep,float dq[3],float div[3],float filt); + int foveon_apply_curve(short *curve,int i); + void foveon_interpolate(void); + void crop_masked_pixels(void); + void remove_zeroes(void); + void bad_pixels(const char *cfname); + void subtract(const char *fname); + void gamma_curve(double pwr,double ts,int mode,int imax); + void pseudoinverse (double (*in)[3],double (*out)[3],int size); + void cam_xyz_coeff(float rgb_cam[3][4],double cam_xyz[4][3]); #ifdef COLORCHECK -static void CLASS colorcheck(void); + void colorcheck(void); #endif -static void CLASS hat_transform(float *temp,float *base,int st,int size,int sc); -static void CLASS wavelet_denoise(void); -static void CLASS scale_colors(void); -static void CLASS pre_interpolate(void); -static void CLASS border_interpolate(int border); -static void CLASS lin_interpolate(void); -static void CLASS vng_interpolate(void); -static void CLASS ppg_interpolate(void); -static void CLASS cielab(ushort rgb[3],short lab[3]); -static void CLASS xtrans_interpolate(int passes); -static void CLASS ahd_interpolate(void); -static void CLASS median_filter(void); -static void CLASS blend_highlights(void); -static void CLASS recover_highlights(void); -static void CLASS tiff_get(unsigned base,unsigned *tag,unsigned *type,unsigned *len,unsigned *save); -static void CLASS parse_thumb_note(int base,unsigned toff,unsigned tlen); -static void CLASS parse_makernote(int base,int uptag); -static void CLASS get_timestamp(int reversed); -static void CLASS parse_exif(int base); -static void CLASS parse_gps(int base); -static void CLASS romm_coeff(float romm_cam[3][3]); -static void CLASS parse_mos(int offset); -static void CLASS linear_table(unsigned len); -static void CLASS parse_kodak_ifd(int base); -static int CLASS parse_tiff_ifd(int base); -static int CLASS parse_tiff(int base); -static void CLASS apply_tiff(void); -static void CLASS parse_minolta(int base); -static void CLASS parse_external_jpeg(void); -static void CLASS ciff_block_1030(void); -static void CLASS parse_ciff(int offset,int length,int depth); -static void CLASS parse_rollei(void); -static void CLASS parse_sinar_ia(void); -static void CLASS parse_phase_one(int base); -static void CLASS parse_fuji(int offset); -static int CLASS parse_jpeg(int offset); -static void CLASS parse_riff(void); -static void CLASS parse_qt(int end); -static void CLASS parse_smal(int offset,int fsize); -static void CLASS parse_cine(void); -static void CLASS parse_redcine(void); -static char *CLASS foveon_gets(int offset,char *str,int len); -static void CLASS parse_foveon(void); -static void CLASS adobe_coeff(const char *make,const char *model); -static void CLASS simple_coeff(int index); -static short CLASS guess_byte_order(int words); -static float CLASS find_green(int bps,int bite,int off0,int off1); -static void CLASS identify(void); + void hat_transform(float *temp,float *base,int st,int size,int sc); + void wavelet_denoise(void); + void scale_colors(void); + void pre_interpolate(void); + void border_interpolate(int border); + void lin_interpolate(void); + void vng_interpolate(void); + void ppg_interpolate(void); + void cielab(ushort rgb[3],short lab[3]); + void xtrans_interpolate(int passes); + void ahd_interpolate(void); + void median_filter(void); + void blend_highlights(void); + void recover_highlights(void); + void tiff_get(unsigned base,unsigned *tag,unsigned *type,unsigned *len,unsigned *save); + void parse_thumb_note(int base,unsigned toff,unsigned tlen); + void parse_makernote(int base,int uptag); + void get_timestamp(int reversed); + void parse_exif(int base); + void parse_gps(int base); + void romm_coeff(float romm_cam[3][3]); + void parse_mos(int offset); + void linear_table(unsigned len); + void parse_kodak_ifd(int base); + int parse_tiff_ifd(int base); + int parse_tiff(int base); + void apply_tiff(void); + void parse_minolta(int base); + void parse_external_jpeg(void); + void ciff_block_1030(void); + void parse_ciff(int offset,int length,int depth); + void parse_rollei(void); + void parse_sinar_ia(void); + void parse_phase_one(int base); + void parse_fuji(int offset); + int parse_jpeg(int offset); + void parse_riff(void); + void parse_qt(int end); + void parse_smal(int offset,int fsize); + void parse_cine(void); + void parse_redcine(void); + char *foveon_gets(int offset,char *str,int len); + void parse_foveon(void); + void adobe_coeff(const char *make,const char *model); + void simple_coeff(int index); + short guess_byte_order(int words); + float find_green(int bps,int bite,int off0,int off1); + void identify(void); #ifndef NO_LCMS -static void CLASS apply_profile(const char *input,const char *output); + void apply_profile(const char *input,const char *output); #endif -static void CLASS convert_to_rgb(void); -static void CLASS fuji_rotate(void); -static void CLASS stretch(void); -static int CLASS flip_index(int row, int col); -static void CLASS tiff_set(struct tiff_hdr *th,ushort *ntag,ushort tag,ushort type,int count,int val); -static void CLASS tiff_head(struct tiff_hdr *th,int full); -static void CLASS jpeg_thumb(void); -static void CLASS write_ppm_tiff(void); -static void CLASS write_cinelerra(void); + void convert_to_rgb(void); + void fuji_rotate(void); + void stretch(void); + int flip_index(int row, int col); + void tiff_set(struct tiff_hdr *th,ushort *ntag,ushort tag,ushort type,int count,int val); + void tiff_head(struct tiff_hdr *th,int full); + void jpeg_thumb(void); + void write_ppm_tiff(void); + void write_cinelerra(void); + void reset(); + + FILE *ifp, *ofp; + short order; + const char *ifname; + char *meta_data, xtrans[6][6], xtrans_abs[6][6]; + char cdesc[5], desc[512], make[64], model[64], model2[64], artist[64]; + float flash_used, canon_ev, iso_speed, shutter, aperture, focal_len; + time_t timestamp; + off_t strip_offset, data_offset; + off_t thumb_offset, meta_offset, profile_offset; + unsigned shot_order, kodak_cbpp, exif_cfa, unique_id; + unsigned thumb_length, meta_length, profile_length; + unsigned thumb_misc, *oprof, fuji_layout; + unsigned tiff_nifds, tiff_samples, tiff_bps, tiff_compress; + unsigned black, maximum, mix_green, raw_color, zero_is_bad; + unsigned zero_after_ff, is_raw, dng_version, is_foveon, data_error; + unsigned tile_width, tile_length, gpsdata[32], load_flags; + unsigned flip, tiff_flip, filters, colors; + ushort raw_height, raw_width, height, width, top_margin, left_margin; + ushort shrink, iheight, iwidth, fuji_width, thumb_width, thumb_height; + ushort *raw_image, (*image)[4], cblack[4102]; + ushort white[8][8], curve[0x10000], cr2_slice[3], sraw_mul[4]; + + unsigned shot_select, multi_out; + double pixel_aspect, aber[4], gamm[6]; + float bright, user_mul[4], threshold; + int mask[8][4]; + int half_size, four_color_rgb, document_mode, highlight; + int verbose, use_auto_wb, use_camera_wb, use_camera_matrix; + int output_color, output_bps, output_tiff, med_passes; + int no_auto_bright; + unsigned greybox[4]; + float cam_mul[4], pre_mul[4], cmatrix[3][4], rgb_cam[3][4]; + const double xyz_rgb[3][3] = { /* XYZ from RGB */ + { 0.412453, 0.357580, 0.180423 }, + { 0.212671, 0.715160, 0.072169 }, + { 0.019334, 0.119193, 0.950227 } }; + const float d65_white[3] = { 0.950456, 1, 1.088754 }; + int histogram[4][0x2000]; + void (CLASS *write_thumb)(), (CLASS *write_fun)(); + void (CLASS *load_raw)(), (CLASS *thumb_load_raw)(); + jmp_buf failure; + + struct decode { + struct decode *branch[2]; + int leaf; + } first_decode[2048], /* *second_decode, CINELERRA */ *free_decode; + + struct tiff_ifd { + int width, height, bps, comp, phint, offset, flip, samples, bytes; + int tile_width, tile_length; + float shutter; + } tiff_ifd[10]; + + struct ph1 { + int format, key_off, tag_21a; + int black, split_col, black_col, split_row, black_row; + float tag_210; + } ph1; + +// local static data + unsigned gbh_bitbuf; + int gbh_vbits, gbh_reset; + uint64_t ph1_bitbuf; + int ph1_vbits; + float ljpeg_cs[106]; + unsigned sony_pad[128], sony_p; + unsigned fov_huff[1024]; + float clb_cbrt[0x10000], clb_xyz_cam[3][4]; + uchar pana_buf[0x4000]; int pana_vbits; + +public: + DCRaw(); + ~DCRaw(); + + char info[1024]; + float **data; + int alpha; + float matrix[9]; + int main(int argc, const char **argv); +}; + +struct jhead; +struct tiff_tag; +struct tiff_hdr; diff --git a/cinelerra-5.1/cinelerra/filecr2.C b/cinelerra-5.1/cinelerra/filecr2.C index 84b07aa8..f7466a0c 100644 --- a/cinelerra-5.1/cinelerra/filecr2.C +++ b/cinelerra-5.1/cinelerra/filecr2.C @@ -30,29 +30,23 @@ #include -extern "C" -{ -extern char dcraw_info[1024]; -extern float **dcraw_data; -extern int dcraw_alpha; -extern float dcraw_matrix[9]; -int dcraw_main (int argc, const char **argv); -} - -Mutex FileCR2::dcraw_lock; +#define NODEPS +#define NO_JASPER +#define NO_JPEG +#define NO_LCMS +#include "dcraw.h" int FileCR2::dcraw_run(FileCR2 *file, int argc, const char **argv, VFrame *frame) { - dcraw_lock.lock("dcraw_run"); - memset(dcraw_info, 0, sizeof(dcraw_info)); - memset(dcraw_matrix, 0, sizeof(dcraw_matrix)); - dcraw_data = !frame ? 0 : (float**) frame->get_rows(); - dcraw_alpha = !frame ? 0 : - frame->get_color_model() == BC_RGBA_FLOAT ? 1 : 0; - int result = dcraw_main(argc, argv); - if( !result && file ) - file->format_to_asset(dcraw_info); - if( !result && frame ) { + DCRaw dcraw; + if( frame ) { + dcraw.data = (float**) frame->get_rows(); + dcraw.alpha = frame->get_color_model() == BC_RGBA_FLOAT ? 1 : 0; + } + int result = dcraw.main(argc, argv); + if( file ) + file->format_to_asset(dcraw.info); + if( frame ) { // This was only used by the bayer interpolate plugin, which itself created // too much complexity to use effectively. // It required bypassing the cache any time a plugin parameter changed @@ -61,14 +55,12 @@ int FileCR2::dcraw_run(FileCR2 *file, int argc, const char **argv, VFrame *frame // from dcraw or a plugin & replace it. char string[BCTEXTLEN]; sprintf(string, "%f %f %f %f %f %f %f %f %f\n", - dcraw_matrix[0], dcraw_matrix[1], dcraw_matrix[2], - dcraw_matrix[3], dcraw_matrix[4], dcraw_matrix[5], - dcraw_matrix[6], dcraw_matrix[7], dcraw_matrix[8]); + dcraw.matrix[0], dcraw.matrix[1], dcraw.matrix[2], + dcraw.matrix[3], dcraw.matrix[4], dcraw.matrix[5], + dcraw.matrix[6], dcraw.matrix[7], dcraw.matrix[8]); frame->get_params()->update("DCRAW_MATRIX", string); // frame->dump_params(); } - - dcraw_lock.unlock(); return result; } @@ -140,11 +132,6 @@ int FileCR2::read_frame(VFrame *frame, char *path) { //printf("FileCR2::read_frame\n"); - if(frame->get_color_model() == BC_RGBA_FLOAT) - dcraw_alpha = 1; - else - dcraw_alpha = 0; - // Want to disable interpolation if an interpolation plugin is on, but // this is impractical because of the amount of caching. The interpolation // could not respond to a change in the plugin settings and it could not diff --git a/cinelerra-5.1/cinelerra/filecr2.h b/cinelerra-5.1/cinelerra/filecr2.h index 1e3884d7..3230e45a 100644 --- a/cinelerra-5.1/cinelerra/filecr2.h +++ b/cinelerra-5.1/cinelerra/filecr2.h @@ -39,7 +39,6 @@ class FileCR2 : public FileList { - static Mutex dcraw_lock; static int dcraw_run(FileCR2 *file, int argc, const char **argv, VFrame *frame=0); void format_to_asset(const char *info); public: diff --git a/cinelerra-5.1/cinelerra/filelist.C b/cinelerra-5.1/cinelerra/filelist.C index e910e8e8..9f24e67a 100644 --- a/cinelerra-5.1/cinelerra/filelist.C +++ b/cinelerra-5.1/cinelerra/filelist.C @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -76,22 +77,27 @@ int FileList::reset_parameters_derived() int FileList::open_file(int rd, int wr) { - int result = 0; + int result = 1; // skip header for write if(file->wr) { + int fd = open(asset->path, O_CREAT+O_TRUNC+O_RDWR, 0777); + if( fd >= 0 ) { + close(fd); + result = 0; // Frame files are created in write_frame and list index is created when // file is closed. // Look for the starting number in the path but ignore the starting character // and total digits since these are used by the header. - Render::get_starting_number(asset->path, - first_number, - number_start, - number_digits); - path_list.remove_all_objects(); - writer = new FrameWriter(this, + Render::get_starting_number(asset->path, + first_number, number_start, number_digits); + path_list.remove_all_objects(); + writer = new FrameWriter(this, asset->format == list_type ? file->cpus : 1); + } + else + eprintf(_("Error while opening \"%s\" for writing. \n%m\n"), asset->path); } else if(file->rd) @@ -132,15 +138,16 @@ int FileList::open_file(int rd, int wr) asset->frame_rate = 1; asset->video_length = -1; } + result = 0; } + else + eprintf(_("Error while opening \"%s\" for reading. \n%m\n"), asset->path); } else { Render::get_starting_number(asset->path, - first_number, - number_start, - number_digits, - 6); + first_number, number_start, number_digits, 6); + result = 0; } } @@ -172,6 +179,7 @@ int FileList::close_file() int FileList::write_list_header() { FILE *stream = fopen(asset->path, "w"); + if( !stream ) return 1; // Use sprintf instead of fprintf for VFS. char string[BCTEXTLEN]; sprintf(string, "%s\n", list_prefix); -- 2.26.2