1 /*******************************************************************************
2 **
3 ** Photivo
4 **
5 ** Copyright (C) 2008,2009 Jos De Laender <jos.de_laender@telenet.be>
6 ** Copyright (C) 2009,2010 Michael Munzert <mail@mm-log.com>
7 ** Copyright (C) 2011 Bernd Schoeler <brjohn@brother-john.net>
8 **
9 ** This file is part of Photivo.
10 **
11 ** Photivo is free software: you can redistribute it and/or modify
12 ** it under the terms of the GNU General Public License version 3
13 ** as published by the Free Software Foundation.
14 **
15 ** Photivo is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ** GNU General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with Photivo.  If not, see <http://www.gnu.org/licenses/>.
22 **
23 *******************************************************************************/
24 /*
25 ** This is the adaptation of dcraw.c into something that is more or less
26 ** a C++ object.
27 ** It is not implied that this now works correctly with different compilers,
28 ** environments and settings. Lots of testing still needed.
29 **
30 *******************************************************************************/
31 
32 #ifndef DLDCDRAW_H
33 #define DLDCDRAW_H
34 
35 // Adaptation of dcraw.c stuff.
36 #define DCRAW_VERSION "dcraw v9.17"    // Update along with dcraw syncing ...
37 // $Revision: 1.454 $
38 // $Date: 2012/12/23 19:25:36 $
39 #ifndef _GNU_SOURCE
40 #define _GNU_SOURCE
41 #endif
42 
43 #include "ptDefines.h"
44 
45 #include <QString>
46 
47 #define _USE_MATH_DEFINES
48 #include <vector>
49 #include <cctype>
50 #include <cerrno>
51 #include <cfloat>
52 #include <climits>
53 #include <cmath>
54 #include <cassert>
55 #include <csetjmp>
56 #include <cstdio>
57 #include <cstdlib>
58 #include <cstring>
59 #include <ctime>
60 #include <fcntl.h>
61 #include <sys/types.h>
62 
63 #ifdef WIN32
64 #define NO_JPEG
65 #endif
66 
67 #ifndef NO_JPEG
68 #ifdef __cplusplus
69   // This hack copes with jpeglib.h that does or doesnt provide the
70   // extern internally.
71   #pragma push_macro("__cplusplus")
72   #undef __cplusplus
73   extern "C" {
74   #include <jpeglib.h>
75   }
76   #pragma pop_macro("__cplusplus")
77 #else
78   #include <jpeglib.h>
79 #endif
80 #endif
81 
82 #ifdef LOCALEDIR
83 #include <libintl.h>
84 #define _(String) gettext(String)
85 #else
86 #define _(String) (String)
87 #endif
88 /* jpta away  ?
89 #ifdef DJGPP
90 #define fseeko fseek
91 #define ftello ftell
92 #else
93 #define fgetc getc_unlocked
94 #endif
95 */
96 #ifdef __CYGWIN__
97 #include <io.h>
98 #endif
99 #ifdef WIN32
100 #include <sys/utime.h>
101 #include <winsock2.h>
102 /* jpta : away ?
103 comment(lib, "ws2_32.lib")
104 */
105 #define snprintf _snprintf
106 #define strcasecmp stricmp
107 #define strncasecmp strnicmp
108 typedef __int64 INT64;
109 typedef unsigned __int64 UINT64;
110 #else
111 #include <unistd.h>
112 #include <utime.h>
113 #include <netinet/in.h>
114 typedef long long INT64;
115 typedef unsigned long long UINT64;
116 #endif
117 
118 #ifdef LJPEG_DECODE
119 #error Please compile dcraw.c by itself.
120 #error Do not link it with ljpeg_decode.
121 #endif
122 
123 #ifndef LONG_BIT
124 #define LONG_BIT (8 * sizeof (long))
125 #endif
126 
127 
128 ////////////////////////////////////////////////////////////////////////////////
129 //
130 // TRACE_ORIGIN
131 //
132 // Macro to try and analyze some of the origins of variables in the
133 // dcraw jungle
134 //
135 ////////////////////////////////////////////////////////////////////////////////
136 
137 // #define TRACE_ORIGIN
138 
139 #ifdef TRACE_ORIGIN
140 #define ASSIGN(x,y) {x.Value=y;strncpy(x.File, __FILE__,1023);x.Line=__LINE__;}
141 #define VALUE(x) x.Value
142 #else
143 #define ASSIGN(x,y) x=y
144 #define VALUE(x)    x
145 #endif
146 
147 
148 class ptDcRaw {
149 ////////////////////////////////////////////////////////////////////////////////
150 //
151 // PUBLIC members
152 //
153 ////////////////////////////////////////////////////////////////////////////////
154 public:
155   /*************************************************************************
156   m_UserSetting_* :
157 
158   Members to be set (or changed from their default) by the user
159   in order to define what dcraw will do.
160 
161   User settings corresponding to command line optins.
162   Those are going to be set when used as embedded in an app.
163   Each of them corresponds roughly to a command line parameter of dcraw.
164   *************************************************************************/
165 
166   // Quality.
167   // Please remark that most probably dcraw implementation and
168   // manual/documentation differ here.
169   //   According to manual :
170   //     0 : Use high-speed, low-quality bilinear interpolation.
171   //     2 : Use Variable Number of Gradients (VNG) interpolation.
172   //     3 : Use Adaptive Homogeneity-Directed (AHD) interpolation.
173   //   According to my reading of the code :
174   //     0 : Use high-speed, low-quality bilinear interpolation.
175   //     1 : Use Variable Number of Gradients (VNG) interpolation.
176   //     2 : Use Patterned Pixel Grouping (PPG) interpolation.
177   //     3 : Use Adaptive Homogeneity-Directed (AHD) interpolation.
178   short       m_UserSetting_Quality;
179 
180   // Output half-size color image. Doubles speed (no interpolation needed)
181   // 1 : Just half size as in original dcraw.
182   // 2 : An additional halving of the image will be done.
183   //     (4 pixels to 1 by averaging = bilinear)
184   short       m_UserSetting_HalfSize;
185 
186   // Automatic hotpixel reduction
187   double      m_UserSetting_HotpixelReduction;
188 
189   // Bayer denoise
190   short       m_UserSetting_BayerDenoise;
191 
192   // Green equilibration
193   int         m_UserSetting_GreenEquil;
194 
195   // CA auto correction
196   int         m_UserSetting_CaCorrect;
197   float       m_UserSetting_CaRed;
198   float       m_UserSetting_CaBlue;
199 
200   // CFA line denoise
201   int         m_UserSetting_CfaLineDn;
202 
203   // Automatic white balance.  The default is to use  a  fixed  color
204   // balance based on a white card photographed in sunlight
205   short       m_UserSetting_AutoWb;
206 
207   // Blackpoint setting.
208   // -1 is the default depending on the camera.
209   int         m_UserSetting_BlackPoint;
210 
211   // Whitepoint setting.
212   // -1 is the default depending on the camera.
213   int         m_UserSetting_Saturation;
214 
215   // Use the white balance specified by the camera.  If this can’t be
216   // found, print a warning and revert to the default.
217   short       m_UserSetting_CameraWb;
218 
219   // <x y width height> Average a grey box for white balance
220   // This defines the area that will be used for the white balance.
221   uint16_t    m_UserSetting_GreyBox[4];
222 
223   // Normalize multiplier to the lowest 1.0
224   short       m_UserSetting_MaxMultiplier;
225 
226   // Specify your own raw white balance.  These  multipliers  can  be
227   // cut and pasted from the output of dcraw -v.
228   float       m_UserSetting_Multiplier[4];
229 
230   // Use or not the embedded color matrix of the camera.
231   short       m_UserSetting_CameraMatrix;
232 
233   // Filename to process.
234   char*       m_UserSetting_InputFileName;
235 
236   // Detail view
237   short       m_UserSetting_DetailView;
238   uint16_t    m_UserSetting_DetailViewCropX;
239   uint16_t    m_UserSetting_DetailViewCropY;
240   uint16_t    m_UserSetting_DetailViewCropW;
241   uint16_t    m_UserSetting_DetailViewCropH;
242 
243   // Adjust maximum threshold (between 0 and 0.25)
244   double      m_UserSetting_AdjustMaximum;
245 
246   // Wavelet denoising before color balancing and demosaicing.
247   int         m_UserSetting_DenoiseThreshold;
248 
249   // Interpolation passes for demosaicing.
250   int         m_UserSetting_InterpolationPasses;
251 
252   // Median passes after demosaicing.
253   int         m_UserSetting_MedianPasses;
254   int         m_UserSetting_ESMedianPasses;
255   int         m_UserSetting_EeciRefine;
256 
257   // photivo in the name is a photivo specific adapation/extension.
258 
259   // Clip/Highlight related parameters
260   short       m_UserSetting_photivo_ClipMode;
261   short       m_UserSetting_photivo_ClipParameter;
262 
263   // [0..N-1] Select one raw image or "all" from each file
264   unsigned  m_UserSetting_ShotSelect;
265 
266   // Bad pixel filename.
267   // Default on NULL and not used.
268   char*     m_UserSetting_BadPixelsFileName;
269 
270   // Dark frame filename.
271   // Default on NULL and not used.
272   char*     m_UserSetting_DarkFrameFileName;
273 
274 
275   /**************************************************************************
276     Methods that the user can apply.
277   **************************************************************************/
278 
279   // Constructor.
280   ptDcRaw();
281 
282   // Destructor.
283   ~ptDcRaw();
284 
285   // ResetNonUserSettings. (For second entry from Identify on).
286   void ResetNonUserSettings();
287 
288   // Identify the input file, the camera parameters etc.
289   // See further for stuff that can be read afterwards.
290   short  Identify(const QString NewInputFile = "");
291 
292   // Do the raw processing up to the image available.
293   short  RunDcRaw_Phase1(); //Load,bad pxs,darkframe.
294   short  RunDcRaw_Phase2(const short NoCache=0); // WB,Interpolation
295   short  RunDcRaw_Phase3(const short NoCache=0); // Highlights
296 
297   // Member functions specifically for photivo or photivo adapted.
298 
299   void  ptWaveletDenoise();
300   void  ptScaleColors();
301   void  ptMedianFilter();
302   void  ptHotpixelReduction();
303   void  ptHotpixelReductionBayer();
304   void  ptHighlight(const short  ClipMode,
305                     const short  ClipParameter);
306   void  ptAdjustMaximum(double Threshold);
307 
308   void  LabToCam(double Lab[3],uint16_t Cam[4]);
309   void  CamToLab(uint16_t Cam[4], double Lab[3]);
310 
311   void  ptRebuildHighlights(const short Effort);
312   void  ptBlendHighlights();
313   void  ptCrop();
314   TImage8RawData thumbnail();
315 
316 
317   /*************************************************************************
318   m_*
319 
320   Members that are set during the program logic and not by the user.
321   Most of them are useful to be *read* by the user. Don't change them.
322   The lower ones are questionable if they should be of interest to the user.
323   *************************************************************************/
324 
325   TImage8RawData m_Thumb;
326 
327   // The image !
328   uint16_t    (*m_Image)[4];
329   uint16_t    (*m_Image_AfterPhase1)[4];  // Cached one.
330   uint16_t    (*m_Image_AfterPhase2)[4];  // Cached one.
331   uint16_t    (*m_Image_AfterPhase3)[4];  // Cached one.
332   uint16_t    (*m_Image_AfterPhase4)[4];  // Cached one.
333 
334   // Height and width of output.
335   uint16_t    m_Width;
336   uint16_t    m_Width_AfterPhase1; // Cached one.
337   uint16_t    m_Height;
338   uint16_t    m_Height_AfterPhase1; // Cached one.
339   uint16_t    m_ReportedWidth; // Take into account already fuji rotate/stretch
340   uint16_t    m_ReportedHeight;
341 
342   // Camera and photo identifications. Typically available after Identify().
343   char      m_CameraMake[64];
344   char      m_CameraModel[64];
345   char      m_CameraModelBis[64];
346   char      m_CameraAdobeIdentification[128]; // Name as in the adobe table.
347   char      m_Artist[64];
348   float     m_IsoSpeed;
349   float     m_Shutter;
350   float     m_Aperture;
351   float     m_FocalLength;
352   time_t    m_TimeStamp;
353 
354   // Nr of raw images found in the file.
355   unsigned  m_IsRaw;
356 
357   // Not 0 if an embedded ICC profile was found.
358   unsigned  m_ProfileLength;
359 
360   // Pixel aspect ratio. Whatever this may be.
361   float    m_PixelAspect;
362 
363   // Dimensions of thumb.
364   uint16_t  m_ThumbWidth;
365   uint16_t  m_ThumbHeight;
366 
367   // Dimensions of the full size image.
368   uint16_t  m_RawHeight;
369   uint16_t  m_RawWidth;
370 
371   // Raw colors.
372   short     m_Colors;
373 
374   // Daylight multipliers.
375 
376   #ifdef TRACE_ORIGIN
377   struct {
378     float Value;
379     char  File[1024];
380     int   Line;
381   } m_PreMultipliers[4];
382   #else
383   float     m_PreMultipliers[4];
384   #endif
385 
386   float     m_MinPreMulti; // Max per construction 1.0 after ptScaleColors.
387   //TODO Mike: Max is no longer 1.0, something todo here?
388 
389   // Camera multipliers.
390 
391   #ifdef TRACE_ORIGIN
392   struct {
393     float Value;
394     char  File[1024];
395     int   Line;
396   } m_CameraMultipliers[4];
397   #else
398   float     m_CameraMultipliers[4];
399   #endif
400 
401   // Multipliers as obtained at the end of 'phase1'. Should be D65 ones (jpta ?)
402 
403   #ifdef TRACE_ORIGIN
404   struct {
405     float Value;
406     char  File[1024];
407     int   Line;
408   } m_D65Multipliers[4];
409   #else
410   float m_D65Multipliers[4];
411   #endif
412 
413   // Final multipliers based on pre, white, black
414 
415   #ifdef TRACE_ORIGIN
416   struct {
417     float Value;
418     char  File[1024];
419     int   Line;
420   } m_Multipliers[4];
421   #else
422   float     m_Multipliers[4];
423   #endif
424 
425 
426   /*************************************************************************
427   From here on it becomes more and more uninteresting
428   internal data. If someone can describe it in a useful way, feel free.
429   *************************************************************************/
430   char      m_ColorDescriptor[5];
431   short     m_ByteOrder;  // 0x4949 ("II") means little-endian.
432   FILE*     m_InputFile;
433   FILE*     m_OutputFile;
434   char*     m_MetaData;
435   unsigned  m_ThumbMisc;
436   char      m_Description[512];
437   unsigned  m_ShotOrder;
438   unsigned  m_Kodak_cbpp;
439   unsigned  m_Filters;
440   unsigned  m_Filters_AfterPhase1;
441   unsigned  m_Filters_AfterPhase2;
442   unsigned  m_Filters_AfterPhase3;
443   off_t     m_Data_Offset;
444   off_t     m_ThumbOffset;
445   off_t     m_ProfileOffset;
446   unsigned  m_ThumbLength;
447   unsigned  m_MetaLength;
448   unsigned  m_Tiff_NrIFDs;
449   unsigned  m_Tiff_Samples;
450   unsigned  m_Tiff_bps;
451   unsigned  m_Tiff_Compress;
452   unsigned  m_BlackLevel;
453   unsigned  m_CBlackLevel[8]; //TODO Mike
454   unsigned  m_BlackLevel_AfterPhase1;
455   unsigned  m_CBlackLevel_AfterPhase1[8]; //TODO Mike
456   unsigned  m_WhiteLevel;
457   unsigned  m_WhiteLevel_AfterPhase1;
458   unsigned  m_MixGreen;
459   unsigned  m_RawColor;
460   unsigned  m_RawColorPhotivo; // mirror for Photivo
461   unsigned  m_ZeroIsBad;
462   unsigned  m_DNG_Version;
463   unsigned  m_IsFoveon;
464   unsigned  m_TileWidth;
465   unsigned  m_TileLength;
466   unsigned  m_Load_Flags;
467   uint16_t  m_TopMargin;
468   short     m_LeftMargin;
469   uint16_t  m_Shrink;
470   uint16_t  m_OutWidth;
471   uint16_t  m_OutWidth_AfterPhase1;
472   uint16_t  m_OutHeight;
473   uint16_t  m_OutHeight_AfterPhase1;
474   uint16_t  m_Fuji_Width;
475   uint16_t  m_IsFuji;
476   int       m_Flip;
477   int       m_Tiff_Flip;
478   int       m_Mask[8][4];
479   uint16_t  m_Curve[0x10000];
480   uint16_t* m_Raw_Image;
481   float     m_cmatrix[3][4];
482   float     m_MatrixCamRGBToSRGB[3][4];
483   double    m_MatrixSRGBToCamRGB[4][3]; // addon photivo
484   void      (ptDcRaw::*m_WriteThumb)();
485   void      (ptDcRaw::*m_WriteFunction)();
486   void      (ptDcRaw::*m_LoadRawFunction)();
487   void      (ptDcRaw::*m_ThumbLoadRawFunction)();
488 
489   jmp_buf   m_Failure;
490 
491   double    m_Gamma[6];
492 
493   // TODO : not yet m_ified.
494 
495   float     flash_used;
496   float     canon_ev;
497   unsigned  fuji_layout;
498   unsigned  exif_cfa;
499   unsigned  unique_id;
500   off_t     strip_offset;
501   off_t     meta_offset;
502   unsigned  zero_after_ff;
503   unsigned  data_error;
504   uint16_t  white[8][8];
505   uint16_t  cr2_slice[3];
506   uint16_t  sraw_mul[4];
507 
508   unsigned    m_getbithuff_bitbuf;
509   int         m_getbithuff_reset;
510   int         m_getbithuff_vbits;
511   uint64_t    m_ph1_bithuffbitbuf;
512   int         m_ph1_bithuffvbits;
513   uint8_t     m_pana_bits_buf[0x4000];
514   int         m_pana_bits_vbits;
515   uint8_t     jpeg_buffer[4096];
516   unsigned    m_sony_decrypt_pad[128];
517   unsigned    m_sony_decrypt_p;
518   unsigned    m_foveon_decoder_huff[1024];
519   double      MatrixXYZToCam[4][3];
520   short       ToCamFunctionInited;
521 
522   // A lookup table used for this purpose.
523   // Initialized at the first call.
524   double      ToLABFunctionTable[0x20000];
525   short       ToLABFunctionInited;
526   double      MatrixCamToXYZ[3][4];
527 
528 
529   struct decode {
530     struct decode *branch[2];
531     int leaf;
532   } first_decode[2048], *second_decode, *free_decode;
533 
534   struct s_Tiff_IFD {
535     int width, height, bps, comp, phint, offset, flip, samples, bytes;
536     int tile_width, tile_length;
537   } m_Tiff_IFD[10];
538 
539   struct s_ph1 {
540     int format, key_off, black, black_off, split_col, tag_21a;
541     float tag_210;
542   } ph1;
543 
544 
545   /*************************************************************************
546   Internally used member functions. Should be completely uninteresting
547   for the user.
548   Pseudo automatically generated.
549   *************************************************************************/
550 
551   void  tiff_head(struct tiff_hdr *th);
552   void  tiff_set(uint16_t *ntag,uint16_t tag,uint16_t type,int count,int val);
553   int   flip_index(int row,int col);
554   void  stretch();
555   void  fuji_rotate();
556   void  identify();
557   short guess_byte_order(int words);
558   float find_green (int bps, int bite, int off0, int off1);
559   void  simple_coeff(int index);
560   void  adobe_coeff(const char *make,const char *model);
561   void  parse_foveon();
562   void  parse_redcine();
563   char *foveon_gets(int offset,char *str,int len);
564   void  parse_cine();
565   void  parse_smal(int offset,int fsize);
566   void  parse_riff();
567   int   parse_jpeg(int offset);
568   void  parse_fuji(int offset);
569   void  parse_phase_one(int base);
570   void  parse_sinar_ia();
571   void  parse_rollei();
572   void  parse_ciff(int offset,int length);
573   void  ciff_block_1030();
574   void  parse_external_jpeg();
575   int   parse_tiff(int base);
576   void  apply_tiff();
577   void  parse_minolta(int base);
578   void  parse_kodak_ifd(int base);
579   void  linear_table(unsigned len);
580   void  parse_mos(int offset);
581   void  romm_coeff(float romm_cam[3][3]);
582   void  parse_exif(int base);
583   void  get_timestamp(int reversed);
584   void  parse_makernote(int base,int uptag);
585   int   parse_tiff_ifd(int base);
586   void  parse_thumb_note(int base,unsigned toff,unsigned tlen);
587   void  tiff_get(unsigned base,unsigned *tag,unsigned *type,unsigned *len,unsigned *save);
588   void  ahd_interpolate();
589   void  ppg_interpolate();
590   void  vng_interpolate();
591   void  lin_interpolate();
592   void  border_interpolate(int border);
593   void  pre_interpolate();
594   void  hat_transform(float *temp,float *base,int st,int size,int sc);
595   void  cam_xyz_coeff(double cam_xyz[4][3]);
596   void  pseudoinverse(double(*in)[3],double(*out)[3],int size);
597   void  gamma_curve (double pwr, double ts, int mode, int imax);
598   void  subtract(const char *fname);
599   void  bad_pixels(const char *fname);
600   void  foveon_interpolate();
601   int   foveon_apply_curve(short *curve,int i);
602   void  foveon_make_curves(short **curvep,float dq[3],float div[3],float filt);
603   short*foveon_make_curve(double max,double mul,double filt);
604   float foveon_avg(short *pix,int range[2],float cfilt);
605   int   foveon_fixed(void *ptr,int size,const char *name);
606   void* foveon_camf_matrix(unsigned dim[3],const char *name);
607   const char * foveon_camf_param(const char *block,const char *param);
608   void  foveon_load_raw();
609   void  foveon_load_camf();
610   void  foveon_thumb();
611   void  foveon_decoder(unsigned size,unsigned code);
612   void  foveon_huff (uint16_t *huff);
613   void  smal_v9_load_raw();
614   void  redcine_load_raw();
615   void  fill_holes(int holes);
616   int   median4(int *p);
617   void  smal_v6_load_raw();
618   void  smal_decode_segment(unsigned seg[2][2],int holes);
619   void  sony_arw2_load_raw();
620   void  sony_arw_load_raw();
621   void  sony_load_raw();
622   void  sony_decrypt(unsigned *data,int len,int start,int key);
623   void  kodak_thumb_load_raw();
624   void  kodak_rgb_load_raw();
625   void  kodak_ycbcr_load_raw();
626   void  kodak_65000_load_raw();
627   int   kodak_65000_decode(short *out,int bsize);
628   void  kodak_262_load_raw();
629   void  kodak_yrgb_load_raw();
630   void  eight_bit_load_raw();
631   void  kodak_dc120_load_raw();
632   void  kodak_jpeg_load_raw();
633   void  kodak_radc_load_raw();
634   int   radc_token(int tree);
635   uint16_t* make_decoder_ref(const uint8_t **source);
636   uint16_t* make_decoder(const uint8_t *source);
637   void  quicktake_100_load_raw();
638   void  casio_qv5700_load_raw();
639   void  minolta_rd175_load_raw();
640   void  olympus_cseries_load_raw();
641   void  olympus_load_raw();
642   void  panasonic_load_raw();
643   void  nokia_load_raw();
644   unsigned  pana_bits(int nbits);
645   void  packed_load_raw();
646   void  imacon_full_load_raw();
647   void  sinar_4shot_load_raw();
648   void  unpacked_load_raw();
649   void  leaf_hdr_load_raw();
650   void  hasselblad_load_raw();
651   void  phase_one_load_raw_c();
652   unsigned ph1_bithuff (int nbits, uint16_t *huff);
653   void  phase_one_load_raw();
654   void  phase_one_correct();
655   void  phase_one_flat_field(int is_float,int nc);
656   int   raw(unsigned row,unsigned col);
657   void  rollei_load_raw();
658   void  rollei_thumb();
659   void  layer_thumb();
660   void  ppm_thumb();
661   void  jpeg_thumb();
662   void  fuji_load_raw();
663   void  nikon_e2100_load_raw();
664   void  nikon_e900_load_raw();
665   int   minolta_z2();
666   void  nikon_3700();
667   int   nikon_e2100();
668   int   nikon_e995();
669   int   nikon_is_compressed();
670   void  nikon_load_raw();
671   void  nikon_compressed_load_raw();
672   void  pentax_load_raw();
673   void  adobe_dng_load_raw_nc();
674   void  adobe_dng_load_raw_lj();
675   void  adobe_copy_pixel(unsigned row, unsigned col, uint16_t **rp);
676   void  canon_sraw_load_raw();
677   void  lossless_jpeg_load_raw();
678   uint16_t * ljpeg_row(int jrow,struct jhead *jh);
679   void  ljpeg_end (struct jhead *jh);
680   int   ljpeg_diff (uint16_t *huff);
681   int   ljpeg_start(struct jhead *jh,int info_only);
682   void  canon_compressed_load_raw();
683   int   canon_has_lowbits();
684   void  crw_init_tables(unsigned table,uint16_t *huff[2]);
685   uint8_t * make_decoder(const uint8_t *source,int level);
686   void  init_decoder();
687   unsigned  getbits(int nbits);
688   void  canon_a5_load_raw();
689   unsigned getbithuff(int nbits,uint16_t *huff);
690   int   canon_s2is();
691   void  remove_zeroes();
692   void  canon_600_load_raw();
693   void  canon_600_correct();
694   void  canon_600_coeff();
695   void  canon_600_auto_wb();
696   int   canon_600_color(int ratio[2],int mar);
697   void  canon_600_fixed_wb(int temp);
698   void  canon_load_raw();
699   void  lossless_dng_load_raw();
700   void  lossy_dng_load_raw();
701   void  packed_dng_load_raw();
702   void  ppm16_thumb();
703   void  foveon_dp_load_raw();
704   void  foveon_sd_load_raw();
705   void  crop_masked_pixels();
706   /* void  canon_black (double dark[2],int nblack); */
707   void  read_shorts(uint16_t *pixel,int count);
708   double  getreal(int type);
709   float  int_to_float(int i);
710   unsigned  getint(int type);
711   unsigned  get4();
712   unsigned  sget4(uint8_t *s);
713   uint16_t  get2();
714   uint16_t  sget2(uint8_t *s);
715   void  derror();
716   void  merror(void *ptr,const char *where);
717   #if !defined(__GLIBC__)
718   char *my_memmem(char *haystack,size_t haystacklen,char *neepte,size_t neeptelen);
719   #endif
720   int  fcol(int row,int col);
721   // functions for dcb
722   void dcb_pp_old();
723   void copy_to_buffer_old(float (*m_Image2)[3]);
724   void restore_from_buffer_old(float (*m_Image2)[3]);
725   void hid_old();
726   void hid2_old();
727   void dcb_color_old();
728   void dcb_map_old();
729   void dcb_map2_old();
730   void dcb_correction_old();
731   void dcb_correction2_old();
732   void dcb_correction3_old();
733   void dcb_interpolate_soft_old(int iterations, int dcb_smoothing);
734   void dcb_interpolate_sharp_old(int iterations, int dcb_smoothing);
735   // functions for new dcb
736   void dcb_pp();
737   void copy_to_buffer(float (*m_Image2)[3]);
738   void restore_from_buffer(float (*m_Image2)[3]);
739   void hid();
740   void hid2();
741   void dcb_color();
742   void dcb_color_full();
743   void dcb_map();
744   void dcb_correction();
745   void dcb_correction2();
746   void dcb_refinement();
747   void fbdd_green();
748   void fbdd_green2();
749   void fbdd_color();
750   void fbdd_correction();
751   void fbdd_correction2(double (*m_Image3)[3]);
752   void fbdd(int noiserd);
753   void dcb(int iterations, int dcb_enhance);
754   void lch_to_rgb(double (*m_Image3)[3]);
755   void rgb_to_lch(double (*m_Image3)[3]);
756   // functions for vcd
757   void ahd_interpolate_mod();
758   void ahd_partial_interpolate(int threshold_value);
759   void es_median_filter();
760   void median_filter_new();
761   void refinement();
762   void vcd_interpolate(int ahd_cutoff);
763   // functions for algorithms from perfect raw
764   void lmmse_interpolate(int gamma_apply);
765   void amaze_demosaic();
766   void cfa_linedn(float noise);
767   void ddct8x8s(int isgn, float **a);
768   void CA_correct(double cared, double cablue);
769   void green_equilibrate(float thresh);
770 };
771 
772 #endif
773 
774 ////////////////////////////////////////////////////////////////////////////////
775