| 54 | } |
| 55 | |
| 56 | RawImage DcrDecoder::decodeRawInternal() { |
| 57 | SimpleTiffDecoder::prepareForRawDecoding(); |
| 58 | |
| 59 | ByteStream input(DataBuffer(mFile->getSubView(off), Endianness::little)); |
| 60 | |
| 61 | int compression = raw->getEntry(COMPRESSION)->getU32(); |
| 62 | if (65000 != compression) |
| 63 | ThrowRDE("Unsupported compression %d", compression); |
| 64 | |
| 65 | TiffEntry* ifdoffset = mRootIFD->getEntryRecursive(KODAK_IFD); |
| 66 | if (!ifdoffset) |
| 67 | ThrowRDE("Couldn't find the Kodak IFD offset"); |
| 68 | |
| 69 | NORangesSet<Buffer> ifds; |
| 70 | |
| 71 | assert(ifdoffset != nullptr); |
| 72 | TiffRootIFD kodakifd(nullptr, &ifds, ifdoffset->getRootIfdData(), |
| 73 | ifdoffset->getU32()); |
| 74 | |
| 75 | TiffEntry* linearization = kodakifd.getEntryRecursive(KODAK_LINEARIZATION); |
| 76 | if (!linearization || |
| 77 | !(linearization->count == 1024 || linearization->count == 4096) || |
| 78 | linearization->type != TIFF_SHORT) |
| 79 | ThrowRDE("Couldn't find the linearization table"); |
| 80 | |
| 81 | assert(linearization != nullptr); |
| 82 | auto linTable = linearization->getU16Array(linearization->count); |
| 83 | |
| 84 | RawImageCurveGuard curveHandler(&mRaw, linTable, uncorrectedRawValues); |
| 85 | |
| 86 | // FIXME: dcraw does all sorts of crazy things besides this to fetch |
| 87 | // WB from what appear to be presets and calculate it in weird ways |
| 88 | // The only file I have only uses this method, if anybody careas look |
| 89 | // in dcraw.c parse_kodak_ifd() for all that weirdness |
| 90 | TiffEntry* blob = kodakifd.getEntryRecursive(static_cast<TiffTag>(0x03fd)); |
| 91 | if (blob && blob->count == 72) { |
| 92 | for (auto i = 0U; i < 3; i++) { |
| 93 | const auto mul = blob->getU16(20 + i); |
| 94 | if (0 == mul) |
| 95 | ThrowRDE("WB coeffient is zero!"); |
| 96 | mRaw->metadata.wbCoeffs[i] = 2048.0F / mul; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | const int bps = [CurveSize = linearization->count]() -> int { |
| 101 | switch (CurveSize) { |
| 102 | case 1024: |
| 103 | return 10; |
| 104 | case 4096: |
| 105 | return 12; |
| 106 | } |
| 107 | __builtin_unreachable(); |
| 108 | }(); |
| 109 | |
| 110 | KodakDecompressor k(mRaw, input, bps, uncorrectedRawValues); |
| 111 | k.decompress(); |
| 112 | |
| 113 | return mRaw; |
nothing calls this directly
no test coverage detected