Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
decode_png_main.cpp
Go to the documentation of this file.
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
12
13#include <cstdio>
14
15int main(int argc, char** argv) {
16 if (argc != 2) {
17 printf("Usage: %s <name.png>", argv[0]);
18 return 1;
19 }
20
21 std::unique_ptr<SkFILEStream> input = SkFILEStream::Make(argv[1]);
22 if (!input || !input->isValid()) {
23 printf("Cannot open file %s\n", argv[1]);
24 return 1;
25 }
26
28 auto codec = SkPngDecoder::Decode(std::move(input), &result);
29 if (!codec) {
30 printf("Cannot decode file %s as a PNG\n", argv[1]);
31 printf("Result code: %d\n", result);
32 return 1;
33 }
34
35 SkImageInfo info = codec->getInfo();
36 printf("Image is %d by %d pixels.\n", info.width(), info.height());
37
38 return 0;
39}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static std::unique_ptr< SkFILEStream > Make(const char path[])
Definition SkStream.h:314
GAsyncResult * result
char ** argv
Definition library.h:9
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
Definition main.py:1