#ifndef PIXMAP_H #define PIXMAP_H #include "common.h" #include "pixelbuffer.h" // supported pixel formats enum PixelFormat { PixelsNone=-1, PixelsR8G8B8A8=PF_R8G8B8A8, PixelsB8G8R8A8=PF_B8G8R8A8, PixelsR8G8B8=PF_R8G8B8, PixelsB8G8R8=PF_B8G8R8, PixelsI8=PF_I8, PixelsA8=PF_A8 }; // Pixmap class. I had to call it Pixelmap so it doesn't conflict with X11's Pixmap. class Pixelmap { private: char *pixels; // Pixel buffer. int width,height,stride; // Dimensions of the image, and buffer stride/pitch. int capacity,align; // Memory capacity and alignment. PixelFormat format; // Format enum. public: // Pixel format information static unsigned int PixelFormatBytesPerPixel(PixelFormat format) {return ::PixelFormatBytesPerPixel((int)format);} static unsigned int PixelFormatColorBitsPerPixel(PixelFormat format) {return ::PixelFormatColorBitsPerPixel((int)format);} static unsigned int PixelFormatRed(PixelFormat format) {return ::PixelFormatRed((int)format);} static unsigned int PixelFormatGreen(PixelFormat format) {return ::PixelFormatGreen((int)format);} static unsigned int PixelFormatBlue(PixelFormat format) {return ::PixelFormatBlue((int)format);} static unsigned int PixelFormatAlpha(PixelFormat format) {return ::PixelFormatAlpha((int)format);} static unsigned int PixelFormatIntensity(PixelFormat format) {return ::PixelFormatIntensity((int)format);} Pixelmap(int w,int h,PixelFormat format=PixelsR8G8B8,int align=4); ~Pixelmap(); // get various metrics int Width() {return width;} int Height() {return height;} int Stride() {return stride;} // the stride may also be known to you as the pitch PixelFormat Format() {return format;} // get a pointer to a specific pixel char *PixPtr(unsigned int x=0,unsigned int y=0); // create a copy, either in the same or a different format. Pixelmap *Copy(); Pixelmap *Convert(PixelFormat format); // swap a pair of color channels, often necessary for resolving endian issues or Direct3D issues void SwapChannels(int chan0,int chan1); static void PixelRed(PixelFormat format,char *pixel,void *red) { switch (format) { case PixelsR8G8B8A8: case PixelsR8G8B8: (*(char *)red)=pixel[0]; break; case PixelsB8G8R8A8: case PixelsB8G8R8: (*(char *)red)=pixel[2]; default: (*(char *)red)=0; break; } } static void PixelGreen(PixelFormat format,char *pixel,void *green) { (*(char *)green)=((int)format