From 1da27ef853ae3e701b7f4aae670c21684396dcce Mon Sep 17 00:00:00 2001 From: Matt Sarett Date: Thu, 19 Jan 2017 17:14:07 -0500 Subject: Add F16 support to SkPNGImageEncoder BUG=skia: CQ_INCLUDE_TRYBOTS=skia.primary:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD Change-Id: Ifd221365a7b9f9a4a4fc5382621e0da7189e1148 Reviewed-on: https://skia-review.googlesource.com/6526 Reviewed-by: Mike Klein Reviewed-by: Leon Scroggins Commit-Queue: Matt Sarett --- gm/encode-srgb.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'gm') diff --git a/gm/encode-srgb.cpp b/gm/encode-srgb.cpp index b9fe65bf6a..d4bd782bf2 100644 --- a/gm/encode-srgb.cpp +++ b/gm/encode-srgb.cpp @@ -10,6 +10,7 @@ #include "Resources.h" #include "SkCanvas.h" #include "SkCodec.h" +#include "SkColorSpace_Base.h" #include "SkData.h" #include "SkImageEncoderPriv.h" #include "SkPM4f.h" @@ -24,6 +25,18 @@ static inline int div_round_up(int a, int b) { return (a + b - 1) / b; } +sk_sp fix_for_colortype(sk_sp colorSpace, SkColorType colorType) { + if (kRGBA_F16_SkColorType == colorType) { + if (!colorSpace) { + return SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named); + } + + return as_CSB(colorSpace)->makeLinearGamma(); + } + + return colorSpace; +} + static void make_index8(SkBitmap* bitmap, SkAlphaType alphaType, sk_sp colorSpace) { const SkColor colors[] = { 0x800000FF, 0x8000FF00, 0x80FF0000, 0x80FFFF00, @@ -73,11 +86,13 @@ static void make(SkBitmap* bitmap, SkColorType colorType, SkAlphaType alphaType, return; } - sk_sp data = GetResourceAsData("color_wheel.png"); + const char* resource = (kOpaque_SkAlphaType == alphaType) ? "color_wheel.jpg" + : "color_wheel.png"; + sk_sp data = GetResourceAsData(resource); std::unique_ptr codec(SkCodec::NewFromData(data)); SkImageInfo dstInfo = codec->getInfo().makeColorType(colorType) .makeAlphaType(alphaType) - .makeColorSpace(colorSpace); + .makeColorSpace(fix_for_colortype(colorSpace, colorType)); bitmap->allocPixels(dstInfo); codec->getPixels(dstInfo, bitmap->getPixels(), bitmap->rowBytes()); } @@ -107,12 +122,16 @@ protected: } SkISize onISize() override { - return SkISize::Make(imageWidth * 2, imageHeight * 4); + return SkISize::Make(imageWidth * 2, imageHeight * 9); } void onDraw(SkCanvas* canvas) override { - const SkColorType colorTypes[] = { kN32_SkColorType, kIndex_8_SkColorType, }; - const SkAlphaType alphaTypes[] = { kUnpremul_SkAlphaType, kPremul_SkAlphaType, }; + const SkColorType colorTypes[] = { + kN32_SkColorType, kRGBA_F16_SkColorType, kIndex_8_SkColorType, + }; + const SkAlphaType alphaTypes[] = { + kUnpremul_SkAlphaType, kPremul_SkAlphaType, kOpaque_SkAlphaType, + }; const sk_sp colorSpaces[] = { nullptr, SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named), }; -- cgit v1.2.3