6666# define SDL_DestroySurface SDL_FreeSurface
6767# define SDL_ERR (-1)
6868# endif // defined HAVE_SDL3
69- #else
70- # include "utils/bitmap_font.h"
71- # define SDL_DestroySurface (...)
7269#endif
7370
7471#include "audio/types.h" // for audio_frame
8178#include "tv.h" // for tv_diff, tv_add_usec, tv_diff...
8279#include "types.h" // for video_desc, RGBA, video_frame
8380#include "utils/color_out.h" // for color_printf, TBOLD, TRED
81+ #include "utils/bitmap_font.h" // for font, FONT_H, FONT_W_SPACE
8482#include "utils/fs.h" // for MAX_PATH_SIZE
8583#include "utils/macros.h" // for IS_KEY_PREFIX, MIN, IF_NOT_NU...
8684#include "utils/random.h" // for ug_rand
@@ -117,6 +115,7 @@ static void vidcap_testcard2_done(void *state);
117115void * vidcap_testcard2_thread (void * args );
118116
119117struct testcard_state2 {
118+ bool use_builtin_font ;
120119#ifdef HAVE_LIBSDL_TTF
121120 TTF_Font * sdl_font ;
122121#endif
@@ -253,6 +252,8 @@ parse_fmt(struct testcard_state2 *s, char *fmt)
253252 s -> noise = IS_KEY_PREFIX (tmp , "noise" )
254253 ? atoi (strchr (tmp , '=' ) + 1 )
255254 : NOISE_DEFAULT ;
255+ } else if (IS_PREFIX (tmp , "builtin" )) {
256+ s -> use_builtin_font = true;
256257 } else {
257258 MSG (ERROR , "Unknown option: %s\n" , tmp );
258259 return false;
@@ -268,17 +269,17 @@ usage()
268269 color_printf ("testcard2 is an alternative implementation of testing "
269270 "signal source.\n" );
270271 color_printf ("It is less maintained than mainline testcard and has "
271- "less features but has some extra ones, i. a. a timer (if "
272- "SDL(2)_ttf is found.\n" );
272+ "less features but has some extra ones, i. a. a timer\n" );
273273 color_printf ("\n" );
274274 color_printf ("testcard2 usage:\n" );
275275 color_printf (TBOLD (
276276 TRED ("\t-t testcard2" ) "[:<width>:<height>:<fps>:<codec>]" ) "\n" );
277277 color_printf ("or\n" );
278278 color_printf (
279279 TBOLD (TRED ("\t-t testcard2" ) "[:size=<width>x<height>][:fps=<fps>]["
280- ":codec=<codec>][:mode=<mode>]" ) "\n" );
280+ ":codec=<codec>][:mode=<mode>][:builtin] " ) "\n" );
281281 printf ("\nOptions:\n" );
282+ color_printf ("\t" TBOLD ("builtin" ) " - use builtin font even if SDL_ttf was found\n" );
282283 color_printf ("\t" TBOLD ("noise[=<val>]" ) " - add noise to the image\n" );
283284 printf ("\n" );
284285 testcard_show_codec_help ("testcard2" , true);
@@ -332,13 +333,6 @@ static int vidcap_testcard2_init(struct vidcap_params *params, void **state)
332333 platform_sem_init (& s -> semaphore , 0 , 0 );
333334 pthread_mutex_init (& s -> lock , NULL );
334335 pthread_cond_init (& s -> data_consumed_cv , NULL );
335- #ifdef HAVE_LIBSDL_TTF
336- s -> sdl_font = get_sdl_render_font ();
337- if (s -> sdl_font == NULL ) {
338- vidcap_testcard2_done (s );
339- return VIDCAP_INIT_FAIL ;
340- }
341- #endif
342336
343337 char * fmt = strdup (vidcap_params_get_fmt (params ));
344338 bool ret = true;
@@ -361,6 +355,17 @@ static int vidcap_testcard2_init(struct vidcap_params *params, void **state)
361355 return VIDCAP_INIT_FAIL ;
362356 }
363357
358+ if (!s -> use_builtin_font ) {
359+ #ifdef HAVE_LIBSDL_TTF
360+ s -> sdl_font = get_sdl_render_font ();
361+ if (s -> sdl_font == NULL ) {
362+ s -> use_builtin_font = true; // fallback
363+ }
364+ #else
365+ s -> use_builtin_font = true;
366+ #endif
367+ }
368+
364369 {
365370 unsigned int rect_size = (s -> desc .width + COL_NUM - 1 ) / COL_NUM ;
366371 int col_num = 0 ;
@@ -395,7 +400,9 @@ static int vidcap_testcard2_init(struct vidcap_params *params, void **state)
395400 s -> seconds_tone_played = 0.0 ;
396401 s -> play_audio_frame = 0 ;
397402
398- printf ("Testcard capture set to %dx%d\n" , s -> desc .width , s -> desc .height );
403+ MSG (NOTICE , "Testcard2 capture set to %dx%d, using %s font\n" ,
404+ s -> desc .width , s -> desc .height ,
405+ s -> use_builtin_font ? "builtin/raster" : "TTF" );
399406
400407 gettimeofday (& s -> start_time , NULL );
401408
@@ -454,10 +461,10 @@ add_noise(unsigned char *data, size_t len, unsigned bpp, unsigned noisiness)
454461 }
455462}
456463
457- #ifdef HAVE_LIBSDL_TTF
458464static void
459465render_sdl_ttf (struct testcard_state2 * s , const char * frames , uint32_t * banner )
460466{
467+ #ifdef HAVE_LIBSDL_TTF
461468 const SDL_Color col = { 0 , 0 , 0 , 0 };
462469 SDL_Surface * text = TTF_RenderText_Solid (s -> sdl_font ,
463470#ifdef HAVE_SDL3
@@ -478,8 +485,12 @@ render_sdl_ttf(struct testcard_state2 *s, const char *frames, uint32_t *banner)
478485 }
479486 }
480487 SDL_DestroySurface (text );
481- }
482488#else
489+ (void ) s , (void ) frames , (void ) banner ;
490+ abort ();
491+ #endif // defined HAVE_LIBSDL_TTF
492+ }
493+
483494static void
484495render_builtin (struct testcard_state2 * s , const char * frames , char * banner )
485496{
@@ -492,7 +503,6 @@ render_builtin(struct testcard_state2 *s, const char *frames, char *banner)
492503 draw_line_scaled (banner + yoff * linesz + xoff * 4 , linesz ,
493504 frames , 0xFF000000U , 0xFFFFFFFFU , scale );
494505}
495- #endif // defined HAVE_LIBSDL_TTF
496506
497507/**
498508 * Only text banner is rendered in RGBA, other elements (background, squares) are already
@@ -580,11 +590,11 @@ void * vidcap_testcard2_thread(void *arg)
580590 (int ) since_start / 60 % 60 ,
581591 (int ) since_start % 60 ,
582592 s -> count % (int ) s -> desc .fps );
583- #ifdef HAVE_LIBSDL_TTF
584- render_sdl_ttf (s , frames , banner );
585- # else
586- render_builtin (s , frames , ( char * ) banner );
587- #endif
593+ if ( s -> use_builtin_font ) {
594+ render_builtin (s , frames , ( char * ) banner );
595+ } else {
596+ render_sdl_ttf (s , frames , banner );
597+ }
588598
589599 testcard_convert_buffer (
590600 RGBA , s -> desc .color_spec ,
0 commit comments