Kevin Lubick | 8b74188 | 2023-10-06 11:41:38 -0400 | [diff] [blame] | 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 | |
| 22 | bool 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 |