diff --git a/egami/egami.cpp b/egami/egami.cpp index e16ab1b..f421d90 100644 --- a/egami/egami.cpp +++ b/egami/egami.cpp @@ -27,75 +27,75 @@ #endif #include -bool egami::scalable(const etk::String& _fileName) { - if (true == etk::end_with(_fileName, ".svg") ) { +bool egami::scalable(const etk::Uri& _uri) { + if (etk::toLower(_uri.getPath().getExtention()) == "svg") { return true; } return false; } -egami::Image egami::load(const etk::String& _fileName, const ivec2& _size) { - etk::String tmpName = etk::toLower(_fileName); +egami::Image egami::load(const etk::Uri& _uri, const ivec2& _size) { + etk::String extention = etk::toLower(_uri.getPath().getExtention()); egami::Image out; // select the corect Loader : - if (etk::end_with(tmpName, ".edf") == true) { + if (extention == "edf") { // internal format for ewol distance field ==> simple sistance field image - out = egami::loadEDF(_fileName); + out = egami::loadEDF(_uri); if (out.exist() == false) { - EGAMI_ERROR("Error to load EDF file '" << _fileName << "'"); + EGAMI_ERROR("Error to load EDF file '" << _uri << "'"); } - } else if (etk::end_with(tmpName, ".bmp") == true) { - out = egami::loadBMP(_fileName); + } else if (extention == "bmp") { + out = egami::loadBMP(_uri); if (out.exist() == false) { - EGAMI_ERROR("Error to load BMP file '" << _fileName << "'"); + EGAMI_ERROR("Error to load BMP file '" << _uri << "'"); } - } else if (etk::end_with(tmpName, ".svg") == true) { + } else if (extention == "svg") { #ifdef EGAMI_BUILD_ESVG - out = egami::loadSVG(_fileName, _size); + out = egami::loadSVG(_uri, _size); if (out.exist() == false) { - EGAMI_ERROR("Error to load SVG file '" << _fileName << "'"); + EGAMI_ERROR("Error to load SVG file '" << _uri << "'"); } #else - EGAMI_WARNING("egami not compile with the ESVG dependency for file '" << _fileName << "'"); + EGAMI_WARNING("egami not compile with the ESVG dependency for file '" << _uri << "'"); #endif - } else if (etk::end_with(tmpName, ".png") == true) { + } else if (extention == "png") { #ifdef EGAMI_BUILD_PNG - out = egami::loadPNG(_fileName); + out = egami::loadPNG(_uri); if (out.exist() == false) { - EGAMI_ERROR("Error to load PNG file '" << _fileName << "'"); + EGAMI_ERROR("Error to load PNG file '" << _uri << "'"); } #else - EGAMI_WARNING("egami not compile with the PNG dependency for file '" << _fileName << "'"); + EGAMI_WARNING("egami not compile with the PNG dependency for file '" << _uri << "'"); #endif - } else if (etk::end_with(tmpName, ".jpg") == true) { + } else if (extention == "jpg") { #ifdef EGAMI_BUILD_JPEG - out = egami::loadJPG(_fileName); + out = egami::loadJPG(_uri); if (out.exist() == false) { - EGAMI_ERROR("Error to load JPG file '" << _fileName << "'"); + EGAMI_ERROR("Error to load JPG file '" << _uri << "'"); } #else - EGAMI_WARNING("egami not compile with the JPEG dependency for file '" << _fileName << "'"); + EGAMI_WARNING("egami not compile with the JPEG dependency for file '" << _uri << "'"); #endif - } else if (etk::end_with(tmpName, ".j2k") == true) { + } else if (extention == "j2k") { #ifdef EGAMI_BUILD_JPEG2000 - out = egami::loadJPG2000(_fileName); + out = egami::loadJPG2000(_uri); if (out.exist() == false) { - EGAMI_ERROR("Error to load JPEG2000 file '" << _fileName << "'"); + EGAMI_ERROR("Error to load JPEG2000 file '" << _uri << "'"); } #else - EGAMI_WARNING("egami not compile with the JPEG 2000 (openjpeg) dependency for file '" << _fileName << "'"); + EGAMI_WARNING("egami not compile with the JPEG 2000 (openjpeg) dependency for file '" << _uri << "'"); #endif - } else if (etk::end_with(tmpName, ".tif") == true) { + } else if (extention == "tif") { #ifdef EGAMI_BUILD_TIFF - out = egami::loadTIFF(_fileName); + out = egami::loadTIFF(_uri); if (out.exist() == false) { - EGAMI_ERROR("Error to load TIFF file '" << _fileName << "'"); + EGAMI_ERROR("Error to load TIFF file '" << _uri << "'"); } #else - EGAMI_WARNING("egami not compile with the TIFF dependency for file '" << _fileName << "'"); + EGAMI_WARNING("egami not compile with the TIFF dependency for file '" << _uri << "'"); #endif } else { - EGAMI_ERROR("Extention not managed '" << _fileName << "' Sopported extention : .edf / .bmp / .svg / .png / .jpg / .j2k / .tif"); + EGAMI_ERROR("Extention not managed '" << _uri << "' Sopported extention : .edf / .bmp / .svg / .png / .jpg / .j2k / .tif"); } return out; } @@ -133,51 +133,51 @@ egami::Image egami::load(const etk::String& _mineType, const etk::Vector '" << _output << "'"); diff --git a/egami/egami.hpp b/egami/egami.hpp index 73db735..fc045b5 100644 --- a/egami/egami.hpp +++ b/egami/egami.hpp @@ -11,14 +11,15 @@ #include #include #include +#include namespace egami { /** * @brief Load a specific ilage file in the requested image data. - * @param[in] _fileName Name of the file (SVG, BMP, PNG). + * @param[in] _uri Uri of the file (SVG, BMP, PNG). * @param[in] _size Dimention of the file when resizable (SVG). */ - egami::Image load(const etk::String& _fileName, const ivec2& _size=ivec2(-1,-1) ); + egami::Image load(const etk::Uri& _uri, const ivec2& _size=ivec2(-1,-1) ); /** * @brief Load a specific ilage file in the requested image data. * @param[in] _mineType mineType of the buffer. @@ -29,10 +30,10 @@ namespace egami { /** * @brief Save an image in a file. * @param[in] _input Data of the image. - * @param[in] _fileName Name of the file. + * @param[in] _uri Uri of the file. * @return true if the file is corectly Stored, false otherwise */ - bool store(const egami::Image& _input, const etk::String& _fileName); + bool store(const egami::Image& _input, const etk::Uri& _uri); /** * @brief Save an image in a memory buffer. * @param[in] _input Data of the image. @@ -43,10 +44,10 @@ namespace egami { bool store(const egami::Image& _input, etk::Vector& _buffer, const etk::String& _mineType); /** * @brief know if a file can have multiple size definition. - * @param[in] _fileName Name of the file. + * @param[in] _uri Uri of the file. * @return true if the format is scalable. */ - bool scalable(const etk::String& _fileName); + bool scalable(const etk::Uri& _uri); /** * @brief Generate a distance field output file from an input file; * @param[in] _input Input file name @@ -54,7 +55,7 @@ namespace egami { * @return true All done corectly. * @return false An error occured. */ - bool generateDistanceFieldFile(const etk::String& _input, const etk::String& _output); + bool generateDistanceFieldFile(const etk::Uri& _input, const etk::Uri& _output); } diff --git a/egami/wrapperBMP.cpp b/egami/wrapperBMP.cpp index be4d64f..2e3b80e 100644 --- a/egami/wrapperBMP.cpp +++ b/egami/wrapperBMP.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include extern "C" { #pragma pack(push,1) struct bitmapFileHeader { @@ -106,19 +106,18 @@ static void display(struct bitmapFileHeader _header, struct bitmapInfoHeader _in }*/ } -egami::Image egami::loadBMP(const etk::String& _inputFile) { - etk::FSNode fileName(_inputFile); - EGAMI_VERBOSE("File='" << _inputFile << "' ==> " << fileName << " ==> " << fileName.getFileSystemName()); - if (fileName.exist() == false) { - EGAMI_ERROR("File does not existed='" << fileName << "'"); +egami::Image egami::loadBMP(const etk::Uri& _uri) { + auto fileIo = etk::uri::get(_uri); + if (fileIo == null) { + EGAMI_ERROR("Can not create the uri: " << _uri); return egami::Image(); } - if(fileName.fileOpenRead() == false) { - EGAMI_ERROR("Can not find the file name='" << fileName << "'"); + if (fileIo->open(etk::io::OpenMode::Read) == false) { + EGAMI_ERROR("Can not open (r) the file : " << _uri); return egami::Image(); } - etk::Vector allData = fileName.fileReadAll(); - fileName.fileClose(); + etk::Vector allData = fileIo->readAll(); + fileIo->close(); return egami::loadBMP(allData); } @@ -305,17 +304,20 @@ egami::Image egami::loadBMP(const etk::Vector& _buffer) { #if 1 // Extended mode -bool egami::storeBMP(const etk::String& _fileName, const egami::Image& _inputImage) { - etk::FSNode fileName(_fileName); - EGAMI_VERBOSE("File='" << _fileName << "' ==> " << fileName << " ==> " << fileName.getFileSystemName()); - if(fileName.fileOpenWrite() == false) { - EGAMI_ERROR("Can not crete the output file name='" << fileName << "'"); +bool egami::storeBMP(const etk::Uri& _uri, const egami::Image& _inputImage) { + auto fileIo = etk::uri::get(_uri); + if (fileIo == null) { + EGAMI_ERROR("Can not create the uri: " << _uri); + return false; + } + if (fileIo->open(etk::io::OpenMode::Write) == false) { + EGAMI_ERROR("Can not open (w) the file : " << _uri); return false; } etk::Vector allData; bool ret = storeBMP(allData, _inputImage); - fileName.fileWriteAll(allData); - fileName.fileClose(); + fileIo->writeAll(allData); + fileIo->close(); return ret; } @@ -418,7 +420,7 @@ bool egami::storeBMP(etk::Vector& _buffer, const egami::Image& _inputIm } #else // old mode: -bool egami::storeBMP(const etk::String& _fileName, const egami::Image& _inputImage) { +bool egami::storeBMP(const etk::Uri& _uri, const egami::Image& _inputImage) { struct bitmapFileHeader m_FileHeader; struct bitmapInfoHeader m_InfoHeader; memset(&m_InfoHeader, 0, sizeof(bitmapInfoHeader)); @@ -456,20 +458,24 @@ bool egami::storeBMP(const etk::String& _fileName, const egami::Image& _inputIma //m_InfoHeader.biClrImportant = 0; - etk::FSNode fileName(_fileName); - if(false == fileName.fileOpenWrite() ) { - EGAMI_ERROR("Can not find the file name=\"" << fileName << "\""); + auto fileIo = etk::uri::get(_uri); + if (fileIo == null) { + EGAMI_ERROR("Can not create the uri: " << _uri); + return false; + } + if (fileIo->open(etk::io::OpenMode::Write) == false) { + EGAMI_ERROR("Can not open (w) the file : " << _uri); return false; } // Write header: - if (fileName.fileWrite(&m_FileHeader,sizeof(struct bitmapFileHeader),1) != 1) { + if (fileIo->write(&m_FileHeader,sizeof(struct bitmapFileHeader),1) != 1) { EGAMI_ERROR("error loading file header"); - fileName.fileClose(); + fileIo->close(); return false; } - if (fileName.fileWrite(&m_InfoHeader,sizeof(struct bitmapInfoHeader),1) != 1) { + if (fileIo->write(&m_InfoHeader,sizeof(struct bitmapInfoHeader),1) != 1) { EGAMI_ERROR("error loading file header"); - fileName.fileClose(); + fileIo->close(); return false; } EGAMI_ERROR("header size = " << sizeof(struct bitmapFileHeader) << " + " << sizeof(struct bitmapInfoHeader) << " = " << (sizeof(struct bitmapFileHeader)+sizeof(struct bitmapInfoHeader)) ); @@ -491,7 +497,7 @@ bool egami::storeBMP(const etk::String& _fileName, const egami::Image& _inputIma *pointer++ = tmpColor.g(); *pointer++ = tmpColor.b(); *pointer++ = tmpColor.a(); - fileName.fileWrite(data,4,1); + fileIo->write(data,4,1); } } } else { @@ -503,7 +509,7 @@ bool egami::storeBMP(const etk::String& _fileName, const egami::Image& _inputIma *pointer++ = tmpColor.b(); *pointer++ = tmpColor.g(); *pointer++ = tmpColor.r(); - fileName.fileWrite(data,3,1); + fileIo->write(data,3,1); } if (offset != 0) { uint8_t pointer[4]; @@ -511,11 +517,11 @@ bool egami::storeBMP(const etk::String& _fileName, const egami::Image& _inputIma pointer[1] = 0; pointer[2] = 0; pointer[3] = 0; - fileName.fileWrite(pointer,1,offset); + fileIo->write(pointer,1,offset); } } } - fileName.fileClose(); + fileIo->close(); return true; } #endif diff --git a/egami/wrapperBMP.hpp b/egami/wrapperBMP.hpp index fcc00fe..0a80d1e 100644 --- a/egami/wrapperBMP.hpp +++ b/egami/wrapperBMP.hpp @@ -10,10 +10,10 @@ namespace egami { /** * @breif Load a bmp file in the image. - * @param[in] _fileName Name of the file. + * @param[in] _uri Uri of the file. * @return Generate image or empty image */ - egami::Image loadBMP(const etk::String& _fileName); + egami::Image loadBMP(const etk::Uri& _uri); /** * @breif Load a bmp file in the image. * @param[in] _buffer file buffer @@ -22,11 +22,11 @@ namespace egami { egami::Image loadBMP(const etk::Vector& _buffer); /** * @breif Store a bmp file in the image. - * @param[in] _fileName Name of the file. + * @param[in] _uri Uri of the file. * @param[in] _inputImage write data. * @return true if all is done correctly, false otherwise. */ - bool storeBMP(const etk::String& _fileName, const egami::Image& _inputImage); + bool storeBMP(const etk::Uri& _uri, const egami::Image& _inputImage); /** * @breif Store a bmp file in the image. * @param[out] _buffer output file buffer. diff --git a/egami/wrapperEDF.cpp b/egami/wrapperEDF.cpp index ea16439..a68c72c 100644 --- a/egami/wrapperEDF.cpp +++ b/egami/wrapperEDF.cpp @@ -8,32 +8,32 @@ #include #include #include -#include +#include //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 -egami::Image egami::loadEDF(const etk::String& _inputFile) { +egami::Image egami::loadEDF(const etk::Uri& _uri) { egami::Image out; - etk::FSNode file(_inputFile); - if (false == file.exist()) { - EGAMI_ERROR("File does not existed='" << file << "'"); + auto fileIo = etk::uri::get(_uri); + if (fileIo == null) { + EGAMI_ERROR("Can not create the uri: " << _uri); return out; } - if(false == file.fileOpenRead() ) { - EGAMI_ERROR("Can not find the file name='" << file << "'"); + if (fileIo->open(etk::io::OpenMode::Read) == false) { + EGAMI_ERROR("Can not open (r) the file : " << _uri); return out; } etk::String line; - file.fileGets(line); + fileIo->gets(line); if (etk::start_with(line, "#edf", false) == false) { EGAMI_ERROR("This file seams not to be a EDF file ..."); - file.fileClose(); + fileIo->close(); return out; } // count number of colomn max an number of line max: ivec2 size(0,0); - while (file.fileGets(line) == true) { + while (fileIo->gets(line) == true) { if (line.size()/2 > (size_t)size.x()) { size.setValue(line.size()/2, size.y()+1); } else { @@ -45,19 +45,17 @@ egami::Image egami::loadEDF(const etk::String& _inputFile) { } else { size += ivec2(0,1); } - EGAMI_DEBUG("'" << file << "' ==> size=" << size); + EGAMI_DEBUG("'" << _uri << "' ==> size=" << size); // jup to the start of the file - file.fileSeek(0, etk::seekNode_start); + fileIo->seek(0, etk::io::SeekMode::Start); // drop the first line - file.fileGets(line); - - + fileIo->gets(line); // resize output: out.configure(size, egami::colorType::RGB8); // TODO : Do it better int32_t currentLineId = 0; char tmp[3]; tmp[2] = '\0'; - while (file.fileGets(line) == true) { + while (fileIo->gets(line) == true) { if (line.size() <= 0) { continue; } @@ -79,26 +77,30 @@ egami::Image egami::loadEDF(const etk::String& _inputFile) { out.set(ivec2(xxx/2, currentLineId), etk::Color<>((uint8_t)val, (uint8_t)val, (uint8_t)val, (uint8_t)val)); } } - file.fileClose(); + fileIo->close(); return out; } -bool egami::storeEDF(const etk::String& _fileName, const egami::Image& _inputImage) { +bool egami::storeEDF(const etk::Uri& _uri, const egami::Image& _inputImage) { bool anErrorEccured = false; - etk::FSNode file(_fileName); - if (file.fileOpenWrite() == false) { - EGAMI_ERROR("Can not find the file name=\"" << file << "\""); + auto fileIo = etk::uri::get(_uri); + if (fileIo == null) { + EGAMI_ERROR("Can not create the uri: " << _uri); return false; } - anErrorEccured = file.filePuts( etk::String("#EDF // Generate with EGAMI (") - + etk::toString(_inputImage.getSize().x()) - + "," - + etk::toString(_inputImage.getSize().y()) + ")\n"); + if (fileIo->open(etk::io::OpenMode::Write) == false) { + EGAMI_ERROR("Can not open (w) the file : " << _uri); + return false; + } + anErrorEccured = fileIo->puts( etk::String("#EDF // Generate with EGAMI (") + + etk::toString(_inputImage.getSize().x()) + + "," + + etk::toString(_inputImage.getSize().y()) + ")\n"); char tmp[256]; for (int32_t yyy = 0; yyy < _inputImage.getSize().y(); ++yyy) { if (yyy != 0) { - if (file.filePut('\n') == false) { + if (fileIo->put('\n') == false) { anErrorEccured = false; } } @@ -109,12 +111,11 @@ bool egami::storeEDF(const etk::String& _fileName, const egami::Image& _inputIma EGAMI_DEBUG(" set : " << _inputImage.get(ivec2(xxx, yyy)) << " : '" << tmp << "'"); } */ - if (file.filePuts(tmp) == false) { + if (fileIo->puts(tmp) == false) { anErrorEccured = false; } } } - - file.fileClose(); + fileIo->close(); return anErrorEccured; } diff --git a/egami/wrapperEDF.hpp b/egami/wrapperEDF.hpp index 8af7b7d..5b745fc 100644 --- a/egami/wrapperEDF.hpp +++ b/egami/wrapperEDF.hpp @@ -19,16 +19,16 @@ namespace egami { * * * * * * [PRE] - * @param[in] _fileName Name of the file. + * @param[in] _uri Uri of the file. * @return Read Image */ - egami::Image loadEDF(const etk::String& _fileName); + egami::Image loadEDF(const etk::Uri& _uri); /** * @breif Store a edf file in the image. - * @param[in] _fileName Name of the file. + * @param[in] _uri Uri of the file. * @param[in] _inputImage write data. * @return true if all is done correctly, false otherwise. */ - bool storeEDF(const etk::String& _fileName, const egami::Image& _inputImage); + bool storeEDF(const etk::Uri& _uri, const egami::Image& _inputImage); } diff --git a/egami/wrapperJPG.cpp b/egami/wrapperJPG.cpp index 3a484d4..1ecd712 100644 --- a/egami/wrapperJPG.cpp +++ b/egami/wrapperJPG.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include extern "C" { #include "jpeglib.h" } @@ -39,18 +39,18 @@ void put_scanline_someplace(const uint8_t* _buffer, int32_t _row_stride) { } -egami::Image egami::loadJPG(const etk::String& _inputFile) { - etk::FSNode fileName(_inputFile); - if (fileName.exist() == false) { - EGAMI_ERROR("File does not existed='" << fileName << "'"); +egami::Image egami::loadJPG(const etk::Uri& _uri) { + auto fileIo = etk::uri::get(_uri); + if (fileIo == null) { + EGAMI_ERROR("Can not create the uri: " << _uri); return egami::Image(); } - if(fileName.fileOpenRead() == false) { - EGAMI_ERROR("Can not find the file name='" << fileName << "'"); + if (fileIo->open(etk::io::OpenMode::Read) == false) { + EGAMI_ERROR("Can not open (r) the file : " << _uri); return egami::Image(); } - etk::Vector allData = fileName.fileReadAll(); - fileName.fileClose(); + etk::Vector allData = fileIo->readAll(); + fileIo->close(); return egami::loadJPG(allData); } @@ -153,17 +153,20 @@ void myTermDestination(j_compress_ptr _cinfo) { myBuffer.resize(myBuffer.size() - _cinfo->dest->free_in_buffer); } -bool egami::storeJPG(const etk::String& _fileName, const egami::Image& _inputImage) { - etk::FSNode fileName(_fileName); - EGAMI_VERBOSE("File='" << _fileName << "' ==> " << fileName << " ==> " << fileName.getFileSystemName()); - if(fileName.fileOpenWrite() == false) { - EGAMI_ERROR("Can not crete the output file name='" << fileName << "'"); +bool egami::storeJPG(const etk::Uri& _uri, const egami::Image& _inputImage) { + auto fileIo = etk::uri::get(_uri); + if (fileIo == null) { + EGAMI_ERROR("Can not create the uri: " << _uri); + return false; + } + if (fileIo->open(etk::io::OpenMode::Write) == false) { + EGAMI_ERROR("Can not open (w) the file : " << _uri); return false; } etk::Vector allData; bool ret = storeJPG(allData, _inputImage); - fileName.fileWriteAll(allData); - fileName.fileClose(); + fileIo->writeAll(allData); + fileIo->close(); return ret; } diff --git a/egami/wrapperJPG.hpp b/egami/wrapperJPG.hpp index 74873df..ee50097 100644 --- a/egami/wrapperJPG.hpp +++ b/egami/wrapperJPG.hpp @@ -10,10 +10,10 @@ namespace egami { /** * @breif Load a jpeg file in the image. - * @param[in] _fileName Name of the file. + * @param[in] _uri Uri of the file. * @return Read Image. */ - egami::Image loadJPG(const etk::String& _fileName); + egami::Image loadJPG(const etk::Uri& _uri); /** * @breif Load a jpeg file in the image. * @param[in] _buffer file Buffer @@ -22,11 +22,11 @@ namespace egami { egami::Image loadJPG(const etk::Vector& _buffer); /** * @breif Store a jpg file in the image. - * @param[in] _fileName Name of the file. + * @param[in] _uri Uri of the file. * @param[in] _inputImage write data. * @return true if all is done correctly, false otherwise. */ - bool storeJPG(const etk::String& _fileName, const egami::Image& _inputImage); + bool storeJPG(const etk::Uri& _uri, const egami::Image& _inputImage); /** * @breif Store a jpg file in the image. * @param[out] _buffer output file buffer. diff --git a/egami/wrapperJPG2000.cpp b/egami/wrapperJPG2000.cpp index bb5cedf..9fd52f2 100644 --- a/egami/wrapperJPG2000.cpp +++ b/egami/wrapperJPG2000.cpp @@ -8,25 +8,10 @@ #include #include #include -#include -egami::Image egami::loadJPG2000(const etk::String& _inputFile) { +egami::Image egami::loadJPG2000(const etk::Uri& _uri) { egami::Image out; - etk::FSNode fileName(_inputFile); - if (fileName.exist() == false) { - EGAMI_ERROR("File does not existed='" << fileName << "'"); - return out; - } - if(fileName.fileOpenRead() == false) { - EGAMI_ERROR("Can not find the file name='" << fileName << "'"); - return out; - } - - - - - - + EGAMI_TODO("Read JPEG2000 file"); return out; } diff --git a/egami/wrapperJPG2000.hpp b/egami/wrapperJPG2000.hpp index 200eaca..de40816 100644 --- a/egami/wrapperJPG2000.hpp +++ b/egami/wrapperJPG2000.hpp @@ -10,9 +10,9 @@ namespace egami { /** * @breif Load a jpeg 2000 file in the image. - * @param[in] _fileName Name of the file. + * @param[in] _uri Uri of the file. * @return Read Image. */ - egami::Image loadJPG2000(const etk::String& _fileName); + egami::Image loadJPG2000(const etk::Uri& _uri); } diff --git a/egami/wrapperPNG.cpp b/egami/wrapperPNG.cpp index c883510..6c56563 100644 --- a/egami/wrapperPNG.cpp +++ b/egami/wrapperPNG.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include namespace egami { class ReaderInstance { @@ -19,22 +19,22 @@ namespace egami { virtual void flush() = 0; }; - class ReaderInstanceFSNode : public egami::ReaderInstance { + class ReaderInstancIOInterface : public egami::ReaderInstance { private: - etk::FSNode& m_data; + ememory::SharedPtr m_data; public: - ReaderInstanceFSNode(etk::FSNode& _data): + ReaderInstancIOInterface(const ememory::SharedPtr& _data): m_data(_data) { } void read(png_bytep _data, png_size_t _length) override { - m_data.fileRead(_data, 1, _length); + m_data->read(_data, 1, _length); } void write(png_bytep _data, png_size_t _length) override { - m_data.fileWrite(_data, 1, _length); + m_data->write(_data, 1, _length); } void flush() override { - m_data.fileFlush(); + m_data->flush(); } }; @@ -267,26 +267,26 @@ static egami::Image genericLoader(png_structp _pngPtr, png_infop _infoPtr) { } -egami::Image egami::loadPNG(const etk::String& _inputFile) { +egami::Image egami::loadPNG(const etk::Uri& _uri) { egami::Image out; - etk::FSNode fileName(_inputFile); - if (fileName.exist() == false) { - EGAMI_ERROR("File does not existed='" << fileName << "'"); + auto fileIo = etk::uri::get(_uri); + if (fileIo == null) { + EGAMI_ERROR("Can not create the uri: " << _uri); return out; } - if(fileName.fileOpenRead() == false) { - EGAMI_ERROR("Can not find the file name='" << fileName << "'"); + if (fileIo->open(etk::io::OpenMode::Read) == false) { + EGAMI_ERROR("Can not open (r) the file : " << _uri); return out; } unsigned char header[8]; - if (fileName.fileRead(header,1,8) != 8) { + if (fileIo->read(header,1,8) != 8) { EGAMI_ERROR("error loading file header"); - fileName.fileClose(); + fileIo->close(); return out; } if (png_sig_cmp(header, 0, 8)) { - EGAMI_ERROR("Invalid file :" << fileName); + EGAMI_ERROR("Invalid file :" << _uri); return out; } @@ -294,14 +294,14 @@ egami::Image egami::loadPNG(const etk::String& _inputFile) { png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, userErrorFunction, userWarningFunction); if (png_ptr == null) { EGAMI_ERROR("Can not Allocate PNG structure"); - fileName.fileClose(); + fileIo->close(); return out; } png_infop info_ptr = png_create_info_struct(png_ptr); if (info_ptr == null) { EGAMI_ERROR("Can not Allocate PNG info structure"); png_destroy_read_struct(&png_ptr, null, null); - fileName.fileClose(); + fileIo->close(); return out; } /* @@ -309,11 +309,11 @@ egami::Image egami::loadPNG(const etk::String& _inputFile) { EGAMI_ERROR(" Can not set the JUMP buffer adresses"); // Free all of the memory associated with the png_ptr and info_ptr png_destroy_read_struct(&png_ptr, &info_ptr, null); - fileName.fileClose(); + fileIo->close(); return false; } */ - ReaderInstanceFSNode tmpNode(fileName); + ReaderInstancIOInterface tmpNode(fileIo); ReaderInstance* tmpPoiter = &tmpNode; @@ -322,7 +322,7 @@ egami::Image egami::loadPNG(const etk::String& _inputFile) { tmpPoiter, &local_ReadData); out = genericLoader(png_ptr, info_ptr); - fileName.fileClose(); + fileIo->close(); return out; } @@ -444,31 +444,36 @@ bool egami::storePNG(etk::Vector& _buffer, const egami::Image& _inputIm return genericWriter(png_ptr, info_ptr, _inputImage); } -bool egami::storePNG(const etk::String& _fileName, const egami::Image& _inputImage) { - etk::FSNode fileName(_fileName); - if(fileName.fileOpenWrite() == false) { - EGAMI_ERROR("Can not find the file name='" << fileName << "'"); +bool egami::storePNG(const etk::Uri& _uri, const egami::Image& _inputImage) { + auto fileIo = etk::uri::get(_uri); + if (fileIo == null) { + EGAMI_ERROR("Can not create the uri: " << _uri); + return false; + } + if (fileIo->open(etk::io::OpenMode::Write) == false) { + EGAMI_ERROR("Can not open (w) the file : " << _uri); return false; } png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, userErrorFunction, userWarningFunction); if (png_ptr == null) { EGAMI_ERROR("Can not Allocate PNG structure"); + fileIo->close(); return false; } png_infop info_ptr = png_create_info_struct(png_ptr); if (info_ptr == null) { EGAMI_ERROR("Can not Allocate PNG info structure"); png_destroy_write_struct(&png_ptr, null); - fileName.fileClose(); + fileIo->close(); return false; } if (setjmp(png_jmpbuf(png_ptr))) { EGAMI_ERROR("Error during init_io"); png_destroy_write_struct(&png_ptr, &info_ptr); - fileName.fileClose(); + fileIo->close(); return false; } - ReaderInstanceFSNode tmpNode(fileName); + ReaderInstancIOInterface tmpNode(fileIo); ReaderInstance* tmpPoiter = &tmpNode; @@ -479,6 +484,6 @@ bool egami::storePNG(const etk::String& _fileName, const egami::Image& _inputIma &local_FlushData); bool out = genericWriter(png_ptr, info_ptr, _inputImage); - fileName.fileClose(); + fileIo->close(); return out; } diff --git a/egami/wrapperPNG.hpp b/egami/wrapperPNG.hpp index e307971..ac44396 100644 --- a/egami/wrapperPNG.hpp +++ b/egami/wrapperPNG.hpp @@ -10,10 +10,10 @@ namespace egami { /** * @breif Load a png file in the image. - * @param[in] _fileName Name of the file. + * @param[in] _uri Uri of the file. * @return Read Image. */ - egami::Image loadPNG(const etk::String& _fileName); + egami::Image loadPNG(const etk::Uri& _uri); /** * @breif Load a png file in the image. * @param[in] _buffer File buffer. @@ -22,11 +22,11 @@ namespace egami { egami::Image loadPNG(const etk::Vector& _buffer); /** * @breif Store a PNG file in the image. - * @param[in] _fileName Name of the file. + * @param[in] _uri Uri of the file. * @param[in] _inputImage write data. * @return true if all is done correctly, false otherwise. */ - bool storePNG(const etk::String& _fileName, const egami::Image& _inputImage); + bool storePNG(const etk::Uri& _uri, const egami::Image& _inputImage); /** * @breif Store a PNG file in the image. * @param[out] _buffer output file buffer. diff --git a/egami/wrapperSVG.cpp b/egami/wrapperSVG.cpp index d5ee673..9832327 100644 --- a/egami/wrapperSVG.cpp +++ b/egami/wrapperSVG.cpp @@ -8,15 +8,15 @@ #include #include #include -#include +#include #include -egami::Image egami::loadSVG(const etk::String& _fileName, const ivec2& _size) { +egami::Image egami::loadSVG(const etk::Uri& _uri, const ivec2& _size) { egami::Image out; esvg::Document svgDocument; - if (svgDocument.load(_fileName) == false) { - EGAMI_ERROR("Error to load SVG file " << _fileName ); + if (svgDocument.load(_uri) == false) { + EGAMI_ERROR("Error to load SVG file " << _uri ); return out; } ivec2 imageSize = _size; diff --git a/egami/wrapperSVG.hpp b/egami/wrapperSVG.hpp index ab9dd86..292bbe1 100644 --- a/egami/wrapperSVG.hpp +++ b/egami/wrapperSVG.hpp @@ -10,10 +10,10 @@ namespace egami { /** * @brief Load a svg file in the image. - * @param[in] _fileName Name of the file. + * @param[in] _uri Uri of the file. * @param[in] _size size of the output image. * @return Generated image */ - egami::Image loadSVG(const etk::String& _fileName, const ivec2& _size=ivec2(-1,-1)); + egami::Image loadSVG(const etk::Uri& _uri, const ivec2& _size=ivec2(-1,-1)); } diff --git a/egami/wrapperTIFF.cpp b/egami/wrapperTIFF.cpp index aed6885..b4b4af8 100644 --- a/egami/wrapperTIFF.cpp +++ b/egami/wrapperTIFF.cpp @@ -8,26 +8,10 @@ #include #include #include -#include - -egami::Image egami::loadTIFF(const etk::String& _inputFile) { +egami::Image egami::loadTIFF(const etk::Uri& _uri) { egami::Image out; - etk::FSNode fileName(_inputFile); - if (fileName.exist() == false) { - EGAMI_ERROR("File does not existed='" << fileName << "'"); - return out; - } - if(fileName.fileOpenRead() == false) { - EGAMI_ERROR("Can not find the file name='" << fileName << "'"); - return out; - } - - - - - - + EGAMI_TODO("Read TIFF file"); return out; } diff --git a/egami/wrapperTIFF.hpp b/egami/wrapperTIFF.hpp index 4be7e57..37b0c07 100644 --- a/egami/wrapperTIFF.hpp +++ b/egami/wrapperTIFF.hpp @@ -10,9 +10,9 @@ namespace egami { /** * @breif Load a tiff file in the image. - * @param[in] _fileName Name of the file. + * @param[in] _uri Uri of the file. * @return Read Image. */ - egami::Image loadTIFF(const etk::String& _fileName); + egami::Image loadTIFF(const etk::Uri& _uri); }