1 // Copyright 2019 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3
4 #include "src/core/SkOSFile.h"
5 #include "src/utils/SkOSPath.h"
6 #include "tools/flags/CommonFlags.h"
7
CollectImages(CommandLineFlags::StringArray images,SkTArray<SkString> * output)8 bool CollectImages(CommandLineFlags::StringArray images, SkTArray<SkString>* output) {
9 SkASSERT(output);
10
11 static const char* const exts[] = {
12 "bmp",
13 "gif",
14 "jpg",
15 "jpeg",
16 "png",
17 "webp",
18 "ktx",
19 "astc",
20 "wbmp",
21 "ico",
22 #if !defined(SK_BUILD_FOR_WIN)
23 "BMP",
24 "GIF",
25 "JPG",
26 "JPEG",
27 "PNG",
28 "WEBP",
29 "KTX",
30 "ASTC",
31 "WBMP",
32 "ICO",
33 #endif
34 #ifdef SK_HAS_HEIF_LIBRARY
35 "heic",
36 #if !defined(SK_BUILD_FOR_WIN)
37 "HEIC",
38 #endif
39 #endif
40 #ifdef SK_CODEC_DECODES_RAW
41 "arw",
42 "cr2",
43 "dng",
44 "nef",
45 "nrw",
46 "orf",
47 "raf",
48 "rw2",
49 "pef",
50 "srw",
51 #if !defined(SK_BUILD_FOR_WIN)
52 "ARW",
53 "CR2",
54 "DNG",
55 "NEF",
56 "NRW",
57 "ORF",
58 "RAF",
59 "RW2",
60 "PEF",
61 "SRW",
62 #endif
63 #endif
64 };
65
66 for (int i = 0; i < images.count(); ++i) {
67 const char* flag = images[i];
68 if (!sk_exists(flag)) {
69 SkDebugf("%s does not exist!\n", flag);
70 return false;
71 }
72
73 if (sk_isdir(flag)) {
74 // If the value passed in is a directory, add all the images
75 bool foundAnImage = false;
76 for (const char* ext : exts) {
77 SkOSFile::Iter it(flag, ext);
78 SkString file;
79 while (it.next(&file)) {
80 foundAnImage = true;
81 output->push_back() = SkOSPath::Join(flag, file.c_str());
82 }
83 }
84 if (!foundAnImage) {
85 SkDebugf("No supported images found in %s!\n", flag);
86 return false;
87 }
88 } else {
89 // Also add the value if it is a single image
90 output->push_back() = flag;
91 }
92 }
93 return true;
94 }
95