Go to the documentation of this file.
31 mem::increment(s_class().c_str());
34 img(
unsigned int a_w,
unsigned int a_h,
unsigned int a_n,T* a_buffer,
bool a_owner)
40 mem::increment(s_class().c_str());
46 mem::decrement(s_class().c_str());
56 mem::increment(s_class().c_str());
72 if(&a_from==
this)
return *
this;
119 void set(
unsigned int a_w,
unsigned int a_h,
unsigned int a_n,T* a_buffer,
bool a_owner) {
127 bool copy(
unsigned int a_w,
unsigned int a_h,
unsigned int a_n,T* a_buffer) {
143 ::memcpy(
m_buffer,a_buffer,sz*
sizeof(T));
167 bool allocate(
unsigned int a_w,
unsigned int a_h,
unsigned int a_n){
170 unsigned int sz = a_w*a_h*a_n;
195 if(!
m_w)
return true;
196 if(!
m_h)
return true;
197 if(!
m_n)
return true;
202 if(
m_w!=a_from.
m_w)
return false;
203 if(
m_h!=a_from.
m_h)
return false;
204 if(
m_n!=a_from.
m_n)
return false;
209 for(
unsigned int index=0;index<sz;index++,pos++,fpos++) {
210 if((*pos)!=(*fpos))
return false;
223 bool pixel(
unsigned int a_i,
unsigned a_j,std::vector<T>& a_pixel)
const {
230 for(
unsigned int ipix=0;ipix<
m_n;ipix++) {
231 a_pixel[ipix] = *(pos+ipix);
236 bool expand(
unsigned int a_factor,
img<T>& a_res,
bool a_res_force_owner =
true)
const {
238 if(a_res_force_owner) {
246 unsigned int nw =
m_w*a_factor;
247 unsigned int nh =
m_h*a_factor;
248 unsigned int sz = nh*nw*
m_n;
260 for(
unsigned int j=0;j<
m_h;j++) {
261 for(
unsigned int i=0;i<
m_w;i++) {
265 for(
unsigned int fr=0;fr<a_factor;fr++) {
266 for(
unsigned int fc=0;fc<a_factor;fc++) {
268 T* npos = nb + (j*a_factor+fr) * (nw *
m_n) + (i*a_factor+fc)*
m_n;
269 for(
unsigned int ipix=0;ipix<
m_n;ipix++) {
270 *(npos+ipix) = *(pos+ipix);
278 a_res.
set(nw,nh,
m_n,nb,
true);
282 bool contract_raw(
unsigned int a_w,
unsigned int a_h,
img<T>& a_res,
bool a_force_res_owner =
true)
const {
283 if((a_w==
m_w)&&(a_h==
m_h)) {
284 if(a_force_res_owner) {
292 unsigned int sz = a_h*a_w*
m_n;
304 double* pixels =
new double[
m_n];
311 unsigned int wfac = double(
m_w)/double(a_w);
312 unsigned int hfac = double(
m_h)/double(a_h);
316 unsigned int wfac_hfac = wfac*hfac;
319 for(
unsigned int j=0;j<a_h;j++) {
320 for(
unsigned int i=0;i<a_w;i++) {
323 {
for(
unsigned int ipix=0;ipix<
m_n;ipix++) pixels[ipix] = 0;}
325 for(
unsigned int fr=0;fr<hfac;fr++) {
327 for(
unsigned int fc=0;fc<wfac;fc++) {
328 pos = hpos + (i*wfac+fc)*
m_n;
329 for(
unsigned int ipix=0;ipix<
m_n;ipix++) {
330 pixels[ipix] += double(*pos)/double(wfac_hfac);pos++;
336 T* rpos = rb + j * (a_w *
m_n) + i*
m_n;
337 {
for(
unsigned int ipix=0;ipix<
m_n;ipix++) {*rpos = T(pixels[ipix]);rpos++;}}
343 a_res.
set(a_w,a_h,
m_n,rb,
true);
347 bool contract(
unsigned int a_w,
unsigned int a_h,
img<T>& a_res,
bool a_force_res_owner =
true)
const {
350 if((a_w==
m_w)&&(a_h==
m_h)) {
351 if(a_force_res_owner) {
359 size_t sz = a_h*a_w*
m_n;
371 double* pixels =
new double[
m_n];
377 {
for(
unsigned int ipix=0;ipix<
m_n;ipix++) pixels[ipix] = 0;}
379 unsigned int wfac = (
unsigned int)(
double(
m_w)/double(a_w));
380 unsigned int hfac = (
unsigned int)(
double(
m_h)/double(a_h));
384 double wfac_hfac = wfac*hfac;
388 T* hpos;T* pos;T* hrpos;T* rpos;T* hhpos;T* _pos;
double* ppos;
389 unsigned int i,j,fr,fc,ipix,i0;
390 unsigned int astride = a_w *
m_n;
391 unsigned int mstride =
m_w *
m_n;
392 unsigned int wfacstride = wfac *
m_n;
395 hrpos = rb + j * astride;
404 for(fr=0;fr<hfac;fr++,hpos+=mstride) {
406 for(fc=0;fc<wfac;fc++,_pos+=
m_n) {
409 for(ipix=0;ipix<
m_n;ipix++,pos++,ppos++) {
410 *ppos += double(*pos)/wfac_hfac;
417 rpos = hrpos + i*
m_n;
419 for(ipix=0;ipix<
m_n;ipix++,rpos++,ppos++) {
429 a_res.
set(a_w,a_h,
m_n,rb,
true);
433 bool contract(
unsigned int a_factor,
img<T>& a_res,
bool a_force_res_owner =
true)
const {
435 unsigned int nw =
m_w/a_factor;
436 unsigned int nh =
m_h/a_factor;
437 return contract(nw,nh,a_res,a_force_res_owner);
445 if(!sz)
return false;
447 TTO* _buffer =
new TTO[sz];
448 if(!_buffer)
return false;
450 unsigned int i,j,ipix,imn;
451 unsigned int mwn =
m_w*
m_n;
453 TTO* _rpos;TTO* rpos;
457 _rpos = _buffer + j*mwn;
462 for(ipix=0;ipix<
m_n;ipix++,pos++,rpos++) *rpos = *pos;
470 bool get_part(
unsigned int a_sx,
unsigned int a_sy,
unsigned int a_sw,
unsigned int a_sh,
img<T>& a_res)
const {
472 if((a_sx>=
m_w)||(a_sy>=
m_h)){
478 unsigned int rw = min_of<unsigned int>(
m_w-a_sx,a_sw);
479 unsigned int rh = min_of<unsigned int>(
m_h-a_sy,a_sh);
480 unsigned int sz = rh*rw*
m_n;
492 unsigned int rstride = rw *
m_n;
495 unsigned int stride =
m_w *
m_n;
501 for(
unsigned int j=0;j<rh;j++,rpos+=rstride,pos+=stride) {
516 ::memcpy(rpos,pos,rstride*
sizeof(T));
519 a_res.
set(rw,rh,
m_n,rb,
true);
525 img<T>& a_res,
bool a_res_force_owner =
true)
const {
537 if((
m_w==1)||(
m_h==1)||a_expand) {
540 while(
true) {
if(rw>=
m_w)
break;rw *=2;}
542 while(
true) {
if(rh>=
m_h)
break;rh *=2;}
544 if((rw==
m_w)&&(rh==
m_h)) {
545 if(a_res_force_owner) {
562 rb =
new T[rh*rw*
m_n];
569 unsigned int num = rw*
m_n;
573 for(
unsigned int i=0;i<rw;i++,pos+=
m_n) {
574 ::memcpy(pos,a_pixel,
m_n*
sizeof(T));
576 unsigned int sz = num*
sizeof(T);
577 for(
unsigned int j=1;j<rh;j++,pos+=num) {
582 unsigned int col = (rw-
m_w)/2;
583 unsigned int row = (rh-
m_h)/2;
585 unsigned int mnum =
m_w*
m_n;
589 T* rpos = rb+row*num+col*
m_n;
590 unsigned int sz = mnum*
sizeof(T);
591 for(
unsigned int j=0;j<
m_h;j++,pos+=mnum,rpos+=num) {
592 ::memcpy(rpos,pos,sz);
595 if(res_set) a_res.
set(rw,rh,
m_n,rb,
true);
603 while(
true) {
if((sw*2)>
m_w)
break;sw *=2;}
605 while(
true) {
if((sh*2)>
m_h)
break;sh *=2;}
607 if((sw==
m_w)&&(sh==
m_h)) {
608 if(a_res_force_owner) {
616 unsigned int sx = (
m_w-sw)/2;
617 unsigned int sy = (
m_h-sh)/2;
628 unsigned int tw =
m_w;
629 unsigned int th =
m_h;
630 if((tw<=a_GL_MAX_TEXTURE_SIZE)&&(th<=a_GL_MAX_TEXTURE_SIZE)) {
634 unsigned int fac = 2;
636 unsigned int pw = tw/fac;
637 unsigned int ph = th/fac;
638 if((pw<=a_GL_MAX_TEXTURE_SIZE)&&(ph<=a_GL_MAX_TEXTURE_SIZE)) {
656 if(
m_n!=1)
return false;
659 if(a_n<
m_n)
return false;
660 unsigned int sz =
m_w*
m_h*a_n;
661 if(!sz)
return false;
670 for(
unsigned int j=0;j<
m_h;j++) {
671 for(
unsigned int i=0;i<
m_w;i++) {
675 T* rpos = a_res.
m_buffer + j * (
m_w * a_n) + i*a_n;
677 for(
unsigned int ipix=0;ipix<a_n;ipix++) {
697 unsigned int stride =
m_w *
m_n;
699 for(
unsigned int j=0;j<
m_h;j++) {
702 ::memcpy(rpos,pos,stride*
sizeof(T));
709 if(
m_n!=4)
return false;
711 unsigned int a_n = 3;
714 unsigned int sz =
m_w*
m_h*a_n;
715 if(!sz)
return false;
724 for(
unsigned int j=0;j<
m_h;j++) {
725 for(
unsigned int i=0;i<
m_w;i++) {
729 T* rpos = a_res.
m_buffer + j * (
m_w * a_n) + i*a_n;
731 for(
unsigned int ipix=0;ipix<a_n;ipix++) {
732 *(rpos+ipix) = *(pos+ipix);
742 if(
m_n!=3)
return false;
747 unsigned int sz =
m_w*
m_h*n;
748 if(!sz)
return false;
757 for(
unsigned int j=0;j<
m_h;j++) {
758 for(
unsigned int i=0;i<
m_w;i++) {
764 *(rpos+0) = *(pos+0);
765 *(rpos+1) = *(pos+1);
766 *(rpos+2) = *(pos+2);
776 if(
m_n!=4)
return false;
777 for(
unsigned int j=0;j<
m_h;j++) {
778 for(
unsigned int i=0;i<
m_w;i++) {
795 unsigned int a_cols,
unsigned int a_rows,
796 unsigned int a_bw,
unsigned int a_bh,
801 unsigned int num = a_cols*a_rows;
804 unsigned int aw = a_imgs[0].m_w;
805 unsigned int ah = a_imgs[0].m_h;
806 unsigned int an = a_imgs[0].m_n;
808 for(
unsigned int index=1;index<num;index++) {
809 if(a_imgs[index].
m_n!=an) {
813 if(a_imgs[index].
m_w!=aw) {
817 if(a_imgs[index].
m_h!=ah) {
823 unsigned int wbw = aw + 2*a_bw;
824 unsigned int hbh = ah + 2*a_bh;
826 unsigned int rw = wbw * a_cols;
827 unsigned int rh = hbh * a_rows;
828 unsigned int rn = an;
833 unsigned int rsz = rh*rw*rn;
840 bool has_border = a_bw||a_bh?
true:
false;
842 ::memset(rb,a_bc,rsz*
sizeof(T));
847 unsigned int awn = aw*an;
848 unsigned int rwn = rw*an;
851 T* pos;T* ptile;T* _pos;
854 unsigned int index = 0;
855 for(j=0;j<a_rows;j++) {
856 for(i=0;i<a_cols;i++) {
858 const T* tile = a_imgs[index].buffer();
867 _pos = rb + (j*hbh+a_bh)*rwn + (i*wbw+a_bw)*rn;
872 ::memcpy(_pos+r*rwn,tile+r*awn,awn*
sizeof(T));
879 a_res.
set(rw,rh,rn,rb,
true);
890 private:
static void check_instantiation() {
img<float> dummy;}
900 unsigned int& a_ew,
unsigned int& a_eh){
903 while(
true) {
if(a_ew>=a_w)
break;a_ew *=2;}
905 while(
true) {
if(a_eh>=a_h)
break;a_eh *=2;}
#define TOOLS_T_SCLASS(a_T, a_name)