next up previous contents index
Next: Color Float Images Up: Float Images Previous: Related file (external) types   Contents   Index


Functions Summary

The following is a description of all the functions related to the Fimage type. The list is in alphabetical order.

$ \bigcirc$Name


mw_alloc_fimage - Allocate the gray plane




$ \bigcirc$Summary


Fimage mw_alloc_fimage(image,nrow,ncol)

Fimage image;

int nrow, ncol;




$ \bigcirc$Description


This function allocates the gray plane of a Fimage structure previously created using mw_new_fimage. The size of the image is given by nrow (number of rows or maximum range of y plus one) and ncol (number of columns or maximum range of x plus one). Pixels can be addressed after this call, if the allocation successed. There is no default value for the pixels.

Do not use this function if image has already an allocated plane: use the function mw_change_fimage instead.

The function mw_alloc_fimage returns NULL if not enough memory is available to allocate the gray plane. Your code should check this return value to send an error message in the NULL case, and do appropriate statement.




$ \bigcirc$Example

Fimage image=NULL; /* Internal use: no Input neither Output of module */

if  ( ((image = mw_new_fimage()) == NULL) ||
      (mw_alloc_fimage(image,256,256) == NULL) )
    mwerror(FATAL,1,"Not enough memory.\n");

/* Set pixel (0,1) to the value -1.0 */
image->gray[256] = -1.0;

$ \bigcirc$Name


mw_change_fimage - Change the size of the gray plane




$ \bigcirc$Summary


Fimage mw_change_fimage(image, nrow, ncol)

Fimage image;

int nrow, ncol;




$ \bigcirc$Description


This function changes the memory allocation of the gray plane of a Fimage structure, even if no previously memory allocation was done. The new size of the image is given by nrow (number of rows or maximum range of y plus one) and ncol (number of columns or maximum range of x plus one).

It can also create the structure if the input image = NULL. Therefore, this function can replace both mw_new_fimage and mw_alloc_fimage. It is the recommended function to set image dimension of input/output modules. Since the function can set the address of image, the variable must be set to the return value of the function (See example below).

The function mw_change_fimage returns NULL if not enough memory is available to allocate the gray plane. Your code should check this return value to send an error message in the NULL case, and do appropriate statement.




$ \bigcirc$Example

Fimage Output; /* Output of module */

Output = mw_change_fimage(Output, 256, 256);
if (Output == NULL) mwerror(FATAL,1,"Not enough memory.\n");

$ \bigcirc$Name


mw_clear_fimage - Clear the gray plane




$ \bigcirc$Summary


void mw_clear_fimage(image, v)

Fimage image;

float v;




$ \bigcirc$Description


This function fills the fimage image with the gray value given by v: all pixels will have the gray level v.




$ \bigcirc$Example

Fimage image; /* Output of module */

image = mw_change_fimage(image, 100, 100);
if (image == NULL) mwerror(FATAL,1,"Not enough memory.\n");
/* Set all pixels to 0.0 */
mw_clear_fimage(image,0.0);

$ \bigcirc$Name


mw_copy_fimage - Copy the pixel values of an image into another one




$ \bigcirc$Summary


void mw_copy_fimage(in, out)

Fimage in,out;




$ \bigcirc$Description


This function copies the content of the gray plane of the image in into the gray plane of the image out. The size of the two gray planes must be the same.

The speed of this function depends to the C library implementation, but it is usually very fast (trying to do faster is a waste of time).




$ \bigcirc$Example

Fimage G; /* Needed Input */
Fimage F; /* Optional Output */

  if (F) {
    printf("F option is active: copy G in F\n");
    if ((F = mw_change_fimage(F, G->nrow, G->ncol)) == NULL)
	mwerror(FATAL,1,"Not enough memory.\n");
    else mw_copy_fimage(G, F);
   }
  else  printf("F option is not active\n");

$ \bigcirc$Name


mw_delete_fimage - Deallocate the gray plane




$ \bigcirc$Summary


void mw_delete_fimage(image)

Fimage image;




$ \bigcirc$Description


This function deallocates the gray plane of a Fimage structure previously allocated using mw_alloc_fimage or mw_change_fimage, and the structure itself.

You should set image = NULL after this call since the address pointed by image is no longer valid.




$ \bigcirc$Example

Fimage image=NULL; /* Internal use: no Input neither Output of module */

if  ( ((image = mw_new_fimage()) == NULL) ||
      (mw_alloc_fimage(image,256,256) == NULL) )
    mwerror(FATAL,1,"Not enough memory.\n");
.
.
.
mw_delete_fimage(image);
image = NULL;

$ \bigcirc$Name


mw_draw_fimage - Draw a line




$ \bigcirc$Summary


void mw_draw_fimage(image, a0, b0, a1, b1, c)

Fimage image;

int a0,b0,a1,b1; float c;




$ \bigcirc$Description


This function draws in image a connected line of gray level c between the pixel (a0, b0) and the pixel (a1, b1).




$ \bigcirc$Example

Fimage image; /* Output of module */

image = mw_change_fimage(image, 100, 100);
if (image == NULL) mwerror(FATAL,1,"Not enough memory.\n");
/* Clear all pixels */
mw_clear_fimage(image,0.0);
/* Draw a diagonal line of gray level 1.0 */
mw_draw_fimage(image,0,0,99,99,1.0);

$ \bigcirc$Name


mw_getdot_fimage - Return the gray level value




$ \bigcirc$Summary


float mw_getdot_fimage(image, x, y)

Fimage image;

int x,y;




$ \bigcirc$Description


This function returns the gray level value (any floating point number) of the given image for the pixel (x, y) (column #x and row #y).

Notice that a call to this function is a slow (but easy and secure) way to read a pixel value. See section 2 page [*] for how to read pixels fast.




$ \bigcirc$Example

Fimage image; /* Needed Input of module */
int x,y;      /* Needed Inputs of module */

if ((x < image->ncol) && (y < image->nrow))
	printf("image(%d,%d) = %f\n",x,y,mw_getdot_fimage(image,x,y));
else mwerror(ERROR,1,"Out of bounds !\n");

$ \bigcirc$Name


mw_new_fimage - Create a new Fimage




$ \bigcirc$Summary


Fimage mw_new_fimage();




$ \bigcirc$Description


This function creates a new Fimage structure with an empty gray plane. No pixels can be addressed at this time. The gray plane may be allocated using the function mw_alloc_fimage or mw_change_fimage.

Do not use this function for input/output of modules, since the MegaWave2 Compiler already created the structure for you if you need it (See Volume one: ``MegaWave2 User's Guide''). Use instead the function mw_change_fimage. Do not forget to deallocate the internal structures before the end of the module.

The function mw_new_fimage returns NULL if not enough memory is available to create the structure. Your code should check this value to send an error message in the NULL case, and do appropriate statement.




$ \bigcirc$Example

Fimage image=NULL; /* Internal use: no Input neither Output of module */

if  ( ((image = mw_new_fimage()) == NULL) ||
      (mw_alloc_fimage(image,256,256) == NULL) )
    mwerror(FATAL,1,"Not enough memory.\n");

$ \bigcirc$Name


mw_newtab_gray_fimage - Create a bi-dimensional tab for the pixels of a Fimage




$ \bigcirc$Summary


float ** mw_newtab_gray_fimage(image)

Fimage image;




$ \bigcirc$Description


This function creates a new bi-dimensional tab which allows an easy and fast access to the pixels' gray level. This tab is actually an one-dimensional tab of pointers, so that each pointer points to the beginning of a line in the gray plane of the given image.

This function must be called after the gray plane has been allocated, using for example one of the functions mw_new_fimage, mw_alloc_fimage or mw_change_fimage. After that, if the gray plane allocation is changed (by e.g. mw_change_fimage or mw_delete_fimage), the tab is no longer valid and must be deleted using free(tab).

Ones the tab has been correctly created, is it possible to read or to write the value of the pixel (x, y) (x being an index for column and y for row) usingtab[y][x].




$ \bigcirc$Example

Fimage image; /* Needed Input of module (gray plane already allocated and filled) */
int x,y;      /* Needed Input of module */
float **tab;

tab =  mw_newtab_gray_fimage(image);
if (tab==NULL) mwerror(FATAL,1,"Not enough memory\n");

/* Put 0 in the pixel (x,y) */
if ((x < image->ncol) && (y < image->nrow)) tab[y][x] = 0.0;
else mwerror(ERROR,1,"Out of bounds !\n");

free(tab);

$ \bigcirc$Name


mw_plot_fimage - Set the gray level value




$ \bigcirc$Summary


void mw_plot_fimage(image, x, y, v)

Fimage image;

int x,y;

float v;




$ \bigcirc$Description


This function set the gray level value of the given image for the pixel (x, y) (column #x and row #y) to be v (any floating point number).

Notice that a call to this function is a slow (but easy and secure) way to write a pixel value. See section 2 page [*] for how to write pixels fast.




$ \bigcirc$Example

Fimage image; /* Needed Input of module */
int x,y;      /* Needed Inputs of module */

/* Put 0.0 in the pixel (x,y) */
if ((x < image->ncol) && (y < image->nrow))
        mw_plot_fimage(image,x,y,0.0));
else mwerror(ERROR,1,"Out of bounds !\n");


next up previous contents index
Next: Color Float Images Up: Float Images Previous: Related file (external) types   Contents   Index
mw 2004-05-05