fixed subimage logic

This commit is contained in:
2025-10-24 12:50:49 -04:00
parent 566c04f6e8
commit e7784ccfef
16 changed files with 115 additions and 25 deletions
-3
View File
@@ -3,9 +3,6 @@
{ {
"path": "." "path": "."
}, },
{
"path": "../../sourceprojs23/amsimglib3"
},
{ {
"path": "../amscimglib4" "path": "../amscimglib4"
}, },
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+6 -2
View File
@@ -115,6 +115,12 @@ namespace ams
int read_image(const char *fname, amsimage* image); int read_image(const char *fname, amsimage* image);
int write_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 class amsbitplane
{ {
public: public:
@@ -216,8 +222,6 @@ namespace ams
}; };
}; //end namespace ams }; //end namespace ams
#include <amscppimglib4/amscppimglib4_tests.hpp> #include <amscppimglib4/amscppimglib4_tests.hpp>
+23 -20
View File
@@ -22,12 +22,12 @@ namespace imglib4
int64_t I,I0,I1,Is,N,Ix,Iy,Ia,Ib; int64_t I,I0,I1,Is,N,Ix,Iy,Ia,Ib;
int dx,dy; int dx,dy;
dx = Nxfrom; dx = Nxto;
dx = (dx>(Nxto-offsetx)) ? (Nxto-offsetx) : dx; dx = (dx>(Nxfrom-offsetx)) ? (Nxfrom-offsetx) : dx;
dx = (dx<0) ? 0 : dx; dx = (dx<0) ? 0 : dx;
dy = Nyfrom; dy = Nyto;
dy = (dy>(Nyto-offsety)) ? (Nyto-offsety) : dy; dy = (dy>(Nyfrom-offsety)) ? (Nyfrom-offsety) : dy;
dy = (dy<0) ? 0 : dy; dy = (dy<0) ? 0 : dy;
N = dx*dy; N = dx*dy;
@@ -41,8 +41,8 @@ namespace imglib4
Ix = I%dx; Ix = I%dx;
Iy = I/dx; Iy = I/dx;
Ia = (Ix+offsetx) + Nxto*(Iy+offsety); Ia = (Ix) + Nxto*(Iy);
Ib = Ix + Nxfrom*Iy; Ib = (Ix+offsetx) + Nxfrom*(Iy+offsety);
datato[0 + 4*Ia] = datafrom[0 + 4*Ib]; datato[0 + 4*Ia] = datafrom[0 + 4*Ib];
datato[1 + 4*Ia] = datafrom[1 + 4*Ib]; datato[1 + 4*Ia] = datafrom[1 + 4*Ib];
@@ -70,12 +70,12 @@ namespace imglib4
if(datato==NULL) return; if(datato==NULL) return;
if(datafrom==NULL) return; if(datafrom==NULL) return;
dx = Nxfrom; dx = Nxto;
dx = (dx>(Nxto-offsetx)) ? (Nxto-offsetx) : dx; dx = (dx>(Nxfrom-offsetx)) ? (Nxfrom-offsetx) : dx;
dx = (dx<0) ? 0 : dx; dx = (dx<0) ? 0 : dx;
dy = Nyfrom; dy = Nyto;
dy = (dy>(Nyto-offsety)) ? (Nyto-offsety) : dy; dy = (dy>(Nyfrom-offsety)) ? (Nyfrom-offsety) : dy;
dy = (dy<0) ? 0 : dy; dy = (dy<0) ? 0 : dy;
N = dx*dy; N = dx*dy;
@@ -179,12 +179,12 @@ namespace imglib4
int64_t I,I0,I1,Is,N,Ix,Iy,Ia,Ib; int64_t I,I0,I1,Is,N,Ix,Iy,Ia,Ib;
int dx,dy; int dx,dy;
dx = Nxfrom; dx = Nxto;
dx = (dx>(Nxto-offsetx)) ? (Nxto-offsetx) : dx; dx = (dx>(Nxfrom-offsetx)) ? (Nxfrom-offsetx) : dx;
dx = (dx<0) ? 0 : dx; dx = (dx<0) ? 0 : dx;
dy = Nyfrom; dy = Nyto;
dy = (dy>(Nyto-offsety)) ? (Nyto-offsety) : dy; dy = (dy>(Nyfrom-offsety)) ? (Nyfrom-offsety) : dy;
dy = (dy<0) ? 0 : dy; dy = (dy<0) ? 0 : dy;
N = dx*dy; N = dx*dy;
@@ -198,8 +198,11 @@ namespace imglib4
Ix = I%dx; Ix = I%dx;
Iy = I/dx; Iy = I/dx;
Ia = Ipto + Npto*((Ix+offsetx) + Nxto*(Iy+offsety)); // Ia = Ipto + Npto*((Ix+offsetx) + Nxto*(Iy+offsety));
Ib = Ipfrom + Npfrom*(Ix + Nxfrom*Iy); // Ib = Ipfrom + Npfrom*(Ix + Nxfrom*Iy);
Ia = Ipto + Npto*((Ix) + Nxto*(Iy));
Ib = Ipfrom + Npfrom*((Ix+offsetx) + Nxfrom*(Iy+offsety));
datato[Ia] = datafrom[Ib]; datato[Ia] = datafrom[Ib];
} }
@@ -228,12 +231,12 @@ namespace imglib4
if(datato==NULL) return; if(datato==NULL) return;
if(datafrom==NULL) return; if(datafrom==NULL) return;
dx = Nxfrom; dx = Nxto;
dx = (dx>(Nxto-offsetx)) ? (Nxto-offsetx) : dx; dx = (dx>(Nxfrom-offsetx)) ? (Nxfrom-offsetx) : dx;
dx = (dx<0) ? 0 : dx; dx = (dx<0) ? 0 : dx;
dy = Nyfrom; dy = Nyto;
dy = (dy>(Nyto-offsety)) ? (Nyto-offsety) : dy; dy = (dy>(Nyfrom-offsety)) ? (Nyfrom-offsety) : dy;
dy = (dy<0) ? 0 : dy; dy = (dy<0) ? 0 : dy;
N = dx*dy; N = dx*dy;
@@ -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;
}
};