27 #include <libopenraw/cameraids.h>
28 #include <libopenraw/consts.h>
29 #include <libopenraw/debug.h>
31 #include "cr3file.hpp"
32 #include "isomediacontainer.hpp"
34 #include "rawdata.hpp"
35 #include "rawfile_private.hpp"
36 #include "bitmapdata.hpp"
39 using namespace Debug;
44 #define OR_MAKE_CANON_TYPEID(camid) \
45 OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, camid)
48 static const BuiltinColourMatrix s_matrices[] = {
49 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_M200),
52 { 10463, -2173, -1437, -4856, 12635, 2482, -1216, 2915, 7237 } },
53 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_M50),
56 { 8532, -701, -1167, -4095, 11879, 2508, -797, 2424, 7010 } },
57 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_M50MKII),
60 { 10463, -2173, -1437, -4856, 12635, 2482, -1216, 2915, 7237 } },
61 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_M6MKII),
64 { 11498, -3759, -1516, -5073, 12954, 2349, -892, 1867, 6118 } },
65 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_90D),
68 { 11498, -3759, -1516, -5073, 12954, 2349, -892, 1867, 6118 } },
69 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R),
72 { 6446, -366, -864, -4436, 12204, 2513, -952, 2496, 6348 } },
73 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_RP),
76 { 8608, -2097, -1178, -5425, 13265, 2383, -1149, 2238, 5680 } },
77 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R3),
80 { 9423, -2839, -1195, -4532, 12377, 2415, -483, 1374, 5276 } },
81 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R5),
84 { 9766, -2953, -1254, -4276, 12116, 2433, -437, 1336, 5131 } },
85 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R50),
88 { 9269, -2012, -1107, -3990, 11762, 2527, -569, 2093, 4913 } },
89 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R6),
92 { 8293, -1611, -1132, -4759, 12711, 2275, -1013, 2415, 5509 } },
93 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R6MKII),
96 { 9539, -2795, -1224, -4175, 11998, 2458, -465, 1755, 6048 } },
97 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R7),
100 { 10424, -3138, -1300, -4221, 11938, 2584, -547, 1658, 6183 } },
101 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R8),
104 { 9539, -2795, -1224, -4175, 11998, 2458, -465, 1755, 6048 } },
105 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R10),
108 { 9269, -2012, -1107, -3990, 11762, 2527, -569, 2093, 4913 } },
109 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_SX70_HS),
112 { 18285, -8907, -1951, -1845, 10688, 1323, 364, 1101, 5139 } },
113 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_250D),
116 { 9079, -1923, -1236, -4677, 12454, 2492, -922, 2319, 5565 } },
117 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_850D),
120 { 9079, -1923, -1236, -4677, 12454, 2492, -922, 2319, 5565 } },
121 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_G5XMKII),
124 { 11629, -5713, -914, -2706, 11090, 1842, -206, 1225, 5515 } },
125 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_G7XMKIII),
128 { 11629, -5713, -914, -2706, 11090, 1842, -206, 1225, 5515 } },
129 { OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_1DXMKIII),
132 { 8971, -2022, -1242, -5405, 13249, 2380, -1280, 2483, 6072 } },
133 { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
136 const RawFile::camera_ids_t Cr3File::s_def[] = {
137 {
"Canon EOS M50", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_M50) },
138 {
"Canon EOS M200", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_M200) },
139 {
"Canon EOS R", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R) },
140 {
"Canon EOS RP", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_RP) },
141 {
"Canon EOS R3", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R3) },
142 {
"Canon EOS R5", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R5) },
143 {
"Canon EOS R6", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R6) },
144 {
"Canon EOS R6 m2", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R6MKII) },
145 {
"Canon EOS R7", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R7) },
146 {
"Canon EOS R8", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R8) },
147 {
"Canon EOS R10", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R10) },
148 {
"Canon EOS R50", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_R50) },
149 {
"Canon EOS 250D", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_250D) },
150 {
"Canon EOS Rebel SL3", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_250D) },
151 {
"Canon EOS 850D", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_850D) },
152 {
"Canon EOS Rebel T8i", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_850D) },
153 {
"Canon PowerShot SX70 HS", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_SX70_HS) },
154 {
"Canon PowerShot G5 X Mark II", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_G5XMKII) },
155 {
"Canon PowerShot G7 X Mark III", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_G7XMKIII) },
156 {
"Canon EOS-1D X Mark III", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_1DXMKIII) },
157 {
"Canon EOS M6 Mark II", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_EOS_M6MKII) },
158 {
"Canon EOS 90D", OR_MAKE_CANON_TYPEID(OR_TYPEID_CANON_90D) },
162 RawFile *Cr3File::factory(
const IO::Stream::Ptr &s)
164 return new Cr3File(s);
167 Cr3File::Cr3File(
const IO::Stream::Ptr &s)
170 , m_container(new IsoMediaContainer(s))
173 _setMatrices(s_matrices);
188 auto track = m_container->get_track(2);
189 if (!track || (*track).track_type != MP4PARSE_TRACK_TYPE_VIDEO) {
190 LOGERR(
"%u Not a video track\n", 2);
193 auto raw_track = m_container->get_raw_track(2);
194 if (!raw_track || (*raw_track).is_jpeg) {
195 LOGERR(
"%u not the RAW data track\n", 2);
200 LOGWARN(
"Can't provide decompressed data yet. Ignoring.\n");
204 data.
setDimensions((*raw_track).image_width, (*raw_track).image_height);
209 data.setActiveArea((*sensorInfo)[0], (*sensorInfo)[1],
210 (*sensorInfo)[2], (*sensorInfo)[3]);
213 auto byte_length = (*raw_track).size;
214 void* p = data.allocData(byte_length);
215 size_t real_size = m_container->fetchData(p, (*raw_track).offset,
217 if (real_size < byte_length) {
218 LOGWARN(
"Size mismatch for data: ignoring.\n");
223 ::or_error Cr3File::_enumThumbnailSizes(std::vector<uint32_t> &list)
226 auto craw_header = m_container->get_craw_header();
228 uint32_t x = (*craw_header).thumb_w;
229 uint32_t y = (*craw_header).thumb_h;
230 auto dim = std::max(x, y);
233 auto data = std::make_unique<BitmapData>();
234 data->setDimensions(x, y);
236 void* p = data->allocData((*craw_header).thumbnail.length);
237 ::memcpy(p, (*craw_header).thumbnail.data, (*craw_header).thumbnail.length);
242 auto track_count = m_container->count_tracks();
243 for (uint32_t i = 0; i < track_count; i++) {
244 auto track = m_container->get_track(i);
245 if (!track || (*track).track_type != MP4PARSE_TRACK_TYPE_VIDEO) {
246 LOGDBG1(
"%u Not a video track\n", i);
249 auto raw_track = m_container->get_raw_track(i);
250 if (!raw_track || !(*raw_track).is_jpeg) {
251 LOGDBG1(
"%u not a RAW data track\n", i);
254 auto dim = std::max((*raw_track).image_width,
255 (*raw_track).image_height);
256 LOGDBG1(
"Dimension %u\n", dim);
258 _addThumbnail(dim,
ThumbDesc((*raw_track).image_width,
259 (*raw_track).image_height,
265 auto desc = m_container->get_preview_desc();
267 auto dim = std::max((*desc).x, (*desc).y);
269 _addThumbnail(dim, desc.value());
279 if (idx >= m_ifds.size()) {
280 LOGERR(
"Invalid ifd index %u\n", idx);
284 auto ifd = m_ifds[idx];
287 ifd = m_container->get_metadata_block(idx);
289 LOGERR(
"cr3: can't find meta block 0\n");
290 return IfdDir::Ref();
294 return ifd->setDirectory(0);
299 auto ifd = findIfd(0);
308 auto ifd = findIfd(1);
315 MakerNoteDir::Ref Cr3File::_locateMakerNoteIfd()
317 auto ifd = findIfd(2);
319 auto mnote = std::make_shared<MakerNoteDir>(*ifd,
"Canon", mnote_canon_tag_names);
323 return std::dynamic_pointer_cast<MakerNoteDir>(ifd);
337 LOGERR(
"Unknown Meta Namespace\n");
344 val = ifd->makeMetaValue(*e);
351 void Cr3File::_identifyId()
356 auto mn = makerNoteIfd();
358 auto id = mn->getValue<uint32_t>(IFD::MNOTE_CANON_MODEL_ID);
360 auto id_value =
id.value();
366 LOGERR(
"model ID %x not found\n", id_value);
368 LOGERR(
"model ID not found\n");
371 LOGERR(
"model ID not found (missing MakerNote)\n");
void setDataType(DataType _type)
Set the data type.
std::shared_ptr< IfdDir > Ref
Shared ptr of an IfdDir.
std::shared_ptr< IfdEntry > Ref
IfdEntry reference (ie shared pointer)
Generic interface for the RAW file container.
Represent camera raw data.
virtual void setDimensions(uint32_t x, uint32_t y) override
Set the pixel dimensions of the bitmap.
Option< std::array< uint32_t, 4 > > canon_get_sensorinfo(const IfdDir::Ref &ifddir)
Get the sensor info from and IfdDir.
const ModelIdMap canon_modelid_map
The model ID map for Canon cameras.
or_error
Error codes returned by libopenraw.
@ OR_DATA_TYPE_COMPRESSED_RAW
@ OR_OPTIONS_DONT_DECOMPRESS
@ OR_IFD_MAIN
Main (like in TIFF)
@ OR_IFD_EXIF
Exif metadata.
Global namespace for libopenraw.