skia2/tests/ExifTest.cpp
Matthew Leibowitz 07055b5e25 Parse out the orientation in the SubIFD of EXIF
Orientation information is sometimes stored in
the SubIFD section of EXIF, so read that. This is
just a matter of searching for the SubIFD offset
value in the EXIF tags and then parsing the
values from there onwards. The data format is
the same as the EXIF data.

The images are not under any copyright as I made
them up locally specifically for these tests.

Bug: skia:10799

Change-Id: I5384ffc1c4a9a0c7d3fc8510ef4da2f278cb8b97
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/323217
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
2020-10-12 13:50:27 +00:00

47 lines
1.6 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/codec/SkCodec.h"
#include "tests/Test.h"
#include "tools/Resources.h"
DEF_TEST(ExifOrientation, r) {
std::unique_ptr<SkStream> stream(GetResourceAsStream("images/exif-orientation-2-ur.jpg"));
REPORTER_ASSERT(r, nullptr != stream);
if (!stream) {
return;
}
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
REPORTER_ASSERT(r, nullptr != codec);
SkEncodedOrigin origin = codec->getOrigin();
REPORTER_ASSERT(r, kTopRight_SkEncodedOrigin == origin);
codec = SkCodec::MakeFromStream(GetResourceAsStream("images/mandrill_512_q075.jpg"));
REPORTER_ASSERT(r, nullptr != codec);
origin = codec->getOrigin();
REPORTER_ASSERT(r, kTopLeft_SkEncodedOrigin == origin);
}
DEF_TEST(ExifOrientationInExif, r) {
std::unique_ptr<SkStream> stream(GetResourceAsStream("images/orientation/exif.jpg"));
std::unique_ptr<SkCodec> codec = SkCodec::MakeFromStream(std::move(stream));
REPORTER_ASSERT(r, nullptr != codec);
SkEncodedOrigin origin = codec->getOrigin();
REPORTER_ASSERT(r, kLeftBottom_SkEncodedOrigin == origin);
}
DEF_TEST(ExifOrientationInSubIFD, r) {
std::unique_ptr<SkStream> stream(GetResourceAsStream("images/orientation/subifd.jpg"));
std::unique_ptr<SkCodec> codec = SkCodec::MakeFromStream(std::move(stream));
REPORTER_ASSERT(r, nullptr != codec);
SkEncodedOrigin origin = codec->getOrigin();
REPORTER_ASSERT(r, kLeftBottom_SkEncodedOrigin == origin);
}