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


Functions Summary

The following is a description of all the functions related to the Cfimage type. The list is in alphabetical order. Conversion between memory models are not implemented as functions of the system library, but as modules (See Volume three: ``MegaWave2 User's Modules Library'').

$ \bigcirc$Name


mw_alloc_cfimage - Allocate the RGB planes




$ \bigcirc$Summary


Cfimage mw_alloc_cfimage(image,nrow,ncol)

Cfimage image;

int nrow, ncol;




$ \bigcirc$Description


This function allocates the RGB planes of a Cfimage structure previously created using mw_new_cfimage. 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_cfimage instead.

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




$ \bigcirc$Example

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

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

/* Set pixel (0,1) to (0.0,0.0,0.0) */
image_>red[256] = image->green[256] = image->blue[256] = 0.0;

$ \bigcirc$Name


mw_change_cfimage - Change the size of the RGB planes




$ \bigcirc$Summary


Cfimage mw_change_cfimage(image, nrow, ncol)

Cfimage image;

int nrow, ncol;




$ \bigcirc$Description


This function changes the memory allocation of the RGB planes of a Cfimage 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_cfimage and mw_alloc_cfimage. 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_cfimage returns NULL if not enough memory is available to allocate the RGB planes. Your code should check this return value to send an error message in the NULL case, and do appropriate statement.




$ \bigcirc$Example

Cimage Output; /* Output of module */

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

$ \bigcirc$Name


mw_clear_cfimage - Clear the RGB planes




$ \bigcirc$Summary


void mw_clear_cfimage(image, r,g,b)

Cfimage image;

float r,g,b;




$ \bigcirc$Description


This function fills the cfimage image with the color given by the triplet r,g,b: all pixels will have this RGB value.




$ \bigcirc$Example

Cfimage image; /* Output of module */

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

$ \bigcirc$Name


mw_copy_cfimage - Copy the pixel values of color image into another one




$ \bigcirc$Summary


void mw_copy_cfimage(in, out)

Cfimage in,out;




$ \bigcirc$Description


This function copies the content of the RGB planes of the image in into the RGB planes of the image out. The size of the two RGB 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

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

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

$ \bigcirc$Name


mw_delete_cfimage - Deallocate the RGB planes




$ \bigcirc$Summary


void mw_delete_cfimage(image)

Cfimage image;




$ \bigcirc$Description


This function deallocates the RGB planes of a Cfimage structure previously allocated using mw_alloc_cfimage or mw_change_cfimage, and the structure itself.

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




$ \bigcirc$Example

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

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

$ \bigcirc$Name


mw_draw_cfimage - Draw a line




$ \bigcirc$Summary


void mw_draw_cfimage(image, a0, b0, a1, b1, r, g, b)

Cfimage image;

int a0,b0,a1,b1;

float r,g,b;




$ \bigcirc$Description


This function draws in image a connected line between the pixel (a0, b0) and the pixel (a1, b1). The color of the line is defined by the triplet r,g,b.




$ \bigcirc$Example

Cfimage image; /* Output of module */

image = mw_change_cfimage(image, 100, 100);
if (image == NULL) mwerror(FATAL,1,"Not enough memory.\n");
/* Set all pixels to (0.0,0.0,0.0) */
mw_clear_cfimage(image,0.0,0.0,0.0);
/* Draw a diagonal line with color (1.0,0.0,0.0) */
mw_draw_cfimage(image,0,0,99,99,1.0,0.0,0.0);

$ \bigcirc$Name


mw_getdot_cfimage - Return the RGB value




$ \bigcirc$Summary


void mw_getdot_cfimage(image, x, y, r, g, b)

Cfimage image;

int x,y;

float *r,*g,*b;




$ \bigcirc$Description


This function returns the RGB value of the given image for the pixel (x, y) (column #x and row #y). The RGB value consists of the triplet *r,*g,*b: *r (any floating point number) gives you the proportion of red, *g the proportion of green and *b the proportion of blue.

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

Cfimage image; /* Needed Input of module */
int x,y;       /* Needed Inputs of module */
float r,g,b;   /* Internal use */

if ((x < image->ncol) && (y < image->nrow))
  {	
    mw_getdot_cfimage(image,x,y,&r,&g,&b);
    printf("image(%d,%d) = %d,%d,%d\n",x,y,r,g,b);
  }
else mwerror(ERROR,1,"Out of bounds !\n");

$ \bigcirc$Name


mw_new_cfimage - Create a new Cfimage




$ \bigcirc$Summary


Cfimage mw_new_cfimage();




$ \bigcirc$Description


This function creates a new Cfimage structure with empty RGB planes. No pixels can be addressed at this time. The RGB planes may be allocated using the function mw_alloc_cfimage or mw_change_cfimage.

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_cfimage. Do not forget to deallocate the internal structures before the end of the module.

The function mw_new_cfimage 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

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

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

$ \bigcirc$Name


mw_newtab_blue_cfimage - Create a bi-dimensional tab for the blue pixels of a Cfimage




$ \bigcirc$Summary


float ** mw_newtab_blue_cfimage(image)

Cfimage image;




$ \bigcirc$Description


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

This function must be called after the blue plane has been allocated, using for example one of the functions mw_new_cfimage, mw_alloc_cfimage or mw_change_cfimage. After that, if the blue plane allocation is changed (by e.g. mw_change_cfimage or mw_delete_cfimage), 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 blue value of the pixel (x, y) (x being an index for column and y for row) using tab[y][x].

Red and green pixels' value can be accessed with such a tab using the corresponding functions
mw_newtab_red_cfimage and mw_newtab_green_cfimage.




$ \bigcirc$Example

Cfimage image; /* Needed Input of module (RGB planes already allocated and filled) */
int x,y;      /* Needed Input of module */
float **red,**green,**blue;

red =  mw_newtab_red_cfimage(image);
if (red==NULL) mwerror(FATAL,1,"Not enough memory\n");
green =  mw_newtab_green_cfimage(image);
if (green==NULL) mwerror(FATAL,1,"Not enough memory\n");
blue =  mw_newtab_blue_cfimage(image);
if (blue==NULL) mwerror(FATAL,1,"Not enough memory\n");

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

free(blue); free(green); free(red);

$ \bigcirc$Name


mw_newtab_green_cfimage - Create a bi-dimensional tab for the green pixels of a Cfimage




$ \bigcirc$Summary


float ** mw_newtab_green_cfimage(image)

Cfimage image;




$ \bigcirc$Description


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

This function must be called after the green plane has been allocated, using for example one of the functions mw_new_cfimage, mw_alloc_cfimage or mw_change_cfimage. After that, if the green plane allocation is changed (by e.g. mw_change_cfimage or mw_delete_cfimage), 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 green value of the pixel (x, y) (x being an index for column and y for row) using tab[y][x].

Red and blue pixels' value can be accessed with such a tab using the corresponding functions
mw_newtab_red_cfimage and mw_newtab_blue_cfimage.




$ \bigcirc$Example

Cfimage image; /* Needed Input of module (RGB planes already allocated and filled) */
int x,y;      /* Needed Input of module */
float **red,**green,**blue;

red =  mw_newtab_red_cfimage(image);
if (red==NULL) mwerror(FATAL,1,"Not enough memory\n");
green =  mw_newtab_green_cfimage(image);
if (green==NULL) mwerror(FATAL,1,"Not enough memory\n");
blue =  mw_newtab_blue_cfimage(image);
if (blue==NULL) mwerror(FATAL,1,"Not enough memory\n");

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

free(blue); free(green); free(red);

$ \bigcirc$Name


mw_newtab_red_cfimage - Create a bi-dimensional tab for the red pixels of a Cfimage




$ \bigcirc$Summary


float ** mw_newtab_red_cfimage(image)

Cfimage image;




$ \bigcirc$Description


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

This function must be called after the red plane has been allocated, using for example one of the functions mw_new_cfimage, mw_alloc_cfimage or mw_change_cfimage. After that, if the red plane allocation is changed (by e.g. mw_change_cfimage or mw_delete_cfimage), 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 red value of the pixel (x, y) (x being an index for column and y for row) using tab[y][x].

Green and blue pixels' value can be accessed with such a tab using the corresponding functions
mw_newtab_green_cfimage and mw_newtab_blue_cfimage.




$ \bigcirc$Example

Cfimage image; /* Needed Input of module (RGB planes already allocated and filled) */
int x,y;      /* Needed Input of module */
float **red,**green,**blue;

red =  mw_newtab_red_cfimage(image);
if (red==NULL) mwerror(FATAL,1,"Not enough memory\n");
green =  mw_newtab_green_cfimage(image);
if (green==NULL) mwerror(FATAL,1,"Not enough memory\n");
blue =  mw_newtab_blue_cfimage(image);
if (blue==NULL) mwerror(FATAL,1,"Not enough memory\n");

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

free(blue); free(green); free(red);

$ \bigcirc$Name


mw_plot_cfimage - Set the RGB value




$ \bigcirc$Summary


void mw_plot_cfimage(image, x, y, r, g, b)

Cfimage image;

int x,y;

float r,g,b;




$ \bigcirc$Description


This function set the RGB value of the given image for the pixel (x, y) (column #x and row #y) to be the triplet r,g,b: r (a floating point number) gives you the proportion of red, g the proportion of green and b the proportion of blue.

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

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

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


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