out of day already, damn
This commit is contained in:
Binary file not shown.
Binary file not shown.
@ -34,6 +34,19 @@ namespace ams
|
||||
const uint8_t& operator[](const int ind) const;
|
||||
};
|
||||
|
||||
//a floating point pixel, normalized so that RGBA is
|
||||
// between 0 and 1
|
||||
struct amsfloatpixel
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
class amsimage
|
||||
{
|
||||
public:
|
||||
@ -79,13 +92,15 @@ namespace ams
|
||||
//todo
|
||||
|
||||
//applies image with alpha blending
|
||||
int apply_image(int I0, int J0, amsimage *img);
|
||||
int apply_image(int x0, int y0, const amsimage *img);
|
||||
|
||||
//applied color to any pixels where the bitplane's value is >= thresh
|
||||
int apply_bitplane_nz(int I0, int J0, amsbitplane* bp, amspixel color, uint8_t thresh);
|
||||
|
||||
int apply_bitplane_mask(int x0, int y0, const amsbitplane* bp, amspixel color, uint8_t thresh);
|
||||
|
||||
amsfloatpixel interpolate(float x, float y);
|
||||
|
||||
//rescales the image with linear interpolation
|
||||
int rescale(int nnx, int nny);
|
||||
amsimage rescale(int nnx, int nny);
|
||||
};
|
||||
|
||||
int read_image(const char *fname, amsimage* image);
|
||||
@ -129,7 +144,7 @@ namespace ams
|
||||
void setall(uint8_t val);
|
||||
|
||||
//rescales the image with linear interpolation
|
||||
int rescale(int _Nx, int _Ny); //todo
|
||||
amsbitplane rescale(int _Nx, int _Ny); //todo
|
||||
};
|
||||
|
||||
|
||||
|
@ -632,4 +632,191 @@ namespace ams
|
||||
return ret;
|
||||
}
|
||||
|
||||
void amsimage_apply_image_tf(
|
||||
int threadnum,
|
||||
int nthreads,
|
||||
amsimage *imgto,
|
||||
const amsimage *imgfrom,
|
||||
int x0, int y0
|
||||
)
|
||||
{
|
||||
int dx,dy;
|
||||
int64_t N;
|
||||
int64_t I,I0,I1,Is,Ix,Iy,Ia,Ib;
|
||||
double r1,g1,b1,a1;
|
||||
double r2,g2,b2,a2;
|
||||
double r3,g3,b3,a3;
|
||||
int r3i,g3i,b3i,a3i;
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
r1 = imgto->data[0 + 4*Ia]/255.0;
|
||||
g1 = imgto->data[1 + 4*Ia]/255.0;
|
||||
b1 = imgto->data[2 + 4*Ia]/255.0;
|
||||
a1 = imgto->data[3 + 4*Ia]/255.0;
|
||||
|
||||
r2 = imgfrom->data[0 + 4*Ib]/255.0;
|
||||
g2 = imgfrom->data[1 + 4*Ib]/255.0;
|
||||
b2 = imgfrom->data[2 + 4*Ib]/255.0;
|
||||
a2 = imgfrom->data[3 + 4*Ib]/255.0;
|
||||
|
||||
r3 = r1 + r2*(1.0-a2);
|
||||
g3 = g1 + g2*(1.0-a2);
|
||||
b3 = b1 + b2*(1.0-a2);
|
||||
a3 = 1.0-(1.0-a1)*(1.0-a2);
|
||||
|
||||
r3i = (int)(r3*255.0);
|
||||
g3i = (int)(g3*255.0);
|
||||
b3i = (int)(b3*255.0);
|
||||
a3i = (int)(a3*255.0);
|
||||
|
||||
r3i = (r3i>255) ? 255 : r3i;
|
||||
g3i = (g3i>255) ? 255 : g3i;
|
||||
b3i = (b3i>255) ? 255 : b3i;
|
||||
a3i = (a3i>255) ? 255 : a3i;
|
||||
|
||||
|
||||
imgto->data[0 + 4*Ia] = r3i;
|
||||
imgto->data[1 + 4*Ia] = g3i;
|
||||
imgto->data[2 + 4*Ia] = b3i;
|
||||
imgto->data[3 + 4*Ia] = a3i;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int amsimage::apply_image(int x0, int y0, const amsimage *img)
|
||||
{
|
||||
int ret = amsimage_success;
|
||||
|
||||
int dx,dy;
|
||||
int64_t N;
|
||||
|
||||
if(img==NULL)
|
||||
{
|
||||
ret = amsimage_failure;
|
||||
return ret;
|
||||
}
|
||||
|
||||
dx = (img->Nx < (this->Nx-x0)) ? img->Nx : this->Nx-x0;
|
||||
dx = (dx<0) ? 0 : dx;
|
||||
dy = (img->Ny < (this->Ny-y0)) ? img->Ny : this->Ny-y0;
|
||||
dy = (dy<0) ? 0 : dy;
|
||||
N = dx*dy;
|
||||
|
||||
imglib4::threaded_execute(
|
||||
amsimage_apply_image_tf, N,
|
||||
this,img,x0,y0
|
||||
);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void amsimage_apply_bitplanemask_tf(
|
||||
int threadnum,
|
||||
int nthreads,
|
||||
amsimage *imgto,
|
||||
const amsbitplane *bpfrom,
|
||||
amspixel color,
|
||||
int x0, int y0,
|
||||
uint8_t thresh
|
||||
)
|
||||
{
|
||||
int dx,dy;
|
||||
int64_t N;
|
||||
int64_t I,I0,I1,Is,Ix,Iy,Ia,Ib;
|
||||
|
||||
|
||||
dx = (bpfrom->Nx < (imgto->Nx-x0)) ? bpfrom->Nx : imgto->Nx-x0;
|
||||
dx = (dx<0) ? 0 : dx;
|
||||
dy = (bpfrom->Ny < (imgto->Ny-y0)) ? bpfrom->Ny : imgto->Ny-y0;
|
||||
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;
|
||||
|
||||
Ia = (Ix+x0) + imgto->Nx*(Iy+y0);
|
||||
Ib = Ix + bpfrom->Nx*Iy;
|
||||
|
||||
if(bpfrom->data[Ib]>=thresh)
|
||||
{
|
||||
imgto->data[0 + 4*Ia] = color.R;
|
||||
imgto->data[1 + 4*Ia] = color.G;
|
||||
imgto->data[2 + 4*Ia] = color.B;
|
||||
imgto->data[3 + 4*Ia] = color.A;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//applied color to any pixels where the bitplane's value is >= thresh
|
||||
int amsimage::apply_bitplane_mask(int x0, int y0, const amsbitplane* bp, amspixel color, uint8_t thresh)
|
||||
{
|
||||
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_bitplanemask_tf, N,
|
||||
this,bp,color,x0,y0,thresh
|
||||
);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
amsfloatpixel amsimage::interpolate(float x, float y)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void amsimage_rescale_tf(
|
||||
int threadnum,
|
||||
int nthreads,
|
||||
amsimage *imgto,
|
||||
const amsimage *imgfrom
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
amsimage amsimage::rescale(int nnx, int nny)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
};
|
Reference in New Issue
Block a user