From 8f540f64b6c170a16fb7e6e52d61819705c1522a Mon Sep 17 00:00:00 2001 From: Yujie Qin Date: Wed, 23 Nov 2016 12:37:05 +0100 Subject: Update PIEX --- src/piex.cc | 13 ++++++++++--- src/tiff_parser.cc | 33 ++++++++++++++++++++++----------- src/tiff_parser.h | 5 +++++ 3 files changed, 37 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/piex.cc b/src/piex.cc index fd381db..338e581 100644 --- a/src/piex.cc +++ b/src/piex.cc @@ -419,19 +419,26 @@ Error DngGetPreviewData(StreamInterface* stream, kTiffTagStripByteCounts, kTiffTagStripOffsets, kTiffTagSubIfd}; TiffContent tiff_content; - const std::uint32_t kNumberOfIfds = 4; + const std::uint32_t kNumberOfIfds = 3; if (!GetPreviewData(extended_tags, 0, kNumberOfIfds, stream, &tiff_content, preview_image_data)) { return kFail; } + const TiffDirectory& tiff_directory = tiff_content.tiff_directory[0]; + + if (!GetFullCropDimension(tiff_directory, &preview_image_data->full_width, + &preview_image_data->full_height)) { + return kFail; + } + // Find the jpeg compressed thumbnail and preview image. Image preview; Image thumbnail; // Search for images in IFD0 Image temp_image; - if (GetImageData(tiff_content.tiff_directory[0], stream, &temp_image)) { + if (GetImageData(tiff_directory, stream, &temp_image)) { if (IsThumbnail(temp_image, kDngThumbnailMaxDimension)) { thumbnail = temp_image; } else if (temp_image.format == Image::kJpegCompressed) { @@ -440,7 +447,7 @@ Error DngGetPreviewData(StreamInterface* stream, } // Search for images in other IFDs - for (const auto& ifd : tiff_content.tiff_directory[0].GetSubDirectories()) { + for (const auto& ifd : tiff_directory.GetSubDirectories()) { if (GetImageData(ifd, stream, &temp_image)) { // Try to find the largest thumbnail/preview. if (IsThumbnail(temp_image, kDngThumbnailMaxDimension)) { diff --git a/src/tiff_parser.cc b/src/tiff_parser.cc index 00bb944..24368e0 100644 --- a/src/tiff_parser.cc +++ b/src/tiff_parser.cc @@ -557,17 +557,7 @@ bool GetFullDimension32(const TiffDirectory& tiff_directory, } if (tiff_directory.Has(kExifTagDefaultCropSize)) { - std::vector crop(2); - std::vector crop_rational(2); - if (tiff_directory.Get(kExifTagDefaultCropSize, &crop)) { - *width = crop[0]; - *height = crop[1]; - } else if (tiff_directory.Get(kExifTagDefaultCropSize, &crop_rational) && - crop_rational[0].denominator != 0 && - crop_rational[1].denominator != 0) { - *width = crop_rational[0].numerator / crop_rational[0].denominator; - *height = crop_rational[1].numerator / crop_rational[1].denominator; - } else { + if (!GetFullCropDimension(tiff_directory, width, height)) { return false; } } else if (tiff_directory.Has(kExifTagWidth) && @@ -604,6 +594,27 @@ bool GetFullDimension32(const TiffDirectory& tiff_directory, return true; } +bool GetFullCropDimension(const tiff_directory::TiffDirectory& tiff_directory, + std::uint32_t* width, std::uint32_t* height) { + if (tiff_directory.Has(kExifTagDefaultCropSize)) { + std::vector crop(2); + std::vector crop_rational(2); + if (tiff_directory.Get(kExifTagDefaultCropSize, &crop)) { + *width = crop[0]; + *height = crop[1]; + } else if (tiff_directory.Get(kExifTagDefaultCropSize, &crop_rational) && + crop_rational[0].denominator != 0 && + crop_rational[1].denominator != 0) { + *width = crop_rational[0].numerator / crop_rational[0].denominator; + *height = crop_rational[1].numerator / crop_rational[1].denominator; + } else { + return false; + } + } + + return true; +} + TiffParser::TiffParser(StreamInterface* stream) : stream_(stream) {} TiffParser::TiffParser(StreamInterface* stream, const std::uint32_t offset) diff --git a/src/tiff_parser.h b/src/tiff_parser.h index 3cb9d7e..84b3fc6 100644 --- a/src/tiff_parser.h +++ b/src/tiff_parser.h @@ -162,6 +162,11 @@ bool GetExifOrientation(StreamInterface* stream, const std::uint32_t offset, bool GetFullDimension32(const tiff_directory::TiffDirectory& tiff_directory, std::uint32_t* width, std::uint32_t* height); +// Reads the width and height of the crop information if available. +// Returns false if an error occured. +bool GetFullCropDimension(const tiff_directory::TiffDirectory& tiff_directory, + std::uint32_t* width, std::uint32_t* height); + // Enables us to parse through data that complies to the Tiff/EP specification. class TiffParser { public: -- cgit v1.2.3