aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEik Brauer <ebrauer@google.com>2016-02-01 12:26:23 +0100
committerEik Brauer <ebrauer@google.com>2016-02-01 12:26:23 +0100
commitb415ce2eec78846ec705c983f98a74c9526f3faa (patch)
treeaa83fd1272e65390cc12a41c8484853edc928bc1 /src
parenta9540117cdd785b0dd75f8c4c28b278f86eb485c (diff)
downloadpiex-b415ce2eec78846ec705c983f98a74c9526f3faa.tar.gz
Enables warnings for unused parameters. Adds cfa_repeat_pattern_dim to identify non bayer patterns e.g. Fuji X-Trans in DNG.
Diffstat (limited to 'src')
-rw-r--r--src/binary_parse/range_checked_byte_ptr.cc6
-rw-r--r--src/piex.cc79
-rw-r--r--src/piex_types.h4
-rw-r--r--src/tiff_parser.cc12
-rw-r--r--src/tiff_parser.h1
5 files changed, 62 insertions, 40 deletions
diff --git a/src/binary_parse/range_checked_byte_ptr.cc b/src/binary_parse/range_checked_byte_ptr.cc
index dd6fac6..bbfdee2 100644
--- a/src/binary_parse/range_checked_byte_ptr.cc
+++ b/src/binary_parse/range_checked_byte_ptr.cc
@@ -52,12 +52,10 @@ size_t MemoryPagedByteArray::length() const { return len_; }
size_t MemoryPagedByteArray::pageSize() const { return len_; }
-void MemoryPagedByteArray::getPage(size_t page_index,
+void MemoryPagedByteArray::getPage(size_t /* page_index */,
const unsigned char **begin,
const unsigned char **end,
PagePtr *page) const {
- assert(page_index == 0);
-
*begin = buffer_;
*end = buffer_ + len_;
*page = PagePtr();
@@ -68,7 +66,7 @@ void MemoryPagedByteArray::getPage(size_t page_index,
class NullFunctor {
public:
void operator()() {}
- void operator()(PagedByteArray *p) const {}
+ void operator()(PagedByteArray * /* p */) const {}
};
} // namespace
diff --git a/src/piex.cc b/src/piex.cc
index 1d341fd..09b154a 100644
--- a/src/piex.cc
+++ b/src/piex.cc
@@ -43,8 +43,9 @@ Error GetPreviewData(const TagSet& extended_tags,
kExifTagExposureTime, kExifTagFnumber,
kExifTagFocalLength, kExifTagGps,
kExifTagIsoSpeed, kTiffTagDateTime,
- kTiffTagExifIfd, kTiffTagMake,
- kTiffTagModel, kTiffTagOrientation};
+ kTiffTagExifIfd, kTiffTagCfaPatternDim,
+ kTiffTagMake, kTiffTagModel,
+ kTiffTagOrientation};
desired_tags.insert(extended_tags.cbegin(), extended_tags.cend());
TiffParser tiff_parser(stream, tiff_offset);
@@ -120,6 +121,28 @@ Error GetExifIfd(const Endian endian, StreamInterface* stream,
stream, exif_ifd, &next_ifd_offset);
}
+bool GetImageFromIfd(const TiffDirectory& ifd, std::uint32_t* offset,
+ std::uint32_t* length) {
+ std::uint32_t compression;
+ std::uint32_t photometric_interpretation;
+ if (ifd.Get(kTiffTagPhotometric, &photometric_interpretation) &&
+ ifd.Get(kTiffTagCompression, &compression)) {
+ if (photometric_interpretation == 6 /* YCbCr */ &&
+ (compression == 6 /* JPEG(old) */ || compression == 7 /* JPEG */)) {
+ std::vector<std::uint32_t> strip_offsets;
+ std::vector<std::uint32_t> byte_counts;
+ if (ifd.Get(kTiffTagStripOffsets, &strip_offsets) &&
+ ifd.Get(kTiffTagStripByteCounts, &byte_counts) &&
+ strip_offsets.size() == 1 && byte_counts.size() == 1) {
+ *length = byte_counts[0];
+ *offset = strip_offsets[0];
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
Error GetMakernoteIfd(const TiffDirectory& exif_ifd, const Endian endian,
const std::uint32_t skip_offset, StreamInterface* stream,
std::uint32_t* makernote_offset,
@@ -377,28 +400,25 @@ Error DngGetPreviewData(StreamInterface* stream,
std::uint32_t preview_offset = 0;
std::uint32_t thumbnail_length = std::numeric_limits<std::uint32_t>::max();
std::uint32_t thumbnail_offset = std::numeric_limits<std::uint32_t>::max();
+
+ std::uint32_t length = 0;
+ std::uint32_t offset = 0;
+ if (GetImageFromIfd(tiff_content.tiff_directory[0], &offset, &length)) {
+ preview_length = length;
+ preview_offset = offset;
+ thumbnail_length = length;
+ thumbnail_offset = offset;
+ }
+
for (const auto& ifd : tiff_content.tiff_directory[0].GetSubDirectories()) {
- std::uint32_t compression;
- std::uint32_t photometric_interpretation;
- if (!ifd.Get(kTiffTagPhotometric, &photometric_interpretation) ||
- !ifd.Get(kTiffTagCompression, &compression)) {
- continue;
- }
- if (photometric_interpretation == 6 /* YCbCr */ &&
- (compression == 6 /* JPEG(old) */ || compression == 7 /* JPEG */)) {
- std::vector<std::uint32_t> strip_offsets;
- std::vector<std::uint32_t> byte_counts;
- if (ifd.Get(kTiffTagStripOffsets, &strip_offsets) &&
- ifd.Get(kTiffTagStripByteCounts, &byte_counts) &&
- strip_offsets.size() == 1 && byte_counts.size() == 1) {
- if (byte_counts[0] > preview_length) {
- preview_length = byte_counts[0];
- preview_offset = strip_offsets[0];
- }
- if (byte_counts[0] < thumbnail_length) {
- thumbnail_length = byte_counts[0];
- thumbnail_offset = strip_offsets[0];
- }
+ if (GetImageFromIfd(ifd, &offset, &length)) {
+ if (length > preview_length) {
+ preview_length = length;
+ preview_offset = offset;
+ }
+ if (length < thumbnail_length) {
+ thumbnail_length = length;
+ thumbnail_offset = offset;
}
}
}
@@ -649,18 +669,7 @@ Error GetPreviewImageData(StreamInterface* data,
}
std::vector<std::string> SupportedExtensions() {
- std::vector<std::string> extensions;
- extensions.push_back("ARW");
- extensions.push_back("CR2");
- extensions.push_back("DNG");
- extensions.push_back("NEF");
- extensions.push_back("NRW");
- extensions.push_back("ORF");
- extensions.push_back("PEF");
- extensions.push_back("RAF");
- extensions.push_back("RW2");
- extensions.push_back("SRW");
- return extensions;
+ return {"ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "PEF", "RAF", "RW2", "SRW"};
}
} // namespace piex
diff --git a/src/piex_types.h b/src/piex_types.h
index f0c216a..6b294bd 100644
--- a/src/piex_types.h
+++ b/src/piex_types.h
@@ -78,6 +78,10 @@ struct PreviewImageData {
Rational fnumber;
Rational focal_length;
Gps gps;
+
+ // Hint for the mosaic pattern dimension of the RAW image data. (0, 0) implies
+ // that no mosaic info found. It is valid for DNG, NEF and NRW files.
+ std::uint32_t cfa_pattern_dim[2] = {0, 0};
};
// Defines the StreamInterface that needs to be implemented by the client.
diff --git a/src/tiff_parser.cc b/src/tiff_parser.cc
index f9488ef..80f3759 100644
--- a/src/tiff_parser.cc
+++ b/src/tiff_parser.cc
@@ -92,7 +92,8 @@ bool GetFullDimension(const TiffDirectory& tiff_directory, std::uint32_t* width,
bool GetRational(const TiffDirectory::Tag& tag, const TiffDirectory& directory,
const int data_size, PreviewImageData::Rational* data) {
std::vector<Rational> value;
- if (directory.Get(tag, &value)) {
+ if (directory.Get(tag, &value) &&
+ value.size() == static_cast<size_t>(data_size)) {
for (size_t i = 0; i < value.size(); ++i) {
data[i].numerator = value[i].numerator;
data[i].denominator = value[i].denominator;
@@ -219,6 +220,15 @@ Error FillPreviewImageData(const TiffDirectory& tiff_directory,
success &= tiff_directory.Get(kTiffTagModel, &preview_image_data->model);
}
+ if (tiff_directory.Has(kTiffTagCfaPatternDim)) {
+ std::vector<std::uint32_t> cfa_pattern_dim;
+ if (tiff_directory.Get(kTiffTagCfaPatternDim, &cfa_pattern_dim) &&
+ cfa_pattern_dim.size() == 2) {
+ preview_image_data->cfa_pattern_dim[0] = cfa_pattern_dim[0];
+ preview_image_data->cfa_pattern_dim[1] = cfa_pattern_dim[1];
+ }
+ }
+
if (tiff_directory.Has(kExifTagDateTimeOriginal)) {
success &= tiff_directory.Get(kExifTagDateTimeOriginal,
&preview_image_data->date_time);
diff --git a/src/tiff_parser.h b/src/tiff_parser.h
index 4518f36..553b652 100644
--- a/src/tiff_parser.h
+++ b/src/tiff_parser.h
@@ -63,6 +63,7 @@ enum TiffTags {
kPentaxTagColorSpace = 0x0037,
kTiffTagArtist = 0x013B,
kTiffTagBitsPerSample = 0x0102,
+ kTiffTagCfaPatternDim = 0x828D,
kTiffTagCompression = 0x0103,
kTiffTagDateTime = 0x0132,
kTiffTagExifIfd = 0x8769,