diff --git a/egami/Image.cpp b/egami/Image.cpp index 54fa256..c822bad 100644 --- a/egami/Image.cpp +++ b/egami/Image.cpp @@ -9,52 +9,48 @@ #include egami::Image::Image(const ivec2& _size) : - m_size(_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()) { + 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::Image::Resize(const ivec2& _size, const etk::Color<>& _color) -{ +void egami::Image::resize(const ivec2& _size, const etk::Color<>& _color) { 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) { - // same size ==> nothing to do ... + if (_size == m_size) { + // same size == > nothing to do ... 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); + m_data.reSize(m_size.x()*m_size.y(), tmpBg); for (int32_t jjj=0; jjj _fill) -{ +void egami::Image::clear(etk::Color<> _fill) { for (int32_t iii=0; iii& egami::Image::Get(const ivec2& _pos) const -{ +const etk::Color<>& egami::Image::get(const ivec2& _pos) const { static const etk::Color<> errorColor(0x00000000); if( _pos.x()>0 && _pos.x()0 && _pos.y()& egami::Image::Get(const ivec2& _pos) const 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()=0 && _pos.y() #include -namespace egami -{ +namespace egami { class Image { private: ivec2 m_size; @@ -27,20 +26,20 @@ 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 : // ----------------------------------------------- public : - 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 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(); }; - void Clear(etk::Color<> _fill); - const etk::Color<>& Get(const ivec2& _pos) const; - void Set(const ivec2& _pos, const etk::Color<>& _newColor); + 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); }; }; diff --git a/egami/egami.cpp b/egami/egami.cpp index 9bebe30..aeb17a9 100644 --- a/egami/egami.cpp +++ b/egami/egami.cpp @@ -23,21 +23,21 @@ bool egami::Scalable(const etk::UString& _fileName) 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 : if (true == tmpName.EndWith(".bmp") ) { if (false == egami::LoadBMP(_fileName, _output)) { - EGAMI_ERROR("Error To load BMP file '" << _fileName << "'"); + EGAMI_ERROR("Error to load BMP file '" << _fileName << "'"); return false; } } else if (true == tmpName.EndWith(".svg") ) { 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; } } else if (true == tmpName.EndWith(".png") ) { if (false == egami::LoadPNG(_fileName, _output)) { - EGAMI_ERROR("Error To load PNG file '" << _fileName << "'"); + EGAMI_ERROR("Error to load PNG file '" << _fileName << "'"); return false; } } 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) { - etk::UString tmpName = _fileName.ToLower(); + etk::UString tmpName = _fileName.toLower(); // select the corect Loader : if (true == tmpName.EndWith(".bmp") ) { if (false == egami::StoreBMP(_fileName, _input)) { - EGAMI_ERROR("Error To load BMP file '" << _fileName << "'"); + EGAMI_ERROR("Error to load BMP file '" << _fileName << "'"); return false; } } else if (true == tmpName.EndWith(".svg") ) { diff --git a/egami/wrapperBMP.cpp b/egami/wrapperBMP.cpp index 41a005c..7438ef7 100644 --- a/egami/wrapperBMP.cpp +++ b/egami/wrapperBMP.cpp @@ -11,32 +11,29 @@ #include #include #include - -#pragma pack(push,1) -typedef struct -{ - int16_t bfType; - int32_t bfSize; - int32_t bfReserved; - int32_t bfOffBits; -} bitmapFileHeader_ts; - -typedef struct -{ - int32_t biSize; - int32_t biWidth; - int32_t biHeight; - int16_t biPlanes; - int16_t biBitCount; - int32_t biCompression; - int32_t biSizeImage; - int32_t biXPelsPerMeter; - int32_t biYPelsPerMeter; - int32_t biClrUsed; - int32_t biClrImportant; -} bitmapInfoHeader_ts; -#pragma pack(pop) - +extern "C" { + #pragma pack(push,1) + struct bitmapFileHeader { + int16_t bfType; + int32_t bfSize; + int32_t bfReserved; + int32_t bfOffBits; + }; + struct bitmapFileHeader { + int32_t biSize; + int32_t biWidth; + int32_t biHeight; + int16_t biPlanes; + int16_t biBitCount; + int32_t biCompression; + int32_t biSizeImage; + int32_t biXPelsPerMeter; + int32_t biYPelsPerMeter; + int32_t biClrUsed; + int32_t biClrImportant; + }; + #pragma pack(pop) +} typedef enum { BITS_16_R5G6B5, BITS_16_X1R5G5B5, @@ -45,57 +42,55 @@ typedef enum { BITS_32_A8R8G8B8 } modeBitmap_te; - #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; int32_t m_width = 0; int32_t m_height = 0; - bitmapFileHeader_ts m_FileHeader; - bitmapInfoHeader_ts m_InfoHeader; + struct bitmapFileHeader m_FileHeader; + struct bitmapFileHeader m_InfoHeader; etk::FSNode fileName(_inputFile); - // Get the fileSize ... - /*if (fileName.Size() < (int32_t)(sizeof(bitmapFileHeader_ts) + sizeof(bitmapInfoHeader_ts) ) ) { + // get the fileSize ... + /*if (fileName.size() < (int32_t)(sizeof(struct bitmapFileHeader) + sizeof(struct bitmapFileHeader) ) ) { EWOL_ERROR("not enought data in the file named=\"" << fileName << "\""); return; }*/ - if (false==fileName.Exist()) { + if (false == fileName.exist()) { EGAMI_ERROR("File does not existed=\"" << fileName << "\""); return false; } - if(false == fileName.FileOpenRead() ) { + if(false == fileName.fileOpenRead() ) { EGAMI_ERROR("Can not find the file name=\"" << fileName << "\""); return false; } // 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"); - fileName.FileClose(); + fileName.fileClose(); 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"); - fileName.FileClose(); + fileName.fileClose(); 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 << "\""); - fileName.FileClose(); + fileName.fileClose(); return false; } - // Check the header error : + // check the header error : if (m_FileHeader.bfType != 0x4D42) { EGAMI_ERROR("the file=\"" << fileName << "\" is not a bitmap file ..."); - fileName.FileClose(); + fileName.fileClose(); return false; } if (m_FileHeader.bfReserved != 0x00000000) { - EGAMI_ERROR("the bfReserved feald is not at 0 ==> not supported format ..."); - fileName.FileClose(); + EGAMI_ERROR("the bfReserved feald is not at 0 == > not supported format ..."); + fileName.fileClose(); return false; } if( m_InfoHeader.biBitCount == 16 @@ -119,24 +114,24 @@ bool egami::LoadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) { m_dataMode = BITS_32_A8R8G8B8; } else { - EGAMI_ERROR("the biBitCount & biCompression fealds are unknow ==> not supported format ..."); - fileName.FileClose();; + EGAMI_ERROR("the biBitCount & biCompression fealds are unknow == > not supported format ..."); + fileName.fileClose();; return false; } m_width = m_InfoHeader.biWidth; m_height = m_InfoHeader.biHeight; // reallocate the image - _ouputImage.Resize(ivec2(m_width,m_height)); + _ouputImage.resize(ivec2(m_width,m_height)); uint8_t* m_data = NULL; if(0 != 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..."); } } - fileName.FileClose(); + fileName.fileClose(); 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; for(int32_t yyy=0; yyy> 8)); - tmpColor.SetG((uint8_t)((*pointer & 0x07E0) >> 3)); - tmpColor.SetB((uint8_t)(*pointer << 3)); - tmpColor.SetA(0xFF); - _ouputImage.Set(ivec2(xxx,yyy), tmpColor); + tmpColor.setR((uint8_t)((*pointer & 0xF800) >> 8)); + tmpColor.setG((uint8_t)((*pointer & 0x07E0) >> 3)); + tmpColor.setB((uint8_t)(*pointer << 3)); + tmpColor.setA(0xFF); + _ouputImage.set(ivec2(xxx,yyy), tmpColor); pointer++; } } @@ -163,11 +158,11 @@ bool egami::LoadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) uint16_t * pointer = (uint16_t*)m_data; for(int32_t yyy=0; yyy> 7)); - tmpColor.SetG((int8_t)((*pointer & 0x03E0) >> 2)); - tmpColor.SetB((int8_t)(*pointer << 3)); - tmpColor.SetA(0xFF); - _ouputImage.Set(ivec2(xxx,yyy), tmpColor); + tmpColor.setR((int8_t)((*pointer & 0x7C00) >> 7)); + tmpColor.setG((int8_t)((*pointer & 0x03E0) >> 2)); + tmpColor.setB((int8_t)(*pointer << 3)); + tmpColor.setA(0xFF); + _ouputImage.set(ivec2(xxx,yyy), tmpColor); pointer++; } } @@ -178,11 +173,11 @@ bool egami::LoadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) uint8_t * pointer = m_data; for(int32_t yyy=0; yyy& tmpColor = _inputImage.Get(ivec2(xxx,yyy)); + for(int32_t yyy=0; yyy<_inputImage.getSize().y(); yyy++) { + for(int32_t xxx=0; xxx<_inputImage.getSize().x(); xxx++) { + const etk::Color<>& tmpColor = _inputImage.get(ivec2(xxx,yyy)); uint8_t* pointer = data; *pointer++ = tmpColor.r(); *pointer++ = tmpColor.g(); *pointer++ = tmpColor.b(); *pointer++ = tmpColor.a(); - fileName.FileWrite(data,4,1); + fileName.fileWrite(data,4,1); } } - fileName.FileClose(); + fileName.fileClose(); return true; } /* -void ewol::texture::TextureBMP::Display(void) +void ewol::texture::TextureBMP::display(void) { if (NULL == m_data) { EWOL_ERROR("Might loading error of this Bitmap ..."); diff --git a/egami/wrapperBMP.h b/egami/wrapperBMP.h index 6e0d1d0..57d6639 100644 --- a/egami/wrapperBMP.h +++ b/egami/wrapperBMP.h @@ -19,14 +19,14 @@ namespace egami * @param[out] _ouputImage Read data. * @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. * @param[in] _fileName Name of the file. * @param[in] _inputImage write data. * @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 diff --git a/egami/wrapperPNG.cpp b/egami/wrapperPNG.cpp index ed99f80..84535b0 100644 --- a/egami/wrapperPNG.cpp +++ b/egami/wrapperPNG.cpp @@ -22,7 +22,7 @@ static void local_ReadData(png_structp png_ptr, png_bytep data, png_size_t lengt { etk::FSNode* fileNode = static_cast(png_get_io_ptr(png_ptr)); 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); - if (false==fileName.Exist()) { + if (false == fileName.exist()) { EGAMI_ERROR("File does not existed=\"" << fileName << "\""); return false; } - if(false == fileName.FileOpenRead() ) { + if(false == fileName.fileOpenRead() ) { EGAMI_ERROR("Can not find the file name=\"" << fileName << "\""); return false; } @@ -64,9 +64,9 @@ bool egami::LoadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage) png_structp png_ptr; png_bytep * row_pointers; - if (fileName.FileRead(header,1,8) != 8) { + if (fileName.fileRead(header,1,8) != 8) { EGAMI_ERROR("error loading file header"); - fileName.FileClose(); + fileName.fileClose(); return false; } 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); // reallocate the image 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); 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++) { png_byte* ptr = &(row[x*4]); - tmpColor.Set(ptr[0], ptr[1],ptr[2],ptr[3]); - _ouputImage.Set(ivec2(x,y), tmpColor); + tmpColor.set(ptr[0], ptr[1],ptr[2],ptr[3]); + _ouputImage.set(ivec2(x,y), tmpColor); } delete row_pointers[y]; } @@ -141,8 +141,8 @@ bool egami::LoadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage) for (x = 0; x < width; x++) { png_byte* ptr = &(row[x*3]); - tmpColor.Set(ptr[0], ptr[1],ptr[2]); - _ouputImage.Set(ivec2(x,y), tmpColor); + tmpColor.set(ptr[0], ptr[1],ptr[2]); + _ouputImage.set(ivec2(x,y), tmpColor); } delete row_pointers[y]; } @@ -152,7 +152,7 @@ bool egami::LoadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage) return false; } - fileName.FileClose(); + fileName.fileClose(); return true; } diff --git a/egami/wrapperPNG.h b/egami/wrapperPNG.h index 67455a4..fcf75fd 100644 --- a/egami/wrapperPNG.h +++ b/egami/wrapperPNG.h @@ -19,7 +19,7 @@ namespace egami * @param[out] _ouputImage Read data. * @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 diff --git a/egami/wrapperSVG.cpp b/egami/wrapperSVG.cpp index 741f990..b9ea9ad 100644 --- a/egami/wrapperSVG.cpp +++ b/egami/wrapperSVG.cpp @@ -18,27 +18,27 @@ #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); - if (false == m_element.IsLoadOk()) { - EGAMI_ERROR("Error To load SVG file " << _fileName ); + if (false == m_element.isLoadOk()) { + EGAMI_ERROR("Error to load SVG file " << _fileName ); return false; } draw::Image tmpImage; if( _size.x()>0 && _size.y()>0 ) { - m_element.GenerateAnImage(_size, tmpImage); + m_element.generateAnImage(_size, tmpImage); } else { - m_element.GenerateAnImage(tmpImage); + 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(tmpColor.r, tmpColor.g, tmpColor.b, tmpColor.a) ); + draw::Color tmpColor = tmpImage.get(tmppos); + _ouputImage.set(tmppos, etk::Color<>(tmpColor.r, tmpColor.g, tmpColor.b, tmpColor.a) ); } } return true; diff --git a/egami/wrapperSVG.h b/egami/wrapperSVG.h index 0ba88c3..22b4c18 100644 --- a/egami/wrapperSVG.h +++ b/egami/wrapperSVG.h @@ -17,10 +17,10 @@ namespace egami * @breif Load a svg file in the image. * @param[in] _fileName Name of the file. * @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. */ - 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 \ No newline at end of file