[DEV] better multiple type of image

This commit is contained in:
Edouard DUPIN 2014-07-10 21:13:03 +02:00
parent 4cfeb0a91c
commit 6a409ac838
3 changed files with 173 additions and 90 deletions

View File

@ -55,48 +55,7 @@ void egami::Image::resize(const ivec2& _size, const ivec2& _startPos) {
EGAMI_WARNING("No internal data for image : Can not resize");
return;
}
switch(m_data->getType()) {
case colorRGBA8: {
std::shared_ptr<ImageTemplate<etk::Color<uint8_t>>> tmp = std::dynamic_pointer_cast<ImageTemplate<etk::Color<uint8_t>>>(m_data);
tmp->resize(_size, _startPos);
}
break;
case colorRGB8: {
std::shared_ptr<ImageTemplate<etk::Color<uint8_t, 3>>> tmp = std::dynamic_pointer_cast<ImageTemplate<etk::Color<uint8_t, 3>>>(m_data);
tmp->resize(_size, _startPos);
}
break;
case colorRGBAf: {
std::shared_ptr<ImageTemplate<etk::Color<float>>> tmp = std::dynamic_pointer_cast<ImageTemplate<etk::Color<float>>>(m_data);
tmp->resize(_size, _startPos);
}
break;
case colorRGBf: {
std::shared_ptr<ImageTemplate<etk::Color<float, 3>>> tmp = std::dynamic_pointer_cast<ImageTemplate<etk::Color<float, 3>>>(m_data);
tmp->resize(_size, _startPos);
}
break;
case colorU16: {
std::shared_ptr<ImageTemplate<etk::Color<uint8_t, 1>>> tmp = std::dynamic_pointer_cast<ImageTemplate<etk::Color<uint8_t, 1>>>(m_data);
tmp->resize(_size, _startPos);
}
break;
case colorU32: {
std::shared_ptr<ImageTemplate<etk::Color<uint32_t, 1>>> tmp = std::dynamic_pointer_cast<ImageTemplate<etk::Color<uint32_t, 1>>>(m_data);
tmp->resize(_size, _startPos);
}
break;
case colorFloat: {
std::shared_ptr<ImageTemplate<etk::Color<float, 1>>> tmp = std::dynamic_pointer_cast<ImageTemplate<etk::Color<float, 1>>>(m_data);
tmp->resize(_size, _startPos);
}
break;
case colorDouble: {
std::shared_ptr<ImageTemplate<etk::Color<double, 1>>> tmp = std::dynamic_pointer_cast<ImageTemplate<etk::Color<double, 1>>>(m_data);
tmp->resize(_size, _startPos);
}
break;
}
m_data->resize(_size, _startPos);
}
void egami::Image::resize(const ivec2& _size, const etk::Color<>& _color, const ivec2& _startPos) {
@ -104,48 +63,49 @@ void egami::Image::resize(const ivec2& _size, const etk::Color<>& _color, const
EGAMI_WARNING("No internal data for image : Can not resize");
return;
}
//m_data->resize(_size, _color);
m_data->resize(_size, _color, _startPos);
}
void egami::Image::resize(const ivec2& _size, const etk::Color<float>& _color, const ivec2& _startPos) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
return;
}
//m_data->resize(_size, _color);
m_data->resize(_size, _color, _startPos);
}
void egami::Image::resize(const ivec2& _size, const etk::Color<int16_t, 1>& _color, const ivec2& _startPos) {
void egami::Image::resize(const ivec2& _size, const etk::Color<uint16_t, 1>& _color, const ivec2& _startPos) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
return;
}
//m_data->resize(_size, _color);
m_data->resize(_size, _color, _startPos);
}
void egami::Image::resize(const ivec2& _size, const etk::Color<int32_t, 1>& _color, const ivec2& _startPos) {
void egami::Image::resize(const ivec2& _size, const etk::Color<uint32_t, 1>& _color, const ivec2& _startPos) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
return;
}
//m_data->resize(_size, _color);
m_data->resize(_size, _color, _startPos);
}
void egami::Image::resize(const ivec2& _size, const etk::Color<float, 1>& _color, const ivec2& _startPos) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
return;
}
//m_data->resize(_size, _color);
m_data->resize(_size, _color, _startPos);
}
void egami::Image::resize(const ivec2& _size, const etk::Color<double, 1>& _color, const ivec2& _startPos) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
return;
}
//m_data->resize(_size, _color);
m_data->resize(_size, _color, _startPos);
}
const ivec2& egami::Image::getSize() const {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not resize");
return ivec2(0,0);
static const ivec2 error(0,0);
return error;
}
return m_data->getSize();
}
@ -172,6 +132,7 @@ void egami::Image::scale(const ivec2& _size) {
EGAMI_WARNING("No internal data for image : Can not scale");
return;
}
resize(_size);
}
void egami::Image::clear(const etk::Color<>& _color) {
@ -179,49 +140,49 @@ void egami::Image::clear(const etk::Color<>& _color) {
EGAMI_WARNING("No internal data for image : Can not clear");
return;
}
m_data->clear();
};
void egami::Image::clear(const etk::Color<float>& _color) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not clear");
return;
}
m_data->clear();
};
void egami::Image::clear(const etk::Color<int16_t, 1>& _color) {
void egami::Image::clear(const etk::Color<uint16_t, 1>& _color) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not clear");
return;
}
m_data->clear();
};
void egami::Image::clear(const etk::Color<int32_t, 1>& _color) {
void egami::Image::clear(const etk::Color<uint32_t, 1>& _color) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not clear");
return;
}
m_data->clear();
};
void egami::Image::clear(const etk::Color<float, 1>& _color) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not clear");
return;
}
m_data->clear();
};
void egami::Image::clear(const etk::Color<double, 1>& _color) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not clear");
return;
}
m_data->clear();
};
etk::Color<> egami::Image::get(const ivec2& _pos) const {
if (m_data == nullptr) {
return etk::Color<>(0,0,0,0);
}
return etk::Color<>(0,0,0,0);
return m_data->get(_pos);;
}
void egami::Image::insert(const ivec2& _pos, const egami::Image& _input) {
@ -229,31 +190,55 @@ void egami::Image::insert(const ivec2& _pos, const egami::Image& _input) {
EGAMI_WARNING("No internal data for image : Can not insert image");
return;
}
EGAMI_CRITICAL("Insert image");
}
void egami::Image::set(const ivec2& _pos, const etk::Color<>& _newColor) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
return;
}
m_data->set(_pos, _newColor);
}
void egami::Image::set(const ivec2& _pos, const etk::Color<float>& _newColor) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
return;
}
m_data->set(_pos, _newColor);
}
void egami::Image::set(const ivec2& _pos, const etk::Color<uint16_t, 1>& _newColor) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
return;
}
m_data->set(_pos, _newColor);
}
void egami::Image::set(const ivec2& _pos, const etk::Color<uint32_t, 1>& _newColor) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
return;
}
m_data->set(_pos, _newColor);
}
void egami::Image::set(const ivec2& _pos, const etk::Color<float, 1>& _newColor) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
return;
}
m_data->set(_pos, _newColor);
}
void egami::Image::set(const ivec2& _pos, const etk::Color<double, 1>& _newColor) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
return;
}
m_data->set(_pos, _newColor);
}

View File

@ -47,8 +47,8 @@ namespace egami {
// TODO : Create a template function ...
void resize(const ivec2& _size, const etk::Color<>& _color, const ivec2& _startPos=ivec2(0,0));
void resize(const ivec2& _size, const etk::Color<float>& _color, const ivec2& _startPos=ivec2(0,0));
void resize(const ivec2& _size, const etk::Color<int16_t, 1>& _color, const ivec2& _startPos=ivec2(0,0));
void resize(const ivec2& _size, const etk::Color<int32_t, 1>& _color, const ivec2& _startPos=ivec2(0,0));
void resize(const ivec2& _size, const etk::Color<uint16_t, 1>& _color, const ivec2& _startPos=ivec2(0,0));
void resize(const ivec2& _size, const etk::Color<uint32_t, 1>& _color, const ivec2& _startPos=ivec2(0,0));
void resize(const ivec2& _size, const etk::Color<float, 1>& _color, const ivec2& _startPos=ivec2(0,0));
void resize(const ivec2& _size, const etk::Color<double, 1>& _color, const ivec2& _startPos=ivec2(0,0));
@ -57,8 +57,8 @@ namespace egami {
int32_t getHeight() const;
void clear(const etk::Color<>& _color);
void clear(const etk::Color<float>& _color);
void clear(const etk::Color<int16_t, 1>& _color);
void clear(const etk::Color<int32_t, 1>& _color);
void clear(const etk::Color<uint16_t, 1>& _color);
void clear(const etk::Color<uint32_t, 1>& _color);
void clear(const etk::Color<float, 1>& _color);
void clear(const etk::Color<double, 1>& _color);

View File

@ -18,11 +18,27 @@ namespace egami {
class ImagePrivate {
public:
ImagePrivate() {};
virtual ~ImagePrivate() {};
virtual void* getTextureDataPointer() { return nullptr; };
virtual const ivec2& getSize() const { return ivec2(0,0);};
virtual const ivec2& getSize()=0;
virtual int32_t getWidth() const { return 0; };
virtual int32_t getHeight() const { return 0; };
virtual enum colorType getType() { return colorRGBA8; };
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;
};
template<typename T = etk::Color<>>
@ -32,7 +48,8 @@ namespace egami {
std::vector<T> m_data;
public:
// constructor :
ImageTemplate(const ivec2& _size=ivec2(32,32)) {
ImageTemplate(const ivec2& _size=ivec2(32,32)) :
m_size(_size) {
// basic element :
etk::Color<> tmpBg(0,0,0,0);
// preallocate data with a basic bg elements :
@ -50,37 +67,111 @@ namespace egami {
void* getTextureDataPointer() {
return &m_data[0];
};
enum colorType getType();
const ivec2& getSize() { return m_size; };
// -----------------------------------------------
// -- basic tools :
// -----------------------------------------------
public :
void resize(const ivec2& _size, const ivec2& _startPos=ivec2(0,0)) {
void resize__(const ivec2& _size, const ivec2& _startPos=ivec2(0,0)) {
if (_size == m_size) {
// same size == > nothing to do ...
return;
}
if ((size_t)(_size.x()*_size.y()) > m_data.size()) {
m_data.resize(_size.x()*_size.y());
}
// grow size :
/*
egami::ImagePrivate* tmpImage(*this);
m_size=_size;
etk::Color<> tmpBg(0,0,0,0);
m_data.resize(m_size.x()*m_size.y(), tmpBg);
for (int32_t jjj=0; jjj<m_size.y(); jjj++) {
for (int32_t iii=0; iii<m_size.y(); iii++) {
ivec2 tmppos(iii,jjj);
//set(tmppos, tmpImage.get(tmppos));
// TODO : set the special case depending on the input and the output...
if (_size.x() == m_size.x()) {
if (_size.y() < m_size.y()) {
// Just remove lines ....
} else {
// just add lines
}
} else if (_size.x() < m_size.x()) {
if (_size.y() <= m_size.y()) {
for (int32_t yyy=0; yyy<_size.y(); ++yyy) {
for (int32_t xxx=0; xxx<_size.x(); ++xxx) {
m_data[yyy*_size.x()+xxx] = m_data[yyy*m_size.x()+xxx];
}
}
} else {
for (int32_t yyy=m_size.y()-1; yyy>=0; --yyy) {
for (int32_t xxx=0; xxx<_size.x(); ++xxx) {
m_data[yyy*_size.x()+xxx] = m_data[yyy*m_size.x()+xxx];
}
}
}
} else { // (_size.x() > m_size.x())
if (_size.y() <= m_size.y()) {
for (int32_t yyy=0; yyy<_size.y(); ++yyy) {
for (int32_t xxx=0; xxx<m_size.x(); ++xxx) {
m_data[yyy*_size.x()+xxx] = m_data[yyy*m_size.x()+xxx];
}
}
} else {
for (int32_t yyy=m_size.y()-1; yyy>=0; --yyy) {
for (int32_t xxx=0; xxx<m_size.x(); ++xxx) {
m_data[yyy*_size.x()+xxx] = m_data[yyy*m_size.x()+xxx];
}
}
}
}
*/
if ((size_t)(_size.x()*_size.y()) < m_data.size()) {
m_data.resize(_size.x()*_size.y());
}
m_size = _size;
}
void resize(const ivec2& _size, const T& _color, const ivec2& _startPos=ivec2(0,0)) {
void resize__(const ivec2& _size, const T& _color) {
m_size=_size;
m_data.resize(m_size.x()*m_size.y(), _color);
}
void resize(const ivec2& _size, const etk::Color<uint8_t, 4>& _color, const ivec2& _startPos) {
resize__(_size, _color);
}
void resize(const ivec2& _size, const etk::Color<float, 4>& _color, const ivec2& _startPos) {
resize__(_size, _color);
}
void resize(const ivec2& _size, const etk::Color<uint16_t, 1>& _color, const ivec2& _startPos) {
resize__(_size, _color);
}
void resize(const ivec2& _size, const etk::Color<uint32_t, 1>& _color, const ivec2& _startPos) {
resize__(_size, _color);
}
void resize(const ivec2& _size, const etk::Color<float, 1>& _color, const ivec2& _startPos) {
resize__(_size, _color);
}
void resize(const ivec2& _size, const etk::Color<double, 1>& _color, const ivec2& _startPos) {
resize__(_size, _color);
}
void resize(const ivec2& _size, const ivec2& _startPos) {
resize__(_size);
}
template<typename TYPE_2> void resize(const ivec2& _size, const TYPE_2& _color) {
T tmp(_color);
resize__(_size, tmp);
}
void set(const ivec2& _pos, const etk::Color<>& _newColor) {
set__(_pos, _newColor);
}
void set(const ivec2& _pos, const etk::Color<float>& _newColor) {
set__(_pos, _newColor);
}
void set(const ivec2& _pos, const etk::Color<uint16_t, 1>& _newColor) {
set__(_pos, _newColor);
}
void set(const ivec2& _pos, const etk::Color<uint32_t, 1>& _newColor) {
set__(_pos, _newColor);
}
void set(const ivec2& _pos, const etk::Color<float, 1>& _newColor) {
set__(_pos, _newColor);
}
void set(const ivec2& _pos, const etk::Color<double, 1>& _newColor) {
set__(_pos, _newColor);
}
const ivec2& getSize() const {
return m_size;
@ -91,12 +182,19 @@ namespace egami {
int32_t getHeight() const {
return m_size.y();
};
void clear(const T& _fill) {
void clearColor(const T& _fill) {
for (int32_t iii=0; iii<m_size.x()*m_size.y(); iii++) {
m_data[iii] = _fill;
}
}
const T& get(const ivec2& _pos) const {
void clear() {
clearColor(T::emptyColor);
}
etk::Color<> get(const ivec2& _pos) const {
return get__(_pos);
}
const T& get__(const ivec2& _pos) const {
static const T errorColor(0x00000000);
if( _pos.x()>0 && _pos.x()<m_size.x()
&& _pos.y()>0 && _pos.y()<m_size.y()) {
@ -104,7 +202,7 @@ namespace egami {
}
return errorColor;
}
void set(const ivec2& _pos, const T& _newColor) {
void set__(const ivec2& _pos, const T& _newColor) {
if( _pos.x()>=0 && _pos.x()<m_size.x()
&& _pos.y()>=0 && _pos.y()<m_size.y()) {
m_data[_pos.x()+_pos.y()*m_size.x()] = _newColor;