This commit is contained in:
2025-06-04 19:08:31 -04:00
parent 09a83f8587
commit 1610fdecd0
44 changed files with 992 additions and 56 deletions

View File

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

View File

@ -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)];
}
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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