[DEV] change mode of color ==> advence interface and conversion (Not finished)
This commit is contained in:
parent
34eac48f51
commit
4cfeb0a91c
287
egami/Image.cpp
287
egami/Image.cpp
@ -8,83 +8,252 @@
|
||||
|
||||
#include <egami/Image.h>
|
||||
#include <egami/debug.h>
|
||||
#include <egami/ImagePrivate.h>
|
||||
#include <memory>
|
||||
|
||||
egami::Image::Image(const ivec2& _size) :
|
||||
m_size(_size) {
|
||||
// basic element :
|
||||
etk::Color<> tmpBg(0,0,0,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;
|
||||
egami::Image::Image(const ivec2& _size, enum colorType _type) :
|
||||
m_data(nullptr) {
|
||||
switch (_type) {
|
||||
case colorRGBA8:
|
||||
//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));
|
||||
break;
|
||||
case colorRGB8:
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint8_t, 3>>(_size));
|
||||
break;
|
||||
case colorRGBAf:
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<float>>(_size));
|
||||
break;
|
||||
case colorRGBf:
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<float, 3>>(_size));
|
||||
break;
|
||||
case colorU16:
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint16_t, 1>>(_size));
|
||||
break;
|
||||
case colorU32:
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint32_t, 1>>(_size));
|
||||
break;
|
||||
case colorFloat:
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<float, 1>>(_size));
|
||||
break;
|
||||
case colorDouble:
|
||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<double, 1>>(_size));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void egami::Image::resize(const ivec2& _size, const etk::Color<>& _color) {
|
||||
m_size=_size;
|
||||
m_data.resize(m_size.x()*m_size.y(), _color);
|
||||
void* egami::Image::getTextureDataPointer() {
|
||||
if (m_data == nullptr) {
|
||||
EGAMI_WARNING("No internal data for image : Can not get internal data pointer");
|
||||
return nullptr;
|
||||
}
|
||||
return m_data->getTextureDataPointer();
|
||||
}
|
||||
|
||||
void egami::Image::resize(const ivec2& _size, const ivec2& _startPos) {
|
||||
if (_size == m_size) {
|
||||
// same size == > nothing to do ...
|
||||
if (m_data == nullptr) {
|
||||
EGAMI_WARNING("No internal data for image : Can not resize");
|
||||
return;
|
||||
}
|
||||
// grow size :
|
||||
egami::Image 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));
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void egami::Image::resize(const ivec2& _size, const etk::Color<>& _color, const ivec2& _startPos) {
|
||||
if (m_data == nullptr) {
|
||||
EGAMI_WARNING("No internal data for image : Can not resize");
|
||||
return;
|
||||
}
|
||||
//m_data->resize(_size, _color);
|
||||
}
|
||||
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);
|
||||
}
|
||||
void egami::Image::resize(const ivec2& _size, const etk::Color<int16_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);
|
||||
}
|
||||
void egami::Image::resize(const ivec2& _size, const etk::Color<int32_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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
const ivec2& egami::Image::getSize() const {
|
||||
if (m_data == nullptr) {
|
||||
EGAMI_WARNING("No internal data for image : Can not resize");
|
||||
return ivec2(0,0);
|
||||
}
|
||||
return m_data->getSize();
|
||||
}
|
||||
|
||||
int32_t egami::Image::getWidth() const {
|
||||
if (m_data == nullptr) {
|
||||
EGAMI_WARNING("No internal data for image : Can not resize");
|
||||
return 0;
|
||||
}
|
||||
return m_data->getWidth();
|
||||
}
|
||||
|
||||
int32_t egami::Image::getHeight() const {
|
||||
if (m_data == nullptr) {
|
||||
EGAMI_WARNING("No internal data for image : Can not resize");
|
||||
return 0;
|
||||
}
|
||||
return m_data->getHeight();
|
||||
}
|
||||
|
||||
|
||||
void egami::Image::scale(const ivec2& _size) {
|
||||
// TODO : Add capabilities ...
|
||||
int32_t stepX = m_size.x() / _size.x();
|
||||
int32_t stepY = m_size.y() / _size.y();
|
||||
stepX = etk_max(1, stepX);
|
||||
stepY = etk_max(1, stepY);
|
||||
EGAMI_VERBOSE("move : " << stepX << " , " << stepY << " from : " << m_size << " ==> " << _size);
|
||||
for (int32_t yyy = 0; yyy < _size.y(); ++yyy) {
|
||||
for (int32_t xxx = 0; xxx < _size.x(); ++xxx) {
|
||||
set(ivec2(xxx, yyy), get(ivec2(xxx*stepX, yyy*stepY)));
|
||||
}
|
||||
}
|
||||
resize(_size);
|
||||
}
|
||||
|
||||
|
||||
void egami::Image::clear(etk::Color<> _fill) {
|
||||
for (int32_t iii=0; iii<m_size.x()*m_size.y(); iii++) {
|
||||
m_data[iii] = _fill;
|
||||
if (m_data == nullptr) {
|
||||
EGAMI_WARNING("No internal data for image : Can not scale");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const etk::Color<>& egami::Image::get(const ivec2& _pos) const {
|
||||
static const etk::Color<> 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::Image::set(const ivec2& _pos, const etk::Color<>& _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;
|
||||
void egami::Image::clear(const etk::Color<>& _color) {
|
||||
if (m_data == nullptr) {
|
||||
EGAMI_WARNING("No internal data for image : Can not clear");
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
void egami::Image::clear(const etk::Color<float>& _color) {
|
||||
if (m_data == nullptr) {
|
||||
EGAMI_WARNING("No internal data for image : Can not clear");
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
void egami::Image::clear(const etk::Color<int16_t, 1>& _color) {
|
||||
if (m_data == nullptr) {
|
||||
EGAMI_WARNING("No internal data for image : Can not clear");
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
void egami::Image::clear(const etk::Color<int32_t, 1>& _color) {
|
||||
if (m_data == nullptr) {
|
||||
EGAMI_WARNING("No internal data for image : Can not clear");
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
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;
|
||||
}
|
||||
|
||||
};
|
||||
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;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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)) );
|
||||
}
|
||||
if (m_data == nullptr) {
|
||||
EGAMI_WARNING("No internal data for image : Can not insert image");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void egami::Image::set(const ivec2& _pos, const etk::Color<>& _newColor) {
|
||||
|
||||
}
|
||||
|
||||
void egami::Image::set(const ivec2& _pos, const etk::Color<float>& _newColor) {
|
||||
|
||||
}
|
||||
|
||||
void egami::Image::set(const ivec2& _pos, const etk::Color<uint16_t, 1>& _newColor) {
|
||||
|
||||
}
|
||||
|
||||
void egami::Image::set(const ivec2& _pos, const etk::Color<uint32_t, 1>& _newColor) {
|
||||
|
||||
}
|
||||
|
||||
void egami::Image::set(const ivec2& _pos, const etk::Color<float, 1>& _newColor) {
|
||||
|
||||
}
|
||||
|
||||
void egami::Image::set(const ivec2& _pos, const etk::Color<double, 1>& _newColor) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,41 +13,70 @@
|
||||
#include <vector>
|
||||
#include <etk/math/Vector2D.h>
|
||||
#include <etk/Color.h>
|
||||
#include <etk/stdTools.h>
|
||||
#include <memory>
|
||||
|
||||
namespace egami {
|
||||
enum colorType {
|
||||
colorRGBA8,
|
||||
colorRGB8,
|
||||
colorRGBAf,
|
||||
colorRGBf,
|
||||
colorU16,
|
||||
colorU32,
|
||||
colorFloat,
|
||||
colorDouble,
|
||||
};
|
||||
class ImagePrivate;
|
||||
class Image {
|
||||
private:
|
||||
ivec2 m_size;
|
||||
std::vector<etk::Color<> > m_data;
|
||||
std::shared_ptr<ImagePrivate> m_data;
|
||||
public:
|
||||
// constructor :
|
||||
Image(const ivec2& _size=ivec2(32,32));
|
||||
Image(const ivec2& _size=ivec2(32,32), enum colorType _type=colorRGBA8);
|
||||
// destructor
|
||||
~Image() { };
|
||||
// EWOL internal API for Texture system :
|
||||
public:
|
||||
void* getTextureDataPointer() {
|
||||
return &m_data[0];
|
||||
};
|
||||
void* getTextureDataPointer();
|
||||
// -----------------------------------------------
|
||||
// -- basic tools :
|
||||
// -----------------------------------------------
|
||||
public :
|
||||
void resize(const ivec2& _size, const ivec2& _startPos=ivec2(0,0));
|
||||
void resize(const ivec2& _size, const etk::Color<>& _color);
|
||||
// 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<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));
|
||||
|
||||
const ivec2& getSize() const {
|
||||
return m_size;
|
||||
};
|
||||
int32_t getWidth() const {
|
||||
return m_size.x();
|
||||
};
|
||||
int32_t getHeight() const {
|
||||
return m_size.y();
|
||||
};
|
||||
void clear(etk::Color<> _fill);
|
||||
const etk::Color<>& get(const ivec2& _pos) const;
|
||||
const ivec2& getSize() const;
|
||||
int32_t getWidth() const;
|
||||
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<float, 1>& _color);
|
||||
void clear(const etk::Color<double, 1>& _color);
|
||||
|
||||
etk::Color<> get(const ivec2& _pos) const;
|
||||
/*
|
||||
etk::Color<> getRGBA8(const ivec2& _pos) const;
|
||||
etk::Color<float> getRGBAf(const ivec2& _pos) const;
|
||||
uint16_t getU16(const ivec2& _pos) const;
|
||||
uint32_t getU32(const ivec2& _pos) const;
|
||||
float getFloat(const ivec2& _pos) const;
|
||||
double getDouble(const ivec2& _pos) const;
|
||||
*/
|
||||
void set(const ivec2& _pos, const etk::Color<>& _newColor);
|
||||
void set(const ivec2& _pos, const etk::Color<float>& _newColor);
|
||||
void set(const ivec2& _pos, const etk::Color<uint16_t, 1>& _newColor);
|
||||
void set(const ivec2& _pos, const etk::Color<uint32_t, 1>& _newColor);
|
||||
void set(const ivec2& _pos, const etk::Color<float, 1>& _newColor);
|
||||
void set(const ivec2& _pos, const etk::Color<double, 1>& _newColor);
|
||||
void insert(const ivec2& _pos, const egami::Image& _input);
|
||||
/**
|
||||
* @brief Scale an image in an other dimention.
|
||||
@ -56,7 +85,6 @@ namespace egami {
|
||||
*/
|
||||
void scale(const ivec2& _size);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
166
egami/ImagePrivate.h
Normal file
166
egami/ImagePrivate.h
Normal file
@ -0,0 +1,166 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __EGAMI_IMAGE_PRIVATE_H__
|
||||
#define __EGAMI_IMAGE_PRIVATE_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <vector>
|
||||
#include <etk/math/Vector2D.h>
|
||||
#include <etk/Color.h>
|
||||
|
||||
namespace egami {
|
||||
class ImagePrivate {
|
||||
public:
|
||||
ImagePrivate() {};
|
||||
virtual void* getTextureDataPointer() { return nullptr; };
|
||||
virtual const ivec2& getSize() const { return ivec2(0,0);};
|
||||
virtual int32_t getWidth() const { return 0; };
|
||||
virtual int32_t getHeight() const { return 0; };
|
||||
virtual enum colorType getType() { return colorRGBA8; };
|
||||
};
|
||||
|
||||
template<typename T = etk::Color<>>
|
||||
class ImageTemplate : public ImagePrivate {
|
||||
private:
|
||||
ivec2 m_size;
|
||||
std::vector<T> m_data;
|
||||
public:
|
||||
// constructor :
|
||||
ImageTemplate(const ivec2& _size=ivec2(32,32)) {
|
||||
// basic element :
|
||||
etk::Color<> tmpBg(0,0,0,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;
|
||||
}
|
||||
}
|
||||
|
||||
// destructor
|
||||
virtual ~ImageTemplate() { };
|
||||
// EWOL internal API for Texture system :
|
||||
public:
|
||||
void* getTextureDataPointer() {
|
||||
return &m_data[0];
|
||||
};
|
||||
|
||||
enum colorType getType();
|
||||
// -----------------------------------------------
|
||||
// -- basic tools :
|
||||
// -----------------------------------------------
|
||||
public :
|
||||
void resize(const ivec2& _size, const ivec2& _startPos=ivec2(0,0)) {
|
||||
if (_size == m_size) {
|
||||
// same size == > nothing to do ...
|
||||
return;
|
||||
}
|
||||
// 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...
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
void resize(const ivec2& _size, const T& _color, const ivec2& _startPos=ivec2(0,0)) {
|
||||
m_size=_size;
|
||||
m_data.resize(m_size.x()*m_size.y(), _color);
|
||||
}
|
||||
|
||||
|
||||
const ivec2& getSize() const {
|
||||
return m_size;
|
||||
};
|
||||
int32_t getWidth() const {
|
||||
return m_size.x();
|
||||
};
|
||||
int32_t getHeight() const {
|
||||
return m_size.y();
|
||||
};
|
||||
void clear(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 {
|
||||
static const 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 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;
|
||||
}
|
||||
}
|
||||
void insert(const ivec2& _pos, const ImageTemplate<T>& _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)) );
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief Scale an image in an other dimention.
|
||||
* @param[in] _size Destination size of the image.
|
||||
* @TODO Set this function more capacity like not a multiple ratio...
|
||||
*/
|
||||
void scale(const ivec2& _size) {
|
||||
// TODO : Add capabilities ...
|
||||
int32_t stepX = m_size.x() / _size.x();
|
||||
int32_t stepY = m_size.y() / _size.y();
|
||||
stepX = std::max(1, stepX);
|
||||
stepY = std::max(1, stepY);
|
||||
EGAMI_VERBOSE("move : " << stepX << " , " << stepY << " from : " << m_size << " ==> " << _size);
|
||||
for (int32_t yyy = 0; yyy < _size.y(); ++yyy) {
|
||||
for (int32_t xxx = 0; xxx < _size.x(); ++xxx) {
|
||||
set(ivec2(xxx, yyy), get(ivec2(xxx*stepX, yyy*stepY)));
|
||||
}
|
||||
}
|
||||
resize(_size);
|
||||
}
|
||||
};
|
||||
template <> enum colorType ImageTemplate<etk::Color<uint8_t>>::getType() {
|
||||
return colorRGBA8;
|
||||
}
|
||||
template <> enum colorType ImageTemplate<etk::Color<uint8_t, 3>>::getType() {
|
||||
return colorRGB8;
|
||||
}
|
||||
template <> enum colorType ImageTemplate<etk::Color<float>>::getType() {
|
||||
return colorRGBAf;
|
||||
}
|
||||
template <> enum colorType ImageTemplate<etk::Color<float, 3>>::getType() {
|
||||
return colorRGBf;
|
||||
}
|
||||
template <> enum colorType ImageTemplate<etk::Color<uint16_t, 1>>::getType() {
|
||||
return colorU16;
|
||||
}
|
||||
template <> enum colorType ImageTemplate<etk::Color<uint32_t, 1>>::getType() {
|
||||
return colorU32;
|
||||
}
|
||||
template <> enum colorType ImageTemplate<etk::Color<float, 1>>::getType() {
|
||||
return colorFloat;
|
||||
}
|
||||
template <> enum colorType ImageTemplate<etk::Color<double, 1>>::getType() {
|
||||
return colorDouble;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@ -91,6 +91,7 @@ static void generateDistanceField(const egami::ImageMono& _input, egami::Image&
|
||||
std::vector<double> data(size);
|
||||
std::vector<double> outside(size);
|
||||
std::vector<double> inside(size);
|
||||
/*
|
||||
// Convert img into double (data)
|
||||
double img_min = 255, img_max = -255;
|
||||
for (int32_t yyy = 0; yyy < _input.getSize().y(); ++yyy) {
|
||||
@ -159,6 +160,7 @@ static void generateDistanceField(const egami::ImageMono& _input, egami::Image&
|
||||
_output.set(ivec2(xxx, yyy), etk::Color<>((int32_t)val,(int32_t)val,(int32_t)val,(int32_t)val));
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@ -173,12 +175,14 @@ bool egami::generateDistanceFieldFile(const std::string& _input, const std::stri
|
||||
}
|
||||
// Generate distance field :
|
||||
egami::ImageMono input;
|
||||
/*
|
||||
input.resize(data.getSize());
|
||||
for (int32_t yyy = 0; yyy < data.getSize().y(); ++yyy) {
|
||||
for (int32_t xxx = 0; xxx < data.getSize().x(); ++xxx) {
|
||||
input.set(ivec2(xxx, yyy), data.get(ivec2(xxx, yyy)).a() );
|
||||
}
|
||||
}
|
||||
*/
|
||||
generateDistanceField(input, data);
|
||||
// scale:
|
||||
data.scale(ivec2(64,64));
|
||||
|
Loading…
x
Reference in New Issue
Block a user