#include "pixmap.h" Pixelmap::Pixelmap(int w,int h,PixelFormat format,int align): width(w), height(h), format(format), align(align) { stride=(this->width*PixelFormatBytesPerPixel(this->format)+(this->align-1))/this->align*this->align; capacity=this->stride*this->height; pixels=(char *)malloc(this->capacity); memset(pixels,0,this->capacity); } Pixelmap::~Pixelmap() { free(pixels); } char *Pixelmap::PixPtr(unsigned int x,unsigned int y) { return pixels+(y*stride+x*PixelFormatBytesPerPixel(format)); } Pixelmap *Pixelmap::Copy() { Pixelmap *newpixmap=new Pixelmap(width,height,format,align); for (register int y=0; y<(int)height; y++) { if (!PixelBufferCopy((unsigned char *)PixPtr(0,y),(unsigned char *)newpixmap->PixPtr(0,y),format,width)) { delete newpixmap; return NULL; } } return newpixmap; } Pixelmap *Pixelmap::Convert(PixelFormat format) { Pixelmap *newpixmap=new Pixelmap(width,height,format,align); for (register int y=0; y<(int)height; y++) { if (!PixelBufferConvert((unsigned char *)this->PixPtr(0,y),this->format,(unsigned char *)newpixmap->PixPtr(0,y),newpixmap->format,width)) { delete newpixmap; return NULL; } } return newpixmap; } void Pixelmap::SwapChannels(int chan0,int chan1) { for (register int y=0; y<(int)height; y++) { for (register int x=0; x<(int)width; x++) { char *pix=this->PixPtr(x,y); register char tmp; tmp=pix[chan0]; pix[chan0]=pix[chan1]; pix[chan1]=tmp; } } }