mirror of
https://github.com/Evolution-X/external_piex
synced 2026-01-27 16:24:09 +00:00
Update PIEX
am: 8f540f64b6
Change-Id: If7cb6f03f63683948f7b65da5ebbd886ea741fc0
This commit is contained in:
13
src/piex.cc
13
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)) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user