Contenu | Menu

After spending too much time looking around the legacy code, and thinking about the "good" way to upgrade it to ANSI C, I decided to try to rewrite it, gradually. So, I start with the images. The basic ideas are:

u8image

This matches the original cimage type, reloaded. uint8 is a typedef for unsigned char; we also have uint16, uint32 (no uint64, no long long int in ANSI C), float32 and float64 for the other structures.

This structure is defined in [[mw4f lib/src/u8image.h]], with the implementation details in [[mw4f lib/src/u8image.c]] :

/**
 * 8-bit unsigned integer gray level image
 */
typedef struct s_u8image
{
     uint16 ncol;  /**< number of columns (dx) */
     uint16 nrow;  /**< number of rows (dy)    */
     uint8 * gray; /**< gray level plane       */
} mw_u8image;

/* create an image */
mw_u8image * mw_new_u8image(uint16, uint16);
/* delete an image */
void mw_del_u8image(mw_u8image *);
/* copy an array an image */
mw_u8image * mw_setdata_u8image(mw_u8image *, const uint8 *);
/* copy an image into an existing one */
mw_u8image * mw_copy_u8image(mw_u8image *, mw_u8image *);
/* copy an image into a new one */
mw_u8image * mw_clone_u8image(mw_u8image *);

/* get one value of an image */
int16 mw_getdot_u8image(mw_u8image *, uint16, uint16);
/* set one value of an image */
int16 mw_setdot_u8image(mw_u8image *, uint16, uint16, uint8);
/* fill an image */
uint8 * mw_fill_u8image(mw_u8image *, uint8);

/* write a text representation of an image to a file */
int32 mw_fwrite_u8image(FILE *, mw_u8image *);
/* read a text representation of an image from a file */
mw_u8image * mw_fread_u8image(FILE *);

So, what is different?

the structure

the functions

u16image, f32image, ...

Same, with another data type. See [[mw4f lib/src/u16image.h]]/[[mw4f lib/src/u16image.c]] and [[mw4f lib/src/f32image.h]]/[[mw4f lib/src/f32image.c]].

notes

All the new code is documented a la doxygen and tested with:

In the future, these gray-level structures might be merged with the color images.

I also think about a "package", with all the basic operations one may want to perform on an image:

By the way, we stick to ANSI C, but overloading and default parameters would be really nice there; it's possible to implement sort of overloading in C with unions, but at the price of a code difficult to write, read, use and maintain. Maybe a C++ overlay later?