1 /* 2 * Copyright 2023 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "tools/DecodeUtils.h" 9 10 #include "include/core/SkBitmap.h" 11 #include "include/core/SkColorSpace.h" 12 #include "include/core/SkData.h" 13 #include "include/core/SkImageGenerator.h" 14 #include "include/core/SkImageInfo.h" 15 #include "src/image/SkImageGeneratorPriv.h" 16 17 #include <memory> 18 #include <utility> 19 20 namespace ToolUtils { 21 DecodeDataToBitmap(sk_sp<SkData> data,SkBitmap * dst)22bool DecodeDataToBitmap(sk_sp<SkData> data, SkBitmap* dst) { 23 std::unique_ptr<SkImageGenerator> gen(SkImageGenerators::MakeFromEncoded(std::move(data))); 24 return gen && dst->tryAllocPixels(gen->getInfo()) && 25 gen->getPixels( 26 gen->getInfo().makeColorSpace(nullptr), dst->getPixels(), dst->rowBytes()); 27 } 28 29 } // namespace ToolUtils 30