2 #include "colormodels.h"
7 #include "rgb601window.h"
13 REGISTER_PLUGIN(RGB601Main)
18 RGB601Config::RGB601Config()
23 RGB601Main::RGB601Main(PluginServer *server)
24 : PluginVClient(server)
26 PLUGIN_CONSTRUCTOR_MACRO
29 RGB601Main::~RGB601Main()
31 PLUGIN_DESTRUCTOR_MACRO
34 char* RGB601Main::plugin_title() { return N_("RGB - 601"); }
35 int RGB601Main::is_realtime() { return 1; }
38 SHOW_GUI_MACRO(RGB601Main, RGB601Thread)
40 SET_STRING_MACRO(RGB601Main)
42 RAISE_WINDOW_MACRO(RGB601Main)
44 NEW_PICON_MACRO(RGB601Main)
46 void RGB601Main::update_gui()
51 thread->window->lock_window();
52 thread->window->forward->update(config.direction == 1);
53 thread->window->reverse->update(config.direction == 2);
54 thread->window->unlock_window();
58 int RGB601Main::load_defaults()
60 char directory[1024], string[1024];
61 // set the default directory
62 sprintf(directory, "%srgb601.rc", BCASTDIR);
65 defaults = new BC_Hash(directory);
68 config.direction = defaults->get("DIRECTION", config.direction);
72 int RGB601Main::save_defaults()
74 defaults->update("DIRECTION", config.direction);
79 void RGB601Main::load_configuration()
81 KeyFrame *prev_keyframe;
83 prev_keyframe = get_prev_keyframe(get_source_position());
84 // Must also switch between interpolation between keyframes and using first keyframe
85 read_data(prev_keyframe);
89 void RGB601Main::save_data(KeyFrame *keyframe)
93 // cause data to be stored directly in text
94 output.set_shared_string(keyframe->data, MESSAGESIZE);
95 output.tag.set_title("RGB601");
96 output.tag.set_property("DIRECTION", config.direction);
98 output.terminate_string();
101 void RGB601Main::read_data(KeyFrame *keyframe)
105 input.set_shared_string(keyframe->data, strlen(keyframe->data));
112 result = input.read_tag();
116 if(input.tag.title_is("RGB601"))
118 config.direction = input.tag.get_property("DIRECTION", config.direction);
125 thread->window->update();
130 #define CREATE_TABLE(max) \
132 for(int i = 0; i < max; i++) \
134 int forward_output = (int)((double)0.8588 * i + max * 0.0627 + 0.5); \
135 int reverse_output = (int)((double)1.1644 * i - max * 0.0627 + 0.5); \
136 forward_table[i] = CLIP(forward_output, 0, max - 1); \
137 reverse_table[i] = CLIP(reverse_output, 0, max - 1); \
141 void RGB601Main::create_table(VFrame *input_ptr)
143 switch(input_ptr->get_color_model())
154 case BC_RGBA16161616:
155 case BC_YUVA16161616:
156 CREATE_TABLE(0x10000);
161 #define PROCESS(table, type, components, yuv) \
163 int bytes = w * components; \
164 for(int i = 0; i < h; i++) \
166 type *in_row = (type*)input_ptr->get_rows()[i]; \
167 type *out_row = (type*)output_ptr->get_rows()[i]; \
172 for(int j = 0; j < w; j++) \
174 out_row[j * components] = table[(int)in_row[j * components]]; \
175 out_row[j * components + 1] = in_row[j * components + 1]; \
176 out_row[j * components + 2] = in_row[j * components + 2]; \
180 if(sizeof(type) == 4) \
182 for(int j = 0; j < w; j++) \
184 if(table == forward_table) \
186 out_row[j * components] = (type)(in_row[j * components] * 0.8588 + 0.0627); \
187 out_row[j * components + 1] = (type)(in_row[j * components + 1] * 0.8588 + 0.0627); \
188 out_row[j * components + 2] = (type)(in_row[j * components + 2] * 0.8588 + 0.0627); \
192 out_row[j * components] = (type)(in_row[j * components] * 1.1644 - 0.0627); \
193 out_row[j * components + 1] = (type)(in_row[j * components + 1] * 1.1644 - 0.0627); \
194 out_row[j * components + 2] = (type)(in_row[j * components + 2] * 1.1644 - 0.0627); \
200 for(int j = 0; j < w; j++) \
202 out_row[j * components] = table[(int)in_row[j * components]]; \
203 out_row[j * components + 1] = table[(int)in_row[j * components + 1]]; \
204 out_row[j * components + 2] = table[(int)in_row[j * components + 2]]; \
210 void RGB601Main::process(int *table, VFrame *input_ptr, VFrame *output_ptr)
212 int w = input_ptr->get_w();
213 int h = input_ptr->get_h();
215 if(config.direction == 1)
216 switch(input_ptr->get_color_model())
219 PROCESS(forward_table, unsigned char, 3, 1);
222 PROCESS(forward_table, unsigned char, 4, 1);
225 PROCESS(forward_table, u_int16_t, 3, 1);
227 case BC_YUVA16161616:
228 PROCESS(forward_table, u_int16_t, 4, 1);
231 PROCESS(forward_table, unsigned char, 3, 0);
234 PROCESS(forward_table, unsigned char, 4, 0);
237 PROCESS(forward_table, float, 3, 0);
240 PROCESS(forward_table, float, 4, 0);
243 PROCESS(forward_table, u_int16_t, 3, 0);
245 case BC_RGBA16161616:
246 PROCESS(forward_table, u_int16_t, 4, 0);
250 if(config.direction == 2)
251 switch(input_ptr->get_color_model())
254 PROCESS(reverse_table, unsigned char, 3, 1);
257 PROCESS(reverse_table, unsigned char, 4, 1);
260 PROCESS(reverse_table, u_int16_t, 3, 1);
262 case BC_YUVA16161616:
263 PROCESS(reverse_table, u_int16_t, 4, 1);
266 PROCESS(reverse_table, unsigned char, 3, 0);
269 PROCESS(reverse_table, unsigned char, 4, 0);
272 PROCESS(reverse_table, float, 3, 0);
275 PROCESS(reverse_table, float, 4, 0);
278 PROCESS(reverse_table, u_int16_t, 3, 0);
280 case BC_RGBA16161616:
281 PROCESS(reverse_table, u_int16_t, 4, 0);
286 int RGB601Main::process_buffer(VFrame *frame,
287 int64_t start_position,
290 load_configuration();
294 if(config.direction == 1)
295 process(forward_table, frame, frame);
297 if(config.direction == 2)
298 process(reverse_table, frame, frame);