skia2/tools/flags/CommonFlagsImages.cpp
Mike Klein c6142d855c de-common the rest of the flags
Turns out lots of tools had two copies of many of these flags.

Some GN and .cpp file refactoring to make sure when flags are
present in a binary, they do something in that binary.

I think this finally finishes the flag refrag.

Change-Id: I01488e37ab73a5c4361786863ddb137a7f1095b1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/203420
Commit-Queue: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2019-03-25 17:39:58 +00:00

95 lines
2.1 KiB
C++

// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "CommonFlags.h"
#include "SkOSFile.h"
#include "SkOSPath.h"
bool CollectImages(CommandLineFlags::StringArray images, SkTArray<SkString>* output) {
SkASSERT(output);
static const char* const exts[] = {
"bmp",
"gif",
"jpg",
"jpeg",
"png",
"webp",
"ktx",
"astc",
"wbmp",
"ico",
#if !defined(SK_BUILD_FOR_WIN)
"BMP",
"GIF",
"JPG",
"JPEG",
"PNG",
"WEBP",
"KTX",
"ASTC",
"WBMP",
"ICO",
#endif
#ifdef SK_HAS_HEIF_LIBRARY
"heic",
#if !defined(SK_BUILD_FOR_WIN)
"HEIC",
#endif
#endif
#ifdef SK_CODEC_DECODES_RAW
"arw",
"cr2",
"dng",
"nef",
"nrw",
"orf",
"raf",
"rw2",
"pef",
"srw",
#if !defined(SK_BUILD_FOR_WIN)
"ARW",
"CR2",
"DNG",
"NEF",
"NRW",
"ORF",
"RAF",
"RW2",
"PEF",
"SRW",
#endif
#endif
};
for (int i = 0; i < images.count(); ++i) {
const char* flag = images[i];
if (!sk_exists(flag)) {
SkDebugf("%s does not exist!\n", flag);
return false;
}
if (sk_isdir(flag)) {
// If the value passed in is a directory, add all the images
bool foundAnImage = false;
for (const char* ext : exts) {
SkOSFile::Iter it(flag, ext);
SkString file;
while (it.next(&file)) {
foundAnImage = true;
output->push_back() = SkOSPath::Join(flag, file.c_str());
}
}
if (!foundAnImage) {
SkDebugf("No supported images found in %s!\n", flag);
return false;
}
} else {
// Also add the value if it is a single image
output->push_back() = flag;
}
}
return true;
}