[DEV] first dev of egami: -Etk Giant Abstract Maker Image- or the reverse of image
This commit is contained in:
commit
4c40195075
72
egami/Image.cpp
Normal file
72
egami/Image.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#include <egami/Image.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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::Resize(const ivec2& _size, const ivec2& _startPos)
|
||||
{
|
||||
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);
|
||||
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::Image::Clear(etk::Color<> _fill)
|
||||
{
|
||||
for (int32_t iii=0; iii<m_size.x()*m_size.y(); iii++) {
|
||||
m_data[iii] = _fill;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
49
egami/Image.h
Normal file
49
egami/Image.h
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __EGAMI_IMAGE_H__
|
||||
#define __EGAMI_IMAGE_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <etk/Vector.h>
|
||||
#include <etk/math/Vector2D.h>
|
||||
#include <etk/Color.h>
|
||||
|
||||
namespace egami
|
||||
{
|
||||
class Image {
|
||||
private:
|
||||
ivec2 m_size;
|
||||
etk::Vector<etk::Color<> > m_data;
|
||||
public:
|
||||
// constructor :
|
||||
Image(const ivec2& _size=ivec2(32,32));
|
||||
// destructor
|
||||
~Image(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 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);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
11
egami/debug.cpp
Normal file
11
egami/debug.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#include <egami/debug.h>
|
||||
|
||||
const char * egamiLibName = "egami ";
|
28
egami/debug.h
Normal file
28
egami/debug.h
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __EGAMI_DEBUG_H__
|
||||
#define __EGAMI_DEBUG_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <etk/Debug.h>
|
||||
|
||||
extern const char * egamiLibName;
|
||||
|
||||
#define EGAMI_CRITICAL(data) ETK_CRITICAL(egamiLibName, data)
|
||||
#define EGAMI_WARNING(data) ETK_WARNING(egamiLibName, data)
|
||||
#define EGAMI_ERROR(data) ETK_ERROR(egamiLibName, data)
|
||||
#define EGAMI_INFO(data) ETK_INFO(egamiLibName, data)
|
||||
#define EGAMI_DEBUG(data) ETK_DEBUG(egamiLibName, data)
|
||||
#define EGAMI_VERBOSE(data) ETK_VERBOSE(egamiLibName, data)
|
||||
#define EGAMI_ASSERT(cond,data) ETK_ASSERT(egamiLibName, cond, data)
|
||||
#define EGAMI_CHECK_INOUT(cond) ETK_CHECK_INOUT(egamiLibName, cond)
|
||||
#define EGAMI_TODO(cond) ETK_TODO(egamiLibName, cond)
|
||||
|
||||
#endif
|
||||
|
48
egami/egami.cpp
Normal file
48
egami/egami.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#include <egami/egami.h>
|
||||
#include <egami/debug.h>
|
||||
|
||||
#include <egami/wrapperSVG.h>
|
||||
#include <egami/wrapperPNG.h>
|
||||
#include <egami/wrapperBMP.h>
|
||||
|
||||
bool egami::Scalable(const etk::UString& _fileName)
|
||||
{
|
||||
if (true == _fileName.EndWith(".svg") ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool egami::Load(egami::Image& _output, const etk::UString& _fileName, const ivec2& _size)
|
||||
{
|
||||
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 " << tmpName );
|
||||
return false;
|
||||
}
|
||||
} else if (true == tmpName.EndWith(".svg") ) {
|
||||
if (false == egami::LoadSVG(_fileName, _output, _size)) {
|
||||
EGAMI_ERROR("Error To load BMP file " << tmpName );
|
||||
return false;
|
||||
}
|
||||
} else if (true == tmpName.EndWith(".png") ) {
|
||||
if (false == egami::LoadPNG(_fileName, _output)) {
|
||||
EGAMI_ERROR("Error To load BMP file " << tmpName );
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
EGAMI_ERROR("Extention not managed " << tmpName << " Sopported extention : .bmp / .svg / .png");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
25
egami/egami.h
Normal file
25
egami/egami.h
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __EGAMI_H__
|
||||
#define __EGAMI_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <etk/Vector.h>
|
||||
#include <etk/math/Vector2D.h>
|
||||
#include <etk/Color.h>
|
||||
#include <egami/Image.h>
|
||||
|
||||
namespace egami
|
||||
{
|
||||
bool Load(egami::Image& _output, const etk::UString& _fileName, const ivec2& _size=ivec2(-1,-1) );
|
||||
bool Scalable(const etk::UString& _fileName);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
280
egami/wrapperBMP.cpp
Normal file
280
egami/wrapperBMP.cpp
Normal file
@ -0,0 +1,280 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <egami/debug.h>
|
||||
#include <egami/Image.h>
|
||||
#include <egami/wrapperBMP.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
|
||||
#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)
|
||||
|
||||
typedef enum {
|
||||
BITS_16_R5G6B5,
|
||||
BITS_16_X1R5G5B5,
|
||||
BITS_24_R8G8B8,
|
||||
BITS_32_X8R8G8B8,
|
||||
BITS_32_A8R8G8B8
|
||||
} modeBitmap_te;
|
||||
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "wrapperBMP"
|
||||
|
||||
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;
|
||||
|
||||
etk::FSNode fileName(_inputFile);
|
||||
// Get the fileSize ...
|
||||
/*if (fileName.Size() < (int32_t)(sizeof(bitmapFileHeader_ts) + sizeof(bitmapInfoHeader_ts) ) ) {
|
||||
EWOL_ERROR("not enought data in the file named=\"" << fileName << "\"");
|
||||
return;
|
||||
}*/
|
||||
if (false==fileName.Exist()) {
|
||||
EGAMI_ERROR("File does not existed=\"" << fileName << "\"");
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
EGAMI_ERROR("error loading file header");
|
||||
fileName.FileClose();
|
||||
return false;
|
||||
}
|
||||
if (fileName.FileRead(&m_InfoHeader,sizeof(bitmapInfoHeader_ts),1) != 1) {
|
||||
EGAMI_ERROR("error loading file header");
|
||||
fileName.FileClose();
|
||||
return false;
|
||||
}
|
||||
if(false == fileName.FileSeek(m_FileHeader.bfOffBits, etk::FSN_SEEK_START)) {
|
||||
EGAMI_ERROR("error with the 'bfOffBits' in the file named=\"" << fileName << "\"");
|
||||
fileName.FileClose();
|
||||
return false;
|
||||
}
|
||||
// Check the header error :
|
||||
if (m_FileHeader.bfType != 0x4D42) {
|
||||
EGAMI_ERROR("the file=\"" << fileName << "\" is not a bitmap file ...");
|
||||
fileName.FileClose();
|
||||
return false;
|
||||
}
|
||||
if (m_FileHeader.bfReserved != 0x00000000) {
|
||||
EGAMI_ERROR("the bfReserved feald is not at 0 ==> not supported format ...");
|
||||
fileName.FileClose();
|
||||
return false;
|
||||
}
|
||||
if( m_InfoHeader.biBitCount == 16
|
||||
&& m_InfoHeader.biCompression == 0)
|
||||
{
|
||||
m_dataMode = BITS_16_X1R5G5B5;
|
||||
} else if( m_InfoHeader.biBitCount == 16
|
||||
&& m_InfoHeader.biCompression == 3)
|
||||
{
|
||||
m_dataMode = BITS_16_R5G6B5;
|
||||
} else if( m_InfoHeader.biBitCount == 24
|
||||
&& m_InfoHeader.biCompression == 0)
|
||||
{
|
||||
m_dataMode = BITS_24_R8G8B8;
|
||||
} else if( m_InfoHeader.biBitCount == 32
|
||||
&& m_InfoHeader.biCompression == 3)
|
||||
{
|
||||
m_dataMode = BITS_32_X8R8G8B8;
|
||||
} else if( m_InfoHeader.biBitCount == 32
|
||||
&& m_InfoHeader.biCompression == 0)
|
||||
{
|
||||
m_dataMode = BITS_32_A8R8G8B8;
|
||||
} else {
|
||||
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));
|
||||
|
||||
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){
|
||||
EGAMI_CRITICAL("Can not read the file with the good size...");
|
||||
}
|
||||
}
|
||||
fileName.FileClose();
|
||||
|
||||
etk::Color<> tmpColor(0,0,0,0);
|
||||
|
||||
// need now to generate RGBA data ...
|
||||
switch(m_dataMode)
|
||||
{
|
||||
case BITS_16_R5G6B5:
|
||||
{
|
||||
uint16_t * pointer = (uint16_t*)m_data;
|
||||
for(int32_t yyy=0; yyy<m_height; yyy++) {
|
||||
for(int32_t xxx=0; xxx<m_width; xxx++) {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BITS_16_X1R5G5B5:
|
||||
{
|
||||
uint16_t * pointer = (uint16_t*)m_data;
|
||||
for(int32_t yyy=0; yyy<m_height; yyy++) {
|
||||
for(int32_t xxx=0; xxx<m_width; xxx++) {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BITS_24_R8G8B8:
|
||||
{
|
||||
uint8_t * pointer = m_data;
|
||||
for(int32_t yyy=0; yyy<m_height; yyy++) {
|
||||
for(int32_t xxx=0; xxx<m_width; xxx++) {
|
||||
tmpColor.SetR(*pointer++);
|
||||
tmpColor.SetG(*pointer++);
|
||||
tmpColor.SetB(*pointer++);
|
||||
tmpColor.SetA(0xFF);
|
||||
_ouputImage.Set(ivec2(xxx,yyy), tmpColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BITS_32_X8R8G8B8:
|
||||
{
|
||||
uint8_t * pointer = m_data;
|
||||
for(int32_t yyy=0; yyy<m_height; yyy++) {
|
||||
for(int32_t xxx=0; xxx<m_width; xxx++) {
|
||||
pointer++;
|
||||
tmpColor.SetR(*pointer++);
|
||||
tmpColor.SetG(*pointer++);
|
||||
tmpColor.SetB(*pointer++);
|
||||
tmpColor.SetA(0xFF);
|
||||
_ouputImage.Set(ivec2(xxx,yyy), tmpColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case BITS_32_A8R8G8B8:
|
||||
{
|
||||
uint8_t * pointer = m_data;
|
||||
for(int32_t yyy=0; yyy<m_height; yyy++) {
|
||||
for(int32_t xxx=0; xxx<m_width; xxx++) {
|
||||
tmpColor.SetR(*pointer++);
|
||||
tmpColor.SetG(*pointer++);
|
||||
tmpColor.SetB(*pointer++);
|
||||
tmpColor.SetA(*pointer++);
|
||||
_ouputImage.Set(ivec2(xxx,yyy), tmpColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
EGAMI_ERROR(" mode = ERROR");
|
||||
break;
|
||||
}
|
||||
if (NULL != m_data) {
|
||||
delete(m_data);
|
||||
m_data=NULL;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
void ewol::texture::TextureBMP::Display(void)
|
||||
{
|
||||
if (NULL == m_data) {
|
||||
EWOL_ERROR("Might loading error of this Bitmap ...");
|
||||
return;
|
||||
}
|
||||
EWOL_DEBUG(" -----------------------------------------------------------");
|
||||
if (false) {
|
||||
EWOL_DEBUG("Display caracteristic of the bitmap : ");
|
||||
EWOL_DEBUG(" Header of file :");
|
||||
EWOL_DEBUG(" bfType =" << m_FileHeader.bfType << " 19778 : must always be set to 'BM' to declare that this is a .bmp-file.");
|
||||
EWOL_DEBUG(" bfSize =" << m_FileHeader.bfSize << " specifies the size of the file in bytes.");
|
||||
EWOL_DEBUG(" bfReserved=" << m_FileHeader.bfReserved << " must always be set to zero.");
|
||||
EWOL_DEBUG(" bfOffBits =" << m_FileHeader.bfOffBits << " 1078 : specifies the offset from the beginning of the file to the bitmap data.");
|
||||
EWOL_DEBUG(" info header of file :");
|
||||
EWOL_DEBUG(" biSize =" << m_InfoHeader.biSize << " specifies the size of the BITMAPINFOHEADER structure, in bytes.");
|
||||
EWOL_DEBUG(" biWidth =" << m_InfoHeader.biWidth << " specifies the width of the image, in pixels.");
|
||||
EWOL_DEBUG(" biHeight =" << m_InfoHeader.biHeight << " specifies the height of the image, in pixels.");
|
||||
EWOL_DEBUG(" biPlanes =" << m_InfoHeader.biPlanes << " specifies the number of planes of the target device, must be set to zero.");
|
||||
EWOL_DEBUG(" biBitCount =" << m_InfoHeader.biBitCount << " specifies the number of bits per pixel.");
|
||||
EWOL_DEBUG(" biCompression =" << m_InfoHeader.biCompression << " Specifies the type of compression, usually set to zero (no compression).");
|
||||
EWOL_DEBUG(" biSizeImage =" << m_InfoHeader.biSizeImage << " specifies the size of the image data, in bytes. If there is no compression, it is valid to set this member to zero.");
|
||||
EWOL_DEBUG(" biXPelsPerMeter=" << m_InfoHeader.biXPelsPerMeter << " specifies the the horizontal pixels per meter on the designated targer device, usually set to zero.");
|
||||
EWOL_DEBUG(" biYPelsPerMeter=" << m_InfoHeader.biYPelsPerMeter << " specifies the the vertical pixels per meter on the designated targer device, usually set to zero.");
|
||||
EWOL_DEBUG(" biClrUsed =" << m_InfoHeader.biClrUsed << " speglTexImage2Dcifies the number of colors used in the bitmap, if set to zero the number of colors is calculated using the biBitCount member.");
|
||||
EWOL_DEBUG(" biClrImportant =" << m_InfoHeader.biClrImportant << " specifies the number of color that are 'important' for the bitmap, if set to zero, all colors are important.");
|
||||
}
|
||||
EWOL_DEBUG("Bitmap : " << m_width << "x" << m_height);
|
||||
switch(m_dataMode)
|
||||
{
|
||||
case BITS_16_R5G6B5:
|
||||
EWOL_DEBUG(" mode = 16 bits R5G6B5");
|
||||
break;
|
||||
case BITS_16_X1R5G5B5:
|
||||
EWOL_DEBUG(" mode = 16 bits X1R5G5B5");
|
||||
break;
|
||||
case BITS_24_R8G8B8:
|
||||
EWOL_DEBUG(" mode = 24 bits R8G8B8");
|
||||
break;
|
||||
case BITS_32_X8R8G8B8:
|
||||
EWOL_DEBUG(" mode = 32 bits X8R8G8B8");
|
||||
break;
|
||||
case BITS_32_A8R8G8B8:
|
||||
EWOL_DEBUG(" mode = 32 bits A8R8G8B8");
|
||||
break;
|
||||
default:
|
||||
EWOL_DEBUG(" mode = ERROR");
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
20
egami/wrapperBMP.h
Normal file
20
egami/wrapperBMP.h
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __EGAMI_WRAPPER_BMP_H__
|
||||
#define __EGAMI_WRAPPER_BMP_H__
|
||||
|
||||
#include <egami/egami.h>
|
||||
|
||||
namespace egami
|
||||
{
|
||||
bool LoadBMP(const etk::UString& _fileName, egami::Image& _ouputImage);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
158
egami/wrapperPNG.cpp
Normal file
158
egami/wrapperPNG.cpp
Normal file
@ -0,0 +1,158 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <egami/debug.h>
|
||||
#include <egami/Image.h>
|
||||
#include <egami/wrapperPNG.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
#include <png/png.h>
|
||||
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "wrapperPNG"
|
||||
|
||||
// we must change the access of the IO of the png lib :
|
||||
static void local_ReadData(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
etk::FSNode* fileNode = static_cast<etk::FSNode*>(png_get_io_ptr(png_ptr));
|
||||
if (NULL!=fileNode) {
|
||||
fileNode->FileRead(data, 1, length);
|
||||
}
|
||||
}
|
||||
/*
|
||||
static void LocalWriteData(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
etk::FSNode* fileNode = static_cast<etk::FSNode*>(png_get_io_ptr(png_ptr));
|
||||
if (NULL!=fileNode) {
|
||||
fileNode->FileWrite(data, 1, length);
|
||||
}
|
||||
}
|
||||
|
||||
static void localFlushData(png_structp png_ptr)
|
||||
{
|
||||
etk::FSNode* fileNode = static_cast<etk::FSNode*>(png_get_io_ptr(png_ptr));
|
||||
if (NULL!=fileNode) {
|
||||
fileNode->FileFlush();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
bool egami::LoadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage)
|
||||
{
|
||||
etk::FSNode fileName(_inputFile);
|
||||
|
||||
if (false==fileName.Exist()) {
|
||||
EGAMI_ERROR("File does not existed=\"" << fileName << "\"");
|
||||
return false;
|
||||
}
|
||||
if(false == fileName.FileOpenRead() ) {
|
||||
EGAMI_ERROR("Can not find the file name=\"" << fileName << "\"");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Vars
|
||||
int x, y = 0;
|
||||
int rowbytes;
|
||||
unsigned char header[8];
|
||||
png_infop info_ptr;
|
||||
png_structp png_ptr;
|
||||
png_bytep * row_pointers;
|
||||
|
||||
if (fileName.FileRead(header,1,8) != 8) {
|
||||
EGAMI_ERROR("error loading file header");
|
||||
fileName.FileClose();
|
||||
return false;
|
||||
}
|
||||
if (png_sig_cmp(header, 0, 8))
|
||||
{
|
||||
EGAMI_ERROR("Invalid file :" << fileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
// PNG read setup
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
setjmp(png_jmpbuf(png_ptr));
|
||||
// overwrite the read and write function :
|
||||
#if 1
|
||||
png_set_read_fn(png_ptr,
|
||||
&fileName,
|
||||
&local_ReadData);
|
||||
/*
|
||||
png_set_write_fn(png_ptr,
|
||||
&fileName,
|
||||
&LocalWriteData,
|
||||
&localFlushData);
|
||||
*/
|
||||
#else
|
||||
png_init_io(png_ptr, fp);
|
||||
#endif
|
||||
png_set_sig_bytes(png_ptr, 8);
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
int32_t width = png_get_image_width(png_ptr, info_ptr);
|
||||
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));
|
||||
|
||||
int32_t bit_depth = png_get_bit_depth(png_ptr, info_ptr);
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
setjmp(png_jmpbuf(png_ptr));
|
||||
row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
|
||||
rowbytes = width * ((bit_depth == 16) ? 8 : 4);
|
||||
|
||||
// File read
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
row_pointers[y] = (png_byte*) malloc(rowbytes);
|
||||
}
|
||||
png_read_image(png_ptr, row_pointers);
|
||||
png_set_expand(png_ptr);
|
||||
png_set_strip_16(png_ptr);
|
||||
|
||||
etk::Color<> tmpColor(0,0,0,0);
|
||||
switch (png_get_color_type(png_ptr, info_ptr) )
|
||||
{
|
||||
case PNG_COLOR_TYPE_RGBA:
|
||||
// Conversion to OpenGL texture
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
png_byte* row = row_pointers[y];
|
||||
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);
|
||||
}
|
||||
delete row_pointers[y];
|
||||
}
|
||||
break;
|
||||
case PNG_COLOR_TYPE_RGB:
|
||||
// Conversion to OpenGL texture
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
png_byte* row = row_pointers[y];
|
||||
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);
|
||||
}
|
||||
delete row_pointers[y];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
EGAMI_ERROR("Must be RGBA/RGB");
|
||||
return false;
|
||||
}
|
||||
|
||||
fileName.FileClose();
|
||||
return true;
|
||||
}
|
||||
|
20
egami/wrapperPNG.h
Normal file
20
egami/wrapperPNG.h
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __EGAMI_WRAPPER_PNG_H__
|
||||
#define __EGAMI_WRAPPER_PNG_H__
|
||||
|
||||
#include <egami/egami.h>
|
||||
|
||||
namespace egami
|
||||
{
|
||||
bool LoadPNG(const etk::UString& _fileName, egami::Image& _ouputImage);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
45
egami/wrapperSVG.cpp
Normal file
45
egami/wrapperSVG.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <egami/debug.h>
|
||||
#include <egami/Image.h>
|
||||
#include <egami/wrapperSVG.h>
|
||||
#include <etk/os/FSNode.h>
|
||||
#include <esvg/esvg.h>
|
||||
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "wrapperSVG"
|
||||
|
||||
|
||||
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 );
|
||||
return false;
|
||||
}
|
||||
draw::Image tmpImage;
|
||||
if( _size.x()>0
|
||||
&& _size.y()>0 ) {
|
||||
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().y(); 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;
|
||||
}
|
19
egami/wrapperSVG.h
Normal file
19
egami/wrapperSVG.h
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @author Edouard DUPIN
|
||||
*
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license BSD v3 (see license file)
|
||||
*/
|
||||
|
||||
#ifndef __EGAMI_WRAPPER_SVG_H__
|
||||
#define __EGAMI_WRAPPER_SVG_H__
|
||||
|
||||
#include <egami/egami.h>
|
||||
|
||||
namespace egami
|
||||
{
|
||||
bool LoadSVG(const etk::UString& _fileName, egami::Image& _ouputImage, const ivec2& _size=ivec2(-1,-1));
|
||||
};
|
||||
|
||||
#endif
|
31
lutin_egami.py
Normal file
31
lutin_egami.py
Normal file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/python
|
||||
import lutinModule
|
||||
import lutinTools
|
||||
|
||||
def Create(target):
|
||||
# module name is 'edn' and type binary.
|
||||
myModule = lutinModule.module(__file__, 'egami', 'LIBRARY')
|
||||
|
||||
# add the file to compile:
|
||||
myModule.AddSrcFile([
|
||||
'egami/Image.cpp',
|
||||
'egami/egami.cpp',
|
||||
'egami/debug.cpp',
|
||||
'egami/wrapperPNG.cpp',
|
||||
'egami/wrapperSVG.cpp',
|
||||
'egami/wrapperBMP.cpp'])
|
||||
|
||||
# name of the dependency
|
||||
myModule.AddModuleDepend(['etk', 'png', 'esvg'])
|
||||
|
||||
myModule.CompileFlags_CC([
|
||||
'-Wno-write-strings',
|
||||
'-Wall'])
|
||||
|
||||
myModule.AddExportPath(lutinTools.GetCurrentPath(__file__))
|
||||
|
||||
|
||||
# add the currrent module at the
|
||||
return myModule
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user