@@ -69,7 +69,9 @@ static int sdl_display_init(const struct device *dev)
69
69
PIXEL_FORMAT_RGB_565
70
70
#elif defined(CONFIG_SDL_DISPLAY_DEFAULT_PIXEL_FORMAT_BGR_565 )
71
71
PIXEL_FORMAT_BGR_565
72
- #else /* SDL_DISPLAY_DEFAULT_PIXEL_FORMAT */
72
+ #elif defined(CONFIG_SDL_DISPLAY_DEFAULT_PIXEL_FORMAT_L_8 )
73
+ PIXEL_FORMAT_L_8
74
+ #else /* SDL_DISPLAY_DEFAULT_PIXEL_FORMAT */
73
75
PIXEL_FORMAT_ARGB_8888
74
76
#endif /* SDL_DISPLAY_DEFAULT_PIXEL_FORMAT */
75
77
;
@@ -223,6 +225,26 @@ static void sdl_display_write_mono(uint8_t *disp_buf,
223
225
}
224
226
}
225
227
228
+ static void sdl_display_write_l8 (uint8_t * disp_buf , const struct display_buffer_descriptor * desc ,
229
+ const void * buf )
230
+ {
231
+ uint32_t w_idx ;
232
+ uint32_t h_idx ;
233
+ uint32_t pixel ;
234
+ const uint8_t * byte_ptr ;
235
+
236
+ __ASSERT ((desc -> pitch * desc -> height ) <= desc -> buf_size , "Input buffer too small" );
237
+
238
+ for (h_idx = 0U ; h_idx < desc -> height ; ++ h_idx ) {
239
+ for (w_idx = 0U ; w_idx < desc -> width ; ++ w_idx ) {
240
+ byte_ptr = (const uint8_t * )buf + ((h_idx * desc -> pitch ) + w_idx );
241
+ pixel = * byte_ptr ;
242
+ * ((uint32_t * )disp_buf ) = pixel | (pixel << 8 ) | (pixel << 16 ) | 0xFF000000 ;
243
+ disp_buf += 4 ;
244
+ }
245
+ }
246
+ }
247
+
226
248
static int sdl_display_write (const struct device * dev , const uint16_t x ,
227
249
const uint16_t y ,
228
250
const struct display_buffer_descriptor * desc ,
@@ -262,6 +284,8 @@ static int sdl_display_write(const struct device *dev, const uint16_t x,
262
284
sdl_display_write_rgb565 (disp_data -> buf , desc , buf );
263
285
} else if (disp_data -> current_pixel_format == PIXEL_FORMAT_BGR_565 ) {
264
286
sdl_display_write_bgr565 (disp_data -> buf , desc , buf );
287
+ } else if (disp_data -> current_pixel_format == PIXEL_FORMAT_L_8 ) {
288
+ sdl_display_write_l8 (disp_data -> buf , desc , buf );
265
289
}
266
290
267
291
sdl_display_write_bottom (desc -> height , desc -> width , x , y , disp_data -> renderer ,
@@ -388,10 +412,29 @@ static void sdl_display_read_mono(const uint8_t *read_buf,
388
412
}
389
413
}
390
414
391
- static int sdl_display_read (const struct device * dev , const uint16_t x ,
392
- const uint16_t y ,
393
- const struct display_buffer_descriptor * desc ,
394
- void * buf )
415
+ static void sdl_display_read_l8 (const uint8_t * read_buf ,
416
+ const struct display_buffer_descriptor * desc , void * buf )
417
+ {
418
+ uint32_t w_idx ;
419
+ uint32_t h_idx ;
420
+ uint8_t * buf8 ;
421
+ const uint32_t * pix_ptr ;
422
+
423
+ __ASSERT ((desc -> pitch * desc -> height ) <= desc -> buf_size , "Read buffer is too small" );
424
+
425
+ for (h_idx = 0U ; h_idx < desc -> height ; ++ h_idx ) {
426
+ buf8 = ((uint8_t * )buf ) + desc -> pitch * h_idx ;
427
+
428
+ for (w_idx = 0U ; w_idx < desc -> width ; ++ w_idx ) {
429
+ pix_ptr = (const uint32_t * )read_buf + ((h_idx * desc -> pitch ) + w_idx );
430
+ * buf8 = * pix_ptr & 0xFF ;
431
+ buf8 += 1 ;
432
+ }
433
+ }
434
+ }
435
+
436
+ static int sdl_display_read (const struct device * dev , const uint16_t x , const uint16_t y ,
437
+ const struct display_buffer_descriptor * desc , void * buf )
395
438
{
396
439
struct sdl_display_data * disp_data = dev -> data ;
397
440
int err ;
@@ -423,6 +466,8 @@ static int sdl_display_read(const struct device *dev, const uint16_t x,
423
466
sdl_display_read_rgb565 (disp_data -> read_buf , desc , buf );
424
467
} else if (disp_data -> current_pixel_format == PIXEL_FORMAT_BGR_565 ) {
425
468
sdl_display_read_bgr565 (disp_data -> read_buf , desc , buf );
469
+ } else if (disp_data -> current_pixel_format == PIXEL_FORMAT_L_8 ) {
470
+ sdl_display_read_l8 (disp_data -> read_buf , desc , buf );
426
471
}
427
472
428
473
return 0 ;
@@ -507,7 +552,8 @@ static void sdl_display_get_capabilities(
507
552
PIXEL_FORMAT_MONO01 |
508
553
PIXEL_FORMAT_MONO10 |
509
554
PIXEL_FORMAT_RGB_565 |
510
- PIXEL_FORMAT_BGR_565 ;
555
+ PIXEL_FORMAT_BGR_565 |
556
+ PIXEL_FORMAT_L_8 ;
511
557
capabilities -> current_pixel_format = disp_data -> current_pixel_format ;
512
558
capabilities -> screen_info = SCREEN_INFO_MONO_VTILED |
513
559
(IS_ENABLED (CONFIG_SDL_DISPLAY_MONO_MSB_FIRST ) ? SCREEN_INFO_MONO_MSB_FIRST : 0 );
@@ -525,6 +571,7 @@ static int sdl_display_set_pixel_format(const struct device *dev,
525
571
case PIXEL_FORMAT_MONO10 :
526
572
case PIXEL_FORMAT_RGB_565 :
527
573
case PIXEL_FORMAT_BGR_565 :
574
+ case PIXEL_FORMAT_L_8 :
528
575
disp_data -> current_pixel_format = pixel_format ;
529
576
return 0 ;
530
577
default :
0 commit comments