1 #include "fadeengine.h"
14 FadeUnit::FadeUnit(FadeEngine *server)
17 this->engine = server;
25 #define APPLY_FADE(equivalent, \
34 temp_type opacity = (temp_type)(alpha * max); \
35 temp_type transparency = (temp_type)(max - opacity); \
36 temp_type product = (temp_type) (chroma_zero * transparency); \
38 for(int i = row1; i < row2; i++) \
40 type *in_row = (type*)input_rows[i]; \
41 type *out_row = (type*)output_rows[i]; \
43 for(int j = 0; j < width; j++, out_row += components, in_row += components) \
48 (type)((temp_type)in_row[0] * opacity / max); \
50 (type)(((temp_type)in_row[1] * opacity + \
53 (type)(((temp_type)in_row[2] * opacity + \
60 out_row[0] = in_row[0]; \
61 out_row[1] = in_row[1]; \
62 out_row[2] = in_row[2]; \
65 if(in_row[3] == max) \
66 out_row[3] = opacity; \
69 (type)((temp_type)in_row[3] * opacity / max); \
77 void FadeUnit::process_package(LoadPackage *package)
79 FadePackage *pkg = (FadePackage*)package;
80 VFrame *output = engine->output;
81 VFrame *input = engine->input;
82 float alpha = engine->alpha;
83 int row1 = pkg->out_row1;
84 int row2 = pkg->out_row2;
85 unsigned char **in_rows = input->get_rows();
86 unsigned char **out_rows = output->get_rows();
87 int width = input->get_w();
89 if(input->get_rows()[0] == output->get_rows()[0])
91 switch(input->get_color_model())
94 APPLY_FADE(1, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x0, 3);
97 APPLY_FADE(1, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x0, 4);
100 APPLY_FADE(1, out_rows, in_rows, 1.0, float, float, 0x0, 3);
103 APPLY_FADE(1, out_rows, in_rows, 1.0, float, float, 0x0, 4);
106 APPLY_FADE(1, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x0, 3);
108 case BC_RGBA16161616:
109 APPLY_FADE(1, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x0, 4);
112 APPLY_FADE(1, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x80, 3);
115 APPLY_FADE(1, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x80, 4);
118 APPLY_FADE(1, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x8000, 3);
120 case BC_YUVA16161616:
121 APPLY_FADE(1, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x8000, 4);
127 switch(input->get_color_model())
130 APPLY_FADE(0, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x0, 3);
133 APPLY_FADE(0, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x0, 4);
136 APPLY_FADE(0, out_rows, in_rows, 1.0, float, float, 0x0, 3);
139 APPLY_FADE(0, out_rows, in_rows, 1.0, float, float, 0x0, 4);
142 APPLY_FADE(0, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x0, 3);
144 case BC_RGBA16161616:
145 APPLY_FADE(0, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x0, 4);
148 APPLY_FADE(0, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x80, 3);
151 APPLY_FADE(0, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x80, 4);
154 APPLY_FADE(0, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x8000, 3);
156 case BC_YUVA16161616:
157 APPLY_FADE(0, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x8000, 4);
171 FadeEngine::FadeEngine(int cpus)
172 : LoadServer(cpus, cpus)
176 FadeEngine::~FadeEngine()
180 void FadeEngine::do_fade(VFrame *output, VFrame *input, float alpha)
182 this->output = output;
188 output->copy_from(input);
194 void FadeEngine::init_packages()
196 for(int i = 0; i < get_total_packages(); i++)
198 FadePackage *package = (FadePackage*)get_package(i);
199 package->out_row1 = input->get_h() * i / get_total_packages();
200 package->out_row2 = input->get_h() * (i + 1) / get_total_packages();
204 LoadClient* FadeEngine::new_client()
206 return new FadeUnit(this);
209 LoadPackage* FadeEngine::new_package()
211 return new FadePackage;
215 FadePackage::FadePackage()
222 // c-file-style: "linux"