Most people would argue that this has no business in the main kernel library, and they may very well be right. However, I wanted this to be a standard part of KOS on any platform it got ported to so that you're guaranteed some platform-independet, device-dependent representation of images. This way, any image loader library that is ported to KOS can convert to this data format and it can be used by anything in the kernel that understands it (drivers, etc).
KOS doesn't try to put any limitations on what format the image may take; instead it tries to encapsulate most of the common formats you'd want to use in writing a game or demo and then provides an ``out'' for platform-specific things that are just too strange to be used elsewhere. A good example of this (though one which isn't actually used currently) would be the PVR2's ``twiddled'' textures. Some somewhat strange things that it does cover are inverted axis textures (e.g., for GL) and YUV formats for MPEG (tm) .
The majority of the PII system is just format specifications so that pieces have a common language to talk about the images. This includes a structure (kos_img_t) that contains a pointer to the raw data, width and height in pixels, and a format descriptor. The first three pieces are pretty self-explanatory, so I won't waste any time on those. However, the format descriptor deserves some attention.
The format descriptor is composed of two parts: the platform independent part, and the platform dependent part. Each of these parts is 16 bits wide. The platform independent part is further divided into a format specifier and standard flags. The format specifier may be one of:
The attributes will be a bitmask with the following:
There is one function associated with the PII system currently:
Frees the image pointed to by img. If struct_also is non-zero, then the kos_img_t struct itself will also be freed. This function is to ensure future compatibility in code that calls libraries to allocate images and then needs to free them later itself.
Several macros are also available for tearing apart and putting together the format descriptor:
In the future, the PII system may also include functions to convert between image formats, but this hasn't been done yet.