Hi all,
Looking at libgpf, I noticed a few problems with the current
highlevel API :
- It doesn't handle palette formats.
- We can't initialize a image to write with a given size/frame
number.
- Writer and loader drivers must be separated to decrease
the memory footprint on embedded systems, especially when
encoding is complicated. ( maybe it was thought like this )
- The read/write callback should accept another void * argument
to 'contextualize' the call. (I hate those context-less SAX
parsers!)
- There should be a way to choose a pixel layout for the driver.
When reading an image, it specifies the expected format.
The driver should handle any required transformations.
examples: - rgba -> rgb
- gray -> rgb
- rgb -> gray
- palette -> rgb
- palette -> rgba
- rgb -> palette (maybe rather complicated if
dithering
or color reducing alogirithms are implemented)
Other weird transformations are possible:
ex: channel extraction rgb -> b
Each channel can have a specific number of bits, the driver should
perform color scaling accordingly.
I propose the following, at least for reading:
gpf_channellayout {
char bitmeaning; /* r,g,b,a, y,u,v, C,M,Y,K... */
char bitnum; /* number of bit for this channel */
char layout; /* Endianness */
char padding; /* ... */
}
gpf_pixelformat {
int nbchannel; /* number of used channel */
gpf_channellayout layout[GPF_MAX_CHANNEL];
}
gpf_fileinfo {
int width,frames;
int frames;
int palette_size; /* -1 means no palette */
gpf_pixelformat pixelformat; /* prefered format */
}
typedef gpf_channellayout * gpf_channellayout_t;
typedef gpf_pixelformat * gpf_pixelformat_t;
typedef gpf_fileinfo * gpf_fileinfo_t;
/* fill 'buffer' with the palette values in the 'format' layout. */
/* The buffer must be allocated to the correct size. */
gpfGetPalette(gpf_handle_t handle, gpf_pixelformat_t format, void *
buffer);
/* instead of gpfSelectImage */
gpfSelectFrame(gpf_handle_t handle, int frame);
/*
Start reading the image. the data 'data' will given to the callback
as the first parameter as context. The pixel will be expressed in the
required 'format'.
Return value:
O Ok
-1 Read error (transfer interrupted, disk crash, hardware on
strike...)
-2 Format error (the file format is invalid )
-3 Pixelformat error (tranformation is impossible for the given file)
*/
int
gpfRead(gpf_handle_t handle, gpf_pixelformat_t format,
gpfReadCallback cbR,
gpfIndicatorCallback cbI,
void * data);
Comments?
Eric.