aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEik Brauer <ebrauer@google.com>2016-01-27 13:25:41 +0100
committerEik Brauer <ebrauer@google.com>2016-01-27 13:25:41 +0100
commita9540117cdd785b0dd75f8c4c28b278f86eb485c (patch)
tree01ffab1667199d718f6b00a570c5168a46671639
parentafc6ebdcba72e4eeeaafab1547c19025fcec5d1f (diff)
downloadpiex-a9540117cdd785b0dd75f8c4c28b278f86eb485c.tar.gz
Updates Piex.
-rwxr-xr-xpiex.gyp19
-rw-r--r--src/binary_parse/cached_paged_byte_array.cc5
-rw-r--r--src/binary_parse/range_checked_byte_ptr.cc18
-rw-r--r--src/piex.cc2
-rw-r--r--src/tiff_parser.cc59
-rw-r--r--src/tiff_parser.h5
6 files changed, 73 insertions, 35 deletions
diff --git a/piex.gyp b/piex.gyp
index 091ace0..2df546c 100755
--- a/piex.gyp
+++ b/piex.gyp
@@ -28,7 +28,10 @@
],
},
'include_dirs': ['.'],
- 'cflags': ['-Wsign-compare'],
+ 'cflags': [
+ '-Wsign-compare',
+ '-Wsign-conversion',
+ ],
'dependencies': [
'binary_parse',
'image_type_recognition',
@@ -48,7 +51,10 @@
],
},
'include_dirs': ['.'],
- 'cflags': ['-Wsign-compare'],
+ 'cflags': [
+ '-Wsign-compare',
+ '-Wsign-conversion',
+ ],
}, {
'target_name': 'image_type_recognition',
'type': 'static_library',
@@ -59,11 +65,18 @@
'headers': ['src/image_type_recognition/image_type_recognition_lite.h'],
},
'include_dirs': ['.'],
- 'cflags': ['-Wsign-compare'],
+ 'cflags': [
+ '-Wsign-compare',
+ '-Wsign-conversion',
+ ],
'dependencies': ['binary_parse'],
}, {
'target_name': 'tiff_directory',
'type': 'static_library',
+ 'cflags': [
+ '-Wsign-compare',
+ '-Wsign-conversion',
+ ],
'sources': [
'src/tiff_directory/tiff_directory.cc',
],
diff --git a/src/binary_parse/cached_paged_byte_array.cc b/src/binary_parse/cached_paged_byte_array.cc
index a6ab3b0..83b6c03 100644
--- a/src/binary_parse/cached_paged_byte_array.cc
+++ b/src/binary_parse/cached_paged_byte_array.cc
@@ -21,6 +21,8 @@
#include "src/binary_parse/cached_paged_byte_array.h"
+#include <cstddef>
+
namespace piex {
namespace binary_parse {
@@ -41,7 +43,8 @@ void CachedPagedByteArray::getPage(size_t page_index,
*page = cached_pages_[cache_index].page;
// Remove the page to insert it at the end of the cache later.
- cached_pages_.erase(cached_pages_.begin() + cache_index);
+ cached_pages_.erase(cached_pages_.begin() +
+ static_cast<std::ptrdiff_t>(cache_index));
} else {
// Cache miss, ask PagedByteArray to load the page.
paged_byte_array_->getPage(page_index, begin, end, page);
diff --git a/src/binary_parse/range_checked_byte_ptr.cc b/src/binary_parse/range_checked_byte_ptr.cc
index 1f882ed..dd6fac6 100644
--- a/src/binary_parse/range_checked_byte_ptr.cc
+++ b/src/binary_parse/range_checked_byte_ptr.cc
@@ -217,7 +217,7 @@ void RangeCheckedBytePtr::loadPageForOffset(size_t offset) const {
// Remember information about page.
page_data_ = page_begin;
page_begin_offset_ = page_index * array_->pageSize();
- current_page_len_ = page_end - page_begin;
+ current_page_len_ = static_cast<size_t>(page_end - page_begin);
// Restrict the boundaries of the page to lie within the sub-array.
restrictPageToSubArray();
@@ -328,9 +328,9 @@ uint16 Get16u(const RangeCheckedBytePtr &input, const bool big_endian,
return 0;
}
if (big_endian) {
- return (input[0] << 8) | input[1];
+ return (static_cast<uint16>(input[0]) << 8) | static_cast<uint16>(input[1]);
} else {
- return (input[1] << 8) | input[0];
+ return (static_cast<uint16>(input[1]) << 8) | static_cast<uint16>(input[0]);
}
}
@@ -388,11 +388,15 @@ uint32 Get32u(const RangeCheckedBytePtr &input, const bool big_endian,
return 0;
}
if (big_endian) {
- return (input[0] << 24) | (input[1] << 16) | (input[2] << 8) |
- (input[3] << 0);
+ return (static_cast<uint32>(input[0]) << 24) |
+ (static_cast<uint32>(input[1]) << 16) |
+ (static_cast<uint32>(input[2]) << 8) |
+ (static_cast<uint32>(input[3]) << 0);
} else {
- return (input[3] << 24) | (input[2] << 16) | (input[1] << 8) |
- (input[0] << 0);
+ return (static_cast<uint32>(input[3]) << 24) |
+ (static_cast<uint32>(input[2]) << 16) |
+ (static_cast<uint32>(input[1]) << 8) |
+ (static_cast<uint32>(input[0]) << 0);
}
}
diff --git a/src/piex.cc b/src/piex.cc
index ed3c8f4..1d341fd 100644
--- a/src/piex.cc
+++ b/src/piex.cc
@@ -328,7 +328,7 @@ bool RafGetDimension(StreamInterface* stream, std::uint32_t* width,
*height = tmp_height;
return true;
}
- cfa_header_index += 4 + length;
+ cfa_header_index += 4u + length;
}
return false;
}
diff --git a/src/tiff_parser.cc b/src/tiff_parser.cc
index 4143b16..f9488ef 100644
--- a/src/tiff_parser.cc
+++ b/src/tiff_parser.cc
@@ -89,7 +89,7 @@ bool GetFullDimension(const TiffDirectory& tiff_directory, std::uint32_t* width,
return true;
}
-bool GetRational(const Tags& tag, const TiffDirectory& directory,
+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)) {
@@ -252,7 +252,7 @@ Error FillPreviewImageData(const TiffDirectory& tiff_directory,
return kOk;
}
-const TiffDirectory* FindFirstTagInIfds(const Tags& tag,
+const TiffDirectory* FindFirstTagInIfds(const TiffDirectory::Tag& tag,
const IfdVector& tiff_directory) {
for (std::uint32_t i = 0; i < tiff_directory.size(); ++i) {
if (tiff_directory[i].Has(tag)) {
@@ -322,11 +322,11 @@ bool Get32u(StreamInterface* stream, const std::uint32_t offset,
std::uint8_t data[4];
if (stream->GetData(offset, 4, data) == kOk) {
if (endian == kBigEndian) {
- *value = (data[0] * 0x1000000) | (data[1] * 0x10000) | (data[2] * 0x100) |
- data[3];
+ *value = (data[0] * 0x1000000u) | (data[1] * 0x10000u) |
+ (data[2] * 0x100u) | data[3];
} else {
- *value = (data[3] * 0x1000000) | (data[2] * 0x10000) | (data[1] * 0x100) |
- data[0];
+ *value = (data[3] * 0x1000000u) | (data[2] * 0x10000u) |
+ (data[1] * 0x100u) | data[0];
}
return true;
} else {
@@ -431,7 +431,7 @@ Error ParseDirectory(const std::uint32_t tiff_offset,
Get16u(stream, ifd_offset + 4 + i, endian, &type) &&
Get32u(stream, ifd_offset + 6 + i, endian, &number_of_elements)) {
// Check if the current tag should be handled.
- if (desired_tags.count(static_cast<Tags>(tag)) != 1) {
+ if (desired_tags.count(static_cast<TiffDirectory::Tag>(tag)) != 1) {
continue;
}
} else {
@@ -467,7 +467,7 @@ Error ParseDirectory(const std::uint32_t tiff_offset,
tiff_directory->AddEntry(tag, type, number_of_elements, value_offset, data);
}
- if (Get32u(stream, ifd_offset + 2 + number_of_entries * 12, endian,
+ if (Get32u(stream, ifd_offset + 2u + number_of_entries * 12u, endian,
next_ifd_offset)) {
return kOk;
} else {
@@ -525,9 +525,10 @@ Error TiffParser::Parse(const TagSet& desired_tags,
}
// Get the Exif data.
- const TiffDirectory* tiff_ifd =
- FindFirstTagInIfds(kTiffTagExifIfd, tiff_content->tiff_directory);
- if (tiff_ifd != NULL) {
+ if (FindFirstTagInIfds(kTiffTagExifIfd, tiff_content->tiff_directory) !=
+ nullptr) {
+ const TiffDirectory* tiff_ifd =
+ FindFirstTagInIfds(kTiffTagExifIfd, tiff_content->tiff_directory);
std::uint32_t offset;
if (tiff_ifd->Get(kTiffTagExifIfd, &offset)) {
tiff_content->exif_directory.reset(new TiffDirectory(endian_));
@@ -539,19 +540,18 @@ Error TiffParser::Parse(const TagSet& desired_tags,
return error;
}
- if (tiff_ifd->Get(kExifTagGps, &offset)) {
- tiff_content->gps_directory.reset(new TiffDirectory(endian_));
- const TagSet gps_tags = {kGpsTagLatitudeRef, kGpsTagLatitude,
- kGpsTagLongitudeRef, kGpsTagLongitude,
- kGpsTagAltitudeRef, kGpsTagAltitude,
- kGpsTagTimeStamp, kGpsTagDateStamp};
- return ParseDirectory(
- tiff_offset_, tiff_offset_ + offset, endian_, gps_tags, stream_,
- tiff_content->gps_directory.get(), &next_ifd_offset);
- }
+ return ParseGpsData(tiff_ifd, tiff_content);
}
}
+ // Get the GPS data from the tiff ifd.
+ if (FindFirstTagInIfds(kExifTagGps, tiff_content->tiff_directory) !=
+ nullptr) {
+ const TiffDirectory* tiff_ifd =
+ FindFirstTagInIfds(kExifTagGps, tiff_content->tiff_directory);
+ return ParseGpsData(tiff_ifd, tiff_content);
+ }
+
return error;
}
@@ -578,4 +578,21 @@ Error TiffParser::ParseIfd(const std::uint32_t offset_to_ifd,
return error;
}
+Error TiffParser::ParseGpsData(const TiffDirectory* tiff_ifd,
+ TiffContent* tiff_content) {
+ std::uint32_t offset;
+ if (tiff_ifd->Get(kExifTagGps, &offset)) {
+ tiff_content->gps_directory.reset(new TiffDirectory(endian_));
+ const TagSet gps_tags = {kGpsTagLatitudeRef, kGpsTagLatitude,
+ kGpsTagLongitudeRef, kGpsTagLongitude,
+ kGpsTagAltitudeRef, kGpsTagAltitude,
+ kGpsTagTimeStamp, kGpsTagDateStamp};
+ std::uint32_t next_ifd_offset;
+ return ParseDirectory(tiff_offset_, tiff_offset_ + offset, endian_,
+ gps_tags, stream_, tiff_content->gps_directory.get(),
+ &next_ifd_offset);
+ }
+ return kOk;
+}
+
} // namespace piex
diff --git a/src/tiff_parser.h b/src/tiff_parser.h
index 88b4006..4518f36 100644
--- a/src/tiff_parser.h
+++ b/src/tiff_parser.h
@@ -91,8 +91,7 @@ enum TiffTags {
kTiffTagYresolution = 0x011B,
};
-typedef int Tags;
-typedef std::set<Tags> TagSet;
+typedef std::set<tiff_directory::TiffDirectory::Tag> TagSet;
typedef std::vector<tiff_directory::TiffDirectory> IfdVector;
struct TiffContent {
@@ -166,6 +165,8 @@ class TiffParser {
Error ParseIfd(const std::uint32_t ifd_offset, const TagSet& desired_tags,
const std::uint16_t max_number_ifds,
IfdVector* tiff_directory);
+ Error ParseGpsData(const tiff_directory::TiffDirectory* tiff_ifd,
+ TiffContent* tiff_content);
StreamInterface* stream_ = nullptr;
std::uint32_t tiff_offset_ = 0;