updates
This commit is contained in:
@ -125,6 +125,7 @@ namespace ams
|
||||
|
||||
if(data!=NULL)
|
||||
{
|
||||
|
||||
imglib4::amsimage_plane_copy(
|
||||
newdata,0,1,_Nx,_Ny,
|
||||
data,0,1,Nx,Ny,
|
||||
@ -465,6 +466,212 @@ namespace ams
|
||||
return;
|
||||
}
|
||||
|
||||
void amsbitplane::clear()
|
||||
{
|
||||
this->setall(0);
|
||||
}
|
||||
|
||||
float amsbitplane::getf(int x, int y) const
|
||||
{
|
||||
float ret = 0.0f;
|
||||
int p;
|
||||
p = get(x,y);
|
||||
ret = (float)p/255.0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int amsbitplane::setf(int x, int y, float f)
|
||||
{
|
||||
int ret = amsimage_failure;
|
||||
int p;
|
||||
|
||||
if(x>=0 && x<Nx && y>=0 && y<Ny)
|
||||
{
|
||||
ret = amsimage_success;
|
||||
|
||||
p = (int)(f*255.0);
|
||||
if(p<0) p = 0;
|
||||
if(p>255) p = 255;
|
||||
set(x,y,p);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
float amsbitplane::interpolate(float x, float y) const
|
||||
{
|
||||
float ret = 0.0f;
|
||||
|
||||
float Nxf,Nyf;
|
||||
//just do simple (0,N-1) interpolation for now
|
||||
int xi,yi,xip,yip;
|
||||
float xif,yif,xr,yr;
|
||||
float w00,w01,w10,w11;
|
||||
float p00,p01,p10,p11;
|
||||
|
||||
Nxf = (float)Nx;
|
||||
Nyf = (float)Ny;
|
||||
|
||||
if(x>-0.5 && x<Nxf-0.5 && y>-0.5 && y<Nyf-0.5)
|
||||
{
|
||||
xr = imglib4::mod(x,1.0f);
|
||||
yr = imglib4::mod(y,1.0f);
|
||||
xif = x - xr;
|
||||
yif = y - yr;
|
||||
if(xif<0.0f) {xr = 1.0f;}
|
||||
if(xif>=(Nxf-1.0f)) {xr = 0.0f;}
|
||||
if(yif<0.0f) {yr = 1.0;}
|
||||
if(yif>=(Nyf-1.0f)) {yr = 0.0f;}
|
||||
xi = (int)xif;
|
||||
yi = (int)yif;
|
||||
w00 = (1.0-xr)*(1.0-yr);
|
||||
w10 = (xr)*(1.0-yr);
|
||||
w01 = (1.0-xr)*(yr);
|
||||
w11 = (xr)*(yr);
|
||||
|
||||
xip = xi + 1;
|
||||
yip = yi + 1;
|
||||
if(xi<0) xi = 0;
|
||||
if(xi>Nx-1) xi = Nx-1;
|
||||
if(yi<0) yi = 0;
|
||||
if(yi>Ny-1) yi = Ny-1;
|
||||
if(xip>Nx-1) xip = Nx-1;
|
||||
if(yip>Ny-1) yip = Ny-1;
|
||||
|
||||
p00 = getf(xi,yi);
|
||||
p10 = getf(xip,yi);
|
||||
p01 = getf(xi,yip);
|
||||
p11 = getf(xip,yip);
|
||||
|
||||
ret = p00*w00 + p10*w10 + p01*w01 + p11*w11;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void amsbitplane_rescale_tf(
|
||||
int threadnum,
|
||||
int nthreads,
|
||||
amsbitplane *imgto,
|
||||
const amsbitplane *imgfrom
|
||||
)
|
||||
{
|
||||
int Nx = imgto->Nx;
|
||||
int Ny = imgto->Ny;
|
||||
int64_t I,I0,I1,Is,N,Ix,Iy;
|
||||
float p;
|
||||
|
||||
int xs,ys;
|
||||
|
||||
N = Nx*Ny;
|
||||
Is = N/nthreads; if(Is<1) Is = 1;
|
||||
I0 = threadnum*Is;
|
||||
I1 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
|
||||
|
||||
for(I=I0;I<I1;I++)
|
||||
{
|
||||
Ix = I%Nx;
|
||||
Iy = I/Nx;
|
||||
|
||||
xs = (float)Ix*((float)(imgfrom->Nx-1))/((float)(imgto->Nx-1));
|
||||
ys = (float)Iy*((float)(imgfrom->Ny-1))/((float)(imgto->Ny-1));
|
||||
|
||||
p = imgfrom->interpolate(xs,ys);
|
||||
imgto->setf(Ix,Iy,p);
|
||||
}
|
||||
}
|
||||
|
||||
amsbitplane amsbitplane::rescale(int nnx, int nny)
|
||||
{
|
||||
amsbitplane ret;
|
||||
int res;
|
||||
|
||||
res = ret.resize(nnx,nny);
|
||||
if(res!=amsimage_success)
|
||||
{
|
||||
printf("amsimage::rescale: error, could not allocate return image.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
imglib4::threaded_execute(
|
||||
amsbitplane_rescale_tf, nnx*nny,
|
||||
&ret,this
|
||||
);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void amsimage_apply_bitplane_tf(
|
||||
int threadnum,
|
||||
int nthreads,
|
||||
amsbitplane *imgto,
|
||||
const amsbitplane *imgfrom,
|
||||
int x0, int y0
|
||||
)
|
||||
{
|
||||
int dx,dy;
|
||||
int64_t N;
|
||||
int64_t I,I0,I1,Is,Ix,Iy,Ia,Ib;
|
||||
uint8_t v1,v2;
|
||||
|
||||
dx = (imgfrom->Nx < (imgto->Nx-x0)) ? imgfrom->Nx : imgto->Nx-x0;
|
||||
dx = (dx<0) ? 0 : dx;
|
||||
dy = (imgfrom->Ny < (imgto->Ny-y0)) ? imgfrom->Ny : imgto->Ny-y0;
|
||||
dy = (dy<0) ? 0 : dy;
|
||||
N = dx*dy;
|
||||
|
||||
Is = N/nthreads; if(Is<1) Is=1;
|
||||
I0 = threadnum*Is;
|
||||
I1 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
|
||||
|
||||
for(I=I0;I<I1;I++)
|
||||
{
|
||||
Ix = I%dx;
|
||||
Iy = I/dx;
|
||||
|
||||
Ia = (Ix + x0) + (Iy + y0)*imgto->Ny;
|
||||
Ib = Ix + Iy*imgfrom->Ny;
|
||||
|
||||
v1 = imgto->data[Ia];
|
||||
v2 = imgfrom->data[Ib];
|
||||
if(v1<v2)
|
||||
imgto->data[Ia] = v2;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int amsbitplane::apply_bitplane(int x0, int y0, const amsbitplane *bp)
|
||||
{
|
||||
int ret = amsimage_success;
|
||||
|
||||
int dx,dy;
|
||||
int64_t N;
|
||||
|
||||
if(bp==NULL)
|
||||
{
|
||||
ret = amsimage_failure;
|
||||
return ret;
|
||||
}
|
||||
|
||||
dx = (bp->Nx < (this->Nx-x0)) ? bp->Nx : this->Nx-x0;
|
||||
dx = (dx<0) ? 0 : dx;
|
||||
dy = (bp->Ny < (this->Ny-y0)) ? bp->Ny : this->Ny-y0;
|
||||
dy = (dy<0) ? 0 : dy;
|
||||
N = dx*dy;
|
||||
|
||||
imglib4::threaded_execute(
|
||||
amsimage_apply_bitplane_tf, N,
|
||||
this,bp,x0,y0
|
||||
);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
}; //end namespace ams
|
@ -673,7 +673,7 @@ namespace ams
|
||||
|
||||
float Nxf,Nyf;
|
||||
//just do simple (0,N-1) interpolation for now
|
||||
int xi,yi;
|
||||
int xi,yi,xip,yip;
|
||||
float xif,yif,xr,yr;
|
||||
float w00,w01,w10,w11;
|
||||
amsfloatpixel p00,p01,p10,p11;
|
||||
@ -698,15 +698,19 @@ namespace ams
|
||||
w01 = (1.0-xr)*(yr);
|
||||
w11 = (xr)*(yr);
|
||||
|
||||
xip = xi + 1;
|
||||
yip = yi + 1;
|
||||
if(xi<0) xi = 0;
|
||||
if(xi>Nx-2) xi = Nx-2;
|
||||
if(xi>Nx-1) xi = Nx-1;
|
||||
if(yi<0) yi = 0;
|
||||
if(yi>Ny-2) yi = Ny-2;
|
||||
if(yi>Ny-1) yi = Ny-1;
|
||||
if(xip>Nx-1) xip = Nx-1;
|
||||
if(yip>Ny-1) yip = Ny-1;
|
||||
|
||||
p00 = get_pixel(xi,yi);
|
||||
p10 = get_pixel(xi+1,yi);
|
||||
p01 = get_pixel(xi,yi+1);
|
||||
p11 = get_pixel(xi+1,yi+1);
|
||||
p10 = get_pixel(xip,yi);
|
||||
p01 = get_pixel(xi,yip);
|
||||
p11 = get_pixel(xip,yip);
|
||||
|
||||
ret = p00*w00 + p10*w10 + p01*w01 + p11*w11;
|
||||
}
|
||||
@ -714,6 +718,8 @@ namespace ams
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void amsfloatimage_rescale_tf(
|
||||
int threadnum,
|
||||
int nthreads,
|
||||
|
@ -848,7 +848,7 @@ namespace ams
|
||||
|
||||
float Nxf,Nyf;
|
||||
//just do simple (0,N-1) interpolation for now
|
||||
int xi,yi;
|
||||
int xi,yi,xip,yip;
|
||||
float xif,yif,xr,yr;
|
||||
float w00,w01,w10,w11;
|
||||
amsfloatpixel p00,p01,p10,p11;
|
||||
@ -873,15 +873,19 @@ namespace ams
|
||||
w01 = (1.0-xr)*(yr);
|
||||
w11 = (xr)*(yr);
|
||||
|
||||
xip = xi + 1;
|
||||
yip = yi + 1;
|
||||
if(xi<0) xi = 0;
|
||||
if(xi>Nx-2) xi = Nx-2;
|
||||
if(xi>Nx-1) xi = Nx-1;
|
||||
if(yi<0) yi = 0;
|
||||
if(yi>Ny-2) yi = Ny-2;
|
||||
if(yi>Ny-1) yi = Ny-1;
|
||||
if(xip>Nx-1) xip = Nx-1;
|
||||
if(yip>Ny-1) yip = Ny-1;
|
||||
|
||||
p00 = get_fpixel(xi,yi);
|
||||
p10 = get_fpixel(xi+1,yi);
|
||||
p01 = get_fpixel(xi,yi+1);
|
||||
p11 = get_fpixel(xi+1,yi+1);
|
||||
p10 = get_fpixel(xip,yi);
|
||||
p01 = get_fpixel(xi,yip);
|
||||
p11 = get_fpixel(xip,yip);
|
||||
|
||||
ret = p00*w00 + p10*w10 + p01*w01 + p11*w11;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ namespace imglib4
|
||||
int offsety
|
||||
)
|
||||
{
|
||||
int64_t I,I0,I1,Is,N,Ix,Iy;
|
||||
int64_t I,I0,I1,Is,N,Ix,Iy,Ia,Ib;
|
||||
int dx,dy;
|
||||
|
||||
dx = Nxfrom;
|
||||
@ -32,26 +32,22 @@ namespace imglib4
|
||||
|
||||
N = dx*dy;
|
||||
|
||||
Is = N/nthreads; Is = (Is<1) ? 1 : N;
|
||||
Is = N/nthreads; Is = (Is<1) ? 1 : Is;
|
||||
I0 = (threadnum)*Is;
|
||||
I1 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
|
||||
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];
|
||||
Ia = (Ix+offsetx) + Nxto*(Iy+offsety);
|
||||
Ib = Ix + 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];
|
||||
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;
|
||||
@ -116,9 +112,9 @@ namespace imglib4
|
||||
dy = (dy<0) ? 0 : dy;
|
||||
N = dx*dy;
|
||||
|
||||
Is = N/nthreads; Is = (Is<1) ? 1 : N;
|
||||
Is = N/nthreads; Is = (Is<1) ? 1 : Is;
|
||||
I0 = (threadnum)*Is;
|
||||
I1 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
|
||||
I1 = (threadnum<(nthreads-1)) ? (threadnum+1)*Is : N;
|
||||
|
||||
for(I=I0;I<I1;I++)
|
||||
{
|
||||
@ -193,9 +189,9 @@ namespace imglib4
|
||||
|
||||
N = dx*dy;
|
||||
|
||||
Is = N/nthreads; Is = (Is<1) ? 1 : N;
|
||||
Is = N/nthreads; Is = (Is<1) ? 1 : Is;
|
||||
I0 = (threadnum)*Is;
|
||||
I1 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
|
||||
I1 = (threadnum<(nthreads-1)) ? (threadnum+1)*Is : N;
|
||||
|
||||
for(I=I0;I<I1;I++)
|
||||
{
|
||||
@ -272,7 +268,7 @@ namespace imglib4
|
||||
dy = (dy<0) ? 0 : dy;
|
||||
N = dx*dy;
|
||||
|
||||
Is = N/nthreads; Is = (Is<1) ? 1 : N;
|
||||
Is = N/nthreads; Is = (Is<1) ? 1 : Is;
|
||||
I0 = (threadnum)*Is;
|
||||
I1 = (threadnum<nthreads-1) ? (threadnum+1)*Is : N;
|
||||
|
||||
|
@ -63,6 +63,66 @@ namespace ams
|
||||
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void amscppimglib4_bitplane_alloc_tests()
|
||||
{
|
||||
amsbitplane bp1;
|
||||
int K;
|
||||
|
||||
printf("resize(100,100)\n");
|
||||
bp1.resize(100,100);
|
||||
printf("resize(0,0)\n");
|
||||
bp1.resize(0,0);
|
||||
printf("resize(100,100)\n");
|
||||
bp1.resize(100,100);
|
||||
printf("resize(1024,1024)\n");
|
||||
bp1.resize(1024,1024);
|
||||
printf("resize(0,0)\n");
|
||||
bp1.resize(0,0);
|
||||
printf("resize(-5,-5)\n");
|
||||
bp1.resize(-5,-5);
|
||||
printf("resize(0,0)\n");
|
||||
bp1.resize(0,0);
|
||||
printf("resize(1024,0)\n");
|
||||
bp1.resize(1024,0);
|
||||
printf("resize(1024,1024)\n");
|
||||
bp1.resize(1024,1024);
|
||||
printf("resize(1024,1024)\n");
|
||||
bp1.resize(1024,1024);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void amscppimglib4_image_alloc_tests()
|
||||
{
|
||||
amsimage bp1;
|
||||
int K;
|
||||
|
||||
printf("image allocation tests - how on earth is this failing and everything else working?!\n");
|
||||
printf("std::thread::hardware_concurrency() %d\n",(int)std::thread::hardware_concurrency());
|
||||
printf("resize(100,100)\n");
|
||||
bp1.resize(100,100);
|
||||
printf("resize(0,0)\n");
|
||||
bp1.resize(0,0);
|
||||
printf("resize(100,100)\n");
|
||||
bp1.resize(100,100);
|
||||
printf("resize(1024,1024)\n");
|
||||
bp1.resize(1024,1024);
|
||||
printf("resize(0,0)\n");
|
||||
bp1.resize(0,0);
|
||||
printf("resize(-5,-5)\n");
|
||||
bp1.resize(-5,-5);
|
||||
printf("resize(0,0)\n");
|
||||
bp1.resize(0,0);
|
||||
printf("resize(1024,0)\n");
|
||||
bp1.resize(1024,0);
|
||||
printf("resize(1024,1024)\n");
|
||||
bp1.resize(1024,1024);
|
||||
printf("resize(1024,1024)\n");
|
||||
bp1.resize(1024,1024);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,9 @@ int main(int argc, char* argv[])
|
||||
|
||||
//amscppimglib4_test1();
|
||||
//amscppimglib4_test2();
|
||||
amscppimglib4_bitplane_alloc_tests();
|
||||
//amscppimglib4_image_alloc_tests();
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
Reference in New Issue
Block a user