diff --git a/amscppimglib4.code-workspace b/amscppimglib4.code-workspace index 362d7c2..161631a 100644 --- a/amscppimglib4.code-workspace +++ b/amscppimglib4.code-workspace @@ -2,6 +2,12 @@ "folders": [ { "path": "." + }, + { + "path": "../../sourceprojs23/amsimglib3" + }, + { + "path": "../amscimglib4" } ] } \ No newline at end of file diff --git a/build/__pycache__/amsbuildlib4.cpython-312.pyc b/build/__pycache__/amsbuildlib4.cpython-312.pyc new file mode 100644 index 0000000..de5d155 Binary files /dev/null and b/build/__pycache__/amsbuildlib4.cpython-312.pyc differ diff --git a/build/make.linux64.lib.py b/build/make.linux64.lib.py index 20531d0..f043572 100644 --- a/build/make.linux64.lib.py +++ b/build/make.linux64.lib.py @@ -14,12 +14,12 @@ depdir = "./dependencies/linux64" #local pre-compiled dependency libraries and t installdir = "../../linux64" #directory to install to when finished builddir = "./build_linux64" -doinstall = False #copies the build_output to the install dir when finished +doinstall = True #copies the build_output to the install dir when finished cc = "g++" #compiler cflags = "-fPIC" -libraries = "-l{}".format(libname) +libraries = "-l{} -lamscimglib4.linux64".format(libname) libdirs = "-L{} -L{}/lib -L{}/lib".format(builddir,commondir,depdir) -linkerflags = "-static -static-libgcc -Wl,-rpath=." +linkerflags = "-static-libgcc -Wl,-rpath=." srcexts = [".c",".cpp"] binsrc = ["main.c","main.cpp"] #ignore these files when compiling the static library @@ -35,6 +35,16 @@ kwargs["recurse"] = True kwargs["objstore"] = "{}/objstore".format(builddir) kwargs["searchincdirs"] = "./include" +#Collect dependencies +shutil.copy( + "{}/lib/libamscimglib4.linux64.a".format(installdir), + '{}/'.format(builddir,libname) +) +shutil.copy( + "{}/lib/libamscimglib4.linux64.so".format(installdir), + '{}/'.format(builddir,libname) +) + #Find all source files, except the main project files srcfiles = flist('./src',exts = srcexts, recurse=True) srcfiles = except_contains(srcfiles,binsrc) @@ -48,10 +58,11 @@ objlist = flist(kwargs['objstore'],exts='.o',recurse=True) ar_list(objlist,'{}/lib{}.a'.format(builddir,libname)) if(doinstall): - #Copy a binary to the common bin folder - #Push any libraries to the common lib folder - shutil.copy('{}/lib/lib{}.a'.format(builddir,libname),commondir) + shutil.copy( + '{}/lib{}.a'.format(builddir,libname), + "{}/lib".format(installdir) + ) #Copy include files to the common include folder - copytree('./include/',commondir+'/include/',dirs_exist_ok=True) + copytree('./include/',installdir+'/include/',dirs_exist_ok=True) diff --git a/build/make.linux64.test.py b/build/make.linux64.test.py index 16d01e7..3a6c070 100644 --- a/build/make.linux64.test.py +++ b/build/make.linux64.test.py @@ -14,12 +14,12 @@ depdir = "./dependencies/linux64" #local pre-compiled dependency libraries and t installdir = "../../linux64" #directory to install to when finished builddir = "./build_linux64" -doinstall = False #copies the build_output to the install dir when finished +doinstall = True #copies the build_output to the install dir when finished cc = "g++" #compiler cflags = "-fPIC" -libraries = "-l{}".format(libname) +libraries = "-l{} -lamscimglib4.linux64".format(libname) libdirs = "-L{} -L{}/lib -L{}/lib".format(builddir,commondir,depdir) -linkerflags = "-static -static-libgcc -Wl,-rpath=." +linkerflags = "-static-libgcc -Wl,-rpath=." srcexts = [".c",".cpp"] binsrc = ["main.c","main.cpp"] #ignore these files when compiling the static library diff --git a/build/make.mingw64.lib.py b/build/make.mingw64.lib.py index ae64c5b..ba72a81 100644 --- a/build/make.mingw64.lib.py +++ b/build/make.mingw64.lib.py @@ -14,12 +14,12 @@ depdir = "./dependencies/winx64" #local pre-compiled dependency libraries and th installdir = "../../winx64" #directory to install to when finished builddir = "./build_mingw64" -doinstall = False #copies the build_output to the install dir when finished +doinstall = True #copies the build_output to the install dir when finished cc = "x86_64-w64-mingw32-g++" #compiler cflags = "-fPIC -O3" -libraries = "-l{}".format(libname) +libraries = "-l{} -lamscimglib4.winx64".format(libname) libdirs = "-L{} -L{}/lib -L{}/lib".format(builddir,commondir,depdir) -linkerflags = "-static -static-libgcc -Wl,-rpath=." +linkerflags = "-static-libgcc -static-libstdc++ -Wl,-rpath=." srcexts = [".c",".cpp"] binsrc = ["main.c","main.cpp"] #ignore these files when compiling the static library @@ -36,6 +36,16 @@ kwargs["recurse"] = True kwargs["objstore"] = "{}/objstore".format(builddir) kwargs["searchincdirs"] = "./include" +#Collect dependencies +shutil.copy( + "{}/lib/libamscimglib4.winx64.a".format(installdir), + '{}/'.format(builddir,libname) +) +shutil.copy( + "{}/lib/libamscimglib4.winx64.dll".format(installdir), + '{}/'.format(builddir,libname) +) + #Find all source files, except the main project files srcfiles = flist('./src',exts = srcexts, recurse=True) srcfiles = except_contains(srcfiles,binsrc) @@ -49,10 +59,11 @@ objlist = flist(kwargs['objstore'],exts='.o',recurse=True) ar_list(objlist,'{}/lib{}.a'.format(builddir,libname)) if(doinstall): - #Copy a binary to the common bin folder - #Push any libraries to the common lib folder - shutil.copy('{}/lib/lib{}.a'.format(builddir,libname),commondir) + shutil.copy( + '{}/lib{}.a'.format(builddir,libname), + "{}/lib".format(installdir) + ) #Copy include files to the common include folder - copytree('./include/',commondir+'/include/',dirs_exist_ok=True) + copytree('./include/',installdir+'/include/',dirs_exist_ok=True) diff --git a/build/make.mingw64.test.py b/build/make.mingw64.test.py index 5fd2155..0ae463e 100644 --- a/build/make.mingw64.test.py +++ b/build/make.mingw64.test.py @@ -14,12 +14,12 @@ depdir = "./dependencies/winx64" #local pre-compiled dependency libraries and th installdir = "../../winx64" #directory to install to when finished builddir = "./build_mingw64" -doinstall = False #copies the build_output to the install dir when finished +doinstall = True #copies the build_output to the install dir when finished cc = "x86_64-w64-mingw32-g++" #compiler cflags = "-fPIC -O3" -libraries = "-l{}".format(libname) +libraries = "-l{} -lamscimglib4.winx64".format(libname) libdirs = "-L{} -L{}/lib -L{}/lib".format(builddir,commondir,depdir) -linkerflags = "-static -static-libgcc -Wl,-rpath=." +linkerflags = "-static-libgcc -static-libstdc++ -Wl,-rpath=." srcexts = [".c",".cpp"] binsrc = ["main.c","main.cpp"] #ignore these files when compiling the static library diff --git a/build/make.msvc64.lib.py b/build/make.msvc64.lib.py index 54b2947..41a4c35 100644 --- a/build/make.msvc64.lib.py +++ b/build/make.msvc64.lib.py @@ -14,10 +14,10 @@ depdir = "./dependencies/winx64" #local pre-compiled dependency libraries and th installdir = "../../winx64" #directory to install to when finished builddir = "./build_msvc64" -doinstall = False #copies the build_output to the install dir when finished +doinstall = True #copies the build_output to the install dir when finished cc = "cl" #compiler cflags = "/O2" -libraries = "lib{}.lib".format(libname) +libraries = "lib{}.lib libamscimglib4.winx64.a".format(libname) libdirs = "/LIBPATH:{} /LIBPATH:{}/lib /LIBPATH:{}/lib".format(builddir,commondir,depdir) linkerflags = "-static -static-libgcc -Wl,-rpath=." srcexts = [".c",".cpp"] @@ -51,10 +51,11 @@ objlist = flist(kwargs['objstore'],exts='.obj',recurse=True) msvc_lib_list(objlist,'{}/lib{}.lib'.format(builddir,libname)) if(doinstall): - #Copy a binary to the common bin folder - #Push any libraries to the common lib folder - shutil.copy('{}/lib/lib{}.lib'.format(builddir,libname),commondir) + shutil.copy( + '{}/lib{}.lib'.format(builddir,libname), + "{}/lib".format(installdir) + ) #Copy include files to the common include folder - copytree('./include/',commondir+'/include/',dirs_exist_ok=True) + copytree('./include/',installdir+'/include/',dirs_exist_ok=True) diff --git a/build/make.msvc64.test.py b/build/make.msvc64.test.py index e5c5923..54461f6 100644 --- a/build/make.msvc64.test.py +++ b/build/make.msvc64.test.py @@ -17,7 +17,7 @@ builddir = "./build_msvc64" doinstall = False #copies the build_output to the install dir when finished cc = "cl" #compiler cflags = "/O2" -libraries = "lib{}.lib".format(libname) +libraries = "lib{}.lib libamscimglib4.winx64.a".format(libname) libdirs = "/LIBPATH:{} /LIBPATH:{}/lib /LIBPATH:{}/lib".format(builddir,commondir,depdir) linkerflags = "" srcexts = [".c",".cpp"] diff --git a/build_linux64/libamscimglib4.linux64.a b/build_linux64/libamscimglib4.linux64.a new file mode 100644 index 0000000..889d11a Binary files /dev/null and b/build_linux64/libamscimglib4.linux64.a differ diff --git a/build_linux64/libamscimglib4.linux64.so b/build_linux64/libamscimglib4.linux64.so new file mode 100644 index 0000000..fe55311 Binary files /dev/null and b/build_linux64/libamscimglib4.linux64.so differ diff --git a/build_linux64/libamscppimglib4.linux64.a b/build_linux64/libamscppimglib4.linux64.a index ffafd85..6fda86b 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 new file mode 100644 index 0000000..35e0749 Binary files /dev/null and b/build_linux64/objstore/amscppimglib4_amsbitplane.o differ diff --git a/build_linux64/objstore/amscppimglib4_amsimage.o b/build_linux64/objstore/amscppimglib4_amsimage.o new file mode 100644 index 0000000..e3e8991 Binary files /dev/null and b/build_linux64/objstore/amscppimglib4_amsimage.o differ diff --git a/build_linux64/objstore/amscppimglib4_amspixel.o b/build_linux64/objstore/amscppimglib4_amspixel.o new file mode 100644 index 0000000..d448041 Binary files /dev/null and b/build_linux64/objstore/amscppimglib4_amspixel.o differ diff --git a/build_linux64/objstore/amscppimglib4_intlutil.o b/build_linux64/objstore/amscppimglib4_intlutil.o new file mode 100644 index 0000000..f499330 Binary files /dev/null and b/build_linux64/objstore/amscppimglib4_intlutil.o differ diff --git a/build_linux64/objstore/amscppimglib4_template.o b/build_linux64/objstore/amscppimglib4_template.o new file mode 100644 index 0000000..8791256 Binary files /dev/null and b/build_linux64/objstore/amscppimglib4_template.o differ diff --git a/build_linux64/objstore/amscppimglib4_tests.o b/build_linux64/objstore/amscppimglib4_tests.o new file mode 100644 index 0000000..dbd48b9 Binary files /dev/null and b/build_linux64/objstore/amscppimglib4_tests.o differ diff --git a/build_linux64/objstore/amscpptemplate25a_src2.o b/build_linux64/objstore/amscpptemplate25a_src2.o deleted file mode 100644 index 225c80d..0000000 Binary files a/build_linux64/objstore/amscpptemplate25a_src2.o and /dev/null differ diff --git a/build_linux64/objstore/amscpptemplate25a_template.o b/build_linux64/objstore/amscpptemplate25a_template.o deleted file mode 100644 index 0e66a26..0000000 Binary files a/build_linux64/objstore/amscpptemplate25a_template.o and /dev/null differ diff --git a/build_linux64/tests b/build_linux64/tests index e134178..da5cbbb 100644 Binary files a/build_linux64/tests and b/build_linux64/tests differ diff --git a/build_mingw64/libamscimglib4.winx64.a b/build_mingw64/libamscimglib4.winx64.a new file mode 100644 index 0000000..089c742 Binary files /dev/null and b/build_mingw64/libamscimglib4.winx64.a differ diff --git a/build_mingw64/libamscimglib4.winx64.dll b/build_mingw64/libamscimglib4.winx64.dll new file mode 100644 index 0000000..0e6e243 Binary files /dev/null and b/build_mingw64/libamscimglib4.winx64.dll differ diff --git a/build_mingw64/libamscppimglib4.mingw64.a b/build_mingw64/libamscppimglib4.mingw64.a new file mode 100644 index 0000000..dd0be5b Binary files /dev/null and b/build_mingw64/libamscppimglib4.mingw64.a differ diff --git a/build_mingw64/objstore/amscppimglib4_amsbitplane.o b/build_mingw64/objstore/amscppimglib4_amsbitplane.o new file mode 100644 index 0000000..ca1ebae Binary files /dev/null and b/build_mingw64/objstore/amscppimglib4_amsbitplane.o differ diff --git a/build_mingw64/objstore/amscppimglib4_amsimage.o b/build_mingw64/objstore/amscppimglib4_amsimage.o new file mode 100644 index 0000000..5089bf8 Binary files /dev/null and b/build_mingw64/objstore/amscppimglib4_amsimage.o differ diff --git a/build_mingw64/objstore/amscppimglib4_amspixel.o b/build_mingw64/objstore/amscppimglib4_amspixel.o new file mode 100644 index 0000000..0ce4dd6 Binary files /dev/null and b/build_mingw64/objstore/amscppimglib4_amspixel.o differ diff --git a/build_mingw64/objstore/amscppimglib4_intlutil.o b/build_mingw64/objstore/amscppimglib4_intlutil.o new file mode 100644 index 0000000..d7eedd6 Binary files /dev/null and b/build_mingw64/objstore/amscppimglib4_intlutil.o differ diff --git a/build_mingw64/objstore/amscppimglib4_template.o b/build_mingw64/objstore/amscppimglib4_template.o new file mode 100644 index 0000000..cf14878 Binary files /dev/null and b/build_mingw64/objstore/amscppimglib4_template.o differ diff --git a/build_mingw64/objstore/amscppimglib4_tests.o b/build_mingw64/objstore/amscppimglib4_tests.o new file mode 100644 index 0000000..c270647 Binary files /dev/null and b/build_mingw64/objstore/amscppimglib4_tests.o differ diff --git a/build_mingw64/objstore/amscpptemplate25a_src2.o b/build_mingw64/objstore/amscpptemplate25a_src2.o deleted file mode 100644 index aa63256..0000000 Binary files a/build_mingw64/objstore/amscpptemplate25a_src2.o and /dev/null differ diff --git a/build_mingw64/objstore/amscpptemplate25a_template.o b/build_mingw64/objstore/amscpptemplate25a_template.o deleted file mode 100644 index fc64bdd..0000000 Binary files a/build_mingw64/objstore/amscpptemplate25a_template.o and /dev/null differ diff --git a/build_mingw64/tests.exe b/build_mingw64/tests.exe new file mode 100644 index 0000000..761c24c Binary files /dev/null and b/build_mingw64/tests.exe differ diff --git a/include/amscppimglib4/amscppimglib4.hpp b/include/amscppimglib4/amscppimglib4.hpp index 5b7dd41..2d29af3 100644 --- a/include/amscppimglib4/amscppimglib4.hpp +++ b/include/amscppimglib4/amscppimglib4.hpp @@ -4,12 +4,136 @@ #include #include #include +#include +#include +#include namespace ams { - void amscpptemplate_testfn(); - void amscpptemplate_testfn2(); -}; + + class amsimage; + class amsbitplane; + + static const bool amsimage_usethreads = 1; //use threads for handling image initialization/copying + static const int amsimage_maxthreads = 20; //max number of threads to use + static const int amsimage_threadpsz = 5000; //when to break into threaded operation + static const int amsimage_success = 0; + static const int amsimage_failure = -1; + + + + struct amspixel + { + public: + uint8_t R,G,B,A; + + amspixel(); + amspixel(uint8_t _R ,uint8_t _G, uint8_t _B, uint8_t _A); + uint8_t& operator[](const int ind); + const uint8_t& operator[](const int ind) const; + }; + + class amsimage + { + public: + int Nx,Ny; //image extent + //int Nc; //number of color-planes (1,3,4) + //Assume we're talking about an RGBA image internally, greyscale is what bitplane is for + uint8_t *data; //[(x + width*y)*4] + + int& width; //aliases to Nx,Ny + int& height; + + amsimage(); + ~amsimage(); + amsimage(const amsimage& other); + amsimage(amsimage&& other) noexcept; + amsimage& operator=(const amsimage& other); + amsimage& operator=(amsimage&& other) noexcept; + + int resize(int _Nx, int _Ny); + + amsimage subimage(int I0, int J0, int I1, int J1) const; + amsimage transpose() const; + amsimage rotcw() const; + amsimage rotccw() const; + amsimage flipx() const; + amsimage flipy() const; + + amspixel get_pixel(int I,int J) const; + int set_pixel(int I,int J,const amspixel pix); + int set_pixel(int I,int J,uint8_t R, uint8_t G, uint8_t B, uint8_t A); + uint8_t& operator[](int ind); + const uint8_t& operator[](int ind) const; + uint8_t& operator()(int Nc, int I, int J); + const uint8_t& operator()(int Nc, int I, int J) const; + + + + + void clear(); + void setall(amspixel color); + int setallplane(int Ncp, uint8_t val); + + int get_colorplane(int Ncp, amsbitplane* bp); + int set_colorplane(int Ncp, const amsbitplane* bp); + + //applies image with alpha blending + int apply_image(int I0, int J0, amsimage *img); + //applied color to any pixels where the bitplane's value is >= thresh + int apply_bitplane_nz(int I0, int J0, amsbitplane* bp, amspixel color, uint8_t thresh); + + //rescales the image with linear interpolation + int rescale(int nnx, int nny); + }; + + int read_image(const char *fname, amsimage* image); + int write_image(const char *fname, amsimage* image); + + class amsbitplane + { + public: + int Nx,Ny; + uint8_t *data; //[x+width*y] + + amsbitplane(); + ~amsbitplane(); + amsbitplane(const amsbitplane& other); + amsbitplane(amsbitplane&& other) noexcept; + amsbitplane& operator=(const amsbitplane& other); + amsbitplane& operator=(amsbitplane&& other) noexcept; + + int resize(int _Nx, int _Ny); + void transpose(); + void rotcw(); + void rotccw(); + void flipx(); + void flipy(); + + uint8_t get(int I, int J) const; + int set(int I, int J, uint8_t val); + + uint8_t& at(int I, int J); + uint8_t& operator()(const int I, const int J); + const uint8_t& operator()(const int I, const int J) const; + uint8_t& operator[](const long I); + const uint8_t& operator[](const long I) const; + + + void clear(); + + //rescales the image with linear interpolation + int rescale(int nnx, int nny); + }; + + + //Tests// + + void amscppimglib_test1(); + +}; //end namespace ams + +#include #endif \ No newline at end of file diff --git a/include/amscppimglib4/amscppimglib4_intlutil.hpp b/include/amscppimglib4/amscppimglib4_intlutil.hpp new file mode 100644 index 0000000..747700b --- /dev/null +++ b/include/amscppimglib4/amscppimglib4_intlutil.hpp @@ -0,0 +1,90 @@ +#ifndef __AMSCPPIMGLIB4_INTLUTIL_HPP__ +#define __AMSCPPIMGLIB4_INTLUTIL_HPP__ + +namespace ams +{ +namespace imglib4 +{ + +//A template function that takes as input a function pointer and a series of arguments +//The function is executed with fptr(threadnum, nthreads, otherargs...) with a certain number of threads +//psize must be supplied to determine whether to execute in threaded mode or not. +template int threaded_execute(callable &&fptr, int64_t psize, argst&&... args) +{ + int ret = amsimage_success; + int nthreads; + int I; + std::vector threads; + + if(psize(args)...); + } + else + { + nthreads = std::thread::hardware_concurrency(); //number of cpu cores the system thinks you have + nthreads = (nthreads<=0) ? 1 : nthreads; + nthreads = (nthreads>amsimage_maxthreads) ? amsimage_maxthreads : nthreads; + threads.resize(nthreads); + for(I=0;I(fptr), + I, + nthreads, + std::forward(args)... + ); + } + for(I=0;Ijoin(); + delete threads[I]; + threads[I] = NULL; + } + } + } + + return ret; +} + +void amsimage_region_copy( + uint8_t *datato, + int Nxto, + int Nyto, + const uint8_t *datafrom, + int Nxfrom, + int Nyfrom, + int offsetx, + int offsety +); + +void amsimage_region_set( + uint8_t *data, + int Nx, int Ny, + int x0, int y0, + int x1, int y1, + amspixel val +); + + + + +}; //end namespace imglib4 +}; //end namespace ams + +#endif + diff --git a/include/amscppimglib4/amscppimglib4_tests.hpp b/include/amscppimglib4/amscppimglib4_tests.hpp new file mode 100644 index 0000000..be7ea56 --- /dev/null +++ b/include/amscppimglib4/amscppimglib4_tests.hpp @@ -0,0 +1,11 @@ +#ifndef __AMSCPPIMGLIB4_TESTS_HPP__ +#define __AMSCPPIMGLIB4_TESTS_HPP__ + +namespace ams +{ + + +}; //end namespace ams + +#endif + diff --git a/src/amscppimglib4/amscppimglib4_amsbitplane.cpp b/src/amscppimglib4/amscppimglib4_amsbitplane.cpp new file mode 100644 index 0000000..616ffb6 --- /dev/null +++ b/src/amscppimglib4/amscppimglib4_amsbitplane.cpp @@ -0,0 +1,8 @@ +#include + +namespace ams +{ + + + +}; \ No newline at end of file diff --git a/src/amscppimglib4/amscppimglib4_amsimage.cpp b/src/amscppimglib4/amscppimglib4_amsimage.cpp new file mode 100644 index 0000000..98feec7 --- /dev/null +++ b/src/amscppimglib4/amscppimglib4_amsimage.cpp @@ -0,0 +1,461 @@ +#include +#include + +namespace ams +{ + + amsimage::amsimage() : Nx(0), Ny(0),data(NULL),width(Nx),height(Ny) + { + return; + } + + amsimage::~amsimage() + { + Nx = 0; + Ny = 0; + if(data!=NULL) {delete[] data; data=NULL;} + return; + } + + int amsimage::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[4*_Nx*_Ny]; + if(newdata==NULL) + { + ret = amsimage_failure; + return ret; + } + + imglib4::amsimage_region_set( + newdata, + _Nx,_Ny, + 0,0,_Nx,_Ny, + amspixel(0,0,0,0) + ); + + if(data!=NULL) + { + imglib4::amsimage_region_copy( + newdata, + _Nx,_Ny, + data, + Nx,Ny, + 0,0 + ); + } + + if(data!=NULL) {delete[] data; data=NULL;} + data = newdata; + Nx = _Nx; + Ny = _Ny; + + return ret; + } + + amsimage::amsimage(const amsimage& other) : + Nx(0), Ny(0),data(NULL),width(Nx),height(Ny) + { + int res; + // Nx = 0; + // Ny = 0; + // data = NULL; + + if(this!=&other) + { + res = this->resize(other.Nx,other.Ny); + if(res==amsimage_success) + { + imglib4::amsimage_region_copy( + data, Nx, Ny, + other.data, other.Nx, other.Ny, + 0,0 + ); + } + } + } + + amsimage::amsimage(amsimage&& other) noexcept : + Nx(0), Ny(0),data(NULL),width(Nx),height(Ny) + { + int res; + // Nx = 0; + // Ny = 0; + // data = NULL; + + 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; + } + + amsimage& amsimage::operator=(const amsimage& other) + { + int res; + + if(this!=&other) + { + res = this->resize(other.Nx,other.Ny); + if(res==amsimage_success) + { + imglib4::amsimage_region_copy( + data, Nx, Ny, + other.data, other.Nx, other.Ny, + 0,0 + ); + } + } + + return *this; + } + + amsimage& amsimage::operator=(amsimage&& 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; + } + + amsimage amsimage::subimage(int I0, int J0, int I1, int J1) const + { + amsimage ret; + int _Nx,_Ny; + _Nx = ((I1-I0) < 0) ? 0 : I1-I0; + _Ny = ((J1-J0) < 0) ? 0 : J1-J0; + + ret.resize(_Nx,_Ny); + + imglib4::amsimage_region_copy( + ret.data, ret.Nx, ret.Ny, + this->data, Nx,Ny, + I0,J0 + ); + + return ret; + } + + void amsimage_transpose_tf( + int threadnum, + int nthreads, + uint8_t *datato, + const uint8_t *datafrom, + int Nx, int Ny + ) + { + int64_t I,I0,I1,Is,N,Ia,Ib,Ix,Iy; + N = Nx*Ny; + Is = N/nthreads; + I0 = (threadnum)*Is; + I1 = (threadnumdata,Nx,Ny + ); + + return ret; + } + + void amsimage_rotcw_tf( + int threadnum, + int nthreads, + uint8_t *datato, + const uint8_t *datafrom, + int Nx, int Ny + ) + { + int64_t I,I0,I1,Is,N,Ia,Ib,Ix,Iy; + N = Nx*Ny; + Is = N/nthreads; + I0 = (threadnum)*Is; + I1 = (threadnumdata,Nx,Ny + ); + + return ret; + } + + void amsimage_rotccw_tf( + int threadnum, + int nthreads, + uint8_t *datato, + const uint8_t *datafrom, + int Nx, int Ny + ) + { + int64_t I,I0,I1,Is,N,Ia,Ib,Ix,Iy; + N = Nx*Ny; + Is = N/nthreads; + I0 = (threadnum)*Is; + I1 = (threadnumdata,Nx,Ny + ); + + return ret; + } + + void amsimage_flipx_tf( + int threadnum, + int nthreads, + uint8_t *datato, + const uint8_t *datafrom, + int Nx, int Ny + ) + { + int64_t I,I0,I1,Is,N,Ia,Ib,Ix,Iy; + N = Nx*Ny; + Is = N/nthreads; + I0 = (threadnum)*Is; + I1 = (threadnumdata,Nx,Ny + ); + + return ret; + } + + void amsimage_flipy_tf( + int threadnum, + int nthreads, + uint8_t *datato, + const uint8_t *datafrom, + int Nx, int Ny + ) + { + int64_t I,I0,I1,Is,N,Ia,Ib,Ix,Iy; + N = Nx*Ny; + Is = N/nthreads; + I0 = (threadnum)*Is; + I1 = (threadnumdata,Nx,Ny + ); + + return ret; + } + + + amspixel amsimage::get_pixel(int I,int J) const + { + amspixel ret; + if(I>=0 && I=0 && J=0 && I=0 && Jset_pixel(I,J,amspixel(R,G,B,A)); + } + + uint8_t& amsimage::operator[](int ind) + { + return data[ind]; + } + + const uint8_t& amsimage::operator[](int ind) const + { + return data[ind]; + } + + uint8_t& amsimage::operator()(int Nc, int I, int J) + { + return data[Nc + 4*(I + Nx*J)]; + } + + const uint8_t& amsimage::operator()(int Nc, int I, int J) const + { + return data[Nc + 4*(I + Nx*J)]; + } + +}; \ No newline at end of file diff --git a/src/amscppimglib4/amscppimglib4_amspixel.cpp b/src/amscppimglib4/amscppimglib4_amspixel.cpp new file mode 100644 index 0000000..227c0a8 --- /dev/null +++ b/src/amscppimglib4/amscppimglib4_amspixel.cpp @@ -0,0 +1,37 @@ +#include + +namespace ams +{ + +amspixel::amspixel() +{ + R = 0; G = 0; B = 0; A = 0; + return; +} + +amspixel::amspixel(uint8_t _R ,uint8_t _G, uint8_t _B, uint8_t _A) +{ + R = _R; G = _G; B = _B; A = _A; + return; +} + +uint8_t& amspixel::operator[](const int ind) +{ + if(ind==0) return R; + if(ind==1) return G; + if(ind==2) return B; + if(ind==3) return A; + return A; +} + +const uint8_t& amspixel::operator[](const int ind) const +{ + if(ind==0) return R; + if(ind==1) return G; + if(ind==2) return B; + if(ind==3) return A; + return A; +} + + +}; \ No newline at end of file diff --git a/src/amscppimglib4/amscppimglib4_intlutil.cpp b/src/amscppimglib4/amscppimglib4_intlutil.cpp new file mode 100644 index 0000000..dbbe48e --- /dev/null +++ b/src/amscppimglib4/amscppimglib4_intlutil.cpp @@ -0,0 +1,169 @@ +#include +#include + +namespace ams +{ +namespace imglib4 +{ + + void amsimage_region_copy_tf( + int threadnum, + int nthreads, + uint8_t *datato, + int Nxto, + int Nyto, + const uint8_t *datafrom, + int Nxfrom, + int Nyfrom, + int offsetx, + int offsety + ) + { + int64_t I,I0,I1,Is,N,Ix,Iy; + 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; + 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_region_copy_tf, + N, + datato, + Nxto,Nyto, + datafrom, + Nxfrom,Nyfrom, + offsetx,offsety + ); + + + return; + } + + void amsimage_region_set_tf( + int threadnum, + int nthreads, + uint8_t *data, + int Nx, int Ny, + int x0, int y0, + int x1, int y1, + amspixel 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; + I0 = (threadnum)*Is; + I1 = (threadnum + +namespace ams +{ + + + +}; \ No newline at end of file diff --git a/src/amscppimglib4/amscppimglib4_tests.cpp b/src/amscppimglib4/amscppimglib4_tests.cpp new file mode 100644 index 0000000..ce584dd --- /dev/null +++ b/src/amscppimglib4/amscppimglib4_tests.cpp @@ -0,0 +1,20 @@ +#include + +namespace ams +{ + + void amscppimglib_test1() + { + amsimage img1, img2; + + img1.resize(1000,2000); + printf("img1:(%d,%d)\n",img1.width,img1.height); + + img2 = img1.transpose(); + img2 = img1.transpose().flipx(); + printf("img1:(%d,%d)\n",img2.width,img2.height); + + return; + } + +}; \ No newline at end of file diff --git a/src/amscppimglib4/amscpptemplate25a_src2.cpp b/src/amscppimglib4/amscpptemplate25a_src2.cpp deleted file mode 100644 index 19b19c1..0000000 --- a/src/amscppimglib4/amscpptemplate25a_src2.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -namespace ams -{ - -void amscpptemplate_testfn2() -{ - printf("Test function 2.\n"); - return; -} - -}; \ No newline at end of file diff --git a/src/amscppimglib4/amscpptemplate25a_template.cpp b/src/amscppimglib4/amscpptemplate25a_template.cpp deleted file mode 100644 index e26a223..0000000 --- a/src/amscppimglib4/amscpptemplate25a_template.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -namespace ams -{ - -void amscpptemplate_testfn() -{ - printf("Test function.\n"); - return; -} - -}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index ad1b666..6b540b1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,12 @@ #include +using namespace ams; + int main(int argc, char* argv[]) { int ret = 0; - printf("ams c++ image library tests.\n"); - ams::amscpptemplate_testfn(); + + amscppimglib_test1(); + return ret; } \ No newline at end of file