Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
use_skresources.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 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
14
15#include <cstdio>
16#include <filesystem>
17
18// bazel run :use_skresources -- $SKIA_HOME/resources
19int main(int argc, char** argv) {
20 if (argc != 2) {
21 printf("Usage: %s [folder]", argv[0]);
22 return 1;
23 }
24
25 SkCodecs::Register(SkJpegDecoder::Decoder());
26 SkCodecs::Register(SkPngDecoder::Decoder());
28
29 // Try to load two arbitrary files in //resources/images
30
31 sk_sp<skresources::ImageAsset> asset = frp->loadImageAsset("images", "baby_tux.png", "");
32 if (!asset) {
33 printf("Could not load baby_tux.png in images subdirectory\n");
34 return 1;
35 }
36 sk_sp<SkImage> tux = asset->getFrameData(0).image;
37 if (!tux) {
38 printf("Could not decode baby_tux.png in images subdirectory\n");
39 return 1;
40 }
41 printf("Baby Tux is %d by %d pixels big\n", tux->width(), tux->height());
42
43 asset = frp->loadImageAsset("images", "CMYK.jpg", "");
44 if (!asset || !asset->getFrameData(0).image) {
45 printf("Could not load/decode CMYK.jpg in images subdirectory\n");
46 return 1;
47 }
48
49 sk_sp<SkImage> cmyk = asset->getFrameData(0).image;
50 if (!cmyk) {
51 printf("Could not decode CMYK.jpg in images subdirectory\n");
52 return 1;
53 }
54 printf("CMYK is %d by %d pixels big\n", cmyk->width(), cmyk->height());
55
56 return 0;
57}
static sk_sp< FileResourceProvider > Make(SkString base_dir, ImageDecodeStrategy=ImageDecodeStrategy::kLazyDecode)
char ** argv
Definition library.h:9
constexpr SkCodecs::Decoder Decoder()
constexpr SkCodecs::Decoder Decoder()
Definition main.py:1