diff options
author | Hal Canary <halcanary@google.com> | 2018-04-05 16:58:41 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-04-07 14:25:30 +0000 |
commit | 83e0f1b1bb111c99d2f11d382b31caef0af5de10 (patch) | |
tree | 8ed18a789d4f8b72525ccd308af2a08e9ea409ef /src/codec/SkJpegCodec.cpp | |
parent | c7695ff269a6ec7c4420d571d9077f2895166083 (diff) |
SkPDF: smarter Jpeg when libjpeg-turbo is present
The fallback code does not parse the color type for EXIF-only jpegs.
Since these exist in the wild, we need to find out if they are really
standard YUV or greyscale Jpegs and embed them in PDFs if they are.
BUG=chromium:801430
Change-Id: I93eaf8b8fc22b7169b2fce9520e022b72ad0bf81
Reviewed-on: https://skia-review.googlesource.com/118992
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'src/codec/SkJpegCodec.cpp')
-rw-r--r-- | src/codec/SkJpegCodec.cpp | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp index 4f48886be2..2cc7921277 100644 --- a/src/codec/SkJpegCodec.cpp +++ b/src/codec/SkJpegCodec.cpp @@ -5,11 +5,13 @@ * found in the LICENSE file. */ -#include "SkCodec.h" #include "SkJpegCodec.h" -#include "SkJpegDecoderMgr.h" + +#include "SkCodec.h" #include "SkCodecPriv.h" #include "SkColorData.h" +#include "SkJpegDecoderMgr.h" +#include "SkJpegInfo.h" #include "SkStream.h" #include "SkTemplates.h" #include "SkTypes.h" @@ -968,3 +970,42 @@ SkCodec::Result SkJpegCodec::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void return kSuccess; } + +// This function is declared in SkJpegInfo.h, used by SkPDF. +bool SkGetJpegInfo(const void* data, size_t len, + SkISize* size, + SkEncodedInfo::Color* colorType, + SkEncodedOrigin* orientation) { + if (!SkJpegCodec::IsJpeg(data, len)) { + return false; + } + + SkMemoryStream stream(data, len); + JpegDecoderMgr decoderMgr(&stream); + // libjpeg errors will be caught and reported here + skjpeg_error_mgr::AutoPushJmpBuf jmp(decoderMgr.errorMgr()); + if (setjmp(jmp)) { + return false; + } + decoderMgr.init(); + jpeg_decompress_struct* dinfo = decoderMgr.dinfo(); + jpeg_save_markers(dinfo, kExifMarker, 0xFFFF); + jpeg_save_markers(dinfo, kICCMarker, 0xFFFF); + if (JPEG_HEADER_OK != jpeg_read_header(dinfo, true)) { + return false; + } + SkEncodedInfo::Color encodedColorType; + if (!decoderMgr.getEncodedColor(&encodedColorType)) { + return false; // Unable to interpret the color channels as colors. + } + if (colorType) { + *colorType = encodedColorType; + } + if (orientation) { + *orientation = get_exif_orientation(dinfo); + } + if (size) { + *size = {SkToS32(dinfo->image_width), SkToS32(dinfo->image_height)}; + } + return true; +} |