2 #include "colormodels.h"
6 #include "rgb601window.h"
12 #define _(String) gettext(String)
13 #define gettext_noop(String) String
14 #define N_(String) gettext_noop (String)
16 REGISTER_PLUGIN(RGB601Main)
21 RGB601Config::RGB601Config()
26 RGB601Main::RGB601Main(PluginServer *server)
27 : PluginVClient(server)
29 PLUGIN_CONSTRUCTOR_MACRO
32 RGB601Main::~RGB601Main()
34 PLUGIN_DESTRUCTOR_MACRO
37 char* RGB601Main::plugin_title() { return _("RGB - 601"); }
38 int RGB601Main::is_realtime() { return 1; }
41 SHOW_GUI_MACRO(RGB601Main, RGB601Thread)
43 SET_STRING_MACRO(RGB601Main)
45 RAISE_WINDOW_MACRO(RGB601Main)
47 NEW_PICON_MACRO(RGB601Main)
49 void RGB601Main::update_gui()
54 thread->window->lock_window();
55 thread->window->forward->update(config.direction == 1);
56 thread->window->reverse->update(config.direction == 2);
57 thread->window->unlock_window();
61 int RGB601Main::load_defaults()
63 char directory[1024], string[1024];
64 // set the default directory
65 sprintf(directory, "%srgb601.rc", BCASTDIR);
68 defaults = new Defaults(directory);
71 config.direction = defaults->get("DIRECTION", config.direction);
75 int RGB601Main::save_defaults()
77 defaults->update("DIRECTION", config.direction);
82 void RGB601Main::load_configuration()
84 KeyFrame *prev_keyframe;
86 prev_keyframe = get_prev_keyframe(get_source_position());
87 // Must also switch between interpolation between keyframes and using first keyframe
88 read_data(prev_keyframe);
92 void RGB601Main::save_data(KeyFrame *keyframe)
96 // cause data to be stored directly in text
97 output.set_shared_string(keyframe->data, MESSAGESIZE);
98 output.tag.set_title("RGB601");
99 output.tag.set_property("DIRECTION", config.direction);
101 output.terminate_string();
104 void RGB601Main::read_data(KeyFrame *keyframe)
108 input.set_shared_string(keyframe->data, strlen(keyframe->data));
115 result = input.read_tag();
119 if(input.tag.title_is("RGB601"))
121 config.direction = input.tag.get_property("DIRECTION", config.direction);
128 thread->window->update();
133 #define CREATE_TABLE(max) \
135 for(int i = 0; i < max; i++) \
137 forward_table[i] = (int)((double)0.8588 * i + max * 0.0627 + 0.5); \
138 reverse_table[i] = (int)((double)1.1644 * i - max * 0.0627 + 0.5); \
139 CLAMP(forward_table[i], 0, max); \
140 CLAMP(reverse_table[i], 0, max); \
144 void RGB601Main::create_table(VFrame *input_ptr)
146 switch(input_ptr->get_color_model())
157 case BC_RGBA16161616:
158 case BC_YUVA16161616:
159 CREATE_TABLE(0xffff);
164 #define PROCESS(table, type, components, yuv) \
166 int bytes = w * components; \
167 for(int i = 0; i < h; i++) \
169 type *in_row = (type*)input_ptr->get_rows()[i]; \
170 type *out_row = (type*)output_ptr->get_rows()[i]; \
175 for(int j = 0; j < w; j++) \
177 out_row[j * components] = table[in_row[j * components]]; \
178 out_row[j * components + 1] = in_row[j * components + 1]; \
179 out_row[j * components + 2] = in_row[j * components + 2]; \
180 if(components == 4) out_row[j * components + 3] = in_row[j * components + 3]; \
185 for(int j = 0; j < bytes; j++) \
187 out_row[j * components] = in_row[j * components]; \
188 out_row[j * components + 1] = table[in_row[j * components + 1]]; \
189 out_row[j * components + 2] = table[in_row[j * components + 2]]; \
190 if(components == 4) out_row[j * components + 3] = table[in_row[j * components + 3]]; \
196 void RGB601Main::process(int *table, VFrame *input_ptr, VFrame *output_ptr)
198 int w = input_ptr->get_w();
199 int h = input_ptr->get_h();
201 if(config.direction == 1)
202 switch(input_ptr->get_color_model())
205 PROCESS(forward_table, unsigned char, 3, 1);
208 PROCESS(forward_table, unsigned char, 4, 1);
211 PROCESS(forward_table, u_int16_t, 3, 1);
213 case BC_YUVA16161616:
214 PROCESS(forward_table, u_int16_t, 4, 1);
217 PROCESS(forward_table, unsigned char, 3, 0);
220 PROCESS(forward_table, unsigned char, 4, 0);
223 PROCESS(forward_table, u_int16_t, 3, 0);
225 case BC_RGBA16161616:
226 PROCESS(forward_table, u_int16_t, 4, 0);
230 if(config.direction == 2)
231 switch(input_ptr->get_color_model())
234 PROCESS(reverse_table, unsigned char, 3, 1);
237 PROCESS(reverse_table, unsigned char, 4, 1);
240 PROCESS(reverse_table, u_int16_t, 3, 1);
242 case BC_YUVA16161616:
243 PROCESS(reverse_table, u_int16_t, 4, 1);
246 PROCESS(reverse_table, unsigned char, 3, 0);
249 PROCESS(reverse_table, unsigned char, 4, 0);
252 PROCESS(reverse_table, u_int16_t, 3, 0);
254 case BC_RGBA16161616:
255 PROCESS(reverse_table, u_int16_t, 4, 0);
259 if(input_ptr->get_rows()[0] != output_ptr->get_rows()[0])
260 output_ptr->copy_from(input_ptr);
263 int RGB601Main::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
265 load_configuration();
267 create_table(input_ptr);
268 if(config.direction == 1)
269 process(forward_table, input_ptr, output_ptr);
271 if(config.direction == 2)
272 process(reverse_table, input_ptr, output_ptr);
274 if(input_ptr->get_rows()[0] != output_ptr->get_rows()[0])
275 output_ptr->copy_from(input_ptr);