3 uint8_t **output_rows, int out_colormodel, int out_x, int out_y, int out_w, int out_h,
4 uint8_t *out_yp, uint8_t *out_up, uint8_t *out_vp, uint8_t *out_ap, int out_rowspan,
5 uint8_t **input_rows, int in_colormodel, int in_x, int in_y, int in_w, int in_h,
6 uint8_t *in_yp, uint8_t *in_up, uint8_t *in_vp, uint8_t *in_ap, int in_rowspan,
9 // prevent bounds errors on poorly dimensioned macro pixel formats
10 switch( in_colormodel ) {
12 case BC_YUV422: in_w &= ~1; break; // 2x1
14 case BC_YUV420PI: in_w &= ~1; in_h &= ~1; break; // 2x2
15 case BC_YUV422P: in_w &= ~1; break; // 2x1
16 case BC_YUV410P: in_w &= ~3; in_h &= ~3; break; // 4x4
17 case BC_YUV411P: in_w &= ~3; break; // 4x1
19 switch( out_colormodel ) {
21 case BC_YUV422: out_w &= ~1; break;
23 case BC_YUV420PI: out_w &= ~1; out_h &= ~1; break;
24 case BC_YUV422P: out_w &= ~1; break;
25 case BC_YUV410P: out_w &= ~3; out_h &= ~3; break;
26 case BC_YUV411P: out_w &= ~3; break;
28 this->output_rows = output_rows;
29 this->input_rows = input_rows;
30 this->out_yp = out_yp;
31 this->out_up = out_up;
32 this->out_vp = out_vp;
33 this->out_ap = out_ap;
46 this->in_colormodel = in_colormodel;
47 switch( in_colormodel ) {
50 if( !BC_CModels::has_alpha(out_colormodel) )
51 this->in_colormodel = BC_RGB_FLOATP;
52 in_rowspan = in_w * sizeof(float);
55 this->total_in_w = in_rowspan;
56 this->out_colormodel = out_colormodel;
57 switch( out_colormodel ) {
60 out_rowspan = out_w * sizeof(float);
63 this->total_out_w = out_rowspan;
64 this->bg_color = bg_color;
65 this->bg_r = (bg_color>>16) & 0xff;
66 this->bg_g = (bg_color>>8) & 0xff;
67 this->bg_b = (bg_color>>0) & 0xff;
69 this->in_pixelsize = BC_CModels::calculate_pixelsize(in_colormodel);
70 this->out_pixelsize = BC_CModels::calculate_pixelsize(out_colormodel);
71 this->scale = (out_w != in_w) || (in_x != 0);
73 /* + 1 so we don't overflow when calculating in advance */
74 column_table = new int[out_w+1];
75 double hscale = (double)in_w/out_w;
76 for( int i=0; i<out_w; ++i ) {
77 column_table[i] = ((int)(hscale * i) + in_x) * in_pixelsize;
78 if( in_colormodel == BC_YUV422 || in_colormodel == BC_UVY422 )
79 column_table[i] &= ~3;
81 double vscale = (double)in_h/out_h;
82 row_table = new int[out_h];
83 for( int i=0; i<out_h; ++i )
84 row_table[i] = (int)(vscale * i) + in_y;
87 BC_Xfer::BC_Xfer(uint8_t **output_rows, uint8_t **input_rows,
88 uint8_t *out_yp, uint8_t *out_up, uint8_t *out_vp,
89 uint8_t *in_yp, uint8_t *in_up, uint8_t *in_vp,
90 int in_x, int in_y, int in_w, int in_h, int out_x, int out_y, int out_w, int out_h,
91 int in_colormodel, int out_colormodel, int bg_color, int in_rowspan, int out_rowspan)
93 init(output_rows, out_colormodel, out_x, out_y, out_w, out_h,
94 out_yp, out_up, out_vp, 0, out_rowspan,
95 input_rows, in_colormodel, in_x, in_y, in_w, in_h,
96 in_yp, in_up, in_vp, 0, in_rowspan, bg_color);
100 uint8_t **output_ptrs, int out_colormodel,
101 int out_x, int out_y, int out_w, int out_h, int out_rowspan,
102 uint8_t **input_ptrs, int in_colormodel,
103 int in_x, int in_y, int in_w, int in_h, int in_rowspan,
106 uint8_t *out_yp = 0, *out_up = 0, *out_vp = 0, *out_ap = 0;
107 uint8_t *in_yp = 0, *in_up = 0, *in_vp = 0, *in_ap = 0;
108 if( BC_CModels::is_planar(in_colormodel) ) {
109 in_yp = input_ptrs[0]; in_up = input_ptrs[1]; in_vp = input_ptrs[2];
110 if( BC_CModels::has_alpha(in_colormodel) ) in_ap = input_ptrs[3];
112 if( BC_CModels::is_planar(out_colormodel) ) {
113 out_yp = output_ptrs[0]; out_up = output_ptrs[1]; out_vp = output_ptrs[2];
114 if( BC_CModels::has_alpha(out_colormodel) ) out_ap = output_ptrs[3];
116 init(output_ptrs, out_colormodel, out_x, out_y, out_w, out_h,
117 out_yp, out_up, out_vp, out_ap, out_rowspan,
118 input_ptrs, in_colormodel, in_x, in_y, in_w, in_h,
119 in_yp, in_up, in_vp, in_ap, in_rowspan, bg_color);
124 delete [] column_table;
128 void BC_CModels::transfer(unsigned char **output_rows, unsigned char **input_rows,
129 unsigned char *out_yp, unsigned char *out_up, unsigned char *out_vp,
130 unsigned char *in_yp, unsigned char *in_up, unsigned char *in_vp,
131 int in_x, int in_y, int in_w, int in_h, int out_x, int out_y, int out_w, int out_h,
132 int in_colormodel, int out_colormodel, int bg_color, int in_rowspan, int out_rowspan)
134 BC_Xfer xfer(output_rows, input_rows,
135 out_yp, out_up, out_vp, in_yp, in_up, in_vp,
136 in_x, in_y, in_w, in_h, out_x, out_y, out_w, out_h,
137 in_colormodel, out_colormodel, bg_color, in_rowspan, out_rowspan);
141 void BC_CModels::transfer(
142 uint8_t **output_ptrs, int out_colormodel,
143 int out_x, int out_y, int out_w, int out_h, int out_rowspan,
144 uint8_t **input_ptrs, int in_colormodel,
145 int in_x, int in_y, int in_w, int in_h, int in_rowspan, int bg_color)
148 output_ptrs, out_colormodel, out_x, out_y, out_w, out_h, out_rowspan,
149 input_ptrs, in_colormodel, in_x, in_y, in_w, in_h, in_rowspan, bg_color);
153 // specialized functions
155 // in bccmdl.py: specialize("bc_rgba8888", "bc_transparency", "XFER_rgba8888_to_transparency")
156 void BC_Xfer::XFER_rgba8888_to_transparency(unsigned y0, unsigned y1)
158 for( unsigned i=y0; i<y1; ++i ) {
159 uint8_t *outp = output_rows[i + out_y] + out_x * out_pixelsize;
160 uint8_t *inp_row = input_rows[row_table[i]];
161 int bit_no = 0, bit_vec = 0;
162 for( unsigned j=0; j<out_w; ) {
163 uint8_t *inp = inp_row + column_table[j];
164 if( inp[3] < 127 ) bit_vec |= 0x01 << bit_no;
166 if( !bit_no ) { *outp++ = bit_vec; bit_vec = 0; }
168 if( bit_no ) *outp = bit_vec;
172 BC_Xfer::SlicerList BC_Xfer::slicers;
174 BC_Xfer::SlicerList::SlicerList()
179 BC_Xfer::SlicerList::~SlicerList()
184 void BC_Xfer::SlicerList::reset()
186 lock("BC_Xfer::SlicerList::reset");
187 while( last ) remove(last);
192 BC_Xfer::Slicer *BC_Xfer::SlicerList::get_slicer(BC_Xfer *xp)
194 Slicer *slicer = first;
196 if( count < BC_Resources::machine_cpus ) {
197 slicer = new Slicer(xp);
202 remove_pointer(slicer);
206 void BC_Xfer::xfer_slices(int slices)
209 int max_slices = BC_Resources::machine_cpus/2;
210 if( slices > max_slices ) slices = max_slices;
211 if( slices < 1 ) slices = 1;
212 Slicer *active[slices];
213 unsigned y0 = 0, y1 = out_h;
214 int slices1 = slices-1;
216 slicers.lock("BC_Xfer::xfer_slices");
217 for( int i=0; i<slices1; y0=y1 ) {
218 Slicer *slicer = slicers.get_slicer(this);
219 if( !slicer ) { slices1 = i; break; }
221 y1 = out_h * ++i / slices;
222 slicer->slice(this, y0, y1);
226 (this->*xfn)(y0, out_h);
228 for( int i=0; i<slices1; ++i )
229 active[i]->complete->lock("BC_Xfer::xfer_slices");
230 slicers.lock("BC_Xfer::xfer_slices");
231 for( int i=0; i<slices1; ++i )
232 slicers.append(active[i]);
237 BC_Xfer::Slicer::Slicer(BC_Xfer *xp)
240 init = new Condition(0, "BC_Xfer::Slicer::init", 0);
241 complete = new Condition(0, "BC_Xfer::Slicer::complete", 0);
245 BC_Xfer::Slicer::~Slicer()
252 void BC_Xfer::Slicer::slice(BC_Xfer *xp, unsigned y0, unsigned y1)
260 void BC_Xfer::Slicer::run()
263 init->lock("Slicer::run");
265 xfer_fn xfn = xp->xfn;
271 void BC_CModels::bcxfer_stop_slicers()
273 BC_Xfer::slicers.reset();