Debian Codegraph @

tools/flags/CommonFlagsImages.cpp

raw
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 {
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_CODEC_DECODES_RAW
38 "arw",
39 "cr2",
40 "dng",
41 "nef",
42 "nrw",
43 "orf",
44 "raf",
45 "rw2",
46 "pef",
47 "srw",
48 #if !defined(SK_BUILD_FOR_WIN)
49 "ARW",
50 "CR2",
51 "DNG",
52 "NEF",
53 "NRW",
54 "ORF",
55 "RAF",
56 "RW2",
57 "PEF",
58 "SRW",
59 #endif
60 #endif
61 };
62
63 for (int i = 0; i < images.size(); ++i) {
64 const char* flag = images[i];
65 if (!sk_exists(flag)) {
66 SkDebugf("%s does not exist!\n", flag);
67 return false;
68 }
69
70 if (sk_isdir(flag)) {
71 // If the value passed in is a directory, add all the images
72 bool foundAnImage = false;
73 for (const char* ext : exts) {
74 SkOSFile::Iter it(flag, ext);
75 SkString file;
76 while (it.next(&file)) {
77 foundAnImage = true;
78 output->push_back() = SkOSPath::Join(flag, file.c_str());
79 }
80 }
81 if (!foundAnImage) {
82 SkDebugf("No supported images found in %s!\n", flag);
83 return false;
84 }
85 } else {
86 // Also add the value if it is a single image
87 output->push_back() = flag;
88 }
89 }
90 return true;
91 }
92
93 } // namespace CommonFlags