Debian Codegraph @

src/filter/heatmap0r/heatmap0r.c

raw symbols SCIP
1 /*
2 * heatmap0r.c -- feel the heat, frei0r style.
3 *
4 * Copyright (C) 2025 Cynthia ([email protected])
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include <stdlib.h>
22 #include <assert.h>
23
24 #include "frei0r.h"cxx . . $ `<file>/include/frei0r.h`/
25 #include "frei0r/math.h"cxx . . $ `<file>/include/frei0r/math.h`/
26
27 typedef structcxx . . $ $anonymous_type_39d793f65b431b3a_0# {
28 unsigned int widthcxx . . $ $anonymous_type_39d793f65b431b3a_0#width., heightcxx . . $ $anonymous_type_39d793f65b431b3a_0#height.;
29 uint8_tcxx . . $ uint8_t# rlutcxx . . $ $anonymous_type_39d793f65b431b3a_0#rlut.[256], glutcxx . . $ $anonymous_type_39d793f65b431b3a_0#glut.[256], blutcxx . . $ $anonymous_type_39d793f65b431b3a_0#blut.[256];
30
31 f0r_param_color_tcxx . . $ f0r_param_color_t# blackcxx . . $ $anonymous_type_39d793f65b431b3a_0#black., greycxx . . $ $anonymous_type_39d793f65b431b3a_0#grey., whitecxx . . $ $anonymous_type_39d793f65b431b3a_0#white.;
32 double gpcxx . . $ $anonymous_type_39d793f65b431b3a_0#gp.; //< Grey point
33 } heatmap0r_tcxx . . $ heatmap0r_t#;
34
35 static void gen_heatmap0r_lutscxx . . $ gen_heatmap0r_luts(52c9d773efccafec).(heatmap0r_tcxx . . $ heatmap0r_t# *inst)
36 {
37 double luma;
38 double L0, L1, L2;
39 double gp = inst->gpcxx . . $ $anonymous_type_39d793f65b431b3a_0#gp.;
40 double l0 = 1.0 / gp,
41 l1 = 1.0 / (gp * (gp - 1.0)),
42 l2 = 1.0 / (1.0 - gp);
43
44 f0r_param_color_tcxx . . $ f0r_param_color_t# black = inst->blackcxx . . $ $anonymous_type_39d793f65b431b3a_0#black.,
45 grey = inst->greycxx . . $ $anonymous_type_39d793f65b431b3a_0#grey.,
46 white = inst->whitecxx . . $ $anonymous_type_39d793f65b431b3a_0#white.;
47
48 for (int i = 0; i < 256; ++i)
49 {
50 luma = 1.0 / 255.0 * (double)i;
51
52 L0 = (luma - gp) * (luma - 1.0) * l0;
53 L1 = luma * (luma - 1.0) * l1;
54 L2 = luma * (luma - gp) * l2;
55
56 inst->rlutcxx . . $ $anonymous_type_39d793f65b431b3a_0#rlut.[i] = CLAMPcxx . . $ `include/frei0r/math.h:48:9`!(255.0 * (L0 * black.r + L1 * grey.r + L2 * white.r), 0, 255);
57 inst->glutcxx . . $ $anonymous_type_39d793f65b431b3a_0#glut.[i] = CLAMPcxx . . $ `include/frei0r/math.h:48:9`!(255.0 * (L0 * black.g + L1 * grey.g + L2 * white.g), 0, 255);
58 inst->blutcxx . . $ $anonymous_type_39d793f65b431b3a_0#blut.[i] = CLAMPcxx . . $ `include/frei0r/math.h:48:9`!(255.0 * (L0 * black.b + L1 * grey.b + L2 * white.b), 0, 255);
59 }
60 }
61
62 int f0r_initcxx . . $ f0r_init(b126dc7c1de90089).()
63 {
64 return 1;
65 }
66
67 void f0r_deinitcxx . . $ f0r_deinit(49f6e7a06ebc5aa8).() {}
68
69 f0r_instance_tcxx . . $ f0r_instance_t# f0r_constructcxx . . $ f0r_construct(da3f471cd007a696).(unsigned int width, unsigned int height)
70 {
71 heatmap0r_tcxx . . $ heatmap0r_t#* inst = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(*inst));
72
73 inst->widthcxx . . $ $anonymous_type_39d793f65b431b3a_0#width. = width; inst->heightcxx . . $ $anonymous_type_39d793f65b431b3a_0#height. = height;
74 inst->gpcxx . . $ $anonymous_type_39d793f65b431b3a_0#gp. = 0.5;
75 inst->whitecxx . . $ $anonymous_type_39d793f65b431b3a_0#white. = (f0r_param_color_tcxx . . $ f0r_param_color_t#) {/* Yellow */ 1.0, 1.0, 0.0};
76 inst->greycxx . . $ $anonymous_type_39d793f65b431b3a_0#grey. = (f0r_param_color_tcxx . . $ f0r_param_color_t#) {/* Deeppink */ 1.0, 0.0, 0.5};
77 inst->blackcxx . . $ $anonymous_type_39d793f65b431b3a_0#black. = (f0r_param_color_tcxx . . $ f0r_param_color_t#) {/* Darkviolet */ 0.27, 0.0, 0.5};
78
79 gen_heatmap0r_lutscxx . . $ gen_heatmap0r_luts(52c9d773efccafec). (inst);
80
81 return (f0r_instance_tcxx . . $ f0r_instance_t#)inst;
82 }
83
84 void f0r_destructcxx . . $ f0r_destruct(5d22bdacc48458e8).(f0r_instance_tcxx . . $ f0r_instance_t# instance)
85 {
86 freecxx . . $ free(5d22bdacc48458e8).(instance);
87 }
88
89 void f0r_get_plugin_infocxx . . $ f0r_get_plugin_info(35d753456c0ea59c).(f0r_plugin_info_tcxx . . $ f0r_plugin_info_t#* info)
90 {
91 info->namecxx . . $ f0r_plugin_info#name. = "heatmap0r";
92 info->authorcxx . . $ f0r_plugin_info#author. = "Cynthia";
93 info->plugin_typecxx . . $ f0r_plugin_info#plugin_type. = F0R_PLUGIN_TYPE_FILTERcxx . . $ `include/frei0r.h:247:9`!;
94 info->color_modelcxx . . $ f0r_plugin_info#color_model. = F0R_COLOR_MODEL_RGBA8888cxx . . $ `include/frei0r.h:308:9`!;
95 info->frei0r_versioncxx . . $ f0r_plugin_info#frei0r_version. = FREI0R_MAJOR_VERSIONcxx . . $ `include/frei0r.h:217:9`!;
96 info->major_versioncxx . . $ f0r_plugin_info#major_version. = 0;
97 info->minor_versioncxx . . $ f0r_plugin_info#minor_version. = 1;
98 info->num_paramscxx . . $ f0r_plugin_info#num_params. = 4;
99 info->explanationcxx . . $ f0r_plugin_info#explanation. = "Performs a continuous trichromatic tinting";
100 }
101
102 void f0r_get_param_infocxx . . $ f0r_get_param_info(a9f9aa7954cc4a37).(f0r_param_info_tcxx . . $ f0r_param_info_t#* info, int param_index)
103 {
104 switch(param_index)
105 {
106 case 0:
107 info->namecxx . . $ f0r_param_info#name. = "Map black to";
108 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_COLORcxx . . $ `include/frei0r.h:389:9`!;
109 info->explanationcxx . . $ f0r_param_info#explanation. = "The color to map source color with zero luminance";
110 break;
111 case 1:
112 info->namecxx . . $ f0r_param_info#name. = "Map grey to";
113 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_COLORcxx . . $ `include/frei0r.h:389:9`!;
114 info->explanationcxx . . $ f0r_param_info#explanation. = "The color to map source color with mid luminance";
115 break;
116 case 2:
117 info->namecxx . . $ f0r_param_info#name. = "Map white to";
118 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_COLORcxx . . $ `include/frei0r.h:389:9`!;
119 info->explanationcxx . . $ f0r_param_info#explanation. = "The color to map source color with full luminance";
120 break;
121 case 3:
122 info->namecxx . . $ f0r_param_info#name. = "Grey point";
123 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
124 info->explanationcxx . . $ f0r_param_info#explanation. = "Point in the luminance axis grey color is located";
125 break;
126 }
127 }
128
129 void f0r_set_param_valuecxx . . $ f0r_set_param_value(5be095a8278d2bf5).(f0r_instance_tcxx . . $ f0r_instance_t# instance,
130 f0r_param_tcxx . . $ f0r_param_t# param, int param_index)
131 {
132 assertcxx . . $ `<external>/4398592474888995393/assert.h:77:11`!(instance);
133 heatmap0r_tcxx . . $ heatmap0r_t#* inst = (heatmap0r_tcxx . . $ heatmap0r_t#*)instance;
134
135 switch(param_index)
136 {
137 case 0:
138 inst->blackcxx . . $ $anonymous_type_39d793f65b431b3a_0#black. = *((f0r_param_color_tcxx . . $ f0r_param_color_t# *)param);
139 break;
140 case 1:
141 inst->greycxx . . $ $anonymous_type_39d793f65b431b3a_0#grey. = *((f0r_param_color_tcxx . . $ f0r_param_color_t# *)param);
142 break;
143 case 2:
144 inst->whitecxx . . $ $anonymous_type_39d793f65b431b3a_0#white. = *((f0r_param_color_tcxx . . $ f0r_param_color_t# *)param);
145 break;
146 case 3:
147 inst->gpcxx . . $ $anonymous_type_39d793f65b431b3a_0#gp. = *((double *)param);
148 break;
149 }
150
151 gen_heatmap0r_lutscxx . . $ gen_heatmap0r_luts(52c9d773efccafec). (inst);
152 }
153
154 void f0r_get_param_valuecxx . . $ f0r_get_param_value(5be095a8278d2bf5).(f0r_instance_tcxx . . $ f0r_instance_t# instance,
155 f0r_param_tcxx . . $ f0r_param_t# param, int param_index)
156 {
157 assertcxx . . $ `<external>/4398592474888995393/assert.h:77:11`!(instance);
158 heatmap0r_tcxx . . $ heatmap0r_t#* inst = (heatmap0r_tcxx . . $ heatmap0r_t#*)instance;
159
160 switch(param_index)
161 {
162 case 0:
163 *((f0r_param_color_tcxx . . $ f0r_param_color_t#*)param) = inst->blackcxx . . $ $anonymous_type_39d793f65b431b3a_0#black.;
164 break;
165 case 1:
166 *((f0r_param_color_tcxx . . $ f0r_param_color_t#*)param) = inst->greycxx . . $ $anonymous_type_39d793f65b431b3a_0#grey.;
167 break;
168 case 2:
169 *((f0r_param_color_tcxx . . $ f0r_param_color_t#*)param) = inst->whitecxx . . $ $anonymous_type_39d793f65b431b3a_0#white.;
170 break;
171 case 3:
172 *((double *)param) = inst->gpcxx . . $ $anonymous_type_39d793f65b431b3a_0#gp.;
173 break;
174 }
175 }
176
177 void f0r_updatecxx . . $ f0r_update(96cd7b27f2fca8a7).(f0r_instance_tcxx . . $ f0r_instance_t# instance, double time,
178 const uint32_tcxx . . $ uint32_t#* inframe, uint32_tcxx . . $ uint32_t#* outframe)
179 {
180 assertcxx . . $ `<external>/4398592474888995393/assert.h:77:11`!(instance);
181 heatmap0r_tcxx . . $ heatmap0r_t#* inst = (heatmap0r_tcxx . . $ heatmap0r_t#*)instance;
182 unsigned int len = inst->widthcxx . . $ $anonymous_type_39d793f65b431b3a_0#width. * inst->heightcxx . . $ $anonymous_type_39d793f65b431b3a_0#height.;
183
184 const unsigned char* src = (void*)inframe;
185 unsigned char* dst = (void*)outframe;
186
187 unsigned char luma, r, g, b;
188 while (len--)
189 {
190 r = *src++;
191 g = *src++;
192 b = *src++;
193
194 luma = 0.299 * r + 0.587 * g + 0.114 * b;
195
196 *dst++ = inst->rlutcxx . . $ $anonymous_type_39d793f65b431b3a_0#rlut.[luma];
197 *dst++ = inst->glutcxx . . $ $anonymous_type_39d793f65b431b3a_0#glut.[luma];
198 *dst++ = inst->blutcxx . . $ $anonymous_type_39d793f65b431b3a_0#blut.[luma];
199 *dst++ = *src++;
200 }
201 }