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);
35 void bgr888_to_rgb565(void *dst_, const void *src_, int bytes)
37 const unsigned char *src = src_;
38 unsigned int *dst = dst_;
39 unsigned int r1, g1, b1, r2, g2, b2;
41 for (; bytes >= 6; bytes -= 6, src += 6, dst++) {
48 *dst = (r2 << 24) | (g2 << 19) | (b2 << 13) |
49 (r1 << 8) | (g1 << 3) | (b1 >> 3);
54 void rgb888_to_rgb565(void *dst, const void *src, int bytes) {}
55 void bgr888_to_rgb888(void *dst, const void *src, int bytes) {}
57 #endif // __ARM_NEON__
60 static int yuv_ry[32], yuv_gy[32], yuv_by[32];
61 static unsigned char yuv_u[32 * 2], yuv_v[32 * 2];
63 void bgr_to_uyvy_init(void)
67 /* init yuv converter:
68 y0 = (int)((0.299f * r0) + (0.587f * g0) + (0.114f * b0));
69 y1 = (int)((0.299f * r1) + (0.587f * g1) + (0.114f * b1));
70 u = (int)(8 * 0.565f * (b0 - y0)) + 128;
71 v = (int)(8 * 0.713f * (r0 - y0)) + 128;
73 for (i = 0; i < 32; i++) {
74 yuv_ry[i] = (int)(0.299f * i * 65536.0f + 0.5f);
75 yuv_gy[i] = (int)(0.587f * i * 65536.0f + 0.5f);
76 yuv_by[i] = (int)(0.114f * i * 65536.0f + 0.5f);
78 for (i = -32; i < 32; i++) {
79 v = (int)(8 * 0.565f * i) + 128;
85 v = (int)(8 * 0.713f * i) + 128;
94 void bgr555_to_uyvy(void *d, const void *s, int pixels)
96 unsigned int *dst = d;
97 const unsigned short *src = s;
98 const unsigned char *yu = yuv_u + 32;
99 const unsigned char *yv = yuv_v + 32;
100 int r0, g0, b0, r1, g1, b1;
103 for (; pixels > 0; src += 2, dst++, pixels -= 2)
105 b0 = (src[0] >> 10) & 0x1f;
106 g0 = (src[0] >> 5) & 0x1f;
108 b1 = (src[1] >> 10) & 0x1f;
109 g1 = (src[1] >> 5) & 0x1f;
111 y0 = (yuv_ry[r0] + yuv_gy[g0] + yuv_by[b0]) >> 16;
112 y1 = (yuv_ry[r1] + yuv_gy[g1] + yuv_by[b1]) >> 16;
115 // valid Y range seems to be 16..235
116 y0 = 16 + 219 * y0 / 31;
117 y1 = 16 + 219 * y1 / 31;
119 *dst = (y1 << 24) | (v << 16) | (y0 << 8) | u;
123 void bgr888_to_uyvy(void *d, const void *s, int pixels)
125 unsigned int *dst = d;
126 const unsigned char *src8 = s;
127 const unsigned char *yu = yuv_u + 32;
128 const unsigned char *yv = yuv_v + 32;
129 int r0, g0, b0, r1, g1, b1;
132 for (; pixels > 0; src8 += 3*2, dst++, pixels -= 2)
134 r0 = src8[0], g0 = src8[1], b0 = src8[2];
135 r1 = src8[3], g1 = src8[4], b1 = src8[5];
136 y0 = (r0 * 19595 + g0 * 38470 + b0 * 7471) >> 16;
137 y1 = (r1 * 19595 + g1 * 38470 + b1 * 7471) >> 16;
138 u = yu[(b0 - y0) / 8];
139 v = yv[(r0 - y0) / 8];
140 y0 = 16 + 219 * y0 / 255;
141 y1 = 16 + 219 * y1 / 255;
143 *dst = (y1 << 24) | (v << 16) | (y0 << 8) | u;