6 #include "lcd-target.h"
8 #define LCDADDR(x, y) (&lcd_framebuffer[(y)][(x)])
10 static volatile bool lcd_on
= true;
11 volatile bool lcd_poweroff
= false;
12 static unsigned lcd_yuv_options
= 0;
14 ** This is imported from lcd-16bit.c
16 extern struct viewport
* current_vp
;
18 /* Copies a rectangle from one framebuffer to another. Can be used in
19 single transfer mode with width = num pixels, and height = 1 which
20 allows a full-width rectangle to be copied more efficiently. */
21 extern void lcd_copy_buffer_rect(fb_data
*dst
, const fb_data
*src
,
22 int width
, int height
);
32 void lcd_init_device(void)
36 /* Update a fraction of the display. */
37 void lcd_update_rect(int x
, int y
, int width
, int height
)
44 if (x
+ width
> LCD_WIDTH
)
45 width
= LCD_WIDTH
- x
; /* Clip right */
47 width
+= x
, x
= 0; /* Clip left */
49 return; /* nothing left to do */
51 if (y
+ height
> LCD_HEIGHT
)
52 height
= LCD_HEIGHT
- y
; /* Clip bottom */
54 height
+= y
, y
= 0; /* Clip top */
56 return; /* nothing left to do */
58 /* TODO: It may be faster to swap the addresses of lcd_driver_framebuffer
59 * and lcd_framebuffer */
60 dst
= (fb_data
*)FRAME
+ LCD_WIDTH
*y
+ x
;
61 src
= &lcd_framebuffer
[y
][x
];
63 /* Copy part of the Rockbox framebuffer to the second framebuffer */
64 if (width
< LCD_WIDTH
)
66 /* Not full width - do line-by-line */
67 lcd_copy_buffer_rect(dst
, src
, width
, height
);
71 /* Full width - copy as one line */
72 lcd_copy_buffer_rect(dst
, src
, LCD_WIDTH
*height
, 1);
76 void lcd_enable(bool state
)
81 bool lcd_enabled(void)
86 /* Update the display.
87 This must be called after all other LCD functions that change the display. */
93 lcd_copy_buffer_rect((fb_data
*)FRAME
, &lcd_framebuffer
[0][0],
94 LCD_WIDTH
*LCD_HEIGHT
, 1);
97 void lcd_bitmap_transparent_part(const fb_data
*src
, int src_x
, int src_y
,
98 int stride
, int x
, int y
, int width
,
104 if (x
+ width
> current_vp
->width
)
105 width
= current_vp
->width
- x
; /* Clip right */
107 width
+= x
, x
= 0; /* Clip left */
109 return; /* nothing left to do */
111 if (y
+ height
> current_vp
->height
)
112 height
= current_vp
->height
- y
; /* Clip bottom */
114 height
+= y
, y
= 0; /* Clip top */
116 return; /* nothing left to do */
118 src
+= stride
* src_y
+ src_x
; /* move starting point */
119 dst
= &lcd_framebuffer
[current_vp
->y
+y
][current_vp
->x
+x
];
123 "mov %[w], %[width] \r\n" /* Load width for inner loop */
125 "ldrh %[px], [%[s]], #2 \r\n" /* Load src pixel */
126 "add %[d], %[d], #2 \r\n" /* Uncoditionally increment dst */
127 "cmp %[px], %[fgcolor] \r\n" /* Compare to foreground color */
128 "streqh %[fgpat], [%[d], #-2] \r\n" /* Store foregroud if match */
129 "cmpne %[px], %[transcolor] \r\n" /* Compare to transparent color */
130 "strneh %[px], [%[d], #-2] \r\n" /* Store dst if not transparent */
131 "subs %[w], %[w], #1 \r\n" /* Width counter has run down? */
132 "bgt .nextpixel \r\n" /* More in this row? */
133 "add %[s], %[s], %[sstp], lsl #1 \r\n" /* Skip over to start of next line */
134 "add %[d], %[d], %[dstp], lsl #1 \r\n"
135 "subs %[h], %[h], #1 \r\n" /* Height counter has run down? */
136 "bgt .rowstart \r\n" /* More rows? */
137 : [w
]"=&r"(w
), [h
]"+&r"(height
), [px
]"=&r"(px
),
138 [s
]"+&r"(src
), [d
]"+&r"(dst
)
140 [sstp
]"r"(stride
- width
),
141 [dstp
]"r"(LCD_WIDTH
- width
),
142 [transcolor
]"r"(TRANSPARENT_COLOR
),
143 [fgcolor
]"r"(REPLACEWITHFG_COLOR
),
144 [fgpat
]"r"(current_vp
->fg_pattern
)
148 void lcd_yuv_set_options(unsigned options
)
150 lcd_yuv_options
= options
;
153 /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
154 extern void lcd_write_yuv420_lines(fb_data
*dst
,
155 unsigned char const * const src
[3],
158 extern void lcd_write_yuv420_lines_odither(fb_data
*dst
,
159 unsigned char const * const src
[3],
162 int x_screen
, /* To align dither pattern */
164 /* Performance function to blit a YUV bitmap directly to the LCD */
165 /* For the Gigabeat - show it rotated */
166 /* So the LCD_WIDTH is now the height */
167 void lcd_blit_yuv(unsigned char * const src
[3],
168 int src_x
, int src_y
, int stride
,
169 int x
, int y
, int width
, int height
)
171 /* Caches for chroma data so it only need be recaculated every other
173 unsigned char const * yuv_src
[3];
179 /* Sorry, but width and height must be >= 2 or else */
183 y
= LCD_WIDTH
- 1 - y
;
184 fb_data
*dst
= (fb_data
*)FRAME
+ x
* LCD_WIDTH
+ y
;
187 yuv_src
[0] = src
[0] + z
+ src_x
;
188 yuv_src
[1] = src
[1] + (z
>> 2) + (src_x
>> 1);
189 yuv_src
[2] = src
[2] + (yuv_src
[1] - src
[1]);
191 if (lcd_yuv_options
& LCD_YUV_DITHER
)
195 lcd_write_yuv420_lines_odither(dst
, yuv_src
, width
, stride
, y
, x
);
196 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
197 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
198 yuv_src
[2] += stride
>> 1;
202 while (--height
> 0);
208 lcd_write_yuv420_lines(dst
, yuv_src
, width
, stride
);
209 yuv_src
[0] += stride
<< 1; /* Skip down two luma lines */
210 yuv_src
[1] += stride
>> 1; /* Skip down one chroma line */
211 yuv_src
[2] += stride
>> 1;
214 while (--height
> 0);
218 void lcd_set_contrast(int val
) {
223 void lcd_set_invert_display(bool yesno
) {
228 void lcd_set_flip(bool yesno
) {