24 #include <utils/system/argparser.h> 25 #include <fvutils/colormap/colormap.h> 26 #include <fvutils/colormap/yuvcm.h> 27 #include <fvutils/colormap/cmfile.h> 36 int main(
int argc,
char** argv )
41 char* out_file = NULL;
45 in_file = strdup( argp->
arg(
"i" ) );
50 out_file = strdup( argp->
arg(
"o" ) );
53 if ( !in_file || !out_file )
55 printf(
"Usage: argv[0] -i <input colormap> -o <output colormap>\n");
59 printf(
"Reading colormap from file %s.\n", in_file);
60 printf(
"Writing modified colormap to file %s.\n", out_file);
63 cmfile.
read( in_file );
65 unsigned int cm_width = cm->
width();
66 unsigned int cm_height = cm->
height();
67 unsigned int cm_depth = cm->
depth();
69 unsigned char* cm_buffer = (
unsigned char*) malloc( cm->
size() );
73 cmpp->set( cm_buffer );
75 for (
unsigned int d = 0; d < cm_depth; ++d )
77 for (
unsigned int w = 0; w < cm_width; ++w )
79 for (
unsigned int h = 0; h < cm_height; ++h )
82 unsigned int y = (
unsigned int) (d * yuvfac);
84 color_t cur_color = cm->
determine(y, w, h);
87 if ( cur_color != C_OTHER )
90 unsigned int cm_counter[ C_OTHER + 1 ];
92 for (
unsigned int i = 0; i <= C_OTHER; ++i )
93 { cm_counter[ i ] = 0; }
95 unsigned int tst_radius_dp = 1;
96 unsigned int tst_radius_uv = 4;
98 unsigned int num_neighbours = 0;
100 for (
unsigned int dd = (
unsigned int) fmax(d - tst_radius_dp, 0);
101 dd <= fmin( d + tst_radius_dp, cm_depth - 1);
104 for (
unsigned int ww = (
unsigned int) fmax(w - tst_radius_uv, 0);
105 ww <= fmin( w + tst_radius_uv, cm_width - 1 );
108 for (
unsigned int hh = (
unsigned int) fmax(h - tst_radius_uv, 0);
109 hh <= fmin( h + tst_radius_uv, cm_height - 1);
112 color_t cur_color = cm->
determine( (
unsigned int) (dd * yuvfac), ww, hh );
113 ++cm_counter[ cur_color ];
120 unsigned int max = 0;
121 color_t max_color = C_OTHER;
123 for (
unsigned int i = 0; i < C_OTHER; ++i )
125 if ( cm_counter[ i ] > max )
127 max = cm_counter[ i ];
128 max_color = (color_t) i;
132 if ( max > num_neighbours * 0.1 && max_color != C_OTHER )
134 printf(
"max=%d max_color=%d num_neighbours=%d\n", max, max_color, num_neighbours);
135 cmpp->set( y, w, h, max_color );
142 cmout.add_colormap( cmpp );
143 printf(
"Writing modified colormap.\n" );
144 cmout.write( out_file );
const char * arg(const char *argn)
Get argument value.
virtual unsigned int depth() const =0
Get depth of colormap.
Fawkes library namespace.
Parse command line arguments.
virtual unsigned int height() const =0
Get height of colormap.
Colormap * get_colormap()
Get a freshly generated colormap based on current file content.
virtual void read(const char *file_name)
Read file.
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const =0
Determine color class for given YUV value.
virtual size_t size()=0
Size in bytes of buffer returned by get_buffer().
virtual unsigned int width() const =0
Get width of colormap.
virtual unsigned int deepness() const =0
Get deepness of colormap.
virtual unsigned char * get_buffer() const =0
Get the raw buffer of this colormap.
bool has_arg(const char *argn)
Check if argument has been supplied.