blob: f193f9806d2f553cd8a1d086359014aabeada878 [file] [log] [blame]
Marcoen Hirschbergdd754882006-08-12 08:01:54 +00001#include "config.h"
2#include "cpu.h"
3#include "lcd.h"
4#include "kernel.h"
5#include "system.h"
Dave Chapman38a5aa12006-08-22 08:04:51 +00006#include "string.h"
Marcoen Hirschbergdd754882006-08-12 08:01:54 +00007
8void lcd_init_device(void);
9void lcd_update_rec(int, int, int, int);
10void lcd_update(void);
11
12/* LCD init */
13void lcd_init_device(void)
14{
15}
16
17/* Update a fraction of the display. */
18void lcd_update_rect(int x, int y, int width, int height)
19{
20 (void)x;
21 (void)y;
22 (void)width;
23 (void)height;
24 memcpy(FRAME, &lcd_framebuffer, sizeof(lcd_framebuffer));
25}
26
27/* Update the display.
28 This must be called after all other LCD functions that change the display. */
29void lcd_update(void)
30{
31 lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
32}
Dave Chapman7fe74272006-08-12 09:27:26 +000033
34#define CSUB_X 2
35#define CSUB_Y 2
36
37#define RYFAC (31*257)
38#define GYFAC (63*257)
39#define BYFAC (31*257)
40#define RVFAC 11170 /* 31 * 257 * 1.402 */
41#define GVFAC (-11563) /* 63 * 257 * -0.714136 */
42#define GUFAC (-5572) /* 63 * 257 * -0.344136 */
43#define BUFAC 14118 /* 31 * 257 * 1.772 */
44
45#define ROUNDOFFS (127*257)
46
47/* Performance function to blit a YUV bitmap directly to the LCD */
48void lcd_yuv_blit(unsigned char * const src[3],
49 int src_x, int src_y, int stride,
50 int x, int y, int width, int height)
51{
52 fb_data *dst, *dst_end;
53
54 width = (width + 1) & ~1;
55
56 dst = (fb_data*)FRAME + LCD_WIDTH * y + x;
57 dst_end = dst + LCD_WIDTH * height;
58
59 do
60 {
61 fb_data *dst_row = dst;
62 fb_data *row_end = dst_row + width;
63 const unsigned char *ysrc = src[0] + stride * src_y + src_x;
64 int y, u, v;
65 int red, green, blue;
66 unsigned rbits, gbits, bbits;
67
68 /* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */
69 const unsigned char *usrc = src[1] + (stride/CSUB_X) * (src_y/CSUB_Y)
70 + (src_x/CSUB_X);
71 const unsigned char *vsrc = src[2] + (stride/CSUB_X) * (src_y/CSUB_Y)
72 + (src_x/CSUB_X);
73 int xphase = src_x % CSUB_X;
74 int rc, gc, bc;
75
76 u = *usrc++ - 128;
77 v = *vsrc++ - 128;
78 rc = RVFAC * v + ROUNDOFFS;
79 gc = GVFAC * v + GUFAC * u + ROUNDOFFS;
80 bc = BUFAC * u + ROUNDOFFS;
81
82 do
83 {
84 y = *ysrc++;
85 red = RYFAC * y + rc;
86 green = GYFAC * y + gc;
87 blue = BYFAC * y + bc;
88
89 if ((unsigned)red > (RYFAC*255+ROUNDOFFS))
90 {
91 if (red < 0)
92 red = 0;
93 else
94 red = (RYFAC*255+ROUNDOFFS);
95 }
96 if ((unsigned)green > (GYFAC*255+ROUNDOFFS))
97 {
98 if (green < 0)
99 green = 0;
100 else
101 green = (GYFAC*255+ROUNDOFFS);
102 }
103 if ((unsigned)blue > (BYFAC*255+ROUNDOFFS))
104 {
105 if (blue < 0)
106 blue = 0;
107 else
108 blue = (BYFAC*255+ROUNDOFFS);
109 }
110 rbits = ((unsigned)red) >> 16 ;
111 gbits = ((unsigned)green) >> 16 ;
112 bbits = ((unsigned)blue) >> 16 ;
113 *dst_row++ = (rbits << 11) | (gbits << 5) | bbits;
114
115 if (++xphase >= CSUB_X)
116 {
117 u = *usrc++ - 128;
118 v = *vsrc++ - 128;
119 rc = RVFAC * v + ROUNDOFFS;
120 gc = GVFAC * v + GUFAC * u + ROUNDOFFS;
121 bc = BUFAC * u + ROUNDOFFS;
122 xphase = 0;
123 }
124 }
125 while (dst_row < row_end);
126
127 src_y++;
128 dst += LCD_WIDTH;
129 }
130 while (dst < dst_end);
131}