bitplane add
This commit is contained in:
		
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							@ -96,6 +96,9 @@ namespace ams
 | 
			
		||||
        int Nx,Ny;
 | 
			
		||||
        uint8_t *data; //[x+width*y]
 | 
			
		||||
 | 
			
		||||
        int &width; //aliases for Nx,Ny
 | 
			
		||||
        int &height;
 | 
			
		||||
 | 
			
		||||
        amsbitplane();
 | 
			
		||||
        ~amsbitplane();
 | 
			
		||||
        amsbitplane(const amsbitplane& other);
 | 
			
		||||
@ -104,11 +107,11 @@ namespace ams
 | 
			
		||||
        amsbitplane& operator=(amsbitplane&& other) noexcept;
 | 
			
		||||
 | 
			
		||||
        int resize(int _Nx, int _Ny);
 | 
			
		||||
        void transpose();
 | 
			
		||||
        void rotcw();
 | 
			
		||||
        void rotccw();
 | 
			
		||||
        void flipx();
 | 
			
		||||
        void flipy();
 | 
			
		||||
        amsbitplane transpose();
 | 
			
		||||
        amsbitplane rotcw();
 | 
			
		||||
        amsbitplane rotccw();
 | 
			
		||||
        amsbitplane flipx();
 | 
			
		||||
        amsbitplane flipy();
 | 
			
		||||
        
 | 
			
		||||
        uint8_t get(int I, int J) const;
 | 
			
		||||
        int set(int I, int J, uint8_t val);
 | 
			
		||||
@ -123,13 +126,11 @@ namespace ams
 | 
			
		||||
        void clear();
 | 
			
		||||
 | 
			
		||||
        //rescales the image with linear interpolation
 | 
			
		||||
        int rescale(int nnx, int nny);
 | 
			
		||||
        int rescale(int _Nx, int _Ny);
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    //Tests//
 | 
			
		||||
 | 
			
		||||
    void amscppimglib_test1();
 | 
			
		||||
 | 
			
		||||
}; //end namespace ams
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -80,6 +80,30 @@ void amsimage_region_set(
 | 
			
		||||
    amspixel val
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
void amsimage_plane_copy(
 | 
			
		||||
    uint8_t *datato,
 | 
			
		||||
    int Ipto,
 | 
			
		||||
    int Npto,
 | 
			
		||||
    int Nxto,
 | 
			
		||||
    int Nyto,
 | 
			
		||||
    const uint8_t *datafrom,
 | 
			
		||||
    int Ipfrom,
 | 
			
		||||
    int Npfrom,
 | 
			
		||||
    int Nxfrom,
 | 
			
		||||
    int Nyfrom,
 | 
			
		||||
    int offsetx,
 | 
			
		||||
    int offsety
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
void amsimage_planeregion_set(
 | 
			
		||||
    uint8_t *data,
 | 
			
		||||
    int Np, int Nx, int Ny,
 | 
			
		||||
    int Ip,
 | 
			
		||||
    int x0, int y0,
 | 
			
		||||
    int x1, int y1,
 | 
			
		||||
    uint8_t val
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,8 +1,145 @@
 | 
			
		||||
#include <amscppimglib4/amscppimglib4.hpp>
 | 
			
		||||
#include <amscppimglib4/amscppimglib4_intlutil.hpp>
 | 
			
		||||
 | 
			
		||||
namespace ams
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    amsbitplane::amsbitplane() : Nx(0), Ny(0), data(NULL), width(Nx), height(Ny)
 | 
			
		||||
    {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    amsbitplane::~amsbitplane()
 | 
			
		||||
    {
 | 
			
		||||
        if(data!=NULL) {delete[] data; data=NULL;}
 | 
			
		||||
        Nx = 0;
 | 
			
		||||
        Ny = 0;
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    amsbitplane::amsbitplane(const amsbitplane& other) : Nx(0), Ny(0), data(NULL), width(Nx), height(Ny)
 | 
			
		||||
    {
 | 
			
		||||
        int res;
 | 
			
		||||
        if(this!=&other)
 | 
			
		||||
        {
 | 
			
		||||
            res = this->resize(Nx,Ny);
 | 
			
		||||
            if(res==amsimage_success)
 | 
			
		||||
            {
 | 
			
		||||
                imglib4::amsimage_plane_copy(
 | 
			
		||||
                    this->data, 0, 1, Nx, Ny,
 | 
			
		||||
                    other.data, 0, 1, other.Nx, other.Ny,
 | 
			
		||||
                    0,0
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    amsbitplane::amsbitplane(amsbitplane&& other) noexcept : Nx(0), Ny(0), data(NULL), width(Nx), height(Ny)
 | 
			
		||||
    {
 | 
			
		||||
        if(this!=&other)
 | 
			
		||||
        {
 | 
			
		||||
            this->Nx = other.Nx;
 | 
			
		||||
            this->Ny = other.Ny;
 | 
			
		||||
            this->data = other.data;
 | 
			
		||||
 | 
			
		||||
            other.Nx = 0;
 | 
			
		||||
            other.Ny = 0;
 | 
			
		||||
            other.data = NULL;
 | 
			
		||||
        }
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    amsbitplane& amsbitplane::operator=(const amsbitplane& other)
 | 
			
		||||
    {
 | 
			
		||||
        int res;
 | 
			
		||||
        if(this!=&other)
 | 
			
		||||
        {
 | 
			
		||||
            res = this->resize(Nx,Ny);
 | 
			
		||||
            if(res==amsimage_success)
 | 
			
		||||
            {
 | 
			
		||||
                imglib4::amsimage_plane_copy(
 | 
			
		||||
                    this->data, 0, 1, Nx, Ny,
 | 
			
		||||
                    other.data, 0, 1, other.Nx, other.Ny,
 | 
			
		||||
                    0,0
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    amsbitplane& amsbitplane::operator=(amsbitplane&& other) noexcept
 | 
			
		||||
    {
 | 
			
		||||
        if(this!=&other)
 | 
			
		||||
        {
 | 
			
		||||
            if(this->data!=NULL) {delete[] this->data; this->data=NULL;}
 | 
			
		||||
            this->Nx = 0; this->Ny = 0;
 | 
			
		||||
 | 
			
		||||
            this->Nx = other.Nx;
 | 
			
		||||
            this->Ny = other.Ny;
 | 
			
		||||
            this->data = other.data;
 | 
			
		||||
 | 
			
		||||
            other.Nx = 0;
 | 
			
		||||
            other.Ny = 0;
 | 
			
		||||
            other.data = NULL;
 | 
			
		||||
        }
 | 
			
		||||
        return *this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int amsbitplane::resize(int _Nx, int _Ny)
 | 
			
		||||
    {
 | 
			
		||||
        int ret = amsimage_success;
 | 
			
		||||
        
 | 
			
		||||
        uint8_t *newdata = NULL;
 | 
			
		||||
 | 
			
		||||
        _Nx = (_Nx<0) ? 0 : _Nx;
 | 
			
		||||
        _Ny = (_Ny<0) ? 0 : _Ny;
 | 
			
		||||
 | 
			
		||||
        if(_Nx == Nx && _Ny == Ny)
 | 
			
		||||
        {
 | 
			
		||||
            return ret; //no resize necessary
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(_Nx==0 || _Ny == 0)
 | 
			
		||||
        {
 | 
			
		||||
            //zero size image
 | 
			
		||||
            if(data!=NULL) {delete[] data; data=NULL;}
 | 
			
		||||
            Nx = 0;
 | 
			
		||||
            Ny = 0;
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        newdata = new(std::nothrow) uint8_t[_Nx*_Ny];
 | 
			
		||||
        if(newdata==NULL)
 | 
			
		||||
        {
 | 
			
		||||
            ret = amsimage_failure;
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        imglib4::amsimage_planeregion_set(
 | 
			
		||||
            newdata,
 | 
			
		||||
            1,_Nx,_Ny,0,
 | 
			
		||||
            0,0,_Nx,_Ny,
 | 
			
		||||
            0
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        if(data!=NULL)
 | 
			
		||||
        {
 | 
			
		||||
            imglib4::amsimage_plane_copy(
 | 
			
		||||
                newdata,0,1,_Nx,_Ny,
 | 
			
		||||
                data,0,1,Nx,Ny,
 | 
			
		||||
                0,0
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(data!=NULL) {delete[] data; data=NULL;}
 | 
			
		||||
        data = newdata;
 | 
			
		||||
        Nx = _Nx;
 | 
			
		||||
        Ny = _Ny;
 | 
			
		||||
 | 
			
		||||
        return ret;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
@ -32,7 +32,7 @@ namespace imglib4
 | 
			
		||||
 | 
			
		||||
        N = dx*dy;
 | 
			
		||||
 | 
			
		||||
        Is = N/nthreads;
 | 
			
		||||
        Is = N/nthreads; Is = (Is<1) ? 1 : N;
 | 
			
		||||
        I0 = (threadnum)*Is;
 | 
			
		||||
        I1 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
 | 
			
		||||
 | 
			
		||||
@ -116,7 +116,7 @@ namespace imglib4
 | 
			
		||||
        dy = (dy<0) ? 0 : dy;
 | 
			
		||||
        N = dx*dy;
 | 
			
		||||
 | 
			
		||||
        Is = N/nthreads;
 | 
			
		||||
        Is = N/nthreads; Is = (Is<1) ? 1 : N;
 | 
			
		||||
        I0 = (threadnum)*Is;
 | 
			
		||||
        I1 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
 | 
			
		||||
 | 
			
		||||
@ -163,7 +163,160 @@ namespace imglib4
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void amsimage_plane_copy_tf(
 | 
			
		||||
        int threadnum,
 | 
			
		||||
        int nthreads,
 | 
			
		||||
        uint8_t *datato,
 | 
			
		||||
        int Ipto,
 | 
			
		||||
        int Npto,
 | 
			
		||||
        int Nxto,
 | 
			
		||||
        int Nyto,
 | 
			
		||||
        const uint8_t *datafrom,
 | 
			
		||||
        int Ipfrom,
 | 
			
		||||
        int Npfrom,
 | 
			
		||||
        int Nxfrom,
 | 
			
		||||
        int Nyfrom,
 | 
			
		||||
        int offsetx,
 | 
			
		||||
        int offsety
 | 
			
		||||
    )
 | 
			
		||||
    {
 | 
			
		||||
        int64_t I,I0,I1,Is,N,Ix,Iy,Ia,Ib;
 | 
			
		||||
        int dx,dy;
 | 
			
		||||
 | 
			
		||||
        dx = Nxfrom;
 | 
			
		||||
        dx = (dx>(Nxto-offsetx)) ? (Nxto-offsetx) : dx;
 | 
			
		||||
        dx = (dx<0) ? 0 : dx;
 | 
			
		||||
 | 
			
		||||
        dy = Nyfrom;
 | 
			
		||||
        dy = (dy>(Nyto-offsety)) ? (Nyto-offsety) : dy;
 | 
			
		||||
        dy = (dy<0) ? 0 : dy;
 | 
			
		||||
 | 
			
		||||
        N = dx*dy;
 | 
			
		||||
 | 
			
		||||
        Is = N/nthreads; Is = (Is<1) ? 1 : N;
 | 
			
		||||
        I0 = (threadnum)*Is;
 | 
			
		||||
        I1 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
 | 
			
		||||
 | 
			
		||||
        for(I=I0;I<I1;I++)
 | 
			
		||||
        {
 | 
			
		||||
            Ix = I%dx;
 | 
			
		||||
            Iy = I/dx;
 | 
			
		||||
 | 
			
		||||
            Ia = Ipto + Npto*((Ix+offsetx) + Nxto*(Iy+offsety));
 | 
			
		||||
            Ib = Ipfrom + Npfrom*(Ix + Nxfrom*Iy);
 | 
			
		||||
            
 | 
			
		||||
            datato[Ia] = datafrom[Ib];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return;
 | 
			
		||||
    }      
 | 
			
		||||
 | 
			
		||||
    void amsimage_plane_copy(
 | 
			
		||||
        uint8_t *datato,
 | 
			
		||||
        int Ipto,
 | 
			
		||||
        int Npto,
 | 
			
		||||
        int Nxto,
 | 
			
		||||
        int Nyto,
 | 
			
		||||
        const uint8_t *datafrom,
 | 
			
		||||
        int Ipfrom,
 | 
			
		||||
        int Npfrom,
 | 
			
		||||
        int Nxfrom,
 | 
			
		||||
        int Nyfrom,
 | 
			
		||||
        int offsetx,
 | 
			
		||||
        int offsety
 | 
			
		||||
    )
 | 
			
		||||
    {
 | 
			
		||||
        int dx,dy;
 | 
			
		||||
        int64_t N;
 | 
			
		||||
 | 
			
		||||
        if(datato==NULL) return;
 | 
			
		||||
        if(datafrom==NULL) return;
 | 
			
		||||
 | 
			
		||||
        dx = Nxfrom;
 | 
			
		||||
        dx = (dx>(Nxto-offsetx)) ? (Nxto-offsetx) : dx;
 | 
			
		||||
        dx = (dx<0) ? 0 : dx;
 | 
			
		||||
 | 
			
		||||
        dy = Nyfrom;
 | 
			
		||||
        dy = (dy>(Nyto-offsety)) ? (Nyto-offsety) : dy;
 | 
			
		||||
        dy = (dy<0) ? 0 : dy;
 | 
			
		||||
 | 
			
		||||
        N = dx*dy;
 | 
			
		||||
 | 
			
		||||
        threaded_execute(
 | 
			
		||||
            amsimage_plane_copy_tf,
 | 
			
		||||
            N,
 | 
			
		||||
            datato,
 | 
			
		||||
            Ipto,Npto,Nxto,Nyto,
 | 
			
		||||
            datafrom,
 | 
			
		||||
            Ipfrom,Npfrom,Nxfrom,Nyfrom,
 | 
			
		||||
            offsetx,offsety
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void amsimage_planeregion_set_tf(
 | 
			
		||||
        int threadnum,
 | 
			
		||||
        int nthreads,
 | 
			
		||||
        uint8_t *data,
 | 
			
		||||
        int Np, int Nx, int Ny,
 | 
			
		||||
        int Ip,
 | 
			
		||||
        int x0, int y0,
 | 
			
		||||
        int x1, int y1,
 | 
			
		||||
        uint8_t val
 | 
			
		||||
    )
 | 
			
		||||
    {
 | 
			
		||||
        int64_t I,I0,I1,Is,N,Ix,Iy;
 | 
			
		||||
        int dx,dy;
 | 
			
		||||
 | 
			
		||||
        dx = (x1-x0); dy = (y1-y0);
 | 
			
		||||
        dx = (dx<0) ? 0 : dx;
 | 
			
		||||
        dy = (dy<0) ? 0 : dy;
 | 
			
		||||
        N = dx*dy;
 | 
			
		||||
 | 
			
		||||
        Is = N/nthreads; Is = (Is<1) ? 1 : N;
 | 
			
		||||
        I0 = (threadnum)*Is;
 | 
			
		||||
        I1 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
 | 
			
		||||
 | 
			
		||||
        for(I=I0;I<I1;I++)
 | 
			
		||||
        {
 | 
			
		||||
            Ix = I%dx;
 | 
			
		||||
            Iy = I/dx;
 | 
			
		||||
 | 
			
		||||
            data[Ip + Np*(Ix+x0) + Np*Nx*(Iy+y0)] = val;
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void amsimage_planeregion_set(
 | 
			
		||||
        uint8_t *data,
 | 
			
		||||
        int Np, int Nx, int Ny,
 | 
			
		||||
        int Ip,
 | 
			
		||||
        int x0, int y0,
 | 
			
		||||
        int x1, int y1,
 | 
			
		||||
        uint8_t val
 | 
			
		||||
    )
 | 
			
		||||
    {
 | 
			
		||||
        int dx,dy;
 | 
			
		||||
        int64_t N;
 | 
			
		||||
 | 
			
		||||
        if(data==NULL) return;
 | 
			
		||||
 | 
			
		||||
        dx = (x1-x0); dy = (y1-y0);
 | 
			
		||||
        dx = (dx<0) ? 0 : dx;
 | 
			
		||||
        dy = (dy<0) ? 0 : dy;
 | 
			
		||||
        N = dx*dy;
 | 
			
		||||
 | 
			
		||||
        threaded_execute(
 | 
			
		||||
            amsimage_planeregion_set_tf,
 | 
			
		||||
            N,
 | 
			
		||||
            data, Np,Nx,Ny, Ip, 
 | 
			
		||||
            x0, y0, x1, y1, 
 | 
			
		||||
            val
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}; //end namespace imglib4
 | 
			
		||||
}; //end namespace ams
 | 
			
		||||
@ -7,7 +7,7 @@ int main(int argc, char* argv[])
 | 
			
		||||
    int ret = 0;
 | 
			
		||||
 | 
			
		||||
    //amscppimglib4_test1();
 | 
			
		||||
    amscppimglib4_test2();
 | 
			
		||||
    //amscppimglib4_test2();
 | 
			
		||||
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user