read write routine connection
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
#include <amscppimglib4/amscppimglib4.hpp>
|
||||
#include <amscppimglib4/amscppimglib4_intlutil.hpp>
|
||||
#include <amscimglib4/amscimglib4.h>
|
||||
|
||||
namespace ams
|
||||
{
|
||||
@ -458,4 +459,86 @@ namespace ams
|
||||
return data[Nc + 4*(I + Nx*J)];
|
||||
}
|
||||
|
||||
|
||||
int read_image(const char *fname, amsimage* image)
|
||||
{
|
||||
int ret = amsimage_success;
|
||||
int res;
|
||||
amscimglib4_image *im2 = NULL;
|
||||
|
||||
if(image==NULL)
|
||||
{
|
||||
ret = amsimage_failure;
|
||||
printf("read_image: Error: image pointer is null.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
res = amscimglib4_image_new(&im2,1,1);
|
||||
if(res!=amscimglib4_success)
|
||||
{
|
||||
ret = amsimage_failure;
|
||||
printf("read_image: Error: c image struct failed to allocate.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
amscimglib4_readimage(fname,im2);
|
||||
//you can NOT move buffers. The im2 buffers are created with malloc, not new. No pseudo-move-semantics for you!
|
||||
|
||||
//copy buffers
|
||||
res = image->resize(im2->sizex,im2->sizey);
|
||||
if(res!=amsimage_success)
|
||||
{
|
||||
ret = amsimage_failure;
|
||||
amscimglib4_image_delete(&im2);
|
||||
printf("read_image: Error: c++ image failed to allocate.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
//both structures have the same memory layout, so the internal copy function works
|
||||
imglib4::amsimage_region_copy(
|
||||
image->data,image->Nx,image->Ny,
|
||||
im2->data,im2->sizex,im2->sizey,
|
||||
0,0
|
||||
);
|
||||
|
||||
|
||||
amscimglib4_image_delete(&im2);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int write_image(const char *fname, amsimage* image)
|
||||
{
|
||||
int ret = amsimage_success;
|
||||
int res;
|
||||
amscimglib4_image *im2 = NULL;
|
||||
|
||||
if(image==NULL)
|
||||
{
|
||||
ret = amsimage_failure;
|
||||
printf("write_image: Error: image pointer is null.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
res = amscimglib4_image_new(&im2,image->Nx,image->Ny);
|
||||
if(res!=amscimglib4_success)
|
||||
{
|
||||
ret = amsimage_failure;
|
||||
printf("write_image: Error: c image struct failed to allocate.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
//both structures have the same memory layout, so the internal copy function works
|
||||
imglib4::amsimage_region_copy(
|
||||
im2->data,im2->sizex,im2->sizey,
|
||||
image->data,image->Nx,image->Ny,
|
||||
0,0
|
||||
);
|
||||
|
||||
amscimglib4_writeimage(fname,im2);
|
||||
|
||||
amscimglib4_image_delete(&im2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
};
|
Reference in New Issue
Block a user