CommonFlagsImages.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. #include "src/core/SkOSFile.h"
  4. #include "src/utils/SkOSPath.h"
  5. #include "tools/flags/CommonFlags.h"
  6. bool CollectImages(CommandLineFlags::StringArray images, SkTArray<SkString>* output) {
  7. SkASSERT(output);
  8. static const char* const exts[] = {
  9. "bmp",
  10. "gif",
  11. "jpg",
  12. "jpeg",
  13. "png",
  14. "webp",
  15. "ktx",
  16. "astc",
  17. "wbmp",
  18. "ico",
  19. #if !defined(SK_BUILD_FOR_WIN)
  20. "BMP",
  21. "GIF",
  22. "JPG",
  23. "JPEG",
  24. "PNG",
  25. "WEBP",
  26. "KTX",
  27. "ASTC",
  28. "WBMP",
  29. "ICO",
  30. #endif
  31. #ifdef SK_HAS_HEIF_LIBRARY
  32. "heic",
  33. #if !defined(SK_BUILD_FOR_WIN)
  34. "HEIC",
  35. #endif
  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. for (int i = 0; i < images.count(); ++i) {
  63. const char* flag = images[i];
  64. if (!sk_exists(flag)) {
  65. SkDebugf("%s does not exist!\n", flag);
  66. return false;
  67. }
  68. if (sk_isdir(flag)) {
  69. // If the value passed in is a directory, add all the images
  70. bool foundAnImage = false;
  71. for (const char* ext : exts) {
  72. SkOSFile::Iter it(flag, ext);
  73. SkString file;
  74. while (it.next(&file)) {
  75. foundAnImage = true;
  76. output->push_back() = SkOSPath::Join(flag, file.c_str());
  77. }
  78. }
  79. if (!foundAnImage) {
  80. SkDebugf("No supported images found in %s!\n", flag);
  81. return false;
  82. }
  83. } else {
  84. // Also add the value if it is a single image
  85. output->push_back() = flag;
  86. }
  87. }
  88. return true;
  89. }