[DEV] update to esvg 0.6-dev and create basic dev version

This commit is contained in:
Edouard DUPIN 2015-12-02 22:05:16 +01:00
parent 324a951c3c
commit bccb11804d
6 changed files with 37 additions and 36 deletions

View File

@ -256,4 +256,11 @@ void egami::Image::set(const ivec2& _pos, const etk::Color<double, 1>& _newColor
m_data->set(_pos, _newColor); m_data->set(_pos, _newColor);
} }
void egami::Image::set(const std::vector<etk::Color<float,4>>& _data, const ivec2& _size) {
if (m_data == nullptr) {
EGAMI_WARNING("No internal data for image : Can not set color");
return;
}
m_data->set(_data, _size);
}

View File

@ -84,6 +84,8 @@ namespace egami {
* @TODO Set this function more capacity like not a multiple ratio... * @TODO Set this function more capacity like not a multiple ratio...
*/ */
void scale(const ivec2& _size); void scale(const ivec2& _size);
void set(const std::vector<etk::Color<float,4>>& _data, const ivec2& _size);
}; };
}; };

View File

@ -39,6 +39,7 @@ namespace egami {
virtual void set(const ivec2& _pos, const etk::Color<float, 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 void set(const ivec2& _pos, const etk::Color<double, 1>& _newColor) = 0;
virtual etk::Color<> get(const ivec2& _pos) const = 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;
}; };
template<typename T = etk::Color<>> template<typename T = etk::Color<>>
@ -234,6 +235,14 @@ namespace egami {
} }
resize(_size); resize(_size);
} }
void set(const std::vector<etk::Color<float,4>>& _data, const ivec2& _size) {
m_data.clear();
m_size = _size;
m_data.resize(_data.size());
for (size_t iii=0; iii<m_data.size(); ++iii) {
m_data[iii] = _data[iii];
}
}
}; };
template <> enum colorType ImageTemplate<etk::Color<uint8_t>>::getType() { template <> enum colorType ImageTemplate<etk::Color<uint8_t>>::getType() {
return colorRGBA8; return colorRGBA8;

View File

@ -58,11 +58,11 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
EWOL_ERROR("not enought data in the file named=\"" << fileName << "\""); EWOL_ERROR("not enought data in the file named=\"" << fileName << "\"");
return; return;
}*/ }*/
if (false == fileName.exist()) { if (fileName.exist() == false) {
EGAMI_ERROR("File does not existed=\"" << fileName << "\""); EGAMI_ERROR("File does not existed=\"" << fileName << "\"");
return false; return false;
} }
if(false == fileName.fileOpenRead() ) { if(fileName.fileOpenRead() ==false) {
EGAMI_ERROR("Can not find the file name=\"" << fileName << "\""); EGAMI_ERROR("Can not find the file name=\"" << fileName << "\"");
return false; return false;
} }
@ -77,7 +77,7 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
fileName.fileClose(); fileName.fileClose();
return false; return false;
} }
if(false == fileName.fileSeek(m_FileHeader.bfOffBits, etk::FSN_SEEK_START)) { if(fileName.fileSeek(m_FileHeader.bfOffBits, etk::FSN_SEEK_START) == false) {
EGAMI_ERROR("error with the 'bfOffBits' in the file named=\"" << fileName << "\""); EGAMI_ERROR("error with the 'bfOffBits' in the file named=\"" << fileName << "\"");
fileName.fileClose(); fileName.fileClose();
return false; return false;
@ -123,10 +123,10 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
// reallocate the image // reallocate the image
_ouputImage.resize(ivec2(m_width,m_height)); _ouputImage.resize(ivec2(m_width,m_height));
uint8_t* m_data = NULL; std::vector<uint8_t> m_data;
if(0 != m_InfoHeader.biSizeImage) { if(0 != m_InfoHeader.biSizeImage) {
m_data=new uint8_t[m_InfoHeader.biSizeImage]; m_data.resize(m_InfoHeader.biSizeImage, 0);
if (fileName.fileRead(m_data,m_InfoHeader.biSizeImage,1) != 1){ if (fileName.fileRead(&m_data[0],m_InfoHeader.biSizeImage,1) != 1){
EGAMI_CRITICAL("Can not read the file with the good size..."); EGAMI_CRITICAL("Can not read the file with the good size...");
} }
} }
@ -137,7 +137,7 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
// need now to generate RGBA data ... // need now to generate RGBA data ...
switch(m_dataMode) { switch(m_dataMode) {
case BITS_16_R5G6B5: { case BITS_16_R5G6B5: {
uint16_t * pointer = (uint16_t*)m_data; uint16_t * pointer = (uint16_t*)(&m_data[0]);
for(int32_t yyy=0; yyy<m_height; yyy++) { for(int32_t yyy=0; yyy<m_height; yyy++) {
for(int32_t xxx=0; xxx<m_width; xxx++) { for(int32_t xxx=0; xxx<m_width; xxx++) {
tmpColor.setR((uint8_t)((*pointer & 0xF800) >> 8)); tmpColor.setR((uint8_t)((*pointer & 0xF800) >> 8));
@ -151,7 +151,7 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
} }
break; break;
case BITS_16_X1R5G5B5: { case BITS_16_X1R5G5B5: {
uint16_t * pointer = (uint16_t*)m_data; uint16_t * pointer = (uint16_t*)(&m_data[0]);
for(int32_t yyy=0; yyy<m_height; yyy++) { for(int32_t yyy=0; yyy<m_height; yyy++) {
for(int32_t xxx=0; xxx<m_width; xxx++) { for(int32_t xxx=0; xxx<m_width; xxx++) {
tmpColor.setR((int8_t)((*pointer & 0x7C00) >> 7)); tmpColor.setR((int8_t)((*pointer & 0x7C00) >> 7));
@ -165,7 +165,7 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
} }
break; break;
case BITS_24_R8G8B8: { case BITS_24_R8G8B8: {
uint8_t * pointer = m_data; uint8_t * pointer = (&m_data[0]);
for(int32_t yyy=0; yyy<m_height; yyy++) { for(int32_t yyy=0; yyy<m_height; yyy++) {
for(int32_t xxx=0; xxx<m_width; xxx++) { for(int32_t xxx=0; xxx<m_width; xxx++) {
tmpColor.setR(*pointer++); tmpColor.setR(*pointer++);
@ -178,7 +178,7 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
} }
break; break;
case BITS_32_X8R8G8B8: { case BITS_32_X8R8G8B8: {
uint8_t * pointer = m_data; uint8_t * pointer = (&m_data[0]);
for(int32_t yyy=0; yyy<m_height; yyy++) { for(int32_t yyy=0; yyy<m_height; yyy++) {
for(int32_t xxx=0; xxx<m_width; xxx++) { for(int32_t xxx=0; xxx<m_width; xxx++) {
pointer++; pointer++;
@ -192,7 +192,7 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
} }
break; break;
case BITS_32_A8R8G8B8: { case BITS_32_A8R8G8B8: {
uint8_t * pointer = m_data; uint8_t * pointer = (&m_data[0]);
for(int32_t yyy=0; yyy<m_height; yyy++) { for(int32_t yyy=0; yyy<m_height; yyy++) {
for(int32_t xxx=0; xxx<m_width; xxx++) { for(int32_t xxx=0; xxx<m_width; xxx++) {
tmpColor.setR(*pointer++); tmpColor.setR(*pointer++);
@ -208,10 +208,6 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
EGAMI_ERROR(" mode = ERROR"); EGAMI_ERROR(" mode = ERROR");
break; break;
} }
if (NULL != m_data) {
delete(m_data);
m_data=NULL;
}
return true; return true;
} }
@ -260,8 +256,8 @@ bool egami::storeBMP(const std::string& _fileName, const egami::Image& _inputIma
} }
*/ */
uint8_t data[16]; uint8_t data[16];
for(int32_t yyy=0; yyy<_inputImage.getSize().y(); yyy++) { for(int32_t yyy=0; yyy<_inputImage.getSize().y(); ++yyy) {
for(int32_t xxx=0; xxx<_inputImage.getSize().x(); xxx++) { for(int32_t xxx=0; xxx<_inputImage.getSize().x(); ++xxx) {
const etk::Color<>& tmpColor = _inputImage.get(ivec2(xxx,yyy)); const etk::Color<>& tmpColor = _inputImage.get(ivec2(xxx,yyy));
uint8_t* pointer = data; uint8_t* pointer = data;
*pointer++ = tmpColor.r(); *pointer++ = tmpColor.r();

View File

@ -19,26 +19,13 @@
bool egami::loadSVG(const std::string& _fileName, egami::Image& _ouputImage, const ivec2& _size) { bool egami::loadSVG(const std::string& _fileName, egami::Image& _ouputImage, const ivec2& _size) {
esvg::Document m_element(_fileName); esvg::Document svgDocument;
if (false == m_element.isLoadOk()) { if (svgDocument.load(_fileName) == false) {
EGAMI_ERROR("Error to load SVG file " << _fileName ); EGAMI_ERROR("Error to load SVG file " << _fileName );
return false; return false;
} }
draw::Image tmpImage; ivec2 imageSize = _size;
if( _size.x()>0 std::vector<etk::Color<float,4>> svgImage = svgDocument.renderImageFloatRGBA(imageSize);
&& _size.y()>0 ) { _ouputImage.set(svgImage, imageSize);
m_element.generateAnImage(_size, tmpImage);
} else {
m_element.generateAnImage(tmpImage);
}
// generate the output image in the corect format:
_ouputImage.resize(tmpImage.getSize(), etk::color::white);
for (int32_t jjj=0; jjj<tmpImage.getSize().y(); jjj++) {
for (int32_t iii=0; iii<tmpImage.getSize().x(); iii++) {
ivec2 tmppos(iii,jjj);
draw::Color tmpColor = tmpImage.get(tmppos);
_ouputImage.set(tmppos, etk::Color<>(tmpColor.r, tmpColor.g, tmpColor.b, tmpColor.a) );
}
}
return true; return true;
} }

View File

@ -22,7 +22,7 @@ def get_maintainer():
return ["Mr DUPIN Edouard <yui.heero@gmail.com>"] return ["Mr DUPIN Edouard <yui.heero@gmail.com>"]
def get_version(): def get_version():
return [0,0,0] return [0,1,"dev"]
def create(target, module_name): def create(target, module_name):
my_module = module.Module(__file__, module_name, get_type()) my_module = module.Module(__file__, module_name, get_type())