38 Msg::Error(
"YUV only implemented for GL_RGB and GL_UNSIGNED_BYTE");
43 unsigned char *dy0, *dy1;
44 unsigned char *dcr, *dcb;
45 unsigned char *src0, *src1;
49 static float mult299[1024], mult587[1024], mult114[1024];
50 static float mult16874[1024], mult33126[1024], mult5[1024];
51 static float mult41869[1024], mult08131[1024];
53 unsigned char **orig_y, **orig_cr, **orig_cb;
61 for(index = 0; index <= maxValue; index++) {
62 mult299[index] = index * 0.29900F;
63 mult587[index] = index * 0.58700F;
64 mult114[index] = index * 0.11400F;
65 mult16874[index] = -0.16874F * index;
66 mult33126[index] = -0.33126F * index;
67 mult5[index] = index * 0.50000F;
68 mult41869[index] = -0.41869F * index;
69 mult08131[index] = -0.08131F * index;
77 unsigned char *pixels = (
unsigned char *)buffer->
getPixels();
83 int row_stride = width * 3;
85 orig_y = (
unsigned char **)
Malloc(
sizeof(
unsigned char *) * height);
86 for(y = 0; y < height; y++) {
87 orig_y[y] = (
unsigned char *)
Malloc(
sizeof(
unsigned char) * width);
90 orig_cr = (
unsigned char **)
Malloc(
sizeof(
char *) * height / 2);
91 for(y = 0; y < height / 2; y++) {
92 orig_cr[y] = (
unsigned char *)
Malloc(
sizeof(
char) * width / 2);
95 orig_cb = (
unsigned char **)
Malloc(
sizeof(
char *) * height / 2);
96 for(y = 0; y < height / 2; y++) {
97 orig_cb[y] = (
unsigned char *)
Malloc(
sizeof(
char) * width / 2);
103 for(y = 0; y < height; y += 2) {
104 src0 = &(pixels[y * row_stride]);
105 src1 = &(pixels[(y + 1) * row_stride]);
108 dcr = orig_cr[y / 2];
109 dcb = orig_cb[y / 2];
111 for(x = 0; x < width;
112 x += 2, dy0 += 2, dy1 += 2, dcr++, dcb++, src0 += 6, src1 += 6) {
114 (
unsigned char)(mult299[*src0] + mult587[src0[1]] + mult114[src0[2]]);
117 (
unsigned char)(mult299[*src1] + mult587[src1[1]] + mult114[src1[2]]);
120 (
unsigned char)(mult299[src0[3]] + mult587[src0[4]] + mult114[src0[5]]);
123 (
unsigned char)(mult299[src1[3]] + mult587[src1[4]] + mult114[src1[5]]);
125 *dcb = (
unsigned char)((mult16874[*src0] + mult33126[src0[1]] +
126 mult5[src0[2]] + mult16874[*src1] +
127 mult33126[src1[1]] + mult5[src1[2]] +
128 mult16874[src0[3]] + mult33126[src0[4]] +
129 mult5[src0[5]] + mult16874[src1[3]] +
130 mult33126[src1[4]] + mult5[src1[5]]) /
134 *dcr = (
unsigned char)((mult5[*src0] + mult41869[src0[1]] +
135 mult08131[src0[2]] + mult5[*src1] +
136 mult41869[src1[1]] + mult08131[src1[2]] +
137 mult5[src0[3]] + mult41869[src0[4]] +
138 mult08131[src0[5]] + mult5[src1[3]] +
139 mult41869[src1[4]] + mult08131[src1[5]]) /
146 for(y = height - 1; y >= 0; y--) fwrite(orig_y[y], 1, width, outfile);
149 for(y = height / 2 - 1; y >= 0; y--)
150 fwrite(orig_cb[y], 1, width / 2, outfile);
153 for(y = height / 2 - 1; y >= 0; y--)
154 fwrite(orig_cr[y], 1, width / 2, outfile);
156 for(y = 0; y < height; y++)
Free(orig_y[y]);
159 for(y = 0; y < height / 2; y++)
Free(orig_cr[y]);
162 for(y = 0; y < height / 2; y++)
Free(orig_cb[y]);