|
|
@ -799,9 +799,94 @@ namespace ams
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
amsfloatpixel amsimage::interpolate(float x, float y)
|
|
|
|
|
|
|
|
|
|
|
|
amsfloatpixel amsimage::get_fpixel(int x, int y) const
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
amsfloatpixel p;
|
|
|
|
|
|
|
|
amspixel pi;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pi = get_pixel(x,y);
|
|
|
|
|
|
|
|
p.R = (float)pi.R/(255.0);
|
|
|
|
|
|
|
|
p.G = (float)pi.G/(255.0);
|
|
|
|
|
|
|
|
p.B = (float)pi.B/(255.0);
|
|
|
|
|
|
|
|
p.A = (float)pi.A/(255.0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return p;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int amsimage::set_fpixel(int x, int y, amsfloatpixel p)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int ret = amsimage_failure;
|
|
|
|
|
|
|
|
amspixel pi;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(x>=0 && x<Nx && y>=0 && y<Ny)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ret = amsimage_success;
|
|
|
|
|
|
|
|
if(p.R<0.0f) p.R = 0.0f;
|
|
|
|
|
|
|
|
if(p.R>1.0f) p.R = 1.0f;
|
|
|
|
|
|
|
|
if(p.G<0.0f) p.G = 0.0f;
|
|
|
|
|
|
|
|
if(p.G>1.0f) p.G = 1.0f;
|
|
|
|
|
|
|
|
if(p.B<0.0f) p.B = 0.0f;
|
|
|
|
|
|
|
|
if(p.B>1.0f) p.B = 1.0f;
|
|
|
|
|
|
|
|
if(p.A<0.0f) p.A = 0.0f;
|
|
|
|
|
|
|
|
if(p.A>1.0f) p.A = 1.0f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pi.R = (int)(p.R*255.0f);
|
|
|
|
|
|
|
|
pi.G = (int)(p.G*255.0f);
|
|
|
|
|
|
|
|
pi.B = (int)(p.B*255.0f);
|
|
|
|
|
|
|
|
pi.A = (int)(p.A*255.0f);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set_pixel(x,y,pi);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
amsfloatpixel amsimage::interpolate(float x, float y) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
amsfloatpixel ret = amsfloatpixel(0.0,0.0,0.0,0.0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float Nxf,Nyf;
|
|
|
|
|
|
|
|
//just do simple (0,N-1) interpolation for now
|
|
|
|
|
|
|
|
int xi,yi;
|
|
|
|
|
|
|
|
float xif,yif,xr,yr;
|
|
|
|
|
|
|
|
float w00,w01,w10,w11;
|
|
|
|
|
|
|
|
amsfloatpixel 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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(xi<0) xi = 0;
|
|
|
|
|
|
|
|
if(xi>Nx-2) xi = Nx-2;
|
|
|
|
|
|
|
|
if(yi<0) yi = 0;
|
|
|
|
|
|
|
|
if(yi>Ny-2) yi = Ny-2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p00 = get_fpixel(xi,yi);
|
|
|
|
|
|
|
|
p10 = get_fpixel(xi+1,yi);
|
|
|
|
|
|
|
|
p01 = get_fpixel(xi,yi+1);
|
|
|
|
|
|
|
|
p11 = get_fpixel(xi+1,yi+1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ret = p00*w00 + p10*w10 + p01*w01 + p11*w11;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void amsimage_rescale_tf(
|
|
|
|
void amsimage_rescale_tf(
|
|
|
@ -811,12 +896,49 @@ namespace ams
|
|
|
|
const amsimage *imgfrom
|
|
|
|
const amsimage *imgfrom
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
int Nx = imgto->Nx;
|
|
|
|
|
|
|
|
int Ny = imgto->Ny;
|
|
|
|
|
|
|
|
int64_t I,I0,I1,Is,N,Ix,Iy;
|
|
|
|
|
|
|
|
amsfloatpixel 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->set_fpixel(Ix,Iy,p);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
amsimage amsimage::rescale(int nnx, int nny)
|
|
|
|
amsimage amsimage::rescale(int nnx, int nny)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
amsimage 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(
|
|
|
|
|
|
|
|
amsimage_rescale_tf, nnx*nny,
|
|
|
|
|
|
|
|
&ret,this
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|