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