#include <stdio.h>
#include <iostream>
#include <memory>
template<class T>
class Surface
{
public:
Surface(){
width = 0;
height = 0;
allocate_self = true;
memset(stride,0,sizeof(stride));
}
virtual ~Surface() {
}
virtual int create(int width, int height, int * stride)=0;
virtual int create(int width, int height, uint8_t * const * data, int * stride)=0;
virtual void release() {
for (int i = 0; i != 4; ++i) {
data[0].reset();
}
};
uint8_t* getPtr() const {
return data[0].get();
}
void getPtr(uint8_t* const * res_data) const {
for (int i = 0; i != 4; ++i) {
res_data[i] = data[i].get();
}
}
public:
int width;
int height;
int stride[4];
protected:
std::shared_ptr<T> data[4];
bool allocate_self;
};
template<class T>
class SurfaceGray :public Surface<T>
{
public:
int create(int _width, int _height, int * _stride)
{
allocate_self = true;
data[0] = std::make_shared<uint8_t>( _stride[0]*height );
width = _width;
height = _height;
memcpy( stride, _stride, sizeof(int)*4 );
return 0;
}
int create(int _width, int _height, uint8_t * const * _data, int * _stride)
{
allocate_self = false;
width = _width;
height = _height;
for (int i = 0; i != 4; ++i) {
if (_data[i]) {
//data[i] = std::make_shared<uint8_t>(_data[i]);
stride[i] = _stride[i];
}
}
return 0;
}
private:
};
int main()
{
SurfaceGray<uint8_t> pic;
int stride[4] = {1920,0,0,0};
pic.create(1920, 1080, stride);
uint8_t* data = pic.getPtr();
pic.release();
return 0;
}