| 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 "include/codec/SkBmpDecoder.h" |
| 9 |
#include "include/codec/SkCodec.h" |
| 10 |
#include "include/codec/SkGifDecoder.h" |
| 11 |
#include "include/codec/SkIcoDecoder.h" |
| 12 |
#include "include/codec/SkJpegDecoder.h" |
| 13 |
#include "include/codec/SkJpegxlDecoder.h" |
| 14 |
#include "include/codec/SkPngDecoder.h" |
| 15 |
#include "include/codec/SkWbmpDecoder.h" |
| 16 |
#include "include/codec/SkWebpDecoder.h" |
| 17 |
#include "include/core/SkData.h" |
| 18 |
#include "include/core/SkImageInfo.h" |
| 19 |
#include "include/core/SkStream.h" |
| 20 |
|
| 21 |
#include <cstdio> |
| 22 |
#include <memory> |
| 23 |
|
| 24 |
int 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 |
} |