3 # Retain python2 compatibility
4 from __future__ import print_function
8 "i8": { "r": " uint32_t r = bg_r, g = bg_g, b = bg_b;", },
9 "i16": { "r": " uint32_t r = bg_r, g = bg_g, b = bg_b;", },
10 "fp": { "r": " float r = bg_fr, g = bg_fg, b = bg_fb;", },
14 "r": " uint32_t in = *inp; int r = ((in>>6)&3)*0x55u, g = ((in>>3)&7)*0x24u, b = (in&7)*0x24u;",
15 "w": " uint32_t ot = (r&0xc0u) | ((g>>2)&0x38u) | ((b>>5)&0x07u);\n" +
19 "r": " uint32_t in = *inp; int r = ((in>>6)&3)*0x5555u, g = ((in>>3)&7)*0x2492u, b = (in&7)*0x2492u;",
20 "w": " uint32_t ot = ((r>>8)&0xc0u) | ((g>>10) & 0x38u) >> 2) | ((b>>13)&0x07u);\n" +
24 "r": " int in = *inp; float r = (in>>6)/3.f, g = ((in>>3)&0x07u)/7.f, b = (in&0x07u)/7.f;",
25 "w": " int vr = clp(4,r), vg = clp(8,g), vb = clp(8,b);\n" +
26 " *out++ = ((vr<<6)&0xc0u) | ((vg<<3)&0x38u) | (vb&0x7u);",
31 "r": " uint32_t in = *(uint16_t*)inp;\n" +
32 " int r = (in>>8)&0xf8u, g = (in>>3)&0xfcu, b = (in&0x1fu)<<3;",
33 "w": " uint32_t ot = ((r<<8) & 0xf800u) | ((g<<3) & 0x07e0u) | ((b>>3) & 0x001fu);\n" +
34 " *(uint16_t*)out = ot; out += sizeof(uint16_t);",
37 "r": " uint32_t in = *(uint16_t*)inp;\n" +
38 " int r = in&0xf800u, g = (in<<5)&0xfc00u, b = (in<<11)&0xf800u;",
39 "w": " uint32_t ot = (r&0xf800u) | ((g>>5) & 0x07e0u) | ((b>>11) & 0x001fu);\n" +
43 "r": " uint32_t in = *(uint16_t*)inp;\n" +
44 " float r = (in>>11)/31.f, g = ((in>>5)&0x3fu)/63.f, b = (in&0x1fu)/31.f;",
45 "w": " uint32_t vr = clp(32,r), vg = clp(64,g), vb = clp(32,b);\n" +
46 " *out++ = ((vr<<11)&0xf800u) | ((vg<<6)&0x07e0u) | (vb&0x001fu);",
51 "r": " int r = *inp++, g = *inp++, b = *inp++;",
52 "w": " *out++ = r; *out++ = g; *out++ = b;",
55 "r": " int r = *inp++, g = *inp++, b = *inp++;\n" +
56 " r = (r<<8) | r; g = (g<<8) | g; b = (b<<8) | b;",
57 "w": " *out++ = r>>8; *out++ = g>>8; *out++ = b>>8;",
60 "r": " float r = fclp(*inp++,256), g=fclp(*inp++,256), b = fclp(*inp++,256);",
61 "w": " *out++ = clp(256,r); *out++ = clp(256,g); *out++ = clp(256,b);",
66 "r": " int r = *inp++>>8, g = *inp++>>8, b = *inp++>>8;",
67 "w": " *out++ = (r<<8) | r; *out++ = (g<<8) | g; *out++ = (b<<8) | b;"
70 "r": " int r = *inp++, g = *inp++, b = *inp++;",
71 "w": " *out++ = r; *out++ = g; *out++ = b;",
74 "r": " float r = fclp(*inp++,65536), g=fclp(*inp++,65536), b = fclp(*inp++,65536);",
75 "w": " *out++ = clp(65536,r); *out++ = clp(65536,g); *out++ = clp(65536,b);",
80 "r": " int r = clp(256,*inp++), g = clp(256,*inp++), b = clp(256,*inp++);",
81 "w": " *out++ = fclp(r,256); *out++ = fclp(g,256); *out++ = fclp(b,256);",
84 "r": " int r = clp(65536,*inp++), g = clp(65536,*inp++), b = clp(65536,*inp++);",
85 "w": " *out++ = fclp(r,65536); *out++ = fclp(g,65536); *out++ = fclp(b,65536);",
88 "r": " float r = *inp++, g=*inp++, b = *inp++;",
89 "w": " *out++ = r; *out++ = g; *out++ = b;",
95 "r": " uint32_t in = *(uint16_t*)inp;\n" +
96 " int b = (in>>8)&0xf8u, g = (in>>3)&0xfcu, r = (in&0x1fu)<<3;",
97 "w": " uint32_t ot = ((b&0xf8u)<<8) | ((g&0xfcu)<<3) | ((r&0xf8u)>>3);\n" +
98 " *(uint16_t*)out = ot; out += sizeof(uint16_t)/sizeof(*out);",
101 "r": " uint32_t in = *(uint16_t*)inp;\n" +
102 " int b = in&0xf800u, g = (in<<5)&0xfc00u, r = (in<<11)&0xf800u;",
103 "w": " uint32_t ot = (b&0xf800u) | ((g>>5) & 0x07e0u) << 3) | (r>>11);\n" +
107 "r": " uint32_t in = *(uint16_t*)inp;\n" +
108 " float b = (in>>11)/31.f, g = ((in>>5)&0x3fu)/63.f, r = (in&0x1fu)/31.f;",
109 "w": " uint32_t vb = clp(32,b), vg = clp(64,g), vr = clp(32,r);\n" +
110 " *out++ = ((vb<<11)&0xf800u) | ((vg<<6)&0x03e0u) | (vr&0x001fu);",
115 "r": " int b = *inp++, g = *inp++, r = *inp++;",
116 "w": " *out++ = b; *out++ = g; *out++ = r;",
119 "r": " int b = *inp++, g = *inp++, r = *inp++;\n" +
120 " b = (b<<8) | b; g = (g<<8) | g; r = (r<<8) | r;",
121 "w": " *out++ = b>>8; *out++ = g>>8; *out++ = r>>8;",
124 "r": " float b = fclp(*inp++,256), g=fclp(*inp++,256), r = fclp(*inp++,256);",
125 "w": " *out++ = clp(256,b); *out++ = clp(256,g); *out++ = clp(256,r);",
130 "r": " int b = *inp++, g = *inp++, r = *inp++;",
131 "w": " *out++ = b; *out++ = g; *out++ = r; ++out;",
134 "r": " int b = *inp++, g = *inp++, r = *inp++;\n" +
135 " b = (b<<8) | b; g = (g<<8) | g; r = (r<<8) | r;",
136 "w": " *out++ = b>>8; *out++ = g>>8; *out++ = r>>8; ++out;",
139 "r": " float b = fclp(*inp++,256), g=fclp(*inp++,256), r = fclp(*inp++,256);",
140 "w": " *out++ = clp(256,b); *out++ = clp(256,g); *out++ = clp(256,r); ++out;",
145 "r": " int b = *inp++>>8, g = *inp++>>8, r = *inp++>>8;",
146 "w": " *out++ = (r<<8) | r; *out++ = (g<<8) | g; *out++ = (b<<8) | b;"
149 "r": " int b = *inp++, g = *inp++, r = *inp++;",
150 "w": " *out++ = b; *out++ = g; *out++ = r;",
153 "r": " float b = fclp(*inp++,65536), g=fclp(*inp++,65536), r = fclp(*inp++,65536);",
154 "w": " *out++ = clp(65536,b); *out++ = clp(65536,g); *out++ = clp(65536,r);",
159 "r": " int b = clp(256,*inp++), g = clp(256,*inp++), r = clp(256,*inp++);",
160 "w": " *out++ = fclp(b,256); *out++ = fclp(g,256); *out++ = fclp(r,256);",
163 "r": " int b = clp(65536,*inp++), g = clp(65536,*inp++), r = clp(65536,*inp++);",
164 "w": " *out++ = fclp(b,65536); *out++ = fclp(g,65536); *out++ = fclp(r,65536);",
167 "r": " float b = *inp++, g=*inp++, r = *inp++;",
168 "w": " *out++ = b; *out++ = g; *out++ = r;",
174 "r": " int32_t y = *inp++, u = *inp++, v = *inp++;",
175 "w": " *out++ = y; *out++ = u; *out++ = v;",
178 "r": " int32_t iy = *inp++, y = (iy<<8) | iy, u = *inp++<<8, v = *inp++<<8;",
179 "w": " *out++ = y>>8; *out++ = u>>8; *out++ = v>>8;",
184 "r": " int32_t y = *inp++>>8, u = *inp++>>8, v = *inp++>>8;",
185 "w": " *out++ = (y<<8) | y; *out++ = u<<8; *out++ = v<<8;",
188 "r": " int32_t y = *inp++, u = *inp++, v = *inp++;",
189 "w": " *out++ = y; *out++ = u; *out++ = v;",
195 "r": " int32_t y = inp[(j&1)<<1], u = inp[1], v = inp[3];",
196 "w": " if( !(j&1) ) { *out++ = y; *out = u; out[2] = v; }\n" +
197 " else { *out++ = u; *out++= y; *out++ = v; }",
200 "r": " int32_t iy = inp[(j&1)<<1], y = (iy<<8) | iy, u = inp[1]<<8, v = inp[3]<<8;",
201 "w": " if( !(j&1) ) { *out++ = y>>8; *out = u>>8; out[2] = v>>8; }\n" +
202 " else { *out++ = u>>8; *out++= y>>8; *out++ = v>>8; }",
208 "r": " int32_t u = inp[0], y = inp[((j&1)<<1)+1], v = inp[2];",
209 "w": " if( !(j&1) ) { *out++ = u; *out++ = y; *out++ = v; *out = y; }\n" +
210 " else { *out++= y; }",
213 "r": " int32_t u = inp[0]<<8, iy = inp[((j&1)<<1)+1], y = (iy<<8) | iy, v = inp[2]<<8;",
214 "w": " if( !(j&1) ) { *out++ = u>>8; *out++ = y>>8; *out++ = v>>8; *out = y>>8; }\n" +
215 " else { *out++= y>>8; }",
221 "r": " uint32_t it = *(uint32_t*)inp;\n" +
222 " int32_t y = (it>>24)&0xffu, u = (it>>14)&0xffu, v = (it>>4)&0xffu;",
223 "w": " uint32_t ot = (y<<24) | (u<<14) | (v<<4);\n" +
224 " *(uint32_t*)out = ot; out += sizeof(uint32_t)/sizeof(*out);",
227 "r": " uint32_t it = *(uint32_t*)inp;\n" +
228 " int32_t y = (it>>16)&0xffc0u, u = (it>>6)&0xffc0u, v = (it<<4)&0xffc0u;",
229 "w": " uint32_t ot = ((y&0xffc0u)<<16) | ((u&0xffc0u)<<6) | ((v&0xffc0u)>>4);\n" +
230 " *(uint32_t*)out = ot; out += sizeof(uint32_t)/sizeof(*out);",
236 "r": " int32_t v = *inp++, y = *inp++, u = *inp++;",
237 "w": " *out++ = v; *out++ = y; *out++ = u;",
240 "r": " int32_t v = *inp++<<8, iy = *inp++, y = (iy<<8) | iy, u = *inp++<<8;",
241 "w": " *out++ = v>>8; *out++ = y>>8; *out++ = u>>8;",
247 "r": " int32_t u = *inp++, y = *inp++, v = *inp++;",
248 "w": " *out++ = u; *out++ = y; *out++ = v;",
251 "r": " int32_t u = *inp++<<8, iy = *inp++, y = (iy<<8) | iy, v = *inp++<<8;",
252 "w": " *out++ = u>>8; *out++ = y>>8; *out++ = v>>8;",
258 "r": " int32_t y = *yip, u = *uip, v = *vip;",
259 "w": " yop[j] = y; uop[j/2] = u; vop[j/2] = v;",
262 "r": " int32_t iy = *yip, y = (iy<<8) | iy, u = *uip<<8, v = *vip<<8;",
263 "w": " yop[j] = y>>8; uop[j/2] = u>>8; vop[j/2] = v>>8;",
268 "r": " int32_t y = *yip, u = *uip, v = *vip;",
269 "w": " yop[j] = y; uop[j/2] = u; vop[j/2] = v;",
272 "r": " int32_t iy = *yip, y = (iy<<8) | iy, u = *uip<<8, v = *vip<<8;",
273 "w": " yop[j] = y>>8; uop[j/2] = u>>8; vop[j/2] = v>>8;",
279 "r": " int32_t y = *yip, u = *uip, v = *vip;",
280 "w": " yop[j] = y; uop[j/2] = u; vop[j/2] = v;",
283 "r": " int32_t iy = *yip, y = (iy<<8) | iy, u = *uip<<8, v = *vip<<8;",
284 "w": " yop[j] = y>>8; uop[j/2] = u>>8; vop[j/2] = v>>8;",
290 "r": " int32_t y = *yip, u = *uip, v = *vip;",
291 "w": " yop[j] = y; uop[j] = u; vop[j] = v;",
294 "r": " int32_t iy = *yip, y = (iy<<8) | iy, u = *uip<<8, v = *vip<<8;",
295 "w": " yop[j] = y>>8; uop[j] = u>>8; vop[j] = v>>8;",
301 "r": " int32_t y = *yip, u = *uip, v = *vip;",
302 "w": " yop[j] = y; uop[j/4] = u; vop[j/4] = v;",
305 "r": " int32_t iy = *yip, y = (iy<<8) | iy, u = *uip<<8, v = *vip<<8;",
306 "w": " yop[j] = y>>8; uop[j/4] = u>>8; vop[j/4] = v>>8;",
312 "r": " int32_t y = *yip, u = *uip, v = *vip;",
313 "w": " yop[j] = y; uop[j/4] = u; vop[j/4] = v;",
316 "r": " int32_t iy = *yip, y = (iy<<8) | iy, u = *uip<<8, v = *vip<<8;",
317 "w": " yop[j] = y>>8; uop[j/4] = u>>8; vop[j/4] = v>>8;",
323 "r": " int r = clp(256,*rip++), g = clp(256,*gip++), b = clp(256,*bip++);",
324 "w": " *rop++ = fclp(r,256); *gop++ = fclp(g,256); *bop++ = fclp(b,256);",
327 "r": " int r = clp(65536,*rip++), g = clp(65536,*gip++), b = clp(65536,*bip++);",
328 "w": " *rop++ = fclp(r,65536); *gop++ = fclp(g,65536); *bop++ = fclp(b,65536);",
331 "r": " float r = *rip++, g = *gip++, b = *bip++;",
332 "w": " *rop++ = r; *gop++ = g; *bop++ = b;",
338 "r": " int g = *rip++, b = *gip++, r = *bip++;",
339 "w": " *rop++ = g; *gop++ = b; *bop++ = r;",
342 "r": " int ig = *rip++, g = (ig<<8) | ig, ib = *gip++, b = (ib<<8) | ib," +
343 " ir = *bip++, r = (ir<<8) | ir;",
344 "w": " *rop++ = g >> 8; *gop++ = b >> 8; *bop++ = r >> 8;",
347 "r": " float g = *rip++/255.f, b = *gip++/255.f, r = *bip++/255.f;",
348 "w": " *rop++ = clp(256,g); *gop++ = clp(256,b); *bop++ = clp(256,r);",
354 "r": " int32_t y = *inp++, u = 0x80, v = 0x80;",
355 "w": " *out++ = y; (void)u; (void)v;",
358 "r": " int32_t iy = *inp++, y = (iy<<8) | iy, u = 0x8000, v = 0x8000;",
359 "w": " *out++ = y>>8; (void)u; (void)v;",
365 "r": " int32_t y = *inp++>>8, u = 0x80, v = 0x80;",
366 "w": " *out++ = (y<<8) | y; (void)u; (void)v;",
369 "r": " int32_t y = *inp++, u = 0x8000, v = 0x8000;",
370 "w": " *out++ = y; (void)u; (void)v;",
377 "r": " z_int a = *inp++;",
381 "r": " z_int a = *inp++; a = (a<<8) | a;",
382 "w": " *out++ = a>>8;",
385 "r": " z_float fa = fclp(*inp++,256);",
386 "w": " *out++ = clp(256,a)",
391 "r": " z_int a = *inp++>>8;",
392 "w": " *out++ = (a<<8) | a;",
395 "r": " z_int a = *inp++;",
399 "r": " z_float fa = fclp(*inp++,65536);",
400 "w": " *out++ = clp(65536,a);",
405 "r": " z_int a = clp(256,*inp++);",
406 "w": " *out++ = fclp(a,256);",
409 "r": " z_int a = clp(65536,*inp++);",
410 "w": " *out++ = fclp(a,65536);",
413 "r": " z_float fa = *inp++;",
414 "w": " *out++ = fa;",
419 "r": " z_int a = clp(256,*aip++);",
420 "w": " *aop++ = fclp(a,256);",
423 "r": " z_int a = clp(65536,*aip++);",
424 "w": " *aop++ = fclp(a,65536);",
427 "r": " z_float fa = *aip++;",
428 "w": " *aop++ = fa;",
435 "w": " *out++ = 0xff;",
439 "w": " *out++ = 0xff;",
443 "w": " *out++ = 0xff;",
449 "w": " *out++ = 0xffff;",
453 "w": " *out++ = 0xffff;",
457 "w": " *out++ = 0xffff;",
463 "w": " *out++ = 1.f;",
467 "w": " *out++ = 1.f;",
471 "w": " *out++ = 1.f;",
474 # alpha blend rgb/black, yuv/black, rgb/bg_color
476 "i8": " r = r*a/0xffu; g = g*a/0xffu; b = b*a/0xffu;",
477 "i16": " r = r*a/0xffffu; g = g*a/0xffffu; b = b*a/0xffffu;",
478 "fp": " r *= fa; g *= fa; b *= fa;",
481 "i8": " z_int a1 = 0xffu-a;\n" +
482 " y = y*a/0xffu; u = (u*a + 0x80u*a1)/0xffu; v = (v*a + 0x80u*a1)/0xffu;",
483 "i16": " z_int a1 = 0xffffu-a;\n" +
484 " y = y*a/0xffffu; u = (u*a + 0x8000u*a1)/0xffffu; v = (v*a + 0x8000u*a1)/0xffffu;",
487 "i8": " int a1 = 0xffu-a;\n" +
488 " r = (r*a + bg_r*a1)/0xffu; g = (g*a + bg_g*a1)/0xffu; b = (b*a + bg_b*a1)/0xffu;",
489 "i16": "int a1 = 0xffffu-a;\n" +
490 " r = (r*a + bg_r*a1)/0xffffu; g = (g*a + bg_g*a1)/0xffffu; b = (b*a + bg_b*a1)/0xffffu;",
491 "fp": " float a1 = 1-fa;\n" +
492 " r = (r*fa + bg_r*a1); g = (g*fa + bg_g*a1); b = (b*fa + bg_b*a1);",
499 dtype = { None: None }
503 def add_cmodel(n, nm, typ=None, *args):
504 global cmodels, bcmodels, layout, dtype, mx_bcmdl
507 if( n > mx_bcmdl ): mx_bcmdl = n
511 def specialize(fr_cmdl, to_cmdl, fn):
513 special[(fr_cmdl, to_cmdl)] = fn
515 add_cmodel( 0, "bc_transparency", "clr", "clear")
516 add_cmodel( 1, "bc_compressed")
518 add_cmodel( 2, "bc_rgb8", "i8", "rgb8")
519 add_cmodel( 3, "bc_rgb565", "i8", "rgb565")
520 add_cmodel( 4, "bc_bgr565", "i8", "bgr565")
521 add_cmodel( 5, "bc_bgr888", "i8", "bgr888")
522 add_cmodel( 6, "bc_bgr8888", "i8", "bgr8888")
524 add_cmodel( 9, "bc_rgb888", "i8", "rgb888")
525 add_cmodel(10, "bc_rgba8888", "i8", "rgb888", "a8")
526 add_cmodel(20, "bc_argb8888", "i8", "a8", "rgb888")
527 add_cmodel(21, "bc_abgr8888", "i8", "a8", "bgr888")
528 add_cmodel(11, "bc_rgb161616", "i16", "rgb161616")
529 add_cmodel(12, "bc_rgba16161616", "i16", "rgb161616", "a16")
530 add_cmodel(13, "bc_yuv888", "i8", "yuv888")
531 add_cmodel(14, "bc_yuva8888", "i8", "yuv888", "a8")
532 add_cmodel(15, "bc_yuv161616", "i16", "yuv161616")
533 add_cmodel(16, "bc_yuva16161616", "i16", "yuv161616", "a16")
534 add_cmodel(35, "bc_ayuv16161616", "i16", "a16", "yuv161616")
536 add_cmodel(18, "bc_uvy422", "i8", "uyvy8888")
537 add_cmodel(19, "bc_yuv422", "i8", "yuyv8888")
538 add_cmodel(22, "bc_a8")
539 add_cmodel(23, "bc_a16")
540 add_cmodel(31, "bc_a_float")
541 add_cmodel(24, "bc_yuv101010", "i16", "yuv10101010")
542 add_cmodel(25, "bc_vyu888", "i8", "vyu888")
543 add_cmodel(26, "bc_uyva8888", "i8", "uyv888", "a8")
544 add_cmodel(29, "bc_rgb_float", "fp", "rgbfloat")
545 add_cmodel(30, "bc_rgba_float", "fp", "rgbfloat", "afp")
547 add_cmodel( 7, "bc_yuv420p", "i8", "yuv420p")
548 add_cmodel( 8, "bc_yuv422p", "i8", "yuv422p")
549 add_cmodel(27, "bc_yuv444p", "i8", "yuv444p")
550 add_cmodel(17, "bc_yuv411p", "i8", "yuv411p")
551 add_cmodel(28, "bc_yuv410p", "i8", "yuv410p")
552 add_cmodel(32, "bc_rgb_floatp", "fp", "rgbfltp")
553 add_cmodel(33, "bc_rgba_floatp", "fp", "rgbfltp", "afpp")
554 add_cmodel(34, "bc_yuv420pi", "i8", "yuv420pi")
556 add_cmodel(36, "bc_grey8", "i8", "grey8")
557 add_cmodel(37, "bc_grey16", "i16", "grey16")
558 add_cmodel(38, "bc_gbrp", "i8", "gbrp")
560 add_cmodel(39, "bc_rgbx8888", "i8", "rgb888", "x8")
561 add_cmodel(40, "bc_rgbx16161616", "i16", "rgb161616", "x16")
562 add_cmodel(41, "bc_yuvx8888", "i8", "yuv888", "x8")
563 add_cmodel(42, "bc_yuvx16161616", "i16", "yuv161616", "x16")
564 add_cmodel(43, "bc_rgbx_float", "fp", "rgbfloat", "xfp")
566 specialize("bc_rgba8888", "bc_transparency", "XFER_rgba8888_to_transparency")
576 "i8": " z_int a=0xff;",
577 "i16": " z_int a=0xffff;",
578 "fp": " z_float fa=1;",
581 "i8": " z_int a = bg_a;",
582 "i16": " z_int a = bg_a;",
583 "fp": " z_float fa = bg_fa;",
587 return nm in ["bc_rgba8888", "bc_argb8888", "bc_abgr8888", \
588 "bc_rgba16161616", "bc_yuva8888", "bc_yuva16161616", "bc_ayuv16161616", \
589 "bc_uyva8888", "bc_rgba_float", "bc_rgba_floatp",]
591 def has_bgcolor(fr_cmdl,to_cmdl):
592 return fr_cmdl in ["bc_rgba8888"] and \
593 to_cmdl in ["bc_rgba888", "bc_bgr565", "bc_rgb565", \
594 "bc_bgr888", "bc_rgb888", "bc_bgr8888"]
596 def is_specialized(fr_cmdl,to_cmdl):
598 return special.get((fr_cmdl, to_cmdl)) is not None
601 return nm in [ "bc_rgb8", "bc_rgb565", "bc_bgr565", \
602 "bc_bgr888", "bc_bgr8888", "bc_rgb888", "bc_rgba8888", \
603 "bc_argb8888", "bc_abgr8888", "bc_rgb", "bc_rgb161616", \
604 "bc_rgba16161616", "bc_rgb_float", "bc_rgba_float", \
605 "bc_rgb_floatp", "bc_rgba_floatp", "bc_gbrp", \
606 "bc_rgbx8888", "bc_rgbx16161616", "bc_rgbx_float", \
610 return nm in [ "bc_yuv888", "bc_yuva8888", "bc_yuv161616", \
611 "bc_yuva16161616", "bc_ayuv16161616", "bc_yuv422", "bc_uvy422", "bc_yuv101010", \
612 "bc_vyu888", "bc_uyva8888", "bc_yuv420p", "bc_yuv420pi", "bc_yuv422p", \
613 "bc_yuv444p", "bc_yuv411p", "bc_yuv410p", "bc_grey8", "bc_grey16", \
614 "bc_yuvx8888", "bc_yuvx16161616", ]
617 return nm in [ "bc_yuv420p", "bc_yuv420pi", "bc_yuv422p", "bc_yuv444p", \
618 "bc_yuv411p", "bc_yuv410p", "bc_rgb_floatp", "bc_rgba_floatp", "bc_gbrp", ]
621 return nm in [ "bc_rgb_float", "bc_rgba_float", "bc_rgbx_float", \
622 "bc_rgb_floatp", "bc_rgba_floatp", ]
624 def gen_xfer_proto(fd, pfx, cls, fr_cmdl, to_cmdl):
626 print("%svoid %sxfer_%s_to_%s" % (pfx, cls, fr_cmdl[3:], to_cmdl[3:]), end=' ', file=fd)
627 ityp = dtype[fr_cmdl];
628 otyp = dtype[to_cmdl];
629 print("(unsigned y0, unsigned y1)", end=' ', file=fd)
631 def gen_xfer_fn(fd, fr_cmdl, to_cmdl):
632 global layout, dtype, adata, cdata
633 ityp = dtype[fr_cmdl]; otyp = dtype[to_cmdl]
634 if( ityp is None or otyp is None ): return
635 fr_typ = ctype[ityp];
636 to_typ = ctype[otyp];
637 if( to_typ is None ): return
639 gen_xfer_proto(fd, "", class_qual, fr_cmdl, to_cmdl);
642 # loops / pointer preload
643 in_xfer = "flat" if not is_planar(fr_cmdl) else \
644 fr_cmdl[3:] if is_yuv(fr_cmdl) else \
645 "rgbp" if not has_alpha(fr_cmdl) else "rgbap"
646 out_xfer = "flat" if not is_planar(to_cmdl) else \
647 to_cmdl[3:] if is_yuv(to_cmdl) else \
648 "rgbp" if not has_alpha(to_cmdl) else "rgbap"
649 print(" xfer_%s_row_out(%s)" % (out_xfer, to_typ), end=' ', file=fd)
650 if( fr_typ is None ):
651 print(" xfer_clear()", end=' ', file=fd)
653 print(" xfer_%s_row_in(%s)" % (in_xfer, fr_typ), end=' ', file=fd)
656 if( is_float(to_cmdl) and is_yuv(fr_cmdl) ):
657 for ic in layout[fr_cmdl]: print("%s" % (base[ic][ityp]['r']), end=' ', file=fd)
659 print("\n float r, g, b; YUV::yuv.yuv_to_rgb_8(r, g, b, y, u, v);", end=' ', file=fd)
660 elif( ityp == "i16" ):
661 print("\n float r, g, b; YUV::yuv.yuv_to_rgb_16(r, g, b, y, u, v);", end=' ', file=fd)
662 if( has_alpha(fr_cmdl) or has_alpha(to_cmdl) ):
663 if( not has_alpha(fr_cmdl) ):
664 print(" z_float fa = 1;", end=' ', file=fd)
665 elif( ityp == "i8" ):
666 print(" float fa = fclp(a,256);", end=' ', file=fd)
667 elif( ityp == "i16" ):
668 print(" float fa = fclp(a,65536);", end=' ', file=fd)
670 for ic in layout[fr_cmdl]: print("%s" % (base[ic][otyp]['r']), end=' ', file=fd)
671 if( has_alpha(to_cmdl) and not has_alpha(fr_cmdl) ):
672 alfa = cdata if fr_typ is None else adata
673 print("%s" % (alfa[otyp]), end=' ', file=fd)
676 if( is_rgb(fr_cmdl) and is_yuv(to_cmdl) ):
678 print(" int32_t y = r, u = g, v = b;", file=fd)
679 elif( otyp == "i8" ):
680 print(" int32_t y, u, v; YUV::yuv.rgb_to_yuv_8(r, g, b, y, u, v);", file=fd)
681 elif( otyp == "i16" ):
682 print(" int32_t y, u, v; YUV::yuv.rgb_to_yuv_16(r, g, b, y, u, v);", file=fd)
683 elif( is_yuv(fr_cmdl) and is_rgb(to_cmdl)):
685 print(" int32_t r, g, b; YUV::yuv.yuv_to_rgb_8(r, g, b, y, u, v);", file=fd)
686 elif( otyp == "i16" ):
687 print(" int32_t r, g, b; YUV::yuv.yuv_to_rgb_16(r, g, b, y, u, v);", file=fd)
689 if( has_bgcolor(fr_cmdl,to_cmdl) ):
690 print("%s" % (base["bbg"][otyp]), file=fd)
691 elif( has_alpha(fr_cmdl) and not has_alpha(to_cmdl) ):
692 if( is_rgb(to_cmdl) ):
693 print("%s" % (base["brgb"][otyp]), file=fd)
694 elif( is_yuv(to_cmdl) ):
695 print("%s" % (base["byuv"][otyp]), file=fd)
697 for oc in layout[to_cmdl]:
698 print("%s" % (base[oc][otyp]['w']), end=' ', file=fd)
699 print("xfer_end", file=fd)
704 class_qual = "BC_Xfer::"
707 xid = "".join([chr(x) if chr(x).isalnum() else '_' for x in range(256)])
708 xid = "__" + xfn.upper()[xfn.rfind("/")+1:].translate(xid) + "__"
709 print("#ifndef %s" % xid, file=fd)
710 print("#define %s" % xid, file=fd)
712 xfd = open("bcxfer.h")
716 for fr_cmdl in cmodels:
717 ityp = dtype[fr_cmdl]
718 for to_cmdl in cmodels:
719 otyp = dtype[to_cmdl]
720 if( is_specialized(fr_cmdl, to_cmdl) ):
721 print(" void %s(unsigned y0, unsigned y1);" % (special[(fr_cmdl, to_cmdl)]), file=fd)
723 if( ityp is None or otyp is None or ctype[otyp] is None ): continue
724 gen_xfer_proto(fd, " ", "", fr_cmdl, to_cmdl);
726 # end of class definition
729 print("#endif", file=fd)
731 xfn = xfn[:xfn.rfind(".h")]
734 for fr_cmdl in cmodels:
735 fd = open(xfn + "_" + fr_cmdl + ".C", "w")
736 print("#include \"xfer.h\"", file=fd)
738 for to_cmdl in cmodels:
739 gen_xfer_fn(fd, fr_cmdl, to_cmdl)
742 fd = open(xfn + ".C", "w")
744 print("#include \"xfer.h\"", file=fd)
746 print("int %sxfer()" % class_qual, file=fd)
749 print(" static xfer_fn xfns[%d][%d] = {" % (mx_no, mx_no), file=fd)
750 for fr_no in range(mx_no):
751 fr_cmdl = bcmodels.get(fr_no)
752 ityp = dtype[fr_cmdl]
753 print(" { // %s" % (fr_cmdl.upper() if ityp else "None"), file=fd)
755 for to_no in range(mx_no):
756 to_cmdl = bcmodels.get(to_no)
757 otyp = dtype[to_cmdl]
758 xfn = special[(fr_cmdl, to_cmdl)] if( is_specialized(fr_cmdl, to_cmdl) ) else \
759 "xfer_%s_to_%s" % (fr_cmdl[3:], to_cmdl[3:]) if ( ityp and otyp and ctype[otyp] ) else None
760 if( n > 72 ): print("", file=fd); n = 0
761 if( n == 0 ): print(" ", end=' ', file=fd); n += 4
762 fn = "&%s%s" % (class_qual, xfn) if( xfn ) else "0"
763 print("%s, " % (fn), end=' ', file=fd)
765 print("}, ", file=fd)
766 print(" }; ", file=fd)
767 print(" xfn = xfns[in_colormodel][out_colormodel];", file=fd)
768 print(" return xfer_slices(out_w*out_h/0x80000+1);", file=fd)
771 print("#include \"bcxfer.C\"", file=fd)