Compare commits

...

6 Commits

29 changed files with 524 additions and 269 deletions

View File

@ -27,75 +27,76 @@
#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) {
EGAMI_ERROR("parse file '" << _uri << "' extention=" << extention);
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 +134,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 +303,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);
}

View File

@ -1,5 +1,5 @@
#!/usr/bin/python
import lutin.debug as debug
import realog.debug as debug
import lutin.tools as tools

View File

@ -1,5 +1,5 @@
#!/usr/bin/python
import lutin.debug as debug
import realog.debug as debug
import lutin.tools as tools

View File

@ -1,5 +1,5 @@
#!/usr/bin/python
import lutin.debug as debug
import realog.debug as debug
import lutin.tools as tools

View File

@ -19,29 +19,29 @@ static void readBMP() {
egami::Image image;
//! [egami_sample_declare_image]
//! [egami_sample_read_file_bmp]
image = egami::load("DATA:read.bmp");
image = egami::load("DATA:///read.bmp");
//! [egami_sample_read_file_bmp]
TEST_INFO("image exist (BMP): " << image.exist());
}
static void readSVG() {
//! [egami_sample_read_file_svg]
egami::Image image = egami::load("DATA:read.svg");
egami::Image image = egami::load("DATA:///read.svg");
//! [egami_sample_read_file_svg]
TEST_INFO("image exist (SVG): " << image.exist());
//! [egami_sample_read_file_svg_rescale]
image = egami::load("DATA:read.svg", ivec2(800,600));
image = egami::load("DATA:///read.svg", ivec2(800,600));
//! [egami_sample_read_file_svg_rescale]
TEST_INFO("image exist (SVG-rescale): " << image.exist());
//! [egami_sample_read_file_svg_scale_factor]
// TODO : image = egami::load("DATA:read.svg", 0.5);
// TODO : image = egami::load("DATA:///read.svg", 0.5);
//! [egami_sample_read_file_svg_scale_factor]
TEST_INFO("image exist (SVG-scale): " << image.exist());
}
static void readPNG() {
//! [egami_sample_read_file_png]
egami::Image image = egami::load("DATA:read_128x128.png");
egami::Image image = egami::load("DATA:///read_128x128.png");
//! [egami_sample_read_file_png]
TEST_INFO("image exist (PNG): " << image.exist());
}

View File

@ -18,7 +18,7 @@ int main(int argc, const char *argv[]) {
}
TEST(TestBMP, read_227x149) {
egami::Image image = egami::load("DATA:read_227x149.bmp");
egami::Image image = egami::load("DATA:///read_227x149.bmp");
egami::store(image, "out/read_227x149.bmp.bmp");
// Check if image is loaded
EXPECT_EQ(true, image.exist());
@ -32,7 +32,7 @@ TEST(TestBMP, read_227x149) {
}
TEST(TestBMP, read_128x128) {
egami::Image image = egami::load("DATA:read_128x128.bmp");
egami::Image image = egami::load("DATA:///read_128x128.bmp");
egami::store(image, "out/read_128x128.bmp.bmp");
// Check if image is loaded
EXPECT_EQ(true, image.exist());
@ -47,7 +47,7 @@ TEST(TestBMP, read_128x128) {
TEST(TestPNG, read_227x149) {
egami::Image image = egami::load("DATA:read_227x149.png");
egami::Image image = egami::load("DATA:///read_227x149.png");
egami::store(image, "out/read.png_227x149.bmp");
// Check if image is loaded
EXPECT_EQ(true, image.exist());
@ -61,7 +61,7 @@ TEST(TestPNG, read_227x149) {
}
TEST(TestPNG, read_128x128) {
egami::Image image = egami::load("DATA:read_128x128.png");
egami::Image image = egami::load("DATA:///read_128x128.png");
egami::store(image, "out/read_128x128.png.bmp");
// Check if image is loaded
EXPECT_EQ(true, image.exist());
@ -75,7 +75,7 @@ TEST(TestPNG, read_128x128) {
}
TEST(TestSVG, read) {
egami::Image image = egami::load("DATA:read.svg");
egami::Image image = egami::load("DATA:///read.svg");
egami::store(image, "out/read.svg.bmp");
// Check if image is loaded
EXPECT_EQ(true, image.exist());
@ -90,7 +90,7 @@ TEST(TestSVG, read) {
TEST(TestJPG, read_227x149) {
egami::Image image = egami::load("DATA:read_227x149.jpg");
egami::Image image = egami::load("DATA:///read_227x149.jpg");
egami::store(image, "out/read_227x149.jpg.bmp");
// Check if image is loaded
EXPECT_EQ(true, image.exist());
@ -105,7 +105,7 @@ TEST(TestJPG, read_227x149) {
TEST(TestJPG, read_128x128) {
egami::Image image = egami::load("DATA:read_128x128.jpg");
egami::Image image = egami::load("DATA:///read_128x128.jpg");
egami::store(image, "out/read_128x128.jpg.bmp");
// Check if image is loaded
EXPECT_EQ(true, image.exist());

View File

@ -0,0 +1,13 @@
/** @file
* @author Edouard DUPIN
* @copyright 2010, Edouard DUPIN, all right reserved
* @license GPL v3 (see license file)
*/
#include <appl/debug.hpp>
int32_t appl::getLogId() {
static int32_t g_val = elog::registerInstance("egami-cutter");
return g_val;
}

View File

@ -0,0 +1,46 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <elog/log.hpp>
extern "C" {
#include <assert.h>
}
namespace appl {
/**
* @brief Get local id of the library
* @return Unique ID of the library
*/
int32_t getLogId();
};
#define APPL_BASIC(info,data) ELOG_BASE(appl::getLogId(),info,data)
#define APPL_PRINT(data) APPL_BASIC(-1, data)
#define APPL_CRITICAL(data) APPL_BASIC(1, data)
#define APPL_ERROR(data) APPL_BASIC(2, data)
#define APPL_WARNING(data) APPL_BASIC(3, data)
#ifdef DEBUG
#define APPL_INFO(data) APPL_BASIC(4, data)
#define APPL_DEBUG(data) APPL_BASIC(5, data)
#define APPL_VERBOSE(data) APPL_BASIC(6, data)
#define APPL_TODO(data) APPL_BASIC(4, "TODO : " << data)
#else
#define APPL_INFO(data) do { } while(false)
#define APPL_DEBUG(data) do { } while(false)
#define APPL_VERBOSE(data) do { } while(false)
#define APPL_TODO(data) do { } while(false)
#endif
#define APPL_HIDDEN(data) do { } while(false)
#define APPL_ASSERT(cond,data) \
do { \
if (!(cond)) { \
APPL_CRITICAL(data); \
assert(!#cond); \
} \
} while (0)

166
tools/cutter/appl/main.cpp Normal file
View File

@ -0,0 +1,166 @@
/** @file
* @author Edouard DUPIN
* @copyright 2016, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <appl/debug.hpp>
#include <etk/etk.hpp>
#include <egami/egami.hpp>
static void usage(int _retValue = 0) {
APPL_PRINT("Help : ");
APPL_PRINT(" ./xxx [options]");
APPL_PRINT(" -h/--help: Display this help");
APPL_PRINT(" -i/--input: Input of the calculator");
APPL_PRINT(" -o/--output: Output of the calculator");
exit(_retValue);
}
int main(int argc, const char *argv[]) {
// the only one init for etk:
etk::init(argc, argv);
etk::Path input;
etk::Path output;
for (int32_t iii=0; iii<argc ; ++iii) {
etk::String data = argv[iii];
if ( data == "-h"
|| data == "--help") {
usage();
} else if (data.startWith("-i=") == true) {
input = etk::String(data.begin() + 3, data.end());
} else if (data.startWith("--input=") == true) {
input = etk::String(data.begin() + 8, data.end());
} else if (data.startWith("-o=") == true) {
output = etk::String(data.begin() + 3, data.end());
} else if (data.startWith("--output=") == true) {
output = etk::String(data.begin() + 9, data.end());
}
}
if (input == "") {
APPL_ERROR("Missing Input ...");
usage(-1);
}
if (output == "") {
APPL_ERROR("Missing output ...");
usage(-1);
}
APPL_INFO("read [START] " << input);
egami::Image image;
image = egami::load(input);
if (image.exist() == false) {
APPL_ERROR("read [STOP ] ==> an error occured...");
return -2;
}
APPL_INFO("read [STOP ]");
ivec2 middle = image.getSize() / 2;
APPL_INFO("Source Image Size:" << image.getSize());
uint8_t baseValue = 0x40;
// top:
uint_t posTop = 0;
uint_t posBottom = image.getSize().y();
uint_t posLeft = 0;
uint_t posRight = image.getSize().x();
uint_t maxOutOfRange = 3;
for (uint_t yyy=0; yyy<middle.y()-maxOutOfRange; ++yyy) {
bool found = false;
//APPL_DEBUG("Check position:" << yyy);
for (uint_t iii=0; iii<maxOutOfRange; ++iii) {
auto val1 = image.get(ivec2(middle.x(), yyy+iii));
//APPL_VERBOSE("Check value:" << iii << " " << val1);
if ( val1.r() < baseValue
&& val1.g() < baseValue
&& val1.b() < baseValue) {
found = true;
break;
}
}
if (found == true) {
continue;
}
posTop = yyy;
break;
}
APPL_INFO("Clip on TOP:" << posTop);
for (uint_t yyy=image.getSize().y()-1; yyy>=middle.y()+maxOutOfRange; --yyy) {
bool found = false;
//APPL_DEBUG("Check position:" << yyy);
for (uint_t iii=0; iii<maxOutOfRange; ++iii) {
auto val1 = image.get(ivec2(middle.x(), yyy-iii));
//APPL_VERBOSE("Check value:" << iii << " " << val1);
if ( val1.r() < baseValue
&& val1.g() < baseValue
&& val1.b() < baseValue) {
found = true;
break;
}
}
if (found == true) {
continue;
}
posBottom = yyy;
break;
}
APPL_INFO("Clip on BOTTOM:" << posBottom);
for (uint_t xxx=0; xxx<middle.x()-maxOutOfRange; ++xxx) {
bool found = false;
//APPL_DEBUG("Check position:" << yyy);
for (uint_t iii=0; iii<maxOutOfRange; ++iii) {
auto val1 = image.get(ivec2(xxx+iii, middle.y()));
//APPL_VERBOSE("Check value:" << iii << " " << val1);
if ( val1.r() < baseValue
&& val1.g() < baseValue
&& val1.b() < baseValue) {
found = true;
break;
}
}
if (found == true) {
continue;
}
posLeft = xxx;
break;
}
APPL_INFO("Clip on LEFT:" << posLeft);
for (uint_t xxx=image.getSize().x()-1; xxx>=middle.x()+maxOutOfRange; --xxx) {
bool found = false;
//APPL_DEBUG("Check position:" << yyy);
for (uint_t iii=0; iii<maxOutOfRange; ++iii) {
auto val1 = image.get(ivec2(xxx-iii, middle.y()));
//APPL_VERBOSE("Check value:" << iii << " " << val1);
if ( val1.r() < baseValue
&& val1.g() < baseValue
&& val1.b() < baseValue) {
found = true;
break;
}
}
if (found == true) {
continue;
}
posRight = xxx;
break;
}
APPL_INFO("Clip on Right:" << posRight);
image.resize(ivec2(image.getSize().x() - posLeft - (image.getSize().x() - posRight),
image.getSize().y() - posTop - (image.getSize().y() - posBottom)),
ivec2(posLeft, posTop));
APPL_INFO("output Image Size:" << image.getSize());
APPL_INFO("write [START] " << output);
bool ret = egami::store(image, output);
if (ret == false) {
APPL_ERROR("write [STOP ] ==> an error occured...");
return -3;
}
APPL_INFO("write [STOP ]");
return 0;
}

View File

@ -0,0 +1,46 @@
#!/usr/bin/python
import realog.debug as debug
import lutin.tools as tools
import os
def get_type():
return "BINARY"
def get_sub_type():
return "TOOL"
def get_desc():
return "egami simple image cutter (bash tools)"
def get_licence():
return "MPL-2"
def get_compagny_type():
return "com"
def get_compagny_name():
return "atria-soft"
def get_maintainer():
return ["Mr DUPIN Edouard <yui.heero@gmail.com>"]
def configure(target, my_module):
# add the file to compile:
my_module.add_src_file([
'appl/debug.cpp',
'appl/main.cpp',
])
my_module.add_depend([
'egami',
])
#my_module.copy_file('data/icon.png','icon.png')
my_module.add_path(".")
return True

View File

@ -10,7 +10,6 @@
#include <ewol/widget/Image.hpp>
#include <ewol/context/Context.hpp>
#include <etk/os/FSNode.hpp>
#include <eproperty/Value.hpp>
appl::MainWindows::MainWindows() :
@ -21,7 +20,7 @@ appl::MainWindows::MainWindows() :
void appl::MainWindows::init() {
ewol::widget::Windows::init();
m_image = ewol::widget::Image::create("src", etk::String("DATA:icon.png"),
m_image = ewol::widget::Image::create("src", etk::String("DATA:///icon.png"),
"expand", bvec2(true,true),
"fill", bvec2(true,true));
propertyTitle.set("EVI");
@ -42,16 +41,16 @@ void appl::MainWindows::onCallbackShortCut(const etk::String& _value) {
}
}
void appl::MainWindows::setListOfFiles(etk::Vector<etk::String> _listImages) {
void appl::MainWindows::setListOfFiles(etk::Vector<etk::Path> _listImages) {
m_listImages = _listImages;
if (m_listImages.size() == 0) {
m_idDisplayed = -1;
m_image->propertySource.set("DATA:icon.png");
m_image->propertySource.set("DATA:///icon.png");
propertyTitle.set("EVI");
} else {
m_idDisplayed = 0;
m_image->propertySource.set(m_listImages[0]);
propertyTitle.set("EVI:" + m_listImages[0]);
propertyTitle.set("EVI:" + m_listImages[0].getString());
}
}
@ -74,7 +73,7 @@ bool appl::MainWindows::onEventEntry(const ewol::event::Entry& _event) {
return true;
}
m_image->propertySource.set(m_listImages[m_idDisplayed]);
propertyTitle.set("EVI:" + m_listImages[m_idDisplayed] + " " + etk::toString(m_idDisplayed+1) + "/" + etk::toString(m_listImages.size()));
propertyTitle.set("EVI:" + m_listImages[m_idDisplayed].getString() + " " + etk::toString(m_idDisplayed+1) + "/" + etk::toString(m_listImages.size()));
return true;
}
if (_event.getType() == gale::key::keyboard::left) {
@ -84,7 +83,7 @@ bool appl::MainWindows::onEventEntry(const ewol::event::Entry& _event) {
return true;
}
m_image->propertySource.set(m_listImages[m_idDisplayed]);
propertyTitle.set("EVI:" + m_listImages[m_idDisplayed] + " " + etk::toString(m_idDisplayed+1) + "/" + etk::toString(m_listImages.size()));
propertyTitle.set("EVI:" + m_listImages[m_idDisplayed].getString() + " " + etk::toString(m_idDisplayed+1) + "/" + etk::toString(m_listImages.size()));
return true;
}
if (_event.getType() == gale::key::keyboard::down) {
@ -93,7 +92,7 @@ bool appl::MainWindows::onEventEntry(const ewol::event::Entry& _event) {
m_idDisplayed = m_listImages.size()-1;
}
m_image->propertySource.set(m_listImages[m_idDisplayed]);
propertyTitle.set("EVI:" + m_listImages[m_idDisplayed] + " " + etk::toString(m_idDisplayed+1) + "/" + etk::toString(m_listImages.size()));
propertyTitle.set("EVI:" + m_listImages[m_idDisplayed].getString() + " " + etk::toString(m_idDisplayed+1) + "/" + etk::toString(m_listImages.size()));
return true;
}
if (_event.getType() == gale::key::keyboard::up) {
@ -102,19 +101,19 @@ bool appl::MainWindows::onEventEntry(const ewol::event::Entry& _event) {
m_idDisplayed = 0;
}
m_image->propertySource.set(m_listImages[m_idDisplayed]);
propertyTitle.set("EVI:" + m_listImages[m_idDisplayed] + " " + etk::toString(m_idDisplayed+1) + "/" + etk::toString(m_listImages.size()));
propertyTitle.set("EVI:" + m_listImages[m_idDisplayed].getString() + " " + etk::toString(m_idDisplayed+1) + "/" + etk::toString(m_listImages.size()));
return true;
}
if (_event.getType() == gale::key::keyboard::pageDown) {
m_idDisplayed = m_listImages.size()-1;
m_image->propertySource.set(m_listImages[m_idDisplayed]);
propertyTitle.set("EVI:" + m_listImages[m_idDisplayed] + " " + etk::toString(m_idDisplayed+1) + "/" + etk::toString(m_listImages.size()));
propertyTitle.set("EVI:" + m_listImages[m_idDisplayed].getString() + " " + etk::toString(m_idDisplayed+1) + "/" + etk::toString(m_listImages.size()));
return true;
}
if (_event.getType() == gale::key::keyboard::pageUp) {
m_idDisplayed = 0;
m_image->propertySource.set(m_listImages[m_idDisplayed]);
propertyTitle.set("EVI:" + m_listImages[m_idDisplayed] + " " + etk::toString(m_idDisplayed+1) + "/" + etk::toString(m_listImages.size()));
propertyTitle.set("EVI:" + m_listImages[m_idDisplayed].getString() + " " + etk::toString(m_idDisplayed+1) + "/" + etk::toString(m_listImages.size()));
return true;
}
}

View File

@ -13,7 +13,7 @@ namespace appl {
class MainWindows : public ewol::widget::Windows {
private:
ewol::widget::ImageShared m_image;
etk::Vector<etk::String> m_listImages;
etk::Vector<etk::Path> m_listImages;
int64_t m_idDisplayed;
public:
// Constructeur
@ -22,7 +22,7 @@ namespace appl {
public:
DECLARE_FACTORY(MainWindows);
~MainWindows() {};
void setListOfFiles(etk::Vector<etk::String> _listImages);
void setListOfFiles(etk::Vector<etk::Path> _listImages);
protected:
void onCallbackShortCut(const etk::String& _value);
bool onEventInput(const ewol::event::Input& _event) override;

View File

@ -6,7 +6,8 @@
#include <etk/types.hpp>
#include <etk/types.hpp>
#include <etk/os/FSNode.hpp>
#include <etk/theme/theme.hpp>
#include <etk/path/fileSystem.hpp>
#include <ewol/ewol.hpp>
#include <ewol/object/Object.hpp>
#include <ewol/context/Context.hpp>
@ -17,7 +18,7 @@
namespace appl {
class MainApplication : public ewol::context::Application {
private:
etk::Vector<etk::String> m_listFiles;
etk::Vector<etk::Path> m_listFiles;
public:
virtual void onCreate(ewol::Context& _context) {
APPL_INFO(" == > CREATE ... (START) [" << gale::getBoardType() << "] (" << gale::getCompilationMode() << ") (BEGIN)");
@ -35,19 +36,16 @@ namespace appl {
continue;
}
// TODO : Check if it is a path ...
if (etk::FSNodeExist(tmpppp) == false) {
if (etk::path::exist(tmpppp) == false) {
APPL_ERROR("element does not exist: '" << tmpppp << "' ==> rejected");
} else {
etk::FSNode elem(tmpppp);
if (elem.getNodeType() == etk::typeNode_folder) {
etk::Vector<etk::String> tmp = elem.folderGetSub(false, true, ".*");
tmp.sort(0, tmp.size(), [](const etk::String& _left, const etk::String& _right) { return _left < _right;});
for (auto &it : tmp) {
if (etk::path::isFile(tmpppp) == true) {
m_listFiles.pushBack(tmpppp);
} else {
etk::Vector<etk::Path> list = etk::path::list(tmpppp, etk::path::LIST_FILE);
for (auto &it : list) {
m_listFiles.pushBack(it);
}
} else {
// simple file:
m_listFiles.pushBack(tmpppp);
}
}
}
@ -67,7 +65,7 @@ namespace appl {
#endif
// set the application icon ...
_context.setIcon("DATA:icon.png");
_context.setIcon("DATA:///icon.png");
APPL_INFO("==> CREATE ... (END)");
}

View File

@ -1,5 +1,5 @@
#!/usr/bin/python
import lutin.debug as debug
import realog.debug as debug
import lutin.tools as tools
import os