Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 4 | #include "src/core/SkOSFile.h" |
| 5 | #include "src/utils/SkOSPath.h" |
| 6 | #include "tools/flags/CommonFlags.h" |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 7 | |
Herb Derby | d7a00839 | 2023-03-02 15:36:17 -0500 | [diff] [blame] | 8 | using namespace skia_private; |
| 9 | |
Kevin Lubick | 8f4e560 | 2021-10-14 09:50:00 -0400 | [diff] [blame] | 10 | namespace CommonFlags { |
John Stiles | 26bf522 | 2023-10-17 10:29:41 -0400 | [diff] [blame] | 11 | bool CollectImages(const CommandLineFlags::StringArray& images, TArray<SkString>* output) { |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 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 | |
Herb Derby | 6a0a4c4 | 2022-09-30 16:43:14 -0400 | [diff] [blame] | 69 | for (int i = 0; i < images.size(); ++i) { |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 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); |
Kevin Lubick | 8f4e560 | 2021-10-14 09:50:00 -0400 | [diff] [blame] | 81 | SkString file; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 82 | while (it.next(&file)) { |
Kevin Lubick | 8f4e560 | 2021-10-14 09:50:00 -0400 | [diff] [blame] | 83 | foundAnImage = true; |
Mike Klein | c6142d8 | 2019-03-25 10:54:59 -0500 | [diff] [blame] | 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 | } |
Kevin Lubick | 8f4e560 | 2021-10-14 09:50:00 -0400 | [diff] [blame] | 98 | |
| 99 | } // namespace CommonFlags |