MCPcopy Create free account
hub / github.com/darktable-org/rawspeed / parseHeader

Method parseHeader

src/librawspeed/decoders/MrwDecoder.cpp:49–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49void MrwDecoder::parseHeader() {
50 if (!isMRW(mFile))
51 ThrowRDE("This isn't actually a MRW file, why are you calling me?");
52
53 const DataBuffer db(*mFile, Endianness::big);
54 ByteStream bs(db);
55
56 // magic
57 bs.skipBytes(4);
58
59 // the size of the rest of the header, up to the image data
60 const auto headerSize = bs.getU32();
61 bs.check(headerSize);
62
63 // ... and offset to the image data at the same time
64 const auto dataOffset = bs.getPosition() + headerSize;
65 assert(bs.getPosition() == 8);
66
67 // now, let's parse rest of the header.
68 bs = bs.getSubStream(0, dataOffset);
69 bs.skipBytes(8);
70
71 bool foundPRD = false;
72 while (bs.getRemainSize() > 0) {
73 uint32_t tag = bs.getU32();
74 uint32_t len = bs.getU32();
75 bs.check(len);
76 if (!len)
77 ThrowRDE("Found entry of zero length, MRW is corrupt.");
78
79 const auto origPos = bs.getPosition();
80
81 switch (tag) {
82 case 0x505244: { // PRD
83 foundPRD = true;
84 bs.skipBytes(8); // Version Number
85 raw_height = bs.getU16(); // CCD Size Y
86 raw_width = bs.getU16(); // CCD Size X
87
88 if (!raw_width || !raw_height || raw_width > 3280 || raw_height > 2456) {
89 ThrowRDE("Unexpected image dimensions found: (%u; %u)", raw_width,
90 raw_height);
91 }
92
93 bs.skipBytes(2); // Image Size Y
94 bs.skipBytes(2); // Image Size X
95
96 bpp = bs.getByte(); // DataSize
97 if (12 != bpp && 16 != bpp)
98 ThrowRDE("Unknown data size");
99
100 if ((raw_height * raw_width * bpp) % 8 != 0)
101 ThrowRDE("Bad combination of image size and raw dimensions.");
102
103 if (12 != bs.getByte()) // PixelSize
104 ThrowRDE("Unexpected pixel size");
105
106 const auto SM = bs.getByte(); // StorageMethod

Callers

nothing calls this directly

Calls 11

getPositionMethod · 0.80
getSubStreamMethod · 0.80
getRemainSizeMethod · 0.80
getBufferMethod · 0.80
setPositionMethod · 0.80
getSubViewMethod · 0.80
skipBytesMethod · 0.45
getU32Method · 0.45
checkMethod · 0.45
getU16Method · 0.45
getByteMethod · 0.45

Tested by

no test coverage detected