Fix code that relied on readPixels not doing color space conversion
SampleApp doesn't have (can't easily get) an image, so I couldn't use
the new helper function there. It's probably still worth having?
BUG=skia:
Change-Id: I60c208ff958076015a9539359921b9aff68f25c8
Reviewed-on: https://skia-review.googlesource.com/7129
Reviewed-by: Matt Sarett <msarett@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/gm/gamut.cpp b/gm/gamut.cpp
index 21312ce..d513bc6 100644
--- a/gm/gamut.cpp
+++ b/gm/gamut.cpp
@@ -9,6 +9,7 @@
#include "SkColorSpace_Base.h"
#include "SkGradientShader.h"
+#include "SkImagePriv.h"
#include "SkPM4fPriv.h"
#include "SkSurface.h"
@@ -147,13 +148,12 @@
SkASSERT(srgbCS);
SkASSERT(wideCS);
- // Make our two working surfaces (one sRGB, one Adobe)
+ // Make our two working surfaces (one sRGB, one Wide)
SkImageInfo srgbGamutInfo = SkImageInfo::Make(gRectSize, gRectSize, origInfo.colorType(),
kPremul_SkAlphaType, srgbCS);
SkImageInfo wideGamutInfo = SkImageInfo::Make(gRectSize, gRectSize, origInfo.colorType(),
kPremul_SkAlphaType, wideCS);
- // readPixels doesn't do color conversion (yet), so we can use it to see the raw (wide) data
- SkImageInfo dstInfo = srgbGamutInfo.makeColorSpace(nullptr);
+
sk_sp<SkSurface> srgbGamutSurface = canvas->makeSurface(srgbGamutInfo);
sk_sp<SkSurface> wideGamutSurface = canvas->makeSurface(wideGamutInfo);
if (!srgbGamutSurface || !wideGamutSurface) {
@@ -179,16 +179,18 @@
canvas->drawText(renderer->label(), strlen(renderer->label()), x, y + textHeight,
textPaint);
- SkBitmap srgbBitmap;
- srgbBitmap.setInfo(dstInfo);
- srgbGamutCanvas->readPixels(&srgbBitmap, 0, 0);
- canvas->drawBitmap(srgbBitmap, x, y + textHeight + 5);
+ // Re-interpret the off-screen images, so we can see the raw data (eg, Wide gamut squares
+ // will look desaturated, relative to sRGB).
+ auto srgbImage = srgbGamutSurface->makeImageSnapshot();
+ srgbImage = SkImageMakeRasterCopyAndAssignColorSpace(srgbImage.get(),
+ origInfo.colorSpace());
+ canvas->drawImage(srgbImage, x, y + textHeight + 5);
x += (gScalarSize + 1);
- SkBitmap wideBitmap;
- wideBitmap.setInfo(dstInfo);
- wideGamutCanvas->readPixels(&wideBitmap, 0, 0);
- canvas->drawBitmap(wideBitmap, x, y + textHeight + 5);
+ auto wideImage = wideGamutSurface->makeImageSnapshot();
+ wideImage = SkImageMakeRasterCopyAndAssignColorSpace(wideImage.get(),
+ origInfo.colorSpace());
+ canvas->drawImage(wideImage, x, y + textHeight + 5);
x += (gScalarSize + 10);
if (x + (2 * gScalarSize + 1) > gTestWidth) {