[DEV] code style de lundi

This commit is contained in:
Edouard DUPIN 2013-10-07 22:07:40 +02:00
parent 516808d6ac
commit 03aea20f51
6 changed files with 44 additions and 66 deletions

View File

@ -25,8 +25,7 @@ void egami::Image::resize(const ivec2& _size, const etk::Color<>& _color) {
m_data.reSize(m_size.x()*m_size.y(), _color); m_data.reSize(m_size.x()*m_size.y(), _color);
} }
void egami::Image::resize(const ivec2& _size, const ivec2& _startPos) void egami::Image::resize(const ivec2& _size, const ivec2& _startPos) {
{
if (_size == m_size) { if (_size == m_size) {
// same size == > nothing to do ... // same size == > nothing to do ...
return; return;

View File

@ -13,30 +13,28 @@
#include <egami/wrapperPNG.h> #include <egami/wrapperPNG.h>
#include <egami/wrapperBMP.h> #include <egami/wrapperBMP.h>
bool egami::Scalable(const etk::UString& _fileName) bool egami::scalable(const etk::UString& _fileName) {
{ if (true == _fileName.endWith(".svg") ) {
if (true == _fileName.EndWith(".svg") ) {
return true; return true;
} }
return false; return false;
} }
bool egami::Load(egami::Image& _output, const etk::UString& _fileName, const ivec2& _size) bool egami::load(egami::Image& _output, const etk::UString& _fileName, const ivec2& _size) {
{
etk::UString tmpName = _fileName.toLower(); etk::UString tmpName = _fileName.toLower();
// select the corect Loader : // select the corect Loader :
if (true == tmpName.EndWith(".bmp") ) { if (true == tmpName.endWith(".bmp") ) {
if (false == egami::LoadBMP(_fileName, _output)) { if (false == egami::loadBMP(_fileName, _output)) {
EGAMI_ERROR("Error to load BMP file '" << _fileName << "'"); EGAMI_ERROR("Error to load BMP file '" << _fileName << "'");
return false; return false;
} }
} else if (true == tmpName.EndWith(".svg") ) { } else if (true == tmpName.endWith(".svg") ) {
if (false == egami::LoadSVG(_fileName, _output, _size)) { if (false == egami::loadSVG(_fileName, _output, _size)) {
EGAMI_ERROR("Error to load SVG file '" << _fileName << "'"); EGAMI_ERROR("Error to load SVG file '" << _fileName << "'");
return false; return false;
} }
} else if (true == tmpName.EndWith(".png") ) { } else if (true == tmpName.endWith(".png") ) {
if (false == egami::LoadPNG(_fileName, _output)) { if (false == egami::loadPNG(_fileName, _output)) {
EGAMI_ERROR("Error to load PNG file '" << _fileName << "'"); EGAMI_ERROR("Error to load PNG file '" << _fileName << "'");
return false; return false;
} }
@ -47,19 +45,18 @@ bool egami::Load(egami::Image& _output, const etk::UString& _fileName, const ive
return true; return true;
} }
bool egami::Store(const egami::Image& _input, const etk::UString& _fileName) bool egami::store(const egami::Image& _input, const etk::UString& _fileName) {
{
etk::UString tmpName = _fileName.toLower(); etk::UString tmpName = _fileName.toLower();
// select the corect Loader : // select the corect Loader :
if (true == tmpName.EndWith(".bmp") ) { if (true == tmpName.endWith(".bmp") ) {
if (false == egami::StoreBMP(_fileName, _input)) { if (false == egami::storeBMP(_fileName, _input)) {
EGAMI_ERROR("Error to load BMP file '" << _fileName << "'"); EGAMI_ERROR("Error to load BMP file '" << _fileName << "'");
return false; return false;
} }
} else if (true == tmpName.EndWith(".svg") ) { } else if (true == tmpName.endWith(".svg") ) {
EGAMI_ERROR("Can not store in SVG file '" << _fileName << "'"); EGAMI_ERROR("Can not store in SVG file '" << _fileName << "'");
return false; return false;
} else if (true == tmpName.EndWith(".png") ) { } else if (true == tmpName.endWith(".png") ) {
EGAMI_ERROR("Can not store in PNG file '" << _fileName << "'"); EGAMI_ERROR("Can not store in PNG file '" << _fileName << "'");
return false; return false;
} else { } else {

View File

@ -24,20 +24,20 @@ namespace egami
* @param[in] _size Dimention of the file when resizable (SVG). * @param[in] _size Dimention of the file when resizable (SVG).
* @return true if the file is corectly loaded, false otherwise. * @return true if the file is corectly loaded, false otherwise.
*/ */
bool Load(egami::Image& _output, const etk::UString& _fileName, const ivec2& _size=ivec2(-1,-1) ); bool load(egami::Image& _output, const etk::UString& _fileName, const ivec2& _size=ivec2(-1,-1) );
/** /**
* @brief Save an image in a file. * @brief Save an image in a file.
* @param[in] _input Data of the image. * @param[in] _input Data of the image.
* @param[in] _fileName Name of the file. * @param[in] _fileName Name of the file.
* @return true if the file is corectly Stored, false otherwise * @return true if the file is corectly Stored, false otherwise
*/ */
bool Store(const egami::Image& _input, const etk::UString& _fileName); bool store(const egami::Image& _input, const etk::UString& _fileName);
/** /**
* @brief know if a file can have multiple size definition. * @brief know if a file can have multiple size definition.
* @param[in] _fileName Name of the file. * @param[in] _fileName Name of the file.
* @return true if the format is scalable. * @return true if the format is scalable.
*/ */
bool Scalable(const etk::UString& _fileName); bool scalable(const etk::UString& _fileName);
}; };
#endif #endif

View File

@ -19,7 +19,7 @@ extern "C" {
int32_t bfReserved; int32_t bfReserved;
int32_t bfOffBits; int32_t bfOffBits;
}; };
struct bitmapFileHeader { struct bitmapInfoHeader {
int32_t biSize; int32_t biSize;
int32_t biWidth; int32_t biWidth;
int32_t biHeight; int32_t biHeight;
@ -46,11 +46,11 @@ typedef enum {
#define __class__ "wrapperBMP" #define __class__ "wrapperBMP"
bool egami::loadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) { bool egami::loadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) {
modeBitmap_te m_dataMode = BITS_16_R5G6B5; modeBitmap_te m_dataMode = BITS_16_R5G6B5;
int32_t m_width = 0; int32_t m_width = 0;
int32_t m_height = 0; int32_t m_height = 0;
struct bitmapFileHeader m_FileHeader; struct bitmapFileHeader m_FileHeader;
struct bitmapFileHeader m_InfoHeader; struct bitmapInfoHeader m_InfoHeader;
etk::FSNode fileName(_inputFile); etk::FSNode fileName(_inputFile);
// get the fileSize ... // get the fileSize ...
@ -72,7 +72,7 @@ bool egami::loadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) {
fileName.fileClose(); fileName.fileClose();
return false; return false;
} }
if (fileName.fileRead(&m_InfoHeader,sizeof(struct bitmapFileHeader),1) != 1) { if (fileName.fileRead(&m_InfoHeader,sizeof(struct bitmapInfoHeader),1) != 1) {
EGAMI_ERROR("error loading file header"); EGAMI_ERROR("error loading file header");
fileName.fileClose(); fileName.fileClose();
return false; return false;
@ -124,8 +124,7 @@ bool egami::loadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) {
_ouputImage.resize(ivec2(m_width,m_height)); _ouputImage.resize(ivec2(m_width,m_height));
uint8_t* m_data = NULL; uint8_t* m_data = NULL;
if(0 != m_InfoHeader.biSizeImage) if(0 != m_InfoHeader.biSizeImage) {
{
m_data=new uint8_t[m_InfoHeader.biSizeImage]; m_data=new uint8_t[m_InfoHeader.biSizeImage];
if (fileName.fileRead(m_data,m_InfoHeader.biSizeImage,1) != 1){ if (fileName.fileRead(m_data,m_InfoHeader.biSizeImage,1) != 1){
EGAMI_CRITICAL("Can not read the file with the good size..."); EGAMI_CRITICAL("Can not read the file with the good size...");
@ -136,10 +135,8 @@ bool egami::loadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) {
etk::Color<> tmpColor(0,0,0,0); etk::Color<> tmpColor(0,0,0,0);
// need now to generate RGBA data ... // need now to generate RGBA data ...
switch(m_dataMode) switch(m_dataMode) {
{ case BITS_16_R5G6B5: {
case BITS_16_R5G6B5:
{
uint16_t * pointer = (uint16_t*)m_data; uint16_t * pointer = (uint16_t*)m_data;
for(int32_t yyy=0; yyy<m_height; yyy++) { for(int32_t yyy=0; yyy<m_height; yyy++) {
for(int32_t xxx=0; xxx<m_width; xxx++) { for(int32_t xxx=0; xxx<m_width; xxx++) {
@ -153,8 +150,7 @@ bool egami::loadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) {
} }
} }
break; break;
case BITS_16_X1R5G5B5: case BITS_16_X1R5G5B5: {
{
uint16_t * pointer = (uint16_t*)m_data; uint16_t * pointer = (uint16_t*)m_data;
for(int32_t yyy=0; yyy<m_height; yyy++) { for(int32_t yyy=0; yyy<m_height; yyy++) {
for(int32_t xxx=0; xxx<m_width; xxx++) { for(int32_t xxx=0; xxx<m_width; xxx++) {
@ -168,8 +164,7 @@ bool egami::loadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) {
} }
} }
break; break;
case BITS_24_R8G8B8: case BITS_24_R8G8B8: {
{
uint8_t * pointer = m_data; uint8_t * pointer = m_data;
for(int32_t yyy=0; yyy<m_height; yyy++) { for(int32_t yyy=0; yyy<m_height; yyy++) {
for(int32_t xxx=0; xxx<m_width; xxx++) { for(int32_t xxx=0; xxx<m_width; xxx++) {
@ -182,8 +177,7 @@ bool egami::loadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) {
} }
} }
break; break;
case BITS_32_X8R8G8B8: case BITS_32_X8R8G8B8: {
{
uint8_t * pointer = m_data; uint8_t * pointer = m_data;
for(int32_t yyy=0; yyy<m_height; yyy++) { for(int32_t yyy=0; yyy<m_height; yyy++) {
for(int32_t xxx=0; xxx<m_width; xxx++) { for(int32_t xxx=0; xxx<m_width; xxx++) {
@ -197,8 +191,7 @@ bool egami::loadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) {
} }
} }
break; break;
case BITS_32_A8R8G8B8: case BITS_32_A8R8G8B8: {
{
uint8_t * pointer = m_data; uint8_t * pointer = m_data;
for(int32_t yyy=0; yyy<m_height; yyy++) { for(int32_t yyy=0; yyy<m_height; yyy++) {
for(int32_t xxx=0; xxx<m_width; xxx++) { for(int32_t xxx=0; xxx<m_width; xxx++) {
@ -224,14 +217,14 @@ bool egami::loadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage) {
bool egami::storeBMP(const etk::UString& _fileName, const egami::Image& _inputImage) { bool egami::storeBMP(const etk::UString& _fileName, const egami::Image& _inputImage) {
struct bitmapFileHeader m_FileHeader; struct bitmapFileHeader m_FileHeader;
struct bitmapFileHeader m_InfoHeader; struct bitmapInfoHeader m_InfoHeader;
m_FileHeader.bfType = 0x4D42; m_FileHeader.bfType = 0x4D42;
m_FileHeader.bfSize = sizeof(struct bitmapFileHeader); m_FileHeader.bfSize = sizeof(struct bitmapFileHeader);
m_FileHeader.bfReserved = 0; m_FileHeader.bfReserved = 0;
m_FileHeader.bfOffBits = 40; m_FileHeader.bfOffBits = 40;
m_InfoHeader.biSize = sizeof(struct bitmapFileHeader); m_InfoHeader.biSize = sizeof(struct bitmapInfoHeader);
m_InfoHeader.biWidth = _inputImage.getSize().x(); m_InfoHeader.biWidth = _inputImage.getSize().x();
m_InfoHeader.biHeight = _inputImage.getSize().y(); m_InfoHeader.biHeight = _inputImage.getSize().y();
m_InfoHeader.biPlanes = 1; m_InfoHeader.biPlanes = 1;
@ -254,7 +247,7 @@ bool egami::storeBMP(const etk::UString& _fileName, const egami::Image& _inputIm
fileName.fileClose(); fileName.fileClose();
return false; return false;
} }
if (fileName.fileWrite(&m_InfoHeader,sizeof(struct bitmapFileHeader),1) != 1) { if (fileName.fileWrite(&m_InfoHeader,sizeof(struct bitmapInfoHeader),1) != 1) {
EGAMI_ERROR("error loading file header"); EGAMI_ERROR("error loading file header");
fileName.fileClose(); fileName.fileClose();
return false; return false;

View File

@ -18,8 +18,7 @@
#define __class__ "wrapperPNG" #define __class__ "wrapperPNG"
// we must change the access of the IO of the png lib : // 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) 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)); etk::FSNode* fileNode = static_cast<etk::FSNode*>(png_get_io_ptr(png_ptr));
if (NULL!=fileNode) { if (NULL!=fileNode) {
fileNode->fileRead(data, 1, length); fileNode->fileRead(data, 1, length);
@ -43,8 +42,7 @@ static void localFlushData(png_structp png_ptr)
} }
*/ */
bool egami::loadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage) bool egami::loadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage) {
{
etk::FSNode fileName(_inputFile); etk::FSNode fileName(_inputFile);
if (false == fileName.exist()) { if (false == fileName.exist()) {
@ -69,8 +67,7 @@ bool egami::loadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage)
fileName.fileClose(); fileName.fileClose();
return false; return false;
} }
if (png_sig_cmp(header, 0, 8)) if (png_sig_cmp(header, 0, 8)) {
{
EGAMI_ERROR("Invalid file :" << fileName); EGAMI_ERROR("Invalid file :" << fileName);
return false; return false;
} }
@ -108,8 +105,7 @@ bool egami::loadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage)
rowbytes = width * ((bit_depth == 16) ? 8 : 4); rowbytes = width * ((bit_depth == 16) ? 8 : 4);
// File read // File read
for (y = 0; y < height; y++) for (y = 0; y < height; y++) {
{
row_pointers[y] = (png_byte*) malloc(rowbytes); row_pointers[y] = (png_byte*) malloc(rowbytes);
} }
png_read_image(png_ptr, row_pointers); png_read_image(png_ptr, row_pointers);
@ -117,15 +113,12 @@ bool egami::loadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage)
png_set_strip_16(png_ptr); png_set_strip_16(png_ptr);
etk::Color<> tmpColor(0,0,0,0); etk::Color<> tmpColor(0,0,0,0);
switch (png_get_color_type(png_ptr, info_ptr) ) switch (png_get_color_type(png_ptr, info_ptr) ) {
{
case PNG_COLOR_TYPE_RGBA: case PNG_COLOR_TYPE_RGBA:
// Conversion to OpenGL texture // Conversion to OpenGL texture
for (y = 0; y < height; y++) for (y = 0; y < height; y++) {
{
png_byte* row = row_pointers[y]; png_byte* row = row_pointers[y];
for (x = 0; x < width; x++) for (x = 0; x < width; x++) {
{
png_byte* ptr = &(row[x*4]); png_byte* ptr = &(row[x*4]);
tmpColor.set(ptr[0], ptr[1],ptr[2],ptr[3]); tmpColor.set(ptr[0], ptr[1],ptr[2],ptr[3]);
_ouputImage.set(ivec2(x,y), tmpColor); _ouputImage.set(ivec2(x,y), tmpColor);
@ -135,11 +128,9 @@ bool egami::loadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage)
break; break;
case PNG_COLOR_TYPE_RGB: case PNG_COLOR_TYPE_RGB:
// Conversion to OpenGL texture // Conversion to OpenGL texture
for (y = 0; y < height; y++) for (y = 0; y < height; y++) {
{
png_byte* row = row_pointers[y]; png_byte* row = row_pointers[y];
for (x = 0; x < width; x++) for (x = 0; x < width; x++) {
{
png_byte* ptr = &(row[x*3]); png_byte* ptr = &(row[x*3]);
tmpColor.set(ptr[0], ptr[1],ptr[2]); tmpColor.set(ptr[0], ptr[1],ptr[2]);
_ouputImage.set(ivec2(x,y), tmpColor); _ouputImage.set(ivec2(x,y), tmpColor);
@ -151,7 +142,6 @@ bool egami::loadPNG(const etk::UString& _inputFile, egami::Image& _ouputImage)
EGAMI_ERROR("Must be RGBA/RGB"); EGAMI_ERROR("Must be RGBA/RGB");
return false; return false;
} }
fileName.fileClose(); fileName.fileClose();
return true; return true;
} }

View File

@ -18,8 +18,7 @@
#define __class__ "wrapperSVG" #define __class__ "wrapperSVG"
bool egami::loadSVG(const etk::UString& _fileName, egami::Image& _ouputImage, const ivec2& _size) bool egami::loadSVG(const etk::UString& _fileName, egami::Image& _ouputImage, const ivec2& _size) {
{
esvg::Document m_element(_fileName); esvg::Document m_element(_fileName);
if (false == m_element.isLoadOk()) { if (false == m_element.isLoadOk()) {
EGAMI_ERROR("Error to load SVG file " << _fileName ); EGAMI_ERROR("Error to load SVG file " << _fileName );