diff options
author | Mike Reed <reed@google.com> | 2017-11-30 15:33:04 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-30 21:06:38 +0000 |
commit | d6cb11ee9df514a3a65b313725d3ac3bfd003e7f (patch) | |
tree | f2381b95ecb3fe1368b7021f16783376b8c6ea51 /src/codec | |
parent | 74663e722ea905972e62c59e60cd0cbc97e8435f (diff) |
encode kAlpha_8 as grayalpha with sigbits for gray==1
Bug: skia:
Change-Id: Ib61e8e0f62af92d8746f5e73469002e7804a8447
Reviewed-on: https://skia-review.googlesource.com/78481
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/codec')
-rw-r--r-- | src/codec/SkCodec.cpp | 4 | ||||
-rw-r--r-- | src/codec/SkPngCodec.cpp | 10 | ||||
-rw-r--r-- | src/codec/SkPngPriv.h | 19 | ||||
-rw-r--r-- | src/codec/SkSwizzler.cpp | 13 |
4 files changed, 45 insertions, 1 deletions
diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp index 59978c6fdf..a0f1fb2706 100644 --- a/src/codec/SkCodec.cpp +++ b/src/codec/SkCodec.cpp @@ -175,6 +175,10 @@ bool SkCodec::conversionSupported(const SkImageInfo& dst, SkEncodedInfo::Color s case kGray_8_SkColorType: return SkEncodedInfo::kGray_Color == srcColor && srcIsOpaque && !needs_color_xform(dst, srcCS, false); + case kAlpha_8_SkColorType: + // conceptually we can convert anything into alpha_8, but we haven't actually coded + // all of those other conversions yet, so only return true for the case we have codec. + return fSrcInfo.colorType() == kAlpha_8_SkColorType;; default: return false; } diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp index e9fff97add..9df7bc67e1 100644 --- a/src/codec/SkPngCodec.cpp +++ b/src/codec/SkPngCodec.cpp @@ -14,6 +14,7 @@ #include "SkMath.h" #include "SkOpts.h" #include "SkPngCodec.h" +#include "SkPngPriv.h" #include "SkPoint3.h" #include "SkSize.h" #include "SkStream.h" @@ -935,7 +936,14 @@ void AutoCleanPng::infoCallback(size_t idatLength) { SkEncodedInfo encodedInfo = SkEncodedInfo::Make(color, alpha, bitDepth); SkImageInfo imageInfo = encodedInfo.makeImageInfo(origWidth, origHeight, colorSpace); - if (SkEncodedInfo::kOpaque_Alpha == alpha) { + if (encodedColorType == PNG_COLOR_TYPE_GRAY_ALPHA) { + png_color_8p sigBits; + if (png_get_sBIT(fPng_ptr, fInfo_ptr, &sigBits)) { + if (8 == sigBits->alpha && kGraySigBit_GrayAlphaIsJustAlpha == sigBits->gray) { + imageInfo = imageInfo.makeColorType(kAlpha_8_SkColorType); + } + } + } else if (SkEncodedInfo::kOpaque_Alpha == alpha) { png_color_8p sigBits; if (png_get_sBIT(fPng_ptr, fInfo_ptr, &sigBits)) { if (5 == sigBits->red && 6 == sigBits->green && 5 == sigBits->blue) { diff --git a/src/codec/SkPngPriv.h b/src/codec/SkPngPriv.h new file mode 100644 index 0000000000..3269309075 --- /dev/null +++ b/src/codec/SkPngPriv.h @@ -0,0 +1,19 @@ +/* + * 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 SkPngPriv_DEFINED +#define SkPngPriv_DEFINED + +#include "SkTypes.h" + +// We store kAlpha_8 images as GrayAlpha in png. Our private signal is significant bits for gray. +// If that is set to 1, we assume the gray channel can be ignored, and we output just alpha. +// We tried 0 at first, but png doesn't like a 0 sigbit for a channel it expects, hence we chose 1. + +static constexpr int kGraySigBit_GrayAlphaIsJustAlpha = 1; + +#endif diff --git a/src/codec/SkSwizzler.cpp b/src/codec/SkSwizzler.cpp index 84bb09702b..f3d97af3d8 100644 --- a/src/codec/SkSwizzler.cpp +++ b/src/codec/SkSwizzler.cpp @@ -357,6 +357,16 @@ static void fast_swizzle_grayalpha_to_n32_premul( SkOpts::grayA_to_rgbA((uint32_t*) dst, src + offset, width); } +static void swizzle_grayalpha_to_a8(void* dst, const uint8_t* src, int width, int bpp, + int deltaSrc, int offset, const SkPMColor[]) { + src += offset; + uint8_t* dst8 = (uint8_t*)dst; + for (int x = 0; x < width; ++x) { + dst8[x] = src[1]; // src[0] is gray, ignored + src += deltaSrc; + } +} + // kBGR static void swizzle_bgr_to_565( @@ -906,6 +916,9 @@ SkSwizzler* SkSwizzler::CreateSwizzler(const SkEncodedInfo& encodedInfo, } } break; + case kAlpha_8_SkColorType: + proc = &swizzle_grayalpha_to_a8; + break; default: return nullptr; } |