diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2022-10-13 11:03:53 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2022-10-13 11:08:06 -0400 |
commit | 418169aff8faf2cf90124cd95dba0af821cea73d (patch) | |
tree | 4fc206af57c9a07fba6cbcb3517fa946a7b84668 /firmware/drivers | |
parent | f9ea1fc79d6aaff9949a5b11ae011b4e04e0e9d9 (diff) | |
download | rockbox-418169aff8faf2cf90124cd95dba0af821cea73d.tar.gz rockbox-418169aff8faf2cf90124cd95dba0af821cea73d.zip |
Revert "Remove YUV blitting functions and LCD modes"
This reverts commit fe6aa21e9eb88f49005863efd2003d0982920048.
Change-Id: I8bb1e5d6c52ed1478002d2140ef494ec5d62b8e3
Diffstat (limited to 'firmware/drivers')
-rw-r--r-- | firmware/drivers/lcd-color-common.c | 189 | ||||
-rw-r--r-- | firmware/drivers/lcd-memframe.c | 98 |
2 files changed, 287 insertions, 0 deletions
diff --git a/firmware/drivers/lcd-color-common.c b/firmware/drivers/lcd-color-common.c index cce0bbbf4e..ae0fe519bc 100644 --- a/firmware/drivers/lcd-color-common.c +++ b/firmware/drivers/lcd-color-common.c | |||
@@ -220,6 +220,195 @@ static inline int clamp(int val, int min, int max) | |||
220 | return val; | 220 | return val; |
221 | } | 221 | } |
222 | 222 | ||
223 | #ifndef _WIN32 | ||
224 | /* | ||
225 | * weak attribute doesn't work for win32 as of gcc 4.6.2 and binutils 2.21.52 | ||
226 | * When building win32 simulators, we won't be using an optimized version of | ||
227 | * lcd_blit_yuv(), so just don't use the weak attribute. | ||
228 | */ | ||
229 | __attribute__((weak)) | ||
230 | #endif | ||
231 | void lcd_yuv_set_options(unsigned options) | ||
232 | { | ||
233 | (void)options; | ||
234 | } | ||
235 | |||
236 | /* Draw a partial YUV colour bitmap */ | ||
237 | #ifndef _WIN32 | ||
238 | __attribute__((weak)) | ||
239 | #endif | ||
240 | void lcd_blit_yuv(unsigned char * const src[3], | ||
241 | int src_x, int src_y, int stride, | ||
242 | int x, int y, int width, int height) | ||
243 | { | ||
244 | const unsigned char *ysrc, *usrc, *vsrc; | ||
245 | int linecounter; | ||
246 | fb_data *dst, *row_end; | ||
247 | long z; | ||
248 | |||
249 | /* width and height must be >= 2 and an even number */ | ||
250 | width &= ~1; | ||
251 | linecounter = height >> 1; | ||
252 | |||
253 | #if LCD_WIDTH >= LCD_HEIGHT | ||
254 | dst = FBADDR(x, y); | ||
255 | row_end = dst + width; | ||
256 | #else | ||
257 | dst = FBADDR(LCD_WIDTH - y - 1, x); | ||
258 | row_end = dst + LCD_WIDTH * width; | ||
259 | #endif | ||
260 | |||
261 | z = stride * src_y; | ||
262 | ysrc = src[0] + z + src_x; | ||
263 | usrc = src[1] + (z >> 2) + (src_x >> 1); | ||
264 | vsrc = src[2] + (usrc - src[1]); | ||
265 | |||
266 | /* stride => amount to jump from end of last row to start of next */ | ||
267 | stride -= width; | ||
268 | |||
269 | /* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */ | ||
270 | |||
271 | do | ||
272 | { | ||
273 | do | ||
274 | { | ||
275 | int y, cb, cr, rv, guv, bu, r, g, b; | ||
276 | |||
277 | y = YFAC*(*ysrc++ - 16); | ||
278 | cb = *usrc++ - 128; | ||
279 | cr = *vsrc++ - 128; | ||
280 | |||
281 | rv = RVFAC*cr; | ||
282 | guv = GUFAC*cb + GVFAC*cr; | ||
283 | bu = BUFAC*cb; | ||
284 | |||
285 | r = y + rv; | ||
286 | g = y + guv; | ||
287 | b = y + bu; | ||
288 | |||
289 | if ((unsigned)(r | g | b) > 64*256-1) | ||
290 | { | ||
291 | r = clamp(r, 0, 64*256-1); | ||
292 | g = clamp(g, 0, 64*256-1); | ||
293 | b = clamp(b, 0, 64*256-1); | ||
294 | } | ||
295 | |||
296 | *dst = FB_RGBPACK(r >> 6, g >> 6, b >> 6); | ||
297 | |||
298 | #if LCD_WIDTH >= LCD_HEIGHT | ||
299 | dst++; | ||
300 | #else | ||
301 | dst += LCD_WIDTH; | ||
302 | #endif | ||
303 | |||
304 | y = YFAC*(*ysrc++ - 16); | ||
305 | r = y + rv; | ||
306 | g = y + guv; | ||
307 | b = y + bu; | ||
308 | |||
309 | if ((unsigned)(r | g | b) > 64*256-1) | ||
310 | { | ||
311 | r = clamp(r, 0, 64*256-1); | ||
312 | g = clamp(g, 0, 64*256-1); | ||
313 | b = clamp(b, 0, 64*256-1); | ||
314 | } | ||
315 | |||
316 | *dst = FB_RGBPACK(r >> 6, g >> 6, b >> 6); | ||
317 | |||
318 | #if LCD_WIDTH >= LCD_HEIGHT | ||
319 | dst++; | ||
320 | #else | ||
321 | dst += LCD_WIDTH; | ||
322 | #endif | ||
323 | } | ||
324 | while (dst < row_end); | ||
325 | |||
326 | ysrc += stride; | ||
327 | usrc -= width >> 1; | ||
328 | vsrc -= width >> 1; | ||
329 | |||
330 | #if LCD_WIDTH >= LCD_HEIGHT | ||
331 | row_end += LCD_WIDTH; | ||
332 | dst += LCD_WIDTH - width; | ||
333 | #else | ||
334 | row_end -= 1; | ||
335 | dst -= LCD_WIDTH*width + 1; | ||
336 | #endif | ||
337 | |||
338 | do | ||
339 | { | ||
340 | int y, cb, cr, rv, guv, bu, r, g, b; | ||
341 | |||
342 | y = YFAC*(*ysrc++ - 16); | ||
343 | cb = *usrc++ - 128; | ||
344 | cr = *vsrc++ - 128; | ||
345 | |||
346 | rv = RVFAC*cr; | ||
347 | guv = GUFAC*cb + GVFAC*cr; | ||
348 | bu = BUFAC*cb; | ||
349 | |||
350 | r = y + rv; | ||
351 | g = y + guv; | ||
352 | b = y + bu; | ||
353 | |||
354 | if ((unsigned)(r | g | b) > 64*256-1) | ||
355 | { | ||
356 | r = clamp(r, 0, 64*256-1); | ||
357 | g = clamp(g, 0, 64*256-1); | ||
358 | b = clamp(b, 0, 64*256-1); | ||
359 | } | ||
360 | |||
361 | *dst = FB_RGBPACK(r >> 6, g >> 6, b >> 6); | ||
362 | |||
363 | #if LCD_WIDTH >= LCD_HEIGHT | ||
364 | dst++; | ||
365 | #else | ||
366 | dst += LCD_WIDTH; | ||
367 | #endif | ||
368 | |||
369 | y = YFAC*(*ysrc++ - 16); | ||
370 | r = y + rv; | ||
371 | g = y + guv; | ||
372 | b = y + bu; | ||
373 | |||
374 | if ((unsigned)(r | g | b) > 64*256-1) | ||
375 | { | ||
376 | r = clamp(r, 0, 64*256-1); | ||
377 | g = clamp(g, 0, 64*256-1); | ||
378 | b = clamp(b, 0, 64*256-1); | ||
379 | } | ||
380 | |||
381 | *dst = FB_RGBPACK(r >> 6, g >> 6, b >> 6); | ||
382 | |||
383 | #if LCD_WIDTH >= LCD_HEIGHT | ||
384 | dst++; | ||
385 | #else | ||
386 | dst += LCD_WIDTH; | ||
387 | #endif | ||
388 | } | ||
389 | while (dst < row_end); | ||
390 | |||
391 | ysrc += stride; | ||
392 | usrc += stride >> 1; | ||
393 | vsrc += stride >> 1; | ||
394 | |||
395 | #if LCD_WIDTH >= LCD_HEIGHT | ||
396 | row_end += LCD_WIDTH; | ||
397 | dst += LCD_WIDTH - width; | ||
398 | #else | ||
399 | row_end -= 1; | ||
400 | dst -= LCD_WIDTH*width + 1; | ||
401 | #endif | ||
402 | } | ||
403 | while (--linecounter > 0); | ||
404 | |||
405 | #if LCD_WIDTH >= LCD_HEIGHT | ||
406 | lcd_update_rect(x, y, width, height); | ||
407 | #else | ||
408 | lcd_update_rect(LCD_WIDTH - y - height, x, height, width); | ||
409 | #endif | ||
410 | } | ||
411 | |||
223 | /* Fill a rectangle with a gradient. This function draws only the partial | 412 | /* Fill a rectangle with a gradient. This function draws only the partial |
224 | * gradient. It assumes the original gradient is src_height high and skips | 413 | * gradient. It assumes the original gradient is src_height high and skips |
225 | * the first few rows. This is useful for drawing only the bottom half of | 414 | * the first few rows. This is useful for drawing only the bottom half of |
diff --git a/firmware/drivers/lcd-memframe.c b/firmware/drivers/lcd-memframe.c index 357b4af32a..bb1682b074 100644 --- a/firmware/drivers/lcd-memframe.c +++ b/firmware/drivers/lcd-memframe.c | |||
@@ -110,3 +110,101 @@ void lcd_update_rect(int x, int y, int width, int height) | |||
110 | } | 110 | } |
111 | } | 111 | } |
112 | #endif /* LCD_OPTIMIZED_UPDATE_RECT */ | 112 | #endif /* LCD_OPTIMIZED_UPDATE_RECT */ |
113 | |||
114 | |||
115 | /*** YUV functions ***/ | ||
116 | static unsigned lcd_yuv_options SHAREDBSS_ATTR = 0; | ||
117 | |||
118 | |||
119 | /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */ | ||
120 | extern void lcd_write_yuv420_lines(fb_data *dst, | ||
121 | unsigned char const * const src[3], | ||
122 | int width, | ||
123 | int stride); | ||
124 | extern void lcd_write_yuv420_lines_odither(fb_data *dst, | ||
125 | unsigned char const * const src[3], | ||
126 | int width, | ||
127 | int stride, | ||
128 | int x_screen, /* To align dither pattern */ | ||
129 | int y_screen); | ||
130 | |||
131 | void lcd_yuv_set_options(unsigned options) | ||
132 | { | ||
133 | lcd_yuv_options = options; | ||
134 | } | ||
135 | |||
136 | #ifndef LCD_OPTIMIZED_BLIT_YUV | ||
137 | /* Performance function to blit a YUV bitmap directly to the LCD | ||
138 | * src_x, src_y, width and height should be even and within the LCD's | ||
139 | * boundaries. | ||
140 | * | ||
141 | * For portrait LCDs, show it rotated counterclockwise by 90 degrees | ||
142 | */ | ||
143 | void lcd_blit_yuv(unsigned char * const src[3], | ||
144 | int src_x, int src_y, int stride, | ||
145 | int x, int y, int width, int height) | ||
146 | { | ||
147 | /* Macrofy the bits that change between orientations */ | ||
148 | #if CONFIG_ORIENTATION == SCREEN_PORTRAIT | ||
149 | #define LCD_FRAMEBUF_ADDR_ORIENTED(col, row) \ | ||
150 | LCD_FRAMEBUF_ADDR(row, col) | ||
151 | #define lcd_write_yuv420_lines_odither_oriented(dst, src, w, s, col, row) \ | ||
152 | lcd_write_yuv420_lines_odither(dst, src, w, s, row, col) | ||
153 | #define YUV_NEXTLINE() dst -= 2 | ||
154 | #define YUV_DITHER_NEXTLINE() dst -= 2, y -= 2 | ||
155 | #else | ||
156 | #define LCD_FRAMEBUF_ADDR_ORIENTED(col, row) \ | ||
157 | LCD_FRAMEBUF_ADDR(col, row) | ||
158 | #define lcd_write_yuv420_lines_odither_oriented(dst, src, w, s, col, row) \ | ||
159 | lcd_write_yuv420_lines_odither(dst, src, w, s, col, row) | ||
160 | #define YUV_NEXTLINE() dst += 2*LCD_FBWIDTH | ||
161 | #define YUV_DITHER_NEXTLINE() dst += 2*LCD_FBWIDTH, y += 2 | ||
162 | #endif | ||
163 | |||
164 | if (!lcd_write_enabled()) | ||
165 | return; | ||
166 | |||
167 | /* Sorry, but width and height must be >= 2 or else */ | ||
168 | width &= ~1; | ||
169 | height >>= 1; | ||
170 | |||
171 | #if CONFIG_ORIENTATION == SCREEN_PORTRAIT | ||
172 | /* Adjust portrait coordinates to make (0, 0) the upper right corner */ | ||
173 | y = LCD_WIDTH - 1 - y; | ||
174 | #endif | ||
175 | |||
176 | fb_data *dst = LCD_FRAMEBUF_ADDR_ORIENTED(x, y); | ||
177 | int z = stride*src_y; | ||
178 | |||
179 | unsigned char const * yuv_src[3]; | ||
180 | yuv_src[0] = src[0] + z + src_x; | ||
181 | yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1); | ||
182 | yuv_src[2] = src[2] + (yuv_src[1] - src[1]); | ||
183 | |||
184 | if (lcd_yuv_options & LCD_YUV_DITHER) | ||
185 | { | ||
186 | do | ||
187 | { | ||
188 | lcd_write_yuv420_lines_odither_oriented(dst, yuv_src, width, | ||
189 | stride, x, y); | ||
190 | yuv_src[0] += stride << 1; /* Skip down two luma lines */ | ||
191 | yuv_src[1] += stride >> 1; /* Skip down one chroma line */ | ||
192 | yuv_src[2] += stride >> 1; | ||
193 | YUV_DITHER_NEXTLINE(); | ||
194 | } | ||
195 | while (--height > 0); | ||
196 | } | ||
197 | else | ||
198 | { | ||
199 | do | ||
200 | { | ||
201 | lcd_write_yuv420_lines(dst, yuv_src, width, stride); | ||
202 | yuv_src[0] += stride << 1; /* Skip down two luma lines */ | ||
203 | yuv_src[1] += stride >> 1; /* Skip down one chroma line */ | ||
204 | yuv_src[2] += stride >> 1; | ||
205 | YUV_NEXTLINE(); | ||
206 | } | ||
207 | while (--height > 0); | ||
208 | } | ||
209 | } | ||
210 | #endif /* LCD_OPTIMIZED_BLIT_YUV */ | ||