by Johan » Mar 17, 2002 @ 9:37pm
Hi Werner,
Currently no devices use the 555 format. But new devices are coming along all the time (including the new smart phones), so it would be wise to be prepared for it.
One solution (if you are using C++) is to use the adapter design pattern to support multiple pixel formats for 16-bit devices:
Allocate space for the screen as a WORD* pointer. Create a template class with a member variable of type T. The T member variable contains inline functions for native pixel <-> RGB color conversions. Then instanciate two objects of the template class, one with a 555 member object, and one with a 565 member object. Put all operations to access the 16-bit surface in the template class as inline operations.
I use this in a GapiDraw which will be announced later tonight. It uses this design pattern to access screen pixels, and can be adapted to support any screen format, with any screen depth, with no loss of performance (since everything becomes inlined code). Adding support for other formats is as easy as adding a new native format <-> RGB color conversion class and a new adapter template class instance.
Best regards,
Johan