From 0d4ff6c601f2ce404a97068718caad5a2bb3d594 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Tue, 17 Jan 2017 16:10:07 -0500 Subject: 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 Reviewed-by: Brian Salomon Commit-Queue: Brian Osman --- src/image/SkImage.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/image/SkImage.cpp') diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index d2fc8456f3..86d1e195ce 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -409,3 +409,30 @@ void SkImage_unpinAsTexture(const SkImage* image, GrContext* ctx) { SkASSERT(ctx); as_IB(image)->onUnpinAsTexture(ctx); } + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +sk_sp SkImageMakeRasterCopyAndAssignColorSpace(const SkImage* src, + SkColorSpace* colorSpace) { + // Read the pixels out of the source image, with no conversion + SkImageInfo info = as_IB(src)->onImageInfo(); + if (kUnknown_SkColorType == info.colorType()) { + SkDEBUGFAIL("Unexpected color type"); + return nullptr; + } + + size_t rowBytes = info.minRowBytes(); + size_t size = info.getSafeSize(rowBytes); + auto data = SkData::MakeUninitialized(size); + if (!data) { + return nullptr; + } + + SkPixmap pm(info, data->writable_data(), rowBytes); + if (!src->readPixels(pm, 0, 0, SkImage::kDisallow_CachingHint)) { + return nullptr; + } + + // Wrap them in a new image with a different color space + return SkImage::MakeRasterData(info.makeColorSpace(sk_ref_sp(colorSpace)), data, rowBytes); +} -- cgit v1.2.3