diff options
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/cspace.c | 173 | ||||
-rw-r--r-- | frontend/cspace.h | 18 | ||||
-rw-r--r-- | frontend/cspace_neon.s | 165 | ||||
-rw-r--r-- | frontend/libretro.c | 2 | ||||
-rw-r--r-- | frontend/menu.c | 2 | ||||
-rw-r--r-- | frontend/plat_pollux.c | 2 | ||||
-rw-r--r-- | frontend/plat_sdl.c | 2 | ||||
-rw-r--r-- | frontend/plugin_lib.c | 2 |
8 files changed, 361 insertions, 5 deletions
diff --git a/frontend/cspace.c b/frontend/cspace.c new file mode 100644 index 0000000..f0c4912 --- /dev/null +++ b/frontend/cspace.c @@ -0,0 +1,173 @@ +/* + * (C) Gražvydas "notaz" Ignotas, 2011,2012 + * + * This work is licensed under the terms of any of these licenses + * (at your option): + * - GNU GPL, version 2 or later. + * - GNU LGPL, version 2.1 or later. + * See the COPYING file in the top-level directory. + */ + +#include "cspace.h" + +/* + * note: these are intended for testing and should be avoided + * in favor of NEON version or platform-specific conversion + */ + +#ifndef __ARM_NEON__ + +void bgr555_to_rgb565(void *dst_, const void *src_, int bytes) +{ + const unsigned int *src = src_; + unsigned int *dst = dst_; + unsigned int p; + int x; + + for (x = 0; x < bytes / 4; x++) { + p = src[x]; + p = ((p & 0x7c007c00) >> 10) | ((p & 0x03e003e0) << 1) + | ((p & 0x001f001f) << 11); + dst[x] = p; + } +} + +void bgr888_to_rgb565(void *dst_, const void *src_, int bytes) +{ + const unsigned char *src = src_; + unsigned int *dst = dst_; + unsigned int r1, g1, b1, r2, g2, b2; + + for (; bytes >= 6; bytes -= 6, src += 6, dst++) { + r1 = src[0] & 0xf8; + g1 = src[1] & 0xfc; + b1 = src[2] & 0xf8; + r2 = src[3] & 0xf8; + g2 = src[4] & 0xfc; + b2 = src[5] & 0xf8; + *dst = (r2 << 24) | (g2 << 19) | (b2 << 13) | + (r1 << 8) | (g1 << 3) | (b1 >> 3); + } +} + +// TODO? +void rgb888_to_rgb565(void *dst, const void *src, int bytes) {} +void bgr888_to_rgb888(void *dst, const void *src, int bytes) {} + +#endif // __ARM_NEON__ + +/* YUV stuff */ +static int yuv_ry[32], yuv_gy[32], yuv_by[32]; +static unsigned char yuv_u[32 * 2], yuv_v[32 * 2]; + +void bgr_to_uyvy_init(void) +{ + int i, v; + + /* init yuv converter: + y0 = (int)((0.299f * r0) + (0.587f * g0) + (0.114f * b0)); + y1 = (int)((0.299f * r1) + (0.587f * g1) + (0.114f * b1)); + u = (int)(8 * 0.565f * (b0 - y0)) + 128; + v = (int)(8 * 0.713f * (r0 - y0)) + 128; + */ + for (i = 0; i < 32; i++) { + yuv_ry[i] = (int)(0.299f * i * 65536.0f + 0.5f); + yuv_gy[i] = (int)(0.587f * i * 65536.0f + 0.5f); + yuv_by[i] = (int)(0.114f * i * 65536.0f + 0.5f); + } + for (i = -32; i < 32; i++) { + v = (int)(8 * 0.565f * i) + 128; + if (v < 0) + v = 0; + if (v > 255) + v = 255; + yuv_u[i + 32] = v; + v = (int)(8 * 0.713f * i) + 128; + if (v < 0) + v = 0; + if (v > 255) + v = 255; + yuv_v[i + 32] = v; + } +} + +void rgb565_to_uyvy(void *d, const void *s, int pixels) +{ + unsigned int *dst = d; + const unsigned short *src = s; + const unsigned char *yu = yuv_u + 32; + const unsigned char *yv = yuv_v + 32; + int r0, g0, b0, r1, g1, b1; + int y0, y1, u, v; + + for (; pixels > 0; src += 2, dst++, pixels -= 2) + { + r0 = (src[0] >> 11) & 0x1f; + g0 = (src[0] >> 6) & 0x1f; + b0 = src[0] & 0x1f; + r1 = (src[1] >> 11) & 0x1f; + g1 = (src[1] >> 6) & 0x1f; + b1 = src[1] & 0x1f; + y0 = (yuv_ry[r0] + yuv_gy[g0] + yuv_by[b0]) >> 16; + y1 = (yuv_ry[r1] + yuv_gy[g1] + yuv_by[b1]) >> 16; + u = yu[b0 - y0]; + v = yv[r0 - y0]; + // valid Y range seems to be 16..235 + y0 = 16 + 219 * y0 / 31; + y1 = 16 + 219 * y1 / 31; + + *dst = (y1 << 24) | (v << 16) | (y0 << 8) | u; + } +} + +void bgr555_to_uyvy(void *d, const void *s, int pixels) +{ + unsigned int *dst = d; + const unsigned short *src = s; + const unsigned char *yu = yuv_u + 32; + const unsigned char *yv = yuv_v + 32; + int r0, g0, b0, r1, g1, b1; + int y0, y1, u, v; + + for (; pixels > 0; src += 2, dst++, pixels -= 2) + { + b0 = (src[0] >> 10) & 0x1f; + g0 = (src[0] >> 5) & 0x1f; + r0 = src[0] & 0x1f; + b1 = (src[1] >> 10) & 0x1f; + g1 = (src[1] >> 5) & 0x1f; + r1 = src[1] & 0x1f; + y0 = (yuv_ry[r0] + yuv_gy[g0] + yuv_by[b0]) >> 16; + y1 = (yuv_ry[r1] + yuv_gy[g1] + yuv_by[b1]) >> 16; + u = yu[b0 - y0]; + v = yv[r0 - y0]; + y0 = 16 + 219 * y0 / 31; + y1 = 16 + 219 * y1 / 31; + + *dst = (y1 << 24) | (v << 16) | (y0 << 8) | u; + } +} + +void bgr888_to_uyvy(void *d, const void *s, int pixels) +{ + unsigned int *dst = d; + const unsigned char *src8 = s; + const unsigned char *yu = yuv_u + 32; + const unsigned char *yv = yuv_v + 32; + int r0, g0, b0, r1, g1, b1; + int y0, y1, u, v; + + for (; pixels > 0; src8 += 3*2, dst++, pixels -= 2) + { + r0 = src8[0], g0 = src8[1], b0 = src8[2]; + r1 = src8[3], g1 = src8[4], b1 = src8[5]; + y0 = (r0 * 19595 + g0 * 38470 + b0 * 7471) >> 16; + y1 = (r1 * 19595 + g1 * 38470 + b1 * 7471) >> 16; + u = yu[(b0 - y0) / 8]; + v = yv[(r0 - y0) / 8]; + y0 = 16 + 219 * y0 / 255; + y1 = 16 + 219 * y1 / 255; + + *dst = (y1 << 24) | (v << 16) | (y0 << 8) | u; + } +} diff --git a/frontend/cspace.h b/frontend/cspace.h new file mode 100644 index 0000000..1a9e339 --- /dev/null +++ b/frontend/cspace.h @@ -0,0 +1,18 @@ +#ifdef __cplusplus +extern "C" +{ +#endif + +void bgr555_to_rgb565(void *dst, const void *src, int bytes); +void bgr888_to_rgb888(void *dst, const void *src, int bytes); +void bgr888_to_rgb565(void *dst, const void *src, int bytes); +void rgb888_to_rgb565(void *dst, const void *src, int bytes); + +void bgr_to_uyvy_init(void); +void rgb565_to_uyvy(void *d, const void *s, int pixels); +void bgr555_to_uyvy(void *d, const void *s, int pixels); +void bgr888_to_uyvy(void *d, const void *s, int pixels); + +#ifdef __cplusplus +} +#endif diff --git a/frontend/cspace_neon.s b/frontend/cspace_neon.s new file mode 100644 index 0000000..b458f06 --- /dev/null +++ b/frontend/cspace_neon.s @@ -0,0 +1,165 @@ +/* + * (C) Gražvydas "notaz" Ignotas, 2010 + * + * This work is licensed under the terms of any of these licenses + * (at your option): + * - GNU GPL, version 2 or later. + * - GNU LGPL, version 2.1 or later. + * See the COPYING file in the top-level directory. + */ + +.text +.align 2 + +.global bgr555_to_rgb565 +bgr555_to_rgb565: + pld [r1] + mov r3, #0x07c0 + vdup.16 q15, r3 + subs r2, r2, #64 + blt btr16_end64 +0: + pld [r1, #64*2] + vldmia r1!, {q0-q3} + vshl.u16 q4, q0, #11 + vshl.u16 q5, q1, #11 + vshl.u16 q6, q2, #11 + vshl.u16 q7, q3, #11 + vsri.u16 q4, q0, #10 + vsri.u16 q5, q1, #10 + vsri.u16 q6, q2, #10 + vsri.u16 q7, q3, #10 + vshl.u16 q0, q0, #1 + vshl.u16 q1, q1, #1 + vshl.u16 q2, q2, #1 + vshl.u16 q3, q3, #1 + vbit q4, q0, q15 + vbit q5, q1, q15 + vbit q6, q2, q15 + vbit q7, q3, q15 + vstmia r0!, {q4-q7} + subs r2, r2, #64 + bge 0b + +btr16_end64: + adds r2, r2, #64 + bxeq lr + subs r2, r2, #16 + blt btr16_end16 + + @ handle the remainder (reasonably rare) +0: + vld1.16 {q0}, [r1]! + vshl.u16 q1, q0, #11 + vshl.u16 q2, q0, #1 + vsri.u16 q1, q0, #10 + vbit q1, q2, q15 + subs r2, r2, #16 + vst1.16 {q1}, [r0]! + bge 0b + +btr16_end16: + adds r2, r2, #16 + bxeq lr + subs r2, r2, #8 + bxlt lr + + @ very rare + vld1.16 d0, [r1]! + vshl.u16 d1, d0, #11 + vshl.u16 d2, d0, #1 + vsri.u16 d1, d0, #10 + vbit d1, d2, d30 + vst1.16 d1, [r0]! + bx lr + + +.global bgr888_to_rgb888 +bgr888_to_rgb888: + pld [r1] + @ r2 /= 48 + mov r2, r2, lsr #4 + movw r3, #0x5556 + movt r3, #0x5555 + umull r12,r2, r3, r2 +0: + pld [r1, #48*3] + vld3.8 {d0-d2}, [r1, :64]! + vld3.8 {d3-d5}, [r1, :64]! + vswp d0, d2 + vswp d3, d5 + vst3.8 {d0-d2}, [r0, :64]! + vst3.8 {d3-d5}, [r0, :64]! + subs r2, r2, #1 + bne 0b + + bx lr + + +.global bgr888_to_rgb565 +bgr888_to_rgb565: + pld [r1] + @ r2 /= 48 + mov r2, r2, lsr #4 + movw r3, #0x5556 + movt r3, #0x5555 + umull r12,r2, r3, r2 + + mov r3, #0x07e0 + vdup.16 q15, r3 +0: + pld [r1, #48*3] + vld3.8 {d1-d3}, [r1, :64]! + vld3.8 {d5-d7}, [r1, :64]! + + vshll.u8 q8, d2, #3 @ g + vshll.u8 q9, d6, #3 + vshr.u8 d0, d3, #3 @ b + vshr.u8 d4, d7, #3 + vzip.8 d0, d1 @ rb + vzip.8 d4, d5 + vbit q0, q8, q15 + vbit q2, q9, q15 + + vstmia r0!, {d0,d1} + vstmia r0!, {d4,d5} + subs r2, r2, #1 + bne 0b + + bx lr + + +.global rgb888_to_rgb565 +rgb888_to_rgb565: + pld [r1] + @ r2 /= 48 + mov r2, r2, lsr #4 + movw r3, #0x5556 + movt r3, #0x5555 + umull r12,r2, r3, r2 + + mov r3, #0x07e0 + vdup.16 q15, r3 +0: + pld [r1, #48*3] + vld3.8 {d1-d3}, [r1, :64]! + vld3.8 {d5-d7}, [r1, :64]! + + vshll.u8 q8, d2, #3 @ g + vshll.u8 q9, d6, #3 + vshr.u8 d2, d1, #3 @ b + vshr.u8 d6, d5, #3 + vzip.8 d2, d3 @ rb + vzip.8 d6, d7 + vbit q1, q8, q15 + vbit q3, q9, q15 + + vstmia r0!, {d2,d3} + vstmia r0!, {d6,d7} + subs r2, r2, #1 + bne 0b + + bx lr + + +@ vim:filetype=armasm diff --git a/frontend/libretro.c b/frontend/libretro.c index 4f6879e..c6d113f 100644 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@ -15,7 +15,7 @@ #include "../libpcsxcore/new_dynarec/new_dynarec.h" #include "../libpcsxcore/cheat.h" #include "../plugins/dfsound/out.h" -#include "../plugins/gpulib/cspace.h" +#include "cspace.h" #include "main.h" #include "plugin.h" #include "plugin_lib.h" diff --git a/frontend/menu.c b/frontend/menu.c index b25e192..46e4298 100644 --- a/frontend/menu.c +++ b/frontend/menu.c @@ -26,6 +26,7 @@ #include "plugin_lib.h" #include "plat.h" #include "pcnt.h" +#include "cspace.h" #include "libpicofe/plat.h" #include "libpicofe/input.h" #include "libpicofe/linux/in_evdev.h" @@ -36,7 +37,6 @@ #include "../libpcsxcore/cheat.h" #include "../libpcsxcore/new_dynarec/new_dynarec.h" #include "../plugins/dfinput/externals.h" -#include "../plugins/gpulib/cspace.h" #include "psemu_plugin_defs.h" #include "revision.h" diff --git a/frontend/plat_pollux.c b/frontend/plat_pollux.c index c932261..252feba 100644 --- a/frontend/plat_pollux.c +++ b/frontend/plat_pollux.c @@ -46,8 +46,8 @@ #include "main.h" #include "menu.h" #include "plat.h" +#include "cspace.h" #include "../libpcsxcore/psxmem_map.h" -#include "../plugins/gpulib/cspace.h" static int fbdev = -1; diff --git a/frontend/plat_sdl.c b/frontend/plat_sdl.c index 2aa199f..dacf584 100644 --- a/frontend/plat_sdl.c +++ b/frontend/plat_sdl.c @@ -17,7 +17,7 @@ #include "libpicofe/fonts.h" #include "libpicofe/plat_sdl.h" #include "libpicofe/gl.h" -#include "../plugins/gpulib/cspace.h" +#include "cspace.h" #include "plugin_lib.h" #include "plugin.h" #include "main.h" diff --git a/frontend/plugin_lib.c b/frontend/plugin_lib.c index 180ee4a..a3dcbab 100644 --- a/frontend/plugin_lib.c +++ b/frontend/plugin_lib.c @@ -28,10 +28,10 @@ #include "plat.h" #include "pcnt.h" #include "pl_gun_ts.h" +#include "cspace.h" #include "psemu_plugin_defs.h" #include "../libpcsxcore/new_dynarec/new_dynarec.h" #include "../libpcsxcore/psxmem_map.h" -#include "../plugins/gpulib/cspace.h" #include "../plugins/dfinput/externals.h" int in_type1, in_type2; |