X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fimage_input.cpp;h=6a2c5abc846b913123ef00647373bd6267ee1d4b;hb=2e1b69c339862fb9b8147bf0ac07d87ca4810d4e;hp=779f7ec0c77745367e974135d9a19b7639a77789;hpb=e3df5f8d9bdc31df5dcd14e5ac214de70f5234af;p=nageru diff --git a/nageru/image_input.cpp b/nageru/image_input.cpp index 779f7ec..6a2c5ab 100644 --- a/nageru/image_input.cpp +++ b/nageru/image_input.cpp @@ -41,9 +41,14 @@ struct SwsContext; using namespace std; +ImageInput::ImageInput() + : sRGBSwitchingFlatInput({movit::COLORSPACE_sRGB, movit::GAMMA_sRGB}, movit::FORMAT_RGBA_POSTMULTIPLIED_ALPHA, + GL_UNSIGNED_BYTE, 1280, 720) // Resolution will be overwritten. +{} + 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. + : sRGBSwitchingFlatInput({movit::COLORSPACE_sRGB, movit::GAMMA_sRGB}, movit::FORMAT_RGBA_POSTMULTIPLIED_ALPHA, + GL_UNSIGNED_BYTE, 1280, 720), // Resolution will be overwritten. pathname(search_for_file_or_die(filename)), current_image(load_image(filename, pathname)) { @@ -66,12 +71,13 @@ void ImageInput::set_gl_state(GLuint glsl_program_num, const string& prefix, uns // is mostly there to save startup time, not RAM). { lock_guard lock(all_images_lock); + assert(all_images.count(pathname)); if (all_images[pathname] != current_image) { current_image = all_images[pathname]; set_texture_num(*current_image->tex); } } - movit::FlatInput::set_gl_state(glsl_program_num, prefix, sampler_num); + sRGBSwitchingFlatInput::set_gl_state(glsl_program_num, prefix, sampler_num); } shared_ptr ImageInput::load_image(const string &filename, const string &pathname) @@ -212,7 +218,7 @@ shared_ptr ImageInput::load_image_raw(const string &pat check_error(); glPixelStorei(GL_UNPACK_ROW_LENGTH, linesizes[0] / 4); check_error(); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, frame->width, frame->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data.get()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8_ALPHA8, frame->width, frame->height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, image_data.get()); check_error(); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); check_error(); @@ -288,6 +294,15 @@ void ImageInput::update_thread_func(QSurface *surface) } } +void ImageInput::switch_image(const string &pathname) +{ +#ifndef NDEBUG + lock_guard lock(all_images_lock); + assert(all_images.count(pathname)); +#endif + this->pathname = pathname; +} + void ImageInput::start_update_thread(QSurface *surface) { update_thread = thread(update_thread_func, surface);