24 #include <sys/types.h>
29 #include <libopenraw/cameraids.h>
30 #include <libopenraw/debug.h>
32 #include "thumbnail.hpp"
33 #include "rawdata.hpp"
36 #include "io/stream.hpp"
37 #include "mrwcontainer.hpp"
39 #include "ifdentry.hpp"
40 #include "ifdfilecontainer.hpp"
41 #include "mrwfile.hpp"
43 #include "rawfile_private.hpp"
45 using namespace Debug;
50 #define OR_MAKE_MINOLTA_TYPEID(camid) \
51 OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_MINOLTA,camid)
54 static const BuiltinColourMatrix s_matrices[] = {
55 { OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_MAXXUM_5D), 0, 0xffb,
56 { 10284,-3283,-1086,-7957,15762,2316,-829,882,6644 } },
57 { OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_MAXXUM_7D), 0, 0xffb,
58 { 10239,-3104,-1099,-8037,15727,2451,-927,925,6871 } },
59 { OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_DIMAGE5), 0, 0xf7d,
60 { 8983,-2942,-963,-6556,14476,2237,-2426,2887,8014 } },
61 { OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_DIMAGE7), 0, 0xf7d,
62 { 9144,-2777,-998,-6676,14556,2281,-2470,3019,7744 } },
63 { OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_DIMAGE7I), 0, 0xf7d,
64 { 9144,-2777,-998,-6676,14556,2281,-2470,3019,7744 } },
65 { OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_DIMAGE7HI), 0, 0xf7d,
66 { 11368,-3894,-1242,-6521,14358,2339,-2475,3056,7285 } },
67 { OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_A1), 0, 0xf8b,
68 { 9274,-2547,-1167,-8220,16323,1943,-2273,2720,8340 } },
69 { OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_A2), 0, 0xf8f,
70 { 9097,-2726,-1053,-8073,15506,2762,-966,981,7763 } },
71 { OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_A200), 0, 0,
72 { 8560,-2487,-986,-8112,15535,2771,-1209,1324,7743 } },
74 { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
78 {
"21860002", OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_MAXXUM_5D) },
79 {
"21810002", OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_MAXXUM_7D) },
80 {
"27730001", OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_DIMAGE5) },
81 {
"27660001", OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_DIMAGE7) },
82 {
"27790001", OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_DIMAGE7I) },
83 {
"27780001", OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_DIMAGE7HI) },
84 {
"27820001", OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_A1) },
85 {
"27200001", OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_A2) },
86 {
"27470002", OR_MAKE_MINOLTA_TYPEID(OR_TYPEID_MINOLTA_A200) },
99 _setMatrices(s_matrices);
126 if(_mainIfd && mc->prd) {
127 auto version = mc->prd->string_val(MRW::PRD_VERSION);
129 _setTypeId(_typeIdFromModel(
"Minolta Co., Ltd.", version.value()));
131 LOGERR(
"Coudln't read Minolta version\n");
151 LOGWARN(
"No MakerNote found\n");
155 uint32_t tnail_offset = 0;
156 uint32_t tnail_len = 0;
157 IfdEntry::Ref thumb_ent = mnote->getEntry(MRW::MRWTAG_THUMBNAIL);
159 tnail_offset = thumb_ent->offset();
160 tnail_len = thumb_ent->count();
162 auto result = mnote->getValue<uint32_t>(MRW::MRWTAG_THUMBNAIL_OFFSET);
163 if (result.empty()) {
164 LOGWARN(
"thumbnail offset entry not found\n");
167 tnail_offset = result.value();
169 result = mnote->getValue<uint32_t>(MRW::MRWTAG_THUMBNAIL_LENGTH);
170 if (result.empty()) {
171 LOGWARN(
"thumbnail lenght entry not found\n");
174 tnail_len = result.value();
177 LOGDBG1(
"thumbnail offset found, offset == %u count == %u\n",
178 tnail_offset, tnail_len);
179 void *p = thumbnail.allocData(tnail_len);
182 + MRW::DataBlockHeaderLength
185 if (fetched != tnail_len) {
186 LOGWARN(
"Unable to fetch all thumbnail data: %lu not %u bytes\n",
187 (LSIZE)fetched, tnail_len);
190 ((
unsigned char *)p)[0] = 0xFF;
206 uint16_t y = mc->prd->uint16_val(MRW::PRD_SENSOR_LENGTH).value_or(0);
207 uint16_t x = mc->prd->uint16_val(MRW::PRD_SENSOR_WIDTH).value_or(0);
208 uint8_t bpc = mc->prd->uint8_val(MRW::PRD_PIXEL_SIZE).value_or(0);
210 bool is_compressed = (mc->prd->uint8_val(MRW::PRD_STORAGE_TYPE).value_or(MRW::STORAGE_TYPE_UNPACKED) == MRW::STORAGE_TYPE_PACKED);
215 uint32_t finaldatalen = 2 * x * y;
217 (is_compressed ? x * y + ((x * y) >> 1) : finaldatalen);
220 finaldatalen = datalen;
231 RawFile::_getBuiltinLevels(_getMatrices(),
typeId(), black, white);
232 data.setBlackLevel(black);
233 data.setWhiteLevel(white);
234 LOGDBG1(
"datalen = %d final datalen = %u\n", datalen, finaldatalen);
235 void *p = data.allocData(finaldatalen);
240 uint16_t* pixels = (uint16_t*)p;
241 for (
auto i = 0; i < x * y; i++) {
242 *pixels = be16toh(*pixels);
247 size_t blocksize = unpack.block_size();
248 auto block = std::make_unique<uint8_t[]>(blocksize);
249 uint16_t* outdata = (uint16_t*)data.data();
250 size_t outsize = finaldatalen;
253 LOGDBG2(
"fetchData @offset %lld\n", (
long long int)offset);
258 LOGDBG2(
"got %lu\n", (LSIZE)got);
262 block.get(), got, out);
265 LOGDBG2(
"unpacked %lu bytes from %lu\n", (LSIZE)out, (LSIZE)got);
271 }
while ((got != 0) && (fetched < datalen));
273 if (fetched < datalen) {
274 LOGWARN(
"Fetched only %lu of %u: continuing anyway.\n", (LSIZE)fetched,
277 uint16_t bpat = mc->prd->uint16_val(MRW::PRD_BAYER_PATTERN)
278 .value_or(MRW::BAYER_PATTERN_RGGB);
282 case MRW::BAYER_PATTERN_RGGB:
283 cfa_pattern = OR_CFA_PATTERN_RGGB;
285 case MRW::BAYER_PATTERN_GBRG:
286 cfa_pattern = OR_CFA_PATTERN_GBRG;
291 data.setCfaPatternType(cfa_pattern);
void setDataType(DataType _type)
Set the data type.
void setBpc(uint32_t _bpc)
Set bit per channel.
virtual void setDimensions(uint32_t x, uint32_t y)
Set the pixel dimensions of the bitmap.
std::shared_ptr< Stream > Ptr
std::shared_ptr< IfdDir > Ref
Shared ptr of an IfdDir.
std::shared_ptr< IfdEntry > Ref
IfdEntry reference (ie shared pointer)
IfdDir::Ref setDirectory(int dir)
Set the current directory.
IfdFileContainer * m_container
off_t pixelDataOffset() const
size_t fetchData(void *buf, off_t offset, size_t buf_size) const
Fetch the data chunk from the file.
or_error unpack_be12to16(uint16_t *dest, size_t destsize, const uint8_t *src, size_t size, size_t &outsize) const
Represent camera raw data.
virtual void setDimensions(uint32_t x, uint32_t y) override
Set the pixel dimensions of the bitmap.
TypeId typeId()
The RAW file type ID. Identify it if needed.
void _setTypeId(TypeId _type_id)
Set the file type id.
Internals::MakerNoteDir::Ref makerNoteIfd()
Get the MakerNote IFD.
Internals::IfdDir::Ref mainIfd()
Get the main IFD.
or_cfa_pattern
CFA pattern types.
or_error
Error codes returned by libopenraw.
@ OR_DATA_TYPE_COMPRESSED_RAW
@ OR_OPTIONS_DONT_DECOMPRESS
@ OR_IFD_MAIN
Main (like in TIFF)
Global namespace for libopenraw.
virtual ::or_error _enumThumbnailSizes(std::vector< uint32_t > &list) override
List the thumbnails in the IFD.
virtual void _identifyId() override
Identify the file and set the ID internally.
virtual ::or_error _getRawData(RawData &data, uint32_t options) override
Get the RAW data.
virtual IfdDir::Ref _locateCfaIfd() override
Locate the IFD for the raw data.
virtual IfdDir::Ref _locateMainIfd() override
Locate the main IFD.