Debian Codegraph @

src/filter/hueshift0r/hueshift0r.c

raw symbols SCIP
1 /* hueshift0r.c
2 * Copyright (C) 2005 Jean-Sebastien Senecal (Drone)
3 * This file is a Frei0r plugin.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <stdlib.h>
21 #if defined(_MSC_VER)
22 #define _USE_MATH_DEFINES
23 #endif /* _MSC_VER */
24 #include <math.h>
25 #include <assert.h>
26 #include <string.h>
27
28 #include "frei0r.h"
29 #include "matrix.h"
30
31 typedef struct hueshift0r_instance
32 {
33 unsigned int width;
34 unsigned int height;
35 int hueshift; /* the shift [0, 360] */
36 float mat[4][4];
37 } hueshift0r_instance_t;
38
39 /* Updates the shift matrix. */
40 void update_mat(hueshift0r_instance_t *inst)
41 {
42 identmat((float*)inst->mat);
43 huerotatemat(inst->mat, (float)inst->hueshift);
44 }
45
46 int f0r_init()
47 {
48 return 1;
49 }
50
51 void f0r_deinit()
52 { /* no initialization required */ }
53
54 void f0r_get_plugin_info(f0r_plugin_info_t* info)
55 {
56 info->name = "Hueshift0r";
57 info->author = "Jean-Sebastien Senecal";
58 info->plugin_type = F0R_PLUGIN_TYPE_FILTER;
59 info->color_model = F0R_COLOR_MODEL_RGBA8888;
60 info->frei0r_version = FREI0R_MAJOR_VERSION;
61 info->major_version = 0;
62 info->minor_version = 3;
63 info->num_params = 1;
64 info->explanation = "Shifts the hue of a source image";
65 }
66
67 void f0r_get_param_info(f0r_param_info_t* info, int param_index)
68 {
69 switch(param_index)
70 {
71 case 0:
72 info->name = "Hue";
73 info->type = F0R_PARAM_DOUBLE;
74 info->explanation = "The shift value";
75 break;
76 }
77 }
78
79 f0r_instance_t f0r_construct(unsigned int width, unsigned int height)
80 {
81 hueshift0r_instance_t* inst = (hueshift0r_instance_t*)calloc(1, sizeof(*inst));
82 inst->width = width; inst->height = height;
83 /* init transformation matrix */
84 inst->hueshift = 0;
85 update_mat(inst);
86 return (f0r_instance_t)inst;
87 }
88
89 void f0r_destruct(f0r_instance_t instance)
90 {
91 free(instance);
92 }
93
94 void f0r_set_param_value(f0r_instance_t instance,
95 f0r_param_t param, int param_index)
96 {
97 assert(instance);
98 hueshift0r_instance_t* inst = (hueshift0r_instance_t*)instance;
99
100 switch(param_index)
101 {
102 int val;
103 case 0:
104 /* contrast */
105 val = (int) (*((double*)param) * 360.0); /* remap to [0, 360] */
106 if (val != inst->hueshift)
107 {
108 inst->hueshift = val;
109 update_mat(inst);
110 }
111 break;
112 }
113 }
114
115 void f0r_get_param_value(f0r_instance_t instance,
116 f0r_param_t param, int param_index)
117 {
118 assert(instance);
119 hueshift0r_instance_t* inst = (hueshift0r_instance_t*)instance;
120
121 switch(param_index)
122 {
123 case 0:
124 *((double*)param) = (double) (inst->hueshift / 360.0);
125 break;
126 }
127 }
128
129 void f0r_update(f0r_instance_t instance, double time,
130 const uint32_t* inframe, uint32_t* outframe)
131 {
132 assert(instance);
133 hueshift0r_instance_t* inst = (hueshift0r_instance_t*)instance;
134 unsigned int len = inst->width * inst->height;
135
136 memcpy(outframe, inframe, len*sizeof(uint32_t));
137 applymatrix((unsigned long*)outframe, inst->mat, len);
138 }
139
140