Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
decode_everything.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
17#include "include/core/SkData.h"
20
21#include <cstdio>
22#include <memory>
23
24int main(int argc, char** argv) {
25 if (argc != 2) {
26 printf("Usage: %s <name.png>", argv[0]);
27 return 1;
28 }
29
30 std::unique_ptr<SkFILEStream> input = SkFILEStream::Make(argv[1]);
31 if (!input || !input->isValid()) {
32 printf("Cannot open file %s\n", argv[1]);
33 return 1;
34 }
35
36 sk_sp<SkData> data = SkData::MakeFromStream(input.get(), input->getLength());
37
38 std::unique_ptr<SkCodec> codec = nullptr;
39 if (SkBmpDecoder::IsBmp(data->bytes(), data->size())) {
40 codec = SkBmpDecoder::Decode(data, nullptr);
41 } else if (SkGifDecoder::IsGif(data->bytes(), data->size())) {
42 codec = SkGifDecoder::Decode(data, nullptr);
43 } else if (SkIcoDecoder::IsIco(data->bytes(), data->size())) {
44 codec = SkIcoDecoder::Decode(data, nullptr);
45 } else if (SkJpegDecoder::IsJpeg(data->bytes(), data->size())) {
46 codec = SkJpegDecoder::Decode(data, nullptr);
47 } else if (SkJpegxlDecoder::IsJpegxl(data->bytes(), data->size())) {
48 codec = SkJpegxlDecoder::Decode(data, nullptr);
49 } else if (SkPngDecoder::IsPng(data->bytes(), data->size())) {
50 codec = SkPngDecoder::Decode(data, nullptr);
51 } else if (SkWbmpDecoder::IsWbmp(data->bytes(), data->size())) {
52 codec = SkWbmpDecoder::Decode(data, nullptr);
53 } else if (SkWebpDecoder::IsWebp(data->bytes(), data->size())) {
54 codec = SkWebpDecoder::Decode(data, nullptr);
55 } else {
56 printf("Unsupported file format\n");
57 return 1;
58 }
59
60 SkImageInfo info = codec->getInfo();
61 printf("Image is %d by %d pixels.\n", info.width(), info.height());
62
63 return 0;
64}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static sk_sp< SkData > MakeFromStream(SkStream *, size_t size)
Definition SkData.cpp:208
static std::unique_ptr< SkFILEStream > Make(const char path[])
Definition SkStream.h:314
char ** argv
Definition library.h:9
SK_API bool IsBmp(const void *, size_t)
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
SK_API bool IsGif(const void *, size_t)
SK_API bool IsIco(const void *, size_t)
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
SK_API bool IsJpeg(const void *, size_t)
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
SK_API bool IsJpegxl(const void *, size_t)
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
SK_API bool IsPng(const void *, size_t)
SK_API bool IsWbmp(const void *, size_t)
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
SK_API std::unique_ptr< SkCodec > Decode(std::unique_ptr< SkStream >, SkCodec::Result *, SkCodecs::DecodeContext=nullptr)
SK_API bool IsWebp(const void *, size_t)
Definition main.py:1