Should it be necessary, support for new types of image can be implemented fairly simply, by defining a structure derived from a fz_image. Perhaps:
Then we'd define a new image creation function, fz_new_image_from_foo, of the form:
The key call here is the call to fz_new_image. This is a macro which wraps a call to fz_new_image_of_size:
The macro takes identical parameters to the function other than passing the structure type in place of the structure type saved, and performing a typecast to simplify the typical enclosing code.
Both function and macro take pointers to 3 functions that need to be defined for the new format. Firstly, foo_get is of the following type:
Secondly, foo_get_size will be of type:
Finally, foo_drop will be of type:
The actual deallocation of the fz_image block and its associated resources will be done on return from this function. The fz_drop_image_fn is responsible just for deallocating its implementation specific resources (i.e. the contents of foo_image rather than fz_image).