diff --git a/build_linux64/libamscppimglib4.linux64.a b/build_linux64/libamscppimglib4.linux64.a index c18cf65..566fdb7 100644 Binary files a/build_linux64/libamscppimglib4.linux64.a and b/build_linux64/libamscppimglib4.linux64.a differ diff --git a/build_linux64/objstore/amscppimglib4_amsbitplane.o b/build_linux64/objstore/amscppimglib4_amsbitplane.o index c184851..3fd3789 100644 Binary files a/build_linux64/objstore/amscppimglib4_amsbitplane.o and b/build_linux64/objstore/amscppimglib4_amsbitplane.o differ diff --git a/build_linux64/objstore/amscppimglib4_intlutil.o b/build_linux64/objstore/amscppimglib4_intlutil.o index 6f9dba3..18a2ccb 100644 Binary files a/build_linux64/objstore/amscppimglib4_intlutil.o and b/build_linux64/objstore/amscppimglib4_intlutil.o differ diff --git a/build_linux64/tests b/build_linux64/tests index 61411a9..f6c0add 100644 Binary files a/build_linux64/tests and b/build_linux64/tests differ diff --git a/include/amscppimglib4/amscppimglib4.hpp b/include/amscppimglib4/amscppimglib4.hpp index 939eab5..6e7702a 100644 --- a/include/amscppimglib4/amscppimglib4.hpp +++ b/include/amscppimglib4/amscppimglib4.hpp @@ -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 diff --git a/include/amscppimglib4/amscppimglib4_intlutil.hpp b/include/amscppimglib4/amscppimglib4_intlutil.hpp index 747700b..535142d 100644 --- a/include/amscppimglib4/amscppimglib4_intlutil.hpp +++ b/include/amscppimglib4/amscppimglib4_intlutil.hpp @@ -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 +); + diff --git a/src/amscppimglib4/amscppimglib4_amsbitplane.cpp b/src/amscppimglib4/amscppimglib4_amsbitplane.cpp index 616ffb6..c4c1ab8 100644 --- a/src/amscppimglib4/amscppimglib4_amsbitplane.cpp +++ b/src/amscppimglib4/amscppimglib4_amsbitplane.cpp @@ -1,8 +1,145 @@ #include +#include 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; + } + }; \ No newline at end of file diff --git a/src/amscppimglib4/amscppimglib4_intlutil.cpp b/src/amscppimglib4/amscppimglib4_intlutil.cpp index dbbe48e..ec37cb9 100644 --- a/src/amscppimglib4/amscppimglib4_intlutil.cpp +++ b/src/amscppimglib4/amscppimglib4_intlutil.cpp @@ -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(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(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