| 1 |
/* |
| 2 |
# (C) 2008-2009 Hans de Goede <[email protected]> |
| 3 |
|
| 4 |
# This program is free software; you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU Lesser General Public License as published by |
| 6 |
# the Free Software Foundation; either version 2.1 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU Lesser General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU Lesser General Public License |
| 15 |
# along with this program; if not, write to the Free Software |
| 16 |
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <math.h> |
| 20 |
#include "libv4lprocessing.h" |
| 21 |
#include "libv4lprocessing-priv.h" |
| 22 |
|
| 23 |
#define CLIP(color) (unsigned char)(((color) > 0xff) ? 0xff : (((color) < 0) ? 0 : (color))) |
| 24 |
|
| 25 |
static int gamma_active(struct v4lprocessing_data *data) |
| 26 |
{ |
| 27 |
int gamma = v4lcontrol_get_ctrl(data->control, V4LCONTROL_GAMMA); |
| 28 |
|
| 29 |
return gamma && gamma != 1000; |
| 30 |
} |
| 31 |
|
| 32 |
static int gamma_calculate_lookup_tables( |
| 33 |
struct v4lprocessing_data *data, |
| 34 |
unsigned char *buf, const struct v4l2_format *fmt) |
| 35 |
{ |
| 36 |
int i, x, gamma; |
| 37 |
|
| 38 |
gamma = v4lcontrol_get_ctrl(data->control, V4LCONTROL_GAMMA); |
| 39 |
|
| 40 |
if (gamma == 0) |
| 41 |
return 0; |
| 42 |
|
| 43 |
if (gamma != data->last_gamma) { |
| 44 |
for (i = 0; i < 256; i++) { |
| 45 |
x = powf(i / 255.0, 1000.0 / gamma) * 255; |
| 46 |
data->gamma_table[i] = CLIP(x); |
| 47 |
} |
| 48 |
data->last_gamma = gamma; |
| 49 |
} |
| 50 |
|
| 51 |
for (i = 0; i < 256; i++) { |
| 52 |
data->comp1[i] = data->gamma_table[data->comp1[i]]; |
| 53 |
data->green[i] = data->gamma_table[data->green[i]]; |
| 54 |
data->comp2[i] = data->gamma_table[data->comp2[i]]; |
| 55 |
} |
| 56 |
|
| 57 |
return 1; |
| 58 |
} |
| 59 |
|
| 60 |
const struct v4lprocessing_filter gamma_filter = { |
| 61 |
gamma_active, gamma_calculate_lookup_tables |
| 62 |
}; |