inlib  1.2.0
Public Member Functions | Static Public Member Functions | Protected Attributes
inlib::img< T > Class Template Reference

List of all members.

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)
imgoperator= (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)
imgoperator= (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

Detailed Description

template<class T>
class inlib::img< T >

Definition at line 21 of file img.


Constructor & Destructor Documentation

template<class T>
inlib::img< T >::img ( unsigned int  a_n) [inline]

Definition at line 27 of file img.

  :m_w(0),m_h(0),m_n(a_n)
  ,m_buffer(0)
  ,m_owner(false)
  {
#ifdef INLIB_MEM
    mem::increment(s_class().c_str());
#endif
  }
template<class T>
inlib::img< T >::img ( unsigned int  a_w,
unsigned int  a_h,
unsigned int  a_n,
T *  a_buffer,
bool  a_owner 
) [inline]

Definition at line 36 of file img.

  :m_w(a_w),m_h(a_h),m_n(a_n)
  ,m_buffer(a_buffer)
  ,m_owner(a_owner)
  {
#ifdef INLIB_MEM
    mem::increment(s_class().c_str());
#endif
  }
template<class T>
virtual inlib::img< T >::~img ( ) [inline, virtual]

Definition at line 46 of file img.

                 {
    if(m_owner) delete [] m_buffer;
#ifdef INLIB_MEM
    mem::decrement(s_class().c_str());
#endif
  }
template<class T>
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;
    }
  }
template<class T>
inlib::img< T >::img ( unsigned int  a_n) [inline]

Definition at line 26 of file img_old.

  :m_w(0),m_h(0),m_n(a_n)
  ,m_buffer(0)
  ,m_owner(false)
  {
#ifdef INLIB_MEM
    mem::increment(s_class().c_str());
#endif
  }
template<class T>
inlib::img< T >::img ( unsigned int  a_w,
unsigned int  a_h,
unsigned int  a_n,
T *  a_buffer,
bool  a_owner 
) [inline]

Definition at line 35 of file img_old.

  :m_w(a_w),m_h(a_h),m_n(a_n)
  ,m_buffer(a_buffer)
  ,m_owner(a_owner)
  {
#ifdef INLIB_MEM
    mem::increment(s_class().c_str());
#endif
  }
template<class T>
virtual inlib::img< T >::~img ( ) [inline, virtual]

Definition at line 45 of file img_old.

                 {
    if(m_owner) delete [] m_buffer;
#ifdef INLIB_MEM
    mem::decrement(s_class().c_str());
#endif
  }
template<class T>
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;
    }
  }

Member Function Documentation

template<class T>
bool inlib::img< T >::allocate ( unsigned int  a_w,
unsigned int  a_h 
) [inline]

Definition at line 148 of file img_old.

                                                  {
    if(m_owner) delete [] m_buffer;
    m_buffer = 0;
    unsigned int sz = a_w*a_h*m_n;
    if(!sz) {
      m_w = 0;m_h = 0;m_owner = false;
      return false;
    }
    m_w = a_w;
    m_h = a_h;
    m_buffer = new T[sz];
    if(!m_buffer) {
      m_w = 0;m_h = 0;m_owner = false;
      return false;
    }
    m_owner = true;
    return true;
  }
template<class T>
bool inlib::img< T >::allocate ( unsigned int  a_w,
unsigned int  a_h 
) [inline]

Definition at line 149 of file img.

                                                  {
    if(m_owner) delete [] m_buffer;
    m_buffer = 0;
    unsigned int sz = a_w*a_h*m_n;
    if(!sz) {
      m_w = 0;m_h = 0;m_owner = false;
      return false;
    }
    m_w = a_w;
    m_h = a_h;
    m_buffer = new T[sz];
    if(!m_buffer) {
      m_w = 0;m_h = 0;m_owner = false;
      return false;
    }
    m_owner = true;
    return true;
  }
template<class T>
unsigned int inlib::img< T >::bpp ( ) const [inline]

Definition at line 190 of file img_old.

{return m_n;}
template<class T>
unsigned int inlib::img< T >::bpp ( ) const [inline]

Definition at line 191 of file img.

{return m_n;}
template<class T>
T* inlib::img< T >::buffer ( ) const [inline]

Definition at line 191 of file img_old.

{return m_buffer;}
template<class T>
T* inlib::img< T >::buffer ( ) const [inline]

Definition at line 192 of file img.

{return m_buffer;}
template<class T>
unsigned int inlib::img< T >::bytes_per_pixel ( ) const [inline]

Definition at line 189 of file img_old.

{return m_n;}
template<class T>
unsigned int inlib::img< T >::bytes_per_pixel ( ) const [inline]

Definition at line 190 of file img.

{return m_n;}
template<class T>
void inlib::img< T >::clear ( ) [inline]

Definition at line 112 of file img_old.

               {
    if(m_owner) delete [] m_buffer;
    m_w = 0;
    m_h = 0;
    m_buffer = 0;
    m_owner = false;
  }
template<class T>
void inlib::img< T >::clear ( ) [inline]

Definition at line 113 of file img.

               {
    if(m_owner) delete [] m_buffer;
    m_w = 0;
    m_h = 0;
    m_buffer = 0;
    m_owner = false;
  }
template<class T>
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,
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;
  }
template<class T>
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,
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;
  }
template<class T>
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;
  }
template<class T>
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;
  }
template<class T>
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;
  }
template<class T>
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;
  }
template<class T>
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;
  }
template<class T>
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;
  }
template<class T>
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;
  }
template<class T>
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;
  }
template<class T>
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;
  }
template<class T>
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;
  }
template<class T>
unsigned int inlib::img< T >::height ( ) const [inline]

Definition at line 188 of file img_old.

{return m_h;}
template<class T>
unsigned int inlib::img< T >::height ( ) const [inline]

Definition at line 189 of file img.

{return m_h;}
template<class T>
void inlib::img< T >::make_empty ( ) [inline]

Definition at line 166 of file img_old.

                    {
    if(m_owner) delete [] m_buffer;
    m_w = 0;
    m_h = 0;
    //don't touch m_n
    m_buffer = 0;
    m_owner = false;
  }
template<class T>
void inlib::img< T >::make_empty ( ) [inline]

Definition at line 167 of file img.

                    {
    if(m_owner) delete [] m_buffer;
    m_w = 0;
    m_h = 0;
    //don't touch m_n
    m_buffer = 0;
    m_owner = false;
  }
template<class T>
bool inlib::img< T >::operator!= ( const img< T > &  a_from) const [inline]

Definition at line 96 of file img_old.

{return !operator==(a_from);}
template<class T>
bool inlib::img< T >::operator!= ( const img< T > &  a_from) const [inline]

Definition at line 97 of file img.

{return !operator==(a_from);}
template<class T>
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;
  }
template<class T>
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;
  }
template<class T>
bool inlib::img< T >::operator== ( const img< T > &  a_from) const [inline]

Definition at line 95 of file img_old.

{return equal(a_from);}
template<class T>
bool inlib::img< T >::operator== ( const img< T > &  a_from) const [inline]

Definition at line 96 of file img.

{return equal(a_from);}
template<class T>
bool inlib::img< T >::owner ( ) const [inline]

Definition at line 192 of file img_old.

{return m_owner;}
template<class T>
bool inlib::img< T >::owner ( ) const [inline]

Definition at line 193 of file img.

{return m_owner;}
template<class T>
void inlib::img< T >::set ( unsigned int  a_w,
unsigned int  a_h,
T *  a_buffer,
bool  a_owner 
) [inline]

Definition at line 119 of file img_old.

                                            {
    if(m_owner) delete [] m_buffer;
    m_w = a_w;
    m_h = a_h;
    //don't touch m_n
    m_buffer = a_buffer;
    m_owner = a_owner;
  }
template<class T>
void inlib::img< T >::set ( unsigned int  a_w,
unsigned int  a_h,
T *  a_buffer,
bool  a_owner 
) [inline]

Definition at line 120 of file img.

                                            {
    if(m_owner) delete [] m_buffer;
    m_w = a_w;
    m_h = a_h;
    //don't touch m_n
    m_buffer = a_buffer;
    m_owner = a_owner;
  }
template<class T>
unsigned int inlib::img< T >::size ( ) const [inline]

Definition at line 193 of file img_old.

{return m_w*m_h*m_n*sizeof(T);} //bytes.
template<class T>
unsigned int inlib::img< T >::size ( ) const [inline]

Definition at line 194 of file img.

{return m_w*m_h*m_n*sizeof(T);} //bytes.
template<class T>
bool inlib::img< T >::to_texture ( bool  a_expand,
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);
    }
  
  }
template<class T>
bool inlib::img< T >::to_texture ( bool  a_expand,
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);
    }
  
  }
template<class T>
void inlib::img< T >::transfer ( img< T > &  a_from) [inline]

Definition at line 98 of file img_old.

                             {
    if(m_owner) delete [] m_buffer;
    m_w = a_from.m_w;
    m_h = a_from.m_h;
    //don't touch m_n
    m_buffer = a_from.m_buffer;
    m_owner = a_from.m_owner;
    // empty a_from :
    a_from.m_w = 0;
    a_from.m_h = 0;
    a_from.m_buffer = 0;
    a_from.m_owner = false;
  }
template<class T>
void inlib::img< T >::transfer ( img< T > &  a_from) [inline]

Definition at line 99 of file img.

                             {
    if(m_owner) delete [] m_buffer;
    m_w = a_from.m_w;
    m_h = a_from.m_h;
    //don't touch m_n
    m_buffer = a_from.m_buffer;
    m_owner = a_from.m_owner;
    // empty a_from :
    a_from.m_w = 0;
    a_from.m_h = 0;
    a_from.m_buffer = 0;
    a_from.m_owner = false;
  }
template<class T>
unsigned int inlib::img< T >::width ( ) const [inline]

Definition at line 187 of file img_old.

{return m_w;}
template<class T>
unsigned int inlib::img< T >::width ( ) const [inline]

Definition at line 188 of file img.

{return m_w;}

Member Data Documentation

template<class T>
T * inlib::img< T >::m_buffer [protected]

Definition at line 860 of file img.

template<class T>
unsigned int inlib::img< T >::m_h [protected]

Definition at line 858 of file img.

template<class T>
unsigned int inlib::img< T >::m_n [protected]

Definition at line 859 of file img.

template<class T>
bool inlib::img< T >::m_owner [protected]

Definition at line 861 of file img.

template<class T>
unsigned int inlib::img< T >::m_w [protected]

Definition at line 857 of file img.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines