[DEV] add monochome image

This commit is contained in:
Edouard DUPIN 2014-01-07 21:35:05 +01:00
parent c14ac65e29
commit d7363f73e0
6 changed files with 145 additions and 4 deletions

View File

@ -64,3 +64,11 @@ void egami::Image::set(const ivec2& _pos, const etk::Color<>& _newColor) {
m_data[_pos.x()+_pos.y()*m_size.x()] = _newColor;
}
}
void egami::Image::insert(const ivec2& _pos, const egami::Image& _input) {
for(int32_t yyy = 0; yyy < _input.getSize().y() && _pos.y() + yyy < m_size.y(); ++yyy) {
for(int32_t xxx = 0; xxx < _input.getSize().x() && _pos.x() + xxx < m_size.x(); ++xxx) {
set(ivec2(_pos.x()+xxx, _pos.y()+yyy), _input.get(ivec2(xxx, yyy)) );
}
}
}

View File

@ -26,7 +26,9 @@ namespace egami {
~Image(void) { };
// EWOL internal API for Texture system :
public:
void* getTextureDataPointer(void) { return &m_data[0]; };
void* getTextureDataPointer(void) {
return &m_data[0];
};
// -----------------------------------------------
// -- basic tools :
// -----------------------------------------------
@ -34,12 +36,19 @@ namespace egami {
void resize(const ivec2& _size, const ivec2& _startPos=ivec2(0,0));
void resize(const ivec2& _size, const etk::Color<>& _color);
const ivec2& getSize(void) const { return m_size; };
int32_t getWidth(void) const { return m_size.x(); };
int32_t getHeight(void) const { return m_size.y(); };
const ivec2& getSize(void) const {
return m_size;
};
int32_t getWidth(void) const {
return m_size.x();
};
int32_t getHeight(void) const {
return m_size.y();
};
void clear(etk::Color<> _fill);
const etk::Color<>& get(const ivec2& _pos) const;
void set(const ivec2& _pos, const etk::Color<>& _newColor);
void insert(const ivec2& _pos, const egami::Image& _input);
};
};

66
egami/ImageMono.cpp Normal file
View File

@ -0,0 +1,66 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <egami/ImageMono.h>
egami::ImageMono::ImageMono(const ivec2& _size) :
m_size(_size) {
// basic element :
uint8_t tmpBg(0);
// preallocate data with a basic bg elements :
m_data.resize(m_size.x()*m_size.y(), tmpBg);
if ((uint32_t)m_size.x()*m_size.y() > m_data.size()) {
TK_ERROR("Allocation of data buffer in error");
return;
}
}
void egami::ImageMono::resize(const ivec2& _size, const uint8_t& _color) {
m_size=_size;
m_data.resize(m_size.x()*m_size.y(), _color);
}
void egami::ImageMono::resize(const ivec2& _size, const ivec2& _startPos) {
if (_size == m_size) {
// same size == > nothing to do ...
return;
}
// grow size :
egami::ImageMono tmpImage(*this);
m_size=_size;
uint8_t tmpBg(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));
}
}
}
void egami::ImageMono::clear(uint8_t _fill) {
for (int32_t iii=0; iii<m_size.x()*m_size.y(); iii++) {
m_data[iii] = _fill;
}
}
const uint8_t& egami::ImageMono::get(const ivec2& _pos) const {
static const uint8_t errorColor(0x00000000);
if( _pos.x()>0 && _pos.x()<m_size.x()
&& _pos.y()>0 && _pos.y()<m_size.y()) {
return m_data[_pos.x()+_pos.y()*m_size.x()];
}
return errorColor;
}
void egami::ImageMono::set(const ivec2& _pos, const uint8_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;
}
}

56
egami/ImageMono.h Normal file
View File

@ -0,0 +1,56 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EGAMI_IMAGE_MONO_H__
#define __EGAMI_IMAGE_MONO_H__
#include <etk/types.h>
#include <vector>
#include <etk/math/Vector2D.h>
#include <etk/Color.h>
namespace egami {
class ImageMono {
private:
ivec2 m_size;
std::vector<uint8_t> m_data;
public:
// constructor :
ImageMono(const ivec2& _size=ivec2(32,32));
// destructor
~ImageMono(void) { };
// EWOL internal API for Texture system :
public:
void* getTextureDataPointer(void) {
return &m_data[0];
};
// -----------------------------------------------
// -- basic tools :
// -----------------------------------------------
public :
void resize(const ivec2& _size, const ivec2& _startPos=ivec2(0,0));
void resize(const ivec2& _size, const uint8_t& _color);
const ivec2& getSize(void) const {
return m_size;
};
int32_t getWidth(void) const {
return m_size.x();
};
int32_t getHeight(void) const {
return m_size.y();
};
void clear(uint8_t _fill);
const uint8_t& get(const ivec2& _pos) const;
void set(const ivec2& _pos, const uint8_t& _newColor);
};
};
#endif

View File

@ -14,6 +14,7 @@
#include <etk/math/Vector2D.h>
#include <etk/Color.h>
#include <egami/Image.h>
#include <egami/ImageMono.h>
namespace egami
{

View File

@ -15,6 +15,7 @@ def create(target):
# add the file to compile:
myModule.add_src_file([
'egami/Image.cpp',
'egami/ImageMono.cpp',
'egami/egami.cpp',
'egami/debug.cpp',
'egami/wrapperPNG.cpp',