aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Matt Sarett <msarett@google.com>2017-03-22 10:07:50 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-22 15:31:11 +0000
commit73879ebecbe706257ffb9f9b86e9ff668734bfec (patch)
tree85e068c88a70cc2166d5c7210334790bfa79bc56
parent2a65cc0ff16bd597e2d4a190b757573b482f43be (diff)
Improve color type handling in SkImage_Base::makeColorSpace()
Color space xforms with Alpha8 images are no-ops. Other xforms should use 8888 as dst color type. BUG=skia: Change-Id: Iede3d94d23c8f4c3dabdaa5450af7b5bfff8d24f Reviewed-on: https://skia-review.googlesource.com/9996 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Matt Sarett <msarett@google.com>
-rw-r--r--src/image/SkImage.cpp7
-rw-r--r--src/image/SkImage_Raster.cpp13
2 files changed, 12 insertions, 8 deletions
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index fe6369ed35..566bdc092f 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -308,9 +308,12 @@ sk_sp<SkImage> SkImage_Base::makeColorSpace(sk_sp<SkColorSpace> target) const {
return nullptr;
}
- // Be sure to treat nullptr srcs as "equal to" sRGB.
+ // No need to create a new image if:
+ // (1) The color spaces are equal (nullptr is considered to be sRGB).
+ // (2) The color type is kAlpha8.
if ((!this->colorSpace() && target->isSRGB()) ||
- SkColorSpace_Base::EqualsIgnoreFlags(this->colorSpace(), target.get())) {
+ SkColorSpace_Base::EqualsIgnoreFlags(this->colorSpace(), target.get()) ||
+ kAlpha_8_SkColorType == this->onImageInfo().colorType()) {
return sk_ref_sp(const_cast<SkImage_Base*>(this));
}
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index 26f43c7e1f..388c8da196 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -371,13 +371,14 @@ bool SkImage_Raster::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) c
}
sk_sp<SkImage> SkImage_Raster::onMakeColorSpace(sk_sp<SkColorSpace> target) const {
+ // Force the color type of the new image to be kN32_SkColorType.
+ // (1) This means we lose precision on F16 images. This is necessary while this function is
+ // used to pre-transform inputs to a legacy canvas. Legacy canvases do not handle F16.
+ // (2) kIndex8 and kGray8 must be expanded in order perform a color space transformation.
+ // (3) Seems reasonable to expand k565 and k4444. It's nice to avoid these color types for
+ // clients who opt into color space support.
+ SkImageInfo dstInfo = fBitmap.info().makeColorType(kN32_SkColorType).makeColorSpace(target);
SkBitmap dst;
- SkImageInfo dstInfo = fBitmap.info().makeColorSpace(target);
- if (kIndex_8_SkColorType == dstInfo.colorType() ||
- kGray_8_SkColorType == dstInfo.colorType())
- {
- dstInfo = dstInfo.makeColorType(kN32_SkColorType);
- }
dst.allocPixels(dstInfo);
SkPixmap src;