using namespace std;
-// FIXME gl context
+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))
{
// is mostly there to save startup time, not RAM).
{
lock_guard<mutex> 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<const ImageInput::Image> ImageInput::load_image(const string &filename, const string &pathname)
fprintf(stderr, "%s: Cannot fill codec parameters\n", pathname.c_str());
return nullptr;
}
- AVCodec *codec = avcodec_find_decoder(codecpar->codec_id);
+ const AVCodec *codec = avcodec_find_decoder(codecpar->codec_id);
if (codec == nullptr) {
fprintf(stderr, "%s: Cannot find decoder\n", pathname.c_str());
return nullptr;
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();
glBindTexture(GL_TEXTURE_2D, 0);
check_error();
- shared_ptr<Image> image(new Image{unsigned(frame->width), unsigned(frame->height), RefCountedTexture(new GLuint(tex)), last_modified});
+ shared_ptr<Image> image(new Image{unsigned(frame->width), unsigned(frame->height), UniqueTexture(new GLuint(tex)), last_modified});
return image;
}
}
}
+void ImageInput::switch_image(const string &pathname)
+{
+#ifndef NDEBUG
+ lock_guard<mutex> 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);