diff options
-rw-r--r-- | BUILD.gn | 6 | ||||
-rw-r--r-- | DEPS | 1 | ||||
-rw-r--r-- | include/codec/SkCodec.h | 22 | ||||
-rw-r--r-- | include/codec/SkEncodedOrigin.h | 23 | ||||
-rw-r--r-- | include/encode/SkJpegEncoder.h | 10 | ||||
-rw-r--r-- | src/codec/SkCodec.cpp | 5 | ||||
-rw-r--r-- | src/codec/SkCodecImageGenerator.cpp | 24 | ||||
-rw-r--r-- | src/codec/SkJpegCodec.cpp | 16 | ||||
-rw-r--r-- | src/codec/SkJpegCodec.h | 2 | ||||
-rw-r--r-- | src/core/SkPixmapPriv.h | 4 | ||||
-rw-r--r-- | src/images/SkJpegEncoder.cpp | 39 | ||||
-rw-r--r-- | tests/ExifTest.cpp | 49 | ||||
-rw-r--r-- | third_party/libexif/BUILD.gn | 47 |
13 files changed, 45 insertions, 203 deletions
@@ -23,7 +23,6 @@ declare_args() { skia_use_freetype = is_android || is_fuchsia || is_linux skia_use_gdi = false skia_use_icu = !is_fuchsia && !is_ios && !is_win # TODO: Windows - skia_use_libexif = !is_win # TODO: Windows skia_use_libjpeg_turbo = true skia_use_libpng = true skia_use_libwebp = !is_fuchsia @@ -611,11 +610,6 @@ optional("jpeg") { "src/images/SkJPEGWriteUtility.cpp", "src/images/SkJpegEncoder.cpp", ] - - if (skia_use_libexif) { - public_defines += [ "SK_HAS_EXIF_LIBRARY" ] - deps += [ "//third_party/libexif" ] - } } optional("pdf") { @@ -12,7 +12,6 @@ deps = { "third_party/externals/icu" : "https://chromium.googlesource.com/chromium/deps/icu.git@ec9c1133693148470ffe2e5e53576998e3650c1d", "third_party/externals/imgui" : "https://github.com/ocornut/imgui.git@6384eee34f08cb7eab8d835043e1738e4adcdf75", "third_party/externals/jsoncpp" : "https://chromium.googlesource.com/external/github.com/open-source-parsers/jsoncpp.git@1.0.0", - "third_party/externals/libexif" : "https://android.googlesource.com/platform/external/libexif@60e63383329bdf3018696af6c9a1914e4ff0a920", "third_party/externals/libjpeg-turbo" : "https://skia.googlesource.com/third_party/libjpeg-turbo.git@6de58e0d28014caf2fc1370145f22fd6d65f63e3", "third_party/externals/libpng" : "https://skia.googlesource.com/third_party/libpng.git@v1.6.33", "third_party/externals/libwebp" : "https://chromium.googlesource.com/webm/libwebp.git@v0.6.0", diff --git a/include/codec/SkCodec.h b/include/codec/SkCodec.h index d3035a7a71..6e9c8280b9 100644 --- a/include/codec/SkCodec.h +++ b/include/codec/SkCodec.h @@ -14,7 +14,6 @@ #include "SkColorSpaceXform.h" #include "SkEncodedImageFormat.h" #include "SkEncodedInfo.h" -#include "SkEncodedOrigin.h" #include "SkImageInfo.h" #include "SkPixmap.h" #include "SkSize.h" @@ -171,11 +170,24 @@ public: const SkEncodedInfo& getEncodedInfo() const { return fEncodedInfo; } + enum Origin { + kTopLeft_Origin = 1, // Default + kTopRight_Origin = 2, // Reflected across y-axis + kBottomRight_Origin = 3, // Rotated 180 + kBottomLeft_Origin = 4, // Reflected across x-axis + kLeftTop_Origin = 5, // Reflected across x-axis, Rotated 90 CCW + kRightTop_Origin = 6, // Rotated 90 CW + kRightBottom_Origin = 7, // Reflected across x-axis, Rotated 90 CW + kLeftBottom_Origin = 8, // Rotated 90 CCW + kDefault_Origin = kTopLeft_Origin, + kLast_Origin = kLeftBottom_Origin, + }; + /** * Returns the image orientation stored in the EXIF data. * If there is no EXIF data, or if we cannot read the EXIF data, returns kTopLeft. */ - SkEncodedOrigin getOrigin() const { return fOrigin; } + Origin getOrigin() const { return fOrigin; } /** * Return a size that approximately supports the desired scale factor. @@ -670,7 +682,7 @@ protected: XformFormat srcFormat, std::unique_ptr<SkStream>, sk_sp<SkColorSpace>, - SkEncodedOrigin = kTopLeft_SkEncodedOrigin); + Origin = kTopLeft_Origin); /** * Allows the subclass to set the recommended SkImageInfo @@ -679,7 +691,7 @@ protected: const SkImageInfo&, XformFormat srcFormat, std::unique_ptr<SkStream>, - SkEncodedOrigin = kTopLeft_SkEncodedOrigin); + Origin = kTopLeft_Origin); virtual SkISize onGetScaledDimensions(float /*desiredScale*/) const { // By default, scaling is not supported. @@ -829,7 +841,7 @@ private: const XformFormat fSrcXformFormat; std::unique_ptr<SkStream> fStream; bool fNeedsRewind; - const SkEncodedOrigin fOrigin; + const Origin fOrigin; SkImageInfo fDstInfo; Options fOptions; diff --git a/include/codec/SkEncodedOrigin.h b/include/codec/SkEncodedOrigin.h deleted file mode 100644 index 622ade1555..0000000000 --- a/include/codec/SkEncodedOrigin.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkEncodedOrigin_DEFINED -#define SkEncodedOrigin_DEFINED -// These values match the orientation www.exif.org/Exif2-2.PDF. -enum SkEncodedOrigin { - kTopLeft_SkEncodedOrigin = 1, // Default - kTopRight_SkEncodedOrigin = 2, // Reflected across y-axis - kBottomRight_SkEncodedOrigin = 3, // Rotated 180 - kBottomLeft_SkEncodedOrigin = 4, // Reflected across x-axis - kLeftTop_SkEncodedOrigin = 5, // Reflected across x-axis, Rotated 90 CCW - kRightTop_SkEncodedOrigin = 6, // Rotated 90 CW - kRightBottom_SkEncodedOrigin = 7, // Reflected across x-axis, Rotated 90 CW - kLeftBottom_SkEncodedOrigin = 8, // Rotated 90 CCW - kDefault_SkEncodedOrigin = kTopLeft_SkEncodedOrigin, - kLast_SkEncodedOrigin = kLeftBottom_SkEncodedOrigin, -}; -#endif // SkEncodedOrigin_DEFINED diff --git a/include/encode/SkJpegEncoder.h b/include/encode/SkJpegEncoder.h index a094e3fb9c..fd7c204161 100644 --- a/include/encode/SkJpegEncoder.h +++ b/include/encode/SkJpegEncoder.h @@ -9,9 +9,6 @@ #define SkJpegEncoder_DEFINED #include "SkEncoder.h" -#ifdef SK_HAS_EXIF_LIBRARY -#include "SkEncodedOrigin.h" -#endif class SkJpegEncoderMgr; class SkWStream; @@ -65,13 +62,6 @@ public: */ AlphaOption fAlphaOption = AlphaOption::kIgnore; SkTransferFunctionBehavior fBlendBehavior = SkTransferFunctionBehavior::kRespect; - -#ifdef SK_HAS_EXIF_LIBRARY - /** - * Origin to be written to EXIF, if anything other than the default. - */ - SkEncodedOrigin fOrigin = kDefault_SkEncodedOrigin; -#endif }; /** diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp index 59978c6fdf..c3d99f2793 100644 --- a/src/codec/SkCodec.cpp +++ b/src/codec/SkCodec.cpp @@ -128,7 +128,7 @@ std::unique_ptr<SkCodec> SkCodec::MakeFromData(sk_sp<SkData> data, SkPngChunkRea SkCodec::SkCodec(int width, int height, const SkEncodedInfo& info, XformFormat srcFormat, std::unique_ptr<SkStream> stream, - sk_sp<SkColorSpace> colorSpace, SkEncodedOrigin origin) + sk_sp<SkColorSpace> colorSpace, Origin origin) : fEncodedInfo(info) , fSrcInfo(info.makeImageInfo(width, height, std::move(colorSpace))) , fSrcXformFormat(srcFormat) @@ -142,8 +142,7 @@ SkCodec::SkCodec(int width, int height, const SkEncodedInfo& info, {} SkCodec::SkCodec(const SkEncodedInfo& info, const SkImageInfo& imageInfo, - XformFormat srcFormat, std::unique_ptr<SkStream> stream, - SkEncodedOrigin origin) + XformFormat srcFormat, std::unique_ptr<SkStream> stream, Origin origin) : fEncodedInfo(info) , fSrcInfo(imageInfo) , fSrcXformFormat(srcFormat) diff --git a/src/codec/SkCodecImageGenerator.cpp b/src/codec/SkCodecImageGenerator.cpp index 741c8e393d..e8d7d3038a 100644 --- a/src/codec/SkCodecImageGenerator.cpp +++ b/src/codec/SkCodecImageGenerator.cpp @@ -15,23 +15,23 @@ #define kSwapXY SkPixmapPriv::kSwapXY const uint8_t gOrientationFlags[] = { - 0, // kTopLeft_SkEncodedOrigin - kMirrorX, // kTopRight_SkEncodedOrigin - kMirrorX | kMirrorY, // kBottomRight_SkEncodedOrigin - kMirrorY, // kBottomLeft_SkEncodedOrigin - kSwapXY, // kLeftTop_SkEncodedOrigin - kMirrorX | kSwapXY, // kRightTop_SkEncodedOrigin - kMirrorX | kMirrorY | kSwapXY, // kRightBottom_SkEncodedOrigin - kMirrorY | kSwapXY, // kLeftBottom_SkEncodedOrigin + 0, // kTopLeft_Origin + kMirrorX, // kTopRight_Origin + kMirrorX | kMirrorY, // kBottomRight_Origin + kMirrorY, // kBottomLeft_Origin + kSwapXY, // kLeftTop_Origin + kMirrorX | kSwapXY, // kRightTop_Origin + kMirrorX | kMirrorY | kSwapXY, // kRightBottom_Origin + kMirrorY | kSwapXY, // kLeftBottom_Origin }; -SkPixmapPriv::OrientFlags SkPixmapPriv::OriginToOrient(SkEncodedOrigin o) { +SkPixmapPriv::OrientFlags SkPixmapPriv::OriginToOrient(SkCodec::Origin o) { unsigned io = static_cast<int>(o) - 1; SkASSERT(io < SK_ARRAY_COUNT(gOrientationFlags)); return static_cast<SkPixmapPriv::OrientFlags>(gOrientationFlags[io]); } -static bool should_swap_width_height(SkEncodedOrigin o) { +static bool should_swap_width_height(SkCodec::Origin o) { return SkToBool(SkPixmapPriv::OriginToOrient(o) & kSwapXY); } @@ -73,12 +73,12 @@ SkData* SkCodecImageGenerator::onRefEncodedData() { bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& requestInfo, void* requestPixels, size_t requestRowBytes, const Options& opts) { - const auto origin = fCodec->getOrigin(); + const SkCodec::Origin origin = fCodec->getOrigin(); const SkPixmap request(requestInfo, requestPixels, requestRowBytes); const SkPixmap* codecMap = &request; SkAutoPixmapStorage storage; // used if we have to post-orient the output from the codec - if (origin != kTopLeft_SkEncodedOrigin) { + if (origin != SkCodec::kTopLeft_Origin) { SkImageInfo info = requestInfo; if (should_swap_width_height(origin)) { info = swap_width_height(info); diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp index 062f05bd01..be5c9f7942 100644 --- a/src/codec/SkJpegCodec.cpp +++ b/src/codec/SkJpegCodec.cpp @@ -45,7 +45,7 @@ static uint32_t get_endian_int(const uint8_t* data, bool littleEndian) { const uint32_t kExifHeaderSize = 14; const uint32_t kExifMarker = JPEG_APP0 + 1; -static bool is_orientation_marker(jpeg_marker_struct* marker, SkEncodedOrigin* orientation) { +static bool is_orientation_marker(jpeg_marker_struct* marker, SkCodec::Origin* orientation) { if (kExifMarker != marker->marker || marker->data_length < kExifHeaderSize) { return false; } @@ -87,8 +87,8 @@ static bool is_orientation_marker(jpeg_marker_struct* marker, SkEncodedOrigin* o uint32_t count = get_endian_int(data + 4, littleEndian); if (kOriginTag == tag && kOriginType == type && 1 == count) { uint16_t val = get_endian_short(data + 8, littleEndian); - if (0 < val && val <= kLast_SkEncodedOrigin) { - *orientation = (SkEncodedOrigin) val; + if (0 < val && val <= SkCodec::kLast_Origin) { + *orientation = (SkCodec::Origin) val; return true; } } @@ -97,15 +97,15 @@ static bool is_orientation_marker(jpeg_marker_struct* marker, SkEncodedOrigin* o return false; } -static SkEncodedOrigin get_exif_orientation(jpeg_decompress_struct* dinfo) { - SkEncodedOrigin orientation; +static SkCodec::Origin get_exif_orientation(jpeg_decompress_struct* dinfo) { + SkCodec::Origin orientation; for (jpeg_marker_struct* marker = dinfo->marker_list; marker; marker = marker->next) { if (is_orientation_marker(marker, &orientation)) { return orientation; } } - return kDefault_SkEncodedOrigin; + return SkCodec::kDefault_Origin; } static bool is_icc_marker(jpeg_marker_struct* marker) { @@ -227,7 +227,7 @@ SkCodec::Result SkJpegCodec::ReadHeader(SkStream* stream, SkCodec** codecOut, // Create image info object and the codec SkEncodedInfo info = SkEncodedInfo::Make(color, SkEncodedInfo::kOpaque_Alpha, 8); - SkEncodedOrigin orientation = get_exif_orientation(decoderMgr->dinfo()); + Origin orientation = get_exif_orientation(decoderMgr->dinfo()); sk_sp<SkData> iccData = get_icc_profile(decoderMgr->dinfo()); sk_sp<SkColorSpace> colorSpace = nullptr; if (iccData) { @@ -284,7 +284,7 @@ std::unique_ptr<SkCodec> SkJpegCodec::MakeFromStream(std::unique_ptr<SkStream> s SkJpegCodec::SkJpegCodec(int width, int height, const SkEncodedInfo& info, std::unique_ptr<SkStream> stream, JpegDecoderMgr* decoderMgr, - sk_sp<SkColorSpace> colorSpace, SkEncodedOrigin origin) + sk_sp<SkColorSpace> colorSpace, Origin origin) : INHERITED(width, height, info, SkColorSpaceXform::kRGBA_8888_ColorFormat, std::move(stream), std::move(colorSpace), origin) , fDecoderMgr(decoderMgr) diff --git a/src/codec/SkJpegCodec.h b/src/codec/SkJpegCodec.h index 41814d2ead..fd8ee63d6c 100644 --- a/src/codec/SkJpegCodec.h +++ b/src/codec/SkJpegCodec.h @@ -107,7 +107,7 @@ private: * takes ownership */ SkJpegCodec(int width, int height, const SkEncodedInfo& info, std::unique_ptr<SkStream> stream, - JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, SkEncodedOrigin origin); + JpegDecoderMgr* decoderMgr, sk_sp<SkColorSpace> colorSpace, Origin origin); /* * Checks if the conversion between the input image and the requested output diff --git a/src/core/SkPixmapPriv.h b/src/core/SkPixmapPriv.h index 1d677fdc46..dfc9ce2dd0 100644 --- a/src/core/SkPixmapPriv.h +++ b/src/core/SkPixmapPriv.h @@ -9,7 +9,7 @@ #define SkPixmapPriv_DEFINED #include "SkPixmap.h" -#include "SkEncodedOrigin.h" +#include "SkCodec.h" class SkPixmapPriv { public: @@ -20,7 +20,7 @@ public: kSwapXY = 1 << 2, }; - static OrientFlags OriginToOrient(SkEncodedOrigin); + static OrientFlags OriginToOrient(SkCodec::Origin); /** * Copy the pixels in this pixmap into dst, applying the orientation transformations specified diff --git a/src/images/SkJpegEncoder.cpp b/src/images/SkJpegEncoder.cpp index 3f818286a1..9fade2449a 100644 --- a/src/images/SkJpegEncoder.cpp +++ b/src/images/SkJpegEncoder.cpp @@ -11,7 +11,6 @@ #include "SkColorData.h" #include "SkColorSpace_Base.h" -#include "SkEncodedOrigin.h" #include "SkImageEncoderFns.h" #include "SkImageInfoPriv.h" #include "SkJpegEncoder.h" @@ -19,12 +18,6 @@ #include "SkStream.h" #include "SkTemplates.h" -#ifdef SK_HAS_EXIF_LIBRARY -#include "libexif/exif-byte-order.h" -#include "libexif/exif-data.h" -#include "libexif/exif-format.h" -#endif - #include <stdio.h> extern "C" { @@ -220,38 +213,6 @@ std::unique_ptr<SkEncoder> SkJpegEncoder::Make(SkWStream* dst, const SkPixmap& s jpeg_write_marker(encoderMgr->cinfo(), kICCMarker, markerData->bytes(), markerData->size()); } -#ifdef SK_HAS_EXIF_LIBRARY - if (options.fOrigin != kDefault_SkEncodedOrigin) { - // Create ExifData. - const auto kByteOrder = EXIF_BYTE_ORDER_INTEL; - SkAutoTCallVProc<ExifData, exif_data_unref> exif(exif_data_new()); - exif_data_set_option(exif.get(), EXIF_DATA_OPTION_FOLLOW_SPECIFICATION); - exif_data_set_data_type(exif.get(), EXIF_DATA_TYPE_COMPRESSED); - exif_data_set_byte_order(exif.get(), kByteOrder); - exif_data_fix(exif.get()); - - // Create entry for rotation. - SkAutoTCallVProc<ExifMem, exif_mem_unref> mem(exif_mem_new_default()); - SkAutoTCallVProc<ExifEntry, exif_entry_unref> entry(exif_entry_new_mem(mem)); - size_t size = exif_format_get_size(EXIF_FORMAT_SHORT); - entry->data = reinterpret_cast<unsigned char*>(exif_mem_alloc(mem, size)); - entry->size = size; - entry->tag = EXIF_TAG_ORIENTATION; - entry->components = 1; - entry->format = EXIF_FORMAT_SHORT; - exif_content_add_entry(exif->ifd[EXIF_IFD_0], entry); - exif_set_short(entry->data, kByteOrder, (ExifShort) options.fOrigin); - - // Serialize the data. - unsigned char* exif_data; - unsigned int exif_data_len; - exif_data_save_data(exif.get(), &exif_data, &exif_data_len); - const uint32_t kExifMarker = JPEG_APP0 + 1; - jpeg_write_marker(encoderMgr->cinfo(), kExifMarker, exif_data, exif_data_len); - sk_free(exif_data); - } -#endif - return std::unique_ptr<SkJpegEncoder>(new SkJpegEncoder(std::move(encoderMgr), src)); } diff --git a/tests/ExifTest.cpp b/tests/ExifTest.cpp index f2eec7a98e..181f0f9f04 100644 --- a/tests/ExifTest.cpp +++ b/tests/ExifTest.cpp @@ -6,12 +6,7 @@ */ #include "Resources.h" -#include "SkBitmap.h" #include "SkCodec.h" -#include "SkColor.h" -#include "SkImageInfo.h" -#include "SkJpegEncoder.h" -#include "SkStream.h" #include "Test.h" DEF_TEST(ExifOrientation, r) { @@ -23,49 +18,11 @@ DEF_TEST(ExifOrientation, r) { 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); + SkCodec::Origin origin = codec->getOrigin(); + REPORTER_ASSERT(r, SkCodec::kTopRight_Origin == origin); codec = SkCodec::MakeFromStream(GetResourceAsStream("mandrill_512_q075.jpg")); REPORTER_ASSERT(r, nullptr != codec); origin = codec->getOrigin(); - REPORTER_ASSERT(r, kTopLeft_SkEncodedOrigin == origin); + REPORTER_ASSERT(r, SkCodec::kTopLeft_Origin == origin); } - -#ifdef SK_HAS_EXIF_LIBRARY -DEF_TEST(ExifWriteOrientation, r) { - SkBitmap bm; - bm.allocPixels(SkImageInfo::MakeN32Premul(100, 100)); - bm.eraseColor(SK_ColorBLUE); - SkPixmap pm; - if (!bm.peekPixels(&pm)) { - ERRORF(r, "failed to peek pixels"); - return; - } - for (auto o : { kTopLeft_SkEncodedOrigin, - kTopRight_SkEncodedOrigin, - kBottomRight_SkEncodedOrigin, - kBottomLeft_SkEncodedOrigin, - kLeftTop_SkEncodedOrigin, - kRightTop_SkEncodedOrigin, - kRightBottom_SkEncodedOrigin, - kLeftBottom_SkEncodedOrigin }) { - SkDynamicMemoryWStream stream; - SkJpegEncoder::Options options; - options.fOrigin = o; - if (!SkJpegEncoder::Encode(&stream, pm, options)) { - ERRORF(r, "Failed to encode with orientation %i", o); - return; - } - - auto data = stream.detachAsData(); - auto codec = SkCodec::MakeFromData(std::move(data)); - if (!codec) { - ERRORF(r, "Failed to create a codec with orientation %i", o); - return; - } - - REPORTER_ASSERT(r, codec->getOrigin() == o); - } -} -#endif diff --git a/third_party/libexif/BUILD.gn b/third_party/libexif/BUILD.gn deleted file mode 100644 index 9bd6c72b28..0000000000 --- a/third_party/libexif/BUILD.gn +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2017 Google Inc. -# -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -declare_args() { - skia_use_system_exif = is_official_build -} - -import("../third_party.gni") - -if (skia_use_system_exif) { - system("libexif") { - libs = [ "exif" ] - } -} else { - third_party("libexif") { - public_include_dirs = [ "../externals/libexif" ] - - sources = [ - "../externals/libexif/libexif/canon/exif-mnote-data-canon.c", - "../externals/libexif/libexif/canon/mnote-canon-entry.c", - "../externals/libexif/libexif/canon/mnote-canon-tag.c", - "../externals/libexif/libexif/exif-byte-order.c", - "../externals/libexif/libexif/exif-content.c", - "../externals/libexif/libexif/exif-data.c", - "../externals/libexif/libexif/exif-entry.c", - "../externals/libexif/libexif/exif-format.c", - "../externals/libexif/libexif/exif-ifd.c", - "../externals/libexif/libexif/exif-loader.c", - "../externals/libexif/libexif/exif-log.c", - "../externals/libexif/libexif/exif-mem.c", - "../externals/libexif/libexif/exif-mnote-data.c", - "../externals/libexif/libexif/exif-tag.c", - "../externals/libexif/libexif/exif-utils.c", - "../externals/libexif/libexif/fuji/exif-mnote-data-fuji.c", - "../externals/libexif/libexif/fuji/mnote-fuji-entry.c", - "../externals/libexif/libexif/fuji/mnote-fuji-tag.c", - "../externals/libexif/libexif/olympus/exif-mnote-data-olympus.c", - "../externals/libexif/libexif/olympus/mnote-olympus-entry.c", - "../externals/libexif/libexif/olympus/mnote-olympus-tag.c", - "../externals/libexif/libexif/pentax/exif-mnote-data-pentax.c", - "../externals/libexif/libexif/pentax/mnote-pentax-entry.c", - "../externals/libexif/libexif/pentax/mnote-pentax-tag.c", - ] - } -} |