3 * \author Copyright 2001 Lutz Müller <lutz@users.sf.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
29 #include <gphoto2/gphoto2-result.h>
32 gp_gamma_correct_triple (unsigned char *table_red,
33 unsigned char *table_green,
34 unsigned char *table_blue,
35 unsigned char *data, unsigned int size)
39 for (x = 0; x < (size * 3); x += 3) {
40 data[x + 0] = table_red [data[x + 0]];
41 data[x + 1] = table_green[data[x + 1]];
42 data[x + 2] = table_blue [data[x + 2]];
49 * \brief Gamma correction
51 * Corrects size pixels within the table with a given Gamma
54 * \param table the gamma correction table as generated by gp_gamma_fill_table()
55 * \param data the data do process, both input and output
56 * \param size in number of pixels (RGB byte pairs)
58 * \returns a gphoto error code
61 gp_gamma_correct_single (unsigned char *table, unsigned char *data,
64 return (gp_gamma_correct_triple (table, table, table, data, size));
68 * \brief Initialize a Gamma conversion table
70 * Initializes the gamma conversion table for later use by gp_gamma_correct_single().
71 * Requires a 256 byte array as table.
72 * \param table a 256 byte array of unsigned char
73 * \param g gamma correction value
75 * \returns a gphoto error code
78 gp_gamma_fill_table (unsigned char *table, double g)
82 for (x = 0; x < 256; x++)
83 table[x] = 255 * pow ((double) x/255., g);