From 3785471ff641b7ec4218a32fcf76363b9ac81bab Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Tue, 26 Jun 2018 11:43:06 -0400 Subject: basic first pass at RGBA F32 support Draws basically the same as f16. The existing load_f32, load_f32_dst, and store_f32 stages all had the same bug that we'd never noticed because dy was always 0 until now. Change-Id: Ibbd393fa1acc5df414be4cdef0f5a9d11dcccdb3 Reviewed-on: https://skia-review.googlesource.com/137585 Commit-Queue: Mike Klein Reviewed-by: Brian Osman Reviewed-by: Mike Reed --- src/images/SkImageEncoderFns.h | 36 +++++++++++++++++++++++++++++++++++- src/images/SkPngEncoder.cpp | 12 ++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) (limited to 'src/images') diff --git a/src/images/SkImageEncoderFns.h b/src/images/SkImageEncoderFns.h index d8d1c64bb8..6bf0081b26 100644 --- a/src/images/SkImageEncoderFns.h +++ b/src/images/SkImageEncoderFns.h @@ -410,6 +410,39 @@ static inline void transform_scanline_F16_to_premul_8888(char* SK_RESTRICT dst, p.run(0,0, width,1); } +/** + * Transform from kRGBA_F32 to 8-bytes-per-pixel RGBA. + */ +static inline void transform_scanline_F32(char* SK_RESTRICT dst, const char* SK_RESTRICT src, + int width, int, const SkPMColor*) { + SkJumper_MemoryCtx src_ctx = { (void*)src, 0 }, + dst_ctx = { (void*)dst, 0 }; + SkRasterPipeline_<256> p; + p.append(SkRasterPipeline::load_f32, &src_ctx); + p.append(SkRasterPipeline::clamp_0); // F32 values may be out of [0,1] range, so clamp. + p.append(SkRasterPipeline::clamp_1); + p.append(SkRasterPipeline::to_srgb); + p.append(SkRasterPipeline::store_u16_be, &dst_ctx); + p.run(0,0, width,1); +} + +/** + * Transform from kPremul, kRGBA_F32 to 8-bytes-per-pixel RGBA. + */ +static inline void transform_scanline_F32_premul(char* SK_RESTRICT dst, const char* SK_RESTRICT src, + int width, int, const SkPMColor*) { + SkJumper_MemoryCtx src_ctx = { (void*)src, 0 }, + dst_ctx = { (void*)dst, 0 }; + SkRasterPipeline_<256> p; + p.append(SkRasterPipeline::load_f32, &src_ctx); + p.append(SkRasterPipeline::unpremul); + p.append(SkRasterPipeline::clamp_0); // F32 values may be out of [0,1] range, so clamp. + p.append(SkRasterPipeline::clamp_1); + p.append(SkRasterPipeline::to_srgb); + p.append(SkRasterPipeline::store_u16_be, &dst_ctx); + p.run(0,0, width,1); +} + static inline sk_sp icc_from_color_space(const SkImageInfo& info) { SkColorSpace* cs = info.colorSpace(); if (!cs) { @@ -417,7 +450,8 @@ static inline sk_sp icc_from_color_space(const SkImageInfo& info) { } sk_sp owned; - if (kRGBA_F16_SkColorType == info.colorType()) { + if (kRGBA_F16_SkColorType == info.colorType() || + kRGBA_F32_SkColorType == info.colorType()) { owned = cs->makeSRGBGamma(); cs = owned.get(); } diff --git a/src/images/SkPngEncoder.cpp b/src/images/SkPngEncoder.cpp index fffda73fd0..7520b9044d 100644 --- a/src/images/SkPngEncoder.cpp +++ b/src/images/SkPngEncoder.cpp @@ -106,6 +106,7 @@ bool SkPngEncoderMgr::setHeader(const SkImageInfo& srcInfo, const SkPngEncoder:: int bitDepth = 8; switch (srcInfo.colorType()) { case kRGBA_F16_SkColorType: + case kRGBA_F32_SkColorType: SkASSERT(srcInfo.colorSpace()); sigBit.red = 16; sigBit.green = 16; @@ -288,6 +289,17 @@ static transform_scanline_proc choose_proc(const SkImageInfo& info, SkASSERT(false); return nullptr; } + case kRGBA_F32_SkColorType: + switch (info.alphaType()) { + case kOpaque_SkAlphaType: + case kUnpremul_SkAlphaType: + return transform_scanline_F32; + case kPremul_SkAlphaType: + return transform_scanline_F32_premul; + default: + SkASSERT(false); + return nullptr; + } case kRGBA_1010102_SkColorType: switch (info.alphaType()) { case kOpaque_SkAlphaType: -- cgit v1.2.3