@@ -405,7 +405,11 @@ class image_pattern_gradient : public image_pattern {
405405 public:
406406 explicit image_pattern_gradient (const string &config) {
407407 if (!config.empty ()) {
408- color = stol (config, nullptr , 0 );
408+ long long c = get_color_by_name (config.c_str ());
409+ if (c == -1 ) {
410+ throw 1 ;
411+ }
412+ color = c;
409413 }
410414 }
411415 static constexpr uint32_t red = 0xFFU ;
@@ -595,18 +599,31 @@ class image_pattern_text : public image_pattern {
595599 public:
596600 explicit image_pattern_text (const string & config) {
597601 if (config == " help" s) {
598- col () << " Testcard text usage:\n\t " << SBOLD (SRED (" -t testcard:pattern=text" ) << " [=pattern][,bg=0x<AABBGGRR<][,fg=0x<AABBGGRR>]" ) << " \n " ;
602+ col () << " Testcard text usage:\n\t "
603+ << SBOLD (SRED (" -t testcard:pattern=text" )
604+ << " [=pattern][,bg=0x<col>|help]"
605+ " [,fg=<col>|help]" )
606+ << " \n " ;
599607 throw 1 ;
600608 }
601609 if (!config.empty ()) {
602610 string_view sv = config;
603611 bool text_set = false ;
604612 while (!sv.empty ()) {
605613 auto tok = tokenize (sv, ' ,' );
606- if (tok.substr (0 ,3 ) == " bg=" ) {
607- bg = stol ((string) tok.substr (3 ), nullptr , 0 );
608- } else if (tok.substr (0 ,3 ) == " fg=" ) {
609- fg = stol ((string) tok.substr (3 ), nullptr , 0 );
614+ if (tok.substr (0 ,3 ) == " bg=" || tok.substr (0 ,3 ) == " fg=" ) {
615+ auto key = tokenize (tok, ' =' );
616+ auto val = tokenize (tok, ' =' );
617+ long long c = get_color_by_name (
618+ ((string) val).c_str ());
619+ if (c == -1 ) {
620+ throw 1 ;
621+ }
622+ if (key == " bg" ) {
623+ bg = c;
624+ } else {
625+ fg = c;
626+ }
610627 } else if (!text_set) {
611628 text = tok;
612629 text_set = true ;
@@ -638,7 +655,14 @@ class image_pattern_diagonal : public image_pattern{
638655 public:
639656 explicit image_pattern_diagonal (const string & config) {
640657 if (config == " help" s) {
641- col () << " Testcard diagonal usage:\n\t " << SBOLD (SRED (" -t testcard:pattern=diagonal" ) << " [,bg=0x<AABBGGRR<][,fg=0x<AABBGGRR>][,stride=<stride>][,line_width=<width>]" ) << " \n " ;
658+ col ()
659+ << " Testcard diagonal usage:\n\t "
660+ << SBOLD (
661+ SRED (" -t testcard:pattern=diagonal" )
662+ << " [,bg=<color>|help][,fg=<color>|"
663+ " help][,stride=<stride>][,line_"
664+ " width=<width>]" )
665+ << " \n " ;
642666 throw 1 ;
643667 }
644668 if (!config.empty ()) {
@@ -647,10 +671,17 @@ class image_pattern_diagonal : public image_pattern{
647671 auto tok = tokenize (sv, ' ,' );
648672 auto key = tokenize (tok, ' =' );
649673 auto val = tokenize (tok, ' =' );
650- if (key == " bg" ) {
651- bg = stol ((string) val, nullptr , 0 );
652- } else if (key == " fg" ) {
653- fg = stol ((string) val, nullptr , 0 );
674+ if (key == " bg" || key == " fg" ) {
675+ long long c = get_color_by_name (
676+ ((string) val).c_str ());
677+ if (c == -1 ) {
678+ throw 1 ;
679+ }
680+ if (key == " bg" ) {
681+ bg = c;
682+ } else {
683+ fg = c;
684+ }
654685 } else if (key == " stride" ) {
655686 stride = stol ((string) val, nullptr , 0 );
656687 } else if (key == " line_width" ) {
@@ -906,7 +937,7 @@ video_pattern_generator_create(const char *config, int width, int height, codec_
906937 BLANK_USAGE,
907938 " diagonal*" ,
908939 " ebu_bars" ,
909- " gradient[=0x<AABBGGRR> ]" ,
940+ " gradient[=<color>|help ]" ,
910941 " gradient2*" ,
911942 " gray" ,
912943 " interlaced" ,
0 commit comments