[DEV] coding style (start)

This commit is contained in:
Edouard DUPIN 2013-10-04 21:53:31 +02:00
parent 4f2f17a043
commit 516808d6ac
9 changed files with 148 additions and 160 deletions

View File

@ -9,52 +9,48 @@
#include <egami/Image.h> #include <egami/Image.h>
egami::Image::Image(const ivec2& _size) : egami::Image::Image(const ivec2& _size) :
m_size(_size) m_size(_size) {
{
// basic element : // basic element :
etk::Color<> tmpBg(0,0,0,0); etk::Color<> tmpBg(0,0,0,0);
// preallocate data with a basic bg elements : // preallocate data with a basic bg elements :
m_data.ReSize(m_size.x()*m_size.y(), tmpBg); m_data.reSize(m_size.x()*m_size.y(), tmpBg);
if ((uint32_t)m_size.x()*m_size.y() > m_data.Size()) { if ((uint32_t)m_size.x()*m_size.y() > m_data.size()) {
TK_ERROR("Allocation of data buffer in error"); TK_ERROR("Allocation of data buffer in error");
return; return;
} }
} }
void egami::Image::Resize(const ivec2& _size, const etk::Color<>& _color) void egami::Image::resize(const ivec2& _size, const etk::Color<>& _color) {
{
m_size=_size; m_size=_size;
m_data.ReSize(m_size.x()*m_size.y(), _color); m_data.reSize(m_size.x()*m_size.y(), _color);
} }
void egami::Image::Resize(const ivec2& _size, const ivec2& _startPos) void egami::Image::resize(const ivec2& _size, const ivec2& _startPos)
{ {
if (_size==m_size) { if (_size == m_size) {
// same size ==> nothing to do ... // same size == > nothing to do ...
return; return;
} }
// grow size : // grow size :
egami::Image tmpImage(*this); egami::Image tmpImage(*this);
m_size=_size; m_size=_size;
etk::Color<> tmpBg(0,0,0,0); etk::Color<> tmpBg(0,0,0,0);
m_data.ReSize(m_size.x()*m_size.y(), tmpBg); m_data.reSize(m_size.x()*m_size.y(), tmpBg);
for (int32_t jjj=0; jjj<m_size.y(); jjj++) { for (int32_t jjj=0; jjj<m_size.y(); jjj++) {
for (int32_t iii=0; iii<m_size.y(); iii++) { for (int32_t iii=0; iii<m_size.y(); iii++) {
ivec2 tmppos(iii,jjj); ivec2 tmppos(iii,jjj);
Set(tmppos, tmpImage.Get(tmppos)); set(tmppos, tmpImage.get(tmppos));
} }
} }
} }
void egami::Image::Clear(etk::Color<> _fill) void egami::Image::clear(etk::Color<> _fill) {
{
for (int32_t iii=0; iii<m_size.x()*m_size.y(); iii++) { for (int32_t iii=0; iii<m_size.x()*m_size.y(); iii++) {
m_data[iii] = _fill; m_data[iii] = _fill;
} }
} }
const etk::Color<>& egami::Image::Get(const ivec2& _pos) const const etk::Color<>& egami::Image::get(const ivec2& _pos) const {
{
static const etk::Color<> errorColor(0x00000000); static const etk::Color<> errorColor(0x00000000);
if( _pos.x()>0 && _pos.x()<m_size.x() if( _pos.x()>0 && _pos.x()<m_size.x()
&& _pos.y()>0 && _pos.y()<m_size.y()) { && _pos.y()>0 && _pos.y()<m_size.y()) {
@ -63,8 +59,7 @@ const etk::Color<>& egami::Image::Get(const ivec2& _pos) const
return errorColor; return errorColor;
} }
void egami::Image::Set(const ivec2& _pos, const etk::Color<>& _newColor) void egami::Image::set(const ivec2& _pos, const etk::Color<>& _newColor) {
{
if( _pos.x()>=0 && _pos.x()<m_size.x() if( _pos.x()>=0 && _pos.x()<m_size.x()
&& _pos.y()>=0 && _pos.y()<m_size.y()) { && _pos.y()>=0 && _pos.y()<m_size.y()) {
m_data[_pos.x()+_pos.y()*m_size.x()] = _newColor; m_data[_pos.x()+_pos.y()*m_size.x()] = _newColor;

View File

@ -14,8 +14,7 @@
#include <etk/math/Vector2D.h> #include <etk/math/Vector2D.h>
#include <etk/Color.h> #include <etk/Color.h>
namespace egami namespace egami {
{
class Image { class Image {
private: private:
ivec2 m_size; ivec2 m_size;
@ -27,20 +26,20 @@ namespace egami
~Image(void) { }; ~Image(void) { };
// EWOL internal API for Texture system : // EWOL internal API for Texture system :
public: public:
void* GetTextureDataPointer(void) { return &m_data[0]; }; void* getTextureDataPointer(void) { return &m_data[0]; };
// ----------------------------------------------- // -----------------------------------------------
// -- basic tools : // -- basic tools :
// ----------------------------------------------- // -----------------------------------------------
public : public :
void Resize(const ivec2& _size, const ivec2& _startPos=ivec2(0,0)); void resize(const ivec2& _size, const ivec2& _startPos=ivec2(0,0));
void Resize(const ivec2& _size, const etk::Color<>& _color); void resize(const ivec2& _size, const etk::Color<>& _color);
const ivec2& GetSize(void) const { return m_size; }; const ivec2& getSize(void) const { return m_size; };
int32_t GetWidth(void) const { return m_size.x(); }; int32_t getWidth(void) const { return m_size.x(); };
int32_t GetHeight(void) const { return m_size.y(); }; int32_t getHeight(void) const { return m_size.y(); };
void Clear(etk::Color<> _fill); void clear(etk::Color<> _fill);
const etk::Color<>& Get(const ivec2& _pos) const; const etk::Color<>& get(const ivec2& _pos) const;
void Set(const ivec2& _pos, const etk::Color<>& _newColor); void set(const ivec2& _pos, const etk::Color<>& _newColor);
}; };
}; };

View File

@ -23,21 +23,21 @@ bool egami::Scalable(const etk::UString& _fileName)
bool egami::Load(egami::Image& _output, const etk::UString& _fileName, const ivec2& _size) bool egami::Load(egami::Image& _output, const etk::UString& _fileName, const ivec2& _size)
{ {
etk::UString tmpName = _fileName.ToLower(); etk::UString tmpName = _fileName.toLower();
// select the corect Loader : // select the corect Loader :
if (true == tmpName.EndWith(".bmp") ) { if (true == tmpName.EndWith(".bmp") ) {
if (false == egami::LoadBMP(_fileName, _output)) { if (false == egami::LoadBMP(_fileName, _output)) {
EGAMI_ERROR("Error To load BMP file '" << _fileName << "'"); EGAMI_ERROR("Error to load BMP file '" << _fileName << "'");
return false; return false;
} }
} else if (true == tmpName.EndWith(".svg") ) { } else if (true == tmpName.EndWith(".svg") ) {
if (false == egami::LoadSVG(_fileName, _output, _size)) { if (false == egami::LoadSVG(_fileName, _output, _size)) {
EGAMI_ERROR("Error To load SVG file '" << _fileName << "'"); EGAMI_ERROR("Error to load SVG file '" << _fileName << "'");
return false; return false;
} }
} else if (true == tmpName.EndWith(".png") ) { } else if (true == tmpName.EndWith(".png") ) {
if (false == egami::LoadPNG(_fileName, _output)) { if (false == egami::LoadPNG(_fileName, _output)) {
EGAMI_ERROR("Error To load PNG file '" << _fileName << "'"); EGAMI_ERROR("Error to load PNG file '" << _fileName << "'");
return false; return false;
} }
} else { } else {
@ -49,11 +49,11 @@ bool egami::Load(egami::Image& _output, const etk::UString& _fileName, const ive
bool egami::Store(const egami::Image& _input, const etk::UString& _fileName) bool egami::Store(const egami::Image& _input, const etk::UString& _fileName)
{ {
etk::UString tmpName = _fileName.ToLower(); etk::UString tmpName = _fileName.toLower();
// select the corect Loader : // select the corect Loader :
if (true == tmpName.EndWith(".bmp") ) { if (true == tmpName.EndWith(".bmp") ) {
if (false == egami::StoreBMP(_fileName, _input)) { if (false == egami::StoreBMP(_fileName, _input)) {
EGAMI_ERROR("Error To load BMP file '" << _fileName << "'"); EGAMI_ERROR("Error to load BMP file '" << _fileName << "'");
return false; return false;
} }
} else if (true == tmpName.EndWith(".svg") ) { } else if (true == tmpName.EndWith(".svg") ) {

View File

@ -11,32 +11,29 @@
#include <egami/Image.h> #include <egami/Image.h>
#include <egami/wrapperBMP.h> #include <egami/wrapperBMP.h>
#include <etk/os/FSNode.h> #include <etk/os/FSNode.h>
extern "C" {
#pragma pack(push,1) #pragma pack(push,1)
typedef struct struct bitmapFileHeader {
{ int16_t bfType;
int16_t bfType; int32_t bfSize;
int32_t bfSize; int32_t bfReserved;
int32_t bfReserved; int32_t bfOffBits;
int32_t bfOffBits; };
} bitmapFileHeader_ts; struct bitmapFileHeader {
int32_t biSize;
typedef struct int32_t biWidth;
{ int32_t biHeight;
int32_t biSize; int16_t biPlanes;
int32_t biWidth; int16_t biBitCount;
int32_t biHeight; int32_t biCompression;
int16_t biPlanes; int32_t biSizeImage;
int16_t biBitCount; int32_t biXPelsPerMeter;
int32_t biCompression; int32_t biYPelsPerMeter;
int32_t biSizeImage; int32_t biClrUsed;
int32_t biXPelsPerMeter; int32_t biClrImportant;
int32_t biYPelsPerMeter; };
int32_t biClrUsed; #pragma pack(pop)
int32_t biClrImportant; }
} bitmapInfoHeader_ts;
#pragma pack(pop)
typedef enum { typedef enum {
BITS_16_R5G6B5, BITS_16_R5G6B5,
BITS_16_X1R5G5B5, BITS_16_X1R5G5B5,
@ -45,57 +42,55 @@ typedef enum {
BITS_32_A8R8G8B8 BITS_32_A8R8G8B8
} modeBitmap_te; } modeBitmap_te;
#undef __class__ #undef __class__
#define __class__ "wrapperBMP" #define __class__ "wrapperBMP"
bool egami::LoadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) bool egami::loadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) {
{
modeBitmap_te m_dataMode = BITS_16_R5G6B5; modeBitmap_te m_dataMode = BITS_16_R5G6B5;
int32_t m_width = 0; int32_t m_width = 0;
int32_t m_height = 0; int32_t m_height = 0;
bitmapFileHeader_ts m_FileHeader; struct bitmapFileHeader m_FileHeader;
bitmapInfoHeader_ts m_InfoHeader; struct bitmapFileHeader m_InfoHeader;
etk::FSNode fileName(_inputFile); etk::FSNode fileName(_inputFile);
// Get the fileSize ... // get the fileSize ...
/*if (fileName.Size() < (int32_t)(sizeof(bitmapFileHeader_ts) + sizeof(bitmapInfoHeader_ts) ) ) { /*if (fileName.size() < (int32_t)(sizeof(struct bitmapFileHeader) + sizeof(struct bitmapFileHeader) ) ) {
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 (false == fileName.exist()) {
EGAMI_ERROR("File does not existed=\"" << fileName << "\""); EGAMI_ERROR("File does not existed=\"" << fileName << "\"");
return false; return false;
} }
if(false == fileName.FileOpenRead() ) { if(false == fileName.fileOpenRead() ) {
EGAMI_ERROR("Can not find the file name=\"" << fileName << "\""); EGAMI_ERROR("Can not find the file name=\"" << fileName << "\"");
return false; return false;
} }
// get the data : // get the data :
if (fileName.FileRead(&m_FileHeader,sizeof(bitmapFileHeader_ts),1) != 1) { if (fileName.fileRead(&m_FileHeader,sizeof(struct bitmapFileHeader),1) != 1) {
EGAMI_ERROR("error loading file header"); EGAMI_ERROR("error loading file header");
fileName.FileClose(); fileName.fileClose();
return false; return false;
} }
if (fileName.FileRead(&m_InfoHeader,sizeof(bitmapInfoHeader_ts),1) != 1) { if (fileName.fileRead(&m_InfoHeader,sizeof(struct bitmapFileHeader),1) != 1) {
EGAMI_ERROR("error loading file header"); EGAMI_ERROR("error loading file header");
fileName.FileClose(); fileName.fileClose();
return false; return false;
} }
if(false == fileName.FileSeek(m_FileHeader.bfOffBits, etk::FSN_SEEK_START)) { if(false == fileName.fileSeek(m_FileHeader.bfOffBits, etk::FSN_SEEK_START)) {
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;
} }
// Check the header error : // check the header error :
if (m_FileHeader.bfType != 0x4D42) { if (m_FileHeader.bfType != 0x4D42) {
EGAMI_ERROR("the file=\"" << fileName << "\" is not a bitmap file ..."); EGAMI_ERROR("the file=\"" << fileName << "\" is not a bitmap file ...");
fileName.FileClose(); fileName.fileClose();
return false; return false;
} }
if (m_FileHeader.bfReserved != 0x00000000) { if (m_FileHeader.bfReserved != 0x00000000) {
EGAMI_ERROR("the bfReserved feald is not at 0 ==> not supported format ..."); EGAMI_ERROR("the bfReserved feald is not at 0 == > not supported format ...");
fileName.FileClose(); fileName.fileClose();
return false; return false;
} }
if( m_InfoHeader.biBitCount == 16 if( m_InfoHeader.biBitCount == 16
@ -119,24 +114,24 @@ bool egami::LoadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage)
{ {
m_dataMode = BITS_32_A8R8G8B8; m_dataMode = BITS_32_A8R8G8B8;
} else { } else {
EGAMI_ERROR("the biBitCount & biCompression fealds are unknow ==> not supported format ..."); EGAMI_ERROR("the biBitCount & biCompression fealds are unknow == > not supported format ...");
fileName.FileClose();; fileName.fileClose();;
return false; return false;
} }
m_width = m_InfoHeader.biWidth; m_width = m_InfoHeader.biWidth;
m_height = m_InfoHeader.biHeight; m_height = m_InfoHeader.biHeight;
// 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; uint8_t* m_data = NULL;
if(0 != m_InfoHeader.biSizeImage) if(0 != m_InfoHeader.biSizeImage)
{ {
m_data=new uint8_t[m_InfoHeader.biSizeImage]; m_data=new uint8_t[m_InfoHeader.biSizeImage];
if (fileName.FileRead(m_data,m_InfoHeader.biSizeImage,1) != 1){ if (fileName.fileRead(m_data,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...");
} }
} }
fileName.FileClose(); fileName.fileClose();
etk::Color<> tmpColor(0,0,0,0); etk::Color<> tmpColor(0,0,0,0);
@ -148,11 +143,11 @@ bool egami::LoadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage)
uint16_t * pointer = (uint16_t*)m_data; uint16_t * pointer = (uint16_t*)m_data;
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));
tmpColor.SetG((uint8_t)((*pointer & 0x07E0) >> 3)); tmpColor.setG((uint8_t)((*pointer & 0x07E0) >> 3));
tmpColor.SetB((uint8_t)(*pointer << 3)); tmpColor.setB((uint8_t)(*pointer << 3));
tmpColor.SetA(0xFF); tmpColor.setA(0xFF);
_ouputImage.Set(ivec2(xxx,yyy), tmpColor); _ouputImage.set(ivec2(xxx,yyy), tmpColor);
pointer++; pointer++;
} }
} }
@ -163,11 +158,11 @@ bool egami::LoadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage)
uint16_t * pointer = (uint16_t*)m_data; uint16_t * pointer = (uint16_t*)m_data;
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));
tmpColor.SetG((int8_t)((*pointer & 0x03E0) >> 2)); tmpColor.setG((int8_t)((*pointer & 0x03E0) >> 2));
tmpColor.SetB((int8_t)(*pointer << 3)); tmpColor.setB((int8_t)(*pointer << 3));
tmpColor.SetA(0xFF); tmpColor.setA(0xFF);
_ouputImage.Set(ivec2(xxx,yyy), tmpColor); _ouputImage.set(ivec2(xxx,yyy), tmpColor);
pointer++; pointer++;
} }
} }
@ -178,11 +173,11 @@ bool egami::LoadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage)
uint8_t * pointer = m_data; uint8_t * pointer = m_data;
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++);
tmpColor.SetG(*pointer++); tmpColor.setG(*pointer++);
tmpColor.SetB(*pointer++); tmpColor.setB(*pointer++);
tmpColor.SetA(0xFF); tmpColor.setA(0xFF);
_ouputImage.Set(ivec2(xxx,yyy), tmpColor); _ouputImage.set(ivec2(xxx,yyy), tmpColor);
} }
} }
} }
@ -193,11 +188,11 @@ bool egami::LoadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage)
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++;
tmpColor.SetR(*pointer++); tmpColor.setR(*pointer++);
tmpColor.SetG(*pointer++); tmpColor.setG(*pointer++);
tmpColor.SetB(*pointer++); tmpColor.setB(*pointer++);
tmpColor.SetA(0xFF); tmpColor.setA(0xFF);
_ouputImage.Set(ivec2(xxx,yyy), tmpColor); _ouputImage.set(ivec2(xxx,yyy), tmpColor);
} }
} }
} }
@ -207,11 +202,11 @@ bool egami::LoadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage)
uint8_t * pointer = m_data; uint8_t * pointer = m_data;
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++);
tmpColor.SetG(*pointer++); tmpColor.setG(*pointer++);
tmpColor.SetB(*pointer++); tmpColor.setB(*pointer++);
tmpColor.SetA(*pointer++); tmpColor.setA(*pointer++);
_ouputImage.Set(ivec2(xxx,yyy), tmpColor); _ouputImage.set(ivec2(xxx,yyy), tmpColor);
} }
} }
} }
@ -227,67 +222,66 @@ bool egami::LoadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage)
return true; return true;
} }
bool egami::StoreBMP(const etk::UString& _fileName, const egami::Image& _inputImage) bool egami::storeBMP(const etk::UString& _fileName, const egami::Image& _inputImage) {
{ struct bitmapFileHeader m_FileHeader;
bitmapFileHeader_ts m_FileHeader; struct bitmapFileHeader m_InfoHeader;
bitmapInfoHeader_ts m_InfoHeader;
m_FileHeader.bfType = 0x4D42; m_FileHeader.bfType = 0x4D42;
m_FileHeader.bfSize = sizeof(bitmapFileHeader_ts); m_FileHeader.bfSize = sizeof(struct bitmapFileHeader);
m_FileHeader.bfReserved = 0; m_FileHeader.bfReserved = 0;
m_FileHeader.bfOffBits = 40; m_FileHeader.bfOffBits = 40;
m_InfoHeader.biSize = sizeof(bitmapInfoHeader_ts); m_InfoHeader.biSize = sizeof(struct bitmapFileHeader);
m_InfoHeader.biWidth = _inputImage.GetSize().x(); m_InfoHeader.biWidth = _inputImage.getSize().x();
m_InfoHeader.biHeight = _inputImage.GetSize().y(); m_InfoHeader.biHeight = _inputImage.getSize().y();
m_InfoHeader.biPlanes = 1; m_InfoHeader.biPlanes = 1;
m_InfoHeader.biBitCount = 32; m_InfoHeader.biBitCount = 32;
m_InfoHeader.biCompression = 0; m_InfoHeader.biCompression = 0;
m_InfoHeader.biSizeImage = _inputImage.GetSize().x()*_inputImage.GetSize().y()*4; m_InfoHeader.biSizeImage = _inputImage.getSize().x()*_inputImage.getSize().y()*4;
m_InfoHeader.biXPelsPerMeter = 75; m_InfoHeader.biXPelsPerMeter = 75;
m_InfoHeader.biYPelsPerMeter = 75; m_InfoHeader.biYPelsPerMeter = 75;
m_InfoHeader.biClrUsed = 0; m_InfoHeader.biClrUsed = 0;
m_InfoHeader.biClrImportant = 0; m_InfoHeader.biClrImportant = 0;
etk::FSNode fileName(_fileName); etk::FSNode fileName(_fileName);
if(false == fileName.FileOpenWrite() ) { if(false == fileName.fileOpenWrite() ) {
EGAMI_ERROR("Can not find the file name=\"" << fileName << "\""); EGAMI_ERROR("Can not find the file name=\"" << fileName << "\"");
return false; return false;
} }
// get the data : // get the data :
if (fileName.FileWrite(&m_FileHeader,sizeof(bitmapFileHeader_ts),1) != 1) { if (fileName.fileWrite(&m_FileHeader,sizeof(struct bitmapFileHeader),1) != 1) {
EGAMI_ERROR("error loading file header"); EGAMI_ERROR("error loading file header");
fileName.FileClose(); fileName.fileClose();
return false; return false;
} }
if (fileName.FileWrite(&m_InfoHeader,sizeof(bitmapInfoHeader_ts),1) != 1) { if (fileName.fileWrite(&m_InfoHeader,sizeof(struct bitmapFileHeader),1) != 1) {
EGAMI_ERROR("error loading file header"); EGAMI_ERROR("error loading file header");
fileName.FileClose(); fileName.fileClose();
return false; return false;
} }
if(false == fileName.FileSeek(m_FileHeader.bfOffBits, etk::FSN_SEEK_START)) { if(false == fileName.fileSeek(m_FileHeader.bfOffBits, etk::FSN_SEEK_START)) {
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;
} }
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();
*pointer++ = tmpColor.g(); *pointer++ = tmpColor.g();
*pointer++ = tmpColor.b(); *pointer++ = tmpColor.b();
*pointer++ = tmpColor.a(); *pointer++ = tmpColor.a();
fileName.FileWrite(data,4,1); fileName.fileWrite(data,4,1);
} }
} }
fileName.FileClose(); fileName.fileClose();
return true; return true;
} }
/* /*
void ewol::texture::TextureBMP::Display(void) void ewol::texture::TextureBMP::display(void)
{ {
if (NULL == m_data) { if (NULL == m_data) {
EWOL_ERROR("Might loading error of this Bitmap ..."); EWOL_ERROR("Might loading error of this Bitmap ...");

View File

@ -19,14 +19,14 @@ namespace egami
* @param[out] _ouputImage Read data. * @param[out] _ouputImage Read data.
* @return true if all is done correctly, false otherwise. * @return true if all is done correctly, false otherwise.
*/ */
bool LoadBMP(const etk::UString& _fileName, egami::Image& _ouputImage); bool loadBMP(const etk::UString& _fileName, egami::Image& _ouputImage);
/** /**
* @breif Store a bmp file in the image. * @breif Store a bmp file in the image.
* @param[in] _fileName Name of the file. * @param[in] _fileName Name of the file.
* @param[in] _inputImage write data. * @param[in] _inputImage write data.
* @return true if all is done correctly, false otherwise. * @return true if all is done correctly, false otherwise.
*/ */
bool StoreBMP(const etk::UString& _fileName, const egami::Image& _inputImage); bool storeBMP(const etk::UString& _fileName, const egami::Image& _inputImage);
}; };
#endif #endif

View File

@ -22,7 +22,7 @@ static void local_ReadData(png_structp png_ptr, png_bytep data, png_size_t lengt
{ {
etk::FSNode* fileNode = static_cast<etk::FSNode*>(png_get_io_ptr(png_ptr)); etk::FSNode* fileNode = static_cast<etk::FSNode*>(png_get_io_ptr(png_ptr));
if (NULL!=fileNode) { if (NULL!=fileNode) {
fileNode->FileRead(data, 1, length); fileNode->fileRead(data, 1, length);
} }
} }
/* /*
@ -43,15 +43,15 @@ static void localFlushData(png_structp png_ptr)
} }
*/ */
bool egami::LoadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage) bool egami::loadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage)
{ {
etk::FSNode fileName(_inputFile); etk::FSNode fileName(_inputFile);
if (false==fileName.Exist()) { if (false == fileName.exist()) {
EGAMI_ERROR("File does not existed=\"" << fileName << "\""); EGAMI_ERROR("File does not existed=\"" << fileName << "\"");
return false; return false;
} }
if(false == fileName.FileOpenRead() ) { if(false == fileName.fileOpenRead() ) {
EGAMI_ERROR("Can not find the file name=\"" << fileName << "\""); EGAMI_ERROR("Can not find the file name=\"" << fileName << "\"");
return false; return false;
} }
@ -64,9 +64,9 @@ bool egami::LoadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage)
png_structp png_ptr; png_structp png_ptr;
png_bytep * row_pointers; png_bytep * row_pointers;
if (fileName.FileRead(header,1,8) != 8) { if (fileName.fileRead(header,1,8) != 8) {
EGAMI_ERROR("error loading file header"); EGAMI_ERROR("error loading file header");
fileName.FileClose(); fileName.fileClose();
return false; return false;
} }
if (png_sig_cmp(header, 0, 8)) if (png_sig_cmp(header, 0, 8))
@ -99,7 +99,7 @@ bool egami::LoadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage)
int32_t height = png_get_image_height(png_ptr, info_ptr); int32_t height = png_get_image_height(png_ptr, info_ptr);
// reallocate the image // reallocate the image
EGAMI_DEBUG("Load PNG image : (" << width << "," << height << ")" ); EGAMI_DEBUG("Load PNG image : (" << width << "," << height << ")" );
_ouputImage.Resize(ivec2(width,height)); _ouputImage.resize(ivec2(width,height));
int32_t bit_depth = png_get_bit_depth(png_ptr, info_ptr); int32_t bit_depth = png_get_bit_depth(png_ptr, info_ptr);
png_read_update_info(png_ptr, info_ptr); png_read_update_info(png_ptr, info_ptr);
@ -127,8 +127,8 @@ bool egami::LoadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage)
for (x = 0; x < width; x++) for (x = 0; x < width; x++)
{ {
png_byte* ptr = &(row[x*4]); png_byte* ptr = &(row[x*4]);
tmpColor.Set(ptr[0], ptr[1],ptr[2],ptr[3]); tmpColor.set(ptr[0], ptr[1],ptr[2],ptr[3]);
_ouputImage.Set(ivec2(x,y), tmpColor); _ouputImage.set(ivec2(x,y), tmpColor);
} }
delete row_pointers[y]; delete row_pointers[y];
} }
@ -141,8 +141,8 @@ bool egami::LoadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage)
for (x = 0; x < width; x++) for (x = 0; x < width; x++)
{ {
png_byte* ptr = &(row[x*3]); png_byte* ptr = &(row[x*3]);
tmpColor.Set(ptr[0], ptr[1],ptr[2]); tmpColor.set(ptr[0], ptr[1],ptr[2]);
_ouputImage.Set(ivec2(x,y), tmpColor); _ouputImage.set(ivec2(x,y), tmpColor);
} }
delete row_pointers[y]; delete row_pointers[y];
} }
@ -152,7 +152,7 @@ bool egami::LoadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage)
return false; return false;
} }
fileName.FileClose(); fileName.fileClose();
return true; return true;
} }

View File

@ -19,7 +19,7 @@ namespace egami
* @param[out] _ouputImage Read data. * @param[out] _ouputImage Read data.
* @return true if all is done correctly, false otherwise. * @return true if all is done correctly, false otherwise.
*/ */
bool LoadPNG(const etk::UString& _fileName, egami::Image& _ouputImage); bool loadPNG(const etk::UString& _fileName, egami::Image& _ouputImage);
}; };
#endif #endif

View File

@ -18,27 +18,27 @@
#define __class__ "wrapperSVG" #define __class__ "wrapperSVG"
bool egami::LoadSVG(const etk::UString& _fileName, egami::Image& _ouputImage, const ivec2& _size) bool egami::loadSVG(const etk::UString& _fileName, egami::Image& _ouputImage, const ivec2& _size)
{ {
esvg::Document m_element(_fileName); esvg::Document m_element(_fileName);
if (false == m_element.IsLoadOk()) { if (false == m_element.isLoadOk()) {
EGAMI_ERROR("Error To load SVG file " << _fileName ); EGAMI_ERROR("Error to load SVG file " << _fileName );
return false; return false;
} }
draw::Image tmpImage; draw::Image tmpImage;
if( _size.x()>0 if( _size.x()>0
&& _size.y()>0 ) { && _size.y()>0 ) {
m_element.GenerateAnImage(_size, tmpImage); m_element.generateAnImage(_size, tmpImage);
} else { } else {
m_element.GenerateAnImage(tmpImage); m_element.generateAnImage(tmpImage);
} }
// generate the output image in the corect format: // generate the output image in the corect format:
_ouputImage.Resize(tmpImage.GetSize(), etk::color::white); _ouputImage.resize(tmpImage.getSize(), etk::color::white);
for (int32_t jjj=0; jjj<tmpImage.GetSize().y(); jjj++) { for (int32_t jjj=0; jjj<tmpImage.getSize().y(); jjj++) {
for (int32_t iii=0; iii<tmpImage.GetSize().y(); iii++) { for (int32_t iii=0; iii<tmpImage.getSize().y(); iii++) {
ivec2 tmppos(iii,jjj); ivec2 tmppos(iii,jjj);
draw::Color tmpColor = tmpImage.Get(tmppos); draw::Color tmpColor = tmpImage.get(tmppos);
_ouputImage.Set(tmppos, etk::Color<>(tmpColor.r, tmpColor.g, tmpColor.b, tmpColor.a) ); _ouputImage.set(tmppos, etk::Color<>(tmpColor.r, tmpColor.g, tmpColor.b, tmpColor.a) );
} }
} }
return true; return true;

View File

@ -17,10 +17,10 @@ namespace egami
* @breif Load a svg file in the image. * @breif Load a svg file in the image.
* @param[in] _fileName Name of the file. * @param[in] _fileName Name of the file.
* @param[out] _ouputImage Read data. * @param[out] _ouputImage Read data.
* @param[in] _size Size of the output image. * @param[in] _size size of the output image.
* @return true if all is done correctly, false otherwise. * @return true if all is done correctly, false otherwise.
*/ */
bool LoadSVG(const etk::UString& _fileName, egami::Image& _ouputImage, const ivec2& _size=ivec2(-1,-1)); bool loadSVG(const etk::UString& _fileName, egami::Image& _ouputImage, const ivec2& _size=ivec2(-1,-1));
}; };
#endif #endif