2 * Copyright 2007-2008, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
9 #include "ReadHelper.h"
16 struct image_meta_info
{
17 char manufacturer
[64];
33 float camera_multipliers
[4];
34 float pre_multipliers
[4];
35 float rgb_camera
[3][4]; /* RGB from camera color */
39 struct image_data_info
{
44 uint32 bits_per_sample
;
46 uint32 photometric_interpretation
;
54 #define COMPRESSION_NONE 1
55 #define COMPRESSION_OLD_JPEG 6 // Old JPEG (before 6.0)
56 #define COMPRESSION_PACKBITS 32773 // Macintosh RLE
59 typedef void (*monitor_hook
)(const char* message
, float percentage
, void* data
);
63 DCRaw(BPositionIO
& stream
);
67 status_t
ReadImageAt(uint32 index
, uint8
*& outputBuffer
,
70 void GetMetaInfo(image_meta_info
& metaInfo
) const;
71 uint32
CountImages() const;
72 status_t
ImageAt(uint32 index
, image_data_info
& info
) const;
74 status_t
GetEXIFTag(off_t
& offset
, size_t& length
,
75 bool& bigEndian
) const;
76 void SetProgressMonitor(monitor_hook hook
, void* data
);
78 void SetHalfSize(bool half
);
81 int32
_AllocateImage();
82 image_data_info
& _Raw();
83 image_data_info
& _Thumb();
84 void _CorrectIndex(uint32
& index
) const;
85 uint16
& _Bayer(int32 column
, int32 row
);
86 int32
_FilterCoefficient(int32 column
, int32 row
);
87 int32
_FlipIndex(uint32 row
, uint32 col
, uint32 flip
);
88 bool _SupportsCompression(image_data_info
& info
) const;
89 bool _IsCanon() const;
90 bool _IsKodak() const;
91 bool _IsNikon() const;
92 bool _IsOlympus() const;
93 bool _IsPentax() const;
94 bool _IsSamsung() const;
96 // image manipulation and conversion
98 void _WaveletDenoise();
99 void _PreInterpolate();
100 void _CameraToCIELab(ushort cam
[4], float lab
[3]);
101 void _CameraXYZCoefficients(double cam_xyz
[4][3]);
102 void _AdobeCoefficients(const char *manufacturer
, const char *model
);
103 void _BorderInterpolate(uint32 border
);
104 void _AHDInterpolate();
105 void _PseudoInverse(double (*in
)[3], double (*out
)[3], uint32 size
);
106 void _ConvertToRGB();
107 void _GammaLookUpTable(uchar
* lut
);
109 void _ParseThumbTag(off_t baseOffset
, uint32 offsetTag
, uint32 lengthTag
);
110 void _ParseManufacturerTag(off_t baseOffset
);
111 void _ParseEXIF(off_t baseOffset
);
112 void _ParseLinearTable(uint32 length
);
117 uchar
*_MakeDecoder(const uchar
* source
, int level
);
118 void _InitDecodeBits();
119 uint32
_GetDecodeBits(uint32 numBits
);
120 status_t
_LosslessJPEGInit(struct jhead
* jh
, bool infoOnly
);
121 int _LosslessJPEGDiff(struct decode
*dindex
);
122 void _LosslessJPEGRow(struct jhead
*jh
, int jrow
);
125 void _LoadRAWUnpacked(const image_data_info
& image
);
126 void _LoadRAWPacked12(const image_data_info
& info
);
127 void _MakeCanonDecoder(uint32 table
);
128 bool _CanonHasLowBits();
129 void _LoadRAWCanonCompressed(const image_data_info
& info
);
130 void _LoadRAWLosslessJPEG(const image_data_info
& image
);
131 void _LoadRAW(const image_data_info
& info
);
134 void _WriteJPEG(image_data_info
& image
, uint8
* outputBuffer
);
135 void _WriteRGB32(image_data_info
& image
, uint8
* outputBuffer
);
138 time_t _ParseTIFFTimestamp(bool reversed
);
139 void _ParseTIFFTag(off_t baseOffset
, tiff_tag
& tag
, off_t
& offset
);
140 status_t
_ParseTIFFImageFileDirectory(off_t baseOffset
, uint32 offset
);
141 status_t
_ParseTIFFImageFileDirectory(off_t baseOffset
);
142 status_t
_ParseTIFF(off_t baseOffset
);
145 image_meta_info fMeta
;
146 image_data_info
* fImages
;
154 uint16 (*fImageData
)[4];
159 bool fUseCameraWhiteBalance
;
160 bool fUseAutoWhiteBalance
;
168 uint32 fOutputHeight
;
176 float fUserMultipliers
[4];
179 uint32
* fOutputProfile
;
180 uint32 fOutputBitsPerSample
;
181 int32 (*fHistogram
)[4];
184 // TODO: find better names for these...
187 decode
* fDecodeBuffer
;
188 decode
* fSecondDecode
;
192 uint32 fDecodeBitsRead
;
193 bool fDecodeBitsReset
;
194 bool fDecodeBitsZeroAfterMax
;
203 monitor_hook fProgressMonitor
;