[DEV] update new ememory::SharedPtr
This commit is contained in:
parent
87316c738a
commit
27e440c4a3
@ -7,7 +7,7 @@
|
||||
#include <egami/Image.h>
|
||||
#include <egami/debug.h>
|
||||
#include <egami/ImagePrivate.h>
|
||||
#include <memory>
|
||||
#include <ememory/memory.h>
|
||||
|
||||
std::ostream& egami::operator <<(std::ostream& _os, const enum egami::colorType _type) {
|
||||
switch (_type) {
|
||||
@ -47,6 +47,10 @@ egami::Image::Image() :
|
||||
EGAMI_WARNING("Chek this code, the caller can not use it corectly ... (NEW API)");
|
||||
}
|
||||
|
||||
egami::Image::~Image() {
|
||||
|
||||
}
|
||||
|
||||
egami::Image::Image(const ivec2& _size, enum colorType _type) :
|
||||
m_data(nullptr) {
|
||||
configure(_size, _type);
|
||||
@ -58,29 +62,29 @@ void egami::Image::configure(const ivec2& _size, enum colorType _type) {
|
||||
m_data = nullptr;
|
||||
break;
|
||||
case egami::colorType::RGBA8:
|
||||
//m_data = std::make_shared<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint8_t>>(_size));
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint8_t>>(_size));
|
||||
//m_data = ememory::makeShared<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint8_t>>(_size));
|
||||
m_data = ememory::makeShared<egami::ImageTemplate<etk::Color<uint8_t>>>(_size);
|
||||
break;
|
||||
case egami::colorType::RGB8:
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint8_t, 3>>(_size));
|
||||
m_data = ememory::makeShared<egami::ImageTemplate<etk::Color<uint8_t, 3>>>(_size);
|
||||
break;
|
||||
case egami::colorType::RGBAf:
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<float>>(_size));
|
||||
m_data = ememory::makeShared<egami::ImageTemplate<etk::Color<float>>>(_size);
|
||||
break;
|
||||
case egami::colorType::RGBf:
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<float, 3>>(_size));
|
||||
m_data = ememory::makeShared<egami::ImageTemplate<etk::Color<float, 3>>>(_size);
|
||||
break;
|
||||
case egami::colorType::unsignedInt16:
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint16_t, 1>>(_size));
|
||||
m_data = ememory::makeShared<egami::ImageTemplate<etk::Color<uint16_t, 1>>>(_size);
|
||||
break;
|
||||
case egami::colorType::unsignedInt32:
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint32_t, 1>>(_size));
|
||||
m_data = ememory::makeShared<egami::ImageTemplate<etk::Color<uint32_t, 1>>>(_size);
|
||||
break;
|
||||
case egami::colorType::float32:
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<float, 1>>(_size));
|
||||
m_data = ememory::makeShared<egami::ImageTemplate<etk::Color<float, 1>>>(_size);
|
||||
break;
|
||||
case egami::colorType::float64:
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<double, 1>>(_size));
|
||||
m_data = ememory::makeShared<egami::ImageTemplate<etk::Color<double, 1>>>(_size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <etk/math/Vector2D.h>
|
||||
#include <etk/Color.h>
|
||||
#include <etk/stdTools.h>
|
||||
#include <memory>
|
||||
#include <ememory/memory.h>
|
||||
|
||||
namespace egami {
|
||||
enum class colorType {
|
||||
@ -26,11 +26,47 @@ namespace egami {
|
||||
float64,
|
||||
};
|
||||
std::ostream& operator <<(std::ostream& _os, const enum egami::colorType _obj);
|
||||
class ImagePrivate;
|
||||
|
||||
class ImagePrivate {
|
||||
public:
|
||||
ImagePrivate() {};
|
||||
virtual ~ImagePrivate() {};
|
||||
virtual void* getTextureDataPointer() {
|
||||
return nullptr;
|
||||
};
|
||||
virtual const ivec2& getSize() const = 0;
|
||||
virtual int32_t getWidth() const {
|
||||
return 0;
|
||||
};
|
||||
virtual int32_t getHeight() const {
|
||||
return 0;
|
||||
};
|
||||
virtual enum colorType getType() const {
|
||||
return egami::colorType::RGBA8;
|
||||
};
|
||||
virtual void clear() = 0;
|
||||
virtual void resize(const ivec2& _size, const etk::Color<uint8_t, 4>& _color, const ivec2& _startPos) = 0;
|
||||
virtual void resize(const ivec2& _size, const etk::Color<float, 4>& _color, const ivec2& _startPos) = 0;
|
||||
virtual void resize(const ivec2& _size, const etk::Color<uint16_t, 1>& _color, const ivec2& _startPos) = 0;
|
||||
virtual void resize(const ivec2& _size, const etk::Color<uint32_t, 1>& _color, const ivec2& _startPos) = 0;
|
||||
virtual void resize(const ivec2& _size, const etk::Color<float, 1>& _color, const ivec2& _startPos) = 0;
|
||||
virtual void resize(const ivec2& _size, const etk::Color<double, 1>& _color, const ivec2& _startPos) = 0;
|
||||
virtual void resize(const ivec2& _size, const ivec2& _startPos) = 0;
|
||||
virtual void set(const ivec2& _pos, const etk::Color<>& _newColor) = 0;
|
||||
virtual void set(const ivec2& _pos, const etk::Color<float>& _newColor) = 0;
|
||||
virtual void set(const ivec2& _pos, const etk::Color<uint16_t, 1>& _newColor) = 0;
|
||||
virtual void set(const ivec2& _pos, const etk::Color<uint32_t, 1>& _newColor) = 0;
|
||||
virtual void set(const ivec2& _pos, const etk::Color<float, 1>& _newColor) = 0;
|
||||
virtual void set(const ivec2& _pos, const etk::Color<double, 1>& _newColor) = 0;
|
||||
virtual etk::Color<> get(const ivec2& _pos) const = 0;
|
||||
virtual void set(const std::vector<etk::Color<float,4>>& _data, const ivec2& _size) = 0;
|
||||
virtual void set(const std::vector<etk::Color<uint8_t,4>>& _data, const ivec2& _size) = 0;
|
||||
};
|
||||
|
||||
class Image {
|
||||
private:
|
||||
// TODO : Change this in a unique_ptr ...
|
||||
std::shared_ptr<ImagePrivate> m_data; //!< data of the image
|
||||
ememory::SharedPtr<ImagePrivate> m_data; //!< data of the image
|
||||
public:
|
||||
/**
|
||||
* @brief contructor that create an empty image (no valid data)
|
||||
@ -39,6 +75,7 @@ namespace egami {
|
||||
Image();
|
||||
Image(const ivec2& _size,
|
||||
enum colorType _type = egami::colorType::undefined);
|
||||
~Image();
|
||||
// TODO : IMplement move operator ... and copy operator...
|
||||
public:
|
||||
void configure(const ivec2& _size=ivec2(32,32),
|
||||
@ -99,4 +136,3 @@ namespace egami {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
@ -9,35 +9,9 @@
|
||||
#include <vector>
|
||||
#include <etk/math/Vector2D.h>
|
||||
#include <etk/Color.h>
|
||||
#include <egami/debug.h>
|
||||
|
||||
namespace egami {
|
||||
class ImagePrivate {
|
||||
public:
|
||||
ImagePrivate() {};
|
||||
virtual ~ImagePrivate() {};
|
||||
virtual void* getTextureDataPointer() { return nullptr; };
|
||||
virtual const ivec2& getSize()=0;
|
||||
virtual int32_t getWidth() const { return 0; };
|
||||
virtual int32_t getHeight() const { return 0; };
|
||||
virtual enum colorType getType() { return egami::colorType::RGBA8; };
|
||||
virtual void clear() = 0;
|
||||
virtual void resize(const ivec2& _size, const etk::Color<uint8_t, 4>& _color, const ivec2& _startPos) = 0;
|
||||
virtual void resize(const ivec2& _size, const etk::Color<float, 4>& _color, const ivec2& _startPos) = 0;
|
||||
virtual void resize(const ivec2& _size, const etk::Color<uint16_t, 1>& _color, const ivec2& _startPos) = 0;
|
||||
virtual void resize(const ivec2& _size, const etk::Color<uint32_t, 1>& _color, const ivec2& _startPos) = 0;
|
||||
virtual void resize(const ivec2& _size, const etk::Color<float, 1>& _color, const ivec2& _startPos) = 0;
|
||||
virtual void resize(const ivec2& _size, const etk::Color<double, 1>& _color, const ivec2& _startPos) = 0;
|
||||
virtual void resize(const ivec2& _size, const ivec2& _startPos) = 0;
|
||||
virtual void set(const ivec2& _pos, const etk::Color<>& _newColor) = 0;
|
||||
virtual void set(const ivec2& _pos, const etk::Color<float>& _newColor) = 0;
|
||||
virtual void set(const ivec2& _pos, const etk::Color<uint16_t, 1>& _newColor) = 0;
|
||||
virtual void set(const ivec2& _pos, const etk::Color<uint32_t, 1>& _newColor) = 0;
|
||||
virtual void set(const ivec2& _pos, const etk::Color<float, 1>& _newColor) = 0;
|
||||
virtual void set(const ivec2& _pos, const etk::Color<double, 1>& _newColor) = 0;
|
||||
virtual etk::Color<> get(const ivec2& _pos) const = 0;
|
||||
virtual void set(const std::vector<etk::Color<float,4>>& _data, const ivec2& _size) = 0;
|
||||
virtual void set(const std::vector<etk::Color<uint8_t,4>>& _data, const ivec2& _size) = 0;
|
||||
};
|
||||
|
||||
template<typename T = etk::Color<>>
|
||||
class ImageTemplate : public ImagePrivate {
|
||||
@ -65,8 +39,10 @@ namespace egami {
|
||||
void* getTextureDataPointer() {
|
||||
return &m_data[0];
|
||||
};
|
||||
enum colorType getType();
|
||||
const ivec2& getSize() { return m_size; };
|
||||
enum colorType getType() const;
|
||||
const ivec2& getSize() {
|
||||
return m_size;
|
||||
};
|
||||
// -----------------------------------------------
|
||||
// -- basic tools :
|
||||
// -----------------------------------------------
|
||||
@ -249,28 +225,28 @@ namespace egami {
|
||||
}
|
||||
}
|
||||
};
|
||||
template <> enum colorType ImageTemplate<etk::Color<uint8_t>>::getType() {
|
||||
template <> enum colorType ImageTemplate<etk::Color<uint8_t>>::getType() const {
|
||||
return egami::colorType::RGBA8;
|
||||
}
|
||||
template <> enum colorType ImageTemplate<etk::Color<uint8_t, 3>>::getType() {
|
||||
template <> enum colorType ImageTemplate<etk::Color<uint8_t, 3>>::getType() const {
|
||||
return egami::colorType::RGB8;
|
||||
}
|
||||
template <> enum colorType ImageTemplate<etk::Color<float>>::getType() {
|
||||
template <> enum colorType ImageTemplate<etk::Color<float>>::getType() const {
|
||||
return egami::colorType::RGBAf;
|
||||
}
|
||||
template <> enum colorType ImageTemplate<etk::Color<float, 3>>::getType() {
|
||||
template <> enum colorType ImageTemplate<etk::Color<float, 3>>::getType() const {
|
||||
return egami::colorType::RGBf;
|
||||
}
|
||||
template <> enum colorType ImageTemplate<etk::Color<uint16_t, 1>>::getType() {
|
||||
template <> enum colorType ImageTemplate<etk::Color<uint16_t, 1>>::getType() const {
|
||||
return egami::colorType::unsignedInt16;
|
||||
}
|
||||
template <> enum colorType ImageTemplate<etk::Color<uint32_t, 1>>::getType() {
|
||||
template <> enum colorType ImageTemplate<etk::Color<uint32_t, 1>>::getType() const {
|
||||
return egami::colorType::unsignedInt32;
|
||||
}
|
||||
template <> enum colorType ImageTemplate<etk::Color<float, 1>>::getType() {
|
||||
template <> enum colorType ImageTemplate<etk::Color<float, 1>>::getType() const {
|
||||
return egami::colorType::float32;
|
||||
}
|
||||
template <> enum colorType ImageTemplate<etk::Color<double, 1>>::getType() {
|
||||
template <> enum colorType ImageTemplate<etk::Color<double, 1>>::getType() const {
|
||||
return egami::colorType::float64;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user