~ubuntu-branches/debian/sid/v4l-utils/sid

« back to all changes in this revision

Viewing changes to lib/libv4lconvert/processing/gamma.c

  • Committer: Bazaar Package Importer
  • Author(s): Gregor Jasny
  • Date: 2010-05-07 20:48:34 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100507204834-ga01cxhz3fekk47r
Tags: 0.8.0-1
* New upstream version
* Switch to 3.0 (quilt) source format
* Re-enable pristine-tar
* Split utils package into command line and the Qt based qv4l2
  (Closes: #576422)
* Update upstream URL

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# You should have received a copy of the GNU Lesser General Public License
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 
*/
 
17
 */
18
18
 
19
19
#include <math.h>
20
20
#include "libv4lprocessing.h"
21
21
#include "libv4lprocessing-priv.h"
22
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
 
  int gamma = v4lcontrol_get_ctrl(data->control, V4LCONTROL_GAMMA);
27
 
 
28
 
  return gamma && gamma != 1000;
 
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;
29
30
}
30
31
 
31
32
static int gamma_calculate_lookup_tables(
32
 
  struct v4lprocessing_data *data,
33
 
  unsigned char *buf, const struct v4l2_format *fmt)
 
33
                struct v4lprocessing_data *data,
 
34
                unsigned char *buf, const struct v4l2_format *fmt)
34
35
{
35
 
  int i, x, gamma;
36
 
 
37
 
  gamma = v4lcontrol_get_ctrl(data->control, V4LCONTROL_GAMMA);
38
 
 
39
 
  if (gamma != data->last_gamma) {
40
 
    for (i = 0; i < 256; i++) {
41
 
      x = powf(i / 255.0, 1000.0 / gamma) * 255;
42
 
      data->gamma_table[i] = CLIP(x);
43
 
    }
44
 
    data->last_gamma = gamma;
45
 
  }
46
 
 
47
 
  for (i = 0; i < 256; i++) {
48
 
    data->comp1[i] = data->gamma_table[data->comp1[i]];
49
 
    data->green[i] = data->gamma_table[data->green[i]];
50
 
    data->comp2[i] = data->gamma_table[data->comp2[i]];
51
 
  }
52
 
 
53
 
  return 1;
 
36
        int i, x, gamma;
 
37
 
 
38
        gamma = v4lcontrol_get_ctrl(data->control, V4LCONTROL_GAMMA);
 
39
 
 
40
        if (gamma != data->last_gamma) {
 
41
                for (i = 0; i < 256; i++) {
 
42
                        x = powf(i / 255.0, 1000.0 / gamma) * 255;
 
43
                        data->gamma_table[i] = CLIP(x);
 
44
                }
 
45
                data->last_gamma = gamma;
 
46
        }
 
47
 
 
48
        for (i = 0; i < 256; i++) {
 
49
                data->comp1[i] = data->gamma_table[data->comp1[i]];
 
50
                data->green[i] = data->gamma_table[data->green[i]];
 
51
                data->comp2[i] = data->gamma_table[data->comp2[i]];
 
52
        }
 
53
 
 
54
        return 1;
54
55
}
55
56
 
56
57
struct v4lprocessing_filter gamma_filter = {
57
 
  gamma_active, gamma_calculate_lookup_tables };
 
58
        gamma_active, gamma_calculate_lookup_tables
 
59
};