diff options
author | Patrick Roth <roth@stettbacher.ch> | 2019-10-04 11:51:48 +0200 |
---|---|---|
committer | Patrick Roth <roth@stettbacher.ch> | 2019-10-04 11:51:48 +0200 |
commit | a0f501fa5650d0b6062cc8f26b34bce11137643d (patch) | |
tree | 8e31c5ac3409d4ce48887d88d4530b88a02c2660 /alg_ccm.h | |
download | o3000-color-pipe-a0f501fa5650d0b6062cc8f26b34bce11137643d.tar.gz o3000-color-pipe-a0f501fa5650d0b6062cc8f26b34bce11137643d.zip |
initial commit
import from github
Diffstat (limited to 'alg_ccm.h')
-rw-r--r-- | alg_ccm.h | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/alg_ccm.h b/alg_ccm.h new file mode 100644 index 0000000..24d37bc --- /dev/null +++ b/alg_ccm.h @@ -0,0 +1,88 @@ +/** +* @file alg_ccm.h +* @brief color correction algorithm definition +* @author Patrick Roth - roth@stettbacher.ch +* @version 1.0 +* @date 2015-08-26 +* @copyright 2012-2016 Stettbacher Signal Processing AG +* +* @remarks +* +* <PRE> +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* </PRE> +* +*/ + + +/* + * This code inplements color correction algorithm and is pixel size independent. Including this code at the + * C-Source file will define the pixel-bit-depth (see color.c). + */ +// static void rgb_color_correction8(uint8_t *img_calib, const uint8_t *img_uncalib, const int color_bit_depth, const int height, const int width, float a[3][3]) +// static void rgb_color_correction16(uint16_t *img_calib, const uint16_t *img_uncalib, const int color_bit_depth, const int height, const int width, float a[3][3]) +{ + int y, x; + int uncal_red, uncal_green, uncal_blue; + int cal_red, cal_green, cal_blue; + int index; + int pix_max_val; + const int shift_fact = 16; + + const int a11 = (int) (a[0][0]*(1<<shift_fact)); + const int a12 = (int) (a[0][1]*(1<<shift_fact)); + const int a13 = (int) (a[0][2]*(1<<shift_fact)); + const int a21 = (int) (a[1][0]*(1<<shift_fact)); + const int a22 = (int) (a[1][1]*(1<<shift_fact)); + const int a23 = (int) (a[1][2]*(1<<shift_fact)); + const int a31 = (int) (a[2][0]*(1<<shift_fact)); + const int a32 = (int) (a[2][1]*(1<<shift_fact)); + const int a33 = (int) (a[2][2]*(1<<shift_fact)); + + index = 0; + pix_max_val = (1<<color_bit_depth)-1; + + for(y = 0; y < height; y++) { + for(x = 0; x < width; x++) { + uncal_red = img_uncalib[index]; + uncal_green = img_uncalib[index+1]; + uncal_blue = img_uncalib[index+2]; + + // apply color correction matrix + cal_red = (uncal_red*a11 + uncal_green*a12 + uncal_blue*a13) >> shift_fact; + cal_green = (uncal_red*a21 + uncal_green*a22 + uncal_blue*a23) >> shift_fact; + cal_blue = (uncal_red*a31 + uncal_green*a32 + uncal_blue*a33) >> shift_fact; + + // range check + if(cal_red > pix_max_val) cal_red = pix_max_val; + else if(cal_red < 0) cal_red = 0; + + if(cal_green > pix_max_val) cal_green = pix_max_val; + else if(cal_green < 0) cal_green = 0; + + if(cal_blue > pix_max_val) cal_blue = pix_max_val; + else if(cal_blue < 0) cal_blue = 0; + + // save calibrated color values at output image + img_calib[index] = cal_red; + img_calib[index+1] = cal_green; + img_calib[index+2] = cal_blue; + + index += 3; + + + } + } +}
\ No newline at end of file |