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