Implement whitebalance
This commit is contained in:
@@ -61,7 +61,6 @@ main()
|
||||
#endif
|
||||
|
||||
color -= blacklevel;
|
||||
color *= 1.0-(1.0/blacklevel);
|
||||
color *= color_matrix;
|
||||
|
||||
vec3 gamma_color = pow(color, vec3(inv_gamma));
|
||||
|
@@ -532,7 +532,8 @@ update_state(MPPipeline *pipeline, const mp_state_io *new_state)
|
||||
state_io.flash_enabled = new_state->flash_enabled;
|
||||
|
||||
state_io.stats.exposure = new_state->stats.exposure;
|
||||
state_io.stats.whitebalance = new_state->stats.whitebalance;
|
||||
state_io.stats.temp = new_state->stats.temp;
|
||||
state_io.stats.tint = new_state->stats.tint;
|
||||
state_io.stats.focus = new_state->stats.focus;
|
||||
}
|
||||
|
||||
|
@@ -133,7 +133,8 @@ update_io_pipeline()
|
||||
.focus.manual_req = state.focus.manual_req,
|
||||
|
||||
.stats.exposure = state.stats.exposure,
|
||||
.stats.whitebalance = state.stats.whitebalance,
|
||||
.stats.temp = state.stats.temp,
|
||||
.stats.tint = state.stats.tint,
|
||||
.stats.focus = state.stats.focus,
|
||||
};
|
||||
mp_io_pipeline_update_state(&new_state);
|
||||
@@ -171,7 +172,8 @@ update_state(const mp_state_main *new_state)
|
||||
state.preview_buffer_height = new_state->preview_buffer_height;
|
||||
|
||||
state.stats.exposure = new_state->stats.exposure;
|
||||
state.stats.whitebalance = new_state->stats.whitebalance;
|
||||
state.stats.temp = new_state->stats.temp;
|
||||
state.stats.tint = new_state->stats.tint;
|
||||
state.stats.focus = new_state->stats.focus;
|
||||
|
||||
// Make the right settings available for the camera
|
||||
|
@@ -388,6 +388,17 @@ mp_process_pipeline_init_gl(GdkSurface *surface)
|
||||
sizeof(GdkSurface *));
|
||||
}
|
||||
|
||||
float
|
||||
clamp_float(float value, float min, float max) {
|
||||
if(value > max)
|
||||
return max;
|
||||
|
||||
if(value < min)
|
||||
return min;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static GdkTexture *
|
||||
process_image_for_preview(const uint8_t *image)
|
||||
{
|
||||
@@ -461,10 +472,10 @@ process_image_for_preview(const uint8_t *image)
|
||||
mp_main_set_preview(output_buffer);
|
||||
|
||||
if (!state_proc.exposure.manual && state_proc.exposure.auto_control == 0) {
|
||||
int width = output_buffer_width / 3;
|
||||
int width = output_buffer_width;
|
||||
int height = output_buffer_height / 3;
|
||||
uint32_t *center = g_malloc_n(width * height * sizeof(uint32_t), 1);
|
||||
glReadPixels(width,
|
||||
glReadPixels(0,
|
||||
height,
|
||||
width,
|
||||
height,
|
||||
@@ -474,9 +485,14 @@ process_image_for_preview(const uint8_t *image)
|
||||
libmegapixels_aaa_software_statistics(
|
||||
center, width, height, &state_proc.stats);
|
||||
|
||||
state_proc.red += (state_proc.stats.whitebalance * -0.02f) + (state_proc.stats.tint * 0.01f);
|
||||
state_proc.blue += (state_proc.stats.whitebalance * +0.02f) + (state_proc.stats.tint * 0.01f);
|
||||
state_proc.blacklevel += state_proc.stats.blacklevel * 0.01f;
|
||||
float w_gain = 0.02f;
|
||||
float t_gain = 0.01f;
|
||||
state_proc.red += (state_proc.stats.temp * +w_gain) + (state_proc.stats.tint * t_gain);
|
||||
state_proc.blue += (state_proc.stats.temp * -w_gain) + (state_proc.stats.tint * t_gain);
|
||||
state_proc.blacklevel -= state_proc.stats.blacklevel * 0.001f;
|
||||
state_proc.blacklevel = clamp_float(state_proc.blacklevel, 0.0f, 0.07f);
|
||||
state_proc.red = clamp_float(state_proc.red, 0.5f, 3.0f);
|
||||
state_proc.blue = clamp_float(state_proc.blue, 0.5f, 3.0f);
|
||||
gles2_debayer_set_shading(gles2_debayer, state_proc.red, state_proc.blue, state_proc.blacklevel);
|
||||
}
|
||||
|
||||
@@ -1052,7 +1068,8 @@ update_state(MPPipeline *pipeline, const mp_state_proc *new_state)
|
||||
.focus.manual = state_proc.focus.manual,
|
||||
|
||||
.stats.exposure = state_proc.stats.exposure,
|
||||
.stats.whitebalance = state_proc.stats.whitebalance,
|
||||
.stats.temp = state_proc.stats.temp,
|
||||
.stats.tint = state_proc.stats.tint,
|
||||
.stats.focus = state_proc.stats.focus,
|
||||
};
|
||||
mp_main_update_state(&new_main);
|
||||
|
Reference in New Issue
Block a user