diff --git a/inc/hgl/2d/Bitmap.h b/inc/hgl/2d/Bitmap.h index 39a6989..d296417 100644 --- a/inc/hgl/2d/Bitmap.h +++ b/inc/hgl/2d/Bitmap.h @@ -3,14 +3,21 @@ #include #include +#include namespace hgl { + template + static void FillPixels(T *p,const T &color,const int length) + { + std::fill_n(p,length,color); + } + /** * 简单的2D象素处理 */ - template class Bitmap + template class Bitmap { - uint width,height; + int width,height; T *data; @@ -27,13 +34,17 @@ namespace hgl delete[] data; } - const uint GetWidth()const{return width;} - const uint GetHeight()const{return height;} - const uint GetTotalPixels()const{return width*height;} - const uint GetLineBytea()const{return width*CHANNELS*sizeof(T);} - const uint GetTotalBytes()const{return width*height*CHANNELS*sizeof(T);} + const int GetWidth ()const{return width;} + const int GetHeight ()const{return height;} + const uint GetTotalPixels ()const{return width*height;} + const uint GetLineBytes ()const{return width*sizeof(T);} + const uint GetTotalBytes ()const{return width*height*sizeof(T);} T *GetData(){return data;} + T *GetData(int x,int y) + { + return (x<0||x>=width||y<0||y>=height)?nullptr:data+(y*width+x); + } bool Create(uint w,uint h) { @@ -49,7 +60,7 @@ namespace hgl delete[] data; - data=new T[width*height*CHANNELS]; + data=new T[width*height]; return(true); } @@ -65,95 +76,23 @@ namespace hgl width=height=0; } - void ClearColor(T *color) + void ClearColor(const T &color) { - if(!data||!color)return; + if(!data)return; - uint total=width*height; - - T *p=data; - - for(size_t i=0; i *outputs) - { - if(!data||!outputs) - return(false); - - T *sp=data; - AutoDeleteArray op=new T *[CHANNELS]; - - for(uint i=0;i *inputs) - { - if(!data||!inputs) - return(false); - - T *dp=data; - AutoDeleteArray ip=new T *[CHANNELS]; - - for(uint i=0;i(data,color,width*height); } void Flip() { if(!data||height<=1)return; - const uint line_pixels=width*CHANNELS; - const uint line_bytes=width*CHANNELS*sizeof(T); + const uint line_bytes=width*sizeof(T); - T *temp=new T[line_pixels]; + T *temp=new T[width]; T *top=data; - T *bottom=data+(line_pixels*(height-1)); + T *bottom=data+(width*(height-1)); while(top=width||y>=height)return; - - T *p=data+(y*width+x)*CHANNELS; - - for(uint i=0;i=width||y>=height)return(false); - - T *p=data+(y*width+x)*CHANNELS; - - for(uint i=0;i class Bitmap - - using BitmapR8 =Bitmap; - using BitmapR16 =Bitmap; - using BitmapR32U =Bitmap; - using BitmapR32F =Bitmap; - - using BitmapRG8 =Bitmap; - using BitmapRG16 =Bitmap; - using BitmapRG32U =Bitmap; - using BitmapRG32F =Bitmap; - - using BitmapRGBA8 =Bitmap; - using BitmapRGBA16 =Bitmap; - using BitmapRGBA32U =Bitmap; - using BitmapRGBA32F =Bitmap; + };//template class Bitmap }//namespace hgl #endif//HGL_2D_BITMAP_INCLUDE