aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/picture_utils.cpp
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-06-09 09:32:24 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-06-09 14:18:12 +0000
commit39afa1226f71d09bbdb21cc3c86cb23539d8311b (patch)
tree1843db3d4e18ddea8256f85f39713db3aedd0b9b /tools/picture_utils.cpp
parenteb86b7094755a5fc1e49d22b4c5323f372344d61 (diff)
fix f16 -> sRGB in encode_bitmap_for_png()
The existing logic looks wrong to me: - clamp premul to [0,1] - unpremul, ignoring zero alpha It seems like we should do: - unpremul, avoiding any divide by zero - clamp unpremul to [0,1] Am I misunderstanding this or has this just always been wrong? Change-Id: I9636b9566c746bc05371e1e660f4e59dde16827b Reviewed-on: https://skia-review.googlesource.com/19264 Reviewed-by: Matt Sarett <msarett@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'tools/picture_utils.cpp')
-rw-r--r--tools/picture_utils.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/tools/picture_utils.cpp b/tools/picture_utils.cpp
index bd32f1938e..db245538d4 100644
--- a/tools/picture_utils.cpp
+++ b/tools/picture_utils.cpp
@@ -113,10 +113,11 @@ namespace sk_tools {
SkHalfToFloat(static_cast<SkHalf>(px[i] >> (1 * 16))),
SkHalfToFloat(static_cast<SkHalf>(px[i] >> (2 * 16))),
SkHalfToFloat(static_cast<SkHalf>(px[i] >> (3 * 16))));
- fs = Sk4f::Max(0.0f, Sk4f::Min(fs, 1.0f)); // Clamp
- float invA = 1.0f / fs[3];
- fs = fs * Sk4f(invA, invA, invA, 1); // Unpremultiply.
- rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes.
+ if (fs[3]) { // Unpremultiply.
+ fs *= Sk4f(1/fs[3], 1/fs[3], 1/fs[3], 1);
+ }
+ fs = Sk4f::Max(0.0f, Sk4f::Min(fs, 1.0f)); // Clamp to [0,1].
+ rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes.
}
} else {