Update PIEX

This commit is contained in:
Yujie Qin
2016-01-07 10:49:46 +01:00
parent d267716b0e
commit a6fb4b68e5
4 changed files with 49 additions and 55 deletions

View File

@@ -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;
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;
}
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.

View File

@@ -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);

View File

@@ -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

View File

@@ -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;
}