Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Piex #2

Merged
merged 1 commit into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions piex.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
'type': 'static_library',
'sources': [
'src/piex.cc',
'src/piex_cr3.cc',
'src/tiff_parser.cc',
],
'variables': {
'headers': [
'src/piex.h',
'src/piex_cr3.h',
'src/piex_types.h',
'src/tiff_parser.h',
],
Expand Down
3 changes: 2 additions & 1 deletion src/image_type_recognition/image_type_recognition_lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,14 @@ class ArwTypeChecker : public TypeChecker {
// Search for (kSignatureFileTypeSection + kSignatureVersions[i]) in first
// requested bytes
const string kSignatureSection("\x00\xb0\x01\x00\x04\x00\x00\x00", 8);
const int kSignatureVersionsSize = 5;
const int kSignatureVersionsSize = 6;
const string kSignatureVersions[kSignatureVersionsSize] = {
string("\x02\x00", 2), // ARW 1.0
string("\x03\x00", 2), // ARW 2.0
string("\x03\x01", 2), // ARW 2.1
string("\x03\x02", 2), // ARW 2.2
string("\x03\x03", 2), // ARW 2.3
string("\x04\x00", 2), // ARW 4.0
};
bool matched = false;
for (int i = 0; i < kSignatureVersionsSize; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions src/piex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ bool GetOlympusPreviewImage(StreamInterface* stream,
}

if (raw_processing_ifd.Has(kOlymTagAspectFrame)) {
std::vector<std::uint32_t> aspect_frame(4);
std::vector<std::uint32_t> aspect_frame;
if (raw_processing_ifd.Get(kOlymTagAspectFrame, &aspect_frame) &&
aspect_frame[2] > aspect_frame[0] &&
aspect_frame.size() == 4 && aspect_frame[2] > aspect_frame[0] &&
aspect_frame[3] > aspect_frame[1]) {
preview_image_data->full_width = aspect_frame[2] - aspect_frame[0] + 1;
preview_image_data->full_height = aspect_frame[3] - aspect_frame[1] + 1;
Expand Down
10 changes: 5 additions & 5 deletions src/piex_cr3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ constexpr Uuid kUuidPrvw = {0xea, 0xf4, 0x2b, 0x5e, 0x1c, 0x98, 0x4b, 0x88,
0xb9, 0xfb, 0xb7, 0xdc, 0x40, 0x6e, 0x4d, 0x16};

constexpr size_t kTagSize = 4;
using BoxTag = std::array<std::uint8_t, kTagSize>;
using BoxTag = std::array<char, kTagSize>;

constexpr BoxTag NewTag(const char s[kTagSize + 1]) {
return BoxTag{s[0], s[1], s[2], s[3]};
Expand Down Expand Up @@ -232,8 +232,8 @@ Box GetNextBox(StreamInterface* stream, size_t offset) {
return Box();
}
BoxTag tag;
Error status =
stream->GetData(offset + sizeof(length_32), kTagSize, tag.data());
Error status = stream->GetData(offset + sizeof(length_32), kTagSize,
reinterpret_cast<std::uint8_t*>(tag.data()));
if (status != kOk) {
return Box();
}
Expand Down Expand Up @@ -531,7 +531,7 @@ bool IsImage(StreamInterface* stream, const Image& image) {

Error Cr3GetPreviewData(StreamInterface* stream,
PreviewImageData* preview_image_data) {
ProcessData data{preview_image_data};
ProcessData data{.preview_image_data = preview_image_data};
if (!ProcessStream(stream, kMdatTag, &data)) {
return kFail;
}
Expand All @@ -548,7 +548,7 @@ Error Cr3GetPreviewData(StreamInterface* stream,

bool Cr3GetOrientation(StreamInterface* stream, std::uint32_t* orientation) {
PreviewImageData preview_image_data;
ProcessData data{&preview_image_data};
ProcessData data{.preview_image_data = &preview_image_data};
if (ProcessStream(stream, kCmt1Tag, &data)) {
*orientation = preview_image_data.exif_orientation;
return true;
Expand Down
11 changes: 5 additions & 6 deletions src/tiff_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace {

using tiff_directory::Endian;
using tiff_directory::Rational;
using tiff_directory::SRational;
using tiff_directory::SizeOfType;
using tiff_directory::TIFF_TYPE_LONG;
using tiff_directory::TIFF_TYPE_UNDEFINED;
Expand Down Expand Up @@ -396,8 +395,8 @@ bool GetImageData(const TiffDirectory& tiff_directory, StreamInterface* stream,
default:
return false;
}
length = static_cast<std::uint32_t>(
std::accumulate(strip_byte_counts.begin(), strip_byte_counts.end(), 0));
length = static_cast<std::uint32_t>(std::accumulate(
strip_byte_counts.begin(), strip_byte_counts.end(), 0U));
offset = strip_offsets[0];
} else if (tiff_directory.Has(kPanaTagJpegImage)) {
if (!tiff_directory.GetOffsetAndLength(
Expand Down Expand Up @@ -715,14 +714,14 @@ bool TiffParser::Parse(const TagSet& desired_tags,
return true;
}

bool TiffParser::ParseIfd(const std::uint32_t offset_to_ifd,
bool TiffParser::ParseIfd(const std::uint32_t ifd_offset,
const TagSet& desired_tags,
const std::uint16_t max_number_ifds,
IfdVector* tiff_directory) {
std::uint32_t next_ifd_offset;
TiffDirectory tiff_ifd(static_cast<Endian>(endian_));
if (!ParseDirectory(tiff_offset_, offset_to_ifd, endian_, desired_tags,
stream_, &tiff_ifd, &next_ifd_offset) ||
if (!ParseDirectory(tiff_offset_, ifd_offset, endian_, desired_tags, stream_,
&tiff_ifd, &next_ifd_offset) ||
!ParseSubIfds(tiff_offset_, desired_tags, max_number_ifds, endian_,
stream_, &tiff_ifd)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/tiff_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class TiffParser {
// Runs over the Tiff IFD, Exif IFD and subIFDs to get the preview image data.
// Returns false if something with the Tiff tags is wrong.
bool GetPreviewImageData(const TiffContent& tiff_content,
PreviewImageData* image_metadata);
PreviewImageData* preview_image_data);

// Returns false if called more that once or something with the Tiff data is
// wrong.
Expand Down