Add texture loader of the SVG files

This commit is contained in:
Edouard Dupin 2012-03-28 18:13:49 +02:00
parent dcd2bdb833
commit 9282ee6915
25 changed files with 904 additions and 432 deletions

View File

@ -119,7 +119,7 @@ namespace ewol
etk::UString bitmapRealFile = m_filename.GetFolder() + "/" + m_bitmapName;
EWOL_INFO("load text font image : \"" << bitmapRealFile << "\"");
etk::File tmpFile(bitmapRealFile, m_filename.GetTypeAccess());
m_textureId = ewol::LoadTexture(tmpFile);
m_textureId = ewol::texture::Load(tmpFile);
m_textureLoaded = true;
m_loadedOK = true;
};
@ -127,7 +127,7 @@ namespace ewol
~EbtFont(void)
{
if (true == m_textureLoaded) {
ewol::UnLoadTexture(m_textureId);
ewol::Texture::UnLoad(m_textureId);
}
};
bool loadedOK(void)
@ -204,7 +204,7 @@ namespace ewol
};
uint32_t GetOglId(void)
{
return GetTextureGLID(m_textureId);
return ewol::Texture::GetGLID(m_textureId);
};
int32_t GetHeight(void)
{

View File

@ -359,7 +359,7 @@ class FTFontInternal
EWOL_DEBUG("End generation of the Fond bitmap, start adding texture");
// use the texture manager to have the texture availlable every restart of the screen
//textureId = LoadTexture(GL_TEXTURE_2D, 0, GL_ALPHA8, textureWidth, textureHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, expanded_data, byfferDataSize * sizeof(GLubyte), "---FreeFont---" );
textureId = ewol::LoadTexture(GL_TEXTURE_2D, 0, GL_ALPHA, textureWidth, textureHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, expanded_data, byfferDataSize * sizeof(GLubyte), "---FreeFont---" );
textureId = ewol::texture::Load(GL_TEXTURE_2D, 0, GL_ALPHA, textureWidth, textureHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, expanded_data, byfferDataSize * sizeof(GLubyte), "---FreeFont---" );
EWOL_DEBUG("end load texture font");
// With The Texture Created, We Don't Need The Expanded Data Anymore.

View File

@ -65,7 +65,7 @@ void ewol::OObject2DText::Draw(void)
}
glColor4f(m_textColorFg.red, m_textColorFg.green, m_textColorFg.blue, m_textColorFg.alpha);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, ewol::GetTextureGLID(m_FontTextureId));
glBindTexture(GL_TEXTURE_2D, ewol::texture::GetGLID(m_FontTextureId));
glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays
glVertexPointer( 2, oglTypeFloat_t, 0, &m_coord[0] );

View File

@ -86,7 +86,7 @@ void ewol::OObject2DTextColored::Draw(void)
return;
}
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, ewol::GetTextureGLID(m_FontTextureId));
glBindTexture(GL_TEXTURE_2D, ewol::texture::GetGLID(m_FontTextureId));
glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays
glEnableClientState( GL_COLOR_ARRAY ); // Enable Color Arrays

View File

@ -34,12 +34,18 @@
ewol::OObject2DTextured::OObject2DTextured(etk::File textureName)
{
EWOL_DEBUG("Create OObject textured : \"" << textureName << "\"");
m_textureId = ewol::LoadTexture(textureName);
m_textureId = ewol::texture::Load(textureName);
}
ewol::OObject2DTextured::OObject2DTextured(etk::File textureName, etkFloat_t sizeX, etkFloat_t sizeY)
{
EWOL_DEBUG("Create OObject textured : \"" << textureName << "\"");
m_textureId = ewol::texture::Load(textureName, sizeX);
}
ewol::OObject2DTextured::~OObject2DTextured(void)
{
ewol::UnLoadTexture(m_textureId);
ewol::texture::UnLoad(m_textureId);
}
void ewol::OObject2DTextured::Draw(void)
@ -48,10 +54,14 @@ void ewol::OObject2DTextured::Draw(void)
EWOL_WARNING("Nothink to draw...");
return;
}
if (m_textureId == -1) {
EWOL_WARNING("Texture does not exist ...");
return;
}
glColor4f(1.0, 1.0, 1.0, 1.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, ewol::GetTextureGLID(m_textureId));
//EWOL_WARNING("Draw with texture : " << m_textureId << " ==> ogl=" << ewol::texture::GetGLID(m_textureId));
glBindTexture(GL_TEXTURE_2D, ewol::texture::GetGLID(m_textureId));
glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays
glVertexPointer( 2, oglTypeFloat_t, 0, &m_coord[0] );

View File

@ -32,6 +32,7 @@ namespace ewol {
{
public:
OObject2DTextured(etk::File textureName);
OObject2DTextured(etk::File textureName, etkFloat_t sizeX, etkFloat_t sizeY);
virtual ~OObject2DTextured(void);
public:
virtual void Draw(void);

View File

@ -27,287 +27,11 @@
#include <ewol/Texture.h>
#include <ewol/importgl.h>
#include <ewol/ewol.h>
#include <pthread.h>
extern "C"
{
#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__ "ewol::Bitmap"
class Bitmap
{
private:
modeBitmap_te m_dataMode;
int32_t m_width;
int32_t m_height;
int32_t m_size;
uint8_t * m_data;
uint8_t * m_dataGenerate;
bitmapFileHeader_ts m_FileHeader;
bitmapInfoHeader_ts m_InfoHeader;
public:
Bitmap(etk::File & fileName) : m_data(NULL), m_dataGenerate(NULL)
{
m_dataMode = BITS_16_R5G6B5;
m_width = 0;
m_height = 0;
m_size = 0;
// 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.fOpenRead() ) {
EWOL_ERROR("Can not find the file name=\"" << fileName << "\"");
return;
}
// get the data :
if (fileName.fRead(&m_FileHeader,sizeof(bitmapFileHeader_ts),1) != 1) {
EWOL_ERROR("error loading file header");
fileName.fClose();
return;
}
if (fileName.fRead(&m_InfoHeader,sizeof(bitmapInfoHeader_ts),1) != 1) {
EWOL_ERROR("error loading file header");
fileName.fClose();
return;
}
if(false == fileName.fSeek(m_FileHeader.bfOffBits, SEEK_SET)) {
EWOL_ERROR("error with the 'bfOffBits' in the file named=\"" << fileName << "\"");
fileName.fClose();
return;
}
// Check the header error :
if (m_FileHeader.bfType != 0x4D42) {
EWOL_ERROR("the file=\"" << fileName << "\" is not a bitmap file ...");
fileName.fClose();
return;
}
if (m_FileHeader.bfReserved != 0x00000000) {
EWOL_ERROR("the bfReserved feald is not at 0 ==> not supported format ...");
fileName.fClose();
return;
}
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 {
EWOL_ERROR("the biBitCount & biCompression fealds are unknow ==> not supported format ...");
fileName.fClose();;
return;
}
m_width = m_InfoHeader.biWidth;
m_height = m_InfoHeader.biHeight;
if(0 != m_InfoHeader.biSizeImage)
{
m_data=new uint8_t[m_InfoHeader.biSizeImage];
if (fileName.fRead(m_data,m_InfoHeader.biSizeImage,1) != 1){
EWOL_CRITICAL("Can not read the file with the good size...");
}
// allocate the destination data ...
m_dataGenerate=new uint8_t[m_width*m_height*4];
}
fileName.fClose();
// 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++) {
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 0] = (int8_t)((*pointer & 0xF800) >> 8);
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 1] = (int8_t)((*pointer & 0x07E0) >> 3);
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 2] = (int8_t)(*pointer << 3);
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 3] = 0xFF;
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++) {
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 0] = (int8_t)((*pointer & 0x7C00) >> 7);
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 1] = (int8_t)((*pointer & 0x03E0) >> 2);
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 2] = (int8_t)(*pointer << 3);
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 3] = 0xFF;
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++) {
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 0] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 1] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 2] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 3] = 0xFF;
}
}
}
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++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 0] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 1] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 2] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 3] = 0xFF;
}
}
}
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++) {
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 0] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 1] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 2] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 3] = *pointer++;
}
}
}
break;
default:
EWOL_DEBUG(" mode = ERROR");
break;
}
}
~Bitmap(void)
{
if (NULL != m_data) {
delete(m_data);
}
if (NULL != m_dataGenerate) {
delete(m_dataGenerate);
}
}
bool LoadOK(void) { if (NULL != m_dataGenerate) { return true; } else { return false; } };
int32_t Width(void) { return m_width; };
int32_t Height(void) { return m_height; };
uint8_t * Data(void) { return m_dataGenerate; };
void 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;
}
}
};
#include <ewol/Texture/TextureBMP.h>
#include <ewol/Texture/TextureSVG.h>
#include <ewol/Texture/TexturePNG.h>
//! One Texture element
class LoadedTexture
{
public:
@ -328,19 +52,18 @@ class LoadedTexture
bool m_loaded;
bool m_destroy;
};
etk::VectorType<LoadedTexture*> listLoadedTexture;
//! List of all Texture loaded ...
etk::VectorType<LoadedTexture*> l_listLoadedTexture;
#undef __class__
#define __class__ "ewol::texture"
#define __class__ "texture"
static pthread_mutex_t localMutex;
/**
* @brief Initialise the texture namespace (init a mutex)
* @param ---
* @return ---
*/
void ewol::texture::Init(void)
{
EWOL_DEBUG("==> Init Texture-Manager");
@ -349,92 +72,112 @@ void ewol::texture::Init(void)
EWOL_ASSERT(ret == 0, "Error creating Mutex ...");
}
/**
* @brief Un-Initialise the Texture namespace (Remove all loaded texture and temporary data and remove Mutex)
* @param ---
* @return ---
*/
void ewol::texture::UnInit(void)
{
pthread_mutex_lock(&localMutex);
EWOL_DEBUG("==> Un-Init Texture-Manager");
for (int32_t iii=0; iii<listLoadedTexture.Size(); iii++) {
if (listLoadedTexture[iii] != NULL) {
delete(listLoadedTexture[iii]);
for (int32_t iii=0; iii<l_listLoadedTexture.Size(); iii++) {
if (l_listLoadedTexture[iii] != NULL) {
delete(l_listLoadedTexture[iii]);
}
listLoadedTexture[iii] = NULL;
l_listLoadedTexture[iii] = NULL;
}
listLoadedTexture.Clear();
l_listLoadedTexture.Clear();
pthread_mutex_unlock(&localMutex);
int ret = pthread_mutex_destroy(&localMutex);
EWOL_ASSERT(ret == 0, "Error destroying Mutex ...");
}
#undef __class__
#define __class__ "ewol"
void ewol::UpdateTextureContextIsDestroy(void)
/**
* @brief Specific for Android, some configuration restart openGl context when the screen is rotate, then,
* Android inform us that the openGl context has been destroy. We mark all the texture like not loaded
* To load it again when a new context will be enable (@ref UpdateContext)
* @param ---
* @return ---
*/
void ewol::texture::UpdateContextIsDestroy(void)
{
pthread_mutex_lock(&localMutex);
for (int32_t iii=0; iii < listLoadedTexture.Size(); iii++) {
if( NULL != listLoadedTexture[iii]
&& NULL != listLoadedTexture[iii]->m_data)
for (int32_t iii=0; iii < l_listLoadedTexture.Size(); iii++) {
if( NULL != l_listLoadedTexture[iii]
&& NULL != l_listLoadedTexture[iii]->m_data)
{
listLoadedTexture[iii]->m_loaded = false;
EWOL_INFO("TEXTURE: Disable [" << iii << "]=(" << listLoadedTexture[iii]->m_width << "px," <<
listLoadedTexture[iii]->m_height << "px) in file:" <<
listLoadedTexture[iii]->m_filename << " OGl_Id=" <<listLoadedTexture[iii]->m_openGlTextureID);
//glDeleteTextures(1, &listLoadedTexture[iii]->m_openGlTextureID);
l_listLoadedTexture[iii]->m_loaded = false;
EWOL_INFO("TEXTURE: Disable [" << iii << "]=(" << l_listLoadedTexture[iii]->m_width << "px," <<
l_listLoadedTexture[iii]->m_height << "px) in file:" <<
l_listLoadedTexture[iii]->m_filename << " OGl_Id=" <<l_listLoadedTexture[iii]->m_openGlTextureID);
// note : the context might be destroy... we can not remove the textures ...
//glDeleteTextures(1, &l_listLoadedTexture[iii]->m_openGlTextureID);
}
}
pthread_mutex_unlock(&localMutex);
}
void ewol::UpdateTextureContext(void)
/**
* @brief Check all texture and load/Remove/Reload all texture that has been Add/Remove/Change from the previous display cycle
* @param ---
* @return ---
*/
// TODO : The reload might be writen ...
void ewol::texture::UpdateContext(void)
{
bool needRedraw = false;
pthread_mutex_lock(&localMutex);
for (int32_t iii=0; iii < listLoadedTexture.Size(); iii++) {
if( NULL != listLoadedTexture[iii]
&& NULL != listLoadedTexture[iii]->m_data)
for (int32_t iii=0; iii < l_listLoadedTexture.Size(); iii++) {
if( NULL != l_listLoadedTexture[iii]
&& NULL != l_listLoadedTexture[iii]->m_data)
{
if( false == listLoadedTexture[iii]->m_destroy
&& false == listLoadedTexture[iii]->m_loaded)
if( false == l_listLoadedTexture[iii]->m_destroy
&& false == l_listLoadedTexture[iii]->m_loaded)
{
GLuint textureid;
glGenTextures(1, &textureid);
glBindTexture(listLoadedTexture[iii]->m_target, textureid);
glBindTexture(l_listLoadedTexture[iii]->m_target, textureid);
//glTexParameteri(tmpTex->m_target, GL_TEXTURE_WRAP_S, GL_REPEAT);
//glTexParameteri(tmpTex->m_target, GL_TEXTURE_WRAP_T, GL_REPEAT);
//--- mode nearest
//glTexParameteri(tmpTex->m_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//glTexParameteri(tmpTex->m_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
//--- Mode linear
glTexParameteri(listLoadedTexture[iii]->m_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(listLoadedTexture[iii]->m_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
EWOL_INFO("TEXTURE: Add [" << iii << "]=(" << listLoadedTexture[iii]->m_width << "px," <<
listLoadedTexture[iii]->m_height << "px) in file:" <<
listLoadedTexture[iii]->m_filename << " OGl_Id=" <<textureid);
glTexImage2D(listLoadedTexture[iii]->m_target,
listLoadedTexture[iii]->m_level,
listLoadedTexture[iii]->m_internalFormat,
listLoadedTexture[iii]->m_width,
listLoadedTexture[iii]->m_height,
listLoadedTexture[iii]->m_border,
listLoadedTexture[iii]->m_format,
listLoadedTexture[iii]->m_type,
listLoadedTexture[iii]->m_data);
listLoadedTexture[iii]->m_openGlTextureID = textureid;
listLoadedTexture[iii]->m_loaded = true;
glTexParameteri(l_listLoadedTexture[iii]->m_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(l_listLoadedTexture[iii]->m_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
EWOL_INFO("TEXTURE: Add [" << iii << "]=(" << l_listLoadedTexture[iii]->m_width << "px," <<
l_listLoadedTexture[iii]->m_height << "px) in file:" <<
l_listLoadedTexture[iii]->m_filename << " OGl_Id=" <<textureid);
glTexImage2D(l_listLoadedTexture[iii]->m_target,
l_listLoadedTexture[iii]->m_level,
l_listLoadedTexture[iii]->m_internalFormat,
l_listLoadedTexture[iii]->m_width,
l_listLoadedTexture[iii]->m_height,
l_listLoadedTexture[iii]->m_border,
l_listLoadedTexture[iii]->m_format,
l_listLoadedTexture[iii]->m_type,
l_listLoadedTexture[iii]->m_data);
l_listLoadedTexture[iii]->m_openGlTextureID = textureid;
l_listLoadedTexture[iii]->m_loaded = true;
needRedraw = true;
} else if ( true == listLoadedTexture[iii]->m_destroy
&& true == listLoadedTexture[iii]->m_loaded)
} else if ( true == l_listLoadedTexture[iii]->m_destroy
&& true == l_listLoadedTexture[iii]->m_loaded)
{
// Request remove texture ...
EWOL_DEBUG("TEXTURE: Rm [" << iii << "] file:" << listLoadedTexture[iii]->m_filename);
glDeleteTextures(1, &listLoadedTexture[iii]->m_openGlTextureID);
listLoadedTexture[iii]->m_loaded = false;
listLoadedTexture[iii]->m_openGlTextureID = -1;
if (NULL != listLoadedTexture[iii]->m_data) {
delete[] listLoadedTexture[iii]->m_data;
listLoadedTexture[iii]->m_data = NULL;
EWOL_INFO("TEXTURE: Rm [" << iii << "] file:" << l_listLoadedTexture[iii]->m_filename);
glDeleteTextures(1, &l_listLoadedTexture[iii]->m_openGlTextureID);
l_listLoadedTexture[iii]->m_loaded = false;
l_listLoadedTexture[iii]->m_openGlTextureID = -1;
if (NULL != l_listLoadedTexture[iii]->m_data) {
delete[] l_listLoadedTexture[iii]->m_data;
l_listLoadedTexture[iii]->m_data = NULL;
}
delete(listLoadedTexture[iii]);
listLoadedTexture[iii] = NULL;
delete(l_listLoadedTexture[iii]);
l_listLoadedTexture[iii] = NULL;
}
}
}
@ -444,17 +187,25 @@ void ewol::UpdateTextureContext(void)
}
}
int32_t ewol::LoadTexture(int32_t target,
int32_t level,
int32_t internalFormat,
int32_t width,
int32_t height,
int32_t border,
int32_t format,
int32_t type,
const void* data,
int32_t nbBytes,
etk::UString filename)
/**
* @brief Register a texture in the automatic system to load and reload
* @param[in] target Standard element of OpenGL target
* @param[in] level Standard element of OpenGL level
* @param[in] internalFormat Standard element of OpenGL internalFormat
* @param[in] width Standard element of OpenGL width
* @param[in] height Standard element of OpenGL height
* @param[in] border Standard element of OpenGL border
* @param[in] format Standard element of OpenGL format
* @param[in] type Standard element of OpenGL type
* @param[in] data Pointer on the buffer where are contain the data (a copy is done automaticly)
* @param[in] nbBytes Number of byte in the buffer
* @param[in] filename File Name of the texture or "---" if it is an internal loaded texture
* @return The Internal ID of the texture, or -1 if an error occured ...
*/
int32_t ewol::texture::Load(int32_t target, int32_t level, int32_t internalFormat, int32_t width, int32_t height,
int32_t border, int32_t format, int32_t type,
const void* data, int32_t nbBytes, etk::UString filename)
{
LoadedTexture *tmpTex = new LoadedTexture();
@ -463,6 +214,10 @@ int32_t ewol::LoadTexture(int32_t target,
EWOL_ERROR("Texture : Allocation ERROR... " << filename);
return -1;
}
if (NULL == data){
EWOL_ERROR("Texture : Input pointer of the data texture =NULL... " << filename);
return -1;
}
tmpTex->m_filename = filename;
tmpTex->m_nbTimeLoaded = 1;
@ -486,80 +241,155 @@ int32_t ewol::LoadTexture(int32_t target,
memcpy(tmpTex->m_data, data, sizeof(char) * tmpTex->m_nbBytes);
pthread_mutex_lock(&localMutex);
listLoadedTexture.PushBack(tmpTex);
outTextureID = listLoadedTexture.Size()-1;
l_listLoadedTexture.PushBack(tmpTex);
outTextureID = l_listLoadedTexture.Size()-1;
pthread_mutex_unlock(&localMutex);
return outTextureID;
}
int32_t ewol::LoadTexture(etk::File fileName)
/**
* @brief get the next power 2 if the input
* @param[in] value Value that we want the next power of 2
* @return result value
*/
static int32_t nextP2(int32_t value)
{
int32_t val=1;
for (int32_t iii=1; iii<31; iii++) {
if (value <= val) {
return val;
}
val *=2;
}
EWOL_CRITICAL("impossible CASE....");
return val;
}
/**
* @brief Load a specific file texture
* @note : dimention must be a power of 2, otherwise, the display can be wrong... For the SVG, the texture automaticly generate the power of 2 dimention ...
* @param[in] fileName File that might be open
* @param[in] requestedWidth Requested size of the file we desire (if we can not resize it, we load it whit his normal size)
* @return The Internal ID of the texture, or -1 if an error occured ...
*/
// TODO : Load non square texture ...
// TODO : Check the size to regenerate the texture if the size change
int32_t ewol::texture::Load(etk::File fileName, int32_t requestedWidth)
{
int32_t outTextureID = -1;
if (listLoadedTexture.Size()!=0) {
for (int32_t iii=0; iii<listLoadedTexture.Size(); iii++) {
if (NULL != listLoadedTexture[iii]) {
if (listLoadedTexture[iii]->m_filename == fileName.GetCompleateName()) {
listLoadedTexture[iii]->m_nbTimeLoaded++;
if (l_listLoadedTexture.Size()!=0) {
for (int32_t iii=0; iii<l_listLoadedTexture.Size(); iii++) {
if (NULL != l_listLoadedTexture[iii]) {
if (l_listLoadedTexture[iii]->m_filename == fileName.GetCompleateName()) {
l_listLoadedTexture[iii]->m_nbTimeLoaded++;
return iii;
}
}
}
}
etk::UString fileExtention = fileName.GetExtention();
if (fileExtention == "bmp") {
if (false == fileName.Exist()) {
EWOL_ERROR("File does not Exist ... " << fileName);
} else {
Bitmap * myBitmap = new Bitmap(fileName);
if (false == fileName.Exist()) {
EWOL_ERROR("File does not Exist ... " << fileName);
} else {
etk::UString fileExtention = fileName.GetExtention();
if (fileExtention == "bmp") {
// create the bitmap texture
ewol::texture::TextureBMP * myBitmap = new ewol::texture::TextureBMP(fileName);
// draw bitmap properties
myBitmap->Display();
// check if all is OK
if (myBitmap->LoadOK() == true) {
if (myBitmap->Width()!= myBitmap->Height()) {
if (myBitmap->Width() != nextP2(myBitmap->Width()) ) {
EWOL_ERROR("Texture has not the good dimention power of 2 : Width=" << myBitmap->Width() << "px ==> maybe not drawable ...");
}
if (myBitmap->Width() != myBitmap->Height()) {
EWOL_ERROR("Texture can not have Width=" << myBitmap->Width() << "px different of height=" << myBitmap->Height() << "px in file:" << fileName);
return -1;
}
outTextureID = LoadTexture(GL_TEXTURE_2D, 0, GL_RGBA, myBitmap->Width(), myBitmap->Height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, myBitmap->Data(), myBitmap->Width()*myBitmap->Height()*4, fileName.GetCompleateName());
outTextureID = ewol::texture::Load(GL_TEXTURE_2D, 0, GL_RGBA, myBitmap->Width(), myBitmap->Height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, myBitmap->Data(), myBitmap->DataSize(), fileName.GetCompleateName());
}
// removet the bitmap handle
delete (myBitmap);
} else if (fileExtention == "svg") {
// get the upper paw2 ot the size requested...
requestedWidth = nextP2(requestedWidth);
/*if (requestedWidth < 32) {
requestedWidth = 32;
}*/
// create the bitmap texture
ewol::texture::TextureSVG * mySvg = new ewol::texture::TextureSVG(fileName, requestedWidth, requestedWidth);
// draw bitmap properties
mySvg->Display();
// check if all is OK
if (mySvg->LoadOK() == true) {
if (mySvg->Width() != mySvg->Height()) {
EWOL_ERROR("Texture can not have Width=" << mySvg->Width() << "px different of height=" << mySvg->Height() << "px in file:" << fileName);
return -1;
}
outTextureID = ewol::texture::Load(GL_TEXTURE_2D, 0, GL_RGBA, mySvg->Width(), mySvg->Height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, mySvg->Data(), mySvg->DataSize(), fileName.GetCompleateName());
}
// removet the bitmap handle
delete (mySvg);
} else if (fileExtention == "png") {
EWOL_ERROR("Extention not supported now, but soon " << fileName );
} else {
EWOL_ERROR("Extention not managed " << fileName << " Sopported extention : .bmp / .svg / .png");
}
} else {
EWOL_ERROR("Extention not managed " << fileName << " Sopported extention : .bmp");
}
return outTextureID;
}
void ewol::UnLoadTexture(uint32_t textureID)
/**
* @brief Remove a specific texture ID from the system
* @note A texture can be loaded as many time we want, the texture will be destroy only when nobody want the texture anymore
* @param[in] textureID The internal texture ID that might be remove
* @return ---
*/
void ewol::texture::UnLoad(uint32_t textureID)
{
EWOL_INFO("Unload a specific tecture ID=" << textureID);
if (textureID>=0 && (int32_t)textureID<listLoadedTexture.Size()) {
if (NULL == listLoadedTexture[textureID]) {
if (textureID>=0 && (int32_t)textureID<l_listLoadedTexture.Size()) {
if (NULL == l_listLoadedTexture[textureID]) {
EWOL_ERROR("Texture : " << textureID << " does not existe anymore...");
return;
}
listLoadedTexture[textureID]->m_nbTimeLoaded--;
if (0 == listLoadedTexture[textureID]->m_nbTimeLoaded) {
EWOL_DEBUG("Remove openGL texture ID=" << textureID << " file:" << listLoadedTexture[textureID]->m_filename);
listLoadedTexture[textureID]->m_destroy = true;
l_listLoadedTexture[textureID]->m_nbTimeLoaded--;
if (0 == l_listLoadedTexture[textureID]->m_nbTimeLoaded) {
EWOL_DEBUG("Remove openGL texture ID=" << textureID << " file:" << l_listLoadedTexture[textureID]->m_filename);
l_listLoadedTexture[textureID]->m_destroy = true;
}
return;
}
EWOL_CRITICAL("Can not find TextureId=" << (int)textureID << " in the list of texture loaded...==> to remove it ...");
}
uint32_t ewol::GetTextureGLID(uint32_t textureID)
/**
* @brief Get the openGL texture ID whith the internal ID
* @param textureID the internal texture ID
* @return the OpenGl texture ID (or 0 if an error occured...)
*/
uint32_t ewol::texture::GetGLID(uint32_t textureID)
{
if (textureID>=0 && (int32_t)textureID<listLoadedTexture.Size()) {
return listLoadedTexture[textureID]->m_openGlTextureID;
if (textureID>=0 && (int32_t)textureID<l_listLoadedTexture.Size()) {
return l_listLoadedTexture[textureID]->m_openGlTextureID;
}
return -1;
return 0;
}
int32_t ewol::GetTextureSize(uint32_t textureID)
/**
* @brief Get the size of the specific texture
* @param[in] textureID the internal texture ID
* @return the width of the texture
*/
int32_t ewol::texture::GetSize(uint32_t textureID)
{
for (int32_t iii=0; iii<listLoadedTexture.Size(); iii++) {
if (listLoadedTexture[iii]->m_openGlTextureID == textureID) {
return listLoadedTexture[iii]->m_width;
for (int32_t iii=0; iii<l_listLoadedTexture.Size(); iii++) {
if (l_listLoadedTexture[iii]->m_openGlTextureID == textureID) {
return l_listLoadedTexture[iii]->m_width;
}
}
EWOL_ERROR("Can not find TextureId=" << textureID << " in the list of texture loaded...");

View File

@ -31,26 +31,18 @@
namespace ewol
{
// TODO : Create a subNameSpace:
/*
namespace texture {
int32_t Load(etk::File fileName);
void UnLoad(uint32_t textureID);
int32_t GetSize(uint32_t textureID);
};
*/
namespace texture {
void Init(void);
void UnInit(void);
int32_t Load(etk::File fileName, int32_t requestedWidth=-1);
int32_t Load(int32_t target, int32_t level, int32_t internalFormat, int32_t width, int32_t height, int32_t border, int32_t format, int32_t type, const void* data, int32_t nbBytes, etk::UString filename);
void UnLoad(uint32_t textureID);
int32_t GetSize(uint32_t textureID);
uint32_t GetGLID(uint32_t textureID);
void UpdateContext(void);
void UpdateContextIsDestroy(void);
void OGLContext(bool enable);
};
int32_t LoadTexture(etk::File fileName);
int32_t LoadTexture(int32_t target, int32_t level, int32_t internalFormat, int32_t width, int32_t height, int32_t border, int32_t format, int32_t type, const void* data, int32_t nbBytes, etk::UString filename);
void UnLoadTexture(uint32_t textureID);
int32_t GetTextureSize(uint32_t textureID);
uint32_t GetTextureGLID(uint32_t textureID);
void UpdateTextureContext(void);
void UpdateTextureContextIsDestroy(void);
void TextureOGLContext(bool enable);
};
#endif

View File

@ -0,0 +1,282 @@
/**
*******************************************************************************
* @file ewol/Texture/TextureBMP.cpp
* @brief ewol Texture Bitmap abstraction (sources)
* @author Edouard DUPIN
* @date 28/03/2012
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
#include <ewol/Texture/TextureBMP.h>
#undef __class__
#define __class__ "texture::TextureBMP"
ewol::texture::TextureBMP::TextureBMP(etk::File & fileName) : m_data(NULL), m_dataGenerate(NULL)
{
m_dataMode = BITS_16_R5G6B5;
m_width = 0;
m_height = 0;
m_size = 0;
// 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.fOpenRead() ) {
EWOL_ERROR("Can not find the file name=\"" << fileName << "\"");
return;
}
// get the data :
if (fileName.fRead(&m_FileHeader,sizeof(bitmapFileHeader_ts),1) != 1) {
EWOL_ERROR("error loading file header");
fileName.fClose();
return;
}
if (fileName.fRead(&m_InfoHeader,sizeof(bitmapInfoHeader_ts),1) != 1) {
EWOL_ERROR("error loading file header");
fileName.fClose();
return;
}
if(false == fileName.fSeek(m_FileHeader.bfOffBits, SEEK_SET)) {
EWOL_ERROR("error with the 'bfOffBits' in the file named=\"" << fileName << "\"");
fileName.fClose();
return;
}
// Check the header error :
if (m_FileHeader.bfType != 0x4D42) {
EWOL_ERROR("the file=\"" << fileName << "\" is not a bitmap file ...");
fileName.fClose();
return;
}
if (m_FileHeader.bfReserved != 0x00000000) {
EWOL_ERROR("the bfReserved feald is not at 0 ==> not supported format ...");
fileName.fClose();
return;
}
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 {
EWOL_ERROR("the biBitCount & biCompression fealds are unknow ==> not supported format ...");
fileName.fClose();;
return;
}
m_width = m_InfoHeader.biWidth;
m_height = m_InfoHeader.biHeight;
if(0 != m_InfoHeader.biSizeImage)
{
m_data=new uint8_t[m_InfoHeader.biSizeImage];
if (fileName.fRead(m_data,m_InfoHeader.biSizeImage,1) != 1){
EWOL_CRITICAL("Can not read the file with the good size...");
}
// allocate the destination data ...
m_dataGenerate=new uint8_t[m_width*m_height*4];
}
fileName.fClose();
// 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++) {
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 0] = (int8_t)((*pointer & 0xF800) >> 8);
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 1] = (int8_t)((*pointer & 0x07E0) >> 3);
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 2] = (int8_t)(*pointer << 3);
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 3] = 0xFF;
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++) {
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 0] = (int8_t)((*pointer & 0x7C00) >> 7);
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 1] = (int8_t)((*pointer & 0x03E0) >> 2);
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 2] = (int8_t)(*pointer << 3);
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 3] = 0xFF;
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++) {
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 0] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 1] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 2] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 3] = 0xFF;
}
}
}
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++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 0] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 1] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 2] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 3] = 0xFF;
}
}
}
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++) {
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 0] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 1] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 2] = *pointer++;
m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 3] = *pointer++;
}
}
}
break;
default:
EWOL_DEBUG(" mode = ERROR");
break;
}
}
ewol::texture::TextureBMP::~TextureBMP(void)
{
if (NULL != m_data) {
delete(m_data);
}
if (NULL != m_dataGenerate) {
delete(m_dataGenerate);
}
}
bool ewol::texture::TextureBMP::LoadOK(void)
{
if (NULL != m_dataGenerate) {
return true;
} else {
return false;
}
};
int32_t ewol::texture::TextureBMP::Width(void)
{
return m_width;
}
int32_t ewol::texture::TextureBMP::Height(void)
{
return m_height;
}
uint8_t * ewol::texture::TextureBMP::Data(void)
{
return m_dataGenerate;
};
uint32_t ewol::texture::TextureBMP::DataSize(void)
{
if (NULL == m_dataGenerate) {
return 0;
}
return m_width*m_height*4;
}
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;
}
}

View File

@ -0,0 +1,93 @@
/**
*******************************************************************************
* @file ewol/Texture/TextureBMP.h
* @brief ewol Texture Bitmap abstraction (header)
* @author Edouard DUPIN
* @date 28/03/2012
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
#ifndef __EWOL_TEXTURE_BITMAP_H__
#define __EWOL_TEXTURE_BITMAP_H__
#include <etk/Types.h>
#include <ewol/Debug.h>
#include <etk/File.h>
namespace ewol
{
namespace texture {
#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;
class TextureBMP
{
private:
modeBitmap_te m_dataMode;
int32_t m_width;
int32_t m_height;
int32_t m_size;
uint8_t * m_data;
uint8_t * m_dataGenerate;
bitmapFileHeader_ts m_FileHeader;
bitmapInfoHeader_ts m_InfoHeader;
public:
TextureBMP(etk::File & fileName);
~TextureBMP(void);
bool LoadOK(void);
int32_t Width(void);
int32_t Height(void);
uint8_t * Data(void);
uint32_t DataSize(void);
void Display(void);
};
};
};
#endif

View File

@ -0,0 +1,86 @@
/**
*******************************************************************************
* @file ewol/Texture/TextureSVG.cpp
* @brief ewol Texture SVG abstraction (Sources)
* @author Edouard DUPIN
* @date 28/03/2012
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
#include <ewol/Texture/TextureSVG.h>
#undef __class__
#define __class__ "texture::TextureSVG"
ewol::texture::TextureSVG::TextureSVG(etk::File & fileName, int32_t width, int32_t height) : m_elementParsed(fileName)
{
m_loadOK = false;
if (false == m_elementParsed.IsLoadOk()) {
EWOL_ERROR("Error To load SVG file " << fileName.GetCompleateName() );
} else {
m_elementParsed.GenerateAnImage(width, height);
m_loadOK = true;
}
if (width == -1) {
coord2D_ts elementSize = m_elementParsed.GetDefinedSize();
m_width = elementSize.x;
m_height = elementSize.y;
} else {
m_width = width;
m_height = height;
}
}
ewol::texture::TextureSVG::~TextureSVG(void)
{
}
bool ewol::texture::TextureSVG::LoadOK(void)
{
return m_loadOK;
}
int32_t ewol::texture::TextureSVG::Width(void)
{
return m_width;
}
int32_t ewol::texture::TextureSVG::Height(void)
{
return m_height;
}
uint8_t * ewol::texture::TextureSVG::Data(void)
{
return m_elementParsed.GetPointerOnData();
}
uint32_t ewol::texture::TextureSVG::DataSize(void)
{
return m_elementParsed.GetSizeOnData();
}
void ewol::texture::TextureSVG::Display(void)
{
EWOL_DEBUG("SVG Texture : (" << m_width << "," << m_height << ") loadedOK=" << m_loadOK);
}

View File

@ -0,0 +1,59 @@
/**
*******************************************************************************
* @file ewol/Texture/TextureSVG.h
* @brief ewol Texture SVG abstraction (header)
* @author Edouard DUPIN
* @date 28/03/2012
* @par Project
* ewol
*
* @par Copyright
* Copyright 2011 Edouard DUPIN, all right reserved
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY.
*
* Licence summary :
* You can modify and redistribute the sources code and binaries.
* You can send me the bug-fix
*
* Term of the licence in in the file licence.txt.
*
*******************************************************************************
*/
#ifndef __EWOL_TEXTURE_SVG_H__
#define __EWOL_TEXTURE_SVG_H__
#include <etk/Types.h>
#include <ewol/Debug.h>
#include <etk/File.h>
#include <parserSVG/parserSVG.h>
namespace ewol
{
namespace texture {
class TextureSVG
{
private:
svg::Parser m_elementParsed;
int32_t m_width;
int32_t m_height;
int32_t m_size;
uint8_t * m_data;
bool m_loadOK;
public:
TextureSVG(etk::File & fileName, int32_t width, int32_t height);
~TextureSVG(void);
bool LoadOK(void);
int32_t Width(void);
int32_t Height(void);
uint8_t * Data(void);
uint32_t DataSize(void);
void Display(void);
};
};
};
#endif

View File

@ -177,6 +177,7 @@ void EWOL_GenericDraw(bool everyTime)
if( true == ewol::widgetManager::GetDoubleBufferNeedDraw()
|| true == everyTime)
{
ewol::texture::UpdateContext();
nbDisplayTime++;
gui_uniqueWindows->SysDraw();
//EWOL_WARNING("DRAW...");
@ -195,7 +196,7 @@ void EWOL_GenericDraw(bool everyTime)
void EWOL_NativeGLDestroy(void)
{
ewol::UpdateTextureContextIsDestroy();
ewol::texture::UpdateContextIsDestroy();
}

View File

@ -82,7 +82,7 @@ static etkFloat_t gTriangleVertices5[] = { 200.0f, 200.0f, 100.0f, 200.0f, 200.0
void EWOL_NativeRender(void)
{
ewol::UpdateTextureContext();
ewol::texture::UpdateContext();
//EWOL_DEBUG("redraw (" << gui_width << "," << gui_height << ")");
if(NULL == gui_uniqueWindows) {
// set the size of the open GL system

View File

@ -292,7 +292,7 @@ bool CreateOGlContext(void)
void EWOL_NativeRender(void)
{
ewol::UpdateTextureContext();
ewol::texture::UpdateContext();
//EWOL_DEBUG("redraw (" << gui_width << "," << gui_height << ")");
if(NULL == gui_uniqueWindows) {
//EWOL_DEBUG("Has No Windows set...");

View File

@ -43,7 +43,7 @@ void ewol::Button::Init(void)
AddEventId(ewolEventButtonPressed);
AddEventId(ewolEventButtonEnter);
AddEventId(ewolEventButtonLeave);
m_hasAnImage = false;
m_alignement = ewol::TEXT_ALIGN_CENTER;
#ifdef __PLATFORM__Android
@ -84,6 +84,15 @@ ewol::Button::~Button(void)
}
void ewol::Button::SetImage(etk::UString imageName)
{
if (imageName == "") {
m_hasAnImage = false;
} else {
m_imageSelected.SetCompleateName(imageName, etk::FILE_TYPE_DATA);
m_hasAnImage = true;
}
}
//!< EObject name :
extern const char * const ewol::TYPE_EOBJECT_WIDGET_BUTTON = "Button";
@ -135,6 +144,13 @@ bool ewol::Button::CalculateMinSize(void)
int32_t minHeight = ewol::GetHeight(fontId);
m_minSize.x = m_padding.x*2 + minWidth;
m_minSize.y = m_padding.y*2 + minHeight;
// Add the image element ...
if (true == m_hasAnImage) {
//m_minSize.x += -m_padding.x + m_padding.y*2 + minHeight;
//m_minSize.y += m_padding.y*2;
m_minSize.x += m_padding.x + minHeight;
}
MarkToReedraw();
return true;
}
@ -202,6 +218,16 @@ void ewol::Button::OnRegenerateDisplay(void)
coord2D_ts textPos;
textPos.x = tmpTextOriginX;
textPos.y = tmpTextOriginY;
ewol::OObject2DTextured * tmpImage = NULL;
if (true == m_hasAnImage) {
int32_t fontId = GetDefaultFontId();
int32_t fontHeight = ewol::GetHeight(fontId);
tmpImage = new ewol::OObject2DTextured(m_imageSelected, fontHeight, fontHeight);
tmpImage->Rectangle(textPos.x, textPos.y, fontHeight, fontHeight);
// update the text position ...
textPos.x += m_padding.x + fontHeight;
}
clipping_ts drawClipping;
drawClipping.x = m_padding.x;
drawClipping.y = m_padding.y;
@ -216,9 +242,16 @@ void ewol::Button::OnRegenerateDisplay(void)
tmpSizeX += m_padding.x/1;
tmpSizeY += m_padding.y/1;
tmpOObjects->Rectangle( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY);
AddOObject(tmpOObjects);
AddOObject(tmpText);
// add all needed objects ...
if (NULL != tmpOObjects) {
AddOObject(tmpOObjects);
}
if (NULL != tmpImage) {
AddOObject(tmpImage);
}
if (NULL != tmpText) {
AddOObject(tmpText);
}
}
}

View File

@ -63,11 +63,14 @@ namespace ewol {
virtual bool CalculateMinSize(void);
void SetLabel(etk::UString newLabel);
etk::UString GetLabel(void) {return m_label;};
void SetImage(etk::UString imageName);
void SetValue(bool val);
bool GetValue(void);
void SetAlignement(textAlignement_te typeAlign);
void SetPadding(coord2D_ts newPadding);
private:
bool m_hasAnImage;
etk::File m_imageSelected;
textAlignement_te m_alignement;
coord2D_ts m_padding;
etk::UString m_label;

View File

@ -141,9 +141,13 @@ int32_t ewol::Menu::Add(int32_t parent, etk::UString label, etk::UString image,
myButton = new ewol::Button(label);
if (NULL == myButton) {
EWOL_ERROR("Allocation button error");
return tmpObject->m_localId;;
return tmpObject->m_localId;
}
// set the image if one is present ...
myButton->SetImage(tmpObject->m_image);
// add it in the widget list
ewol::SizerHori::SubWidgetAdd(myButton);
// keep the specific event ...
myButton->RegisterOnEvent(this, ewolEventButtonPressed, ewolEventButtonPressed);
tmpObject->m_widgetPointer = myButton;
}
@ -229,13 +233,17 @@ void ewol::Menu::OnReceiveMessage(ewol::EObject * CallerObject, const char * eve
myButton = new ewol::Button(m_listElement[jjj]->m_label);
if (NULL == myButton) {
EWOL_ERROR("Allocation Error");
} else {
// set the image if one is present ...
myButton->SetImage(m_listElement[jjj]->m_image);
myButton->RegisterOnEvent(this, ewolEventButtonPressed, ewolEventButtonPressed, "");
myButton->SetExpendX(true);
myButton->SetFillX(true);
myButton->SetAlignement(ewol::TEXT_ALIGN_LEFT);
// add it in the widget list
mySizerVert->SubWidgetAdd(myButton);
m_listElement[jjj]->m_widgetPointer = myButton;
}
m_listElement[jjj]->m_widgetPointer = myButton;
myButton->RegisterOnEvent(this, ewolEventButtonPressed, ewolEventButtonPressed, "");
myButton->SetExpendX(true);
myButton->SetFillX(true);
myButton->SetAlignement(ewol::TEXT_ALIGN_LEFT);
mySizerVert->SubWidgetAdd(myButton);
}
}
ewol::PopUpWidgetPush(m_widgetContextMenu);

View File

@ -15,6 +15,9 @@ FILE_LIST = ewol/ewol.cpp \
ewol/OObject/2DTextured.cpp \
ewol/OObject/e2d.cpp \
ewol/Texture.cpp \
ewol/Texture/TextureBMP.cpp \
ewol/Texture/TexturePNG.cpp \
ewol/Texture/TextureSVG.cpp \
ewol/FontBitmap.cpp \
ewol/FontFreeType.cpp \
ewol/Widget.cpp \

View File

@ -30,10 +30,12 @@
svg::Renderer::Renderer(uint32_t width, uint32_t height)
{
m_allocatedSize = 0;
m_size.x = width;
m_size.y = height;
int32_t dataSize = ((int32_t)width * (int32_t)height * DATA_ALLOCATION_ELEMENT);
m_allocatedSize = dataSize;
// allocate Data
SVG_DEBUG("Allocate buffer : " << dataSize);
@ -41,10 +43,11 @@ svg::Renderer::Renderer(uint32_t width, uint32_t height)
ETK_MALLOC(m_buffer, dataSize, uint8_t);
if (NULL == m_buffer) {
SVG_ERROR("Allocation of the output buffer for SVG drawing error");
m_allocatedSize = 0;
return;
}
memset(m_buffer, 0xFF, dataSize * sizeof(uint8_t) );
memset(m_buffer, 0x00, dataSize * sizeof(uint8_t) );
m_renderingBuffer = new agg::rendering_buffer(m_buffer, m_size.x, m_size.y, m_size.x * DATA_ALLOCATION_ELEMENT);
if (NULL == m_renderingBuffer) {

View File

@ -69,6 +69,7 @@ namespace svg
class Renderer {
private:
uint8_t * m_buffer;
uint32_t m_allocatedSize;
public:
Renderer(uint32_t width, uint32_t height);
~Renderer(void);
@ -80,6 +81,8 @@ namespace svg
rendererSolid_t * m_renderArea;
agg::rasterizer_scanline_aa<> m_rasterizer; //!< AGG renderer system
agg::scanline_p8 m_scanLine; //!<
uint8_t* GetDataPointer(void) { return m_buffer; };
uint32_t GetDataSize(void) { return m_allocatedSize; };
};
};

View File

@ -47,11 +47,11 @@
#include <agg-2.4/agg_color_rgba.h>
#include <agg-2.4/agg_pixfmt_rgba.h>
svg::Parser::Parser(etk::File fileName)
svg::Parser::Parser(etk::File fileName) : m_renderedElement(NULL)
{
m_fileName = fileName;
m_version = "0.0";
m_loadOK = false;
m_loadOK = true;
m_paint.fill.red = 0xFF;
m_paint.fill.green = 0;
m_paint.fill.blue = 0;
@ -78,21 +78,25 @@ svg::Parser::Parser(etk::File fileName)
TiXmlDocument XmlDocument;
if (false == m_fileName.Exist()) {
SVG_ERROR("File Does not exist : " << m_fileName);
m_loadOK = false;
return;
}
int32_t fileSize = m_fileName.Size();
if (0==fileSize) {
SVG_ERROR("This file is empty : " << m_fileName);
m_loadOK = false;
return;
}
if (false == m_fileName.fOpenRead()) {
SVG_ERROR("Can not open the file : " << m_fileName);
m_loadOK = false;
return;
}
// allocate data
char * fileBuffer = new char[fileSize+5];
if (NULL == fileBuffer) {
SVG_ERROR("Error Memory allocation size=" << fileSize);
m_loadOK = false;
return;
}
memset(fileBuffer, 0, (fileSize+5)*sizeof(char));
@ -106,6 +110,7 @@ svg::Parser::Parser(etk::File fileName)
TiXmlElement* root = XmlDocument.FirstChildElement( "svg" );
if (NULL == root ) {
SVG_ERROR("(l ?) main node not find: \"svg\" in \"" << m_fileName << "\"");
m_loadOK = false;
} else {
// get the svg version :
const char *version = root->ToElement()->Attribute("version");
@ -197,7 +202,10 @@ svg::Parser::Parser(etk::File fileName)
svg::Parser::~Parser(void)
{
if(NULL != m_renderedElement) {
delete(m_renderedElement);
m_renderedElement = NULL;
}
}
@ -225,7 +233,6 @@ void svg::Parser::AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTra
void svg::Parser::GenerateTestFile(void)
{
float coefmult = 2;
int32_t SizeX = m_size.x;
if (SizeX == 0) {
SizeX = 50;
@ -234,7 +241,11 @@ void svg::Parser::GenerateTestFile(void)
if (SizeY == 0) {
SizeY = 50;
}
svg::Renderer * myRenderer = new svg::Renderer(SizeX, SizeY);
if(NULL != m_renderedElement) {
delete(m_renderedElement);
m_renderedElement = NULL;
}
m_renderedElement = new svg::Renderer(SizeX, SizeY);
// create the first element matrix modification ...
agg::trans_affine basicTrans;
//basicTrans *= agg::trans_affine_translation(-g_base_dx, -g_base_dy);
@ -245,13 +256,62 @@ void svg::Parser::GenerateTestFile(void)
//basicTrans *= agg::trans_affine_translation(width/3, height/3);
AggDraw(*myRenderer, basicTrans);
AggDraw(*m_renderedElement, basicTrans);
etk::UString tmpFileOut = "yyy_out_";
tmpFileOut += m_fileName.GetShortFilename();
tmpFileOut += ".ppm";
myRenderer->WritePpm(tmpFileOut);
m_renderedElement->WritePpm(tmpFileOut);
}
void svg::Parser::GenerateAnImage(int32_t sizeX, int32_t sizeY)
{
int32_t SizeX = sizeX;
if (SizeX == 0) {
SizeX = 50;
}
int32_t SizeY = sizeY;
if (SizeY == 0) {
SizeY = 50;
}
if(NULL != m_renderedElement) {
delete(m_renderedElement);
m_renderedElement = NULL;
}
m_renderedElement = new svg::Renderer(SizeX, SizeY);
// create the first element matrix modification ...
agg::trans_affine basicTrans;
//basicTrans *= agg::trans_affine_translation(-g_base_dx, -g_base_dy);
basicTrans *= agg::trans_affine_scaling(SizeX/m_size.x, SizeY/m_size.y);
//basicTrans *= agg::trans_affine_rotation(g_angle);// + agg::pi);
//basicTrans *= agg::trans_affine_skewing(2.0, 5.0);
//basicTrans *= agg::trans_affine_translation(width*0.3, height/2);
//basicTrans *= agg::trans_affine_translation(width/3, height/3);
AggDraw(*m_renderedElement, basicTrans);
etk::UString tmpFileOut = "zzz_out_test.ppm";
m_renderedElement->WritePpm(tmpFileOut);
}
uint8_t* svg::Parser::GetPointerOnData(void)
{
if(NULL == m_renderedElement) {
return NULL;
}
return m_renderedElement->GetDataPointer();
}
uint32_t svg::Parser::GetSizeOnData(void)
{
if(NULL == m_renderedElement) {
return 0;
}
return m_renderedElement->GetDataSize();
}

View File

@ -40,6 +40,7 @@ namespace svg
etk::UString m_title;
etk::VectorType<svg::Base *> m_subElementList;
coord2D_ts m_size;
svg::Renderer* m_renderedElement;
public:
Parser(etk::File fileName);
@ -47,7 +48,11 @@ namespace svg
bool IsLoadOk(void) { return m_loadOK; };
void DisplayDebug(void);
void GenerateTestFile(void);
void GenerateAnImage(int32_t sizeX, int32_t sizeY);
virtual void AggDraw(svg::Renderer& myRenderer, agg::trans_affine& basicTrans);
uint8_t* GetPointerOnData(void);
uint32_t GetSizeOnData(void);
coord2D_ts GetDefinedSize(void) { return m_size;};
};
};