1
0
Fork 0
forked from len0rd/rockbox

FS #7763 by Andree Buschmann. Speed up video rendering for Ipod Video.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14882 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Thom Johansen 2007-09-28 11:25:02 +00:00
parent d7cb90722f
commit d6ad3fbeb5

View file

@ -104,7 +104,7 @@ static void lcd_bcm_setup_rect(unsigned cmd,
lcd_bcm_write32(0xE001C, 0); lcd_bcm_write32(0xE001C, 0);
} }
static unsigned lcd_bcm_read32(unsigned address) { static inline unsigned lcd_bcm_read32(unsigned address) {
while ((inw(0x30020000) & 1) == 0); while ((inw(0x30020000) & 1) == 0);
/* write out destination address as two 16bit values */ /* write out destination address as two 16bit values */
@ -205,27 +205,39 @@ void lcd_update(void)
lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
} }
#define CSUB_X 2 /* YUV- > RGB565 conversion
#define CSUB_Y 2 * |R| |1.000000 -0.000001 1.402000| |Y'|
* |G| = |1.000000 -0.334136 -0.714136| |Pb|
* |B| |1.000000 1.772000 0.000000| |Pr|
* Scaled, normalized, rounded and tweaked to yield RGB 565:
* |R| |74 0 101| |Y' - 16| >> 9
* |G| = |74 -24 -51| |Cb - 128| >> 8
* |B| |74 128 0| |Cr - 128| >> 9
*/
#define RYFAC (31*257) #define RGBYFAC 74 /* 1.0 */
#define GYFAC (31*257) #define RVFAC 101 /* 1.402 */
#define BYFAC (31*257) #define GVFAC (-51) /* -0.714136 */
#define RVFAC 11170 /* 31 * 257 * 1.402 */ #define GUFAC (-24) /* -0.334136 */
#define GVFAC (-5690) /* 31 * 257 * -0.714136 */ #define BUFAC 128 /* 1.772 */
#define GUFAC (-2742) /* 31 * 257 * -0.344136 */
#define BUFAC 14118 /* 31 * 257 * 1.772 */
#define ROUNDOFFS (127*257) /* ROUNDOFFS contain constant for correct round-offs as well as
#define ROUNDOFFSG (63*257) constant parts of the conversion matrix (e.g. (Y'-16)*RGBYFAC
-> constant part = -16*RGBYFAC). Through extraction of these
constant parts we save at leat 4 substractions in the conversion
loop */
#define ROUNDOFFSR (256 - 16*RGBYFAC - 128*RVFAC)
#define ROUNDOFFSG (128 - 16*RGBYFAC - 128*GVFAC - 128*GUFAC)
#define ROUNDOFFSB (256 - 16*RGBYFAC - 128*BUFAC)
#define MAX_5BIT 0x1f
#define MAX_6BIT 0x3f
/* Performance function to blit a YUV bitmap directly to the LCD */ /* Performance function to blit a YUV bitmap directly to the LCD */
void lcd_yuv_blit(unsigned char * const src[3], void lcd_yuv_blit(unsigned char * const src[3],
int src_x, int src_y, int stride, int src_x, int src_y, int stride,
int x, int y, int width, int height) int x, int y, int width, int height)
{ {
int ymax;
width = (width + 1) & ~1; width = (width + 1) & ~1;
if (finishup_needed) { if (finishup_needed) {
@ -261,119 +273,83 @@ void lcd_yuv_blit(unsigned char * const src[3],
/* wait for it to be write ready */ /* wait for it to be write ready */
while ((inw(0x30030000) & 0x2) == 0); while ((inw(0x30030000) & 0x2) == 0);
ymax = y + height - 1 ; const int ymax = y + height - 1;
const int stride_div_sub_x = stride >> 1;
const int stride_div_csub_x = stride/CSUB_X; unsigned char *ysrc = 0;
unsigned char *usrc = 0;
unsigned char *vsrc = 0;
unsigned char *row_end = 0;
int uvoffset;
int yp, up, vp, rc, gc, bc; /* temporary variables */
int red1, green1, blue1; /* contain RGB of 1st pixel */
int red2, green2, blue2; /* contain RGB of 2nd pixel */
for (; y <= ymax ; y++) for (; y <= ymax ; y++)
{ {
/* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */ /* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */
const unsigned char *ysrc = src[0] + stride * src_y + src_x; uvoffset = stride_div_sub_x*(src_y >> 1) + (src_x >> 1);
ysrc = src[0] + stride * src_y + src_x;
usrc = src[1] + uvoffset;
vsrc = src[2] + uvoffset;
const int uvoffset = stride_div_csub_x * (src_y/CSUB_Y) + row_end = ysrc + width;
(src_x/CSUB_X);
const unsigned char *usrc = src[1] + uvoffset;
const unsigned char *vsrc = src[2] + uvoffset;
const unsigned char *row_end = ysrc + width;
int y, u, v;
int red1, green1, blue1;
int red2, green2, blue2;
unsigned rbits, gbits, bbits;
int rc, gc, bc;
do do
{ {
u = *usrc++ - 128; up = *usrc++;
v = *vsrc++ - 128; vp = *vsrc++;
rc = RVFAC * v + ROUNDOFFS; rc = RVFAC * vp + ROUNDOFFSR;
gc = GVFAC * v + GUFAC * u + ROUNDOFFSG; gc = GVFAC * vp + GUFAC * up + ROUNDOFFSG;
bc = BUFAC * u + ROUNDOFFS; bc = BUFAC * up + ROUNDOFFSB;
/* Pixel 1 */ /* Pixel 1 -> RGB565 */
y = *ysrc++; yp = *ysrc++ * RGBYFAC;
red1 = (yp + rc) >> 9;
green1 = (yp + gc) >> 8;
blue1 = (yp + bc) >> 9;
red1 = RYFAC * y + rc; /* Pixel 2 -> RGB565 */
green1 = GYFAC * y + gc; yp = *ysrc++ * RGBYFAC;
blue1 = BYFAC * y + bc; red2 = (yp + rc) >> 9;
green2 = (yp + gc) >> 8;
/* Pixel 2 */ blue2 = (yp + bc) >> 9;
y = *ysrc++;
red2 = RYFAC * y + rc;
green2 = GYFAC * y + gc;
blue2 = BYFAC * y + bc;
/* Since out of bounds errors are relatively rare, we check two /* Since out of bounds errors are relatively rare, we check two
pixels at once to see if any components are out of bounds, and pixels at once to see if any components are out of bounds, and
then fix whichever is broken. This works due to high values and then fix whichever is broken. This works due to high values and
negative values both becoming larger than the cutoff when negative values both being !=0 when bitmasking them.
casted to unsigned. And ORing them together checks all of them We first check for red and blue components (5bit range). */
simultaneously. */ if ((red1 | blue1 | red2 | blue2) & ~MAX_5BIT)
if (((unsigned)(red1 | green1 | blue1 |
red2 | green2 | blue2)) > (RYFAC*255+ROUNDOFFS)) {
if (((unsigned)(red1 | green1 | blue1)) >
(RYFAC*255+ROUNDOFFS)) {
if ((unsigned)red1 > (RYFAC*255+ROUNDOFFS))
{ {
if (red1 < 0) if ((red1 | blue1) & ~MAX_5BIT)
red1 = 0;
else
red1 = (RYFAC*255+ROUNDOFFS);
}
if ((unsigned)green1 > (GYFAC*255+ROUNDOFFSG))
{ {
if (green1 < 0) if (red1 & ~MAX_5BIT)
green1 = 0; red1 = (red1 >> 31) ? 0 : MAX_5BIT;
else if (blue1 & ~MAX_5BIT)
green1 = (GYFAC*255+ROUNDOFFSG); blue1 = (blue1 >> 31) ? 0 : MAX_5BIT;
} }
if ((unsigned)blue1 > (BYFAC*255+ROUNDOFFS)) if ((red2 | blue2) & ~MAX_5BIT)
{ {
if (blue1 < 0) if (red2 & ~MAX_5BIT)
blue1 = 0; red2 = (red2 >> 31) ? 0 : MAX_5BIT;
else if (blue2 & ~MAX_5BIT)
blue1 = (BYFAC*255+ROUNDOFFS); blue2 = (blue2 >> 31) ? 0 : MAX_5BIT;
} }
} }
/* We second check for green component (6bit range) */
if ((green1 | green2) & ~MAX_6BIT)
{
if (green1 & ~MAX_6BIT)
green1 = (green1 >> 31) ? 0 : MAX_6BIT;
if (green2 & ~MAX_6BIT)
green2 = (green2 >> 31) ? 0 : MAX_6BIT;
}
if (((unsigned)(red2 | green2 | blue2)) > /* pixel1 */
(RYFAC*255+ROUNDOFFS)) { outw((red1 << 11) | (green1 << 5) | blue1, 0x30000000);
if ((unsigned)red2 > (RYFAC*255+ROUNDOFFS))
{
if (red2 < 0)
red2 = 0;
else
red2 = (RYFAC*255+ROUNDOFFS);
}
if ((unsigned)green2 > (GYFAC*255+ROUNDOFFSG))
{
if (green2 < 0)
green2 = 0;
else
green2 = (GYFAC*255+ROUNDOFFSG);
}
if ((unsigned)blue2 > (BYFAC*255+ROUNDOFFS))
{
if (blue2 < 0)
blue2 = 0;
else
blue2 = (BYFAC*255+ROUNDOFFS);
}
}
}
rbits = red1 >> 16 ; /* pixel2 */
gbits = green1 >> 15 ; outw((red2 << 11) | (green2 << 5) | blue2, 0x30000000);
bbits = blue1 >> 16 ;
outw((rbits << 11) | (gbits << 5) | bbits, 0x30000000);
rbits = red2 >> 16 ;
gbits = green2 >> 15 ;
bbits = blue2 >> 16 ;
outw((rbits << 11) | (gbits << 5) | bbits, 0x30000000);
} }
while (ysrc < row_end); while (ysrc < row_end);