Skip to content

Commit

Permalink
output image macro
Browse files Browse the repository at this point in the history
  • Loading branch information
oguyon committed Sep 23, 2023
1 parent ba863d7 commit 3f25f2f
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 25 deletions.
76 changes: 68 additions & 8 deletions src/CommandLineInterface/CLIcore/CLIcore_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@ typedef struct
CLIARG_VISIBLE_DEFAULT, (void **) &imkey.name \
}






typedef struct
{
char *name;
uint32_t *xsize;
uint32_t *ysize;
uint32_t *datatype;
uint32_t *shared;
uint32_t *NBkw;
uint32_t *CBsize;
Expand Down Expand Up @@ -112,6 +118,31 @@ typedef struct
CLIARG_HIDDEN_DEFAULT, (void **) &imkey.CBsize, NULL \
}



// connect to and/or create output 2D image/stream
//
#define FARG_OUTIM2DCREATE(imkey, img, data_type) \
IMGID img = mkIMGID_from_name(imkey.name); \
img.shared = *imkey.shared; \
img.NBkw = *imkey.NBkw; \
img.CBsize = *imkey.CBsize; \
if(*imkey.shared == 1) { \
img = stream_connect_create_2D(imkey.name, *imkey.xsize, *imkey.ysize, data_type); \
} else { \
img.naxis = 2;\
img.size[0] = *imkey.xsize;\
img.size[1] = *imkey.ysize;\
img.datatype = data_type;\
createimagefromIMGID(&img); \
} \
imcreateIMGID(&img);






// binding between variables and function args/params
#define STD_FARG_LINKfunction \
for (int argi = 0; argi < (int) (sizeof(farg) / sizeof(CLICMDARGDEF)); \
Expand All @@ -126,6 +157,18 @@ typedef struct
} \
}













/** @brief Standard Function call wrapper
*
* CLI argument(s) is(are) parsed and checked with CLI_checkarray(), then
Expand Down Expand Up @@ -651,8 +694,11 @@ static inline IMGID makeIMGID_blank()



static inline IMGID makeIMGID_2D(CONST_WORD name, uint32_t xsize,
uint32_t ysize)
static inline IMGID makeIMGID_2D(
CONST_WORD name,
uint32_t xsize,
uint32_t ysize
)
{
IMGID img = mkIMGID_from_name(name);
img.naxis = 2;
Expand All @@ -662,8 +708,12 @@ static inline IMGID makeIMGID_2D(CONST_WORD name, uint32_t xsize,
return img;
}

static inline IMGID makeIMGID_3D(CONST_WORD name, uint32_t xsize,
uint32_t ysize, uint32_t zsize)
static inline IMGID makeIMGID_3D(
CONST_WORD name,
uint32_t xsize,
uint32_t ysize,
uint32_t zsize
)
{
IMGID img = mkIMGID_from_name(name);
img.naxis = 3;
Expand All @@ -677,7 +727,10 @@ static inline IMGID makeIMGID_3D(CONST_WORD name, uint32_t xsize,



static inline int copyIMGID(IMGID *imgin, IMGID *imgout)
static inline int copyIMGID(
IMGID *imgin,
IMGID *imgout
)
{
imgout->datatype = imgin->datatype;
imgout->shared = imgin->shared;
Expand Down Expand Up @@ -823,24 +876,31 @@ static inline IMGID makesetIMGID(CONST_WORD name, imageID ID)
* ERRMODE_FAIL : error
* ERRMODE_ABORT : abort
*/
static inline imageID resolveIMGID(IMGID *img, int ERRMODE)
static inline imageID resolveIMGID(
IMGID *img,
int ERRMODE
)
{
// IF:
// Not resolved before OR create counter mismatch OR not used
if(img->ID == -1 || (img->createcnt != data.image[img->ID].createcnt) ||
(data.image[img->ID].used != 1))
if( (img->ID == -1)
|| (img->createcnt != data.image[img->ID].createcnt)
|| (data.image[img->ID].used != 1))
{
img->ID = image_ID(img->name);
if(img->ID > -1) // Resolve success !
{
img->im = &data.image[img->ID];
img->md = &data.image[img->ID].md[0];
img->createcnt = data.image[img->ID].createcnt;

// Populate the IMGID from the imageID metadata
updateIMGIDcreationparams(img);
}
}

// if still unresolved
//
if(img->ID == -1)
{
if((ERRMODE == ERRMODE_FAIL) || (ERRMODE == ERRMODE_ABORT))
Expand Down
34 changes: 17 additions & 17 deletions src/milk_module_example/examplefunc4_streamprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

static char *inimname;

static LOCVAR_OUTIMG2D outim;

static char *outimname;

static uint32_t *cntindex;
static long fpi_cntindex = -1;
Expand All @@ -51,15 +51,7 @@ static CLICMDARGDEF farg[] =
(void **) &inimname,
NULL
},
{
CLIARG_IMG,
".out_name",
"output image",
"out1",
CLIARG_VISIBLE_DEFAULT,
(void **) &outimname,
NULL
},
FARG_OUTIM2D(outim),
{
CLIARG_UINT32,
".cntindex",
Expand Down Expand Up @@ -174,15 +166,20 @@ static errno_t help_function()


static errno_t streamprocess(
IMGID inimg,
IMGID outimg
IMGID *inimg,
IMGID *outimg
)
{
DEBUG_TRACE_FSTART();
// custom stream process function code

(void) inimg;
(void) outimg;

// resolve imgpos
resolveIMGID(inimg, ERRMODE_ABORT);

// Create output image if needed
imcreateIMGID(outimg);


DEBUG_TRACE_FEXIT();
return RETURN_SUCCESS;
Expand All @@ -198,8 +195,11 @@ static errno_t compute_function()
IMGID inimg = mkIMGID_from_name(inimname);
resolveIMGID(&inimg, ERRMODE_ABORT);

IMGID outimg = mkIMGID_from_name(outimname);
resolveIMGID(&outimg, ERRMODE_ABORT);
// link/create output image/stream
FARG_OUTIM2DCREATE(outim, outimg, _DATATYPE_FLOAT);




printf(" COMPUTE Flags = %ld\n", CLIcmddata.cmdsettings->flags);
INSERT_STD_PROCINFO_COMPUTEFUNC_INIT
Expand All @@ -221,7 +221,7 @@ static errno_t compute_function()
INSERT_STD_PROCINFO_COMPUTEFUNC_LOOPSTART
{

streamprocess(inimg, outimg);
streamprocess(&inimg, &outimg);

// stream is updated here, and not in the function called above, so that multiple
// the above function can be chained with others
Expand Down

0 comments on commit 3f25f2f

Please sign in to comment.