2 * (C) GraÅžvydas "notaz" Ignotas, 2011,2012
4 * This work is licensed under the terms of any of these licenses
6 * - GNU GPL, version 2 or later.
7 * - GNU LGPL, version 2.1 or later.
8 * See the COPYING file in the top-level directory.
14 * note: these are intended for testing and should be avoided
15 * in favor of NEON version or platform-specific conversion
20 void bgr555_to_rgb565(void *dst_, const void *src_, int bytes)
22 const unsigned int *src = src_;
23 unsigned int *dst = dst_;
27 for (x = 0; x < bytes / 4; x++) {
29 p = ((p & 0x7c007c00) >> 10) | ((p & 0x03e003e0) << 1)
30 | ((p & 0x001f001f) << 11);
39 void bgr888_to_rgb565(void *dst_, const void *src_, int bytes)
41 const unsigned char *src = src_;
42 unsigned int *dst = dst_;
43 unsigned int r1, g1, b1, r2, g2, b2;
45 for (; bytes >= 6; bytes -= 6, src += 6, dst++) {
52 *dst = (r2 << 24) | (g2 << 19) | (b2 << 13) |
53 (r1 << 8) | (g1 << 3) | (b1 >> 3);
61 void bgr888_to_rgb565(void *dst_, const void *src_, int bytes)
63 const unsigned char *src = src_;
64 unsigned int *dst = dst_;
65 unsigned int r1, g1, b1, r2, g2, b2;
67 for (; bytes >= 6; bytes -= 6, src += 6, dst++) {
74 *dst = (r2 << 24) | (g2 << 19) | (b2 << 13) |
75 (r1 << 8) | (g1 << 3) | (b1 >> 3);
80 void rgb888_to_rgb565(void *dst, const void *src, int bytes) {}
81 void bgr888_to_rgb888(void *dst, const void *src, int bytes) {}
83 #endif // __ARM_NEON__
86 static int yuv_ry[32], yuv_gy[32], yuv_by[32];
87 static unsigned char yuv_u[32 * 2], yuv_v[32 * 2];
89 void bgr_to_uyvy_init(void)
93 /* init yuv converter:
94 y0 = (int)((0.299f * r0) + (0.587f * g0) + (0.114f * b0));
95 y1 = (int)((0.299f * r1) + (0.587f * g1) + (0.114f * b1));
96 u = (int)(8 * 0.565f * (b0 - y0)) + 128;
97 v = (int)(8 * 0.713f * (r0 - y0)) + 128;
99 for (i = 0; i < 32; i++) {
100 yuv_ry[i] = (int)(0.299f * i * 65536.0f + 0.5f);
101 yuv_gy[i] = (int)(0.587f * i * 65536.0f + 0.5f);
102 yuv_by[i] = (int)(0.114f * i * 65536.0f + 0.5f);
104 for (i = -32; i < 32; i++) {
105 v = (int)(8 * 0.565f * i) + 128;
111 v = (int)(8 * 0.713f * i) + 128;
120 void rgb565_to_uyvy(void *d, const void *s, int pixels)
122 unsigned int *dst = d;
123 const unsigned short *src = s;
124 const unsigned char *yu = yuv_u + 32;
125 const unsigned char *yv = yuv_v + 32;
126 int r0, g0, b0, r1, g1, b1;
129 for (; pixels > 0; src += 2, dst++, pixels -= 2)
131 r0 = (src[0] >> 11) & 0x1f;
132 g0 = (src[0] >> 6) & 0x1f;
134 r1 = (src[1] >> 11) & 0x1f;
135 g1 = (src[1] >> 6) & 0x1f;
137 y0 = (yuv_ry[r0] + yuv_gy[g0] + yuv_by[b0]) >> 16;
138 y1 = (yuv_ry[r1] + yuv_gy[g1] + yuv_by[b1]) >> 16;
141 // valid Y range seems to be 16..235
142 y0 = 16 + 219 * y0 / 31;
143 y1 = 16 + 219 * y1 / 31;
145 *dst = (y1 << 24) | (v << 16) | (y0 << 8) | u;
149 void bgr555_to_uyvy(void *d, const void *s, int pixels)
151 unsigned int *dst = d;
152 const unsigned short *src = s;
153 const unsigned char *yu = yuv_u + 32;
154 const unsigned char *yv = yuv_v + 32;
155 int r0, g0, b0, r1, g1, b1;
158 for (; pixels > 0; src += 2, dst++, pixels -= 2)
160 b0 = (src[0] >> 10) & 0x1f;
161 g0 = (src[0] >> 5) & 0x1f;
163 b1 = (src[1] >> 10) & 0x1f;
164 g1 = (src[1] >> 5) & 0x1f;
166 y0 = (yuv_ry[r0] + yuv_gy[g0] + yuv_by[b0]) >> 16;
167 y1 = (yuv_ry[r1] + yuv_gy[g1] + yuv_by[b1]) >> 16;
170 y0 = 16 + 219 * y0 / 31;
171 y1 = 16 + 219 * y1 / 31;
173 *dst = (y1 << 24) | (v << 16) | (y0 << 8) | u;
177 void bgr888_to_uyvy(void *d, const void *s, int pixels)
179 unsigned int *dst = d;
180 const unsigned char *src8 = s;
181 const unsigned char *yu = yuv_u + 32;
182 const unsigned char *yv = yuv_v + 32;
183 int r0, g0, b0, r1, g1, b1;
186 for (; pixels > 0; src8 += 3*2, dst++, pixels -= 2)
188 r0 = src8[0], g0 = src8[1], b0 = src8[2];
189 r1 = src8[3], g1 = src8[4], b1 = src8[5];
190 y0 = (r0 * 19595 + g0 * 38470 + b0 * 7471) >> 16;
191 y1 = (r1 * 19595 + g1 * 38470 + b1 * 7471) >> 16;
192 u = yu[(b0 - y0) / 8];
193 v = yv[(r0 - y0) / 8];
194 y0 = 16 + 219 * y0 / 255;
195 y1 = 16 + 219 * y1 / 255;
197 *dst = (y1 << 24) | (v << 16) | (y0 << 8) | u;