From 8999ff503db4e575aec00a3f383f78c7df2e516e Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Wed, 13 Sep 2023 11:23:16 +0200 Subject: [PATCH] unai: Fix scalers doing endianness conversion Both the VRAM and the downscale buffers are in little-endian format, there's no need to do any endianness conversion. Signed-off-by: Paul Cercueil --- plugins/gpu_unai/gpu_unai.h | 2 +- plugins/gpu_unai/gpulib_if.cpp | 35 +++++++++++++++------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/plugins/gpu_unai/gpu_unai.h b/plugins/gpu_unai/gpu_unai.h index 7aa06679..4ab5a52f 100644 --- a/plugins/gpu_unai/gpu_unai.h +++ b/plugins/gpu_unai/gpu_unai.h @@ -181,7 +181,7 @@ struct gpu_unai_t { le16_t *vram; #ifdef USE_GPULIB - u16 *downscale_vram; + le16_t *downscale_vram; #endif //////////////////////////////////////////////////////////////////////////// // Variables used only by older standalone version of gpu_unai (gpu.cpp) diff --git a/plugins/gpu_unai/gpulib_if.cpp b/plugins/gpu_unai/gpulib_if.cpp index 960ad89d..140193e6 100644 --- a/plugins/gpu_unai/gpulib_if.cpp +++ b/plugins/gpu_unai/gpulib_if.cpp @@ -70,7 +70,7 @@ #define DOWNSCALE_VRAM_SIZE (1024 * 512 * 2 * 2 + 4096) -INLINE void scale_640_to_320(uint16_t *dest, const le16_t *src, bool isRGB24) { +INLINE void scale_640_to_320(le16_t *dest, const le16_t *src, bool isRGB24) { size_t uCount = 320; if(isRGB24) { @@ -84,17 +84,17 @@ INLINE void scale_640_to_320(uint16_t *dest, const le16_t *src, bool isRGB24) { src8 += 4; } while(--uCount); } else { - const le16_t *src16 = src; - uint16_t* dst16 = dest; + const le16_t* src16 = src; + le16_t* dst16 = dest; do { - *dst16++ = le16_to_u16(*src16); + *dst16++ = *src16; src16 += 2; } while(--uCount); } } -INLINE void scale_512_to_320(uint16_t *dest, const le16_t *src, bool isRGB24) { +INLINE void scale_512_to_320(le16_t *dest, const le16_t *src, bool isRGB24) { size_t uCount = 64; if(isRGB24) { @@ -123,16 +123,16 @@ INLINE void scale_512_to_320(uint16_t *dest, const le16_t *src, bool isRGB24) { } while(--uCount); } else { const le16_t* src16 = src; - uint16_t* dst16 = dest; + le16_t* dst16 = dest; do { - *dst16++ = le16_to_u16(*src16++); - *dst16++ = le16_to_u16(*src16); + *dst16++ = *src16++; + *dst16++ = *src16; src16 += 2; - *dst16++ = le16_to_u16(*src16++); - *dst16++ = le16_to_u16(*src16); + *dst16++ = *src16++; + *dst16++ = *src16; src16 += 2; - *dst16++ = le16_to_u16(*src16); + *dst16++ = *src16; src16 += 2; } while(--uCount); } @@ -140,7 +140,7 @@ INLINE void scale_512_to_320(uint16_t *dest, const le16_t *src, bool isRGB24) { static uint16_t *get_downscale_buffer(int *x, int *y, int *w, int *h, int *vram_h) { - uint16_t *dest = gpu_unai.downscale_vram; + le16_t *dest = gpu_unai.downscale_vram; const le16_t *src = gpu_unai.vram; bool isRGB24 = (gpu_unai.GPU_GP1 & 0x00200000 ? true : false); int stride = 1024, dstride = 1024, lines = *h, orig_w = *w; @@ -184,19 +184,14 @@ static uint16_t *get_downscale_buffer(int *x, int *y, int *w, int *h, int *vram_ size_t size = isRGB24 ? *w * 3 : *w * 2; do { -#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - for (unsigned int i; i < size; i += 2) - dest[fb_offset_dest + i] = le16_to_u16(src[fb_offset_src + i]); -#else - memcpy(dest + fb_offset_dest, (u16 *)src + fb_offset_src, size); -#endif + memcpy(dest + fb_offset_dest, src + fb_offset_src, size); fb_offset_src = (fb_offset_src + stride) & fb_mask; fb_offset_dest = (fb_offset_dest + dstride) & fb_mask; } while(--lines); break; } - return gpu_unai.downscale_vram; + return (uint16_t *)gpu_unai.downscale_vram; } static void map_downscale_buffer(void) @@ -204,7 +199,7 @@ static void map_downscale_buffer(void) if (gpu_unai.downscale_vram) return; - gpu_unai.downscale_vram = (uint16_t*)gpu.mmap(DOWNSCALE_VRAM_SIZE); + gpu_unai.downscale_vram = (le16_t*)gpu.mmap(DOWNSCALE_VRAM_SIZE); if (gpu_unai.downscale_vram == NULL) { fprintf(stderr, "failed to map downscale buffer\n"); -- 2.39.5