Debian Codegraph @

src/filter/threshold0r/threshold0r.c

raw symbols SCIP
1 /* threshold0r.c
2 * Copyright (C) 2005 Jean-Sebastien Senecal ([email protected])
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 #include <string.h>
22 #include <assert.h>
23
24 #include "frei0r.h"cxx . . $ `<file>/include/frei0r.h`/
25
26 typedef struct threshold0r_instancecxx . . $ threshold0r_instance#
27 {
28 unsigned int widthcxx . . $ threshold0r_instance#width.;
29 unsigned int heightcxx . . $ threshold0r_instance#height.;
30 unsigned char thresholdcxx . . $ threshold0r_instance#threshold.; /* the threshold [0, 255] */
31 unsigned char lutcxx . . $ threshold0r_instance#lut.[256]; /* look-up table */
32 } threshold0r_instance_tcxx . . $ threshold0r_instance_t#;
33
34 /* Updates the look-up-table. */
35 void update_lutcxx . . $ update_lut(b6c1d8748f982c67).(threshold0r_instance_tcxx . . $ threshold0r_instance_t# *inst)
36 {
37 int i;
38 unsigned char *lut = inst->lutcxx . . $ threshold0r_instance#lut.;
39 unsigned char thresh = inst->thresholdcxx . . $ threshold0r_instance#threshold.;
40 if (thresh == 0xff)
41 memsetcxx . . $ memset(d1de1e4fb215f1c6).(lut, 0x00, 256*sizeof(unsigned char));
42 else if (thresh == 0x00)
43 memsetcxx . . $ memset(d1de1e4fb215f1c6).(lut, 0xff, 256*sizeof(unsigned char));
44 else
45 {
46 for (i=0; i<thresh; ++i)
47 lut[i] = 0x00;
48 for (i=thresh; i<256; ++i)
49 lut[i] = 0xff;
50 }
51 }
52
53 int f0r_initcxx . . $ f0r_init(b126dc7c1de90089).()
54 {
55 return 1;
56 }
57
58 void f0r_deinitcxx . . $ f0r_deinit(49f6e7a06ebc5aa8).()
59 { /* no initialization required */ }
60
61 void f0r_get_plugin_infocxx . . $ f0r_get_plugin_info(35d753456c0ea59c).(f0r_plugin_info_tcxx . . $ f0r_plugin_info_t#* threshold0r_info)
62 {
63 threshold0r_info->namecxx . . $ f0r_plugin_info#name. = "Threshold0r";
64 threshold0r_info->authorcxx . . $ f0r_plugin_info#author. = "Jean-Sebastien Senecal";
65 threshold0r_info->plugin_typecxx . . $ f0r_plugin_info#plugin_type. = F0R_PLUGIN_TYPE_FILTERcxx . . $ `include/frei0r.h:247:9`!;
66 threshold0r_info->color_modelcxx . . $ f0r_plugin_info#color_model. = F0R_COLOR_MODEL_RGBA8888cxx . . $ `include/frei0r.h:308:9`!;
67 threshold0r_info->frei0r_versioncxx . . $ f0r_plugin_info#frei0r_version. = FREI0R_MAJOR_VERSIONcxx . . $ `include/frei0r.h:217:9`!;
68 threshold0r_info->major_versioncxx . . $ f0r_plugin_info#major_version. = 0;
69 threshold0r_info->minor_versioncxx . . $ f0r_plugin_info#minor_version. = 2;
70 threshold0r_info->num_paramscxx . . $ f0r_plugin_info#num_params. = 1;
71 threshold0r_info->explanationcxx . . $ f0r_plugin_info#explanation. = "Thresholds a source image";
72 }
73
74 void f0r_get_param_infocxx . . $ f0r_get_param_info(a9f9aa7954cc4a37).(f0r_param_info_tcxx . . $ f0r_param_info_t#* info, int param_index)
75 {
76 switch(param_index)
77 {
78 case 0:
79 info->namecxx . . $ f0r_param_info#name. = "Threshold";
80 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
81 info->explanationcxx . . $ f0r_param_info#explanation. = "The threshold";
82 break;
83 }
84 }
85
86 f0r_instance_tcxx . . $ f0r_instance_t# f0r_constructcxx . . $ f0r_construct(da3f471cd007a696).(unsigned int width, unsigned int height)
87 {
88 threshold0r_instance_tcxx . . $ threshold0r_instance_t#* inst = (threshold0r_instance_tcxx . . $ threshold0r_instance_t#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(*inst));
89 inst->widthcxx . . $ threshold0r_instance#width. = width; inst->heightcxx . . $ threshold0r_instance#height. = height;
90 /* init look-up-table */
91 update_lutcxx . . $ update_lut(b6c1d8748f982c67).(inst);
92 return (f0r_instance_tcxx . . $ f0r_instance_t#)inst;
93 }
94
95 void f0r_destructcxx . . $ f0r_destruct(5d22bdacc48458e8).(f0r_instance_tcxx . . $ f0r_instance_t# instance)
96 {
97 freecxx . . $ free(5d22bdacc48458e8).(instance);
98 }
99
100 void f0r_set_param_valuecxx . . $ f0r_set_param_value(5be095a8278d2bf5).(f0r_instance_tcxx . . $ f0r_instance_t# instance,
101 f0r_param_tcxx . . $ f0r_param_t# param, int param_index)
102 {
103 assertcxx . . $ `<external>/4398592474888995393/assert.h:77:11`!(instance);
104 threshold0r_instance_tcxx . . $ threshold0r_instance_t#* inst = (threshold0r_instance_tcxx . . $ threshold0r_instance_t#*)instance;
105
106 switch(param_index)
107 {
108 unsigned char val;
109 case 0:
110 /* threshold */
111 val = (unsigned char) (255.0 * *((double*)param));
112 if (val != inst->thresholdcxx . . $ threshold0r_instance#threshold.)
113 {
114 inst->thresholdcxx . . $ threshold0r_instance#threshold. = val;
115 update_lutcxx . . $ update_lut(b6c1d8748f982c67).(inst);
116 }
117 break;
118 }
119 }
120
121 void f0r_get_param_valuecxx . . $ f0r_get_param_value(5be095a8278d2bf5).(f0r_instance_tcxx . . $ f0r_instance_t# instance,
122 f0r_param_tcxx . . $ f0r_param_t# param, int param_index)
123 {
124 assertcxx . . $ `<external>/4398592474888995393/assert.h:77:11`!(instance);
125 threshold0r_instance_tcxx . . $ threshold0r_instance_t#* inst = (threshold0r_instance_tcxx . . $ threshold0r_instance_t#*)instance;
126
127 switch(param_index)
128 {
129 case 0:
130 *((double*)param) = (double)(inst->thresholdcxx . . $ threshold0r_instance#threshold.) / 255.0;
131 break;
132 }
133 }
134
135 void f0r_updatecxx . . $ f0r_update(96cd7b27f2fca8a7).(f0r_instance_tcxx . . $ f0r_instance_t# instance, double time,
136 const uint32_tcxx . . $ uint32_t#* inframe, uint32_tcxx . . $ uint32_t#* outframe)
137 {
138 assertcxx . . $ `<external>/4398592474888995393/assert.h:77:11`!(instance);
139 threshold0r_instance_tcxx . . $ threshold0r_instance_t#* inst = (threshold0r_instance_tcxx . . $ threshold0r_instance_t#*)instance;
140 unsigned int len = inst->widthcxx . . $ threshold0r_instance#width. * inst->heightcxx . . $ threshold0r_instance#height.;
141
142 unsigned char* lut = inst->lutcxx . . $ threshold0r_instance#lut.;
143 unsigned char* dst = (unsigned char*)outframe;
144 const unsigned char* src = (unsigned char*)inframe;
145 while (len--)
146 {
147 *dst++ = lut[*src++];
148 *dst++ = lut[*src++];
149 *dst++ = lut[*src++];
150 *dst++ = *src++; // copy alpha
151 }
152 }
153