[DEV] integrate the new interface of URI and file

This commit is contained in:
Edouard DUPIN 2018-09-24 23:26:06 +02:00
parent 37c83f9728
commit 41a2c25992
16 changed files with 214 additions and 228 deletions

View File

@ -27,75 +27,75 @@
#endif
#include <edtaa3/edtaa3func.h>
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<uint8_t
return out;
}
bool egami::store(const egami::Image& _input, const etk::String& _fileName) {
etk::String tmpName = etk::toLower(_fileName);
EGAMI_DEBUG("Store file : " << _fileName);
bool egami::store(const egami::Image& _input, const etk::Uri& _uri) {
etk::String extention = etk::toLower(_uri.getPath().getExtention());
EGAMI_DEBUG("Store file : " << _uri);
// select the corect Loader :
if (etk::end_with(tmpName, ".edf") == true) {
if (egami::storeEDF(_fileName, _input) == false) {
EGAMI_ERROR("Error to store EDF file '" << _fileName << "'");
if (extention == "edf") {
if (egami::storeEDF(_uri, _input) == false) {
EGAMI_ERROR("Error to store EDF file '" << _uri << "'");
return false;
}
} else if (etk::end_with(tmpName, ".bmp") == true) {
if (egami::storeBMP(_fileName, _input) == false) {
EGAMI_ERROR("Error to store BMP file '" << _fileName << "'");
} else if (extention == "bmp") {
if (egami::storeBMP(_uri, _input) == false) {
EGAMI_ERROR("Error to store BMP file '" << _uri << "'");
return false;
}
} else if (etk::end_with(tmpName, ".svg") == true) {
EGAMI_ERROR("Can not store in SVG file '" << _fileName << "'");
} else if (extention == "svg") {
EGAMI_ERROR("Can not store in SVG file '" << _uri << "'");
return false;
} else if (etk::end_with(tmpName, ".png") == true) {
} else if (extention == "png") {
#ifdef EGAMI_BUILD_PNG
if (egami::storePNG(_fileName, _input) == false) {
EGAMI_ERROR("Error to store PNG file '" << _fileName << "'");
if (egami::storePNG(_uri, _input) == false) {
EGAMI_ERROR("Error to store PNG file '" << _uri << "'");
return false;
}
#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 << "'");
return false;
#endif
} else if (etk::end_with(tmpName, ".jpg") == true) {
} else if (extention == "jpg") {
#ifdef EGAMI_BUILD_JPEG
if (egami::storeJPG(_fileName, _input) == false) {
EGAMI_ERROR("Error to store JPEG file '" << _fileName << "'");
if (egami::storeJPG(_uri, _input) == false) {
EGAMI_ERROR("Error to store JPEG file '" << _uri << "'");
return false;
}
#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 << "'");
return false;
#endif
} else if (etk::end_with(tmpName, ".j2k") == true) {
EGAMI_ERROR("Can not store in JPEG 2000 file '" << _fileName << "'");
} else if (extention == "j2k") {
EGAMI_ERROR("Can not store in JPEG 2000 file '" << _uri << "'");
return false;
} else if (etk::end_with(tmpName, ".tif") == true) {
EGAMI_ERROR("Can not store in TIFF file '" << _fileName << "'");
} else if (extention == "tif") {
EGAMI_ERROR("Can not store in TIFF file '" << _uri << "'");
return false;
} 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 false;
}
return true;
@ -302,9 +302,10 @@ static void generateDistanceField(const egami::ImageMono& _input, egami::Image&
}
bool egami::generateDistanceFieldFile(const etk::String& _input, const etk::String& _output) {
bool egami::generateDistanceFieldFile(const etk::Uri& _input, const etk::Uri& _output) {
egami::Image data;
if (etk::end_with(_input, ".edf") == true) {
etk::String extention = etk::toLower(_input.getPath().getExtention());
if (extention == "edf") {
return false;
}
EGAMI_ERROR("Generate distance field : '" << _input << "' ==> '" << _output << "'");

View File

@ -11,14 +11,15 @@
#include <etk/Color.hpp>
#include <egami/Image.hpp>
#include <egami/ImageMono.hpp>
#include <etk/uri/Uri.hpp>
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<uint8_t>& _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);
}

View File

@ -8,7 +8,7 @@
#include <egami/debug.hpp>
#include <egami/Image.hpp>
#include <egami/wrapperBMP.hpp>
#include <etk/os/FSNode.hpp>
#include <etk/uri/uri.hpp>
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<uint8_t> allData = fileName.fileReadAll<uint8_t>();
fileName.fileClose();
etk::Vector<uint8_t> allData = fileIo->readAll<uint8_t>();
fileIo->close();
return egami::loadBMP(allData);
}
@ -305,17 +304,20 @@ egami::Image egami::loadBMP(const etk::Vector<uint8_t>& _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<uint8_t> 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<uint8_t>& _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

View File

@ -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<uint8_t>& _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.

View File

@ -8,32 +8,32 @@
#include <egami/debug.hpp>
#include <egami/Image.hpp>
#include <egami/wrapperEDF.hpp>
#include <etk/os/FSNode.hpp>
#include <etk/uri/uri.hpp>
//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;
}

View File

@ -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);
}

View File

@ -8,7 +8,7 @@
#include <egami/debug.hpp>
#include <egami/Image.hpp>
#include <egami/wrapperJPG.hpp>
#include <etk/os/FSNode.hpp>
#include <etk/uri/uri.hpp>
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<uint8_t> allData = fileName.fileReadAll<uint8_t>();
fileName.fileClose();
etk::Vector<uint8_t> allData = fileIo->readAll<uint8_t>();
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<uint8_t> allData;
bool ret = storeJPG(allData, _inputImage);
fileName.fileWriteAll(allData);
fileName.fileClose();
fileIo->writeAll(allData);
fileIo->close();
return ret;
}

View File

@ -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<uint8_t>& _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.

View File

@ -8,25 +8,10 @@
#include <egami/debug.hpp>
#include <egami/Image.hpp>
#include <egami/wrapperJPG2000.hpp>
#include <etk/os/FSNode.hpp>
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;
}

View File

@ -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);
}

View File

@ -8,7 +8,7 @@
#include <egami/debug.hpp>
#include <egami/Image.hpp>
#include <egami/wrapperPNG.hpp>
#include <etk/os/FSNode.hpp>
#include <etk/uri/uri.hpp>
#include <png/png.h>
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<etk::io::Interface> m_data;
public:
ReaderInstanceFSNode(etk::FSNode& _data):
ReaderInstancIOInterface(const ememory::SharedPtr<etk::io::Interface>& _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<uint8_t>& _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;
}

View File

@ -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<uint8_t>& _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.

View File

@ -8,15 +8,15 @@
#include <egami/debug.hpp>
#include <egami/Image.hpp>
#include <egami/wrapperSVG.hpp>
#include <etk/os/FSNode.hpp>
#include <etk/uri/uri.hpp>
#include <esvg/esvg.hpp>
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;

View File

@ -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));
}

View File

@ -8,26 +8,10 @@
#include <egami/debug.hpp>
#include <egami/Image.hpp>
#include <egami/wrapperTIFF.hpp>
#include <etk/os/FSNode.hpp>
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;
}

View File

@ -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);
}