master
Aaron 2 days ago
parent 09a83f8587
commit 1610fdecd0

@ -2,6 +2,12 @@
"folders": [
{
"path": "."
},
{
"path": "../../sourceprojs23/amsimglib3"
},
{
"path": "../amscimglib4"
}
]
}

@ -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)

@ -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

@ -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)

@ -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

@ -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)

@ -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"]

Binary file not shown.

Binary file not shown.

@ -4,12 +4,136 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdint.h>
#include <vector>
#include <thread>
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 <amscppimglib4/amscppimglib4_tests.hpp>
#endif

@ -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<typename callable, typename ... argst> int threaded_execute(callable &&fptr, int64_t psize, argst&&... args)
{
int ret = amsimage_success;
int nthreads;
int I;
std::vector<std::thread*> threads;
if(psize<amsimage_threadpsz)
{
nthreads = 1;
I = 0;
fptr(I,nthreads,std::forward<argst>(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<nthreads;I++) threads[I] = NULL;
for(I=0;I<nthreads;I++)
{
threads[I] = new(std::nothrow) std::thread
(
std::forward<callable>(fptr),
I,
nthreads,
std::forward<argst>(args)...
);
}
for(I=0;I<nthreads;I++)
{
if(threads[I]==NULL)
{ //null thread creation failure check
//printf("debug check!\n");
ret = amsimage_failure;
}
}
for(I=0;I<nthreads;I++)
{
if(threads[I]!=NULL)
{
threads[I]->join();
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

@ -0,0 +1,11 @@
#ifndef __AMSCPPIMGLIB4_TESTS_HPP__
#define __AMSCPPIMGLIB4_TESTS_HPP__
namespace ams
{
}; //end namespace ams
#endif

@ -0,0 +1,8 @@
#include <amscppimglib4/amscppimglib4.hpp>
namespace ams
{
};

@ -0,0 +1,461 @@
#include <amscppimglib4/amscppimglib4.hpp>
#include <amscppimglib4/amscppimglib4_intlutil.hpp>
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 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
for(I=I0;I<I1;I++)
{
Ix = I%Nx;
Iy = I/Nx;
Ia = Iy + Ny*Ix;
Ib = Ix+Nx*Iy;
datato[0 + 4*Ia] = datafrom[0 + 4*Ib];
datato[1 + 4*Ia] = datafrom[1 + 4*Ib];
datato[2 + 4*Ia] = datafrom[2 + 4*Ib];
datato[3 + 4*Ia] = datafrom[3 + 4*Ib];
}
return;
}
amsimage amsimage::transpose() const
{
amsimage ret;
int64_t N;
ret.resize(Ny,Nx);
N = Nx*Ny;
imglib4::threaded_execute(
amsimage_transpose_tf,
N,
ret.data,this->data,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 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
for(I=I0;I<I1;I++)
{
Ix = I%Nx;
Iy = I/Nx;
Ia = Iy + Ny*Ix;
Ib = Ix+Nx*(Ny-Iy-1);
datato[0 + 4*Ia] = datafrom[0 + 4*Ib];
datato[1 + 4*Ia] = datafrom[1 + 4*Ib];
datato[2 + 4*Ia] = datafrom[2 + 4*Ib];
datato[3 + 4*Ia] = datafrom[3 + 4*Ib];
}
return;
}
amsimage amsimage::rotcw() const
{
amsimage ret;
int64_t N;
ret.resize(Ny,Nx);
N = Nx*Ny;
imglib4::threaded_execute(
amsimage_rotcw_tf,
N,
ret.data,this->data,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 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
for(I=I0;I<I1;I++)
{
Ix = I%Nx;
Iy = I/Nx;
Ia = Iy + Ny*Ix;
Ib = (Nx-Ix-1)+Nx*Iy;
datato[0 + 4*Ia] = datafrom[0 + 4*Ib];
datato[1 + 4*Ia] = datafrom[1 + 4*Ib];
datato[2 + 4*Ia] = datafrom[2 + 4*Ib];
datato[3 + 4*Ia] = datafrom[3 + 4*Ib];
}
return;
}
amsimage amsimage::rotccw() const
{
amsimage ret;
int64_t N;
ret.resize(Ny,Nx);
N = Nx*Ny;
imglib4::threaded_execute(
amsimage_rotccw_tf,
N,
ret.data,this->data,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 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
for(I=I0;I<I1;I++)
{
Ix = I%Nx;
Iy = I/Nx;
Ia = Ix + Nx*Iy;
Ib = (Nx-Ix-1)+Nx*Iy;
datato[0 + 4*Ia] = datafrom[0 + 4*Ib];
datato[1 + 4*Ia] = datafrom[1 + 4*Ib];
datato[2 + 4*Ia] = datafrom[2 + 4*Ib];
datato[3 + 4*Ia] = datafrom[3 + 4*Ib];
}
return;
}
amsimage amsimage::flipx() const
{
amsimage ret;
int64_t N;
ret.resize(Nx,Ny);
N = Nx*Ny;
imglib4::threaded_execute(
amsimage_flipx_tf,
N,
ret.data,this->data,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 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
for(I=I0;I<I1;I++)
{
Ix = I%Nx;
Iy = I/Nx;
Ia = Ix + Nx*Iy;
Ib = Ix+Nx*(Ny-Iy-1);
datato[0 + 4*Ia] = datafrom[0 + 4*Ib];
datato[1 + 4*Ia] = datafrom[1 + 4*Ib];
datato[2 + 4*Ia] = datafrom[2 + 4*Ib];
datato[3 + 4*Ia] = datafrom[3 + 4*Ib];
}
return;
}
amsimage amsimage::flipy() const
{
amsimage ret;
int64_t N;
ret.resize(Nx,Ny);
N = Nx*Ny;
imglib4::threaded_execute(
amsimage_flipy_tf,
N,
ret.data,this->data,Nx,Ny
);
return ret;
}
amspixel amsimage::get_pixel(int I,int J) const
{
amspixel ret;
if(I>=0 && I<Nx && J>=0 && J<Ny)
{
ret.R = data[0 + 4*(I + Nx*J)];
ret.G = data[1 + 4*(I + Nx*J)];
ret.B = data[2 + 4*(I + Nx*J)];
ret.A = data[3 + 4*(I + Nx*J)];
}
return ret;
}
int amsimage::set_pixel(int I,int J,const amspixel pix)
{
int ret = amsimage_failure;
if(I>=0 && I<Nx && J>=0 && J<Ny)
{
ret = amsimage_success;
data[0 + 4*(I + Nx*J)] = pix.R;
data[1 + 4*(I + Nx*J)] = pix.G;
data[2 + 4*(I + Nx*J)] = pix.B;
data[3 + 4*(I + Nx*J)] = pix.A;
}
return ret;
}
int amsimage::set_pixel(int I,int J,uint8_t R, uint8_t G, uint8_t B, uint8_t A)
{
return this->set_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)];
}
};

@ -0,0 +1,37 @@
#include <amscppimglib4/amscppimglib4.hpp>
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;
}
};

@ -0,0 +1,169 @@
#include <amscppimglib4/amscppimglib4.hpp>
#include <amscppimglib4/amscppimglib4_intlutil.hpp>
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<nthreads-1) ? (threadnum+1)*Is : N;
for(I=I0;I<I1;I++)
{
Ix = I%dx;
Iy = I/dx;
datato[0 + 4*(Ix+offsetx) + 4*Nxto*(Iy+offsety)] =
datafrom[0 + 4*Ix + 4*Nxfrom*Iy];
datato[1 + 4*(Ix+offsetx) + 4*Nxto*(Iy+offsety)] =
datafrom[1 + 4*Ix + 4*Nxfrom*Iy];
datato[2 + 4*(Ix+offsetx) + 4*Nxto*(Iy+offsety)] =
datafrom[2 + 4*Ix + 4*Nxfrom*Iy];
datato[3 + 4*(Ix+offsetx) + 4*Nxto*(Iy+offsety)] =
datafrom[3 + 4*Ix + 4*Nxfrom*Iy];
}
return;
}
void amsimage_region_copy(
uint8_t *datato,
int Nxto,
int Nyto,
const uint8_t *datafrom,
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_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<nthreads-1) ? (threadnum+1)*Is : N;
for(I=I0;I<I1;I++)
{
Ix = I%dx;
Iy = I/dx;
data[0 + 4*(Ix+x0) + 4*Nx*(Iy+y0)] = val.R;
data[1 + 4*(Ix+x0) + 4*Nx*(Iy+y0)] = val.G;
data[2 + 4*(Ix+x0) + 4*Nx*(Iy+y0)] = val.B;
data[3 + 4*(Ix+x0) + 4*Nx*(Iy+y0)] = val.A;
}
return;
}
void amsimage_region_set(
uint8_t *data,
int Nx, int Ny,
int x0, int y0,
int x1, int y1,
amspixel 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_region_set_tf,
N,
data, Nx,Ny,
x0, y0, x1, y1,
val
);
return;
}
}; //end namespace imglib4
}; //end namespace ams

@ -0,0 +1,8 @@
#include <amscppimglib4/amscppimglib4.hpp>
namespace ams
{
};

@ -0,0 +1,20 @@
#include <amscppimglib4/amscppimglib4.hpp>
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;
}
};

@ -1,12 +0,0 @@
#include <amscppimglib4/amscppimglib4.hpp>
namespace ams
{
void amscpptemplate_testfn2()
{
printf("Test function 2.\n");
return;
}
};

@ -1,12 +0,0 @@
#include <amscppimglib4/amscppimglib4.hpp>
namespace ams
{
void amscpptemplate_testfn()
{
printf("Test function.\n");
return;
}
};

@ -1,9 +1,12 @@
#include <amscppimglib4/amscppimglib4.hpp>
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;
}
Loading…
Cancel
Save