4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "fadeengine.h"
35 FadeUnit::FadeUnit(FadeEngine *server)
38 this->engine = server;
46 #define APPLY_FADE(equivalent, \
55 temp_type opacity = (temp_type)(alpha * max); \
56 temp_type transparency = (temp_type)(max - opacity); \
57 temp_type product = (temp_type) (chroma_zero * transparency); \
59 for(int i = row1; i < row2; i++) \
61 type *in_row = (type*)input_rows[i]; \
62 type *out_row = (type*)output_rows[i]; \
64 for(int j = 0; j < width; j++, out_row += components, in_row += components) \
69 (type)((temp_type)in_row[0] * opacity / max); \
71 (type)(((temp_type)in_row[1] * opacity + \
74 (type)(((temp_type)in_row[2] * opacity + \
81 out_row[0] = in_row[0]; \
82 out_row[1] = in_row[1]; \
83 out_row[2] = in_row[2]; \
86 if(in_row[3] == max) \
87 out_row[3] = opacity; \
90 (type)((temp_type)in_row[3] * opacity / max); \
98 void FadeUnit::process_package(LoadPackage *package)
100 FadePackage *pkg = (FadePackage*)package;
101 VFrame *output = engine->output;
102 VFrame *input = engine->input;
103 float alpha = engine->alpha;
104 int row1 = pkg->out_row1;
105 int row2 = pkg->out_row2;
106 unsigned char **in_rows = input->get_rows();
107 unsigned char **out_rows = output->get_rows();
108 int width = input->get_w();
110 if(input->get_rows()[0] == output->get_rows()[0])
112 switch(input->get_color_model())
115 APPLY_FADE(1, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x0, 3);
118 APPLY_FADE(1, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x0, 4);
121 APPLY_FADE(1, out_rows, in_rows, 1.0, float, float, 0x0, 3);
124 APPLY_FADE(1, out_rows, in_rows, 1.0, float, float, 0x0, 4);
127 APPLY_FADE(1, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x0, 3);
129 case BC_RGBA16161616:
130 APPLY_FADE(1, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x0, 4);
133 APPLY_FADE(1, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x80, 3);
136 APPLY_FADE(1, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x80, 4);
139 APPLY_FADE(1, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x8000, 3);
141 case BC_YUVA16161616:
142 APPLY_FADE(1, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x8000, 4);
148 switch(input->get_color_model())
151 APPLY_FADE(0, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x0, 3);
154 APPLY_FADE(0, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x0, 4);
157 APPLY_FADE(0, out_rows, in_rows, 1.0, float, float, 0x0, 3);
160 APPLY_FADE(0, out_rows, in_rows, 1.0, float, float, 0x0, 4);
163 APPLY_FADE(0, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x0, 3);
165 case BC_RGBA16161616:
166 APPLY_FADE(0, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x0, 4);
169 APPLY_FADE(0, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x80, 3);
172 APPLY_FADE(0, out_rows, in_rows, 0xff, unsigned char, uint16_t, 0x80, 4);
175 APPLY_FADE(0, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x8000, 3);
177 case BC_YUVA16161616:
178 APPLY_FADE(0, out_rows, in_rows, 0xffff, uint16_t, uint32_t, 0x8000, 4);
192 FadeEngine::FadeEngine(int cpus)
193 : LoadServer(cpus, cpus)
197 FadeEngine::~FadeEngine()
201 void FadeEngine::do_fade(VFrame *output, VFrame *input, float alpha)
203 this->output = output;
209 output->copy_from(input);
215 void FadeEngine::init_packages()
217 for(int i = 0; i < get_total_packages(); i++)
219 FadePackage *package = (FadePackage*)get_package(i);
220 package->out_row1 = input->get_h() * i / get_total_packages();
221 package->out_row2 = input->get_h() * (i + 1) / get_total_packages();
225 LoadClient* FadeEngine::new_client()
227 return new FadeUnit(this);
230 LoadPackage* FadeEngine::new_package()
232 return new FadePackage;
236 FadePackage::FadePackage()