diff --git a/Image2D.cpp b/Image2D.cpp new file mode 100644 index 0000000..4a19137 --- /dev/null +++ b/Image2D.cpp @@ -0,0 +1,71 @@ +#include"Image2D.h" +struct HalfImage +{ + virtual void Process(void *,void *,const uint,const uint,const uint)=0; +}; + +template +struct HalfImageImple:public HalfImage +{ + void Process(void *target,void *source,const uint width,const uint height,const uint channels) override + { + const uint line_length=width*channels; + + T *tp=(T *)target; + + T *sp0=(T *)source; + T *sp1=sp0+channels; + T *sp2=sp0+line_length; + T *sp3=sp1+line_length; + + for(uint row=0;row;else + if(type==PixelDataType::U16)hi=new HalfImageImple;else + if(type==PixelDataType::U32)hi=new HalfImageImple;else + if(type==PixelDataType::F32)hi=new HalfImageImple;else + if(type==PixelDataType::F64)hi=new HalfImageImple;else + return(nullptr); + + uint hw=width>>1; + uint hh=height>>1; + + void *new_data=new uint8[hw*hh*channels]; + + hi->Process(new_data,data,width,height,channels); + + delete hi; + + return(new Image2D(hw,hh,channels,type,new_data)); +} \ No newline at end of file diff --git a/Image2D.h b/Image2D.h new file mode 100644 index 0000000..0d59e13 --- /dev/null +++ b/Image2D.h @@ -0,0 +1,55 @@ +#pragma once +#include + +using namespace hgl; + +enum class PixelDataType +{ + U8, + U16, + U32, + F32, + F64 +}; + +class Image2D +{ + uint width; + uint height; + uint channels; + + PixelDataType type; + + void *data; + +public: + + const uint GetWidth()const{return width;} + const uint GetHeight()const{return height;} + const uint GetChannels()const{return channels;} + const PixelDataType GetType()const{return type;} + void *GetData()const{return data;} + +public: + + Image2D() + { + width=height=channels=0; + } + + Image2D(const uint w,const uint h,const uint c,const PixelDataType &pdt,void *ptr) + { + width=w; + height=h; + channels=c; + type=pdt; + data=ptr; + } + + ~Image2D() + { + delete[] data; + } + + Image2D *CreateHalfImage(); +};//class Image2D