fixed subimage logic
This commit is contained in:
@ -3,9 +3,6 @@
|
||||
{
|
||||
"path": "."
|
||||
},
|
||||
{
|
||||
"path": "../../sourceprojs23/amsimglib3"
|
||||
},
|
||||
{
|
||||
"path": "../amscimglib4"
|
||||
},
|
||||
|
||||
BIN
build/__pycache__/amsbuildlib4.cpython-311.pyc
Normal file
BIN
build/__pycache__/amsbuildlib4.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
build_linux64/objstore/amscppimglib4_pngbytes.o
Normal file
BIN
build_linux64/objstore/amscppimglib4_pngbytes.o
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
build_mingw64/objstore/amscppimglib4_pngbytes.o
Normal file
BIN
build_mingw64/objstore/amscppimglib4_pngbytes.o
Normal file
Binary file not shown.
Binary file not shown.
@ -115,6 +115,12 @@ namespace ams
|
||||
int read_image(const char *fname, amsimage* image);
|
||||
int write_image(const char *fname, amsimage* image);
|
||||
|
||||
//functions to manipulate png compressed images in memory
|
||||
int image_to_pngbytes(amsimage *image, unsigned char *pngbytes, long bytes_available, long *bytes_written);
|
||||
long image_to_pngbytes_bytesneeded(amsimage *image);
|
||||
int pngbytes_to_image(unsigned char *pngbytes, long bufferlength, amsimage *image);
|
||||
|
||||
|
||||
class amsbitplane
|
||||
{
|
||||
public:
|
||||
@ -216,8 +222,6 @@ namespace ams
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
}; //end namespace ams
|
||||
|
||||
#include <amscppimglib4/amscppimglib4_tests.hpp>
|
||||
|
||||
@ -22,12 +22,12 @@ namespace imglib4
|
||||
int64_t I,I0,I1,Is,N,Ix,Iy,Ia,Ib;
|
||||
int dx,dy;
|
||||
|
||||
dx = Nxfrom;
|
||||
dx = (dx>(Nxto-offsetx)) ? (Nxto-offsetx) : dx;
|
||||
dx = Nxto;
|
||||
dx = (dx>(Nxfrom-offsetx)) ? (Nxfrom-offsetx) : dx;
|
||||
dx = (dx<0) ? 0 : dx;
|
||||
|
||||
dy = Nyfrom;
|
||||
dy = (dy>(Nyto-offsety)) ? (Nyto-offsety) : dy;
|
||||
dy = Nyto;
|
||||
dy = (dy>(Nyfrom-offsety)) ? (Nyfrom-offsety) : dy;
|
||||
dy = (dy<0) ? 0 : dy;
|
||||
|
||||
N = dx*dy;
|
||||
@ -41,8 +41,8 @@ namespace imglib4
|
||||
Ix = I%dx;
|
||||
Iy = I/dx;
|
||||
|
||||
Ia = (Ix+offsetx) + Nxto*(Iy+offsety);
|
||||
Ib = Ix + Nxfrom*Iy;
|
||||
Ia = (Ix) + Nxto*(Iy);
|
||||
Ib = (Ix+offsetx) + Nxfrom*(Iy+offsety);
|
||||
|
||||
datato[0 + 4*Ia] = datafrom[0 + 4*Ib];
|
||||
datato[1 + 4*Ia] = datafrom[1 + 4*Ib];
|
||||
@ -70,12 +70,12 @@ namespace imglib4
|
||||
if(datato==NULL) return;
|
||||
if(datafrom==NULL) return;
|
||||
|
||||
dx = Nxfrom;
|
||||
dx = (dx>(Nxto-offsetx)) ? (Nxto-offsetx) : dx;
|
||||
dx = Nxto;
|
||||
dx = (dx>(Nxfrom-offsetx)) ? (Nxfrom-offsetx) : dx;
|
||||
dx = (dx<0) ? 0 : dx;
|
||||
|
||||
dy = Nyfrom;
|
||||
dy = (dy>(Nyto-offsety)) ? (Nyto-offsety) : dy;
|
||||
dy = Nyto;
|
||||
dy = (dy>(Nyfrom-offsety)) ? (Nyfrom-offsety) : dy;
|
||||
dy = (dy<0) ? 0 : dy;
|
||||
|
||||
N = dx*dy;
|
||||
@ -179,12 +179,12 @@ namespace imglib4
|
||||
int64_t I,I0,I1,Is,N,Ix,Iy,Ia,Ib;
|
||||
int dx,dy;
|
||||
|
||||
dx = Nxfrom;
|
||||
dx = (dx>(Nxto-offsetx)) ? (Nxto-offsetx) : dx;
|
||||
dx = Nxto;
|
||||
dx = (dx>(Nxfrom-offsetx)) ? (Nxfrom-offsetx) : dx;
|
||||
dx = (dx<0) ? 0 : dx;
|
||||
|
||||
dy = Nyfrom;
|
||||
dy = (dy>(Nyto-offsety)) ? (Nyto-offsety) : dy;
|
||||
dy = Nyto;
|
||||
dy = (dy>(Nyfrom-offsety)) ? (Nyfrom-offsety) : dy;
|
||||
dy = (dy<0) ? 0 : dy;
|
||||
|
||||
N = dx*dy;
|
||||
@ -198,8 +198,11 @@ namespace imglib4
|
||||
Ix = I%dx;
|
||||
Iy = I/dx;
|
||||
|
||||
Ia = Ipto + Npto*((Ix+offsetx) + Nxto*(Iy+offsety));
|
||||
Ib = Ipfrom + Npfrom*(Ix + Nxfrom*Iy);
|
||||
// Ia = Ipto + Npto*((Ix+offsetx) + Nxto*(Iy+offsety));
|
||||
// Ib = Ipfrom + Npfrom*(Ix + Nxfrom*Iy);
|
||||
|
||||
Ia = Ipto + Npto*((Ix) + Nxto*(Iy));
|
||||
Ib = Ipfrom + Npfrom*((Ix+offsetx) + Nxfrom*(Iy+offsety));
|
||||
|
||||
datato[Ia] = datafrom[Ib];
|
||||
}
|
||||
@ -228,12 +231,12 @@ namespace imglib4
|
||||
if(datato==NULL) return;
|
||||
if(datafrom==NULL) return;
|
||||
|
||||
dx = Nxfrom;
|
||||
dx = (dx>(Nxto-offsetx)) ? (Nxto-offsetx) : dx;
|
||||
dx = Nxto;
|
||||
dx = (dx>(Nxfrom-offsetx)) ? (Nxfrom-offsetx) : dx;
|
||||
dx = (dx<0) ? 0 : dx;
|
||||
|
||||
dy = Nyfrom;
|
||||
dy = (dy>(Nyto-offsety)) ? (Nyto-offsety) : dy;
|
||||
dy = Nyto;
|
||||
dy = (dy>(Nyfrom-offsety)) ? (Nyfrom-offsety) : dy;
|
||||
dy = (dy<0) ? 0 : dy;
|
||||
|
||||
N = dx*dy;
|
||||
|
||||
86
src/amscppimglib4/amscppimglib4_pngbytes.cpp
Normal file
86
src/amscppimglib4/amscppimglib4_pngbytes.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
|
||||
#include <amscppimglib4/amscppimglib4.hpp>
|
||||
#include <amscppimglib4/amscppimglib4_intlutil.hpp>
|
||||
#include <amscimglib4/amscimglib4.h>
|
||||
|
||||
namespace ams
|
||||
{
|
||||
|
||||
//functions to manipulate png compressed images in memory
|
||||
|
||||
long image_to_pngbytes_bytesneeded(amsimage *image)
|
||||
{
|
||||
long ret = 0;
|
||||
amscimglib4_image dummyimg;
|
||||
|
||||
dummyimg.data = image->data;
|
||||
dummyimg.sizex = image->Nx;
|
||||
dummyimg.sizey = image->Ny;
|
||||
|
||||
ret = amscimglib4_pngbytebufferlen(&dummyimg);
|
||||
|
||||
|
||||
dummyimg.data = NULL;
|
||||
dummyimg.sizex = 0;
|
||||
dummyimg.sizey = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int image_to_pngbytes(amsimage *image, unsigned char *pngbytes, long bytes_available, long *bytes_written)
|
||||
{
|
||||
int ret = amsimage_success;
|
||||
long lbytes_written;
|
||||
amscimglib4_image dummyimg;
|
||||
int res;
|
||||
|
||||
dummyimg.data = image->data;
|
||||
dummyimg.sizex = image->Nx;
|
||||
dummyimg.sizey = image->Ny;
|
||||
|
||||
res = amscimglib4_pngbytebuffer_from_img(&dummyimg,pngbytes,bytes_available, &lbytes_written);
|
||||
if(bytes_written!=NULL) *bytes_written = lbytes_written;
|
||||
if(res==amscimglib4_failure)
|
||||
{
|
||||
ret = amsimage_failure;
|
||||
}
|
||||
|
||||
dummyimg.data = NULL;
|
||||
dummyimg.sizex = 0;
|
||||
dummyimg.sizey = 0;
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int pngbytes_to_image(unsigned char *pngbytes, long bufferlength, amsimage *image)
|
||||
{
|
||||
int ret = amsimage_success;
|
||||
int res;
|
||||
amscimglib4_image *dummyimg = NULL;
|
||||
|
||||
amscimglib4_image_new(&dummyimg,1,1);
|
||||
|
||||
res = amscimglib4_pngbytebuffer_to_img(dummyimg,pngbytes,bufferlength);
|
||||
if(res == amscimglib4_failure)
|
||||
{
|
||||
ret = amsimage_failure;
|
||||
return ret;
|
||||
}
|
||||
|
||||
image->resize(dummyimg->sizex,dummyimg->sizey);
|
||||
imglib4::amsimage_region_copy(
|
||||
image->data,
|
||||
image->Nx,image->Ny,
|
||||
dummyimg->data,dummyimg->sizex,dummyimg->sizey,0,0
|
||||
);
|
||||
|
||||
|
||||
amscimglib4_image_delete(&dummyimg);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user