Skip to content

Commit 2af2cd0

Browse files
committed
Do not throw if DNG crop is undefined
The file is probably usable, so fall back to default values and log error instead
1 parent 834caca commit 2af2cd0

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

src/librawspeed/decoders/DngDecoder.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -509,13 +509,19 @@ void DngDecoder::handleMetadata(const TiffIFD* raw) {
509509
const TiffEntry* size_entry = raw->getEntry(TiffTag::DEFAULTCROPSIZE);
510510

511511
const auto tl_r = origin_entry->getRationalArray(2);
512-
std::array<unsigned, 2> tl;
513-
std::transform(tl_r.begin(), tl_r.end(), tl.begin(),
514-
[](const NotARational<unsigned>& r) {
515-
if (r.den == 0 || r.num % r.den != 0)
516-
ThrowRDE("Error decoding default crop origin");
517-
return r.num / r.den;
518-
});
512+
std::array<unsigned, 2> tl = {0, 0};
513+
try {
514+
std::transform(tl_r.begin(), tl_r.end(), tl.begin(),
515+
[](const NotARational<unsigned>& r) {
516+
if (r.den == 0 || r.num % r.den != 0)
517+
ThrowRDE("Error decoding default crop origin");
518+
return r.num / r.den;
519+
});
520+
} catch (const RawDecoderException& e) {
521+
// We push back errors from the crop parser, since the image may still
522+
// be usable
523+
mRaw->setError(e.what());
524+
}
519525

520526
if (iPoint2D cropOrigin(tl[0], tl[1]);
521527
cropped.isPointInsideInclusive(cropOrigin))
@@ -524,13 +530,19 @@ void DngDecoder::handleMetadata(const TiffIFD* raw) {
524530
cropped.dim = mRaw->dim - cropped.pos;
525531

526532
const auto sz_r = size_entry->getRationalArray(2);
527-
std::array<unsigned, 2> sz;
528-
std::transform(sz_r.begin(), sz_r.end(), sz.begin(),
529-
[](const NotARational<unsigned>& r) {
530-
if (r.den == 0 || r.num % r.den != 0)
531-
ThrowRDE("Error decoding default crop size");
532-
return r.num / r.den;
533-
});
533+
std::array<unsigned, 2> sz = {mRaw->dim.x, mRaw->dim.y};
534+
try {
535+
std::transform(sz_r.begin(), sz_r.end(), sz.begin(),
536+
[](const NotARational<unsigned>& r) {
537+
if (r.den == 0 || r.num % r.den != 0)
538+
ThrowRDE("Error decoding default crop size");
539+
return r.num / r.den;
540+
});
541+
} catch (const RawDecoderException& e) {
542+
// We push back errors from the crop parser, since the image may still
543+
// be usable
544+
mRaw->setError(e.what());
545+
}
534546

535547
if (iPoint2D size(sz[0], sz[1]);
536548
size.isThisInside(mRaw->dim) &&

0 commit comments

Comments
 (0)