1 /* 2 * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef RAW_H 6 #define RAW_H 7 8 9 #include "ReadHelper.h" 10 11 struct jhead; 12 struct tiff_tag; 13 14 15 struct image_meta_info { 16 char manufacturer[64]; 17 char model[128]; 18 char software[64]; 19 float flash_used; 20 float iso_speed; 21 float shutter; 22 float aperture; 23 float focal_length; 24 double pixel_aspect; 25 uint32 raw_width; 26 uint32 raw_height; 27 int flip; 28 uint32 dng_version; 29 uint32 shot_order; 30 int32 black; 31 int32 maximum; 32 float camera_multipliers[4]; 33 float pre_multipliers[4]; 34 float rgb_camera[3][4]; /* RGB from camera color */ 35 time_t timestamp; 36 }; 37 38 struct image_data_info { 39 uint32 width; 40 uint32 height; 41 uint32 output_width; 42 uint32 output_height; 43 uint32 bits_per_sample; 44 uint32 compression; 45 uint32 photometric_interpretation; 46 uint32 flip; 47 uint32 samples; 48 uint32 bytes; 49 off_t data_offset; 50 bool is_raw; 51 }; 52 53 typedef void (*monitor_hook)(const char* message, float percentage, void* data); 54 55 class DCRaw { 56 public: 57 DCRaw(BPositionIO& stream); 58 ~DCRaw(); 59 60 status_t Identify(); 61 status_t ReadImageAt(uint32 index, uint8*& outputBuffer, 62 size_t& bufferSize); 63 64 void GetMetaInfo(image_meta_info& metaInfo) const; 65 uint32 CountImages() const; 66 status_t ImageAt(uint32 index, image_data_info& info) const; 67 68 status_t GetEXIFTag(off_t& offset, size_t& length, 69 bool& bigEndian) const; 70 void SetProgressMonitor(monitor_hook hook, void* data); 71 72 void SetHalfSize(bool half); 73 74 private: 75 int32 _AllocateImage(); 76 image_data_info& _Raw(); 77 image_data_info& _Thumb(); 78 void _CorrectIndex(uint32& index) const; 79 uint16& _Bayer(int32 column, int32 row); 80 int32 _FilterCoefficient(int32 column, int32 row); 81 int32 _FlipIndex(uint32 row, uint32 col, uint32 flip); 82 bool _IsCanon() const; 83 bool _IsKodak() const; 84 bool _IsNikon() const; 85 bool _IsPentax() const; 86 bool _IsSamsung() const; 87 88 // image manipulation and conversion 89 void _ScaleColors(); 90 void _WaveletDenoise(); 91 void _PreInterpolate(); 92 void _CameraToCIELab(ushort cam[4], float lab[3]); 93 void _CameraXYZCoefficients(double cam_xyz[4][3]); 94 void _AdobeCoefficients(char* manufacturer, char* model); 95 void _BorderInterpolate(uint32 border); 96 void _AHDInterpolate(); 97 void _PseudoInverse(double (*in)[3], double (*out)[3], uint32 size); 98 void _ConvertToRGB(); 99 void _GammaLookUpTable(uchar* lut); 100 101 void _ParseThumbTag(off_t baseOffset, uint32 offsetTag, uint32 lengthTag); 102 void _ParseManufacturerTag(off_t baseOffset); 103 void _ParseEXIF(off_t baseOffset); 104 void _ParseLinearTable(uint32 length); 105 void _FixupValues(); 106 107 // Lossless JPEG 108 void _InitDecoder(); 109 uchar *_MakeDecoder(const uchar* source, int level); 110 void _InitDecodeBits(); 111 uint32 _GetDecodeBits(uint32 numBits); 112 status_t _LosslessJPEGInit(struct jhead* jh, bool infoOnly); 113 int _LosslessJPEGDiff(struct decode *dindex); 114 void _LosslessJPEGRow(struct jhead *jh, int jrow); 115 116 // RAW Loader 117 void _LoadRAWPacked12(const image_data_info& info); 118 void _MakeCanonDecoder(uint32 table); 119 bool _CanonHasLowBits(); 120 void _LoadRAWCanonCompressed(const image_data_info& info); 121 void _LoadRAWLosslessJPEG(const image_data_info& image); 122 void _LoadRAW(const image_data_info& info); 123 124 // Image writers 125 void _WriteJPEG(image_data_info& image, uint8* outputBuffer); 126 void _WriteRGB32(image_data_info& image, uint8* outputBuffer); 127 128 // TIFF 129 time_t _ParseTIFFTimestamp(bool reversed); 130 void _ParseTIFFTag(off_t baseOffset, tiff_tag& tag, off_t& offset); 131 status_t _ParseTIFFImageFileDirectory(off_t baseOffset, uint32 offset); 132 status_t _ParseTIFFImageFileDirectory(off_t baseOffset); 133 status_t _ParseTIFF(off_t baseOffset); 134 135 TReadHelper fRead; 136 image_meta_info fMeta; 137 image_data_info* fImages; 138 uint32 fNumImages; 139 140 int32 fRawIndex; 141 int32 fThumbIndex; 142 uint32 fDNGVersion; 143 bool fIsTIFF; 144 145 uint16 (*fImageData)[4]; 146 // output image data 147 float fThreshold; 148 int32 fShrink; 149 bool fHalfSize; 150 bool fUseCameraWhiteBalance; 151 bool fUseAutoWhiteBalance; 152 bool fRawColor; 153 bool fUseGamma; 154 float fBrightness; 155 int32 fOutputColor; 156 int32 fHighlight; 157 int32 fDocumentMode; 158 uint32 fOutputWidth; 159 uint32 fOutputHeight; 160 uint32 fInputWidth; 161 uint32 fInputHeight; 162 int32 fTopMargin; 163 int32 fLeftMargin; 164 uint32 fUniqueID; 165 uint32 fColors; 166 uint16 fWhite[8][8]; 167 float fUserMultipliers[4]; 168 uint16* fCurve; 169 uint16 fCR2Slice[3]; 170 uint32* fOutputProfile; 171 uint32 fOutputBitsPerSample; 172 int32 (*fHistogram)[4]; 173 float* cbrt; 174 float xyz_cam[3][4]; 175 // TODO: find better names for these... 176 177 // Lossless JPEG 178 decode* fDecodeBuffer; 179 decode* fSecondDecode; 180 decode* fFreeDecode; 181 int fDecodeLeaf; 182 uint32 fDecodeBits; 183 uint32 fDecodeBitsRead; 184 bool fDecodeBitsReset; 185 bool fDecodeBitsZeroAfterMax; 186 187 uint32 fFilters; 188 uint32 fEXIFFilters; 189 off_t fEXIFOffset; 190 uint32 fEXIFLength; 191 192 off_t fCurveOffset; 193 194 monitor_hook fProgressMonitor; 195 void* fProgressData; 196 }; 197 198 #endif // RAW_H 199