summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/sdl/lcd-bitmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/sdl/lcd-bitmap.c')
-rw-r--r--firmware/target/hosted/sdl/lcd-bitmap.c205
1 files changed, 0 insertions, 205 deletions
diff --git a/firmware/target/hosted/sdl/lcd-bitmap.c b/firmware/target/hosted/sdl/lcd-bitmap.c
index 4c296924af..4ee0bbef5c 100644
--- a/firmware/target/hosted/sdl/lcd-bitmap.c
+++ b/firmware/target/hosted/sdl/lcd-bitmap.c
@@ -223,208 +223,3 @@ void sim_lcd_ex_update_rect(int x_start, int y_start, int width, int height)
223 } 223 }
224} 224}
225#endif 225#endif
226
227#ifdef HAVE_LCD_COLOR
228/**
229 * |R| |1.000000 -0.000001 1.402000| |Y'|
230 * |G| = |1.000000 -0.334136 -0.714136| |Pb|
231 * |B| |1.000000 1.772000 0.000000| |Pr|
232 * Scaled, normalized, rounded and tweaked to yield RGB 565:
233 * |R| |74 0 101| |Y' - 16| >> 9
234 * |G| = |74 -24 -51| |Cb - 128| >> 8
235 * |B| |74 128 0| |Cr - 128| >> 9
236 */
237#define YFAC (74)
238#define RVFAC (101)
239#define GUFAC (-24)
240#define GVFAC (-51)
241#define BUFAC (128)
242
243static inline int clamp(int val, int min, int max)
244{
245 if (val < min)
246 val = min;
247 else if (val > max)
248 val = max;
249 return val;
250}
251
252void lcd_yuv_set_options(unsigned options)
253{
254 (void)options;
255}
256
257/* Draw a partial YUV colour bitmap - similiar behavior to lcd_blit_yuv
258 in the core */
259void lcd_blit_yuv(unsigned char * const src[3],
260 int src_x, int src_y, int stride,
261 int x, int y, int width, int height)
262{
263 const unsigned char *ysrc, *usrc, *vsrc;
264 int linecounter;
265 fb_data *dst, *row_end;
266 long z;
267
268 /* width and height must be >= 2 and an even number */
269 width &= ~1;
270 linecounter = height >> 1;
271
272#if LCD_WIDTH >= LCD_HEIGHT
273 dst = &lcd_framebuffer[y][x];
274 row_end = dst + width;
275#else
276 dst = &lcd_framebuffer[x][LCD_WIDTH - y - 1];
277 row_end = dst + LCD_WIDTH * width;
278#endif
279
280 z = stride * src_y;
281 ysrc = src[0] + z + src_x;
282 usrc = src[1] + (z >> 2) + (src_x >> 1);
283 vsrc = src[2] + (usrc - src[1]);
284
285 /* stride => amount to jump from end of last row to start of next */
286 stride -= width;
287
288 /* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */
289
290 do
291 {
292 do
293 {
294 int y, cb, cr, rv, guv, bu, r, g, b;
295
296 y = YFAC*(*ysrc++ - 16);
297 cb = *usrc++ - 128;
298 cr = *vsrc++ - 128;
299
300 rv = RVFAC*cr;
301 guv = GUFAC*cb + GVFAC*cr;
302 bu = BUFAC*cb;
303
304 r = y + rv;
305 g = y + guv;
306 b = y + bu;
307
308 if ((unsigned)(r | g | b) > 64*256-1)
309 {
310 r = clamp(r, 0, 64*256-1);
311 g = clamp(g, 0, 64*256-1);
312 b = clamp(b, 0, 64*256-1);
313 }
314
315 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
316
317#if LCD_WIDTH >= LCD_HEIGHT
318 dst++;
319#else
320 dst += LCD_WIDTH;
321#endif
322
323 y = YFAC*(*ysrc++ - 16);
324 r = y + rv;
325 g = y + guv;
326 b = y + bu;
327
328 if ((unsigned)(r | g | b) > 64*256-1)
329 {
330 r = clamp(r, 0, 64*256-1);
331 g = clamp(g, 0, 64*256-1);
332 b = clamp(b, 0, 64*256-1);
333 }
334
335 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
336
337#if LCD_WIDTH >= LCD_HEIGHT
338 dst++;
339#else
340 dst += LCD_WIDTH;
341#endif
342 }
343 while (dst < row_end);
344
345 ysrc += stride;
346 usrc -= width >> 1;
347 vsrc -= width >> 1;
348
349#if LCD_WIDTH >= LCD_HEIGHT
350 row_end += LCD_WIDTH;
351 dst += LCD_WIDTH - width;
352#else
353 row_end -= 1;
354 dst -= LCD_WIDTH*width + 1;
355#endif
356
357 do
358 {
359 int y, cb, cr, rv, guv, bu, r, g, b;
360
361 y = YFAC*(*ysrc++ - 16);
362 cb = *usrc++ - 128;
363 cr = *vsrc++ - 128;
364
365 rv = RVFAC*cr;
366 guv = GUFAC*cb + GVFAC*cr;
367 bu = BUFAC*cb;
368
369 r = y + rv;
370 g = y + guv;
371 b = y + bu;
372
373 if ((unsigned)(r | g | b) > 64*256-1)
374 {
375 r = clamp(r, 0, 64*256-1);
376 g = clamp(g, 0, 64*256-1);
377 b = clamp(b, 0, 64*256-1);
378 }
379
380 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
381
382#if LCD_WIDTH >= LCD_HEIGHT
383 dst++;
384#else
385 dst += LCD_WIDTH;
386#endif
387
388 y = YFAC*(*ysrc++ - 16);
389 r = y + rv;
390 g = y + guv;
391 b = y + bu;
392
393 if ((unsigned)(r | g | b) > 64*256-1)
394 {
395 r = clamp(r, 0, 64*256-1);
396 g = clamp(g, 0, 64*256-1);
397 b = clamp(b, 0, 64*256-1);
398 }
399
400 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
401
402#if LCD_WIDTH >= LCD_HEIGHT
403 dst++;
404#else
405 dst += LCD_WIDTH;
406#endif
407 }
408 while (dst < row_end);
409
410 ysrc += stride;
411 usrc += stride >> 1;
412 vsrc += stride >> 1;
413
414#if LCD_WIDTH >= LCD_HEIGHT
415 row_end += LCD_WIDTH;
416 dst += LCD_WIDTH - width;
417#else
418 row_end -= 1;
419 dst -= LCD_WIDTH*width + 1;
420#endif
421 }
422 while (--linecounter > 0);
423
424#if LCD_WIDTH >= LCD_HEIGHT
425 lcd_update_rect(x, y, width, height);
426#else
427 lcd_update_rect(LCD_WIDTH - y - height, x, height, width);
428#endif
429}
430#endif /* HAVE_LCD_COLOR */