diff options
author | Yujie Qin <yujieqin@google.com> | 2016-01-07 10:49:46 +0100 |
---|---|---|
committer | Yujie Qin <yujieqin@google.com> | 2016-01-07 10:49:46 +0100 |
commit | a6fb4b68e5c6ef3597b8d7815f5e4464f4bea5c2 (patch) | |
tree | 5e7b6e33f7e42d6b9a0487edd676109a2e2b56f7 /src | |
parent | d267716b0e04aa482363620e9cdbc6a11f7b8655 (diff) | |
download | piex-a6fb4b68e5c6ef3597b8d7815f5e4464f4bea5c2.tar.gz |
Update PIEX
Diffstat (limited to 'src')
-rw-r--r-- | src/piex.cc | 73 | ||||
-rw-r--r-- | src/piex.h | 5 | ||||
-rw-r--r-- | src/piex_types.h | 2 | ||||
-rw-r--r-- | src/tiff_parser.cc | 26 |
4 files changed, 50 insertions, 56 deletions
diff --git a/src/piex.cc b/src/piex.cc index 83906f7..9fd028c 100644 --- a/src/piex.cc +++ b/src/piex.cc @@ -309,6 +309,7 @@ Error DngGetPreviewData(StreamInterface* stream, // Find the largest jpeg compressed preview image. std::uint32_t jpeg_length = 0; + std::uint32_t jpeg_offset = 0; for (const auto& ifd : tiff_content.tiff_directory[0].GetSubDirectories()) { std::uint32_t compression; std::uint32_t photometric_interpretation; @@ -325,16 +326,12 @@ Error DngGetPreviewData(StreamInterface* stream, strip_offsets.size() == 1 && byte_counts.size() == 1 && byte_counts[0] > jpeg_length) { jpeg_length = byte_counts[0]; - preview_image_data->jpeg_length = jpeg_length; - preview_image_data->jpeg_offset = strip_offsets[0]; + jpeg_offset = strip_offsets[0]; } } } - - // A 'jpeg_length' of 0 indicates that we could not find any jpeg preview. - if (jpeg_length == 0) { - return kUnsupported; - } + preview_image_data->jpeg_length = jpeg_length; + preview_image_data->jpeg_offset = jpeg_offset; // This format doesn't necessarily embed a full jpeg. preview_image_data->full_preview = false; @@ -362,25 +359,27 @@ Error NefGetPreviewData(StreamInterface* stream, // size needs to be taken into account. Based on experiments the preview image // dimensions must be at least 90% of the sensor image dimensions to let it be // a full size preview image. - const float kEpsilon = 0.9f; - - std::uint16_t width; - std::uint16_t height; - if (!GetPreviewDimensions(preview_image_data->jpeg_offset, stream, &width, - &height) || - preview_image_data->full_width == 0 || - preview_image_data->full_height == 0) { - return kUnsupported; - } + if (preview_image_data->jpeg_length > 0) { // when preview image exists + const float kEpsilon = 0.9f; + + std::uint16_t width; + std::uint16_t height; + if (!GetPreviewDimensions(preview_image_data->jpeg_offset, stream, &width, + &height) || + preview_image_data->full_width == 0 || + preview_image_data->full_height == 0) { + return kUnsupported; + } - if (static_cast<float>(width) / - static_cast<float>(preview_image_data->full_width) > - kEpsilon || - static_cast<float>(height) / - static_cast<float>(preview_image_data->full_height) > - kEpsilon) { - preview_image_data->full_width = width; - preview_image_data->full_height = height; + if (static_cast<float>(width) / + static_cast<float>(preview_image_data->full_width) > + kEpsilon || + static_cast<float>(height) / + static_cast<float>(preview_image_data->full_height) > + kEpsilon) { + preview_image_data->full_width = width; + preview_image_data->full_height = height; + } } return kOk; } @@ -416,11 +415,13 @@ Error RafGetPreviewData(StreamInterface* stream, return kFail; } - // Parse the Exif information from the preview image. Omit kUnsupported, - // because the exif data does not contain any preview image. - const std::uint32_t exif_offset = jpeg_offset + 12; - if (GetExifData(exif_offset, stream, preview_image_data) == kFail) { - return kFail; + if (jpeg_length > 0) { // when preview image exists + // Parse the Exif information from the preview image. Omit kUnsupported, + // because the exif data does not contain any preview image. + const std::uint32_t exif_offset = jpeg_offset + 12; + if (GetExifData(exif_offset, stream, preview_image_data) == kFail) { + return kFail; + } } // Merge the Exif data with the RAW data to form the preview_image_data. @@ -453,11 +454,13 @@ Error Rw2GetPreviewData(StreamInterface* stream, return error; } - // Parse the Exif information from the preview image. Omit kUnsupported, - // because the exif data does not contain any preview image. - const std::uint32_t exif_offset = preview_data.jpeg_offset + 12; - if (GetExifData(exif_offset, stream, preview_image_data) == kFail) { - return kFail; + if (preview_data.jpeg_length > 0) { // when preview image exists + // Parse the Exif information from the preview image. Omit kUnsupported, + // because the exif data does not contain any preview image. + const std::uint32_t exif_offset = preview_data.jpeg_offset + 12; + if (GetExifData(exif_offset, stream, preview_image_data) == kFail) { + return kFail; + } } // Merge the Exif data with the RAW data to form the preview_image_data. @@ -67,7 +67,10 @@ bool IsRaw(StreamInterface* data); // offset to a JPEG compressed image from the beginning of the file. // // Returns 'kFail' when something with the data is wrong. -// Returns 'kUnsupported' if no preview image data was found. +// Returns 'kUnsupported' if file format is not supported. +// +// One could check the "preview_image_data->jpeg_length != 0" for the existance +// of a preview image. Error GetPreviewImageData(StreamInterface* data, PreviewImageData* preview_image_data); diff --git a/src/piex_types.h b/src/piex_types.h index 36ae5b9..54dc5b6 100644 --- a/src/piex_types.h +++ b/src/piex_types.h @@ -56,7 +56,7 @@ struct PreviewImageData { std::string date_stamp; // Giving as "YYYY:MM:DD" format. }; - // Required data to find the preview image and to handle it correctly. + // Optional data to find the preview image and to handle it correctly. std::uint32_t jpeg_offset = 0; std::uint32_t jpeg_length = 0; std::uint32_t exif_orientation = 1; // horizontal as default diff --git a/src/tiff_parser.cc b/src/tiff_parser.cc index ce98a9c..af25803 100644 --- a/src/tiff_parser.cc +++ b/src/tiff_parser.cc @@ -158,8 +158,7 @@ void FillGpsPreviewImageData(const TiffDirectory& gps_directory, } Error FillPreviewImageData(const TiffDirectory& tiff_directory, - PreviewImageData* preview_image_data, - bool* has_preview) { + PreviewImageData* preview_image_data) { bool success = true; // Get jpeg_offset and jpeg_length if (tiff_directory.Has(kTiffTagStripOffsets) && @@ -170,19 +169,16 @@ Error FillPreviewImageData(const TiffDirectory& tiff_directory, !tiff_directory.Get(kTiffTagStripByteCounts, &strip_byte_counts)) { return kFail; } - if (strip_offsets.size() != 1 || strip_byte_counts.size() != 1) { - return kUnsupported; + if (strip_offsets.size() == 1 && strip_byte_counts.size() == 1) { + preview_image_data->jpeg_offset = strip_offsets[0]; + preview_image_data->jpeg_length = strip_byte_counts[0]; } - preview_image_data->jpeg_offset = strip_offsets[0]; - preview_image_data->jpeg_length = strip_byte_counts[0]; - *has_preview = true; } else if (tiff_directory.Has(kTiffTagJpegOffset) && tiff_directory.Has(kTiffTagJpegByteCount)) { success &= tiff_directory.Get(kTiffTagJpegOffset, &preview_image_data->jpeg_offset); success &= tiff_directory.Get(kTiffTagJpegByteCount, &preview_image_data->jpeg_length); - *has_preview = true; } else if (tiff_directory.Has(kPanaTagJpegImage)) { if (!tiff_directory.GetOffsetAndLength(kPanaTagJpegImage, TIFF_TYPE_UNDEFINED, @@ -190,7 +186,6 @@ Error FillPreviewImageData(const TiffDirectory& tiff_directory, &preview_image_data->jpeg_length)) { return kFail; } - *has_preview = true; } // Get exif_orientation @@ -484,15 +479,13 @@ TiffParser::TiffParser(StreamInterface* stream, const std::uint32_t offset) Error TiffParser::GetPreviewImageData(const TiffContent& tiff_content, PreviewImageData* preview_image_data) { - bool has_preview = false; Error error = kOk; for (const auto& tiff_directory : tiff_content.tiff_directory) { - error = - FillPreviewImageData(tiff_directory, preview_image_data, &has_preview); + error = FillPreviewImageData(tiff_directory, preview_image_data); if (error == kOk && tiff_directory.Has(kTiffTagExifIfd) && tiff_content.exif_directory) { error = FillPreviewImageData(*tiff_content.exif_directory, - preview_image_data, &has_preview); + preview_image_data); } if (error == kOk && tiff_directory.Has(kExifTagGps) && tiff_content.gps_directory) { @@ -500,15 +493,10 @@ Error TiffParser::GetPreviewImageData(const TiffContent& tiff_content, } for (const auto& sub_directory : tiff_directory.GetSubDirectories()) { if (error == kOk) { - error = FillPreviewImageData(sub_directory, preview_image_data, - &has_preview); + error = FillPreviewImageData(sub_directory, preview_image_data); } } } - - if (error == kOk && !has_preview) { - return kUnsupported; - } return error; } |