diff options
author | Yujie Qin <yujieqin@google.com> | 2016-11-23 17:08:11 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-11-23 17:08:11 +0000 |
commit | 49b27718a2ad96da69c4fab687c71f0b1f135f12 (patch) | |
tree | 63b7e64eacbc46053d9c3dffd12ec7f8bc608994 | |
parent | d1f05a56ede6d8e914e5a476a085323fce311d6c (diff) | |
parent | ba003b8b3103df7ed033e60dd755ad092b411673 (diff) | |
download | piex-49b27718a2ad96da69c4fab687c71f0b1f135f12.tar.gz |
Update PIEX am: 8f540f64b6 am: bb7d7bd270 am: 96f8fa17a5
am: ba003b8b31
Change-Id: I232c119b637f70c7d637b25fbcc2f40349995725
-rw-r--r-- | src/piex.cc | 13 | ||||
-rw-r--r-- | src/tiff_parser.cc | 33 | ||||
-rw-r--r-- | src/tiff_parser.h | 5 |
3 files changed, 37 insertions, 14 deletions
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<std::uint32_t> crop(2); - std::vector<Rational> 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<std::uint32_t> crop(2); + std::vector<Rational> 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: |