added Image2D.h/.cpp
This commit is contained in:
parent
1a9631dae9
commit
e173b88097
71
Image2D.cpp
Normal file
71
Image2D.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
#include"Image2D.h"
|
||||
struct HalfImage
|
||||
{
|
||||
virtual void Process(void *,void *,const uint,const uint,const uint)=0;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
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<height;row+=2)
|
||||
{
|
||||
for(uint col=0;col<=width;col+=2)
|
||||
{
|
||||
for(uint i=0;i<channels;i++)
|
||||
{
|
||||
*tp=((*sp0)+(*sp1)+(*sp2)+(*sp3))/T(4);
|
||||
++tp;
|
||||
|
||||
++sp0;
|
||||
++sp1;
|
||||
++sp2;
|
||||
++sp3;
|
||||
}
|
||||
|
||||
sp0+=channels;
|
||||
sp1+=channels;
|
||||
sp2+=channels;
|
||||
sp3+=channels;
|
||||
}
|
||||
|
||||
sp0+=line_length;
|
||||
sp1+=line_length;
|
||||
sp2+=line_length;
|
||||
sp3+=line_length;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Image2D *Image2D::CreateHalfImage()
|
||||
{
|
||||
HalfImage *hi;
|
||||
|
||||
if(type==PixelDataType::U8 )hi=new HalfImageImple<uint8>;else
|
||||
if(type==PixelDataType::U16)hi=new HalfImageImple<uint16>;else
|
||||
if(type==PixelDataType::U32)hi=new HalfImageImple<uint32>;else
|
||||
if(type==PixelDataType::F32)hi=new HalfImageImple<float>;else
|
||||
if(type==PixelDataType::F64)hi=new HalfImageImple<double>;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));
|
||||
}
|
55
Image2D.h
Normal file
55
Image2D.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
#include<hgl/type/DataType.h>
|
||||
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user