[Redbutton-devel] SF.net SVN: redbutton: [149] redbutton-browser/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2006-11-05 10:30:54
|
Revision: 149
http://svn.sourceforge.net/redbutton/?rev=149&view=rev
Author: skilvington
Date: 2006-11-05 02:30:39 -0800 (Sun, 05 Nov 2006)
Log Message:
-----------
don't convert pixel formats more than we need to
Modified Paths:
--------------
redbutton-browser/trunk/MHEGDisplay.c
redbutton-browser/trunk/utils.c
redbutton-browser/trunk/utils.h
redbutton-browser/trunk/videoout_xshm.c
Modified: redbutton-browser/trunk/MHEGDisplay.c
===================================================================
--- redbutton-browser/trunk/MHEGDisplay.c 2006-10-12 10:00:30 UTC (rev 148)
+++ redbutton-browser/trunk/MHEGDisplay.c 2006-11-05 10:30:39 UTC (rev 149)
@@ -756,13 +756,28 @@
*/
for(i=0; i<width*height; i++)
{
- uint8_t r = rgba[(i * 4) + 0];
- uint8_t g = rgba[(i * 4) + 1];
- uint8_t b = rgba[(i * 4) + 2];
- uint8_t a = rgba[(i * 4) + 3];
-/* TODO */
-/* if we still need to do r=g=b=0 when a=0, do it here */
- uint32_t pix = (a << 24) | (r << 16) | (g << 8) | b;
+ uint8_t a, r, g, b;
+ uint32_t pix;
+ /*
+ * if the pixel is transparent, set the RGB components to 0
+ * otherwise, if we scale up the bitmap in fullscreen mode,
+ * we may end up with a border around the image
+ * this happens, for example, with the BBC's "Press Red" image
+ * it has a transparent box around it, but the RGB values are not 0 in the transparent area
+ * when we scale it up we get a pink border around it
+ */
+ a = rgba[(i * 4) + 3];
+ if(a == 0)
+ {
+ pix = 0;
+ }
+ else
+ {
+ r = rgba[(i * 4) + 0];
+ g = rgba[(i * 4) + 1];
+ b = rgba[(i * 4) + 2];
+ pix = (a << 24) | (r << 16) | (g << 8) | b;
+ }
*((uint32_t *) &rgba[i * 4]) = pix;
}
@@ -890,6 +905,7 @@
unsigned int i, npixs;
XImage *ximg;
XRenderPictFormat *pic_format;
+ enum PixelFormat av_format;
GC gc;
bitmap = safe_malloc(sizeof(MHEGBitmap));
@@ -897,41 +913,44 @@
/* find a matching XRender pixel format */
pic_format = XRenderFindStandardFormat(d->dpy, PictStandardARGB32);
+ av_format = find_av_pix_fmt(32,
+ pic_format->direct.redMask << pic_format->direct.red,
+ pic_format->direct.greenMask << pic_format->direct.green,
+ pic_format->direct.blueMask << pic_format->direct.blue);
/* copy the RGBA values into a block we can use as XImage data */
npixs = width * height;
/* 4 bytes per pixel */
xdata = safe_malloc(npixs * 4);
- /*
- * copy the pixels, converting them to our XRender RGBA order as we go
- * even if the XRender pixel layout is the same as the ffmpeg one we still process each pixel
- * because we want to make sure transparent pixels have 0 for their RGB components
- * otherwise, if we scale up the bitmap in fullscreen mode and apply our bilinear filter,
- * we may end up with a border around the image
- * this happens, for example, with the BBC's "Press Red" image
- * it has a transparent box around it, but the RGB values are not 0 in the transparent area
- * when we scale it up we get a pink border around it
- */
- for(i=0; i<npixs; i++)
+ /* are the pixel layouts exactly the same */
+ if(av_format == PIX_FMT_RGBA32)
{
- rgba_pix = *((uint32_t *) &rgba[i * 4]);
- a = (rgba_pix >> 24) & 0xff;
- r = (rgba_pix >> 16) & 0xff;
- g = (rgba_pix >> 8) & 0xff;
- b = rgba_pix & 0xff;
- /* is it transparent */
- if(a == 0)
+ memcpy(xdata, rgba, npixs * 4);
+ }
+ else
+ {
+ /* swap the RGBA components as needed */
+ for(i=0; i<npixs; i++)
{
- xpix = 0;
+ rgba_pix = *((uint32_t *) &rgba[i * 4]);
+ a = (rgba_pix >> 24) & 0xff;
+ r = (rgba_pix >> 16) & 0xff;
+ g = (rgba_pix >> 8) & 0xff;
+ b = rgba_pix & 0xff;
+ /* is it transparent */
+ if(a == 0)
+ {
+ xpix = 0;
+ }
+ else
+ {
+ xpix = a << pic_format->direct.alpha;
+ xpix |= r << pic_format->direct.red;
+ xpix |= g << pic_format->direct.green;
+ xpix |= b << pic_format->direct.blue;
+ }
+ *((uint32_t *) &xdata[i * 4]) = xpix;
}
- else
- {
- xpix = a << pic_format->direct.alpha;
- xpix |= r << pic_format->direct.red;
- xpix |= g << pic_format->direct.green;
- xpix |= b << pic_format->direct.blue;
- }
- *((uint32_t *) &xdata[i * 4]) = xpix;
}
/* get X to draw the XImage onto a Pixmap */
Modified: redbutton-browser/trunk/utils.c
===================================================================
--- redbutton-browser/trunk/utils.c 2006-10-12 10:00:30 UTC (rev 148)
+++ redbutton-browser/trunk/utils.c 2006-11-05 10:30:39 UTC (rev 149)
@@ -31,6 +31,48 @@
#include "utils.h"
/*
+ * returns a PIX_FMT_xxx type that matches the given bits per pixel and RGB bit mask values
+ * returns PIX_FMT_NONE if none match
+ */
+
+enum PixelFormat
+find_av_pix_fmt(int bpp, unsigned long rmask, unsigned long gmask, unsigned long bmask)
+{
+ enum PixelFormat fmt;
+
+ fmt = PIX_FMT_NONE;
+ switch(bpp)
+ {
+ case 32:
+ if(rmask == 0xff0000 && gmask == 0xff00 && bmask == 0xff)
+ fmt = PIX_FMT_RGBA32;
+ break;
+
+ case 24:
+ if(rmask == 0xff0000 && gmask == 0xff00 && bmask == 0xff)
+ fmt = PIX_FMT_RGB24;
+ else if(rmask == 0xff && gmask == 0xff00 && bmask == 0xff0000)
+ fmt = PIX_FMT_BGR24;
+ break;
+
+ case 16:
+ if(rmask == 0xf800 && gmask == 0x07e0 && bmask == 0x001f)
+ fmt = PIX_FMT_RGB565;
+ else if(rmask == 0x7c00 && gmask == 0x03e0 && bmask == 0x001f)
+ fmt = PIX_FMT_RGB555;
+ break;
+
+ default:
+ break;
+ }
+
+ if(fmt == PIX_FMT_NONE)
+ error("Unsupported pixel format (bpp=%d r=%lx g=%lx b=%lx)", bpp, rmask, gmask, bmask);
+
+ return fmt;
+}
+
+/*
* returns 15 for 'f' etc
*/
Modified: redbutton-browser/trunk/utils.h
===================================================================
--- redbutton-browser/trunk/utils.h 2006-10-12 10:00:30 UTC (rev 148)
+++ redbutton-browser/trunk/utils.h 2006-11-05 10:30:39 UTC (rev 149)
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <stdarg.h>
+#include <ffmpeg/avformat.h>
#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
@@ -33,6 +34,8 @@
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
+enum PixelFormat find_av_pix_fmt(int, unsigned long, unsigned long, unsigned long);
+
unsigned int char2hex(unsigned char);
int next_utf8(unsigned char *, int, int *);
Modified: redbutton-browser/trunk/videoout_xshm.c
===================================================================
--- redbutton-browser/trunk/videoout_xshm.c 2006-10-12 10:00:30 UTC (rev 148)
+++ redbutton-browser/trunk/videoout_xshm.c 2006-11-05 10:30:39 UTC (rev 149)
@@ -31,8 +31,6 @@
static void vo_xshm_resize_frame(vo_xshm_ctx *, unsigned int, unsigned int);
static void vo_xshm_destroy_frame(vo_xshm_ctx *);
-static enum PixelFormat find_av_pix_fmt(int, unsigned long, unsigned long, unsigned long);
-
void *
vo_xshm_init(void)
{
@@ -210,45 +208,3 @@
return;
}
-/*
- * returns a PIX_FMT_xxx type that matches the given bits per pixel and RGB bit mask values
- * returns PIX_FMT_NONE if none match
- */
-
-static enum PixelFormat
-find_av_pix_fmt(int bpp, unsigned long rmask, unsigned long gmask, unsigned long bmask)
-{
- enum PixelFormat fmt;
-
- fmt = PIX_FMT_NONE;
- switch(bpp)
- {
- case 32:
- if(rmask == 0xff0000 && gmask == 0xff00 && bmask == 0xff)
- fmt = PIX_FMT_RGBA32;
- break;
-
- case 24:
- if(rmask == 0xff0000 && gmask == 0xff00 && bmask == 0xff)
- fmt = PIX_FMT_RGB24;
- else if(rmask == 0xff && gmask == 0xff00 && bmask == 0xff0000)
- fmt = PIX_FMT_BGR24;
- break;
-
- case 16:
- if(rmask == 0xf800 && gmask == 0x07e0 && bmask == 0x001f)
- fmt = PIX_FMT_RGB565;
- else if(rmask == 0x7c00 && gmask == 0x03e0 && bmask == 0x001f)
- fmt = PIX_FMT_RGB555;
- break;
-
- default:
- break;
- }
-
- if(fmt == PIX_FMT_NONE)
- error("Unsupported pixel format (bpp=%d r=%lx g=%lx b=%lx)", bpp, rmask, gmask, bmask);
-
- return fmt;
-}
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|