[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) {
|
||||
switch (_type) {
|
||||
case egami::colorType::undefined:
|
||||
_os << "egami::colorType::undefined";
|
||||
break;
|
||||
case egami::colorType::RGBA8:
|
||||
_os << "egami::colorType::RGBA8";
|
||||
break;
|
||||
@ -39,6 +42,10 @@ std::ostream& egami::operator <<(std::ostream& _os, const enum egami::colorType
|
||||
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) :
|
||||
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) {
|
||||
switch (_type) {
|
||||
case egami::colorType::undefined:
|
||||
m_data = nullptr;
|
||||
break;
|
||||
case egami::colorType::RGBA8:
|
||||
//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));
|
||||
@ -78,7 +88,7 @@ void egami::Image::configure(const ivec2& _size, enum colorType _type) {
|
||||
enum egami::colorType egami::Image::getType() {
|
||||
if (m_data == nullptr) {
|
||||
EGAMI_WARNING("No internal data for image (nullptr)");
|
||||
return egami::colorType::RGBA8;
|
||||
return egami::colorType::undefined;
|
||||
}
|
||||
return m_data->getType();
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
namespace egami {
|
||||
enum class colorType {
|
||||
undefined,
|
||||
RGBA8,
|
||||
RGB8,
|
||||
RGBAf,
|
||||
@ -28,16 +29,25 @@ namespace egami {
|
||||
class ImagePrivate;
|
||||
class Image {
|
||||
private:
|
||||
// TODO : Change this in a unique_ptr ...
|
||||
std::shared_ptr<ImagePrivate> m_data; //!< data of the image
|
||||
public:
|
||||
// constructor :
|
||||
Image(const ivec2& _size=ivec2(32,32), enum colorType _type=egami::colorType::RGBA8);
|
||||
// destructor
|
||||
~Image() { };
|
||||
/**
|
||||
* @brief contructor that create an empty image (no valid data)
|
||||
* @note use @ref configure to set a correct image
|
||||
*/
|
||||
Image();
|
||||
Image(const ivec2& _size,
|
||||
enum colorType _type = egami::colorType::undefined);
|
||||
// TODO : IMplement move operator ... and copy operator...
|
||||
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();
|
||||
enum colorType getType();
|
||||
bool exist() {
|
||||
return m_data != nullptr;
|
||||
}
|
||||
// -----------------------------------------------
|
||||
// -- basic tools :
|
||||
// -----------------------------------------------
|
||||
|
@ -14,42 +14,42 @@
|
||||
#include <edtaa3/edtaa3func.h>
|
||||
|
||||
bool egami::scalable(const std::string& _fileName) {
|
||||
if (true == etk::end_with(_fileName, ".svg") ) {
|
||||
if (true == etk::end_with(_fileName, ".svg") ) {
|
||||
return true;
|
||||
}
|
||||
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);
|
||||
egami::Image out;
|
||||
// select the corect Loader :
|
||||
if (etk::end_with(tmpName, ".edf") == true) {
|
||||
// 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 << "'");
|
||||
return false;
|
||||
}
|
||||
} 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 << "'");
|
||||
return false;
|
||||
}
|
||||
} 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 << "'");
|
||||
return false;
|
||||
}
|
||||
//egami::storeEDF(_fileName + ".edf", _output);
|
||||
} 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 << "'");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
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) {
|
||||
@ -169,7 +169,8 @@ bool egami::generateDistanceFieldFile(const std::string& _input, const std::stri
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
// Generate distance field :
|
||||
|
@ -15,12 +15,10 @@
|
||||
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 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.
|
||||
* @param[in] _input Data of the image.
|
||||
|
@ -40,7 +40,8 @@ enum modeBitmap {
|
||||
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;
|
||||
int32_t m_width = 0;
|
||||
int32_t m_height = 0;
|
||||
@ -55,38 +56,38 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
|
||||
}*/
|
||||
if (fileName.exist() == false) {
|
||||
EGAMI_ERROR("File does not existed=\"" << fileName << "\"");
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
if(fileName.fileOpenRead() ==false) {
|
||||
EGAMI_ERROR("Can not find the file name=\"" << fileName << "\"");
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
// get the data :
|
||||
if (fileName.fileRead(&m_FileHeader,sizeof(struct bitmapFileHeader),1) != 1) {
|
||||
EGAMI_ERROR("error loading file header");
|
||||
fileName.fileClose();
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
if (fileName.fileRead(&m_InfoHeader,sizeof(struct bitmapInfoHeader),1) != 1) {
|
||||
EGAMI_ERROR("error loading file header");
|
||||
fileName.fileClose();
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
if(fileName.fileSeek(m_FileHeader.bfOffBits, etk::seekNode_start) == false) {
|
||||
EGAMI_ERROR("error with the 'bfOffBits' in the file named=\"" << fileName << "\"");
|
||||
fileName.fileClose();
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
// check the header error :
|
||||
if (m_FileHeader.bfType != 0x4D42) {
|
||||
EGAMI_ERROR("the file=\"" << fileName << "\" is not a bitmap file ...");
|
||||
fileName.fileClose();
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
if (m_FileHeader.bfReserved != 0x00000000) {
|
||||
EGAMI_ERROR("the bfReserved feald is not at 0 == > not supported format ...");
|
||||
fileName.fileClose();
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
if( m_InfoHeader.biBitCount == 16
|
||||
&& m_InfoHeader.biCompression == 0)
|
||||
@ -111,12 +112,12 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
|
||||
} else {
|
||||
EGAMI_ERROR("the biBitCount & biCompression fealds are unknow == > not supported format ...");
|
||||
fileName.fileClose();;
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
m_width = m_InfoHeader.biWidth;
|
||||
m_height = m_InfoHeader.biHeight;
|
||||
// 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;
|
||||
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.setB((uint8_t)(*pointer << 3));
|
||||
tmpColor.setA(0xFF);
|
||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
||||
out.set(ivec2(xxx,yyy), tmpColor);
|
||||
pointer++;
|
||||
}
|
||||
}
|
||||
@ -153,7 +154,7 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
|
||||
tmpColor.setG((int8_t)((*pointer & 0x03E0) >> 2));
|
||||
tmpColor.setB((int8_t)(*pointer << 3));
|
||||
tmpColor.setA(0xFF);
|
||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
||||
out.set(ivec2(xxx,yyy), tmpColor);
|
||||
pointer++;
|
||||
}
|
||||
}
|
||||
@ -167,7 +168,7 @@ bool egami::loadBMP(const std::string& _inputFile, egami::Image& _ouputImage) {
|
||||
tmpColor.setG(*pointer++);
|
||||
tmpColor.setB(*pointer++);
|
||||
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.setB(*pointer++);
|
||||
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.setB(*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");
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
return out;
|
||||
}
|
||||
|
||||
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.
|
||||
* @param[in] _fileName Name of the file.
|
||||
* @param[out] _ouputImage Read data.
|
||||
* @return true if all is done correctly, false otherwise.
|
||||
* @return Generate image or empty image
|
||||
*/
|
||||
bool loadBMP(const std::string& _fileName, egami::Image& _ouputImage);
|
||||
egami::Image loadBMP(const std::string& _fileName);
|
||||
/**
|
||||
* @breif Store a bmp file in the image.
|
||||
* @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)
|
||||
// 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);
|
||||
if (false == file.exist()) {
|
||||
EGAMI_ERROR("File does not existed='" << file << "'");
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
if(false == file.fileOpenRead() ) {
|
||||
EGAMI_ERROR("Can not find the file name='" << file << "'");
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
std::string line;
|
||||
file.fileGets(line);
|
||||
if (etk::start_with(line, "#edf", false) == false) {
|
||||
EGAMI_ERROR("This file seams not to be a EDF file ...");
|
||||
file.fileClose();
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
// count number of colomn max an number of line max:
|
||||
ivec2 size(0,0);
|
||||
@ -53,7 +53,7 @@ bool egami::loadEDF(const std::string& _inputFile, egami::Image& _ouputImage) {
|
||||
|
||||
|
||||
// resize output:
|
||||
_ouputImage.resize(size);
|
||||
out.configure(size, egami::colorType::RGB8); // TODO : Do it better
|
||||
int32_t currentLineId = 0;
|
||||
char tmp[3];
|
||||
tmp[2] = '\0';
|
||||
@ -66,7 +66,7 @@ bool egami::loadEDF(const std::string& _inputFile, egami::Image& _ouputImage) {
|
||||
tmp[1] = line[xxx+1];
|
||||
int32_t val = 0;
|
||||
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;
|
||||
}
|
||||
@ -76,11 +76,11 @@ bool egami::loadEDF(const std::string& _inputFile, egami::Image& _ouputImage) {
|
||||
tmp[1] = line[xxx+1];
|
||||
int32_t val = 0;
|
||||
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();
|
||||
return true;
|
||||
return out;
|
||||
}
|
||||
|
||||
bool egami::storeEDF(const std::string& _fileName, const egami::Image& _inputImage) {
|
||||
|
@ -20,10 +20,9 @@ namespace egami {
|
||||
* *
|
||||
* [PRE]
|
||||
* @param[in] _fileName Name of the file.
|
||||
* @param[out] _ouputImage Read data.
|
||||
* @return true if all is done correctly, false otherwise.
|
||||
* @return Read Image
|
||||
*/
|
||||
bool loadEDF(const std::string& _fileName, egami::Image& _ouputImage);
|
||||
egami::Image loadEDF(const std::string& _fileName);
|
||||
/**
|
||||
* @breif Store a edf file in the image.
|
||||
* @param[in] _fileName Name of the file.
|
||||
|
@ -14,7 +14,7 @@
|
||||
// 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) {
|
||||
etk::FSNode* fileNode = static_cast<etk::FSNode*>(png_get_io_ptr(png_ptr));
|
||||
if (NULL!=fileNode) {
|
||||
if (fileNode != nullptr) {
|
||||
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 << "'");
|
||||
}
|
||||
|
||||
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);
|
||||
if (fileName.exist() == false) {
|
||||
EGAMI_ERROR("File does not existed='" << fileName << "'");
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
if(fileName.fileOpenRead() == false) {
|
||||
EGAMI_ERROR("Can not find the file name='" << fileName << "'");
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
unsigned char header[8];
|
||||
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) {
|
||||
EGAMI_ERROR("error loading file header");
|
||||
fileName.fileClose();
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
if (png_sig_cmp(header, 0, 8)) {
|
||||
EGAMI_ERROR("Invalid file :" << fileName);
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
|
||||
// PNG read setup
|
||||
@ -73,14 +74,14 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
|
||||
if (png_ptr == nullptr) {
|
||||
EGAMI_ERROR("Can not Allocate PNG structure");
|
||||
fileName.fileClose();
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (info_ptr == nullptr) {
|
||||
EGAMI_ERROR("Can not Allocate PNG info structure");
|
||||
png_destroy_read_struct(&png_ptr, nullptr, nullptr);
|
||||
fileName.fileClose();
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
/*
|
||||
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 colorType = 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
|
||||
EGAMI_VERBOSE("Load PNG image : (" << width << "," << height << ")" );
|
||||
switch (colorType) {
|
||||
case PNG_COLOR_TYPE_RGBA:
|
||||
_ouputImage.configure(ivec2(width,height), egami::colorType::RGBA8);
|
||||
out.configure(ivec2(width,height), egami::colorType::RGBA8);
|
||||
break;
|
||||
case PNG_COLOR_TYPE_RGB:
|
||||
_ouputImage.configure(ivec2(width,height), egami::colorType::RGB8);
|
||||
out.configure(ivec2(width,height), egami::colorType::RGB8);
|
||||
break;
|
||||
case PNG_COLOR_TYPE_GRAY:
|
||||
_ouputImage.configure(ivec2(width,height), egami::colorType::RGB8);
|
||||
out.configure(ivec2(width,height), egami::colorType::RGB8);
|
||||
break;
|
||||
case PNG_COLOR_TYPE_GRAY_ALPHA:
|
||||
_ouputImage.configure(ivec2(width,height), egami::colorType::RGBA8);
|
||||
out.configure(ivec2(width,height), egami::colorType::RGBA8);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -210,7 +211,7 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
|
||||
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
|
||||
png_byte* ptr = &(row[xxx*4]);
|
||||
tmpColor.set(ptr[0], ptr[1], ptr[2], ptr[3]);
|
||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
||||
out.set(ivec2(xxx,yyy), tmpColor);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -222,7 +223,7 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
|
||||
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
|
||||
png_byte* ptr = &(row[xxx*3]);
|
||||
tmpColor.set(ptr[0], ptr[1], ptr[2]);
|
||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
||||
out.set(ivec2(xxx,yyy), tmpColor);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -234,7 +235,7 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
|
||||
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
|
||||
png_byte* ptr = &(row[xxx]);
|
||||
tmpColor.set(ptr[0], ptr[0], ptr[0]);
|
||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
||||
out.set(ivec2(xxx,yyy), tmpColor);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -246,7 +247,7 @@ bool egami::loadPNG(const std::string& _inputFile, egami::Image& _ouputImage) {
|
||||
for (png_uint_32 xxx = 0; xxx < width; ++xxx) {
|
||||
png_byte* ptr = &(row[xxx*2]);
|
||||
tmpColor.set(ptr[0], ptr[0], ptr[0], ptr[1]);
|
||||
_ouputImage.set(ivec2(xxx,yyy), tmpColor);
|
||||
out.set(ivec2(xxx,yyy), tmpColor);
|
||||
}
|
||||
}
|
||||
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) {
|
||||
EGAMI_ERROR(" Alpha");
|
||||
}
|
||||
return false;
|
||||
return egami::Image();
|
||||
}
|
||||
fileName.fileClose();
|
||||
// Clean up after the read, and free any memory allocated - REQUIRED
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
return true;
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,8 @@ 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.
|
||||
* @return Read Image.
|
||||
*/
|
||||
bool loadPNG(const std::string& _fileName, egami::Image& _ouputImage);
|
||||
egami::Image loadPNG(const std::string& _fileName);
|
||||
}
|
||||
|
||||
|
@ -12,19 +12,20 @@
|
||||
#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;
|
||||
if (svgDocument.load(_fileName) == false) {
|
||||
EGAMI_ERROR("Error to load SVG file " << _fileName );
|
||||
return false;
|
||||
return out;
|
||||
}
|
||||
ivec2 imageSize = _size;
|
||||
#if 0
|
||||
std::vector<etk::Color<float,4>> svgImage = svgDocument.renderImageFloatRGBA(imageSize);
|
||||
_ouputImage.set(svgImage, imageSize);
|
||||
out.set(svgImage, imageSize);
|
||||
#else
|
||||
std::vector<etk::Color<uint8_t,4>> svgImage = svgDocument.renderImageU8RGBA(imageSize);
|
||||
_ouputImage.set(svgImage, imageSize);
|
||||
out.set(svgImage, imageSize);
|
||||
#endif
|
||||
return true;
|
||||
return out;
|
||||
}
|
@ -9,12 +9,11 @@
|
||||
|
||||
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[out] _ouputImage Read data.
|
||||
* @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