19 unsigned int a_w,
unsigned int a_h,
21 unsigned int a_cols,
unsigned int a_rows,
22 unsigned int a_bw,
unsigned int a_bh,
24 unsigned int& a_rw,
unsigned int& a_rh){
30 unsigned int wbw = a_w + 2*a_bw;
31 unsigned int hbh = a_h + 2*a_bh;
39 unsigned char* rb =
new unsigned char[a_rh*a_rw*a_bpp];
40 if(!rb) {a_rw = 0;a_rh = 0;
return 0;}
42 unsigned int wbw3 = wbw*a_bpp;
43 unsigned int aw3 = a_w*a_bpp;
46 unsigned int index = 0;
47 for(
unsigned int j=0;j<a_rows;j++) {
48 for(
unsigned int i=0;i<a_cols;i++) {
49 unsigned char* tile = a_buffers[index];
51 for(
unsigned int r=0;r<hbh;r++) {
52 unsigned char* pos = rb + (j*hbh+r)*a_rw*a_bpp + i*wbw*a_bpp;
53 ::memset(pos,a_bc,wbw3);
56 for(
unsigned int r=0;r<a_h;r++) {
57 unsigned char* pos = rb + (j*hbh+r+a_bh)*a_rw*a_bpp + (i*wbw+a_bw)*a_bpp;
58 unsigned char* ptile = tile+r*aw3;
59 for(
unsigned int c=0;c<aw3;c++,pos++,ptile++) *pos = *ptile;
77 typedef unsigned char* (*file_reader)(std::ostream&,
const std::string&,
unsigned int&,
unsigned int&,
unsigned int&);
80 const std::vector<std::string>& a_files,
81 unsigned int a_cols,
unsigned int a_rows,
82 unsigned int a_bw,
unsigned int a_bh,
85 unsigned int& a_w,
unsigned int& a_h,
86 unsigned int& a_bpp) {
93 unsigned int number = a_cols*a_rows;
94 if(number!=a_files.size()) {
95 a_out <<
"tools::image::concatenate :"
96 <<
" bad number of files. " << number <<
" expected."
98 a_bpp = a_w = a_h = 0;
101 if(a_files.empty()) {
102 a_out <<
"tools::image::concatenate :"
103 <<
" list of files is empty."
105 a_bpp = a_w = a_h = 0;
111 unsigned int bpp1 = 0;
113 typedef unsigned char* buffer_t;
114 buffer_t* bs =
new buffer_t[number];
115 {
for(
unsigned int i=0;i<number;i++) {bs[i] = 0;}}
117 bool read_failed =
false;
118 unsigned int index = 0;
119 for(
unsigned int j=0;j<a_rows;j++) {
120 for(
unsigned int i=0;i<a_cols;i++) {
121 const std::string& file = a_files[index];
122 unsigned int w,h,bpp;
123 unsigned char* b = a_file_reader(a_out,file,w,h,bpp);
125 a_out <<
"tools::image::concatenate :"
126 <<
" can't read " << file <<
" expected."
137 a_out <<
"tools::image::concatenate :"
139 <<
" does not have same width image as the first file one."
140 <<
" (" << w <<
"," << w1 <<
")."
147 a_out <<
"tools::image::concatenate :"
149 <<
" does not have same height image as the first file one."
150 <<
" (" << h <<
"," << h1 <<
")."
157 a_out <<
"tools::image::concatenate :"
159 <<
" does not have same bytes per pixel as the first file one."
160 <<
" (" << h <<
"," << h1 <<
")."
172 if(read_failed)
break;
176 {
for(
unsigned int i=0;i<number;i++) {
delete [] bs[i];}}
177 a_bpp = a_w = a_h = 0;
182 unsigned char* ba =
image::concatenate(bs,w1,h1,bpp1,a_cols,a_rows,a_bw,a_bh,a_bc,wa,ha);
184 a_out <<
"tools::image::concatenate :"
185 <<
" failed to concatenate all buffers."
187 {
for(
unsigned int i=0;i<number;i++) {
delete [] bs[i];}}
188 a_bpp = a_w = a_h = 0;
192 {
for(
unsigned int i=0;i<number;i++) {
delete [] bs[i];}}
200 typedef unsigned char* (*reader)(FILE*,
unsigned int&,
unsigned int&);
201 typedef bool(*
writer)(FILE*,
unsigned char*,
unsigned int,
unsigned int);
204 const std::string& a_sin,
206 const std::string& a_sout,
209 FILE* fin = ::fopen(a_sin.c_str(),
"rb");
211 a_out <<
"tools::image::convert :"
212 <<
" can't open " << a_sin
218 unsigned char* b = a_reader(fin,w,h);
220 a_out <<
"tools::image::convert :"
221 <<
" can't read " << a_sin
228 FILE* fout = ::fopen(a_sout.c_str(),
"wb");
230 a_out <<
"tools::image::convert :"
231 <<
" can't open " << a_sout
237 if(!a_writer(fout,b,w,h)) {
238 a_out <<
"tools::image::convert :"
239 <<
" can't write " << a_sout
274 virtual unsigned int index()
const = 0;
275 virtual unsigned char*
read_image(
unsigned int& a_w,
unsigned int& a_h,
276 unsigned int& a_bpp) = 0;
288 virtual unsigned char*
read_image(
unsigned int& a_w,
unsigned int& a_h,
289 unsigned int& a_bpp) {
294 if((*it)->is(file)) {
295 unsigned char* buffer =
_open(*(*it),file,a_w,a_h,a_bpp);
302 a_w = 0;a_h = 0;a_bpp = 0;
314 mem::increment(s_class().c_str());
320 mem::decrement(s_class().c_str());
330 mem::increment(s_class().c_str());
335 if(&a_from==
this)
return *
this;
346 const std::string& a_path,
347 unsigned int& a_w,
unsigned int& a_h,
348 unsigned int& a_bpp){
351 unsigned char* buffer = 0;
354 if(!a_reader.
infos(
m_out,a_path,a_w,a_h,a_bpp)) {
355 m_out <<
"tools::image::iterator_reader::_open :"
356 <<
" for file " <<
sout(a_path)
357 <<
" ireader::infos failed."
359 a_w = 0;a_h = 0;a_bpp = 0;
378 if(((2*sw)*(2*sh)*a_bpp)>
m_limit)
break;
383 unsigned int sx = (a_w-sw)/2;
384 unsigned int sy = (a_h-sh)/2;
387 (
m_out,a_path,sx,sy,sw,sh,a_w,a_h,a_bpp);
389 buffer = a_reader.
read(
m_out,a_path,a_w,a_h,a_bpp);
392 buffer = a_reader.
read(
m_out,a_path,a_w,a_h,a_bpp);
396 m_out <<
"tools::image::iterator_reader::_open :"
397 <<
" for file " <<
sout(a_path)
400 a_w = 0;a_h = 0;a_bpp = 0;
408 std::vector<ireader*>::iterator it;
415 void _copy(
const std::vector<ireader*>& a_from) {