• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef DecodeUtils_DEFINED
9 #define DecodeUtils_DEFINED
10 
11 #include "include/core/SkImage.h"
12 #include "include/core/SkRefCnt.h"
13 #include "tools/Resources.h"
14 
15 class SkBitmap;
16 class SkData;
17 enum SkColorType : int;
18 
19 namespace ToolUtils {
20 bool DecodeDataToBitmap(sk_sp<SkData> data, SkBitmap* dst);
21 bool DecodeDataToBitmapWithColorType(sk_sp<SkData> data, SkBitmap* dst, SkColorType dstCT);
22 
GetResourceAsBitmap(const char * resource,SkBitmap * dst)23 inline bool GetResourceAsBitmap(const char* resource, SkBitmap* dst) {
24     return DecodeDataToBitmap(GetResourceAsData(resource), dst);
25 }
26 
GetResourceAsBitmapWithColortype(const char * resource,SkBitmap * dst,SkColorType dstCT)27 inline bool GetResourceAsBitmapWithColortype(const char* resource, SkBitmap* dst, SkColorType dstCT) {
28     return DecodeDataToBitmapWithColorType(GetResourceAsData(resource), dst, dstCT);
29 }
30 
GetResourceAsImage(const char * resource)31 inline sk_sp<SkImage> GetResourceAsImage(const char* resource) {
32     return SkImages::DeferredFromEncodedData(GetResourceAsData(resource));
33 }
34 
35 }  // namespace ToolUtils
36 
37 #endif
38