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/SkCodec.h" 9 #include "include/codec/SkPngDecoder.h" 10 #include "include/core/SkImageInfo.h" 11 #include "include/core/SkStream.h" 12 13 #include <cstdio> 14 main(int argc,char ** argv)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 27 SkCodec::Result result; 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 } 40