[DEV] add store image in a bmp file

This commit is contained in:
Edouard DUPIN 2013-09-30 00:04:06 +02:00
parent 92aee6787a
commit 4f2f17a043
6 changed files with 131 additions and 4 deletions

View File

@ -27,21 +27,43 @@ bool egami::Load(egami::Image& _output, const etk::UString& _fileName, const ive
// select the corect Loader :
if (true == tmpName.EndWith(".bmp") ) {
if (false == egami::LoadBMP(_fileName, _output)) {
EGAMI_ERROR("Error To load BMP file " << tmpName );
EGAMI_ERROR("Error To load BMP file '" << _fileName << "'");
return false;
}
} else if (true == tmpName.EndWith(".svg") ) {
if (false == egami::LoadSVG(_fileName, _output, _size)) {
EGAMI_ERROR("Error To load SVG file " << tmpName );
EGAMI_ERROR("Error To load SVG file '" << _fileName << "'");
return false;
}
} else if (true == tmpName.EndWith(".png") ) {
if (false == egami::LoadPNG(_fileName, _output)) {
EGAMI_ERROR("Error To load PNG file " << tmpName );
EGAMI_ERROR("Error To load PNG file '" << _fileName << "'");
return false;
}
} else {
EGAMI_ERROR("Extention not managed " << tmpName << " Sopported extention : .bmp / .svg / .png");
EGAMI_ERROR("Extention not managed '" << _fileName << "' Sopported extention : .bmp / .svg / .png");
return false;
}
return true;
}
bool egami::Store(const egami::Image& _input, const etk::UString& _fileName)
{
etk::UString tmpName = _fileName.ToLower();
// select the corect Loader :
if (true == tmpName.EndWith(".bmp") ) {
if (false == egami::StoreBMP(_fileName, _input)) {
EGAMI_ERROR("Error To load BMP file '" << _fileName << "'");
return false;
}
} else if (true == tmpName.EndWith(".svg") ) {
EGAMI_ERROR("Can not store in SVG file '" << _fileName << "'");
return false;
} else if (true == tmpName.EndWith(".png") ) {
EGAMI_ERROR("Can not store in PNG file '" << _fileName << "'");
return false;
} else {
EGAMI_ERROR("Extention not managed '" << _fileName << "' Sopported extention : .bmp / .svg / .png");
return false;
}
return true;

View File

@ -17,7 +17,26 @@
namespace egami
{
/**
* @brief Load a specific ilage file in the requested image data.
* @param[out] _output Data of the image.
* @param[in] _fileName Name of the file (SVG, BMP, PNG).
* @param[in] _size Dimention of the file when resizable (SVG).
* @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) );
/**
* @brief Save an image in a file.
* @param[in] _input Data of the image.
* @param[in] _fileName Name of the file.
* @return true if the file is corectly Stored, false otherwise
*/
bool Store(const egami::Image& _input, const etk::UString& _fileName);
/**
* @brief know if a file can have multiple size definition.
* @param[in] _fileName Name of the file.
* @return true if the format is scalable.
*/
bool Scalable(const etk::UString& _fileName);
};

View File

@ -226,6 +226,66 @@ bool egami::LoadBMP(const etk::UString& _inputFile, egami::Image& _ouputImage)
}
return true;
}
bool egami::StoreBMP(const etk::UString& _fileName, const egami::Image& _inputImage)
{
bitmapFileHeader_ts m_FileHeader;
bitmapInfoHeader_ts m_InfoHeader;
m_FileHeader.bfType = 0x4D42;
m_FileHeader.bfSize = sizeof(bitmapFileHeader_ts);
m_FileHeader.bfReserved = 0;
m_FileHeader.bfOffBits = 40;
m_InfoHeader.biSize = sizeof(bitmapInfoHeader_ts);
m_InfoHeader.biWidth = _inputImage.GetSize().x();
m_InfoHeader.biHeight = _inputImage.GetSize().y();
m_InfoHeader.biPlanes = 1;
m_InfoHeader.biBitCount = 32;
m_InfoHeader.biCompression = 0;
m_InfoHeader.biSizeImage = _inputImage.GetSize().x()*_inputImage.GetSize().y()*4;
m_InfoHeader.biXPelsPerMeter = 75;
m_InfoHeader.biYPelsPerMeter = 75;
m_InfoHeader.biClrUsed = 0;
m_InfoHeader.biClrImportant = 0;
etk::FSNode fileName(_fileName);
if(false == fileName.FileOpenWrite() ) {
EGAMI_ERROR("Can not find the file name=\"" << fileName << "\"");
return false;
}
// get the data :
if (fileName.FileWrite(&m_FileHeader,sizeof(bitmapFileHeader_ts),1) != 1) {
EGAMI_ERROR("error loading file header");
fileName.FileClose();
return false;
}
if (fileName.FileWrite(&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;
}
uint8_t data[16];
for(int32_t yyy=0; yyy<_inputImage.GetSize().y(); yyy++) {
for(int32_t xxx=0; xxx<_inputImage.GetSize().x(); xxx++) {
const etk::Color<>& tmpColor = _inputImage.Get(ivec2(xxx,yyy));
uint8_t* pointer = data;
*pointer++ = tmpColor.r();
*pointer++ = tmpColor.g();
*pointer++ = tmpColor.b();
*pointer++ = tmpColor.a();
fileName.FileWrite(data,4,1);
}
}
fileName.FileClose();
return true;
}
/*
void ewol::texture::TextureBMP::Display(void)
{

View File

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

View File

@ -13,6 +13,12 @@
namespace egami
{
/**
* @breif Load a png file in the image.
* @param[in] _fileName Name of the file.
* @param[out] _ouputImage Read data.
* @return true if all is done correctly, false otherwise.
*/
bool LoadPNG(const etk::UString& _fileName, egami::Image& _ouputImage);
};

View File

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