diff --git a/data/debayer.frag b/data/debayer.frag index bf3d042..7302e43 100644 --- a/data/debayer.frag +++ b/data/debayer.frag @@ -6,6 +6,7 @@ uniform sampler2D texture; uniform mat3 color_matrix; #ifdef BITS_10 uniform float row_length; +uniform float padding_ratio; #endif varying vec2 top_left_uv; @@ -22,6 +23,9 @@ skip_5th_pixel(vec2 uv) new_uv.x *= 0.8; new_uv.x += floor(uv.x * row_length / 5.0) / row_length; + // Crop out padding + new_uv.x *= padding_ratio; + return new_uv; } #endif diff --git a/src/gles2_debayer.c b/src/gles2_debayer.c index 66caec4..db56207 100644 --- a/src/gles2_debayer.c +++ b/src/gles2_debayer.c @@ -14,6 +14,7 @@ struct _GLES2Debayer { GLuint program; GLuint uniform_transform; GLuint uniform_pixel_size; + GLuint uniform_padding_ratio; GLuint uniform_texture; GLuint uniform_color_matrix; GLuint uniform_row_length; @@ -68,6 +69,8 @@ gles2_debayer_new(MPPixelFormat format) self->uniform_transform = glGetUniformLocation(self->program, "transform"); self->uniform_pixel_size = glGetUniformLocation(self->program, "pixel_size"); + self->uniform_padding_ratio = + glGetUniformLocation(self->program, "padding_ratio"); self->uniform_texture = glGetUniformLocation(self->program, "texture"); self->uniform_color_matrix = glGetUniformLocation(self->program, "color_matrix"); @@ -156,12 +159,17 @@ gles2_debayer_configure(GLES2Debayer *self, } check_gl(); + GLuint row_length = mp_pixel_format_width_to_bytes(self->format, src_width); if (mp_pixel_format_bits_per_pixel(self->format) == 10) { assert(src_width % 4 == 0); - glUniform1f(self->uniform_row_length, - mp_pixel_format_width_to_bytes(self->format, src_width)); + glUniform1f(self->uniform_row_length, row_length); check_gl(); } + + GLuint padding_bytes = + mp_pixel_format_width_to_padding(self->format, src_width); + GLfloat padding_ratio = (float)row_length / (row_length + padding_bytes); + glUniform1f(self->uniform_padding_ratio, padding_ratio); } void diff --git a/src/process_pipeline.c b/src/process_pipeline.c index 04d03cb..58e9549 100644 --- a/src/process_pipeline.c +++ b/src/process_pipeline.c @@ -327,7 +327,9 @@ process_image_for_preview(const uint8_t *image) glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, - mp_pixel_format_width_to_bytes(mode.pixel_format, mode.width), + mp_pixel_format_width_to_bytes(mode.pixel_format, mode.width) + + mp_pixel_format_width_to_padding(mode.pixel_format, + mode.width), mode.height, 0, GL_LUMINANCE, @@ -681,8 +683,10 @@ process_image(MPPipeline *pipeline, const MPBuffer *buffer) clock_t t1 = clock(); #endif - size_t size = mp_pixel_format_width_to_bytes(mode.pixel_format, mode.width) * - mode.height; + size_t size = + (mp_pixel_format_width_to_bytes(mode.pixel_format, mode.width) + + mp_pixel_format_width_to_padding(mode.pixel_format, mode.width)) * + mode.height; uint8_t *image = malloc(size); memcpy(image, buffer->data, size); mp_io_pipeline_release_buffer(buffer->index);