Commit 37999459 authored by Wan-Teh Chang's avatar Wan-Teh Chang Committed by Commit Bot

Use skcms_AlphaFormat_Unpremul if !has_alpha

If has_alpha is false, pass skcms_AlphaFormat_Unpremul instead of
skcms_AlphaFormat_Opaque to skcms_Transform(). Brian Osman explains in
an email to Peter Kasting:
  If we don't care about the "alpha" data, then using Unpremul is
  (slightly) faster. Unlike Skia, skcms interprets Opaque as
  instructions to *guarantee* that things are treated as opaque. This
  means that we will load the source data, then replace the alpha with
  1.0, and also set it to 1.0 before writing if the dstAlpha is opaque.
  With unpremul src and dst, the alpha is never used, so it just gets
  loaded and stored without any extra work.

After this CL, skcms_AlphaFormat_Opaque is only used in
third_party/skia/tools/HashAndEncode.cpp, and only for srcAlpha.

Change-Id: I38062ca46583ea0586be80e6a69980a1b1e777d3
Bug: 1085550
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212781
Commit-Queue: Wan-Teh Chang <wtc@google.com>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarBrian Osman <brianosman@google.com>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771197}
parent d1f8acc8
...@@ -42,8 +42,8 @@ ColorSpaceGamut GetColorSpaceGamut(const skcms_ICCProfile* color_profile) { ...@@ -42,8 +42,8 @@ ColorSpaceGamut GetColorSpaceGamut(const skcms_ICCProfile* color_profile) {
in[1][1] = 255; in[1][1] = 255;
in[2][2] = 255; in[2][2] = 255;
bool color_converison_successful = skcms_Transform( bool color_converison_successful = skcms_Transform(
in, skcms_PixelFormat_RGB_888, skcms_AlphaFormat_Opaque, color_profile, in, skcms_PixelFormat_RGB_888, skcms_AlphaFormat_Unpremul, color_profile,
out, skcms_PixelFormat_RGB_fff, skcms_AlphaFormat_Opaque, &sc_rgb, 3); out, skcms_PixelFormat_RGB_fff, skcms_AlphaFormat_Unpremul, &sc_rgb, 3);
DCHECK(color_converison_successful); DCHECK(color_converison_successful);
float score = out[0][0] * out[1][1] * out[2][2]; float score = out[0][0] * out[1][1] * out[2][2];
......
...@@ -711,7 +711,7 @@ void PNGImageDecoder::RowAvailable(unsigned char* row_buffer, ...@@ -711,7 +711,7 @@ void PNGImageDecoder::RowAvailable(unsigned char* row_buffer,
// TODO: Apply the xform to the RGB pixels, skipping second pass over // TODO: Apply the xform to the RGB pixels, skipping second pass over
// data. // data.
if (ColorProfileTransform* xform = ColorTransform()) { if (ColorProfileTransform* xform = ColorTransform()) {
skcms_AlphaFormat alpha_format = skcms_AlphaFormat_Opaque; skcms_AlphaFormat alpha_format = skcms_AlphaFormat_Unpremul;
bool color_conversion_successful = bool color_conversion_successful =
skcms_Transform(dst_row, XformColorFormat(), alpha_format, skcms_Transform(dst_row, XformColorFormat(), alpha_format,
xform->SrcProfile(), dst_row, XformColorFormat(), xform->SrcProfile(), dst_row, XformColorFormat(),
...@@ -737,12 +737,10 @@ void PNGImageDecoder::RowAvailable(unsigned char* row_buffer, ...@@ -737,12 +737,10 @@ void PNGImageDecoder::RowAvailable(unsigned char* row_buffer,
auto* dst_profile = xform ? xform->DstProfile() : nullptr; auto* dst_profile = xform ? xform->DstProfile() : nullptr;
auto src_format = has_alpha ? skcms_PixelFormat_RGBA_16161616BE auto src_format = has_alpha ? skcms_PixelFormat_RGBA_16161616BE
: skcms_PixelFormat_RGB_161616BE; : skcms_PixelFormat_RGB_161616BE;
auto src_alpha_format = auto src_alpha_format = skcms_AlphaFormat_Unpremul;
has_alpha ? skcms_AlphaFormat_Unpremul : skcms_AlphaFormat_Opaque; auto dst_alpha_format = (has_alpha && buffer.PremultiplyAlpha())
auto dst_alpha_format = has_alpha ? (buffer.PremultiplyAlpha() ? skcms_AlphaFormat_PremulAsEncoded
? skcms_AlphaFormat_PremulAsEncoded : skcms_AlphaFormat_Unpremul;
: skcms_AlphaFormat_Unpremul)
: skcms_AlphaFormat_Opaque;
bool success = skcms_Transform( bool success = skcms_Transform(
src_ptr, src_format, src_alpha_format, src_profile, dst_row_f16, src_ptr, src_format, src_alpha_format, src_profile, dst_row_f16,
skcms_PixelFormat_RGBA_hhhh, dst_alpha_format, dst_profile, width); skcms_PixelFormat_RGBA_hhhh, dst_alpha_format, dst_profile, width);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment