diff --git a/rtengine/dcraw.cc b/rtengine/dcraw.cc index c25be2170..2d00ef936 100644 --- a/rtengine/dcraw.cc +++ b/rtengine/dcraw.cc @@ -1,6 +1,5 @@ /*RT*/#include /*RT*/#include -/*RT*/int ciff_base, ciff_len, exif_base, pre_filters; /*RT*/#undef MAX /*RT*/#undef MIN /*RT*/#define NO_LCMS @@ -111,60 +110,70 @@ typedef unsigned long long UINT64; typedef unsigned char uchar; typedef unsigned short ushort; +// RT specify thread local storage +#ifdef __GNUC__ +#define THREAD_LOCAL static __thread +#define THREAD_LOCK +#else +#define THREAD_LOCAL +#define THREAD_LOCK Glib::Mutex::Lock locker(*dcrMutex); +#endif + /* All global variables are defined here, and all functions that access them are prefixed with "CLASS". Note that a thread-safe C++ class cannot have non-const static local variables. */ -/*RT*/IMFILE *ifp; -FILE * ofp; -short order; -const char *ifname; -char *meta_data; -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; -unsigned shot_order, kodak_cbpp, filters, exif_cfa, unique_id; -off_t strip_offset, data_offset; -off_t thumb_offset, meta_offset, profile_offset; -unsigned thumb_length, meta_length, profile_length; -unsigned thumb_misc, *oprof, fuji_layout, shot_select=0, multi_out=0; -unsigned tiff_nifds, tiff_samples, tiff_bps, tiff_compress; -unsigned black, cblack[8], 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; -ushort raw_height, raw_width, height, width, top_margin, left_margin; -ushort shrink, iheight, iwidth, fuji_width, thumb_width, thumb_height; -int flip, tiff_flip, colors; -double pixel_aspect, aber[4]={1,1,1,1}, gamm[6]={ 0.45,4.5,0,0,0,0 }; -ushort (*image)[4], white[8][8], curve[0x10000], cr2_slice[3], sraw_mul[4]; -float bright=1, user_mul[4]={0,0,0,0}, threshold=0; -int half_size=0, four_color_rgb=0, document_mode=0, highlight=0; -int verbose=0, use_auto_wb=0, use_camera_wb=0, use_camera_matrix=-1; -int output_color=1, output_bps=8, output_tiff=0, med_passes=0; -int no_auto_bright=0; -unsigned greybox[4] = { 0, 0, UINT_MAX, UINT_MAX }; -float cam_mul[4], pre_mul[4], cmatrix[3][4], rgb_cam[3][4]; -const double xyz_rgb[3][3] = { /* XYZ from RGB */ +/*RT*/THREAD_LOCAL int ciff_base, ciff_len, exif_base, pre_filters; +/*RT*/THREAD_LOCAL IMFILE *ifp; +THREAD_LOCAL FILE * ofp; +THREAD_LOCAL short order; +THREAD_LOCAL const char *ifname; +THREAD_LOCAL char *meta_data; +THREAD_LOCAL char cdesc[5], desc[512], make[64], model[64], model2[64], artist[64]; +THREAD_LOCAL float flash_used, canon_ev, iso_speed, shutter, aperture, focal_len; +THREAD_LOCAL time_t timestamp; +THREAD_LOCAL unsigned shot_order, kodak_cbpp, filters, exif_cfa, unique_id; +THREAD_LOCAL off_t strip_offset, data_offset; +THREAD_LOCAL off_t thumb_offset, meta_offset, profile_offset; +THREAD_LOCAL unsigned thumb_length, meta_length, profile_length; +THREAD_LOCAL unsigned thumb_misc, *oprof, fuji_layout, shot_select=0, multi_out=0; +THREAD_LOCAL unsigned tiff_nifds, tiff_samples, tiff_bps, tiff_compress; +THREAD_LOCAL unsigned black, cblack[8], maximum, mix_green, raw_color, zero_is_bad; +THREAD_LOCAL unsigned zero_after_ff, is_raw, dng_version, is_foveon, data_error; +THREAD_LOCAL unsigned tile_width, tile_length, gpsdata[32], load_flags; +THREAD_LOCAL ushort raw_height, raw_width, height, width, top_margin, left_margin; +THREAD_LOCAL ushort shrink, iheight, iwidth, fuji_width, thumb_width, thumb_height; +THREAD_LOCAL int flip, tiff_flip, colors; +THREAD_LOCAL double pixel_aspect, aber[4]={1,1,1,1}, gamm[6]={ 0.45,4.5,0,0,0,0 }; +THREAD_LOCAL ushort (*image)[4], white[8][8], curve[0x10000], cr2_slice[3], sraw_mul[4]; +THREAD_LOCAL float bright=1, user_mul[4]={0,0,0,0}, threshold=0; +THREAD_LOCAL int half_size=0, four_color_rgb=0, document_mode=0, highlight=0; +THREAD_LOCAL int verbose=0, use_auto_wb=0, use_camera_wb=0, use_camera_matrix=-1; +THREAD_LOCAL int output_color=1, output_bps=8, output_tiff=0, med_passes=0; +THREAD_LOCAL int no_auto_bright=0; +THREAD_LOCAL unsigned greybox[4] = { 0, 0, UINT_MAX, UINT_MAX }; +THREAD_LOCAL 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 } }; -const float d65_white[3] = { 0.950456, 1, 1.088754 }; -int histogram[4][0x2000]; -void (*write_thumb)(), (*write_fun)(); -void (*load_raw)(), (*thumb_load_raw)(); -jmp_buf failure; +static const float d65_white[3] = { 0.950456, 1, 1.088754 }; +THREAD_LOCAL int histogram[4][0x2000]; +THREAD_LOCAL void (*write_thumb)(), (*write_fun)(); +THREAD_LOCAL void (*load_raw)(), (*thumb_load_raw)(); +THREAD_LOCAL jmp_buf failure; -struct decode { +THREAD_LOCAL struct decode { struct decode *branch[2]; int leaf; } first_decode[2048], *second_decode, *free_decode; -struct tiff_ifd { +THREAD_LOCAL struct tiff_ifd { int width, height, bps, comp, phint, offset, flip, samples, bytes; } tiff_ifd[10]; -struct ph1 { +THREAD_LOCAL struct ph1 { int format, key_off, black, black_off, split_col, tag_21a; float tag_210; } ph1; @@ -555,8 +564,8 @@ int CLASS canon_s2is() */ unsigned CLASS getbithuff (int nbits, ushort *huff) { - static unsigned bitbuf=0; - static int vbits=0, reset=0; + THREAD_LOCAL unsigned bitbuf=0; + THREAD_LOCAL int vbits=0, reset=0; unsigned c; if (nbits == -1) @@ -1577,8 +1586,8 @@ void CLASS phase_one_load_raw() unsigned CLASS ph1_bithuff (int nbits, ushort *huff) { - static UINT64 bitbuf=0; - static int vbits=0; + THREAD_LOCAL UINT64 bitbuf=0; + THREAD_LOCAL int vbits=0; unsigned c; if (nbits == -1) @@ -1840,8 +1849,8 @@ void CLASS nokia_load_raw() unsigned CLASS pana_bits (int nbits) { - static uchar buf[0x4000]; - static int vbits; + THREAD_LOCAL uchar buf[0x4000]; + THREAD_LOCAL int vbits; int byte; if (!nbits) return vbits=0; @@ -2130,7 +2139,7 @@ void CLASS kodak_jpeg_load_raw() {} METHODDEF(boolean) fill_input_buffer (j_decompress_ptr cinfo) { - static uchar jpeg_buffer[4096]; + THREAD_LOCAL uchar jpeg_buffer[4096]; size_t nbytes; nbytes = fread (jpeg_buffer, 1, 4096, ifp); @@ -2408,7 +2417,7 @@ void CLASS kodak_thumb_load_raw() void CLASS sony_decrypt (unsigned *data, int len, int start, int key) { - static unsigned pad[128], p; + THREAD_LOCAL unsigned pad[128], p; if (start) { for (p=0; p < 4; p++) @@ -2655,7 +2664,7 @@ void CLASS smal_v9_load_raw() void CLASS foveon_decoder (unsigned size, unsigned code) { - static unsigned huff[1024]; + THREAD_LOCAL unsigned huff[1024]; struct decode *cur; int i, len; @@ -8937,7 +8946,7 @@ int loadRaw (const char* fname, struct RawImage *ri) { { 0.222507, 0.716888, 0.060608 }, { 0.013930, 0.097097, 0.714022 } }; -dcrMutex->lock (); + THREAD_LOCK ifname = fname;//strdup (fname); image = NULL; @@ -8952,7 +8961,6 @@ dcrMutex->lock (); ri->profile_data = NULL; ifp = gfopen (fname); if (!ifp) { - dcrMutex->unlock (); return 3; } @@ -8964,7 +8972,6 @@ dcrMutex->lock (); use_camera_wb = 1; if (!is_raw) { fclose(ifp); - dcrMutex->unlock (); return 2; } @@ -8983,7 +8990,6 @@ dcrMutex->lock (); if (ri->data) free(ri->data); fclose (ifp); - dcrMutex->unlock (); return 100; } @@ -9070,15 +9076,14 @@ dcrMutex->lock (); ri->coeff[a][b] = rgb_cam[a][b]; free (image); -dcrMutex->unlock (); return 0; } int getRawFileBasicInfo (const Glib::ustring& fname, rtengine::RawMetaDataLocation& rml, int& rotation, int& thumbWidth, int& thumbHeight, int& thumbOffset, int& thumbType) { - int status=0; + THREAD_LOCK -dcrMutex->lock (); + int status=0; exif_base = -1; ciff_base = -1; @@ -9097,14 +9102,12 @@ dcrMutex->lock (); ifname = fname.c_str(); if (!(ifp = gfopen (ifname))) { status = 2; - dcrMutex->unlock (); return status; } identify (); if (!is_raw || colors>3) { status = 3; fclose (ifp); - dcrMutex->unlock (); return status; } @@ -9136,7 +9139,6 @@ dcrMutex->lock (); rml.ciffLength = ciff_len; fclose (ifp); -dcrMutex->unlock (); return !is_raw; } @@ -9144,7 +9146,8 @@ dcrMutex->unlock (); rtengine::Thumbnail* rtengine::Thumbnail::loadFromRaw (const Glib::ustring& fname, rtengine::RawMetaDataLocation& rml, int &w, int &h, int fixwh) { -dcrMutex->lock (); + THREAD_LOCK + MyTime t0, t1, t2, t3, t4, t5, t6; t0.set (); @@ -9157,7 +9160,6 @@ t0.set (); oprof = NULL; ifp = gfopen (fname.c_str()); if (!ifp) { - dcrMutex->unlock (); return NULL; } @@ -9167,7 +9169,6 @@ t1.set (); if (image) free (image); fclose (ifp); - dcrMutex->unlock (); return NULL; } @@ -9179,7 +9180,6 @@ t1.set (); use_camera_wb = 1; if (!is_raw || colors>3) { fclose(ifp); - dcrMutex->unlock (); return NULL; } @@ -9441,8 +9441,6 @@ if (settings->verbose) printf ("0: %d, 1: %d, 2: %d, 3: %d, 4: %d, 5: %d All: %d free (image); -dcrMutex->unlock (); - return tpp; } diff --git a/rtengine/dcraw.patch b/rtengine/dcraw.patch index 826580dff..fec902bbc 100644 --- a/rtengine/dcraw.patch +++ b/rtengine/dcraw.patch @@ -1,9 +1,8 @@ ---- dcraw.c 2010-06-30 10:40:16.000000000 -0600 -+++ dcraw.cc 2010-06-30 10:36:00.000000000 -0600 -@@ -1,3 +1,16 @@ +--- dcraw.c 2010-10-25 09:45:14.000000000 -0400 ++++ dcraw.cc 2010-10-27 11:30:33.000000000 -0400 +@@ -1,3 +1,15 @@ +/*RT*/#include +/*RT*/#include -+/*RT*/int ciff_base, ciff_len, exif_base, pre_filters; +/*RT*/#undef MAX +/*RT*/#undef MIN +/*RT*/#define NO_LCMS @@ -17,7 +16,7 @@ /* dcraw.c -- Dave Coffin's raw photo decoder Copyright 1997-2010 by Dave Coffin, dcoffin a cybercom o net -@@ -46,7 +59,9 @@ +@@ -46,7 +58,9 @@ NO_LCMS disables the "-p" option. */ #ifndef NO_JPEG @@ -28,17 +27,115 @@ #endif #ifndef NO_LCMS #include -@@ -101,7 +116,8 @@ +@@ -96,59 +110,70 @@ + typedef unsigned char uchar; + typedef unsigned short ushort; + ++// RT specify thread local storage ++#ifdef __GNUC__ ++#define THREAD_LOCAL static __thread ++#define THREAD_LOCK ++#else ++#define THREAD_LOCAL ++#define THREAD_LOCK Glib::Mutex::Lock locker(*dcrMutex); ++#endif ++ + /* + All global variables are defined here, and all functions that access them are prefixed with "CLASS". Note that a thread-safe C++ class cannot have non-const static local variables. */ -FILE *ifp, *ofp; -+/*RT*/IMFILE *ifp; -+FILE * ofp; - short order; - const char *ifname; - char *meta_data; -@@ -271,6 +287,7 @@ +-short order; +-const char *ifname; +-char *meta_data; +-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; +-unsigned shot_order, kodak_cbpp, filters, exif_cfa, unique_id; +-off_t strip_offset, data_offset; +-off_t thumb_offset, meta_offset, profile_offset; +-unsigned thumb_length, meta_length, profile_length; +-unsigned thumb_misc, *oprof, fuji_layout, shot_select=0, multi_out=0; +-unsigned tiff_nifds, tiff_samples, tiff_bps, tiff_compress; +-unsigned black, cblack[8], 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; +-ushort raw_height, raw_width, height, width, top_margin, left_margin; +-ushort shrink, iheight, iwidth, fuji_width, thumb_width, thumb_height; +-int flip, tiff_flip, colors; +-double pixel_aspect, aber[4]={1,1,1,1}, gamm[6]={ 0.45,4.5,0,0,0,0 }; +-ushort (*image)[4], white[8][8], curve[0x10000], cr2_slice[3], sraw_mul[4]; +-float bright=1, user_mul[4]={0,0,0,0}, threshold=0; +-int half_size=0, four_color_rgb=0, document_mode=0, highlight=0; +-int verbose=0, use_auto_wb=0, use_camera_wb=0, use_camera_matrix=-1; +-int output_color=1, output_bps=8, output_tiff=0, med_passes=0; +-int no_auto_bright=0; +-unsigned greybox[4] = { 0, 0, UINT_MAX, UINT_MAX }; +-float cam_mul[4], pre_mul[4], cmatrix[3][4], rgb_cam[3][4]; +-const double xyz_rgb[3][3] = { /* XYZ from RGB */ ++/*RT*/THREAD_LOCAL int ciff_base, ciff_len, exif_base, pre_filters; ++/*RT*/THREAD_LOCAL IMFILE *ifp; ++THREAD_LOCAL FILE * ofp; ++THREAD_LOCAL short order; ++THREAD_LOCAL const char *ifname; ++THREAD_LOCAL char *meta_data; ++THREAD_LOCAL char cdesc[5], desc[512], make[64], model[64], model2[64], artist[64]; ++THREAD_LOCAL float flash_used, canon_ev, iso_speed, shutter, aperture, focal_len; ++THREAD_LOCAL time_t timestamp; ++THREAD_LOCAL unsigned shot_order, kodak_cbpp, filters, exif_cfa, unique_id; ++THREAD_LOCAL off_t strip_offset, data_offset; ++THREAD_LOCAL off_t thumb_offset, meta_offset, profile_offset; ++THREAD_LOCAL unsigned thumb_length, meta_length, profile_length; ++THREAD_LOCAL unsigned thumb_misc, *oprof, fuji_layout, shot_select=0, multi_out=0; ++THREAD_LOCAL unsigned tiff_nifds, tiff_samples, tiff_bps, tiff_compress; ++THREAD_LOCAL unsigned black, cblack[8], maximum, mix_green, raw_color, zero_is_bad; ++THREAD_LOCAL unsigned zero_after_ff, is_raw, dng_version, is_foveon, data_error; ++THREAD_LOCAL unsigned tile_width, tile_length, gpsdata[32], load_flags; ++THREAD_LOCAL ushort raw_height, raw_width, height, width, top_margin, left_margin; ++THREAD_LOCAL ushort shrink, iheight, iwidth, fuji_width, thumb_width, thumb_height; ++THREAD_LOCAL int flip, tiff_flip, colors; ++THREAD_LOCAL double pixel_aspect, aber[4]={1,1,1,1}, gamm[6]={ 0.45,4.5,0,0,0,0 }; ++THREAD_LOCAL ushort (*image)[4], white[8][8], curve[0x10000], cr2_slice[3], sraw_mul[4]; ++THREAD_LOCAL float bright=1, user_mul[4]={0,0,0,0}, threshold=0; ++THREAD_LOCAL int half_size=0, four_color_rgb=0, document_mode=0, highlight=0; ++THREAD_LOCAL int verbose=0, use_auto_wb=0, use_camera_wb=0, use_camera_matrix=-1; ++THREAD_LOCAL int output_color=1, output_bps=8, output_tiff=0, med_passes=0; ++THREAD_LOCAL int no_auto_bright=0; ++THREAD_LOCAL unsigned greybox[4] = { 0, 0, UINT_MAX, UINT_MAX }; ++THREAD_LOCAL 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 } }; +-const float d65_white[3] = { 0.950456, 1, 1.088754 }; +-int histogram[4][0x2000]; +-void (*write_thumb)(), (*write_fun)(); +-void (*load_raw)(), (*thumb_load_raw)(); +-jmp_buf failure; ++static const float d65_white[3] = { 0.950456, 1, 1.088754 }; ++THREAD_LOCAL int histogram[4][0x2000]; ++THREAD_LOCAL void (*write_thumb)(), (*write_fun)(); ++THREAD_LOCAL void (*load_raw)(), (*thumb_load_raw)(); ++THREAD_LOCAL jmp_buf failure; + +-struct decode { ++THREAD_LOCAL struct decode { + struct decode *branch[2]; + int leaf; + } first_decode[2048], *second_decode, *free_decode; + +-struct tiff_ifd { ++THREAD_LOCAL struct tiff_ifd { + int width, height, bps, comp, phint, offset, flip, samples, bytes; + } tiff_ifd[10]; + +-struct ph1 { ++THREAD_LOCAL struct ph1 { + int format, key_off, black, black_off, split_col, tag_21a; + float tag_210; + } ph1; +@@ -271,6 +296,7 @@ fprintf (stderr,_("Corrupt data near 0x%llx\n"), (INT64) ftello(ifp)); } data_error++; @@ -46,7 +143,7 @@ } ushort CLASS sget2 (uchar *s) -@@ -344,7 +361,7 @@ +@@ -344,7 +370,7 @@ { if (fread (pixel, 2, count, ifp) < count) derror(); if ((order == 0x4949) == (ntohs(0x1234) == 0x1234)) @@ -55,7 +152,45 @@ } void CLASS canon_600_fixed_wb (int temp) -@@ -2117,7 +2134,7 @@ +@@ -538,8 +564,8 @@ + */ + unsigned CLASS getbithuff (int nbits, ushort *huff) + { +- static unsigned bitbuf=0; +- static int vbits=0, reset=0; ++ THREAD_LOCAL unsigned bitbuf=0; ++ THREAD_LOCAL int vbits=0, reset=0; + unsigned c; + + if (nbits == -1) +@@ -1560,8 +1586,8 @@ + + unsigned CLASS ph1_bithuff (int nbits, ushort *huff) + { +- static UINT64 bitbuf=0; +- static int vbits=0; ++ THREAD_LOCAL UINT64 bitbuf=0; ++ THREAD_LOCAL int vbits=0; + unsigned c; + + if (nbits == -1) +@@ -1823,8 +1849,8 @@ + + unsigned CLASS pana_bits (int nbits) + { +- static uchar buf[0x4000]; +- static int vbits; ++ THREAD_LOCAL uchar buf[0x4000]; ++ THREAD_LOCAL int vbits; + int byte; + + if (!nbits) return vbits=0; +@@ -2113,11 +2139,11 @@ + METHODDEF(boolean) + fill_input_buffer (j_decompress_ptr cinfo) + { +- static uchar jpeg_buffer[4096]; ++ THREAD_LOCAL uchar jpeg_buffer[4096]; size_t nbytes; nbytes = fread (jpeg_buffer, 1, 4096, ifp); @@ -64,7 +199,25 @@ cinfo->src->next_input_byte = jpeg_buffer; cinfo->src->bytes_in_buffer = nbytes; return TRUE; -@@ -3765,6 +3782,7 @@ +@@ -2391,7 +2417,7 @@ + + void CLASS sony_decrypt (unsigned *data, int len, int start, int key) + { +- static unsigned pad[128], p; ++ THREAD_LOCAL unsigned pad[128], p; + + if (start) { + for (p=0; p < 4; p++) +@@ -2638,7 +2664,7 @@ + + void CLASS foveon_decoder (unsigned size, unsigned code) + { +- static unsigned huff[1024]; ++ THREAD_LOCAL unsigned huff[1024]; + struct decode *cur; + int i, len; + +@@ -3765,6 +3791,7 @@ for (row = FC(1,0) >> 1; row < height; row+=2) for (col = FC(row,1) & 1; col < width; col+=2) image[row*width+col][1] = image[row*width+col][3]; @@ -72,7 +225,7 @@ filters &= ~((filters & 0x55555555) << 1); } } -@@ -4817,7 +4835,7 @@ +@@ -4817,7 +4844,7 @@ unsigned sony_curve[] = { 0,0,0,0,0,4095 }; unsigned *buf, sony_offset=0, sony_length=0, sony_key=0; struct jhead jh; @@ -81,7 +234,7 @@ if (tiff_nifds >= sizeof tiff_ifd / sizeof tiff_ifd[0]) return 1; -@@ -5225,12 +5243,13 @@ +@@ -5225,12 +5252,13 @@ fread (buf, sony_length, 1, ifp); sony_decrypt (buf, sony_length/4, 1, sony_key); sfp = ifp; @@ -100,7 +253,7 @@ ifp = sfp; free (buf); } -@@ -5256,6 +5275,8 @@ +@@ -5256,6 +5284,8 @@ int doff, max_samp=0, raw=-1, thm=-1, i; struct jhead jh; @@ -109,7 +262,7 @@ fseek (ifp, base, SEEK_SET); order = get2(); if (order != 0x4949 && order != 0x4d4d) return; -@@ -5424,7 +5445,7 @@ +@@ -5424,7 +5454,7 @@ { const char *file, *ext; char *jname, *jfile, *jext; @@ -118,7 +271,7 @@ ext = strrchr (ifname, '.'); file = strrchr (ifname, '/'); -@@ -5452,7 +5473,8 @@ +@@ -5452,7 +5482,8 @@ *jext = '0'; } if (strcmp (jname, ifname)) { @@ -128,7 +281,7 @@ if (verbose) fprintf (stderr,_("Reading metadata from %s ...\n"), jname); parse_tiff (12); -@@ -5790,7 +5812,11 @@ +@@ -5790,7 +5821,11 @@ order = get2(); hlen = get4(); if (get4() == 0x48454150) /* "HEAP" */ @@ -140,7 +293,7 @@ parse_tiff (save+6); fseek (ifp, save+len, SEEK_SET); } -@@ -6738,6 +6764,12 @@ +@@ -6738,6 +6773,12 @@ fread (head, 1, 32, ifp); fseek (ifp, 0, SEEK_END); flen = fsize = ftell(ifp); @@ -153,7 +306,7 @@ if ((cp = (char *) memmem (head, 32, "MMMM", 4)) || (cp = (char *) memmem (head, 32, "IIII", 4))) { parse_phase_one (cp-head); -@@ -6745,6 +6777,8 @@ +@@ -6745,6 +6786,8 @@ } else if (order == 0x4949 || order == 0x4d4d) { if (!memcmp (head+6,"HEAPCCDR",8)) { data_offset = hlen; @@ -162,7 +315,25 @@ parse_ciff (hlen, flen - hlen); } else { parse_tiff(0); -@@ -8494,13 +8528,13 @@ +@@ -6858,6 +6901,8 @@ + if (height == 3136 && width == 4736) /* Pentax K-7 */ + { height = 3122; width = 4684; + top_margin = 2; filters = 0x16161616; } ++ if (height == 2868 && width == 4352) /* Pentax K-x */ ++ width = 4308; + if (height == 3014 && width == 4096) /* Ricoh GX200 */ + width = 4014; + if (dng_version) { +@@ -7405,7 +7450,7 @@ + } else if (!strcmp(model,"K20D")) { + filters = 0x16161616; + } else if (!strcmp(model,"K-x")) { +- width = 4309; ++ width = 4308; + filters = 0x16161616; + } else if (!strcmp(model,"Optio S")) { + if (fsize == 3178560) { +@@ -8494,13 +8539,13 @@ FORCC ppm [col*colors+c] = curve[image[soff][c]] >> 8; else FORCC ppm2[col*colors+c] = curve[image[soff][c]]; if (output_bps == 16 && !output_tiff && htons(0x55aa) != 0x55aa) @@ -178,7 +349,7 @@ { int arg, status=0; int timestamp_only=0, thumbnail_only=0, identify_only=0; -@@ -8613,7 +8647,7 @@ +@@ -8613,7 +8658,7 @@ case 'i': identify_only = 1; break; case 'c': write_to_stdout = 1; break; case 'v': verbose = 1; break; @@ -187,7 +358,7 @@ case 'f': four_color_rgb = 1; break; case 'A': FORC4 greybox[c] = atoi(argv[arg++]); case 'a': use_auto_wb = 1; break; -@@ -8877,3 +8911,537 @@ +@@ -8877,3 +8922,526 @@ } return status; } @@ -213,7 +384,7 @@ + { 0.222507, 0.716888, 0.060608 }, + { 0.013930, 0.097097, 0.714022 } }; + -+dcrMutex->lock (); ++ THREAD_LOCK + + ifname = fname;//strdup (fname); + image = NULL; @@ -228,7 +399,6 @@ + ri->profile_data = NULL; + ifp = gfopen (fname); + if (!ifp) { -+ dcrMutex->unlock (); + return 3; + } + @@ -240,7 +410,6 @@ + use_camera_wb = 1; + if (!is_raw) { + fclose(ifp); -+ dcrMutex->unlock (); + return 2; + } + @@ -259,7 +428,6 @@ + if (ri->data) + free(ri->data); + fclose (ifp); -+ dcrMutex->unlock (); + return 100; + } + @@ -346,15 +514,14 @@ + ri->coeff[a][b] = rgb_cam[a][b]; + + free (image); -+dcrMutex->unlock (); + return 0; +} + +int getRawFileBasicInfo (const Glib::ustring& fname, rtengine::RawMetaDataLocation& rml, int& rotation, int& thumbWidth, int& thumbHeight, int& thumbOffset, int& thumbType) { + -+ int status=0; ++ THREAD_LOCK + -+dcrMutex->lock (); ++ int status=0; + + exif_base = -1; + ciff_base = -1; @@ -373,14 +540,12 @@ + ifname = fname.c_str(); + if (!(ifp = gfopen (ifname))) { + status = 2; -+ dcrMutex->unlock (); + return status; + } + identify (); + if (!is_raw || colors>3) { + status = 3; + fclose (ifp); -+ dcrMutex->unlock (); + return status; + } + @@ -412,7 +577,6 @@ + rml.ciffLength = ciff_len; + + fclose (ifp); -+dcrMutex->unlock (); + return !is_raw; +} + @@ -420,7 +584,8 @@ + +rtengine::Thumbnail* rtengine::Thumbnail::loadFromRaw (const Glib::ustring& fname, rtengine::RawMetaDataLocation& rml, int &w, int &h, int fixwh) { + -+dcrMutex->lock (); ++ THREAD_LOCK ++ +MyTime t0, t1, t2, t3, t4, t5, t6; +t0.set (); + @@ -433,7 +598,6 @@ + oprof = NULL; + ifp = gfopen (fname.c_str()); + if (!ifp) { -+ dcrMutex->unlock (); + return NULL; + } + @@ -443,7 +607,6 @@ + if (image) + free (image); + fclose (ifp); -+ dcrMutex->unlock (); + return NULL; + } + @@ -455,7 +618,6 @@ + use_camera_wb = 1; + if (!is_raw || colors>3) { + fclose(ifp); -+ dcrMutex->unlock (); + return NULL; + } + @@ -610,7 +772,7 @@ + + // generate histogram for auto exposure + tpp->aeHistCompression = 3; -+ tpp->aeHistogram = new int[65536>>tpp->aeHistCompression]; ++ tpp->aeHistogram = new unsigned int[65536>>tpp->aeHistCompression]; + memset (tpp->aeHistogram, 0, (65536>>tpp->aeHistCompression)*sizeof(int)); + int radd = 4; + int gadd = 2; @@ -717,8 +879,6 @@ + + free (image); + -+dcrMutex->unlock (); -+ + return tpp; +} +