From 7992da32f02f90e0ac9ab6914eb31676b502eb71 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Fri, 18 Nov 2016 11:28:24 -0500 Subject: Support decoding images to multiple formats, depending on usage Our codec generator will now preserve any asked-for color space, and convert the encoded data to that representation. Cacherator now allows decoding an image to both legacy (nullptr color space), and color-correct formats. In color-correct mode, we choose the best decoded format, based on the original properties, and our backend's capabilities. Preference is given to the native format, when it's already texturable (sRGB 8888 or F16 linear). Otherwise, we prefer linear F16, and fall back to sRGB when that's not an option. Re-land (and fix) of: https://skia-review.googlesource.com/c/4438/ https://skia-review.googlesource.com/c/4796/ BUG=skia:5907 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4838 Change-Id: I20ff972ffe1c7e6535ddc501e2a8ab8c246e4061 Reviewed-on: https://skia-review.googlesource.com/4838 Commit-Queue: Brian Osman Reviewed-by: Matt Sarett --- tools/Resources.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tools/Resources.cpp') diff --git a/tools/Resources.cpp b/tools/Resources.cpp index 3a9bb58c4e..981bfba337 100644 --- a/tools/Resources.cpp +++ b/tools/Resources.cpp @@ -30,7 +30,12 @@ bool GetResourceAsBitmap(const char* resource, SkBitmap* dst) { SkString resourcePath = GetResourcePath(resource); sk_sp resourceData(SkData::MakeFromFileName(resourcePath.c_str())); std::unique_ptr gen(SkImageGenerator::NewFromEncoded(resourceData.get())); - return gen && gen->tryGenerateBitmap(dst); + SkPMColor ctStorage[256]; + sk_sp ctable(new SkColorTable(ctStorage, 256)); + int count = ctable->count(); + return dst->tryAllocPixels(gen->getInfo(), nullptr, ctable.get()) && + gen->getPixels(gen->getInfo().makeColorSpace(nullptr), dst->getPixels(), dst->rowBytes(), + const_cast(ctable->readColors()), &count); } sk_sp GetResourceAsImage(const char* resource) { -- cgit v1.2.3