3 /* pretty simple but astonishingly very effective "debayer" function
6 void redcode_ycbcr2rgb_fullscale(
7 int ** planes, int width, int height, float * out)
11 int mask = pix_max - 1;
14 for (y = 0; y < height; y++) {
15 for (x = 0; x < width; x++) {
17 int i_p = (y > 0) ? i-width : i;
18 int i_n = (y < (height-1)) ? i + width : i;
19 float y1n = planes[0][i_n] & mask;
20 float y1 = planes[0][i] & mask;
21 float cb = (planes[1][i] & mask) - pix_max/2;
22 float cr = (planes[2][i] & mask) - pix_max/2;
23 float y2 = (planes[3][i] & mask);
24 float y2p = (planes[3][i_p] & mask);
26 float b_ = cb /(pix_max/2);
27 float r_ = cr /(pix_max/2);
30 float y_[4] = {y1 / pix_max,
31 (y2 + y2p)/2 / pix_max,
32 (y1 + y1n)/2 / pix_max,
38 o = out + (2*height-1-2*y)*2*4*width
41 for (j = 0; j < 8; j += 4) {
49 o = out + (2*height-1-2*y)*2*4*width
52 for (j = 0; j < 8; j += 4) {
63 void redcode_ycbcr2rgb_halfscale(
64 int ** planes, int width, int height, float * out)
68 int mask = pix_max - 1;
70 for (y = 0; y < height; y++) {
71 float *o = out + width * (height - y - 1);
72 for (x = 0; x < width; x++) {
74 float y1 = (planes[0][i] & mask);
75 float cb = (planes[1][i] & mask) - pix_max/2;
76 float cr = (planes[2][i] & mask) - pix_max/2;
77 float y2 = (planes[3][i] & mask);
79 float b_ = cb /(pix_max/2);
80 float r_ = cr /(pix_max/2);
83 float y = (y1 + y2)/2 / pix_max;
94 void redcode_ycbcr2rgb_quarterscale(
95 int ** planes, int width, int height, float * out)
99 int mask = pix_max - 1;
101 for (y = 0; y < height; y += 2) {
102 float *o = out + (width/2) * (height/2 - y/2 - 1);
103 for (x = 0; x < width; x += 2) {
104 int i = y * width + x;
105 float y1 = planes[0][i] & mask;
106 float cb = (planes[1][i] & mask) - pix_max/2;
107 float cr = (planes[2][i] & mask) - pix_max/2;
108 float y2 = planes[3][i] & mask;
110 float b_ = cb /(pix_max/2);
111 float r_ = cr /(pix_max/2);
114 float y = (y1 + y2)/2 / pix_max;