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