diff options
author | Leon Scroggins III <scroggo@google.com> | 2017-10-18 11:43:29 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-10-18 17:38:15 +0000 |
commit | 5411a60e0d7370a5d47b5049de845a06fe52e98b (patch) | |
tree | 8995da6236e7f37419a4d3075c35bbdc36049672 /src/images | |
parent | 1d014105ac8e5968b6d260745c807ab45dfee956 (diff) |
Add an Option for orientation on JPEG encodes
Move Origin to its own header so that SkPixmap and SkJpegEncoder need
not depend on SkCodec.
Add libexif, which is already used by Android, and use it to write the
orientation. Write a makefile based on the Android.bp in Android, minus
warnings. (libexif has an LGPL license.)
Add a test that verifies all the orientations work.
Optionally enable writing the orientation (and therefore including
libexif). Chromium does not currently need it, and Android does not
expose an API that would allow using it. Disable on Windows, where we
still have build errors to fix.
Bug: skia:7138
Change-Id: Iaeff44c36aebe0e639666979dc00e1b7594bbeb1
Reviewed-on: https://skia-review.googlesource.com/60721
Commit-Queue: Leon Scroggins <scroggo@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Reviewed-by: Mike Reed <reed@google.com>
Diffstat (limited to 'src/images')
-rw-r--r-- | src/images/SkJpegEncoder.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/images/SkJpegEncoder.cpp b/src/images/SkJpegEncoder.cpp index 9fade2449a..3f818286a1 100644 --- a/src/images/SkJpegEncoder.cpp +++ b/src/images/SkJpegEncoder.cpp @@ -11,6 +11,7 @@ #include "SkColorData.h" #include "SkColorSpace_Base.h" +#include "SkEncodedOrigin.h" #include "SkImageEncoderFns.h" #include "SkImageInfoPriv.h" #include "SkJpegEncoder.h" @@ -18,6 +19,12 @@ #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" { @@ -213,6 +220,38 @@ 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)); } |