#include "autoexposure.h"
Include dependency graph for white_balance.c:
Go to the source code of this file.
Functions | |
void | initWhiteBalanceCorr (void) |
int | whiteBalanceCorr (int frame, int target_frame, int ae_rslt) |
Single white balance correction step (through scaling "gamma" curves). white balance parameters are used for the target fram, not for the currenly processed. |
void initWhiteBalanceCorr | ( | void | ) |
*************************************************************************** ! FILE NAME : white_balance.c ! DESCRIPTION: White balance part of the autoexposure/white balance/hdr daemon ! Copyright (C) 2008 Elphel, Inc. ! -----------------------------------------------------------------------------** ! This program is free software: you can redistribute it and/or modify ! it under the terms of the GNU General Public License as published by ! the Free Software Foundation, either version 3 of the License, or ! (at your option) any later version. ! ! This program is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program. If not, see <http://www.gnu.org/licenses/>. ! -----------------------------------------------------------------------------** ! !
Definition at line 43 of file white_balance.c.
References G_NEXT_WB_FRAME, and GLOBALPARS.
Referenced by initParams().
int whiteBalanceCorr | ( | int | frame, | |
int | target_frame, | |||
int | ae_rslt | |||
) |
Single white balance correction step (through scaling "gamma" curves). white balance parameters are used for the target fram, not for the currenly processed.
TODO: at startup or long pause, set wb after aexp settles to within thershold TODO: SupportT P_WB_MASK - now it is just ON/OFF. NOTE:When the bit is off it should be scaled with the G1 color!
int gamma_index; - global int hist_index; - global int error_thresh;
brightest one of the enabled colors (including COLOR_Y_NUMBER)
maximal (among colors) number of "white" (>wb_whitelev) pixels
256 of cumulated histogram values (in pixels) for selected color
256 of rounded percentiles (1 byte) - used as a starting point for linear interpolation
16-bit levels for "white" for different colors (output levels),
16.16 additional manual color correction coefficients
minimal scale of all selected colors (to normalize all sclaes >=1.0)
lower byte
next byte
don't try to synchronize to availble histograms
white balance is off (mask==0)
too early to bother
======= 0 here
Get the histogram (including percentiles)
wait for all histograms, not just Y (G1)
specify that reverse histogram(s) are needed. Are they?
request histograms for the previous frame
histogram is too old - try again
will request histogram for this frame
repeat up to 8 times trying to get a fresh histogram
request histograms for the previous frame
histogram is too old - try again
will request histogram for this frame
0xfae1 // 98%
0x028f // 1%
allow small variations
Find the "brightest" color (maximal number of pixels above wb_whitelev ). wb_whitelev is currently rounded to 8 bits
this one is definitely calculated
Find the "brightest" color (maximal number of pixels above wb_whitelev ). wb_whitelev is currently rounded to 8 bits
No, wb_whitelev has to be lowered and brightest color is unknown (maybe max_white_pixels==0)
See if enough pixels are above wb_whitelev
No, wb_whitelev has to be lowered
Find levels for other (than brightest) colors so the same number of pixels is below it. First - output range, then correct by gamma-tables to input range
number of non-white (less than level) pixels for the brightest color
still bad
nonwhite_frac-> levels[color]
8 MSBs used as index
seems hist_percentile[perc] rounds up, not down
adjust down (is that needed at all?)
adjust up (is that needed at all?)
No need to un-gamma as scales apply to outputs, not inputs
now request gamma table for that hash32, including reverse
Here levels_corr[color] are defined for all non-zero bits in colors, need some final calculations hash32[color] has current scales in lower 16 bits (0x400 = 1.0) corr[color] - 16.16 manual corrections
minimal scale of all selected colors (to normalize all sclaes >=1.0)
Applying changes to analog gains. Unfortunately we do not know what exactly gain will be set by the driver (only can check it next time when it will be corrected to the sensor capabilities. So we should not try to make chnages smaller than sensor gain step - otherwise gains/gamma scales would "fight" NOTE: sensor analogs gain naturally apply to sensor "space" (before gamma), while gamma scales - after. now levels[color] are actually gains (>=0x400)
FIXME: When Green1 scale is >0x400 autoexposure can fight white balance Use the same analog gain for both greens if same gain is requested
saturation level for colors (0..0xffff) - referenced to sensor space (before gamma)
at least one color requires correction higher than threshold
">>2" to avoid overflow later
so argument is in 0..0x10000 range,
same ">>2" so analog gains up to 32 would not cause
integer overflow (TODO:change to unsigned)
Keep analog gains f0r both greens the same (if not requested otherwise)
was the chnage above the treshold?
levels are now scales
One more correction if the scale of Y color was not the minimal - recheck it
Now apply modified scales
modify overall next_frame
Definition at line 58 of file white_balance.c.
References color, COLOR_GREEN1, COLOR_GREEN2, COLOR_Y_NUMBER, histogram_stuct_t::cumul_hist, DEFAULT_WB_PERIOD_CHANGE, DEFAULT_WB_PERIOD_NOCHANGE, DEFAULT_WB_WHITEFRAC, DEFAULT_WB_WHITELEV, ELP_FERR, fd_fparmsall, fd_histogram_cache, framePars, FRAMEPARS_SETFRAME, G_NEXT_WB_FRAME, G_WB_INTEGERR, GAIN_BIT_ENABLE, GAMMA_SCALE_SHIFT, gammaDirect(), gammaReverse(), get_imageParamsThat(), GLOBALPARS, gamma_stuct_t::hash32, hist_index, histogram_cache, LSEEK_FRAME_WAIT_ABS, LSEEK_HIST_NEEDED, LSEEK_HIST_WAIT_C, MDF3, MDF4, P_GAIN_CTRL, P_GAIN_MAX, P_GAIN_MIN, P_GAINR, P_GTAB_R, P_WB_MASK, P_WB_PERIOD, P_WB_SCALE_B, P_WB_SCALE_GB, P_WB_SCALE_R, P_WB_WHITEFRAC, P_WB_WHITELEV, framepars_t::pars, PARS_FRAMES_MASK, histogram_stuct_t::percentile, PERCENTILE_SHIFT, SEEK_END, SEEK_SET, stderr, this_frame, and write.
Referenced by main().