[DEV] end rework API
This commit is contained in:
parent
0afda0e999
commit
4475968d31
@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
std::ostream& egami::operator <<(std::ostream& _os, const enum egami::colorType _type) {
|
std::ostream& egami::operator <<(std::ostream& _os, const enum egami::colorType _type) {
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
|
case egami::colorType::undefined:
|
||||||
|
_os << "egami::colorType::undefined";
|
||||||
|
break;
|
||||||
case egami::colorType::RGBA8:
|
case egami::colorType::RGBA8:
|
||||||
_os << "egami::colorType::RGBA8";
|
_os << "egami::colorType::RGBA8";
|
||||||
break;
|
break;
|
||||||
@ -39,6 +42,10 @@ std::ostream& egami::operator <<(std::ostream& _os, const enum egami::colorType
|
|||||||
return _os;
|
return _os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
egami::Image::Image() :
|
||||||
|
m_data(nullptr) {
|
||||||
|
EGAMI_WARNING("Chek this code, the caller can not use it corectly ... (NEW API)");
|
||||||
|
}
|
||||||
|
|
||||||
egami::Image::Image(const ivec2& _size, enum colorType _type) :
|
egami::Image::Image(const ivec2& _size, enum colorType _type) :
|
||||||
m_data(nullptr) {
|
m_data(nullptr) {
|
||||||
@ -47,6 +54,9 @@ egami::Image::Image(const ivec2& _size, enum colorType _type) :
|
|||||||
|
|
||||||
void egami::Image::configure(const ivec2& _size, enum colorType _type) {
|
void egami::Image::configure(const ivec2& _size, enum colorType _type) {
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
|
case egami::colorType::undefined:
|
||||||
|
m_data = nullptr;
|
||||||
|
break;
|
||||||
case egami::colorType::RGBA8:
|
case egami::colorType::RGBA8:
|
||||||
//m_data = std::make_shared<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint8_t>>(_size));
|
//m_data = std::make_shared<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint8_t>>(_size));
|
||||||
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint8_t>>(_size));
|
m_data = std::shared_ptr<egami::ImagePrivate>(new egami::ImageTemplate<etk::Color<uint8_t>>(_size));
|
||||||
@ -78,7 +88,7 @@ void egami::Image::configure(const ivec2& _size, enum colorType _type) {
|
|||||||
enum egami::colorType egami::Image::getType() {
|
enum egami::colorType egami::Image::getType() {
|
||||||
if (m_data == nullptr) {
|
if (m_data == nullptr) {
|
||||||
EGAMI_WARNING("No internal data for image (nullptr)");
|
EGAMI_WARNING("No internal data for image (nullptr)");
|
||||||
return egami::colorType::RGBA8;
|
return egami::colorType::undefined;
|
||||||
}
|
}
|
||||||
return m_data->getType();
|
return m_data->getType();
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
namespace egami {
|
namespace egami {
|
||||||
enum class colorType {
|
enum class colorType {
|
||||||
|
undefined,
|
||||||
RGBA8,
|
RGBA8,
|
||||||
RGB8,
|
RGB8,
|
||||||
RGBAf,
|
RGBAf,
|
||||||
@ -28,16 +29,25 @@ namespace egami {
|
|||||||
class ImagePrivate;
|
class ImagePrivate;
|
||||||
class Image {
|
class Image {
|
||||||
private:
|
private:
|
||||||
|
// TODO : Change this in a unique_ptr ...
|
||||||
std::shared_ptr<ImagePrivate> m_data; //!< data of the image
|
std::shared_ptr<ImagePrivate> m_data; //!< data of the image
|
||||||
public:
|
public:
|
||||||
// constructor :
|
/**
|
||||||
Image(const ivec2& _size=ivec2(32,32), enum colorType _type=egami::colorType::RGBA8);
|
* @brief contructor that create an empty image (no valid data)
|
||||||
// destructor
|
* @note use @ref configure to set a correct image
|
||||||
~Image() { };
|
*/
|
||||||
|
Image();
|
||||||
|
Image(const ivec2& _size,
|
||||||
|
enum colorType _type = egami::colorType::undefined);
|
||||||
|
// TODO : IMplement move operator ... and copy operator...
|
||||||
public:
|
public:
|
||||||
void configure(const ivec2& _size=ivec2(32,32), enum colorType _type=egami::colorType::RGBA8);
|
void configure(const ivec2& _size=ivec2(32,32),
|
||||||
|
enum colorType _type=egami::colorType::RGBA8);
|
||||||
void* getTextureDataPointer();
|
void* getTextureDataPointer();
|
||||||
enum colorType getType();
|
enum colorType getType();
|
||||||
|
bool exist() {
|
||||||
|
return m_data != nullptr;
|
||||||
|
}
|
||||||
// -----------------------------------------------
|
// -----------------------------------------------
|
||||||
// -- basic tools :
|
// -- basic tools :
|
||||||
// -----------------------------------------------
|
// -----------------------------------------------
|
||||||
|
@ -14,42 +14,42 @@
|
|||||||
#include <edtaa3/edtaa3func.h>
|
#include <edtaa3/edtaa3func.h>
|
||||||
|
|
||||||
bool egami::scalable(const std::string& _fileName) {
|
bool egami::scalable(const std::string& _fileName) {
|
||||||
if (true == etk::end_with(_fileName, ".svg") ) {
|
if (true == etk::end_with(_fileName, ".svg") ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool egami::load(egami::Image& _output, const std::string& _fileName, const ivec2& _size) {
|
egami::Image egami::load(const std::string& _fileName, const ivec2& _size) {
|
||||||
std::string tmpName = etk::tolower(_fileName);
|
std::string tmpName = etk::tolower(_fileName);
|
||||||
|
egami::Image out;
|
||||||
// select the corect Loader :
|
// select the corect Loader :
|
||||||
if (etk::end_with(tmpName, ".edf") == true) {
|
if (etk::end_with(tmpName, ".edf") == true) {
|
||||||
// internal format for ewol distance field ==> simple sistance field image
|
// internal format for ewol distance field ==> simple sistance field image
|
||||||
if (egami::loadEDF(_fileName, _output) == false) {
|
out = egami::loadEDF(_fileName);
|
||||||
|
if (out.exist() == false) {
|
||||||
EGAMI_ERROR("Error to load EDF file '" << _fileName << "'");
|
EGAMI_ERROR("Error to load EDF file '" << _fileName << "'");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else if (etk::end_with(tmpName, ".bmp") == true) {
|
} else if (etk::end_with(tmpName, ".bmp") == true) {
|
||||||
if (egami::loadBMP(_fileName, _output) == false) {
|
out = egami::loadBMP(_fileName);
|
||||||
|
if (out.exist() == false) {
|
||||||
EGAMI_ERROR("Error to load BMP file '" << _fileName << "'");
|
EGAMI_ERROR("Error to load BMP file '" << _fileName << "'");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else if (etk::end_with(tmpName, ".svg") == true) {
|
} else if (etk::end_with(tmpName, ".svg") == true) {
|
||||||
if (egami::loadSVG(_fileName, _output, _size) == false) {
|
out = egami::loadSVG(_fileName, _size);
|
||||||
|
if (out.exist() == false) {
|
||||||
EGAMI_ERROR("Error to load SVG file '" << _fileName << "'");
|
EGAMI_ERROR("Error to load SVG file '" << _fileName << "'");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
//egami::storeEDF(_fileName + ".edf", _output);
|
//egami::storeEDF(_fileName + ".edf", _output);
|
||||||
} else if (etk::end_with(tmpName, ".png") == true) {
|
} else if (etk::end_with(tmpName, ".png") == true) {
|
||||||
if (egami::loadPNG(_fileName, _output) == false) {
|
out = egami::loadPNG(_fileName);
|
||||||
|
if (out.exist() == false) {
|
||||||
EGAMI_ERROR("Error to load PNG file '" << _fileName << "'");
|
EGAMI_ERROR("Error to load PNG file '" << _fileName << "'");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
EGAMI_ERROR("Extention not managed '" << _fileName << "' Sopported extention : .edf / .bmp / .svg / .png");
|
EGAMI_ERROR("Extention not managed '" << _fileName << "' Sopported extention : .edf / .bmp / .svg / .png");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool egami::store(const egami::Image& _input, const std::string& _fileName) {
|
bool egami::store(const egami::Image& _input, const std::string& _fileName) {
|
||||||
@ -169,7 +169,8 @@ bool egami::generateDistanceFieldFile(const std::string& _input, const std::stri
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EGAMI_ERROR("Generate distance field : '" << _input << "' ==> '" << _output << "'");
|
EGAMI_ERROR("Generate distance field : '" << _input << "' ==> '" << _output << "'");
|
||||||
if (egami::load(data, _input, ivec2(64*5,64*5)) == false) {
|
data = egami::load(_input, ivec2(64*5,64*5));
|
||||||
|
if (data.exist() == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Generate distance field :
|
// Generate distance field :
|
||||||
|
@ -15,12 +15,10 @@
|
|||||||
namespace egami {
|
namespace egami {
|
||||||
/**
|
/**
|
||||||
* @brief Load a specific ilage file in the requested image data.
|
* @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] _fileName Name of the file (SVG, BMP, PNG).
|
||||||
* @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.
|
|
||||||
*/
|
*/
|
||||||
bool load(egami::Image& _output, const std::string& _fileName, const ivec2& _size=ivec2(-1,-1) );
|
egami::Image load(const std::string& _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.
|
||||||
|
@ -40,7 +40,8 @@ enum modeBitmap {
|
|||||||
BITS_32_A8R8G8B8
|
BITS_32_A8R8G8B8
|
||||||
};
|
};
|
||||||
|
|
||||||
bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
|
egami::Image egami::loadBMP(const std::string& _inputFile) {
|
||||||
|
egami::Image out;
|
||||||
enum modeBitmap m_dataMode = BITS_16_R5G6B5;
|
enum modeBitmap 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;
|
||||||
@ -55,38 +56,38 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
}*/
|
}*/
|
||||||
if (fileName.exist() == false) {
|
if (fileName.exist() == false) {
|
||||||
EGAMI_ERROR("File does not existed=\"" << fileName << "\"");
|
EGAMI_ERROR("File does not existed=\"" << fileName << "\"");
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
if(fileName.fileOpenRead() ==false) {
|
if(fileName.fileOpenRead() ==false) {
|
||||||
EGAMI_ERROR("Can not find the file name=\"" << fileName << "\"");
|
EGAMI_ERROR("Can not find the file name=\"" << fileName << "\"");
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
// get the data :
|
// get the data :
|
||||||
if (fileName.fileRead(&m_FileHeader,sizeof(struct bitmapFileHeader),1) != 1) {
|
if (fileName.fileRead(&m_FileHeader,sizeof(struct bitmapFileHeader),1) != 1) {
|
||||||
EGAMI_ERROR("error loading file header");
|
EGAMI_ERROR("error loading file header");
|
||||||
fileName.fileClose();
|
fileName.fileClose();
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
if (fileName.fileRead(&m_InfoHeader,sizeof(struct bitmapInfoHeader),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 out;
|
||||||
}
|
}
|
||||||
if(fileName.fileSeek(m_FileHeader.bfOffBits, etk::seekNode_start) == false) {
|
if(fileName.fileSeek(m_FileHeader.bfOffBits, etk::seekNode_start) == false) {
|
||||||
EGAMI_ERROR("error with the 'bfOffBits' in the file named=\"" << fileName << "\"");
|
EGAMI_ERROR("error with the 'bfOffBits' in the file named=\"" << fileName << "\"");
|
||||||
fileName.fileClose();
|
fileName.fileClose();
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
// check the header error :
|
// check the header error :
|
||||||
if (m_FileHeader.bfType != 0x4D42) {
|
if (m_FileHeader.bfType != 0x4D42) {
|
||||||
EGAMI_ERROR("the file=\"" << fileName << "\" is not a bitmap file ...");
|
EGAMI_ERROR("the file=\"" << fileName << "\" is not a bitmap file ...");
|
||||||
fileName.fileClose();
|
fileName.fileClose();
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
if (m_FileHeader.bfReserved != 0x00000000) {
|
if (m_FileHeader.bfReserved != 0x00000000) {
|
||||||
EGAMI_ERROR("the bfReserved feald is not at 0 == > not supported format ...");
|
EGAMI_ERROR("the bfReserved feald is not at 0 == > not supported format ...");
|
||||||
fileName.fileClose();
|
fileName.fileClose();
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
if( m_InfoHeader.biBitCount == 16
|
if( m_InfoHeader.biBitCount == 16
|
||||||
&& m_InfoHeader.biCompression == 0)
|
&& m_InfoHeader.biCompression == 0)
|
||||||
@ -111,12 +112,12 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
} else {
|
} else {
|
||||||
EGAMI_ERROR("the biBitCount & biCompression fealds are unknow == > not supported format ...");
|
EGAMI_ERROR("the biBitCount & biCompression fealds are unknow == > not supported format ...");
|
||||||
fileName.fileClose();;
|
fileName.fileClose();;
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
m_width = m_InfoHeader.biWidth;
|
m_width = m_InfoHeader.biWidth;
|
||||||
m_height = m_InfoHeader.biHeight;
|
m_height = m_InfoHeader.biHeight;
|
||||||
// reallocate the image
|
// reallocate the image
|
||||||
_ouputImage.resize(ivec2(m_width,m_height));
|
out.configure(ivec2(m_width,m_height), egami::colorType::RGBA8);
|
||||||
|
|
||||||
std::vector<uint8_t> m_data;
|
std::vector<uint8_t> m_data;
|
||||||
if(0 != m_InfoHeader.biSizeImage) {
|
if(0 != m_InfoHeader.biSizeImage) {
|
||||||
@ -139,7 +140,7 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
tmpColor.setG((uint8_t)((*pointer & 0x07E0) >> 3));
|
tmpColor.setG((uint8_t)((*pointer & 0x07E0) >> 3));
|
||||||
tmpColor.setB((uint8_t)(*pointer << 3));
|
tmpColor.setB((uint8_t)(*pointer << 3));
|
||||||
tmpColor.setA(0xFF);
|
tmpColor.setA(0xFF);
|
||||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
out.set(ivec2(xxx,yyy), tmpColor);
|
||||||
pointer++;
|
pointer++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,7 +154,7 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
tmpColor.setG((int8_t)((*pointer & 0x03E0) >> 2));
|
tmpColor.setG((int8_t)((*pointer & 0x03E0) >> 2));
|
||||||
tmpColor.setB((int8_t)(*pointer << 3));
|
tmpColor.setB((int8_t)(*pointer << 3));
|
||||||
tmpColor.setA(0xFF);
|
tmpColor.setA(0xFF);
|
||||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
out.set(ivec2(xxx,yyy), tmpColor);
|
||||||
pointer++;
|
pointer++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,7 +168,7 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
tmpColor.setG(*pointer++);
|
tmpColor.setG(*pointer++);
|
||||||
tmpColor.setB(*pointer++);
|
tmpColor.setB(*pointer++);
|
||||||
tmpColor.setA(0xFF);
|
tmpColor.setA(0xFF);
|
||||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
out.set(ivec2(xxx,yyy), tmpColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,7 +182,7 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
tmpColor.setG(*pointer++);
|
tmpColor.setG(*pointer++);
|
||||||
tmpColor.setB(*pointer++);
|
tmpColor.setB(*pointer++);
|
||||||
tmpColor.setA(0xFF);
|
tmpColor.setA(0xFF);
|
||||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
out.set(ivec2(xxx,yyy), tmpColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -194,7 +195,7 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
tmpColor.setG(*pointer++);
|
tmpColor.setG(*pointer++);
|
||||||
tmpColor.setB(*pointer++);
|
tmpColor.setB(*pointer++);
|
||||||
tmpColor.setA(*pointer++);
|
tmpColor.setA(*pointer++);
|
||||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
out.set(ivec2(xxx,yyy), tmpColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,7 +204,7 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
EGAMI_ERROR(" mode = ERROR");
|
EGAMI_ERROR(" mode = ERROR");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool egami::storeBMP(const std::string& _fileName, const egami::Image& _inputImage) {
|
bool egami::storeBMP(const std::string& _fileName, const egami::Image& _inputImage) {
|
||||||
|
@ -11,10 +11,9 @@ namespace egami {
|
|||||||
/**
|
/**
|
||||||
* @breif Load a bmp file in the image.
|
* @breif Load a bmp file in the image.
|
||||||
* @param[in] _fileName Name of the file.
|
* @param[in] _fileName Name of the file.
|
||||||
* @param[out] _ouputImage Read data.
|
* @return Generate image or empty image
|
||||||
* @return true if all is done correctly, false otherwise.
|
|
||||||
*/
|
*/
|
||||||
bool loadBMP(const std::string& _fileName, egami::Image& _ouputImage);
|
egami::Image loadBMP(const std::string& _fileName);
|
||||||
/**
|
/**
|
||||||
* @breif Store a bmp file in the image.
|
* @breif Store a bmp file in the image.
|
||||||
* @param[in] _fileName Name of the file.
|
* @param[in] _fileName Name of the file.
|
||||||
|
@ -13,23 +13,23 @@
|
|||||||
//EDF format is a simple format for image in text for distance field image (special case)
|
//EDF format is a simple format for image in text for distance field image (special case)
|
||||||
// it is composed of the fist line : description of type (starting with #EDF and some other information, the data start just after the first \n
|
// it is composed of the fist line : description of type (starting with #EDF and some other information, the data start just after the first \n
|
||||||
|
|
||||||
bool egami::loadEDF(const std::string& _inputFile, egami::Image& _ouputImage) {
|
egami::Image egami::loadEDF(const std::string& _inputFile) {
|
||||||
|
egami::Image out;
|
||||||
etk::FSNode file(_inputFile);
|
etk::FSNode file(_inputFile);
|
||||||
if (false == file.exist()) {
|
if (false == file.exist()) {
|
||||||
EGAMI_ERROR("File does not existed='" << file << "'");
|
EGAMI_ERROR("File does not existed='" << file << "'");
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
if(false == file.fileOpenRead() ) {
|
if(false == file.fileOpenRead() ) {
|
||||||
EGAMI_ERROR("Can not find the file name='" << file << "'");
|
EGAMI_ERROR("Can not find the file name='" << file << "'");
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
std::string line;
|
std::string line;
|
||||||
file.fileGets(line);
|
file.fileGets(line);
|
||||||
if (etk::start_with(line, "#edf", false) == false) {
|
if (etk::start_with(line, "#edf", false) == false) {
|
||||||
EGAMI_ERROR("This file seams not to be a EDF file ...");
|
EGAMI_ERROR("This file seams not to be a EDF file ...");
|
||||||
file.fileClose();
|
file.fileClose();
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
// count number of colomn max an number of line max:
|
// count number of colomn max an number of line max:
|
||||||
ivec2 size(0,0);
|
ivec2 size(0,0);
|
||||||
@ -53,7 +53,7 @@ bool egami::loadEDF(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
|
|
||||||
|
|
||||||
// resize output:
|
// resize output:
|
||||||
_ouputImage.resize(size);
|
out.configure(size, egami::colorType::RGB8); // TODO : Do it better
|
||||||
int32_t currentLineId = 0;
|
int32_t currentLineId = 0;
|
||||||
char tmp[3];
|
char tmp[3];
|
||||||
tmp[2] = '\0';
|
tmp[2] = '\0';
|
||||||
@ -66,7 +66,7 @@ bool egami::loadEDF(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
tmp[1] = line[xxx+1];
|
tmp[1] = line[xxx+1];
|
||||||
int32_t val = 0;
|
int32_t val = 0;
|
||||||
sscanf(tmp, "%x", &val);
|
sscanf(tmp, "%x", &val);
|
||||||
_ouputImage.set(ivec2(xxx/2, currentLineId), etk::Color<>((uint8_t)val, (uint8_t)val, (uint8_t)val, (uint8_t)val));
|
out.set(ivec2(xxx/2, currentLineId), etk::Color<>((uint8_t)val, (uint8_t)val, (uint8_t)val, (uint8_t)val));
|
||||||
}
|
}
|
||||||
++currentLineId;
|
++currentLineId;
|
||||||
}
|
}
|
||||||
@ -76,11 +76,11 @@ bool egami::loadEDF(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
tmp[1] = line[xxx+1];
|
tmp[1] = line[xxx+1];
|
||||||
int32_t val = 0;
|
int32_t val = 0;
|
||||||
sscanf(tmp, "%x", &val);
|
sscanf(tmp, "%x", &val);
|
||||||
_ouputImage.set(ivec2(xxx/2, currentLineId), etk::Color<>((uint8_t)val, (uint8_t)val, (uint8_t)val, (uint8_t)val));
|
out.set(ivec2(xxx/2, currentLineId), etk::Color<>((uint8_t)val, (uint8_t)val, (uint8_t)val, (uint8_t)val));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file.fileClose();
|
file.fileClose();
|
||||||
return true;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool egami::storeEDF(const std::string& _fileName, const egami::Image& _inputImage) {
|
bool egami::storeEDF(const std::string& _fileName, const egami::Image& _inputImage) {
|
||||||
|
@ -20,10 +20,9 @@ namespace egami {
|
|||||||
* *
|
* *
|
||||||
* [PRE]
|
* [PRE]
|
||||||
* @param[in] _fileName Name of the file.
|
* @param[in] _fileName Name of the file.
|
||||||
* @param[out] _ouputImage Read data.
|
* @return Read Image
|
||||||
* @return true if all is done correctly, false otherwise.
|
|
||||||
*/
|
*/
|
||||||
bool loadEDF(const std::string& _fileName, egami::Image& _ouputImage);
|
egami::Image loadEDF(const std::string& _fileName);
|
||||||
/**
|
/**
|
||||||
* @breif Store a edf file in the image.
|
* @breif Store a edf file in the image.
|
||||||
* @param[in] _fileName Name of the file.
|
* @param[in] _fileName Name of the file.
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// 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 (fileNode != nullptr) {
|
||||||
fileNode->fileRead(data, 1, length);
|
fileNode->fileRead(data, 1, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,15 +44,16 @@ void user_warning_fn(png_structp _pngPtr, png_const_charp _warningMsg) {
|
|||||||
EGAMI_WARNING("libpng warning: '" << _warningMsg << "'");
|
EGAMI_WARNING("libpng warning: '" << _warningMsg << "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
|
egami::Image egami::loadPNG(const std::string& _inputFile) {
|
||||||
|
egami::Image out;
|
||||||
etk::FSNode fileName(_inputFile);
|
etk::FSNode fileName(_inputFile);
|
||||||
if (fileName.exist() == false) {
|
if (fileName.exist() == false) {
|
||||||
EGAMI_ERROR("File does not existed='" << fileName << "'");
|
EGAMI_ERROR("File does not existed='" << fileName << "'");
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
if(fileName.fileOpenRead() == false) {
|
if(fileName.fileOpenRead() == false) {
|
||||||
EGAMI_ERROR("Can not find the file name='" << fileName << "'");
|
EGAMI_ERROR("Can not find the file name='" << fileName << "'");
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
unsigned char header[8];
|
unsigned char header[8];
|
||||||
png_infop info_ptr;
|
png_infop info_ptr;
|
||||||
@ -61,11 +62,11 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
if (fileName.fileRead(header,1,8) != 8) {
|
if (fileName.fileRead(header,1,8) != 8) {
|
||||||
EGAMI_ERROR("error loading file header");
|
EGAMI_ERROR("error loading file header");
|
||||||
fileName.fileClose();
|
fileName.fileClose();
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
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 out;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PNG read setup
|
// PNG read setup
|
||||||
@ -73,14 +74,14 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
if (png_ptr == nullptr) {
|
if (png_ptr == nullptr) {
|
||||||
EGAMI_ERROR("Can not Allocate PNG structure");
|
EGAMI_ERROR("Can not Allocate PNG structure");
|
||||||
fileName.fileClose();
|
fileName.fileClose();
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
info_ptr = png_create_info_struct(png_ptr);
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
if (info_ptr == nullptr) {
|
if (info_ptr == nullptr) {
|
||||||
EGAMI_ERROR("Can not Allocate PNG info structure");
|
EGAMI_ERROR("Can not Allocate PNG info structure");
|
||||||
png_destroy_read_struct(&png_ptr, nullptr, nullptr);
|
png_destroy_read_struct(&png_ptr, nullptr, nullptr);
|
||||||
fileName.fileClose();
|
fileName.fileClose();
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||||
@ -110,21 +111,21 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
int bit_depth = 0;
|
int bit_depth = 0;
|
||||||
int colorType = 0;
|
int colorType = 0;
|
||||||
int interlace_type = 0;
|
int interlace_type = 0;
|
||||||
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &colorType, &interlace_type, NULL, NULL);
|
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &colorType, &interlace_type, nullptr, nullptr);
|
||||||
// reallocate the image
|
// reallocate the image
|
||||||
EGAMI_VERBOSE("Load PNG image : (" << width << "," << height << ")" );
|
EGAMI_VERBOSE("Load PNG image : (" << width << "," << height << ")" );
|
||||||
switch (colorType) {
|
switch (colorType) {
|
||||||
case PNG_COLOR_TYPE_RGBA:
|
case PNG_COLOR_TYPE_RGBA:
|
||||||
_ouputImage.configure(ivec2(width,height), egami::colorType::RGBA8);
|
out.configure(ivec2(width,height), egami::colorType::RGBA8);
|
||||||
break;
|
break;
|
||||||
case PNG_COLOR_TYPE_RGB:
|
case PNG_COLOR_TYPE_RGB:
|
||||||
_ouputImage.configure(ivec2(width,height), egami::colorType::RGB8);
|
out.configure(ivec2(width,height), egami::colorType::RGB8);
|
||||||
break;
|
break;
|
||||||
case PNG_COLOR_TYPE_GRAY:
|
case PNG_COLOR_TYPE_GRAY:
|
||||||
_ouputImage.configure(ivec2(width,height), egami::colorType::RGB8);
|
out.configure(ivec2(width,height), egami::colorType::RGB8);
|
||||||
break;
|
break;
|
||||||
case PNG_COLOR_TYPE_GRAY_ALPHA:
|
case PNG_COLOR_TYPE_GRAY_ALPHA:
|
||||||
_ouputImage.configure(ivec2(width,height), egami::colorType::RGBA8);
|
out.configure(ivec2(width,height), egami::colorType::RGBA8);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -210,7 +211,7 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
|
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
|
||||||
png_byte* ptr = &(row[xxx*4]);
|
png_byte* ptr = &(row[xxx*4]);
|
||||||
tmpColor.set(ptr[0], ptr[1], ptr[2], ptr[3]);
|
tmpColor.set(ptr[0], ptr[1], ptr[2], ptr[3]);
|
||||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
out.set(ivec2(xxx,yyy), tmpColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -222,7 +223,7 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
|
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
|
||||||
png_byte* ptr = &(row[xxx*3]);
|
png_byte* ptr = &(row[xxx*3]);
|
||||||
tmpColor.set(ptr[0], ptr[1], ptr[2]);
|
tmpColor.set(ptr[0], ptr[1], ptr[2]);
|
||||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
out.set(ivec2(xxx,yyy), tmpColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -234,7 +235,7 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
|
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
|
||||||
png_byte* ptr = &(row[xxx]);
|
png_byte* ptr = &(row[xxx]);
|
||||||
tmpColor.set(ptr[0], ptr[0], ptr[0]);
|
tmpColor.set(ptr[0], ptr[0], ptr[0]);
|
||||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
out.set(ivec2(xxx,yyy), tmpColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -246,7 +247,7 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
|
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
|
||||||
png_byte* ptr = &(row[xxx*2]);
|
png_byte* ptr = &(row[xxx*2]);
|
||||||
tmpColor.set(ptr[0], ptr[0], ptr[0], ptr[1]);
|
tmpColor.set(ptr[0], ptr[0], ptr[0], ptr[1]);
|
||||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
out.set(ivec2(xxx,yyy), tmpColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -261,11 +262,11 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
|
|||||||
if ((png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA) != 0) {
|
if ((png_get_color_type(png_ptr, info_ptr) & PNG_COLOR_MASK_ALPHA) != 0) {
|
||||||
EGAMI_ERROR(" Alpha");
|
EGAMI_ERROR(" Alpha");
|
||||||
}
|
}
|
||||||
return false;
|
return egami::Image();
|
||||||
}
|
}
|
||||||
fileName.fileClose();
|
fileName.fileClose();
|
||||||
// Clean up after the read, and free any memory allocated - REQUIRED
|
// Clean up after the read, and free any memory allocated - REQUIRED
|
||||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
|
||||||
return true;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,9 +11,8 @@ namespace egami {
|
|||||||
/**
|
/**
|
||||||
* @breif Load a png file in the image.
|
* @breif Load a png file in the image.
|
||||||
* @param[in] _fileName Name of the file.
|
* @param[in] _fileName Name of the file.
|
||||||
* @param[out] _ouputImage Read data.
|
* @return Read Image.
|
||||||
* @return true if all is done correctly, false otherwise.
|
|
||||||
*/
|
*/
|
||||||
bool loadPNG(const std::string& _fileName, egami::Image& _ouputImage);
|
egami::Image loadPNG(const std::string& _fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,19 +12,20 @@
|
|||||||
#include <esvg/esvg.h>
|
#include <esvg/esvg.h>
|
||||||
|
|
||||||
|
|
||||||
bool egami::loadSVG(const std::string& _fileName, egami::Image& _ouputImage, const ivec2& _size) {
|
egami::Image egami::loadSVG(const std::string& _fileName, const ivec2& _size) {
|
||||||
|
egami::Image out;
|
||||||
esvg::Document svgDocument;
|
esvg::Document svgDocument;
|
||||||
if (svgDocument.load(_fileName) == false) {
|
if (svgDocument.load(_fileName) == false) {
|
||||||
EGAMI_ERROR("Error to load SVG file " << _fileName );
|
EGAMI_ERROR("Error to load SVG file " << _fileName );
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
ivec2 imageSize = _size;
|
ivec2 imageSize = _size;
|
||||||
#if 0
|
#if 0
|
||||||
std::vector<etk::Color<float,4>> svgImage = svgDocument.renderImageFloatRGBA(imageSize);
|
std::vector<etk::Color<float,4>> svgImage = svgDocument.renderImageFloatRGBA(imageSize);
|
||||||
_ouputImage.set(svgImage, imageSize);
|
out.set(svgImage, imageSize);
|
||||||
#else
|
#else
|
||||||
std::vector<etk::Color<uint8_t,4>> svgImage = svgDocument.renderImageU8RGBA(imageSize);
|
std::vector<etk::Color<uint8_t,4>> svgImage = svgDocument.renderImageU8RGBA(imageSize);
|
||||||
_ouputImage.set(svgImage, imageSize);
|
out.set(svgImage, imageSize);
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return out;
|
||||||
}
|
}
|
@ -9,12 +9,11 @@
|
|||||||
|
|
||||||
namespace egami {
|
namespace egami {
|
||||||
/**
|
/**
|
||||||
* @breif Load a svg file in the image.
|
* @brief Load a svg file in the image.
|
||||||
* @param[in] _fileName Name of the file.
|
* @param[in] _fileName Name of the file.
|
||||||
* @param[out] _ouputImage Read data.
|
|
||||||
* @param[in] _size size of the output image.
|
* @param[in] _size size of the output image.
|
||||||
* @return true if all is done correctly, false otherwise.
|
* @return Generated image
|
||||||
*/
|
*/
|
||||||
bool loadSVG(const std::string& _fileName, egami::Image& _ouputImage, const ivec2& _size=ivec2(-1,-1));
|
egami::Image loadSVG(const std::string& _fileName, const ivec2& _size=ivec2(-1,-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user