Debian Codegraph @

src/filter/spillsupress/spillsupress.c

raw symbols SCIP
1 /*
2 * spillsupress.c
3 * Copyright 2012 Janne Liljeblad
4 *
5 * This file is a Frei0r plugin.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include <stdlib.h>
23 #include <assert.h>
24 #include <string.h>
25
26 #include "frei0r.h"
27
28 void green_limited_by_blue(unsigned int len, const uint32_t* inframe, uint32_t* outframe)
29 {
30
31 unsigned char* dst = (unsigned char*)outframe;
32 const unsigned char* src = (unsigned char*)inframe;
33 unsigned char b = 0;
34 unsigned char g = 0;
35
36 while (len--)
37 {
38 *dst++ = *src++;
39 g = *src++;
40 dst++;
41 b = *src++;
42 dst++;
43 *dst++ = *src++;
44
45 if( g > b )
46 {
47 *(dst - 3) = b;
48 *(dst - 2) = b;
49 }
50 else
51 {
52 *(dst - 3) = g;
53 *(dst - 2) = b;
54 }
55
56 }
57 }
58
59 void blue_limited_by_green(unsigned int len, const uint32_t* inframe, uint32_t* outframe)
60 {
61
62 unsigned char* dst = (unsigned char*)outframe;
63 const unsigned char* src = (unsigned char*)inframe;
64 unsigned char b = 0;
65 unsigned char g = 0;
66
67 while (len--)
68 {
69 *dst++ = *src++;
70 g = *src++;
71 dst++;
72 b = *src++;
73 dst++;
74 *dst++ = *src++;
75
76 if( b > g )
77 {
78 *(dst - 3) = g;
79 *(dst - 2) = g;
80 }
81 else
82 {
83 *(dst - 3) = g;
84 *(dst - 2) = b;
85 }
86
87 }
88 }
89
90 typedef struct spillsupress_instance
91 {
92 unsigned int width;
93 unsigned int height;
94 double supress_type; /* type of spill suppression applied to image
95 <= 0.5, green suppress
96 > 0.5, blue suppress */
97 } spillsupress_instance_t;
98
99 int f0r_init()
100 {
101 return 1;
102 }
103
104 void f0r_deinit()
105 { /* no initialization required */ }
106
107 void f0r_get_plugin_info(f0r_plugin_info_t* spillsupress_info)
108 {
109 spillsupress_info->name = "spillsupress";
110 spillsupress_info->author = "Janne Liljeblad";
111 spillsupress_info->plugin_type = F0R_PLUGIN_TYPE_FILTER;
112 spillsupress_info->color_model = F0R_COLOR_MODEL_RGBA8888;
113 spillsupress_info->frei0r_version = FREI0R_MAJOR_VERSION;
114 spillsupress_info->major_version = 0;
115 spillsupress_info->minor_version = 1;
116 spillsupress_info->num_params = 1;
117 spillsupress_info->explanation = "Remove green or blue spill light from subjects shot in front of green or blue screen";
118 }
119
120 void f0r_get_param_info(f0r_param_info_t* info, int param_index)
121 {
122 switch(param_index)
123 {
124 case 0:
125 info->name = "supresstype";
126 info->type = F0R_PARAM_DOUBLE;
127 info->explanation = "Defines if green or blue screen spill suppress is applied";
128 break;
129 }
130 }
131
132 f0r_instance_t f0r_construct(unsigned int width, unsigned int height)
133 {
134 spillsupress_instance_t* inst = (spillsupress_instance_t*)calloc(1, sizeof(*inst));
135 inst->width = width;
136 inst->height = height;
137 inst->supress_type = 0.0; // default suppress type is green suppress
138 return (f0r_instance_t)inst;
139 }
140
141 void f0r_destruct(f0r_instance_t instance)
142 {
143 free(instance);
144 }
145
146 void f0r_set_param_value(f0r_instance_t instance,
147 f0r_param_t param, int param_index)
148 {
149 assert(instance);
150 spillsupress_instance_t* inst = (spillsupress_instance_t*)instance;
151
152 switch(param_index)
153 {
154 case 0:
155 inst->supress_type = *((double*)param);
156 break;
157 }
158 }
159
160 void f0r_get_param_value(f0r_instance_t instance,
161 f0r_param_t param, int param_index)
162 {
163 assert(instance);
164 spillsupress_instance_t* inst = (spillsupress_instance_t*)instance;
165
166 switch(param_index)
167 {
168 case 0:
169 *((double*)param) = inst->supress_type;
170 break;
171 }
172 }
173
174 void f0r_update(f0r_instance_t instance, double time,
175 const uint32_t* inframe, uint32_t* outframe)
176 {
177 assert(instance);
178 spillsupress_instance_t* inst = (spillsupress_instance_t*)instance;
179 unsigned int len = inst->width * inst->height;
180
181 if (inst->supress_type > 0.5)
182 {
183 blue_limited_by_green(len, inframe, outframe);
184 }
185 else
186 {
187 green_limited_by_blue(len, inframe, outframe);
188 }
189 }
190