X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=image_input.cpp;h=a3a110c6ca293ae8beb12525f574c2c9cf6ad4c1;hb=63f0f22270455648d31a190089be58317a45b9cd;hp=5c9d7966cd7404b395ddab4ecaf40523c9215549;hpb=18347d8325cadd11ce732c7cdcb9b55c727e4938;p=nageru diff --git a/image_input.cpp b/image_input.cpp index 5c9d796..a3a110c 100644 --- a/image_input.cpp +++ b/image_input.cpp @@ -37,10 +37,24 @@ struct SwsContext; using namespace std; -namespace { - string search_for_file(const string &filename) { + if (!filename.empty() && filename[0] == '/') { + // Absolute path. + return filename; + } + + // See if we match ^[a-z]:/, which is probably a URL of some sort + // (FFmpeg understands various forms of these). + for (size_t i = 0; i < filename.size() - 1; ++i) { + if (filename[i] == ':' && filename[i + 1] == '/') { + return filename; + } + if (!isalpha(filename[i])) { + break; + } + } + // Look for the file in all theme_dirs until we find one; // that will be the permanent resolution of this file, whether // it is actually valid or not. @@ -61,18 +75,25 @@ string search_for_file(const string &filename) for (const string &error : errors) { fprintf(stderr, "%s\n", error.c_str()); } - fprintf(stderr, "Couldn't find %s in any directory in --theme-dirs, exiting.\n", - filename.c_str()); - exit(1); + return ""; } -} // namespace +string search_for_file_or_die(const string &filename) +{ + string pathname = search_for_file(filename); + if (pathname.empty()) { + fprintf(stderr, "Couldn't find %s in any directory in --theme-dirs, exiting.\n", + filename.c_str()); + exit(1); + } + return pathname; +} ImageInput::ImageInput(const string &filename) : movit::FlatInput({movit::COLORSPACE_sRGB, movit::GAMMA_sRGB}, movit::FORMAT_RGBA_POSTMULTIPLIED_ALPHA, GL_UNSIGNED_BYTE, 1280, 720), // Resolution will be overwritten. filename(filename), - pathname(search_for_file(filename)), + pathname(search_for_file_or_die(filename)), current_image(load_image(filename, pathname)) { if (current_image == nullptr) { // Could happen even though search_for_file() returned.