Commit 69849a44 authored by Mike Klein's avatar Mike Klein Committed by Commit Bot

port ui/gfx/color_transform to skcms

We're doing some clean up and would like to retract SkColorSpaceXform
from Skia's public API.  It's obsolete now that you can either,

   1) just use Skia's drawing pipeline or readPixels()/writePixels()
      for most of its functionality; or
   2) use the much more flexible skcms interface for fancy features.

In the case of ui/gfx/color_transform, I decided to go with skcms
because it can naturally consume and produce the 3-float TriStim format
this code wants to use.  The old SkColorSpaceXform required two extra
transformations and an allocation, where skcms can do everything in
place natively.

Using draws or readPixels()/writePixels() would have required us to keep
those extra transforms, as they don't (yet?) support RGB_fff pixels.

Change-Id: I70f64c3ad72ebe227ed7a2a1dd7391863a8737e3
Reviewed-on: https://chromium-review.googlesource.com/1196375Reviewed-by: default avatarccameron <ccameron@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587703}
parent cabdc5f1
......@@ -242,6 +242,7 @@ jumbo_component("gfx") {
":selection_bound_sources",
"//base",
"//skia",
"//skia:skcms",
"//third_party/icu",
"//ui/gfx/animation",
"//ui/gfx/codec",
......
......@@ -13,7 +13,7 @@
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkColorSpaceXform.h"
#include "third_party/skia/third_party/skcms/skcms.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/icc_profile.h"
#include "ui/gfx/skia_color_space_util.h"
......@@ -923,39 +923,18 @@ class SkiaColorTransform : public ColorTransformStep {
return false;
}
void Transform(ColorTransform::TriStim* colors, size_t num) const override {
// Transform to SkColors.
std::vector<uint8_t> sk_colors(4 * num);
for (size_t i = 0; i < num; ++i) {
float rgb[3] = {colors[i].x(), colors[i].y(), colors[i].z()};
for (size_t c = 0; c < 3; ++c) {
int value_int = static_cast<int>(255.f * rgb[c] + 0.5f);
value_int = min(value_int, 255);
value_int = max(value_int, 0);
sk_colors[4 * i + c] = value_int;
}
sk_colors[4 * i + 3] = 255;
}
// Perform the transform.
std::unique_ptr<SkColorSpaceXform> xform =
SkColorSpaceXform::New(src_.get(), dst_.get());
DCHECK(xform);
if (!xform)
return;
std::vector<uint8_t> sk_colors_transformed(4 * num);
bool xform_apply_result = xform->apply(
SkColorSpaceXform::kRGBA_8888_ColorFormat, sk_colors_transformed.data(),
SkColorSpaceXform::kRGBA_8888_ColorFormat, sk_colors.data(), num,
kOpaque_SkAlphaType);
DCHECK(xform_apply_result);
sk_colors = sk_colors_transformed;
// Convert back to TriStim.
for (size_t i = 0; i < num; ++i) {
colors[i].set_x(sk_colors[4 * i + 0] / 255.f);
colors[i].set_y(sk_colors[4 * i + 1] / 255.f);
colors[i].set_z(sk_colors[4 * i + 2] / 255.f);
}
// We could do this either using Skia or skcms, but since skcms can handle
// TriStim directly as skcms_PixelFormat_RGB_fff, let's use that.
skcms_ICCProfile src_profile, dst_profile;
src_->toProfile(&src_profile);
dst_->toProfile(&dst_profile);
const skcms_PixelFormat kFFF = skcms_PixelFormat_RGB_fff;
const skcms_AlphaFormat kUPM = skcms_AlphaFormat_Unpremul;
bool xform_result = skcms_Transform(colors, kFFF, kUPM, &src_profile,
colors, kFFF, kUPM, &dst_profile, num);
DCHECK(xform_result);
}
private:
......
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