From 50d78fb8043402cb8d595a3755249be7e6b3e808 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 13 Mar 2011 15:49:00 +0100 Subject: [PATCH] Endian fixes --- gfx/xvideo.c | 65 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/gfx/xvideo.c b/gfx/xvideo.c index 2f30184004..f01a486f3e 100644 --- a/gfx/xvideo.c +++ b/gfx/xvideo.c @@ -152,7 +152,7 @@ static void set_fullscreen(xv_t *xv) static void render16_yuy2(xv_t *xv, const void *input_, unsigned width, unsigned height, unsigned pitch) { const uint16_t *input = input_; - uint16_t *output = (uint16_t*)xv->image->data; + uint8_t *output = (uint8_t*)xv->image->data; for (unsigned y = 0; y < height; y++) { @@ -161,23 +161,26 @@ static void render16_yuy2(xv_t *xv, const void *input_, unsigned width, unsigned uint16_t p0 = *input++; uint16_t p1 = *input++; - uint8_t u = (xv->utable[p0] + xv->utable[p1]) >> 1; - uint8_t v = (xv->vtable[p0] + xv->vtable[p1]) >> 1; + uint8_t y0 = xv->ytable[p0]; + uint8_t y1 = xv->ytable[p1]; + uint8_t u = (uint8_t)(((unsigned)xv->utable[p0] + (unsigned)xv->utable[p1]) >> 1); + uint8_t v = (uint8_t)(((unsigned)xv->vtable[p0] + (unsigned)xv->vtable[p1]) >> 1); - // TODO: Will this only work on little-endian? - *output++ = (u << 8) | xv->ytable[p0]; - *output++ = (v << 8) | xv->ytable[p1]; + *output++ = y0; + *output++ = u; + *output++ = y1; + *output++ = v; } input += (pitch >> 1) - width; - output += xv->width - width; + output += (xv->width - width) << 1; } } static void render16_uyvy(xv_t *xv, const void *input_, unsigned width, unsigned height, unsigned pitch) { const uint16_t *input = input_; - uint16_t *output = (uint16_t*)xv->image->data; + uint8_t *output = (uint8_t*)xv->image->data; for (unsigned y = 0; y < height; y++) { @@ -186,23 +189,26 @@ static void render16_uyvy(xv_t *xv, const void *input_, unsigned width, unsigned uint16_t p0 = *input++; uint16_t p1 = *input++; - uint8_t u = (xv->utable[p0] + xv->utable[p1]) >> 1; - uint8_t v = (xv->vtable[p0] + xv->vtable[p1]) >> 1; + uint8_t y0 = xv->ytable[p0]; + uint8_t y1 = xv->ytable[p1]; + uint8_t u = (uint8_t)(((unsigned)xv->utable[p0] + (unsigned)xv->utable[p1]) >> 1); + uint8_t v = (uint8_t)(((unsigned)xv->vtable[p0] + (unsigned)xv->vtable[p1]) >> 1); - // TODO: Will this only work on little-endian? - *output++ = (xv->ytable[p0] << 8) | u; - *output++ = (xv->ytable[p1] << 8) | v; + *output++ = u; + *output++ = y0; + *output++ = v; + *output++ = y1; } input += (pitch >> 1) - width; - output += xv->width - width; + output += (xv->width - width) << 1; } } static void render32_yuy2(xv_t *xv, const void *input_, unsigned width, unsigned height, unsigned pitch) { const uint32_t *input = input_; - uint16_t *output = (uint16_t*)xv->image->data; + uint8_t *output = (uint8_t*)xv->image->data; for (unsigned y = 0; y < height; y++) { @@ -213,16 +219,19 @@ static void render32_yuy2(xv_t *xv, const void *input_, unsigned width, unsigned p0 = ((p0 >> 9) & 0x7c00) | ((p0 >> 6) & 0x03e0) | ((p0 >> 3) & 0x1f); // RGBA -> RGB15 p1 = ((p1 >> 9) & 0x7c00) | ((p1 >> 6) & 0x03e0) | ((p1 >> 3) & 0x1f); - uint8_t u = (xv->utable[p0] + xv->utable[p1]) >> 1; - uint8_t v = (xv->vtable[p0] + xv->vtable[p1]) >> 1; + uint8_t y0 = xv->ytable[p0]; + uint8_t y1 = xv->ytable[p1]; + uint8_t u = (uint8_t)(((unsigned)xv->utable[p0] + (unsigned)xv->utable[p1]) >> 1); + uint8_t v = (uint8_t)(((unsigned)xv->vtable[p0] + (unsigned)xv->vtable[p1]) >> 1); - // TODO: Will this only work on little-endian? - *output++ = (u << 8) | xv->ytable[p0]; - *output++ = (v << 8) | xv->ytable[p1]; + *output++ = y0; + *output++ = u; + *output++ = y1; + *output++ = v; } input += (pitch >> 2) - width; - output += xv->width - width; + output += (xv->width - width) << 1; } } @@ -240,12 +249,15 @@ static void render32_uyvy(xv_t *xv, const void *input_, unsigned width, unsigned p0 = ((p0 >> 9) & 0x7c00) | ((p0 >> 6) & 0x03e0) | ((p0 >> 3) & 0x1f); p1 = ((p1 >> 9) & 0x7c00) | ((p1 >> 6) & 0x03e0) | ((p1 >> 3) & 0x1f); - uint8_t u = (xv->utable[p0] + xv->utable[p1]) >> 1; - uint8_t v = (xv->vtable[p0] + xv->vtable[p1]) >> 1; + uint8_t y0 = xv->ytable[p0]; + uint8_t y1 = xv->ytable[p1]; + uint8_t u = (uint8_t)(((unsigned)xv->utable[p0] + (unsigned)xv->utable[p1]) >> 1); + uint8_t v = (uint8_t)(((unsigned)xv->vtable[p0] + (unsigned)xv->vtable[p1]) >> 1); - // TODO: Will this only work on little-endian? - *output++ = (xv->ytable[p0] << 8) | u; - *output++ = (xv->ytable[p1] << 8) | v; + *output++ = u; + *output++ = y0; + *output++ = v; + *output++ = y1; } input += (pitch >> 2) - width; @@ -254,7 +266,6 @@ static void render32_uyvy(xv_t *xv, const void *input_, unsigned width, unsigned } - static void* xv_init(video_info_t *video, const input_driver_t **input, void **input_data) { xv_t *xv = calloc(1, sizeof(*xv));