Skip to content

Commit ffb963d

Browse files
committed
Optimize Image Validation and Loading in ivmain.cpp
Signed-off-by: Chaitanya Sharma <39400946+CheeksTheGeek@users.noreply.github.com>
1 parent 2bf1a90 commit ffb963d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/iv/ivmain.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ main(int argc, char* argv[])
107107
mainWin->raise();
108108
mainWin->activateWindow();
109109

110+
// Set up the imagecache with parameters that make sense for iv
111+
ImageCache* imagecache = ImageCache::create(true);
112+
ustring uexists("exists");
113+
std::string knownExtensions;
114+
OIIO::getattribute("extension_list", knownExtensions);
115+
110116
// Add the images
111117
for (auto& f : ap["filename"].as_vec<std::string>()) {
112118
// Check if the file exists
@@ -122,10 +128,12 @@ main(int argc, char* argv[])
122128

123129
std::vector<std::string> validImages; // Vector to hold valid images
124130
for (auto& file : files) {
125-
auto in = ImageInput::open(file);
126-
if (in) {
127-
validImages.push_back(file);
128-
in->close(); // Close the ImageInput object to free resources
131+
std::string extension = Filesystem::extension(file);
132+
if (knownExtensions.find(extension) != std::string::npos) {
133+
int exists = 0;
134+
bool ok = imagecache->get_image_info(ustring(file), 0, 0, uexists, OIIO::TypeInt, &exists);
135+
if (ok && exists)
136+
validImages.push_back(file);
129137
}
130138
}
131139

0 commit comments

Comments
 (0)