32 void output(
const char * p )
34 std::cout << p << std::flush ;
36 int env(
const std::string & name )
40 throw std::runtime_error(
"no environment variable '"+name+
"'; try \"export "+name+
"\"" ) ;
42 throw std::runtime_error(
"invalid value of envionment variable '"+name+
"'" ) ;
45 throw std::runtime_error(
"invalid value of envionment variable '"+name+
"'" ) ;
53 m_mask(dx,dy,m_config.m_mask_file)
55 output(
"\033[2J\033[1;1H" ) ;
68 output(
"\033[2J\033[1;1H" ) ;
73 line.reserve( dx + 2 ) ;
76 for(
Gr::Scaler y_scaler(dy,data_dy) ; !!y_scaler ; ++y_scaler )
78 int display_y = y_scaler.first() ;
84 std::cout << line << std::flush ;
87 for(
Gr::Scaler x_scaler(dx,data_dx) ; !!x_scaler ; ++x_scaler )
89 int display_x = x_scaler.first() ;
94 int data_x = x_scaler.second() ;
95 int data_y = y_scaler.second() ;
97 int data_offset = data_y * data_dx + data_x ;
98 if( data_channels != 1 )
99 data_offset *= data_channels ;
100 const unsigned char * p =
reinterpret_cast<const unsigned char *
>(data_p+data_offset) ;
102 unsigned int r = *p++ ;
103 unsigned int g = data_channels > 1 ? *p++ : r ;
104 unsigned int b = data_channels > 2 ? *p++ : r ;
107 static const char * luma_map =
" .,:;|(){}%%$@@##" ;
109 bool masked = m_mask.masked(data_x,data_y) ;
110 char c = masked ?
'_' : luma_map[(luma/16U)%16U] ;
112 if( y == 0 && x <
int(m_config.m_title.length()) )
113 line.append( 1U , m_config.m_title.at(x) ) ;
115 line.append( 1U , c ) ;
119 line.erase( line.begin() + (line.size()-1U) ) ;
120 std::cout << line << std::flush ;
125 return env(
"COLUMNS" ) ;
130 return env(
"LINES" ) ;
static std::string get(const std::string &name, const std::string &default_)
Returns the environment variable value or the given default.
virtual ~ViewerWindowAnsi()
Destructor.
virtual void display(int, int, int, const char *, size_t) override
Override from ViewerWindow.
A class that allows for iterating over one integer range while accessing values from another...
ViewerWindowAnsi(ViewerWindowHandler &, ViewerWindowConfig, int dx, int dy)
Constructor.
static unsigned int toUInt(const std::string &s)
Converts string 's' to an unsigned int.
virtual int dx() const override
Override from ViewerWindow.
virtual int dy() const override
Override from ViewerWindow.
A configuration structure for Gv::ViewerWindow.
virtual void init() override
Override from ViewerWindow.
triple< unsigned char > yuv_int(triple< unsigned char > rgb) g__noexcept
A fast conversion from rgb to yuv.
static bool isUInt(const std::string &s)
Returns true if the string can be converted into an unsigned integer without throwing an exception...
A callback interface for Gv::ViewerWindow.