bla
This commit is contained in:
@ -8,6 +8,9 @@
|
||||
},
|
||||
{
|
||||
"path": "../amscimglib4"
|
||||
},
|
||||
{
|
||||
"path": "../amsmathutil25"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -41,10 +41,16 @@ namespace ams
|
||||
public:
|
||||
float R,G,B,A;
|
||||
|
||||
amspixel();
|
||||
amspixel(float _R ,float _G, float _B, float _A);
|
||||
uint8_t& operator[](const int ind);
|
||||
const uint8_t& operator[](const int ind) const;
|
||||
amsfloatpixel();
|
||||
amsfloatpixel(float _R ,float _G, float _B, float _A);
|
||||
float& operator[](const int ind);
|
||||
const float& operator[](const int ind) const;
|
||||
|
||||
amsfloatpixel operator+(amsfloatpixel rhs);
|
||||
amsfloatpixel operator-(amsfloatpixel rhs);
|
||||
amsfloatpixel operator*(float rhs);
|
||||
amsfloatpixel operator/(float rhs);
|
||||
|
||||
};
|
||||
|
||||
class amsimage
|
||||
@ -82,6 +88,9 @@ namespace ams
|
||||
uint8_t& operator()(int Nc, int I, int J);
|
||||
const uint8_t& operator()(int Nc, int I, int J) const;
|
||||
|
||||
amsfloatpixel get_fpixel(int x, int y) const;
|
||||
int set_fpixel(int x, int y, amsfloatpixel p);
|
||||
|
||||
void clear();
|
||||
void setall(amspixel color);
|
||||
|
||||
@ -97,7 +106,7 @@ namespace ams
|
||||
//applied color to any pixels where the bitplane's value is >= thresh
|
||||
int apply_bitplane_mask(int x0, int y0, const amsbitplane* bp, amspixel color, uint8_t thresh);
|
||||
|
||||
amsfloatpixel interpolate(float x, float y);
|
||||
amsfloatpixel interpolate(float x, float y) const;
|
||||
|
||||
//rescales the image with linear interpolation
|
||||
amsimage rescale(int nnx, int nny);
|
||||
@ -138,6 +147,10 @@ namespace ams
|
||||
const uint8_t& operator()(int I, int J) const;
|
||||
uint8_t& operator[](long I);
|
||||
const uint8_t& operator[](long I) const;
|
||||
|
||||
float getf(int x, int y) const;
|
||||
int setf(int x, int y, float f) const;
|
||||
float interpolate(int x, int y);
|
||||
|
||||
|
||||
void clear();
|
||||
|
@ -104,8 +104,10 @@ void amsimage_planeregion_set(
|
||||
uint8_t val
|
||||
);
|
||||
|
||||
|
||||
|
||||
double mod(double x, double n);
|
||||
float mod(float x, float n);
|
||||
int32_t mod(int32_t x, int32_t n);
|
||||
int64_t mod(int64_t x, int64_t n);
|
||||
|
||||
}; //end namespace imglib4
|
||||
}; //end namespace ams
|
||||
|
@ -799,9 +799,94 @@ namespace ams
|
||||
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(
|
||||
@ -811,12 +896,49 @@ namespace ams
|
||||
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 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;
|
||||
}
|
||||
|
||||
};
|
@ -33,5 +33,80 @@ const uint8_t& amspixel::operator[](const int ind) const
|
||||
return A;
|
||||
}
|
||||
|
||||
amsfloatpixel::amsfloatpixel()
|
||||
{
|
||||
R = 0.0;
|
||||
G = 0.0;
|
||||
B = 0.0;
|
||||
A = 0.0;
|
||||
return;
|
||||
}
|
||||
|
||||
amsfloatpixel::amsfloatpixel(float _R ,float _G, float _B, float _A)
|
||||
{
|
||||
R = _R; G = _G; B = _B; A = _A;
|
||||
return;
|
||||
}
|
||||
|
||||
float& amsfloatpixel::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 float& amsfloatpixel::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;
|
||||
}
|
||||
|
||||
amsfloatpixel amsfloatpixel::operator+(amsfloatpixel rhs)
|
||||
{
|
||||
amsfloatpixel ret;
|
||||
ret.R = R + rhs.R;
|
||||
ret.G = G + rhs.G;
|
||||
ret.B = B + rhs.B;
|
||||
ret.A = A + rhs.A;
|
||||
return ret;
|
||||
}
|
||||
|
||||
amsfloatpixel amsfloatpixel::operator-(amsfloatpixel rhs)
|
||||
{
|
||||
amsfloatpixel ret;
|
||||
ret.R = R - rhs.R;
|
||||
ret.G = G - rhs.G;
|
||||
ret.B = B - rhs.B;
|
||||
ret.A = A - rhs.A;
|
||||
return ret;
|
||||
}
|
||||
|
||||
amsfloatpixel amsfloatpixel::operator*(float rhs)
|
||||
{
|
||||
amsfloatpixel ret;
|
||||
ret.R = R*rhs;
|
||||
ret.G = G*rhs;
|
||||
ret.B = B*rhs;
|
||||
ret.A = A*rhs;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
amsfloatpixel amsfloatpixel::operator/(float rhs)
|
||||
{
|
||||
amsfloatpixel ret;
|
||||
ret.R = R/rhs;
|
||||
ret.G = G/rhs;
|
||||
ret.B = B/rhs;
|
||||
ret.A = A/rhs;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
};
|
@ -318,5 +318,44 @@ namespace imglib4
|
||||
return;
|
||||
}
|
||||
|
||||
double mod(double x, double n)
|
||||
{
|
||||
x = ::fmod(x,n);
|
||||
if(x<0)
|
||||
{
|
||||
x = x + n;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
float mod(float x, float n)
|
||||
{
|
||||
x = ::fmodf(x,n);
|
||||
if(x<0)
|
||||
{
|
||||
x = x + n;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
int32_t mod(int32_t x, int32_t n)
|
||||
{
|
||||
x = x % n;
|
||||
if(x<0)
|
||||
{
|
||||
x = x + n;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
int64_t mod(int64_t x, int64_t n)
|
||||
{
|
||||
x = x % n;
|
||||
if(x<0)
|
||||
{
|
||||
x = x + n;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
}; //end namespace imglib4
|
||||
}; //end namespace ams
|
Reference in New Issue
Block a user