|
inlib
1.2.0
|
Public Member Functions | |
| img (unsigned int a_n) | |
| img (unsigned int a_w, unsigned int a_h, unsigned int a_n, T *a_buffer, bool a_owner) | |
| virtual | ~img () |
| img (const img &a_from) | |
| img & | operator= (const img &a_from) |
| bool | operator== (const img &a_from) const |
| bool | operator!= (const img &a_from) const |
| void | transfer (img &a_from) |
| void | clear () |
| void | set (unsigned int a_w, unsigned int a_h, T *a_buffer, bool a_owner) |
| bool | copy (const img &a_from) |
| bool | allocate (unsigned int a_w, unsigned int a_h) |
| void | make_empty () |
| bool | equal (const img &a_from) const |
| unsigned int | width () const |
| unsigned int | height () const |
| unsigned int | bytes_per_pixel () const |
| unsigned int | bpp () const |
| T * | buffer () const |
| bool | owner () const |
| unsigned int | size () const |
| bool | expand (unsigned int a_factor, img< T > &a_res) const |
| bool | contract (unsigned int a_factor, img< T > &a_res) const |
| bool | get_part (unsigned int a_sx, unsigned int a_sy, unsigned int a_sw, unsigned int a_sh, img< T > &a_res) const |
| bool | to_texture (bool a_expand, T a_pixel[], img< T > &a_res) const |
| img (unsigned int a_n) | |
| img (unsigned int a_w, unsigned int a_h, unsigned int a_n, T *a_buffer, bool a_owner) | |
| virtual | ~img () |
| img (const img &a_from) | |
| img & | operator= (const img &a_from) |
| bool | operator== (const img &a_from) const |
| bool | operator!= (const img &a_from) const |
| void | transfer (img &a_from) |
| void | clear () |
| void | set (unsigned int a_w, unsigned int a_h, T *a_buffer, bool a_owner) |
| bool | copy (const img &a_from) |
| bool | allocate (unsigned int a_w, unsigned int a_h) |
| void | make_empty () |
| bool | equal (const img &a_from) const |
| unsigned int | width () const |
| unsigned int | height () const |
| unsigned int | bytes_per_pixel () const |
| unsigned int | bpp () const |
| T * | buffer () const |
| bool | owner () const |
| unsigned int | size () const |
| bool | expand (unsigned int a_factor, img< T > &a_res) const |
| bool | contract (unsigned int a_factor, img< T > &a_res) const |
| bool | get_part (unsigned int a_sx, unsigned int a_sy, unsigned int a_sw, unsigned int a_sh, img< T > &a_res) const |
| bool | to_texture (bool a_expand, T a_pixel[], img< T > &a_res) const |
Static Public Member Functions | |
| static bool | concatenate (const std::vector< img< T > > &a_imgs, unsigned int a_cols, unsigned int a_rows, unsigned int a_bw, unsigned int a_bh, T a_bc, img< T > &a_res) |
| static bool | concatenate (const std::vector< img< T > > &a_imgs, unsigned int a_cols, unsigned int a_rows, unsigned int a_bw, unsigned int a_bh, T a_bc, img< T > &a_res) |
Protected Attributes | |
| unsigned int | m_w |
| unsigned int | m_h |
| unsigned int | m_n |
| T * | m_buffer |
| bool | m_owner |
| inlib::img< T >::img | ( | unsigned int | a_n | ) | [inline] |
| inlib::img< T >::img | ( | unsigned int | a_w, |
| unsigned int | a_h, | ||
| unsigned int | a_n, | ||
| T * | a_buffer, | ||
| bool | a_owner | ||
| ) | [inline] |
| virtual inlib::img< T >::~img | ( | ) | [inline, virtual] |
| inlib::img< T >::img | ( | const img< T > & | a_from | ) | [inline] |
Definition at line 53 of file img.
:m_w(a_from.m_w),m_h(a_from.m_h),m_n(a_from.m_n) ,m_buffer(0) ,m_owner(a_from.m_owner) { #ifdef INLIB_MEM mem::increment(s_class().c_str()); #endif if(m_owner) { unsigned int sz = m_w*m_h*m_n; if(!sz) return; m_buffer = new T[sz]; if(!m_buffer) { m_w = 0;m_h = 0;m_owner = false; return; //throw } ::memcpy(m_buffer,a_from.m_buffer,sz*sizeof(T)); } else { m_buffer = a_from.m_buffer; } }
| inlib::img< T >::img | ( | unsigned int | a_n | ) | [inline] |
| inlib::img< T >::img | ( | unsigned int | a_w, |
| unsigned int | a_h, | ||
| unsigned int | a_n, | ||
| T * | a_buffer, | ||
| bool | a_owner | ||
| ) | [inline] |
| virtual inlib::img< T >::~img | ( | ) | [inline, virtual] |
| inlib::img< T >::img | ( | const img< T > & | a_from | ) | [inline] |
Definition at line 52 of file img_old.
:m_w(a_from.m_w),m_h(a_from.m_h),m_n(a_from.m_n) ,m_buffer(0) ,m_owner(a_from.m_owner) { #ifdef INLIB_MEM mem::increment(s_class().c_str()); #endif if(m_owner) { unsigned int sz = m_w*m_h*m_n; if(!sz) return; m_buffer = new T[sz]; if(!m_buffer) { m_w = 0;m_h = 0;m_owner = false; return; //throw } ::memcpy(m_buffer,a_from.m_buffer,sz*sizeof(T)); } else { m_buffer = a_from.m_buffer; } }
| bool inlib::img< T >::allocate | ( | unsigned int | a_w, |
| unsigned int | a_h | ||
| ) | [inline] |
| bool inlib::img< T >::allocate | ( | unsigned int | a_w, |
| unsigned int | a_h | ||
| ) | [inline] |
| unsigned int inlib::img< T >::bpp | ( | ) | const [inline] |
| unsigned int inlib::img< T >::bpp | ( | ) | const [inline] |
| T* inlib::img< T >::buffer | ( | ) | const [inline] |
| T* inlib::img< T >::buffer | ( | ) | const [inline] |
| unsigned int inlib::img< T >::bytes_per_pixel | ( | ) | const [inline] |
| unsigned int inlib::img< T >::bytes_per_pixel | ( | ) | const [inline] |
| void inlib::img< T >::clear | ( | ) | [inline] |
| void inlib::img< T >::clear | ( | ) | [inline] |
| static bool inlib::img< T >::concatenate | ( | const std::vector< img< T > > & | a_imgs, |
| unsigned int | a_cols, | ||
| unsigned int | a_rows, | ||
| unsigned int | a_bw, | ||
| unsigned int | a_bh, | ||
| T | a_bc, | ||
| img< T > & | a_res | ||
| ) | [inline, static] |
Definition at line 431 of file img_old.
{
//not tested yet.
// We assume that size of a_imgs is a_cols*a_rows
// We should check that all a_imgs are consistents.
unsigned int num = a_cols*a_rows;
if(!num) {a_res.make_empty();return false;}
unsigned int a_w = a_imgs[0].m_w;
unsigned int a_h = a_imgs[0].m_h;
unsigned int a_n = a_imgs[0].m_n;
if(a_res.m_n!=a_n) {
a_res.make_empty();
return false;
}
for(unsigned int index=1;index<num;index++) {
if(a_imgs[index].m_n!=a_n) {
a_res.make_empty();
return false;
}
if(a_imgs[index].m_w!=a_w) {
a_res.make_empty();
return false;
}
if(a_imgs[index].m_h!=a_h) {
a_res.make_empty();
return false;
}
}
unsigned wbw = a_w + 2*a_bw;
unsigned hbh = a_h + 2*a_bh;
unsigned int rw = wbw * a_cols;
unsigned int rh = hbh * a_rows;
//printf("debug : %d %d\n",rw,rh);
// on big concatenated image the below may fail :
T* rb = new T[rh*rw*a_n];
if(!rb) {
a_res.make_empty();
return false;
}
unsigned int wbwn = wbw*a_n;
unsigned int awn = a_w*a_n;
//copy tiles :
unsigned int index = 0;
for(unsigned int j=0;j<a_rows;j++) {
for(unsigned int i=0;i<a_cols;i++) {
T* tile = a_imgs[index].buffer();
for(unsigned int r=0;r<hbh;r++) {
T* pos = rb + (j*hbh+r)*rw*a_n + i*wbw*a_n;
::memset(pos,a_bc,wbwn*sizeof(T));
}
for(unsigned int r=0;r<a_h;r++) {
T* pos = rb + (j*hbh+r+a_bh)*rw*a_n + (i*wbw+a_bw)*a_n;
T* ptile = tile+r*awn;
for(unsigned int c=0;c<awn;c++) *pos++ = *ptile++;
}
index++;
}
}
a_res.set(rw,rh,rb,true);
return true;
}
| static bool inlib::img< T >::concatenate | ( | const std::vector< img< T > > & | a_imgs, |
| unsigned int | a_cols, | ||
| unsigned int | a_rows, | ||
| unsigned int | a_bw, | ||
| unsigned int | a_bh, | ||
| T | a_bc, | ||
| img< T > & | a_res | ||
| ) | [inline, static] |
Definition at line 775 of file img.
{
//not tested yet.
// We assume that size of a_imgs is a_cols*a_rows
// We should check that all a_imgs are consistents.
unsigned int num = a_cols*a_rows;
if(!num) {a_res.make_empty();return false;}
unsigned int a_w = a_imgs[0].m_w;
unsigned int a_h = a_imgs[0].m_h;
unsigned int a_n = a_imgs[0].m_n;
if(a_res.m_n!=a_n) {
a_res.make_empty();
return false;
}
for(unsigned int index=1;index<num;index++) {
if(a_imgs[index].m_n!=a_n) {
a_res.make_empty();
return false;
}
if(a_imgs[index].m_w!=a_w) {
a_res.make_empty();
return false;
}
if(a_imgs[index].m_h!=a_h) {
a_res.make_empty();
return false;
}
}
unsigned wbw = a_w + 2*a_bw;
unsigned hbh = a_h + 2*a_bh;
unsigned int rw = wbw * a_cols;
unsigned int rh = hbh * a_rows;
//printf("debug : %d %d\n",rw,rh);
// on big concatenated image the below may fail :
T* rb = new T[rh*rw*a_n];
if(!rb) {
a_res.make_empty();
return false;
}
unsigned int wbwn = wbw*a_n;
unsigned int awn = a_w*a_n;
//copy tiles :
unsigned int index = 0;
for(unsigned int j=0;j<a_rows;j++) {
for(unsigned int i=0;i<a_cols;i++) {
T* tile = a_imgs[index].buffer();
for(unsigned int r=0;r<hbh;r++) {
T* pos = rb + (j*hbh+r)*rw*a_n + i*wbw*a_n;
::memset(pos,a_bc,wbwn*sizeof(T));
}
for(unsigned int r=0;r<a_h;r++) {
T* pos = rb + (j*hbh+r+a_bh)*rw*a_n + (i*wbw+a_bw)*a_n;
T* ptile = tile+r*awn;
for(unsigned int c=0;c<awn;c++) *pos++ = *ptile++;
}
index++;
}
}
a_res.set(rw,rh,rb,true);
return true;
}
| bool inlib::img< T >::contract | ( | unsigned int | a_factor, |
| img< T > & | a_res | ||
| ) | const [inline] |
Definition at line 240 of file img_old.
{
// a_factor pixels are contracted in one.
if(a_res.m_n!=m_n) {
a_res.make_empty();
return false;
}
if(!a_factor) {
a_res.make_empty();
return false;
}
if(a_factor==1) {
a_res.set(m_w,m_h,m_buffer,false);
return true;
}
unsigned int nw = m_w/a_factor;
unsigned int nh = m_h/a_factor;
unsigned int sz = nh*nw*m_n;
if(!sz) {
a_res.make_empty();
return false;
}
T* nb = new T[sz];
if(!nb) {
a_res.make_empty();
return false;
}
//T* npos = nb;
//for(unsigned int ipix=0;ipix<sz;ipix++) {*npos = 125;npos++;}
double* pixels = new double[m_n]; //for mean value.
if(!pixels) {
delete [] nb;
a_res.make_empty();
return false;
}
unsigned int nfac = a_factor*a_factor;
for(unsigned int j=0;j<nh;j++) {
for(unsigned int i=0;i<nw;i++) {
// take mean value of a_factor*a_factor pixels :
for(unsigned int ipix=0;ipix<m_n;ipix++) pixels[ipix] = 0;
for(unsigned int fr=0;fr<a_factor;fr++) {
for(unsigned int fc=0;fc<a_factor;fc++) {
T* pos = m_buffer + (j*a_factor+fr)*(m_w*m_n) +(i*a_factor+fc)*m_n;
for(unsigned int ipix=0;ipix<m_n;ipix++) {
pixels[ipix] += double(*pos);pos++;
}
}
}
for(unsigned int ipix=0;ipix<m_n;ipix++) {
pixels[ipix] /= double(nfac);
}
//position in the result image.
T* npos = nb + j * (nw * m_n) + i*m_n;
for(unsigned int ipix=0;ipix<m_n;ipix++) {
*npos = T(pixels[ipix]);npos++;
}
}
}
delete [] pixels;
a_res.set(nw,nh,nb,true);
return true;
}
| bool inlib::img< T >::contract | ( | unsigned int | a_factor, |
| img< T > & | a_res | ||
| ) | const [inline] |
Definition at line 242 of file img.
{
// a_factor pixels are contracted in one.
if(a_res.m_n!=m_n) {
a_res.make_empty();
return false;
}
if(a_factor==1) {
a_res.set(m_w,m_h,m_buffer,false);
return true;
}
if(!a_factor) {
a_res.make_empty();
return false;
}
unsigned int nw = m_w/a_factor;
unsigned int nh = m_h/a_factor;
unsigned int sz = nh*nw*m_n;
if(!sz) {
a_res.make_empty();
return false;
}
T* nb = new T[sz];
if(!nb) {
a_res.make_empty();
return false;
}
//T* npos = nb;
//for(unsigned int ipix=0;ipix<sz;ipix++) {*npos = 125;npos++;}
double* pixels = new double[m_n]; //for mean value.
if(!pixels) {
delete [] nb;
a_res.make_empty();
return false;
}
unsigned int nfac = a_factor*a_factor;
for(unsigned int j=0;j<nh;j++) {
for(unsigned int i=0;i<nw;i++) {
// take mean value of a_factor*a_factor pixels :
for(unsigned int ipix=0;ipix<m_n;ipix++) pixels[ipix] = 0;
for(unsigned int fr=0;fr<a_factor;fr++) {
for(unsigned int fc=0;fc<a_factor;fc++) {
T* pos = m_buffer + (j*a_factor+fr)*(m_w*m_n) +(i*a_factor+fc)*m_n;
for(unsigned int ipix=0;ipix<m_n;ipix++) {
pixels[ipix] += double(*pos);pos++;
}
}
}
for(unsigned int ipix=0;ipix<m_n;ipix++) {
pixels[ipix] /= double(nfac);
}
//position in the result image.
T* npos = nb + j * (nw * m_n) + i*m_n;
for(unsigned int ipix=0;ipix<m_n;ipix++) {
*npos = T(pixels[ipix]);npos++;
}
}
}
delete [] pixels;
a_res.set(nw,nh,nb,true);
return true;
}
| bool inlib::img< T >::copy | ( | const img< T > & | a_from | ) | [inline] |
Definition at line 128 of file img_old.
{
if(m_owner) delete [] m_buffer;
m_buffer = 0;
m_w = a_from.m_w;
m_h = a_from.m_h;
m_n = a_from.m_n;
unsigned int sz = m_w*m_h*m_n;
if(!sz) {
m_w = 0;m_h = 0;m_owner = false;
return false;
}
m_buffer = new T[sz];
if(!m_buffer) {
m_w = 0;m_h = 0;m_owner = false;
return false;
}
::memcpy(m_buffer,a_from.m_buffer,sz*sizeof(T));
m_owner = true;
return true;
}
| bool inlib::img< T >::copy | ( | const img< T > & | a_from | ) | [inline] |
Definition at line 129 of file img.
{
if(m_owner) delete [] m_buffer;
m_buffer = 0;
m_w = a_from.m_w;
m_h = a_from.m_h;
m_n = a_from.m_n;
unsigned int sz = m_w*m_h*m_n;
if(!sz) {
m_w = 0;m_h = 0;m_owner = false;
return false;
}
m_buffer = new T[sz];
if(!m_buffer) {
m_w = 0;m_h = 0;m_owner = false;
return false;
}
::memcpy(m_buffer,a_from.m_buffer,sz*sizeof(T));
m_owner = true;
return true;
}
| bool inlib::img< T >::equal | ( | const img< T > & | a_from | ) | const [inline] |
Definition at line 174 of file img_old.
{
if(m_w!=a_from.m_w) return false;
if(m_h!=a_from.m_h) return false;
if(m_n!=a_from.m_n) return false;
//don't test ownership.
unsigned int sz = m_w*m_h*m_n;
T* pos = m_buffer;
T* fpos = a_from.m_buffer;
for(unsigned int index=0;index<sz;index++,pos++,fpos++) {
if((*pos)!=(*fpos)) return false;
}
return true;
}
| bool inlib::img< T >::equal | ( | const img< T > & | a_from | ) | const [inline] |
Definition at line 175 of file img.
{
if(m_w!=a_from.m_w) return false;
if(m_h!=a_from.m_h) return false;
if(m_n!=a_from.m_n) return false;
//don't test ownership.
unsigned int sz = m_w*m_h*m_n;
T* pos = m_buffer;
T* fpos = a_from.m_buffer;
for(unsigned int index=0;index<sz;index++,pos++,fpos++) {
if((*pos)!=(*fpos)) return false;
}
return true;
}
| bool inlib::img< T >::expand | ( | unsigned int | a_factor, |
| img< T > & | a_res | ||
| ) | const [inline] |
Definition at line 195 of file img_old.
{
if(a_res.m_n!=m_n) {
a_res.make_empty();
return false;
}
if(!a_factor) {
a_res.make_empty();
return false;
}
if(a_factor==1) {
a_res.set(m_w,m_h,m_buffer,false);
return true;
}
unsigned int nw = m_w*a_factor;
unsigned int nh = m_h*a_factor;
T* nb = new T[nh*nw*m_n];
if(!nb) {
a_res.make_empty();
return false;
}
for(unsigned int j=0;j<m_h;j++) {
for(unsigned int i=0;i<m_w;i++) {
//position in the original image.
T* pos = m_buffer + j * (m_w * m_n) + i*m_n;
for(unsigned int fr=0;fr<a_factor;fr++) {
for(unsigned int fc=0;fc<a_factor;fc++) {
//position in the new image.
T* npos = nb + (j*a_factor+fr) * (nw * m_n) + (i*a_factor+fc)*m_n;
for(unsigned int ipix=0;ipix<m_n;ipix++) {
*(npos+ipix) = *(pos+ipix);
}
}
}
}
}
a_res.set(nw,nh,nb,true);
return true;
}
| bool inlib::img< T >::expand | ( | unsigned int | a_factor, |
| img< T > & | a_res | ||
| ) | const [inline] |
Definition at line 196 of file img.
{
if(a_res.m_n!=m_n) {
a_res.make_empty();
return false;
}
if(a_factor==1) {
a_res.set(m_w,m_h,m_buffer,false);
return true;
}
unsigned int nw = m_w*a_factor;
unsigned int nh = m_h*a_factor;
unsigned int sz = nh*nw*m_n;
if(!sz) {
a_res.make_empty();
return false;
}
T* nb = new T[sz];
if(!nb) {
a_res.make_empty();
return false;
}
for(unsigned int j=0;j<m_h;j++) {
for(unsigned int i=0;i<m_w;i++) {
//position in the original image.
T* pos = m_buffer + j * (m_w * m_n) + i*m_n;
for(unsigned int fr=0;fr<a_factor;fr++) {
for(unsigned int fc=0;fc<a_factor;fc++) {
//position in the new image.
T* npos = nb + (j*a_factor+fr) * (nw * m_n) + (i*a_factor+fc)*m_n;
for(unsigned int ipix=0;ipix<m_n;ipix++) {
*(npos+ipix) = *(pos+ipix);
}
}
}
}
}
a_res.set(nw,nh,nb,true);
return true;
}
| bool inlib::img< T >::get_part | ( | unsigned int | a_sx, |
| unsigned int | a_sy, | ||
| unsigned int | a_sw, | ||
| unsigned int | a_sh, | ||
| img< T > & | a_res | ||
| ) | const [inline] |
Definition at line 312 of file img_old.
{
if(a_res.m_n!=m_n) {
a_res.make_empty();
return false;
}
if((a_sx>=m_w)||(a_sy>=m_h)){
a_res.make_empty();
return false;
}
// 012345
unsigned int rw = inlib::mn<unsigned int>(m_w-a_sx,a_sw);
unsigned int rh = inlib::mn<unsigned int>(m_h-a_sy,a_sh);
if((!rw)||(!rh)) {
a_res.make_empty();
return false;
}
//printf("debug : %d %d\n",a_rw,a_rh);
T* rb = new T[rh*rw*m_n];
if(!rb) {
a_res.make_empty();
return false;
}
unsigned int rstride = rw * m_n;
T* rpos = rb;
unsigned int stride = m_w * m_n;
T* pos = m_buffer+a_sy*stride+a_sx*m_n;
for(unsigned int j=0;j<rh;j++,rpos+=rstride,pos+=stride) {//j=0 -> bottom.
::memcpy(rpos,pos,rstride*sizeof(T));
}
a_res.set(rw,rh,rb,true);
return true;
}
| bool inlib::img< T >::get_part | ( | unsigned int | a_sx, |
| unsigned int | a_sy, | ||
| unsigned int | a_sw, | ||
| unsigned int | a_sh, | ||
| img< T > & | a_res | ||
| ) | const [inline] |
Definition at line 314 of file img.
{
if(a_res.m_n!=m_n) {
a_res.make_empty();
return false;
}
if((a_sx>=m_w)||(a_sy>=m_h)){
a_res.make_empty();
return false;
}
// 012345
unsigned int rw = inlib::mn<unsigned int>(m_w-a_sx,a_sw);
unsigned int rh = inlib::mn<unsigned int>(m_h-a_sy,a_sh);
unsigned int sz = rh*rw*m_n;
if(!sz) {
a_res.make_empty();
return false;
}
//printf("debug : %d %d\n",a_rw,a_rh);
T* rb = new T[sz];
if(!rb) {
a_res.make_empty();
return false;
}
unsigned int rstride = rw * m_n;
T* rpos = rb;
unsigned int stride = m_w * m_n;
T* pos = m_buffer+a_sy*stride+a_sx*m_n;
for(unsigned int j=0;j<rh;j++,rpos+=rstride,pos+=stride) {//j=0 -> bottom.
::memcpy(rpos,pos,rstride*sizeof(T));
}
a_res.set(rw,rh,rb,true);
return true;
}
| unsigned int inlib::img< T >::height | ( | ) | const [inline] |
| unsigned int inlib::img< T >::height | ( | ) | const [inline] |
| void inlib::img< T >::make_empty | ( | ) | [inline] |
| void inlib::img< T >::make_empty | ( | ) | [inline] |
| bool inlib::img< T >::operator!= | ( | const img< T > & | a_from | ) | const [inline] |
Definition at line 96 of file img_old.
{return !operator==(a_from);}
| bool inlib::img< T >::operator!= | ( | const img< T > & | a_from | ) | const [inline] |
Definition at line 97 of file img.
{return !operator==(a_from);}
| img& inlib::img< T >::operator= | ( | const img< T > & | a_from | ) | [inline] |
Definition at line 73 of file img_old.
{
if(m_owner) delete [] m_buffer;
m_buffer = 0;
m_w = a_from.m_w;
m_h = a_from.m_h;
m_n = a_from.m_n;
m_owner = a_from.m_owner;
if(m_owner) {
unsigned int sz = m_w*m_h*m_n;
if(!sz) return *this;
m_buffer = new T[sz];
if(!m_buffer) {
m_w = 0;m_h = 0;m_owner = false;
return *this; //throw
}
::memcpy(m_buffer,a_from.m_buffer,sz*sizeof(T));
} else {
m_buffer = a_from.m_buffer;
}
return *this;
}
| img& inlib::img< T >::operator= | ( | const img< T > & | a_from | ) | [inline] |
Definition at line 74 of file img.
{
if(m_owner) delete [] m_buffer;
m_buffer = 0;
m_w = a_from.m_w;
m_h = a_from.m_h;
m_n = a_from.m_n;
m_owner = a_from.m_owner;
if(m_owner) {
unsigned int sz = m_w*m_h*m_n;
if(!sz) return *this;
m_buffer = new T[sz];
if(!m_buffer) {
m_w = 0;m_h = 0;m_owner = false;
return *this; //throw
}
::memcpy(m_buffer,a_from.m_buffer,sz*sizeof(T));
} else {
m_buffer = a_from.m_buffer;
}
return *this;
}
| bool inlib::img< T >::operator== | ( | const img< T > & | a_from | ) | const [inline] |
| bool inlib::img< T >::operator== | ( | const img< T > & | a_from | ) | const [inline] |
| bool inlib::img< T >::owner | ( | ) | const [inline] |
| bool inlib::img< T >::owner | ( | ) | const [inline] |
| void inlib::img< T >::set | ( | unsigned int | a_w, |
| unsigned int | a_h, | ||
| T * | a_buffer, | ||
| bool | a_owner | ||
| ) | [inline] |
| void inlib::img< T >::set | ( | unsigned int | a_w, |
| unsigned int | a_h, | ||
| T * | a_buffer, | ||
| bool | a_owner | ||
| ) | [inline] |
| unsigned int inlib::img< T >::size | ( | ) | const [inline] |
| unsigned int inlib::img< T >::size | ( | ) | const [inline] |
| bool inlib::img< T >::to_texture | ( | bool | a_expand, |
| T | a_pixel[], | ||
| img< T > & | a_res | ||
| ) | const [inline] |
Definition at line 356 of file img_old.
{
if(a_res.m_n!=m_n) {
a_res.make_empty();
return false;
}
if(a_expand) {
// if a_w, a_h are not power of two, we expand
// the image and fill new spaces with rgb.
// are a_w, a_h power of two ?
unsigned int rw = 2;
while(true) {if(rw>=m_w) break;rw *=2;}
unsigned int rh = 2;
while(true) {if(rh>=m_h) break;rh *=2;}
if((rw==m_w)&&(rh==m_h)) {
a_res.set(m_w,m_h,m_buffer,false); //WARNING owner=false.
return true;
}
T* rb = new T[rh*rw*m_n];
if(!rb) {
a_res.make_empty();
return false;
}
// initialize with given color :
for(unsigned int j=0;j<rh;j++) { //j=0 -> bottom.
T* pos = rb + j * (rw * m_n);
for(unsigned int i=0;i<rw;i++) {
for(unsigned int n=0;n<m_n;n++) {
*pos = a_pixel[n];pos++; //memcpy ?
}
}
}
// center :
unsigned int col = (rw-m_w)/2;
unsigned int row = (rh-m_h)/2;
// copy original image in a centered part of the new one :
for(unsigned int j=0;j<m_h;j++) {
T* pos = m_buffer + j * (m_w * m_n);
T* rpos = rb + (j+row) * (rw * m_n) + col*m_n;
::memcpy(rpos,pos,m_w*m_n*sizeof(T));
}
a_res.set(rw,rh,rb,true);
return true;
} else {
// closest w,h power of two :
unsigned int sw = 2;
while(true) {if((sw*2)>m_w) break;sw *=2;}
unsigned int sh = 2;
while(true) {if((sh*2)>m_h) break;sh *=2;}
if((sw==m_w)&&(sh==m_h)) {
a_res.set(m_w,m_h,m_buffer,false); //WARNING owner=false.
return true;
}
unsigned int sx = (m_w-sw)/2;
unsigned int sy = (m_h-sh)/2;
return get_part(sx,sy,sw,sh,a_res);
}
}
| bool inlib::img< T >::to_texture | ( | bool | a_expand, |
| T | a_pixel[], | ||
| img< T > & | a_res | ||
| ) | const [inline] |
Definition at line 359 of file img.
{
//NOTE : pixels of the original image are not expanded or shrinked.
if(a_res.m_n!=m_n) {
a_res.make_empty();
return false;
}
if((!m_w)||(!m_h)) {
a_res.make_empty();
return false;
}
// in case (m_w==1)||(m_h==1), expand the pixel
// up to the closest power of 2 ?
if((m_w==1)||(m_h==1)||a_expand) {
// find closest power of two upper than m_w, m_h :
unsigned int rw = 2;
while(true) {if(rw>=m_w) break;rw *=2;}
unsigned int rh = 2;
while(true) {if(rh>=m_h) break;rh *=2;}
if((rw==m_w)&&(rh==m_h)) { //exact match.
a_res.set(m_w,m_h,m_buffer,false); //WARNING owner=false.
return true;
}
// we expand the image and fill new spaces with rgb.
T* rb = new T[rh*rw*m_n];
if(!rb) {
a_res.make_empty();
return false;
}
// initialize with given color :
for(unsigned int j=0;j<rh;j++) { //j=0 -> bottom.
T* pos = rb + j * (rw * m_n);
for(unsigned int i=0;i<rw;i++) {
for(unsigned int n=0;n<m_n;n++) {
*pos = a_pixel[n];pos++; //memcpy ?
}
}
}
// center :
unsigned int col = (rw-m_w)/2;
unsigned int row = (rh-m_h)/2;
// copy original image in a centered part of the new one :
for(unsigned int j=0;j<m_h;j++) {
T* pos = m_buffer + j * (m_w * m_n);
T* rpos = rb + (j+row) * (rw * m_n) + col*m_n;
::memcpy(rpos,pos,m_w*m_n*sizeof(T));
}
a_res.set(rw,rh,rb,true);
return true;
} else {
// then m_w>=2 and m_h>=2
// find closest power of two lower than m_w, m_h :
unsigned int sw = 2;
while(true) {if((sw*2)>m_w) break;sw *=2;}
unsigned int sh = 2;
while(true) {if((sh*2)>m_h) break;sh *=2;}
if((sw==m_w)&&(sh==m_h)) { //exact match.
a_res.set(m_w,m_h,m_buffer,false); //WARNING owner=false.
return true;
}
unsigned int sx = (m_w-sw)/2;
unsigned int sy = (m_h-sh)/2;
return get_part(sx,sy,sw,sh,a_res);
}
}
| void inlib::img< T >::transfer | ( | img< T > & | a_from | ) | [inline] |
| void inlib::img< T >::transfer | ( | img< T > & | a_from | ) | [inline] |
| unsigned int inlib::img< T >::width | ( | ) | const [inline] |
| unsigned int inlib::img< T >::width | ( | ) | const [inline] |
T * inlib::img< T >::m_buffer [protected] |
unsigned int inlib::img< T >::m_h [protected] |
unsigned int inlib::img< T >::m_n [protected] |
bool inlib::img< T >::m_owner [protected] |
unsigned int inlib::img< T >::m_w [protected] |
1.7.5.1