| 266 | } |
| 267 | |
| 268 | void DngDecoder::decodeData(const TiffIFD* raw, uint32_t sample_format) { |
| 269 | if (compression == 8 && sample_format != 3) { |
| 270 | ThrowRDE("Only float format is supported for " |
| 271 | "deflate-compressed data."); |
| 272 | } else if ((compression == 7 || compression == 0x884c) && |
| 273 | sample_format != 1) { |
| 274 | ThrowRDE("Only 16 bit unsigned data supported for " |
| 275 | "JPEG-compressed data."); |
| 276 | } |
| 277 | |
| 278 | uint32_t predictor = ~0U; |
| 279 | if (raw->hasEntry(PREDICTOR)) |
| 280 | predictor = raw->getEntry(PREDICTOR)->getU32(); |
| 281 | |
| 282 | // Some decompressors (such as VC5) may depend on the white point |
| 283 | if (raw->hasEntry(WHITELEVEL)) { |
| 284 | TiffEntry* whitelevel = raw->getEntry(WHITELEVEL); |
| 285 | if (whitelevel->isInt()) |
| 286 | mRaw->whitePoint = whitelevel->getU32(); |
| 287 | } |
| 288 | |
| 289 | AbstractDngDecompressor slices(mRaw, getTilingDescription(raw), compression, |
| 290 | mFixLjpeg, bps, predictor); |
| 291 | |
| 292 | slices.slices.reserve(slices.dsc.numTiles); |
| 293 | |
| 294 | TiffEntry* offsets = nullptr; |
| 295 | TiffEntry* counts = nullptr; |
| 296 | if (raw->hasEntry(TILEOFFSETS)) { |
| 297 | offsets = raw->getEntry(TILEOFFSETS); |
| 298 | counts = raw->getEntry(TILEBYTECOUNTS); |
| 299 | } else { // Strips |
| 300 | offsets = raw->getEntry(STRIPOFFSETS); |
| 301 | counts = raw->getEntry(STRIPBYTECOUNTS); |
| 302 | } |
| 303 | assert(slices.dsc.numTiles == offsets->count); |
| 304 | assert(slices.dsc.numTiles == counts->count); |
| 305 | |
| 306 | NORangesSet<Buffer> tilesLegality; |
| 307 | for (auto n = 0U; n < slices.dsc.numTiles; n++) { |
| 308 | const auto offset = offsets->getU32(n); |
| 309 | const auto count = counts->getU32(n); |
| 310 | |
| 311 | if (count < 1) |
| 312 | ThrowRDE("Tile %u is empty", n); |
| 313 | |
| 314 | ByteStream bs(DataBuffer(mFile->getSubView(offset, count), |
| 315 | mRootIFD->rootBuffer.getByteOrder())); |
| 316 | |
| 317 | if (!tilesLegality.emplace(bs).second) |
| 318 | ThrowTPE("Two tiles overlap. Raw corrupt!"); |
| 319 | |
| 320 | slices.slices.emplace_back(slices.dsc, n, bs); |
| 321 | } |
| 322 | |
| 323 | assert(slices.slices.size() == slices.dsc.numTiles); |
| 324 | if (slices.slices.empty()) |
| 325 | ThrowRDE("No valid slices found."); |
nothing calls this directly
no test coverage detected