[DEBUG] correct save on bmp file (better select output format)
This commit is contained in:
parent
492e32b4b3
commit
3a0b25923a
@ -89,7 +89,7 @@ void egami::Image::configure(const ivec2& _size, enum colorType _type) {
|
||||
}
|
||||
}
|
||||
|
||||
enum egami::colorType egami::Image::getType() {
|
||||
enum egami::colorType egami::Image::getType() const {
|
||||
if (m_data == nullptr) {
|
||||
EGAMI_DEBUG("No internal data for image (nullptr)");
|
||||
return egami::colorType::undefined;
|
||||
|
@ -81,7 +81,7 @@ namespace egami {
|
||||
void configure(const ivec2& _size=ivec2(32,32),
|
||||
enum colorType _type=egami::colorType::RGBA8);
|
||||
void* getTextureDataPointer();
|
||||
enum colorType getType();
|
||||
enum colorType getType() const;
|
||||
bool exist() {
|
||||
return m_data != nullptr;
|
||||
}
|
||||
|
@ -58,12 +58,12 @@ bool egami::store(const egami::Image& _input, const std::string& _fileName) {
|
||||
// select the corect Loader :
|
||||
if (etk::end_with(tmpName, ".edf") == true) {
|
||||
if (egami::storeEDF(_fileName, _input) == false) {
|
||||
EGAMI_ERROR("Error to load EDF file '" << _fileName << "'");
|
||||
EGAMI_ERROR("Error to store EDF file '" << _fileName << "'");
|
||||
return false;
|
||||
}
|
||||
} else if (etk::end_with(tmpName, ".bmp") == true) {
|
||||
if (egami::storeBMP(_fileName, _input) == false) {
|
||||
EGAMI_ERROR("Error to load BMP file '" << _fileName << "'");
|
||||
EGAMI_ERROR("Error to store BMP file '" << _fileName << "'");
|
||||
return false;
|
||||
}
|
||||
} else if (etk::end_with(tmpName, ".svg") == true) {
|
||||
@ -73,7 +73,7 @@ bool egami::store(const egami::Image& _input, const std::string& _fileName) {
|
||||
EGAMI_ERROR("Can not store in PNG file '" << _fileName << "'");
|
||||
return false;
|
||||
} else {
|
||||
EGAMI_ERROR("Extention not managed '" << _fileName << "' Sopported extention : .bmp / .svg / .png");
|
||||
EGAMI_ERROR("Extention not managed '" << _fileName << "' Sopported extention: .edf / .bmp / .svg / .png");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -89,38 +89,35 @@ egami::Image egami::loadBMP(const std::string& _inputFile) {
|
||||
fileName.fileClose();
|
||||
return out;
|
||||
}
|
||||
m_width = m_InfoHeader.biWidth;
|
||||
m_height = m_InfoHeader.biHeight;
|
||||
if( m_InfoHeader.biBitCount == 16
|
||||
&& m_InfoHeader.biCompression == 0)
|
||||
{
|
||||
&& m_InfoHeader.biCompression == 0) {
|
||||
m_dataMode = BITS_16_X1R5G5B5;
|
||||
out.configure(ivec2(m_width,m_height), egami::colorType::RGB8);
|
||||
} else if( m_InfoHeader.biBitCount == 16
|
||||
&& m_InfoHeader.biCompression == 3)
|
||||
{
|
||||
&& m_InfoHeader.biCompression == 3) {
|
||||
m_dataMode = BITS_16_R5G6B5;
|
||||
out.configure(ivec2(m_width,m_height), egami::colorType::RGB8);
|
||||
} else if( m_InfoHeader.biBitCount == 24
|
||||
&& m_InfoHeader.biCompression == 0)
|
||||
{
|
||||
&& m_InfoHeader.biCompression == 0) {
|
||||
m_dataMode = BITS_24_R8G8B8;
|
||||
out.configure(ivec2(m_width,m_height), egami::colorType::RGB8);
|
||||
} else if( m_InfoHeader.biBitCount == 32
|
||||
&& m_InfoHeader.biCompression == 3)
|
||||
{
|
||||
&& m_InfoHeader.biCompression == 3) {
|
||||
m_dataMode = BITS_32_X8R8G8B8;
|
||||
out.configure(ivec2(m_width,m_height), egami::colorType::RGB8);
|
||||
} else if( m_InfoHeader.biBitCount == 32
|
||||
&& m_InfoHeader.biCompression == 0)
|
||||
{
|
||||
&& m_InfoHeader.biCompression == 0) {
|
||||
m_dataMode = BITS_32_A8R8G8B8;
|
||||
out.configure(ivec2(m_width,m_height), egami::colorType::RGBA8);
|
||||
} else {
|
||||
EGAMI_ERROR("the biBitCount & biCompression fealds are unknow == > not supported format ...");
|
||||
fileName.fileClose();;
|
||||
return out;
|
||||
}
|
||||
m_width = m_InfoHeader.biWidth;
|
||||
m_height = m_InfoHeader.biHeight;
|
||||
// reallocate the image
|
||||
out.configure(ivec2(m_width,m_height), egami::colorType::RGBA8);
|
||||
|
||||
std::vector<uint8_t> m_data;
|
||||
if(0 != m_InfoHeader.biSizeImage) {
|
||||
if(m_InfoHeader.biSizeImage != 0) {
|
||||
m_data.resize(m_InfoHeader.biSizeImage, 0);
|
||||
if (fileName.fileRead(&m_data[0],m_InfoHeader.biSizeImage,1) != 1){
|
||||
EGAMI_CRITICAL("Can not read the file with the good size...");
|
||||
@ -220,9 +217,15 @@ bool egami::storeBMP(const std::string& _fileName, const egami::Image& _inputIma
|
||||
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;
|
||||
if (_inputImage.getType() == egami::colorType::RGBA8) {
|
||||
m_InfoHeader.biBitCount = 32;
|
||||
m_InfoHeader.biCompression = 0;
|
||||
m_InfoHeader.biSizeImage = _inputImage.getSize().x()*_inputImage.getSize().y()*4;
|
||||
} else {
|
||||
m_InfoHeader.biBitCount = 24;
|
||||
m_InfoHeader.biCompression = 0;
|
||||
m_InfoHeader.biSizeImage = _inputImage.getSize().x()*_inputImage.getSize().y()*3;
|
||||
}
|
||||
m_InfoHeader.biXPelsPerMeter = 75;
|
||||
m_InfoHeader.biYPelsPerMeter = 75;
|
||||
m_InfoHeader.biClrUsed = 0;
|
||||
@ -251,16 +254,30 @@ bool egami::storeBMP(const std::string& _fileName, const egami::Image& _inputIma
|
||||
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);
|
||||
if (_inputImage.getType() == egami::colorType::RGBA8) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
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();
|
||||
fileName.fileWrite(data,3,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
fileName.fileClose();
|
||||
|
Loading…
x
Reference in New Issue
Block a user