Debian Codegraph @

src/filter/softglow/softglow.c

raw symbols SCIP
1 /*
2 * This file is a modified port of Softglow plug-in from Gimp.
3 * It contains code from plug-ins/common/softglow.c, see that for copyrights.
4 *
5 * softglow.c
6 * Copyright 2012 Janne Liljeblad
7 *
8 * This file is a Frei0r plugin.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25
26 #include <stdlib.h>
27 #include <assert.h>
28 #include <math.h>
29 #include "frei0r.h"cxx . . $ `<file>/include/frei0r.h`/
30 #include "frei0r/blur.h"cxx . . $ `<file>/include/frei0r/blur.h`/
31 #include "frei0r/math.h"cxx . . $ `<file>/include/frei0r/math.h`/
32
33 #define SIGMOIDAL_BASEcxx . . $ `src/filter/softglow/softglow.c:33:9`! 2
34 #define SIGMOIDAL_RANGEcxx . . $ `src/filter/softglow/softglow.c:34:9`! 20
35 #define NBYTEScxx . . $ `src/filter/softglow/softglow.c:35:9`! 4
36 #define ALPHAcxx . . $ `src/filter/softglow/softglow.c:36:9`! 3
37
38 double PIcxx . . $ PI.=3.14159265358979;
39
40 typedef struct softglow_instancecxx . . $ softglow_instance#
41 {
42 unsigned int widthcxx . . $ softglow_instance#width.;
43 unsigned int heightcxx . . $ softglow_instance#height.;
44 double blurcxx . . $ softglow_instance#blur.;
45 double brightnesscxx . . $ softglow_instance#brightness.;
46 double sharpnesscxx . . $ softglow_instance#sharpness.;
47 double blendtypecxx . . $ softglow_instance#blendtype.;
48 f0r_instance_tcxx . . $ f0r_instance_t#* blur_instancecxx . . $ softglow_instance#blur_instance.;
49 uint32_tcxx . . $ uint32_t#* sigm_framecxx . . $ softglow_instance#sigm_frame.;
50 uint32_tcxx . . $ uint32_t#* blurredcxx . . $ softglow_instance#blurred.;
51 } softglow_instance_tcxx . . $ softglow_instance_t#;
52
53 void overlaycxx . . $ overlay(2ff1da390bbe518f).(const uint32_tcxx . . $ uint32_t#* source1, const uint32_tcxx . . $ uint32_t#* source2, uint32_tcxx . . $ uint32_t#* out, unsigned int len)
54 {
55 unsigned char* src1 = (unsigned char*)source1;
56 unsigned char* src2 = (unsigned char*)source2;
57 unsigned char* dst = (unsigned char*)out;
58
59 uint32_tcxx . . $ uint32_t# b, tmp, tmpM;
60
61 while (len--)
62 {
63 for (b = 0; b < ALPHAcxx . . $ `src/filter/softglow/softglow.c:36:9`!; b++)
64 {
65 dst[b] = INT_MULTcxx . . $ `include/frei0r/math.h:31:9`!(src1[b], src1[b] + INT_MULTcxx . . $ `include/frei0r/math.h:31:9`!(2 * src2[b], 255 - src1[b], tmpM), tmp);
66 }
67
68 dst[ALPHAcxx . . $ `src/filter/softglow/softglow.c:36:9`!] = MINcxx . . $ `include/frei0r/math.h:67:9`!(src1[ALPHAcxx . . $ `src/filter/softglow/softglow.c:36:9`!], src2[ALPHAcxx . . $ `src/filter/softglow/softglow.c:36:9`!]);
69
70 src1 += NBYTEScxx . . $ `src/filter/softglow/softglow.c:35:9`!;
71 src2 += NBYTEScxx . . $ `src/filter/softglow/softglow.c:35:9`!;
72 dst += NBYTEScxx . . $ `src/filter/softglow/softglow.c:35:9`!;
73 }
74 }
75
76 void screencxx . . $ screen(2ff1da390bbe518f).(const uint32_tcxx . . $ uint32_t#* source1, const uint32_tcxx . . $ uint32_t#* source2, uint32_tcxx . . $ uint32_t#* out, unsigned int len)
77 {
78 unsigned char* src1 = (unsigned char*)source1;
79 unsigned char* src2 = (unsigned char*)source2;
80 unsigned char* dst = (unsigned char*)out;
81
82 uint32_tcxx . . $ uint32_t# b, tmp;
83
84 while (len--)
85 {
86 for (b = 0; b < ALPHAcxx . . $ `src/filter/softglow/softglow.c:36:9`!; b++)
87 dst[b] = 255 - INT_MULTcxx . . $ `include/frei0r/math.h:31:9`!((255 - src1[b]), (255 - src2[b]), tmp);
88
89 dst[ALPHAcxx . . $ `src/filter/softglow/softglow.c:36:9`!] = MINcxx . . $ `include/frei0r/math.h:67:9`!(src1[ALPHAcxx . . $ `src/filter/softglow/softglow.c:36:9`!], src2[ALPHAcxx . . $ `src/filter/softglow/softglow.c:36:9`!]);
90
91 src1 += NBYTEScxx . . $ `src/filter/softglow/softglow.c:35:9`!;
92 src2 += NBYTEScxx . . $ `src/filter/softglow/softglow.c:35:9`!;
93 dst += NBYTEScxx . . $ `src/filter/softglow/softglow.c:35:9`!;
94 }
95 }
96
97 void addcxx . . $ add(2ff1da390bbe518f).(const uint32_tcxx . . $ uint32_t#* source1, const uint32_tcxx . . $ uint32_t#* source2, uint32_tcxx . . $ uint32_t#* out, unsigned int len)
98 {
99 unsigned char* src1 = (unsigned char*)source1;
100 unsigned char* src2 = (unsigned char*)source2;
101 unsigned char* dst = (unsigned char*)out;
102
103 uint32_tcxx . . $ uint32_t# b, val;
104
105 while (len--)
106 {
107 for (b = 0; b < ALPHAcxx . . $ `src/filter/softglow/softglow.c:36:9`!; b++)
108 {
109 val = src1[b] + src2[b];
110 dst[b] = CLAMPcxx . . $ `include/frei0r/math.h:48:9`!(val, 0, 255);
111 }
112
113 dst[ALPHAcxx . . $ `src/filter/softglow/softglow.c:36:9`!] = MINcxx . . $ `include/frei0r/math.h:67:9`!(src1[ALPHAcxx . . $ `src/filter/softglow/softglow.c:36:9`!], src2[ALPHAcxx . . $ `src/filter/softglow/softglow.c:36:9`!]);
114
115 src1 += NBYTEScxx . . $ `src/filter/softglow/softglow.c:35:9`!;
116 src2 += NBYTEScxx . . $ `src/filter/softglow/softglow.c:35:9`!;
117 dst += NBYTEScxx . . $ `src/filter/softglow/softglow.c:35:9`!;
118 }
119 }
120
121 int
122 gimp_rgb_to_l_intcxx . . $ gimp_rgb_to_l_int(2326284602b0bb2d). (int red,
123 int green,
124 int blue)
125 {
126 int min, max;
127
128 if (red > green)
129 {
130 max = MAXcxx . . $ `include/frei0r/math.h:71:9`! (red, blue);
131 min = MINcxx . . $ `include/frei0r/math.h:67:9`! (green, blue);
132 }
133 else
134 {
135 max = MAXcxx . . $ `include/frei0r/math.h:71:9`! (green, blue);
136 min = MINcxx . . $ `include/frei0r/math.h:67:9`! (red, blue);
137 }
138
139 return ROUNDcxx . . $ `include/frei0r/math.h:53:9`! ((max + min) / 2.0);
140 }
141
142 int f0r_initcxx . . $ f0r_init(b126dc7c1de90089).()
143 {
144 return 1;
145 }
146
147 void f0r_deinitcxx . . $ f0r_deinit(49f6e7a06ebc5aa8).()
148 { /* no initialization required */ }
149
150 void f0r_get_plugin_infocxx . . $ f0r_get_plugin_info(35d753456c0ea59c).(f0r_plugin_info_tcxx . . $ f0r_plugin_info_t#* softglowInfo)
151 {
152 softglowInfo->namecxx . . $ f0r_plugin_info#name. = "softglow";
153 softglowInfo->authorcxx . . $ f0r_plugin_info#author. = "Janne Liljeblad";
154 softglowInfo->plugin_typecxx . . $ f0r_plugin_info#plugin_type. = F0R_PLUGIN_TYPE_FILTERcxx . . $ `include/frei0r.h:247:9`!;
155 softglowInfo->color_modelcxx . . $ f0r_plugin_info#color_model. = F0R_COLOR_MODEL_RGBA8888cxx . . $ `include/frei0r.h:308:9`!;
156 softglowInfo->frei0r_versioncxx . . $ f0r_plugin_info#frei0r_version. = FREI0R_MAJOR_VERSIONcxx . . $ `include/frei0r.h:217:9`!;
157 softglowInfo->major_versioncxx . . $ f0r_plugin_info#major_version. = 0;
158 softglowInfo->minor_versioncxx . . $ f0r_plugin_info#minor_version. = 9;
159 softglowInfo->num_paramscxx . . $ f0r_plugin_info#num_params. = 4;
160 softglowInfo->explanationcxx . . $ f0r_plugin_info#explanation. = "Does softglow effect on highlights";
161 }
162
163 void f0r_get_param_infocxx . . $ f0r_get_param_info(a9f9aa7954cc4a37).(f0r_param_info_tcxx . . $ f0r_param_info_t#* info, int param_index)
164 {
165 switch ( param_index ) {
166 case 0:
167 info->namecxx . . $ f0r_param_info#name. = "blur";
168 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
169 info->explanationcxx . . $ f0r_param_info#explanation. = "Blur of the glow";
170 break;
171 case 1:
172 info->namecxx . . $ f0r_param_info#name. = "brightness";
173 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
174 info->explanationcxx . . $ f0r_param_info#explanation. = "Brightness of highlight areas";
175 break;
176 case 2:
177 info->namecxx . . $ f0r_param_info#name. = "sharpness";
178 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
179 info->explanationcxx . . $ f0r_param_info#explanation. = "Sharpness of highlight areas";
180 break;
181 case 3: // 0 - 0.33 screen, 0.33 - 0.66 overla7, 0.66 - 1.0 add
182 info->namecxx . . $ f0r_param_info#name. = "blurblend";
183 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
184 info->explanationcxx . . $ f0r_param_info#explanation. = "Blend mode used to blend highlight blur with input image";
185 break;
186 }
187 }
188
189 f0r_instance_tcxx . . $ f0r_instance_t# f0r_constructcxx . . $ f0r_construct(da3f471cd007a696).(unsigned int width, unsigned int height)
190 {
191 softglow_instance_tcxx . . $ softglow_instance_t#* inst = (softglow_instance_tcxx . . $ softglow_instance_t#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(*inst));
192 inst->widthcxx . . $ softglow_instance#width. = width;
193 inst->heightcxx . . $ softglow_instance#height. = height;
194 inst->blurcxx . . $ softglow_instance#blur. = 0.5;
195 inst->brightnesscxx . . $ softglow_instance#brightness. = 0.75;
196 inst->sharpnesscxx . . $ softglow_instance#sharpness. = 0.85;
197 inst->blendtypecxx . . $ softglow_instance#blendtype. = 0.0;
198 inst->blur_instancecxx . . $ softglow_instance#blur_instance. = (f0r_instance_tcxx . . $ f0r_instance_t# *)blur_constructcxx . . $ blur_construct(da3f471cd007a696).(width, height);
199 inst->sigm_framecxx . . $ softglow_instance#sigm_frame. = (uint32_tcxx . . $ uint32_t#*)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(width * height * sizeof(uint32_tcxx . . $ uint32_t#));
200 inst->blurredcxx . . $ softglow_instance#blurred. = (uint32_tcxx . . $ uint32_t#*)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(width * height * sizeof(uint32_tcxx . . $ uint32_t#));
201 return (f0r_instance_tcxx . . $ f0r_instance_t#)inst;
202 }
203
204 void f0r_destructcxx . . $ f0r_destruct(5d22bdacc48458e8).(f0r_instance_tcxx . . $ f0r_instance_t# instance)
205 {
206 softglow_instance_tcxx . . $ softglow_instance_t#* inst = (softglow_instance_tcxx . . $ softglow_instance_t#*)instance;
207 blur_destructcxx . . $ blur_destruct(5d22bdacc48458e8).(inst->blur_instancecxx . . $ softglow_instance#blur_instance.);
208 freecxx . . $ free(5d22bdacc48458e8).(inst->sigm_framecxx . . $ softglow_instance#sigm_frame.);
209 freecxx . . $ free(5d22bdacc48458e8).(inst->blurredcxx . . $ softglow_instance#blurred.);
210 freecxx . . $ free(5d22bdacc48458e8).(instance);
211 }
212
213 void f0r_set_param_valuecxx . . $ f0r_set_param_value(5be095a8278d2bf5).(f0r_instance_tcxx . . $ f0r_instance_t# instance,
214 f0r_param_tcxx . . $ f0r_param_t# param, int param_index)
215 {
216 softglow_instance_tcxx . . $ softglow_instance_t#* inst = (softglow_instance_tcxx . . $ softglow_instance_t#*)instance;
217 switch (param_index)
218 {
219 case 0:
220 inst->blurcxx . . $ softglow_instance#blur. = *((double*)param);
221 blur_set_param_valuecxx . . $ blur_set_param_value(5be095a8278d2bf5).(inst->blur_instancecxx . . $ softglow_instance#blur_instance., &inst->blurcxx . . $ softglow_instance#blur., 0 );
222 break;
223 case 1:
224 inst->brightnesscxx . . $ softglow_instance#brightness. = *((double*)param);
225 break;
226 case 2:
227 inst->sharpnesscxx . . $ softglow_instance#sharpness. = *((double*)param);
228 break;
229 case 3:
230 inst->blendtypecxx . . $ softglow_instance#blendtype. = *((double*)param);
231 break;
232 }
233 }
234
235 void f0r_get_param_valuecxx . . $ f0r_get_param_value(5be095a8278d2bf5).(f0r_instance_tcxx . . $ f0r_instance_t# instance,
236 f0r_param_tcxx . . $ f0r_param_t# param, int param_index)
237 {
238 softglow_instance_tcxx . . $ softglow_instance_t#* inst = (softglow_instance_tcxx . . $ softglow_instance_t#*)instance;
239 switch (param_index)
240 {
241 case 0:
242 *((double*)param) = inst->blurcxx . . $ softglow_instance#blur.;
243 break;
244 case 1:
245 *((double*)param) = inst->brightnesscxx . . $ softglow_instance#brightness.;
246 break;
247 case 2:
248 *((double*)param) = inst->sharpnesscxx . . $ softglow_instance#sharpness.;
249 break;
250 case 3:
251 *((double*)param) = inst->blendtypecxx . . $ softglow_instance#blendtype.;
252 break;
253 }
254 }
255
256 void f0r_updatecxx . . $ f0r_update(96cd7b27f2fca8a7).(f0r_instance_tcxx . . $ f0r_instance_t# instance, double time,
257 const uint32_tcxx . . $ uint32_t#* inframe, uint32_tcxx . . $ uint32_t#* outframe)
258 {
259 // Check and cast instance
260 assertcxx . . $ `<external>/4398592474888995393/assert.h:77:11`!(instance);
261 softglow_instance_tcxx . . $ softglow_instance_t#* inst = (softglow_instance_tcxx . . $ softglow_instance_t#*)instance;
262 unsigned int len = inst->widthcxx . . $ softglow_instance#width. * inst->heightcxx . . $ softglow_instance#height.;
263
264 double brightness = inst->brightnesscxx . . $ softglow_instance#brightness.;
265 double sharpness = inst->sharpnesscxx . . $ softglow_instance#sharpness.;
266
267 const unsigned char* src = (unsigned char*)inframe;
268
269 memcpycxx . . $ memcpy(cc817cb175f282d).(inst->sigm_framecxx . . $ softglow_instance#sigm_frame., inframe, len*sizeof(uint32_tcxx . . $ uint32_t#));
270 unsigned char* dst = (unsigned char*)inst->sigm_framecxx . . $ softglow_instance#sigm_frame.;
271
272 unsigned char luma, r, g, b;
273 double val;
274 while (len--)
275 {
276 r = *src++;
277 g = *src++;
278 b = *src++;
279
280 //desaturate
281 luma = (unsigned char) gimp_rgb_to_l_intcxx . . $ gimp_rgb_to_l_int(2326284602b0bb2d). (r, g, b);
282
283 //compute sigmoidal transfer
284 val = luma / 255.0;
285 val = 255.0 / (1 + exp (-(SIGMOIDAL_BASEcxx . . $ `src/filter/softglow/softglow.c:33:9`! + (sharpness * SIGMOIDAL_RANGEcxx . . $ `src/filter/softglow/softglow.c:34:9`!)) * (val - 0.5)));
286 val = val * brightness;
287 luma = (unsigned char) CLAMPcxx . . $ `include/frei0r/math.h:48:9`! (val, 0, 255);
288
289 *dst++ = luma;
290 *dst++ = luma;
291 *dst++ = luma;
292 *dst++ = *src++;
293 }
294
295 blur_updatecxx . . $ blur_update(96cd7b27f2fca8a7).(inst->blur_instancecxx . . $ softglow_instance#blur_instance., 0.0, inst->sigm_framecxx . . $ softglow_instance#sigm_frame., inst->blurredcxx . . $ softglow_instance#blurred.);
296
297 if (inst->blendtypecxx . . $ softglow_instance#blendtype. <= 0.33)
298 screencxx . . $ screen(2ff1da390bbe518f).(inst->blurredcxx . . $ softglow_instance#blurred., inframe, outframe, inst->widthcxx . . $ softglow_instance#width. * inst->heightcxx . . $ softglow_instance#height.);
299 else if(inst->blendtypecxx . . $ softglow_instance#blendtype. <= 0.66)
300 overlaycxx . . $ overlay(2ff1da390bbe518f).(inst->blurredcxx . . $ softglow_instance#blurred., inframe, outframe, inst->widthcxx . . $ softglow_instance#width. * inst->heightcxx . . $ softglow_instance#height.);
301 else
302 addcxx . . $ add(2ff1da390bbe518f).(inst->blurredcxx . . $ softglow_instance#blurred., inframe, outframe, inst->widthcxx . . $ softglow_instance#width. * inst->heightcxx . . $ softglow_instance#height.);
303 }
304
305
306
307