/**
* @file gamma_corr.c
* @brief gamma correction algorithm
* @author Patrick Roth - roth@stettbacher.ch
* @copyright Stettbacher Signal Processing AG
*
* @remarks
*
*
* 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
*
*
*/
#include
#include
#include
#include "color_pipe_private.h"
/**
* Apply gamma correction to given image type: RGB or monochrome with 8 bit per color channel
*
* @param img_rgb On return: gamma corrected image
* @param img_in image to be gamma corrected
* @param height image height in number of pixels
* @param width image width in number of pixels
* @param max_val maximum pixel value
* @param gamma gamma coefficient
* @param is_color 1 if it's a color image, 0 if it's a monochrome image
* @return 0 on success otherwise -1
*/
static void gamma_corr8(uint8_t *img_rgb, const uint8_t *img_in, const int height, const int width, const int *gamma_table, const int is_color)
#include "alg_gamma.h"
/**
* Apply gamma correction to given image type: RGB or monochrome with 16 bit per color channel
*
* @param img_rgb On return: gamma corrected image
* @param img_in image to be gamma corrected
* @param height image height in number of pixels
* @param width image width in number of pixels
* @param max_val maximum pixel value
* @param gamma gamma coefficient
* @param is_color 1 if it's a color image, 0 if it's a monochrome image
* @return 0 on success otherwise -1
*/
static void gamma_corr16(uint16_t *img_rgb, const uint16_t *img_in, const int height, const int width, const int *gamma_table, const int is_color)
#include "alg_gamma.h"
/**
* Apply gamma correction to given image type.
*
* @param gamma_data required data for gamma correction
* @return 0 on success otherwise -1
*/
int gamma_corr(struct gamma_data_t *gamma_data) {
void *img_gamma, *img_in;
int *gamma_table;
int i, is_color, bit_channel, width, height, max_pix, gamma_table_bitdepth;
float gamma, gamma_table_init;
// put variables on stack
is_color = gamma_data->is_color;
img_gamma = gamma_data->img_gamma;
img_in = gamma_data->img_in;
bit_channel = gamma_data->bit_channel;
width = gamma_data->width;
height = gamma_data->height;
gamma = gamma_data->gamma;
max_pix = (1<gamma_table_bitdepth;
gamma_table_init = gamma_data->gamma_table_init;
gamma_table = gamma_data->gamma_table;
/*
* Do check whether lookup table is initialzed with correct gamma value
*/
if(gamma_table_bitdepth != bit_channel || gamma != gamma_table_init) {
for(i = 0; i <= max_pix; i++) {
gamma_table[i] = roundf(max_pix*pow(i/((float)max_pix), gamma));
}
gamma_data->gamma_table_bitdepth = bit_channel;
gamma_data->gamma_table_init = gamma;
}
if(bit_channel <= 8) {
gamma_corr8(img_gamma, img_in, height, width, gamma_table, is_color);
}
else if(bit_channel <= 16) {
gamma_corr16(img_gamma, img_in, height, width, gamma_table, is_color);
}
return 0;
}