From: Steinar H. Gunderson Date: Thu, 11 Oct 2012 21:57:22 +0000 (+0200) Subject: Let FlatInput take in float data (sort of kludgy, though). Also remove the get_*... X-Git-Tag: 1.0~316 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=89da3437c862c15acb870fbe3175b9e4a0a8244a Let FlatInput take in float data (sort of kludgy, though). Also remove the get_* methods, since we do not need them. --- diff --git a/flat_input.cpp b/flat_input.cpp index 9c27cc8..0516083 100644 --- a/flat_input.cpp +++ b/flat_input.cpp @@ -5,9 +5,10 @@ #include "util.h" #include "opengl.h" -FlatInput::FlatInput(ImageFormat image_format, MovitPixelFormat pixel_format, unsigned width, unsigned height) +FlatInput::FlatInput(ImageFormat image_format, MovitPixelFormat pixel_format, GLenum type, unsigned width, unsigned height) : image_format(image_format), pixel_format(pixel_format), + type(type), needs_update(false), finalized(false), output_linear_gamma(false), @@ -16,6 +17,7 @@ FlatInput::FlatInput(ImageFormat image_format, MovitPixelFormat pixel_format, un height(height), pitch(width) { + assert(type == GL_FLOAT || type == GL_UNSIGNED_BYTE); register_int("output_linear_gamma", &output_linear_gamma); register_int("needs_mipmaps", &needs_mipmaps); } @@ -24,9 +26,13 @@ void FlatInput::finalize() { // Translate the input format to OpenGL's enums. GLenum internal_format; - if (output_linear_gamma) { + if (type == GL_FLOAT) { + internal_format = GL_RGBA16F_ARB; + } else if (output_linear_gamma) { + assert(type == GL_UNSIGNED_BYTE); internal_format = GL_SRGB8; } else { + assert(type == GL_UNSIGNED_BYTE); internal_format = GL_RGBA8; } if (pixel_format == FORMAT_RGB) { @@ -47,6 +53,9 @@ void FlatInput::finalize() } else { assert(false); } + if (type == GL_FLOAT) { + bytes_per_pixel *= sizeof(float); + } // Create PBO to hold the texture holding the input image, and then the texture itself. glGenBuffers(1, &pbo); @@ -70,7 +79,7 @@ void FlatInput::finalize() // instead of calling glGenerateMipmap(). glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, needs_mipmaps); check_error(); - glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, internal_format, width, height, 0, format, type, NULL); check_error(); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); check_error(); @@ -98,7 +107,7 @@ void FlatInput::set_gl_state(GLuint glsl_program_num, const std::string& prefix, // Re-upload the texture from the PBO. glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch); check_error(); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0)); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, GL_FLOAT, BUFFER_OFFSET(0)); check_error(); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); check_error(); diff --git a/flat_input.h b/flat_input.h index 90c0386..1820eaf 100644 --- a/flat_input.h +++ b/flat_input.h @@ -7,7 +7,7 @@ // comes from a single 2D array with chunky pixels. class FlatInput : public Input { public: - FlatInput(ImageFormat format, MovitPixelFormat pixel_format, unsigned width, unsigned height); + FlatInput(ImageFormat format, MovitPixelFormat pixel_format, GLenum type, unsigned width, unsigned height); virtual std::string effect_type_id() const { return "FlatInput"; } @@ -38,18 +38,21 @@ public: // on subsequent frames. void set_pixel_data(const unsigned char *pixel_data) { + assert(this->type == GL_UNSIGNED_BYTE); this->pixel_data = pixel_data; invalidate_pixel_data(); } - void invalidate_pixel_data() + void set_pixel_data(const float *pixel_data) { - needs_update = true; + assert(this->type == GL_FLOAT); + this->pixel_data = pixel_data; + invalidate_pixel_data(); } - const unsigned char *get_pixel_data() const + void invalidate_pixel_data() { - return pixel_data; + needs_update = true; } void set_pitch(unsigned pitch) { @@ -57,19 +60,15 @@ public: this->pitch = pitch; } - unsigned get_pitch() { - return pitch; - } - private: ImageFormat image_format; MovitPixelFormat pixel_format; - GLenum format; + GLenum format, type; GLuint pbo, texture_num; bool needs_update, finalized; int output_linear_gamma, needs_mipmaps; unsigned width, height, pitch, bytes_per_pixel; - const unsigned char *pixel_data; + const void *pixel_data; }; #endif // !defined(_FLAT_INPUT_H) diff --git a/main.cpp b/main.cpp index 3c807a1..625dba6 100644 --- a/main.cpp +++ b/main.cpp @@ -166,7 +166,7 @@ int main(int argc, char **argv) inout_format.color_space = COLORSPACE_sRGB; inout_format.gamma_curve = GAMMA_sRGB; - FlatInput *input = new FlatInput(inout_format, FORMAT_BGRA, img_w, img_h); + FlatInput *input = new FlatInput(inout_format, FORMAT_BGRA, GL_UNSIGNED_BYTE, img_w, img_h); chain.add_input(input); Effect *lift_gamma_gain_effect = chain.add_effect(new LiftGammaGainEffect()); Effect *saturation_effect = chain.add_effect(new SaturationEffect()); diff --git a/ycbcr_input.h b/ycbcr_input.h index 379279f..ed0c6ee 100644 --- a/ycbcr_input.h +++ b/ycbcr_input.h @@ -66,12 +66,6 @@ public: needs_update = true; } - const unsigned char *get_pixel_data(unsigned channel) const - { - assert(channel >= 0 && channel < 3); - return pixel_data[channel]; - } - void set_pitch(unsigned channel, unsigned pitch) { assert(channel >= 0 && channel < 3); if (this->pitch[channel] != pitch) { @@ -80,11 +74,6 @@ public: } } - unsigned get_pitch(unsigned channel) { - assert(channel >= 0 && channel < 3); - return pitch[channel]; - } - private: ImageFormat image_format; YCbCrFormat ycbcr_format;