@@ -454,6 +454,46 @@ add_noise(unsigned char *data, size_t len, unsigned bpp, unsigned noisiness)
454454 }
455455}
456456
457+ #ifdef HAVE_LIBSDL_TTF
458+ static void
459+ render_sdl_ttf (struct testcard_state2 * s , const char * frames , uint32_t * banner )
460+ {
461+ const SDL_Color col = { 0 , 0 , 0 , 0 };
462+ SDL_Surface * text = TTF_RenderText_Solid (s -> sdl_font ,
463+ #ifdef HAVE_SDL3
464+ frames , 0 , col );
465+ #else
466+ frames , col );
467+ #endif
468+ long xoff = ((long ) s -> desc .width - text -> w ) / 2 ;
469+ long yoff = (BANNER_HEIGHT - text -> h ) / 2 ;
470+ for (int i = 0 ; i < text -> h ; i ++ ) {
471+ uint32_t * d = banner + xoff + (i + yoff ) * s -> desc .width ;
472+ for (int j = 0 ; j < MIN (text -> w , (int ) s -> desc .width - xoff );
473+ j ++ ) {
474+ if (((char * ) text -> pixels )[i * text -> pitch + j ]) {
475+ * d = 0x00000000U ;
476+ }
477+ d ++ ;
478+ }
479+ }
480+ SDL_DestroySurface (text );
481+ }
482+ #else
483+ static void
484+ render_builtin (struct testcard_state2 * s , const char * frames , char * banner )
485+ {
486+ int scale = FONT_HEIGHT / FONT_H ;
487+ int w = strlen (frames ) * FONT_W_SPACE * scale ;
488+ int h = FONT_H * scale ;
489+ long xoff = ((long ) s -> desc .width - w ) / 2 ;
490+ long yoff = (BANNER_HEIGHT - h ) / 2 ;
491+ int linesz = vc_get_linesize (s -> desc .width , RGBA );
492+ draw_line_scaled (banner + yoff * linesz + xoff * 4 , linesz ,
493+ frames , 0xFF000000U , 0xFFFFFFFFU , scale );
494+ }
495+ #endif // defined HAVE_LIBSDL_TTF
496+
457497/**
458498 * Only text banner is rendered in RGBA, other elements (background, squares) are already
459499 * converted to destination color space. Keep in mind that the regions should be aligned
@@ -541,34 +581,10 @@ void * vidcap_testcard2_thread(void *arg)
541581 (int ) since_start % 60 ,
542582 s -> count % (int ) s -> desc .fps );
543583#ifdef HAVE_LIBSDL_TTF
544- SDL_Color col = { 0 , 0 , 0 , 0 };
545- SDL_Surface * text = TTF_RenderText_Solid (s -> sdl_font ,
546- # ifdef HAVE_SDL3
547- frames , 0 , col );
548- # else
549- frames , col );
550- # endif
551- long xoff = ((long ) s -> desc .width - text -> w ) / 2 ;
552- long yoff = (BANNER_HEIGHT - text -> h ) / 2 ;
553- for (int i = 0 ; i < text -> h ; i ++ ) {
554- uint32_t * d = banner + xoff + (i + yoff ) * s -> desc .width ;
555- for (int j = 0 ; j < MIN (text -> w , (int ) s -> desc .width - xoff ); j ++ ) {
556- if (((char * )text -> pixels ) [i * text -> pitch + j ]) {
557- * d = 0x00000000U ;
558- }
559- d ++ ;
560- }
561- }
584+ render_sdl_ttf (s , frames , banner );
562585#else
563- int scale = FONT_HEIGHT / FONT_H ;
564- int w = strlen (frames ) * FONT_W_SPACE * scale ;
565- int h = FONT_H * scale ;
566- long xoff = ((long ) s -> desc .width - w ) / 2 ;
567- long yoff = (BANNER_HEIGHT - h ) / 2 ;
568- int linesz = vc_get_linesize (s -> desc .width , RGBA );
569- draw_line_scaled ((char * ) banner + yoff * linesz + xoff * 4 ,
570- linesz , frames , 0xFF000000U , 0xFFFFFFFFU , scale );
571- #endif // defined HAVE_LIBSDL_TTF
586+ render_builtin (s , frames , (char * ) banner );
587+ #endif
572588
573589 testcard_convert_buffer (
574590 RGBA , s -> desc .color_spec ,
@@ -578,7 +594,6 @@ void * vidcap_testcard2_thread(void *arg)
578594 s -> desc .color_spec )),
579595 (unsigned char * ) banner , (int ) s -> desc .width ,
580596 BANNER_HEIGHT );
581- SDL_DestroySurface (text );
582597
583598next_frame :
584599 next_frame_time = s -> start_time ;
0 commit comments