next up previous contents index
Next: Miscellaneous System Functions Up: Miscellaneous Features Previous: Global System Variables   Contents   Index

Conversion between memory types

The System Library contains functions to convert memory types. However do not expect to find a function to convert structures which are very dissimilar, as Curves and Cimage. If the meaning one can give of a conversion is not evident or not unique, a conversion procedure has to be implemented as a module rather than as a system function.

Conversion function summaries follow the following rule : out = (Y) mw_x_to_y(in,old) where x is the internal C type of the input in, y the internal C type of the requested output out (letters in lowercase) and Y the cast to the output (internal C type of out with first letter in uppercase). In the last argument old you may put the name of a variable of type Y : in such a case, the memory allocation will be reused for out (the pointer old will have the same address than out). This is especially useful when converting lot of images with same size, to avoid memory blowup. If you do not want to use this possibility, just put NULL as the last argument : memory for out will be allocated.

In addition to the various mw_x_to_y() undocumented conversion functions, there exists an ``all-purpose'' conversion function called mw_conv_internal_type() and documented next page.

$ \bigcirc$Name


mw_conv_internal_type - Convert any possible internal type to another one




$ \bigcirc$Summary


void *mw_conv_internal_type(mwstruct,typein,typeout)

void *mwstruct; /* Any type of MegaWave2 structure */

char *typein; /* Type of the input <mwstruct> */

char *typeout; /* Type of the output structure */




$ \bigcirc$Description


This function may be used instead of the mw_x_to_y() various functions to convert any possible internal type a to b, even if the mw_a_to_b() function does not exist : the system creates mw_conv_internal_type() by analyzing existing mw_x_to_y() functions, by finding the shortest path between two internal types, say a and b, and by calling appropriate mw_x_to_y() functions (for example, mw_a_to_c() and mw_c_to_b() if those functions exist).

The input mwstruct is a variable of internal C type given by the string typein (use lower letters only). The output of the function is a variable of internal C type given by the string typeout, or NULL if the conversion is impossible.

Do not forget to cast the output to the right type.




$ \bigcirc$Example

Ccimage in;  
Cimage out1;
Fimage out2;

/* The line */
out1 = (Cimage) mw_conv_internal_type(in,"ccimage","cimage");
/* is equivalent to */
out1 = (Cimage) mw_ccimage_to_cimage(in);

if (out1==NULL) mwerror(FATAL,1,"Cannot convert Ccimage to Cimage !\n");

/* But to convert a Ccimage to a Fimage you shall use */
out2 = (Fimage) mw_conv_internal_type(in,"ccimage","fimage");
/* Since the following function does not exist at this time */
out2 = (Fimage) mw_ccimage_to_fimage(in);

if (out2==NULL) mwerror(FATAL,1,"Cannot convert Ccimage to Fimage !\n");


next up previous contents index
Next: Miscellaneous System Functions Up: Miscellaneous Features Previous: Global System Variables   Contents   Index
mw 2004-05-05