diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-12-07 02:27:45 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-12-07 02:27:45 +0400 |
commit | 2c21e2ee4c47096011a07be2d30eead8359b0f32 (patch) | |
tree | 0f83a8ae2e1313ead466e20da27676f14c4a31ce /libavutil | |
parent | 22ef9cb46dae20458470f968487515dbec78adc0 (diff) |
avutil/log: merge calls that set ansi color and print the string
about 1/3 or so faster
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/log.c | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/libavutil/log.c b/libavutil/log.c index 5923228039..6cc4d97f87 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -75,9 +75,6 @@ static const uint8_t color[16 + AV_CLASS_CATEGORY_NB] = { static int16_t background, attr_orig; static HANDLE con; -#define set_color(x) SetConsoleTextAttribute(con, background | color[x]) -#define set_256color set_color -#define reset_color() SetConsoleTextAttribute(con, attr_orig) #else static const uint32_t color[16 + AV_CLASS_CATEGORY_NB] = { @@ -101,9 +98,6 @@ static const uint32_t color[16 + AV_CLASS_CATEGORY_NB] = { [16+AV_CLASS_CATEGORY_SWRESAMPLER ] = 147 << 8 | 0x14, }; -#define set_color(x) fprintf(stderr, "\033[%d;3%dm", (color[x] >> 4) & 15, color[x] & 15) -#define set_256color(x) fprintf(stderr, "\033[48;5;%dm\033[38;5;%dm", (color[x] >> 16) & 0xff, (color[x] >> 8) & 0xff) -#define reset_color() fprintf(stderr, "\033[0m") #endif static int use_color = -1; @@ -132,14 +126,29 @@ static void colored_fputs(int level, const char *str) #endif } - if (use_color == 1) { - set_color(level); - } else if (use_color == 256) - set_256color(level); +#if HAVE_SETCONSOLETEXTATTRIBUTE + if (use_color) + SetConsoleTextAttribute(con, background | color[level]); fputs(str, stderr); - if (use_color) { - reset_color(); - } + if (use_color) + SetConsoleTextAttribute(con, attr_orig); +#else + if (use_color == 1) { + fprintf(stderr, + "\033[%d;3%dm%s\033[0m", + (color[level] >> 4) & 15, + color[level] & 15, + str); + } else if (use_color == 256) { + fprintf(stderr, + "\033[48;5;%dm\033[38;5;%dm%s\033[0m", + (color[level] >> 16) & 0xff, + (color[level] >> 8) & 0xff, + str); + } else + fputs(str, stderr); +#endif + } const char *av_default_item_name(void *ptr) |