drawcanvas class added

This commit is contained in:
2025-06-03 09:36:08 -04:00
commit e515644432
43 changed files with 1707 additions and 0 deletions

View File

@ -0,0 +1,9 @@
#include <amscppsimpledraw/amscppsimpledraw.hpp>
namespace ams
{
namespace simpledraw
{
};
};

View File

@ -0,0 +1,17 @@
#include <amscppsimpledraw/amscppsimpledraw.hpp>
namespace ams
{
namespace simpledraw
{
void test_drawcanvas1()
{
drawcanvas q;
q.resize(1000,1000);
};
};
};

View File

@ -0,0 +1,308 @@
#include <amscppsimpledraw/amscppsimpledraw.hpp>
namespace ams
{
namespace simpledraw
{
drawcanvas::drawcanvas()
{
width = 0;
height = 0;
data = NULL;
return;
}
drawcanvas::~drawcanvas()
{
width = 0;
height = 0;
if(data!=NULL) {delete[] data; data=NULL;}
return;
}
drawcanvas::drawcanvas(const drawcanvas &other)
{
width = 0;
height = 0;
data = NULL;
if(this!=&other)
{
this->resize(other.width,other.height);
::ams::buffer_cast_copy<double,double>(this->data,other.data,width*height*5);
}
}
drawcanvas::drawcanvas(drawcanvas &&other) noexcept
{
width = 0;
height = 0;
data = NULL;
if(this!=&other)
{
this->width = other.width;
this->height = other.height;
this->data = other.data;
other.width = 0;
other.height = 0;
other.data = NULL;
}
return;
}
drawcanvas& drawcanvas::operator=(const drawcanvas &other)
{
if(this!=&other)
{
this->resize(other.width,other.height);
::ams::buffer_cast_copy<double,double>(this->data,other.data,width*height*5);
}
return *this;
}
drawcanvas& drawcanvas::operator=(drawcanvas &&other) noexcept
{
if(this!=&other)
{
width = 0;
height = 0;
if(data != NULL) {delete[] data; data=NULL;}
this->width = other.width;
this->height = other.height;
this->data = other.data;
other.width = 0;
other.height = 0;
other.data = NULL;
}
return *this;
}
void drawcanvas_copy_region_tf(
int threadnum,
int nthreads,
drawcanvas *to,
drawcanvas *from,
int xoffset,
int yoffset
)
{
int64_t I,I0,I1,N;
int Ix,Iy,K;
int64_t xmin,xmax,ymin,ymax,dx,dy;
xmin = xoffset;
ymin = yoffset;
xmax = ::ams::min(to->width, from->width + xoffset);
ymax = ::ams::min(to->height, from->height + yoffset);
dx = ((xmax-xmin)<0) ? 0 : xmax-xmin;
dy = ((ymax-ymin)<0) ? 0 : ymax-ymin;
N = dx*dy;
I0 = (threadnum)*N;
I1 = (threadnum<nthreads-1) ? (threadnum+1)*N : N;
for(I=I0;I<I1;I++)
{
Ix = I0%dx;
Iy = I0/dx;
for(K=0;K<5;K++)
{
to->at(K,Ix+xoffset,Iy+yoffset) = from->at(K,Ix,Iy);
}
}
}
void drawcanvas_copy_region(
drawcanvas *to,
drawcanvas *from,
int xoffset,
int yoffset
)
{
int64_t N;
int64_t xmin,xmax,ymin,ymax,dx,dy;
xmin = xoffset;
ymin = yoffset;
xmax = ::ams::min(to->width, from->width + xoffset);
ymax = ::ams::min(to->height, from->height + yoffset);
dx = ((xmax-xmin)<0) ? 0 : xmax-xmin;
dy = ((ymax-ymin)<0) ? 0 : ymax-ymin;
N = dx*dy;
if(N>=0)
{
::ams::threaded_execute(
drawcanvas_copy_region_tf,
N,
to,
from,
xoffset,
yoffset
);
}
return;
}
void drawcanvas_copy_region_tf2(
int threadnum,
int nthreads,
double *to,
int to_width,
int to_height,
double *from,
int from_width,
int from_height,
int xoffset,
int yoffset
)
{
int64_t I,I0,I1,N;
int Ix,Iy,K;
int64_t xmin,xmax,ymin,ymax,dx,dy;
xmin = xoffset;
ymin = yoffset;
xmax = ::ams::min(to_width, from_width + xoffset);
ymax = ::ams::min(to_height, from_height + yoffset);
dx = ((xmax-xmin)<0) ? 0 : xmax-xmin;
dy = ((ymax-ymin)<0) ? 0 : ymax-ymin;
N = dx*dy;
I0 = (threadnum)*N;
I1 = (threadnum<nthreads-1) ? (threadnum+1)*N : N;
for(I=I0;I<I1;I++)
{
Ix = I0%dx;
Iy = I0/dx;
for(K=0;K<5;K++)
{
to[K + 5*(Ix + xoffset) + 5*to_width*(Iy+yoffset)] =
from[K + 5*(Ix) + 5*from_width*(Iy)];
}
}
}
void drawcanvas_copy_region(
double *to,
int to_width,
int to_height,
double *from,
int from_width,
int from_height,
int xoffset,
int yoffset
)
{
int64_t N;
int64_t xmin,xmax,ymin,ymax,dx,dy;
xmin = xoffset;
ymin = yoffset;
xmax = ::ams::min(to_width, from_width + xoffset);
ymax = ::ams::min(to_height, from_height + yoffset);
dx = ((xmax-xmin)<0) ? 0 : xmax-xmin;
dy = ((ymax-ymin)<0) ? 0 : ymax-ymin;
N = dx*dy;
if(N>=0)
{
::ams::threaded_execute(
drawcanvas_copy_region_tf2,
N,
to,
to_width,
to_height,
from,
from_width,
from_height,
xoffset,
yoffset
);
}
return;
}
int drawcanvas::resize(int _width, int _height)
{
int ret = simpledraw_success;
double *newdata = NULL;
_width = (_width<0)? 0 : _width;
_height = (_height<0)? 0 : _height;
if(_width*_height==0)
{
if(data!=NULL) {delete[] data; data=NULL;}
width = 0;
height = 0;
ret = simpledraw_success;
return ret;
}
newdata = new(std::nothrow) double[_width*_height*5];
if(newdata=NULL)
{
printf("drawcanvas::resize : Error, newdata could not be allocated.\n");
ret = simpledraw_failure;
return ret;
}
::ams::buffer_set<double>(newdata,width*height,0);
drawcanvas_copy_region(
this->data,
this->width,
this->height,
newdata,
_width,
_height,
0,0
);
return ret;
}
double& drawcanvas::operator[](int64_t ind)
{
return data[ind];
}
const double& drawcanvas::operator[](int64_t ind) const
{
return data[ind];
}
double& drawcanvas::operator()(int channel, int ix, int iy)
{
return data[channel + 5*ix + 5*width*iy];
}
const double& drawcanvas::operator()(int channel, int ix, int iy) const
{
return data[channel + 5*ix + 5*width*iy];
}
double& drawcanvas::at(int channel, int ix, int iy)
{
return data[channel + 5*ix + 5*width*iy];
}
const double& drawcanvas::at(int channel, int ix, int iy) const
{
return data[channel + 5*ix + 5*width*iy];
}
};
};

11
src/main.cpp Normal file
View File

@ -0,0 +1,11 @@
#include <amscppsimpledraw/amscppsimpledraw.hpp>
int main(int argc, char* argv[])
{
int ret = 0;
printf("ams c++ project template tests.\n");
ams::simpledraw::test_drawcanvas1();
return ret;
}