Rewrite YUV processing pipeline.
Use a 4-channel texture instead for packed YUV data so every pixel in the texture has all the 4:2:2 color data available.
This commit is contained in:
@@ -7,26 +7,24 @@ uniform mat3 color_matrix;
|
||||
uniform float inv_gamma;
|
||||
uniform float blacklevel;
|
||||
|
||||
varying vec2 top_left_uv;
|
||||
varying vec2 top_right_uv;
|
||||
varying vec2 bottom_left_uv;
|
||||
varying vec2 bottom_right_uv;
|
||||
varying vec2 texture_coord;
|
||||
|
||||
void
|
||||
main()
|
||||
{
|
||||
// Note the coordinates for texture samples need to be a varying, as the
|
||||
// Mali-400 has this as a fast path allowing 32-bit floats. Otherwise
|
||||
// they end up as 16-bit floats and that's not accurate enough.
|
||||
// Sample format: Y,U,Y,V
|
||||
vec4 samples = texture2D(texture, texture_coord);
|
||||
float y = samples.x;
|
||||
float u = samples.y-0.5;
|
||||
float v = samples.w-0.5;
|
||||
|
||||
vec4 samples = vec4(texture2D(texture, top_left_uv).r,
|
||||
texture2D(texture, top_right_uv).r,
|
||||
texture2D(texture, bottom_left_uv).r,
|
||||
texture2D(texture, bottom_right_uv).r);
|
||||
vec3 color = vec3(samples.z, samples.z, samples.z);
|
||||
vec3 rgb;
|
||||
rgb.r = y + (1.403 * v);
|
||||
rgb.g = y - (0.344 * u) - (0.714 * v);
|
||||
rgb.b = y + (1.770 * u);
|
||||
|
||||
//color *= color_matrix;
|
||||
vec3 gamma_color = pow(color, vec3(inv_gamma));
|
||||
vec3 gamma_color = pow(rgb, vec3(inv_gamma));
|
||||
|
||||
gl_FragColor = vec4(gamma_color, 1);
|
||||
}
|
||||
|
@@ -8,18 +8,11 @@ attribute vec2 tex_coord;
|
||||
uniform mat3 transform;
|
||||
uniform vec2 pixel_size;
|
||||
|
||||
varying vec2 top_left_uv;
|
||||
varying vec2 top_right_uv;
|
||||
varying vec2 bottom_left_uv;
|
||||
varying vec2 bottom_right_uv;
|
||||
varying vec2 texture_coord;
|
||||
|
||||
void
|
||||
main()
|
||||
{
|
||||
top_left_uv = tex_coord - pixel_size / 2.0;
|
||||
bottom_right_uv = tex_coord + pixel_size / 2.0;
|
||||
top_right_uv = vec2(top_left_uv.x, bottom_right_uv.y);
|
||||
bottom_left_uv = vec2(bottom_right_uv.x, top_left_uv.y);
|
||||
|
||||
texture_coord = vert.xy * vec2(0.5, 0.5) + vec2(0.5, 0.5);
|
||||
gl_Position = vec4(transform * vec3(vert, 1), 1);
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@ gles2_debayer_new(int format)
|
||||
uint32_t pixfmt = libmegapixels_format_to_v4l_pixfmt(format);
|
||||
|
||||
int shader = 0;
|
||||
int texture_mode = 0;
|
||||
|
||||
switch (pixfmt) {
|
||||
case V4L2_PIX_FMT_SBGGR8:
|
||||
@@ -33,15 +34,18 @@ gles2_debayer_new(int format)
|
||||
case V4L2_PIX_FMT_SGRBG12:
|
||||
case V4L2_PIX_FMT_SRGGB12:
|
||||
shader = SHADER_DEBAYER;
|
||||
texture_mode = TEXTURE_BAYER;
|
||||
break;
|
||||
case V4L2_PIX_FMT_SBGGR10P:
|
||||
case V4L2_PIX_FMT_SGBRG10P:
|
||||
case V4L2_PIX_FMT_SGRBG10P:
|
||||
case V4L2_PIX_FMT_SRGGB10P:
|
||||
shader = SHADER_DEBAYER_PACKED;
|
||||
texture_mode = TEXTURE_BAYER;
|
||||
break;
|
||||
case V4L2_PIX_FMT_YUYV:
|
||||
shader = SHADER_YUV;
|
||||
texture_mode = TEXTURE_YUV;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -86,6 +90,7 @@ gles2_debayer_new(int format)
|
||||
GLES2Debayer *self = malloc(sizeof(GLES2Debayer));
|
||||
self->format = format;
|
||||
self->shader = shader;
|
||||
self->texture_mode = texture_mode;
|
||||
|
||||
self->frame_buffer = frame_buffer;
|
||||
self->program = program;
|
||||
|
@@ -8,10 +8,14 @@
|
||||
#define SHADER_DEBAYER_PACKED 2
|
||||
#define SHADER_YUV 3
|
||||
|
||||
#define TEXTURE_BAYER 1
|
||||
#define TEXTURE_YUV 2
|
||||
|
||||
typedef struct {
|
||||
int format;
|
||||
int shader;
|
||||
float forward_matrix[9];
|
||||
int texture_mode;
|
||||
|
||||
GLuint frame_buffer;
|
||||
GLuint program;
|
||||
|
@@ -406,7 +406,7 @@ static void
|
||||
auto_focus_step(const struct focus_stats *stats)
|
||||
{
|
||||
static uint64_t best_sharp, best_focus;
|
||||
static const int debug = 1;
|
||||
static const int debug = 0;
|
||||
|
||||
if (focus_phase >= PH_DONE) {
|
||||
if (debug>1) printf("Phase %d, sharp %d best %d ", focus_phase, (int)(stats->sharp / 10000), (int)(best_sharp/ 10000));
|
||||
@@ -616,7 +616,7 @@ process_aaa()
|
||||
update_control(&state_proc.gain);
|
||||
update_control(&state_proc.dgain);
|
||||
update_control(&state_proc.exposure);
|
||||
summarize();
|
||||
//summarize();
|
||||
}
|
||||
|
||||
if (auto_balance) {
|
||||
@@ -682,6 +682,8 @@ process_image_for_preview(const uint8_t *image)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
switch(gles2_debayer->texture_mode) {
|
||||
case TEXTURE_BAYER:
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
@@ -695,6 +697,22 @@ process_image_for_preview(const uint8_t *image)
|
||||
GL_LUMINANCE,
|
||||
GL_UNSIGNED_BYTE,
|
||||
image);
|
||||
break;
|
||||
case TEXTURE_YUV:
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA8,
|
||||
state_proc.mode->width/2 +
|
||||
libmegapixels_mode_width_to_padding(state_proc.mode->format,
|
||||
state_proc.mode->width),
|
||||
state_proc.mode->height,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
image);
|
||||
break;
|
||||
}
|
||||
check_gl();
|
||||
|
||||
gles2_debayer_process(
|
||||
|
Reference in New Issue
Block a user