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);
58 void rgb888_to_rgb565(void *dst, const void *src, int bytes) {}
59 void bgr888_to_rgb888(void *dst, const void *src, int bytes) {}
61 #endif // __ARM_NEON__
64 static int yuv_ry[32], yuv_gy[32], yuv_by[32];
65 static unsigned char yuv_u[32 * 2], yuv_v[32 * 2];
67 void bgr_to_uyvy_init(void)
71 /* init yuv converter:
72 y0 = (int)((0.299f * r0) + (0.587f * g0) + (0.114f * b0));
73 y1 = (int)((0.299f * r1) + (0.587f * g1) + (0.114f * b1));
74 u = (int)(8 * 0.565f * (b0 - y0)) + 128;
75 v = (int)(8 * 0.713f * (r0 - y0)) + 128;
77 for (i = 0; i < 32; i++) {
78 yuv_ry[i] = (int)(0.299f * i * 65536.0f + 0.5f);
79 yuv_gy[i] = (int)(0.587f * i * 65536.0f + 0.5f);
80 yuv_by[i] = (int)(0.114f * i * 65536.0f + 0.5f);
82 for (i = -32; i < 32; i++) {
83 v = (int)(8 * 0.565f * i) + 128;
89 v = (int)(8 * 0.713f * i) + 128;
98 void rgb565_to_uyvy(void *d, const void *s, int pixels)
100 unsigned int *dst = d;
101 const unsigned short *src = s;
102 const unsigned char *yu = yuv_u + 32;
103 const unsigned char *yv = yuv_v + 32;
104 int r0, g0, b0, r1, g1, b1;
107 for (; pixels > 0; src += 2, dst++, pixels -= 2)
109 r0 = (src[0] >> 11) & 0x1f;
110 g0 = (src[0] >> 6) & 0x1f;
112 r1 = (src[1] >> 11) & 0x1f;
113 g1 = (src[1] >> 6) & 0x1f;
115 y0 = (yuv_ry[r0] + yuv_gy[g0] + yuv_by[b0]) >> 16;
116 y1 = (yuv_ry[r1] + yuv_gy[g1] + yuv_by[b1]) >> 16;
119 // valid Y range seems to be 16..235
120 y0 = 16 + 219 * y0 / 31;
121 y1 = 16 + 219 * y1 / 31;
123 *dst = (y1 << 24) | (v << 16) | (y0 << 8) | u;
127 void bgr555_to_uyvy(void *d, const void *s, int pixels)
129 unsigned int *dst = d;
130 const unsigned short *src = s;
131 const unsigned char *yu = yuv_u + 32;
132 const unsigned char *yv = yuv_v + 32;
133 int r0, g0, b0, r1, g1, b1;
136 for (; pixels > 0; src += 2, dst++, pixels -= 2)
138 b0 = (src[0] >> 10) & 0x1f;
139 g0 = (src[0] >> 5) & 0x1f;
141 b1 = (src[1] >> 10) & 0x1f;
142 g1 = (src[1] >> 5) & 0x1f;
144 y0 = (yuv_ry[r0] + yuv_gy[g0] + yuv_by[b0]) >> 16;
145 y1 = (yuv_ry[r1] + yuv_gy[g1] + yuv_by[b1]) >> 16;
148 y0 = 16 + 219 * y0 / 31;
149 y1 = 16 + 219 * y1 / 31;
151 *dst = (y1 << 24) | (v << 16) | (y0 << 8) | u;
155 void bgr888_to_uyvy(void *d, const void *s, int pixels)
157 unsigned int *dst = d;
158 const unsigned char *src8 = s;
159 const unsigned char *yu = yuv_u + 32;
160 const unsigned char *yv = yuv_v + 32;
161 int r0, g0, b0, r1, g1, b1;
164 for (; pixels > 0; src8 += 3*2, dst++, pixels -= 2)
166 r0 = src8[0], g0 = src8[1], b0 = src8[2];
167 r1 = src8[3], g1 = src8[4], b1 = src8[5];
168 y0 = (r0 * 19595 + g0 * 38470 + b0 * 7471) >> 16;
169 y1 = (r1 * 19595 + g1 * 38470 + b1 * 7471) >> 16;
170 u = yu[(b0 - y0) / 8];
171 v = yv[(r0 - y0) / 8];
172 y0 = 16 + 219 * y0 / 255;
173 y1 = 16 + 219 * y1 / 255;
175 *dst = (y1 << 24) | (v << 16) | (y0 << 8) | u;