From 6a0f006a0c10c8dae657482bcff3c9ae179fbd5f Mon Sep 17 00:00:00 2001 From: martii Date: Sat, 27 Jul 2013 11:17:49 +0200 Subject: [PATCH] libeplayer3: use uint32_t for frame buffer access Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/b64bdcb37002b72cbdeaedad82999b56472d022a Author: martii Date: 2013-07-27 (Sat, 27 Jul 2013) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- libeplayer3/container/container_ass.c | 22 ++-- libeplayer3/include/subtitle.h | 2 +- libeplayer3/include/writer.h | 3 +- libeplayer3/output/output_subtitle.c | 15 +-- libeplayer3/output/writer/framebuffer.c | 163 +++++++++++------------- libspark/playback_libeplayer3.cpp | 2 +- libspark/playback_libeplayer3.h | 4 +- 7 files changed, 98 insertions(+), 113 deletions(-) diff --git a/libeplayer3/container/container_ass.c b/libeplayer3/container/container_ass.c index fa814ee..61ae2e3 100644 --- a/libeplayer3/container/container_ass.c +++ b/libeplayer3/container/container_ass.c @@ -123,8 +123,8 @@ static unsigned int screen_width = 0; static unsigned int screen_height = 0; static int shareFramebuffer = 0; static int framebufferFD = -1; -static unsigned char* destination = NULL; -static int destStride = 0; +static uint32_t *destination = NULL; +static int destStride = 0; static void (*framebufferBlit)(void) = NULL; static int needsBlit = 0; @@ -414,19 +414,17 @@ static void ASSThread(Context_t *context) { } if (x1 > 0 && y1 > 0) { + x1++; + y1++; int x, y; - unsigned char *dst = destination + y0 * destStride + 4 * x0; - int destStrideDiff = destStride - (x1 - x0 + 1) * 4; - for (y = y0; y <= y1; y++) { - for (x = x0; x <= x1; x++) { - *dst++ = 128; - *dst++ = 128; - *dst++ = 128; - *dst++ = 128; - } + uint32_t *dst = destination + y0 * destStride/sizeof(uint32_t) + x0; + int destStrideDiff = destStride/sizeof(uint32_t) - (x1 - x0); + for (y = y0; y < y1; y++) { + for (x = x0; x < x1; x++) + *dst++ = 0x80808080; dst += destStrideDiff; } - storeRegion(x0, y0, x1 - x0 + 1, y1 - y0 + 1, undisplay); + storeRegion(x0, y0, x1 - x0, y1 - y0, undisplay); needsBlit = 1; } } diff --git a/libeplayer3/include/subtitle.h b/libeplayer3/include/subtitle.h index d53761c..24ddbeb 100644 --- a/libeplayer3/include/subtitle.h +++ b/libeplayer3/include/subtitle.h @@ -114,7 +114,7 @@ typedef struct typedef struct { - unsigned char* destination; + uint32_t *destination; unsigned int screen_width; unsigned int screen_height; unsigned int destStride; diff --git a/libeplayer3/include/writer.h b/libeplayer3/include/writer.h index 82c699e..61c6c35 100644 --- a/libeplayer3/include/writer.h +++ b/libeplayer3/include/writer.h @@ -2,6 +2,7 @@ #define WRITER_H_ #include +#include typedef enum { eNone, eAudio, eVideo, eGfx} eWriterType_t; @@ -33,7 +34,7 @@ typedef struct { int fd; unsigned int Screen_Width; unsigned int Screen_Height; - unsigned char* destination; + uint32_t *destination; unsigned int destStride; } WriterFBCallData_t; diff --git a/libeplayer3/output/output_subtitle.c b/libeplayer3/output/output_subtitle.c index c96b10c..acb8cf9 100644 --- a/libeplayer3/output/output_subtitle.c +++ b/libeplayer3/output/output_subtitle.c @@ -103,14 +103,13 @@ static int readPointer = 0; static int writePointer = 0; static int hasThreadStarted = 0; static int isSubtitleOpened = 0; - -static int screen_width = 0; -static int screen_height = 0; -static int destStride = 0; -static int shareFramebuffer = 0; -static int framebufferFD = -1; -static void (*framebufferBlit) = NULL; -static unsigned char* destination = NULL; +static int screen_width = 0; +static int screen_height = 0; +static int destStride = 0; +static int shareFramebuffer = 0; +static int framebufferFD = -1; +static void (*framebufferBlit) = NULL; +static uint32_t *destination = NULL; /* ***************************** */ /* Prototypes */ diff --git a/libeplayer3/output/writer/framebuffer.c b/libeplayer3/output/writer/framebuffer.c index 644e897..8e06329 100644 --- a/libeplayer3/output/writer/framebuffer.c +++ b/libeplayer3/output/writer/framebuffer.c @@ -95,112 +95,99 @@ if (debug_level >= level) printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); static int reset() { - return 0; + return 0; } static int writeData(void* _call) { - int res = 0; - - WriterFBCallData_t* call = (WriterFBCallData_t*) _call; - - fb_printf(100, "\n"); + int res = 0; - if (call == NULL) - { - fb_err("call data is NULL...\n"); - return 0; - } + WriterFBCallData_t* call = (WriterFBCallData_t*) _call; - if (call->destination == NULL) - { - fb_err("file pointer < 0. ignoring ...\n"); - return 0; - } - - if (call->data != NULL) - { - unsigned int a = (unsigned int)_a(call->color); - unsigned int r = (unsigned int)_r(call->color); - unsigned int g = (unsigned int)_g(call->color); - unsigned int b = (unsigned int)_b(call->color); - unsigned int opacity = 255 - a; - int src_stride = call->Stride; - int dst_stride = call->destStride; - int dst_delta = dst_stride - call->Width*4; - unsigned int x,y; - const unsigned char *src = call->data; - unsigned char *dst = call->destination + (call->y * dst_stride + call->x * 4); -#if 1 // !HAVE_SPARK_HARDWARE - unsigned int k; -#else - unsigned int k,ck,t; -#endif + fb_printf(100, "\n"); - fb_printf(100, "x %d\n", call->x); - fb_printf(100, "y %d\n", call->y); - fb_printf(100, "width %d\n", call->Width); - fb_printf(100, "height %d\n", call->Height); - fb_printf(100, "stride %d\n", call->Stride); - fb_printf(100, "color 0x%.8x\n", call->color); - fb_printf(100, "data %p\n", call->data); - fb_printf(100, "dest %p\n", call->destination); - fb_printf(100, "dest.stride %d\n", call->destStride); + if (!call) + { + fb_err("call data is NULL...\n"); + return 0; + } - fb_printf(100, "r 0x%hhx, g 0x%hhx, b 0x%hhx, a 0x%hhx, opacity 0x%hhx\n", r, g, b, a, opacity); + if (!call->destination) + { + fb_err("frame buffer == NULL. ignoring ...\n"); + return 0; + } - for (y=0;yHeight;y++) - { - for (x = 0; x < call->Width; x++) - { - k = ((unsigned)src[x]) * opacity / 256; -#if 1 // HAVE_SPARK_HARDWARE - if (src[x]) { - *dst++ = b; - *dst++ = g; - *dst++ = r; - *dst++ = k; - } else - dst += 4; -#else - ck = 255 - k; - t = *dst; - *dst++ = (k*b + ck*t) / 256; - t = *dst; - *dst++ = (k*g + ck*t) / 256; - t = *dst; - *dst++ = (k*r + ck*t) / 256; - *dst++ = 0; -#endif - } + if (call->data) + { + int src_stride = call->Stride; + unsigned int x,y; + const unsigned char *src = call->data; + int dst_stride = call->destStride/sizeof(uint32_t); + int dst_delta = dst_stride - call->Width; + uint32_t *dst = call->destination + call->y * dst_stride + call->x; + static uint32_t last_color = 0; + static uint32_t colortable[256]; + if (last_color != call->color) { + // call->color is rgba, our spark frame buffer is argb + uint32_t c = call->color >> 8; + uint32_t a = 255 - (call->color & 0xff); + int i; + for (i = 0; i < 256; i++) + colortable[i] = c | (((a * i) >> 8) << 24); + last_color = call->color; + } - dst += dst_delta; - src += src_stride; - } - } else - { - unsigned int y; - for (y = 0; y < call->Height; y++) - memset(call->destination + ((call->y + y) * call->destStride) + call->x * 4, 0, call->Width * 4); - } - fb_printf(100, "< %d\n", res); - return res; + fb_printf(100, "x %d\n", call->x); + fb_printf(100, "y %d\n", call->y); + fb_printf(100, "width %d\n", call->Width); + fb_printf(100, "height %d\n", call->Height); + fb_printf(100, "stride %d\n", call->Stride); + fb_printf(100, "color 0x%.8x\n", call->color); + fb_printf(100, "data %p\n", call->data); + fb_printf(100, "dest %p\n", call->destination); + fb_printf(100, "dest.stride %d\n", call->destStride); + + for (y=0;yHeight;y++) { + for (x = 0; x < call->Width; x++) { + uint32_t c = colortable[src[x]]; + if (c >> 24) + *dst++ = c; + else + dst++; + } + dst += dst_delta; + src += src_stride; + } + } else { + unsigned int y; + int dst_stride = call->destStride/sizeof(uint32_t); + uint32_t *dst = call->destination + call->y * dst_stride + call->x; + + for (y = 0; y < call->Height; y++) { + memset(dst, 0, call->Width * 4); + dst += dst_stride; + } + } + + fb_printf(100, "< %d\n", res); + return res; } /* ***************************** */ /* Writer Definition */ /* ***************************** */ static WriterCaps_t caps = { - "framebuffer", - eGfx, - "framebuffer", - 0 + "framebuffer", + eGfx, + "framebuffer", + 0 }; struct Writer_s WriterFramebuffer = { - &reset, - &writeData, - NULL, - &caps + &reset, + &writeData, + NULL, + &caps }; diff --git a/libspark/playback_libeplayer3.cpp b/libspark/playback_libeplayer3.cpp index 2b1fcf2..f12d25f 100644 --- a/libspark/playback_libeplayer3.cpp +++ b/libspark/playback_libeplayer3.cpp @@ -702,7 +702,7 @@ void cPlayback::GetChapters(std::vector &positions, std::vector