#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),
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);
}
{
// 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) {
} 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);
// 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();
// 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();
// 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"; }
// 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) {
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)
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());
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) {
}
}
- unsigned get_pitch(unsigned channel) {
- assert(channel >= 0 && channel < 3);
- return pitch[channel];
- }
-
private:
ImageFormat image_format;
YCbCrFormat ycbcr_format;