summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-04-02 09:27:12 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-04-02 09:27:12 +0000
commit6f56607212ae8d2e0ce637553bb9068f84e01798 (patch)
tree8ef278bab8748ac6a85599f95f059aec0d712739
parentfef40e465abe7ddfc5895bf2547a3f004eaa9b5c (diff)
Gigabeat: Add an assembly lcd_yuv_blit. Seems to be good for a modest speedup. ;)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12998 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/SOURCES1
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/lcd-as-meg-fx.S222
-rw-r--r--firmware/target/arm/gigabeat/meg-fx/lcd-meg-fx.c126
3 files changed, 255 insertions, 94 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index 9ec97c191e..8b1d3cf896 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -494,6 +494,7 @@ target/arm/gigabeat/meg-fx/ata-meg-fx.c
target/arm/gigabeat/meg-fx/backlight-meg-fx.c
target/arm/gigabeat/meg-fx/button-meg-fx.c
target/arm/gigabeat/meg-fx/i2c-meg-fx.c
+target/arm/gigabeat/meg-fx/lcd-as-meg-fx.S
target/arm/gigabeat/meg-fx/lcd-meg-fx.c
target/arm/gigabeat/meg-fx/power-meg-fx.c
target/arm/gigabeat/meg-fx/sc606-meg-fx.c
diff --git a/firmware/target/arm/gigabeat/meg-fx/lcd-as-meg-fx.S b/firmware/target/arm/gigabeat/meg-fx/lcd-as-meg-fx.S
new file mode 100644
index 0000000000..414f26d3c5
--- /dev/null
+++ b/firmware/target/arm/gigabeat/meg-fx/lcd-as-meg-fx.S
@@ -0,0 +1,222 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id:$
+ *
+ * Copyright (C) 2007 by Michael Sevakis
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "config.h"
+#include "cpu.h"
+
+/****************************************************************************
+ * void lcd_write_yuv_420_lines(fb_data *dst,
+ * unsigned char chroma_buf[3][LCD_HEIGHT/2],
+ unsigned char const * const src[3],
+ * int width,
+ * int stride);
+ *
+ * |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
+ */
+ .section .icode, "ax", %progbits
+ .align 2
+ .global lcd_write_yuv420_lines
+ .type lcd_write_yuv420_lines, %function
+lcd_write_yuv420_lines:
+ @ r0 = dst
+ @ r1 = chroma_buf
+ @ r2 = yuv_src
+ @ r3 = width
+ @ [sp] = stride
+ stmdb sp!, { r4-r12, lr } @ save non-scratch
+ stmdb sp!, { r0, r3 } @ save dst and width
+ mov r14, #74 @ r14 = Y factor
+ ldmia r2, { r4, r5, r6 } @ r4 = yuv_src[0] = Y'_p
+ @ r5 = yuv_src[1] = Cb_p
+ @ r6 = yuv_src[2] = Cr_p
+10: @ loop line 1 @
+ ldrb r2, [r4], #1 @ r2 = *Y'_p++;
+ ldrb r8, [r5], #1 @ r8 = *Cb_p++;
+ ldrb r11, [r6], #1 @ r11 = *Cr_p++;
+ @
+ @ compute Y
+ sub r2, r2, #16 @ r7 = Y = (Y' - 16)*74
+ mul r7, r2, r14 @
+ @
+ sub r8, r8, #128 @ Cb -= 128
+ sub r11, r11, #128 @ Cr -= 128
+ @
+ mvn r2, #24 @ compute guv
+ mul r10, r2, r8 @ r10 = Cb*-24
+ mvn r2, #51 @
+ mla r10, r2, r11, r10 @ r10 = r10 + Cr*-51
+ @
+ mov r2, #101 @ compute rv
+ mul r9, r11, r2 @ r9 = rv = Cr*101
+ @
+ @ store chromas in line buffer
+ add r8, r8, #2 @ bu = (Cb + 2) >> 2
+ mov r8, r8, asr #2 @
+ strb r8, [r1], #1 @
+ add r9, r9, #256 @ rv = (Cr + 256) >> 9
+ mov r9, r9, asr #9 @
+ strb r9, [r1], #1 @
+ mov r10, r10, asr #8 @ guv >>= 8
+ strb r10, [r1], #1 @
+ @ compute R, G, and B
+ add r2, r8, r7, asr #9 @ r2 = b = (Y >> 9) + bu
+ add r11, r9, r7, asr #9 @ r11 = r = (Y >> 9) + rv
+ add r7, r10, r7, asr #8 @ r7 = g = (Y >> 8) + guv
+ @
+ orr r12, r2, r11 @ check if clamping is needed...
+ orr r12, r12, r7, asr #1 @ ...at all
+ cmp r12, #31 @
+ bls 15f @ no clamp @
+ mov r12, #31 @
+ cmp r12, r2 @ clamp b
+ andlo r2, r12, r2, asr #31 @
+ eorlo r2, r2, r12 @
+ cmp r12, r11 @ clamp r
+ andlo r11, r12, r11, asr #31 @
+ eorlo r11, r11, r12 @
+ cmp r12, r7, asr #1 @ clamp g
+ andlo r7, r12, r7, asr #31 @
+ eorlo r7, r7, r12 @
+ orrlo r7, r7, r7, asl #1 @
+15: @ no clamp @
+ @
+ orr r12, r2, r7, lsl #5 @ r4 |= (g << 5)
+ ldrb r2, [r4], #1 @ r2 = Y' = *Y'_p++
+ orr r12, r12, r11, lsl #11 @ r4 = b | (r << 11)
+ strh r12, [r0], #240 @ store pixel
+ @
+ sub r2, r2, #16 @ r7 = Y = (Y' - 16)*74
+ mul r7, r2, r14 @ next Y
+ @ compute R, G, and B
+ add r2, r8, r7, asr #9 @ r2 = b = (Y >> 9) + bu
+ add r11, r9, r7, asr #9 @ r11 = r = (Y >> 9) + rv
+ add r7, r10, r7, asr #8 @ r7 = g = (Y >> 8) + guv
+ @
+ orr r12, r2, r11 @ check if clamping is needed...
+ orr r12, r12, r7, asr #1 @ ...at all
+ cmp r12, #31 @
+ bls 15f @ no clamp @
+ mov r12, #31 @
+ cmp r12, r2 @ clamp b
+ andlo r2, r12, r2, asr #31 @
+ eorlo r2, r2, r12 @
+ cmp r12, r11 @ clamp r
+ andlo r11, r12, r11, asr #31 @
+ eorlo r11, r11, r12 @
+ cmp r12, r7, asr #1 @ clamp g
+ andlo r7, r12, r7, asr #31 @
+ eorlo r7, r7, r12 @
+ orrlo r7, r7, r7, asl #1 @
+15: @ no clamp @
+ @
+ orr r12, r2, r11, lsl #11 @ r4 = b | (r << 11)
+ orr r12, r12, r7, lsl #5 @ r4 |= (g << 5)
+ strh r12, [r0, #240]! @ store pixel
+ add r0, r0, #2*240 @
+ @
+ subs r3, r3, #2 @
+ bgt 10b @ loop line 1 @
+ @ do second line
+ @
+ ldmia sp!, { r0, r3 } @ pop dst and width
+ sub r0, r0, #2 @ set dst to start of next line @
+ sub r1, r1, r3, asl #1 @ rewind chroma pointer...
+ ldr r2, [sp, #40] @ r2 = stride
+ add r1, r1, r3, asr #1 @ ... (r1 -= width/2*3)
+ @ move sources to start of next line
+ sub r2, r2, r3 @ r2 = skip = stride - width
+ add r4, r4, r2 @ r4 = Y'_p + skip
+ @
+20: @ loop line 2 @
+ ldrb r2, [r4], #1 @ r7 = Y' = *Y'_p++
+ ldrsb r8, [r1], #1 @ reload saved chromas
+ ldrsb r9, [r1], #1 @
+ ldrsb r10, [r1], #1 @
+ @
+ sub r2, r2, #16 @ r2 = Y = (Y' - 16)*74
+ mul r7, r2, r14 @
+ @ compute R, G, and B
+ add r2, r8, r7, asr #9 @ r2 = b = (Y >> 9) + bu
+ add r11, r9, r7, asr #9 @ r11 = r = (Y >> 9) + rv
+ add r7, r10, r7, asr #8 @ r7 = g = (Y >> 8) + guv
+ @
+ orr r12, r2, r11 @ check if clamping is needed...
+ orr r12, r12, r7, asr #1 @ ...at all
+ cmp r12, #31 @
+ bls 25f @ no clamp @
+ mov r12, #31 @
+ cmp r12, r2 @ clamp b
+ andlo r2, r12, r2, asr #31 @
+ eorlo r2, r2, r12 @
+ cmp r12, r11 @ clamp r
+ andlo r11, r12, r11, asr #31 @
+ eorlo r11, r11, r12 @
+ cmp r12, r7, asr #1 @ clamp g
+ andlo r7, r12, r7, asr #31 @
+ eorlo r7, r7, r12 @
+ orrlo r7, r7, r7, asl #1 @
+25: @ no clamp @
+ @
+ orr r12, r2, r11, lsl #11 @ r4 = b | (r << 11)
+ ldrb r2, [r4], #1 @ r2 = Y' = *Y'_p++
+ orr r12, r12, r7, lsl #5 @ r4 |= (g << 5)
+ strh r12, [r0], #240 @ store pixel
+ @
+ @ do second pixel
+ @
+ sub r2, r2, #16 @ r2 = Y = (Y' - 16)*74
+ mul r7, r2, r14 @
+ @ compute R, G, and B
+ add r2, r8, r7, asr #9 @ r2 = b = (Y >> 9) + bu
+ add r11, r9, r7, asr #9 @ r11 = r = (Y >> 9) + rv
+ add r7, r10, r7, asr #8 @ r7 = g = (Y >> 8) + guv
+ @
+ orr r12, r2, r11 @ check if clamping is needed...
+ orr r12, r12, r7, asr #1 @ ...at all
+ cmp r12, #31 @
+ bls 25f @ no clamp @
+ mov r12, #31 @
+ cmp r12, r2 @ clamp b
+ andlo r2, r12, r2, asr #31 @
+ eorlo r2, r2, r12 @
+ cmp r12, r11 @ clamp r
+ andlo r11, r12, r11, asr #31 @
+ eorlo r11, r11, r12 @
+ cmp r12, r7, asr #1 @ clamp g
+ andlo r7, r12, r7, asr #31 @
+ eorlo r7, r7, r12 @
+ orrlo r7, r7, r7, asl #1 @
+25: @ no clamp @
+ @
+ orr r12, r2, r11, lsl #11 @ r4 = b | (r << 11)
+ orr r12, r12, r7, lsl #5 @ r4 |= (g << 5)
+ strh r12, [r0, #240]! @ store pixel
+ add r0, r0, #2*240 @
+ @
+ subs r3, r3, #2 @
+ bgt 20b @ loop line 2 @
+ @
+ ldmia sp!, { r4-r12, pc } @ restore registers and return
+ .size lcd_write_yuv420_lines, .-lcd_write_yuv420_lines
diff --git a/firmware/target/arm/gigabeat/meg-fx/lcd-meg-fx.c b/firmware/target/arm/gigabeat/meg-fx/lcd-meg-fx.c
index 2d2f32069a..1bb68f9686 100644
--- a/firmware/target/arm/gigabeat/meg-fx/lcd-meg-fx.c
+++ b/firmware/target/arm/gigabeat/meg-fx/lcd-meg-fx.c
@@ -293,22 +293,12 @@ void lcd_bitmap_transparent_part(const fb_data *src, int src_x, int src_y,
: : "r" (src), "r" (dst), "r" (width), "r" (dst_end), "r" (stride), "r" (transcolor) : "r0", "r1" );
}
-#define CSUB_X 2
-#define CSUB_Y 2
-
-#define RFULL (31*257)
-#define GFULL (63*257)
-#define BFULL (31*257)
-#define RYFAC 9277 /* 31 * 257 * 1.0 * (255/219) */
-#define GYFAC 18853 /* 63 * 257 * 1.0 * (255/219) */
-#define BYFAC 9277 /* 31 * 257 * 1.0 * (255/219) */
-#define RVFAC 12716 /* 31 * 257 * 1.402 * (255/224) */
-#define GVFAC (-13163) /* 63 * 257 * -0.714136 * (255/224) */
-#define GUFAC (-6343) /* 63 * 257 * -0.344136 * (255/224) */
-#define BUFAC 16071 /* 31 * 257 * 1.772 * (255/224) */
-
-#define ROUNDOFFS (127*257)
-
+/* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
+extern void lcd_write_yuv420_lines(fb_data *dst,
+ unsigned char chroma_buf[LCD_HEIGHT/2*3],
+ unsigned char const * const src[3],
+ int width,
+ int stride);
/* Performance function to blit a YUV bitmap directly to the LCD */
/* For the Gigabeat - show it rotated */
/* So the LCD_WIDTH is now the height */
@@ -316,90 +306,38 @@ void lcd_yuv_blit(unsigned char * const src[3],
int src_x, int src_y, int stride,
int x, int y, int width, int height)
{
- width = (width + 1) & ~1;
- fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + (LCD_WIDTH - y) - 1;
- fb_data *dst_last = dst - (height - 1);
+ /* Caches for chroma data so it only need be recaculated every other
+ line */
+ unsigned char chroma_buf[LCD_HEIGHT/2*3]; /* 480 bytes */
+ unsigned char const * yuv_src[3];
+ off_t z;
- for (;;)
- {
- fb_data *dst_row = dst;
- int count = width;
- const unsigned char *ysrc = src[0] + stride * src_y + src_x;
- int y, u, v;
- int red, green, blue;
- unsigned rbits, gbits, bbits;
-
- /* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */
- const unsigned char *usrc = src[1] + (stride/CSUB_X) * (src_y/CSUB_Y)
- + (src_x/CSUB_X);
- const unsigned char *vsrc = src[2] + (stride/CSUB_X) * (src_y/CSUB_Y)
- + (src_x/CSUB_X);
- int xphase = src_x % CSUB_X;
- int rc, gc, bc;
-
- u = *usrc++ - 128;
- v = *vsrc++ - 128;
- rc = RVFAC * v + ROUNDOFFS;
- gc = GVFAC * v + GUFAC * u + ROUNDOFFS;
- bc = BUFAC * u + ROUNDOFFS;
-
- do
- {
- y = *ysrc++ - 16;
- red = RYFAC * y + rc;
- green = GYFAC * y + gc;
- blue = BYFAC * y + bc;
-
- if ((unsigned)red > (RFULL*255+ROUNDOFFS))
- {
- if (red < 0)
- red = 0;
- else
- red = (RFULL*255+ROUNDOFFS);
- }
- if ((unsigned)green > (GFULL*255+ROUNDOFFS))
- {
- if (green < 0)
- green = 0;
- else
- green = (GFULL*255+ROUNDOFFS);
- }
- if ((unsigned)blue > (BFULL*255+ROUNDOFFS))
- {
- if (blue < 0)
- blue = 0;
- else
- blue = (BFULL*255+ROUNDOFFS);
- }
- rbits = ((unsigned)red) >> 16 ;
- gbits = ((unsigned)green) >> 16 ;
- bbits = ((unsigned)blue) >> 16 ;
-
- *dst_row = (rbits << 11) | (gbits << 5) | bbits;
-
- /* next pixel - since rotated, add WIDTH */
- dst_row += LCD_WIDTH;
-
- if (++xphase >= CSUB_X)
- {
- u = *usrc++ - 128;
- v = *vsrc++ - 128;
- rc = RVFAC * v + ROUNDOFFS;
- gc = GVFAC * v + GUFAC * u + ROUNDOFFS;
- bc = BUFAC * u + ROUNDOFFS;
- xphase = 0;
- }
- }
- while (--count);
+ if (!lcd_on)
+ return;
- if (dst == dst_last) break;
+ /* Sorry, but width and height must be >= 2 or else */
+ width &= ~1;
+ height >>= 1;
- dst--;
- src_y++;
+ fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + (LCD_WIDTH - y) - 1;
+
+ z = stride*src_y;
+ yuv_src[0] = src[0] + z + src_x;
+ yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
+ yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
+
+ do
+ {
+ lcd_write_yuv420_lines(dst, chroma_buf, yuv_src, width,
+ stride);
+ yuv_src[0] += stride << 1; /* Skip down two luma lines */
+ yuv_src[1] += stride >> 1; /* Skip down one chroma line */
+ yuv_src[2] += stride >> 1;
+ dst -= 2;
}
+ while (--height > 0);
}
-
void lcd_set_contrast(int val) {
(void) val;
// TODO: