diff --git a/data/read_128x128.bmp b/data/read_128x128.bmp new file mode 100644 index 0000000..addc4a4 Binary files /dev/null and b/data/read_128x128.bmp differ diff --git a/data/read_128x128.jpg b/data/read_128x128.jpg new file mode 100644 index 0000000..88bdd1f Binary files /dev/null and b/data/read_128x128.jpg differ diff --git a/data/read_128x128.png b/data/read_128x128.png new file mode 100644 index 0000000..69ead76 Binary files /dev/null and b/data/read_128x128.png differ diff --git a/data/read.bmp b/data/read_227x149.bmp similarity index 100% rename from data/read.bmp rename to data/read_227x149.bmp diff --git a/data/read.jpg b/data/read_227x149.jpg similarity index 100% rename from data/read.jpg rename to data/read_227x149.jpg diff --git a/data/read.png b/data/read_227x149.png similarity index 100% rename from data/read.png rename to data/read_227x149.png diff --git a/data/read_228x149.bmp b/data/read_228x149.bmp new file mode 100644 index 0000000..29005da Binary files /dev/null and b/data/read_228x149.bmp differ diff --git a/egami/Image.cpp b/egami/Image.cpp index db449b3..82123d9 100644 --- a/egami/Image.cpp +++ b/egami/Image.cpp @@ -149,7 +149,7 @@ void egami::Image::resize(const ivec2& _size, const ivec2& _startPos) { EGAMI_DEBUG("No internal data for image (nullptr)"); return; } - m_data->resize(_size, _startPos); + m_data->resize2(_size, _startPos); } void egami::Image::resize(const ivec2& _size, const etk::Color<>& _color, const ivec2& _startPos) { diff --git a/egami/Image.hpp b/egami/Image.hpp index bd95694..35bfa56 100644 --- a/egami/Image.hpp +++ b/egami/Image.hpp @@ -57,7 +57,7 @@ namespace egami { virtual void resize(const ivec2& _size, const etk::Color& _color, const ivec2& _startPos) = 0; virtual void resize(const ivec2& _size, const etk::Color& _color, const ivec2& _startPos) = 0; virtual void resize(const ivec2& _size, const etk::Color& _color, const ivec2& _startPos) = 0; - virtual void resize(const ivec2& _size, const ivec2& _startPos) = 0; + virtual void resize2(const ivec2& _size, const ivec2& _startPos) = 0; virtual void set(const ivec2& _pos, const etk::Color<>& _newColor) = 0; virtual void set(const ivec2& _pos, const etk::Color& _newColor) = 0; virtual void set(const ivec2& _pos, const etk::Color& _newColor) = 0; diff --git a/egami/ImagePrivate.hpp b/egami/ImagePrivate.hpp index e5ef2cd..08b65c0 100644 --- a/egami/ImagePrivate.hpp +++ b/egami/ImagePrivate.hpp @@ -14,18 +14,18 @@ namespace egami { - template> + template> class ImageTemplate : public ImagePrivate { private: ivec2 m_size; - std::vector m_data; + std::vector m_data; public: // constructor : ImageTemplate(const ivec2& _size=ivec2(32,32)) : m_size(_size) { - // basic element : + // basic element: etk::Color<> tmpBg(0,0,0,0); - // preallocate data with a basic bg elements : + // preallocate data with a basic bg elements: m_data.resize(m_size.x()*m_size.y(), tmpBg); if ((uint32_t)m_size.x()*m_size.y() > m_data.size()) { //TK_ERROR("Allocation of data buffer in error"); @@ -35,7 +35,7 @@ namespace egami { // destructor virtual ~ImageTemplate() { }; - // EWOL internal API for Texture system : + // EWOL internal API for Texture system: public: void* getTextureDataPointer() { return &m_data[0]; @@ -45,60 +45,74 @@ namespace egami { return m_size; }; // ----------------------------------------------- - // -- basic tools : + // -- basic tools: // ----------------------------------------------- public : - void resize__(const ivec2& _size, const ivec2& _startPos=ivec2(0,0)) { + void resize2__(const ivec2& _size, const ivec2& _startPos=ivec2(0,0)) { if (_size == m_size) { // same size == > nothing to do ... return; } - if ((size_t)(_size.x()*_size.y()) > m_data.size()) { - m_data.resize(_size.x()*_size.y()); + ivec2 oldSize = m_size; + m_size = _size; + if ((size_t)(m_size.x()*m_size.y()) > m_data.size()) { + m_data.resize(m_size.x()*m_size.y()); } // grow size : - if (_size.x() == m_size.x()) { - if (_size.y() < m_size.y()) { + if (m_size.x() == oldSize.x()) { + if (m_size.y() < oldSize.y()) { // Just remove lines .... } else { // just add lines } - } else if (_size.x() < m_size.x()) { - if (_size.y() <= m_size.y()) { - for (int32_t yyy=0; yyy<_size.y(); ++yyy) { - for (int32_t xxx=0; xxx<_size.x(); ++xxx) { - m_data[yyy*_size.x()+xxx] = m_data[yyy*m_size.x()+xxx]; + } else if (m_size.x() < oldSize.x()) { + if (m_size.y() <= oldSize.y()) { + for (int32_t yyy=0; yyy=0; --yyy) { - for (int32_t xxx=0; xxx<_size.x(); ++xxx) { - m_data[yyy*_size.x()+xxx] = m_data[yyy*m_size.x()+xxx]; + for (int32_t yyy=oldSize.y()-1; yyy>=0; --yyy) { + for (int32_t xxx=0; xxx m_size.x()) + } else { // (m_size.x() > oldSize.x()) - if (_size.y() <= m_size.y()) { - for (int32_t yyy=0; yyy<_size.y(); ++yyy) { - for (int32_t xxx=0; xxx=0; --yyy) { - for (int32_t xxx=0; xxx=0; --yyy) { + for (int32_t xxx=0; xxx tmpBg(0,0,0,0); + for (int32_t yyy=oldSize.y()-1; yyy void resize(const ivec2& _size, const TYPE_2& _color) { - T tmp(_color); + template void resize(const ivec2& _size, const EGAMI_TYPE_COLOR_2& _color) { + EGAMI_TYPE_COLOR tmp(_color); resize__(_size, tmp); } void set(const ivec2& _pos, const etk::Color<>& _newColor) { @@ -157,33 +171,33 @@ namespace egami { int32_t getHeight() const { return m_size.y(); }; - void clearColor(const T& _fill) { + void clearColor(const EGAMI_TYPE_COLOR& _fill) { for (int32_t iii=0; iii get(const ivec2& _pos) const { return get__(_pos); } - const T& get__(const ivec2& _pos) const { - static const T errorColor(0x00000000); + const EGAMI_TYPE_COLOR& get__(const ivec2& _pos) const { + static const EGAMI_TYPE_COLOR errorColor(0x00000000); if( _pos.x()>=0 && _pos.x()=0 && _pos.y()=0 && _pos.x()=0 && _pos.y()& _input) { + void insert(const ivec2& _pos, const ImageTemplate& _input) { for(int32_t yyy = 0; yyy < _input.getSize().y() && _pos.y() + yyy < m_size.y(); ++yyy) { for(int32_t xxx = 0; xxx < _input.getSize().x() && _pos.x() + xxx < m_size.x(); ++xxx) { set(ivec2(_pos.x()+xxx, _pos.y()+yyy), _input.get(ivec2(xxx, yyy)) ); diff --git a/egami/wrapperBMP.cpp b/egami/wrapperBMP.cpp index 3c0045a..ae7add1 100644 --- a/egami/wrapperBMP.cpp +++ b/egami/wrapperBMP.cpp @@ -27,8 +27,28 @@ extern "C" { int32_t biSizeImage; int32_t biXPelsPerMeter; int32_t biYPelsPerMeter; - int32_t biClrUsed; - int32_t biClrImportant; + int32_t biPaletteNumber; + int32_t biImportantColor; + }; + struct bitmapInfoHeaderExtended { + int32_t biSize; + int32_t biWidth; + int32_t biHeight; + int16_t biPlanes; + int16_t biBitCount; + int32_t biCompression; + int32_t biSizeImage; + int32_t biXPelsPerMeter; + int32_t biYPelsPerMeter; + // https://en.wikipedia.org/wiki/BMP_file_format / example 2 + int32_t biPaletteNumber; + int32_t biImportantColor; + int32_t biLCSColorSpace; // This is at this position, inspection of "gimp" output ... + int32_t biBitMaskRed; + int32_t biBitMaskGreen; + int32_t biBitMaskBlue; + int32_t biBitMaskAlpha; + int32_t biUnused[12]; }; #pragma pack(pop) } @@ -59,8 +79,8 @@ static void display(struct bitmapFileHeader _header, struct bitmapInfoHeader _in EGAMI_DEBUG(" biSizeImage =" << _info.biSizeImage << " specifies the size of the image data, in bytes. If there is no compression, it is valid to set this member to zero."); EGAMI_DEBUG(" biXPelsPerMeter=" << _info.biXPelsPerMeter << " specifies the the horizontal pixels per meter on the designated targer device, usually set to zero."); EGAMI_DEBUG(" biYPelsPerMeter=" << _info.biYPelsPerMeter << " specifies the the vertical pixels per meter on the designated targer device, usually set to zero."); - EGAMI_DEBUG(" biClrUsed =" << _info.biClrUsed << " speglTexImage2Dcifies the number of colors used in the bitmap, if set to zero the number of colors is calculated using the biBitCount member."); - EGAMI_DEBUG(" biClrImportant =" << _info.biClrImportant << " specifies the number of color that are 'important' for the bitmap, if set to zero, all colors are important."); + EGAMI_DEBUG(" biClrUsed =" << _info.biPaletteNumber << " Pallet color number."); + EGAMI_DEBUG(" biClrImportant =" << _info.biImportantColor << " Important color ID."); /* EGAMI_DEBUG("Bitmap : " << m_width << "x" << m_height); switch(m_dataMode) @@ -94,7 +114,9 @@ egami::Image egami::loadBMP(const std::string& _inputFile) { int32_t m_width = 0; int32_t m_height = 0; struct bitmapFileHeader m_FileHeader; + bool useExtended = false; struct bitmapInfoHeader m_InfoHeader; + struct bitmapInfoHeaderExtended m_InfoHeaderExtended; etk::FSNode fileName(_inputFile); // get the fileSize ... @@ -116,10 +138,32 @@ egami::Image egami::loadBMP(const std::string& _inputFile) { fileName.fileClose(); return out; } - if (fileName.fileRead(&m_InfoHeader,sizeof(struct bitmapInfoHeader),1) != 1) { - EGAMI_ERROR("error loading file header"); - fileName.fileClose(); - return out; + if (m_FileHeader.bfOffBits > sizeof(struct bitmapFileHeader) + sizeof(struct bitmapInfoHeader)) { + EGAMI_WARNING("Read bitmap in EXTENDED mode ..."); + if (fileName.fileRead(&m_InfoHeaderExtended,sizeof(struct bitmapInfoHeaderExtended),1) != 1) { + EGAMI_ERROR("error loading file header"); + fileName.fileClose(); + return out; + } + useExtended = true; + m_InfoHeader.biSize = m_InfoHeaderExtended.biSize; + m_InfoHeader.biWidth = m_InfoHeaderExtended.biWidth; + m_InfoHeader.biHeight = m_InfoHeaderExtended.biHeight; + m_InfoHeader.biHeight = m_InfoHeaderExtended.biHeight; + m_InfoHeader.biHeight = m_InfoHeaderExtended.biHeight; + m_InfoHeader.biBitCount = m_InfoHeaderExtended.biBitCount; + m_InfoHeader.biCompression = m_InfoHeaderExtended.biCompression; + m_InfoHeader.biSizeImage = m_InfoHeaderExtended.biSizeImage; + m_InfoHeader.biXPelsPerMeter = m_InfoHeaderExtended.biXPelsPerMeter; + m_InfoHeader.biYPelsPerMeter = m_InfoHeaderExtended.biYPelsPerMeter; + } else { + EGAMI_WARNING("Read bitmap in BASIC mode ..."); + if (fileName.fileRead(&m_InfoHeader,sizeof(struct bitmapInfoHeader),1) != 1) { + EGAMI_ERROR("error loading file header"); + fileName.fileClose(); + return out; + } + useExtended = false; } //display(m_FileHeader, m_InfoHeader); //EGAMI_ERROR("plopppppppppppppp " << m_FileHeader.bfOffBits); @@ -166,6 +210,7 @@ egami::Image egami::loadBMP(const std::string& _inputFile) { fileName.fileClose();; return out; } + std::vector m_data; if(m_InfoHeader.biSizeImage != 0) { m_data.resize(m_InfoHeader.biSizeImage, 0); @@ -183,11 +228,11 @@ egami::Image egami::loadBMP(const std::string& _inputFile) { uint16_t * pointer = (uint16_t*)(&m_data[0]); for(int32_t yyy=0; yyy> 8)); + tmpColor.setB((uint8_t)((*pointer & 0xF800) >> 8)); tmpColor.setG((uint8_t)((*pointer & 0x07E0) >> 3)); - tmpColor.setB((uint8_t)(*pointer << 3)); + tmpColor.setR((uint8_t)(*pointer << 3)); tmpColor.setA(0xFF); - out.set(ivec2(xxx,yyy), tmpColor); + out.set(ivec2(xxx,m_height-yyy-1), tmpColor); pointer++; } } @@ -197,11 +242,11 @@ egami::Image egami::loadBMP(const std::string& _inputFile) { uint16_t * pointer = (uint16_t*)(&m_data[0]); for(int32_t yyy=0; yyy> 7)); + tmpColor.setB((int8_t)((*pointer & 0x7C00) >> 7)); tmpColor.setG((int8_t)((*pointer & 0x03E0) >> 2)); - tmpColor.setB((int8_t)(*pointer << 3)); + tmpColor.setR((int8_t)(*pointer << 3)); tmpColor.setA(0xFF); - out.set(ivec2(xxx,yyy), tmpColor); + out.set(ivec2(xxx,m_height-yyy-1), tmpColor); pointer++; } } @@ -220,16 +265,15 @@ egami::Image egami::loadBMP(const std::string& _inputFile) { uint8_t * pointer = (&m_data[0]); for(int32_t yyy=0; yyy& tmpColor = _inputImage.get(ivec2(xxx,yyy)); + const etk::Color<>& tmpColor = _inputImage.get(ivec2(xxx,_inputImage.getSize().y()-yyy-1)); uint8_t* pointer = data; *pointer++ = tmpColor.r(); *pointer++ = tmpColor.g(); @@ -346,11 +397,11 @@ bool egami::storeBMP(const std::string& _fileName, const egami::Image& _inputIma uint8_t data[16]; for(int32_t yyy=0; yyy<_inputImage.getSize().y(); ++yyy) { for(int32_t xxx=0; xxx<_inputImage.getSize().x(); ++xxx) { - const etk::Color<>& tmpColor = _inputImage.get(ivec2(xxx,yyy)); + const etk::Color<>& tmpColor = _inputImage.get(ivec2(xxx,_inputImage.getSize().y()-yyy-1)); uint8_t* pointer = data; - *pointer++ = tmpColor.r(); - *pointer++ = tmpColor.g(); *pointer++ = tmpColor.b(); + *pointer++ = tmpColor.g(); + *pointer++ = tmpColor.r(); fileName.fileWrite(data,3,1); } if (offset != 0) { diff --git a/egami/wrapperJPG.cpp b/egami/wrapperJPG.cpp index 15bcf13..395e495 100644 --- a/egami/wrapperJPG.cpp +++ b/egami/wrapperJPG.cpp @@ -107,12 +107,13 @@ egami::Image egami::loadJPG(const std::string& _inputFile) { // Here we use the library's state variable cinfo.output_scanline as the loop counter, so that we don't have to keep track ourselves. - int32_t yyy = 1; + int32_t yyy = 0; while (cinfo.output_scanline < cinfo.output_height) { // Get a simple line: (void) jpeg_read_scanlines(&cinfo, buffer, 1); // Direst push on the output (got output format RGB8) - uint8_t* tmpp = dataOutPointer + (row_stride*(cinfo.output_height-yyy)); + //uint8_t* tmpp = dataOutPointer + (row_stride*(cinfo.output_height-yyy)); + uint8_t* tmpp = dataOutPointer + (row_stride*yyy); memcpy(tmpp, buffer[0], row_stride); yyy++; } diff --git a/egami/wrapperPNG.cpp b/egami/wrapperPNG.cpp index 25c2846..7cb2eef 100644 --- a/egami/wrapperPNG.cpp +++ b/egami/wrapperPNG.cpp @@ -211,7 +211,7 @@ egami::Image egami::loadPNG(const std::string& _inputFile) { for (png_uint_32 xxx = 0; xxx < width; ++xxx) { png_byte* ptr = &(row[xxx*4]); tmpColor.set(ptr[0], ptr[1], ptr[2], ptr[3]); - out.set(ivec2(xxx,height-yyy-1), tmpColor); + out.set(ivec2(xxx,yyy), tmpColor); } } break; @@ -223,7 +223,7 @@ egami::Image egami::loadPNG(const std::string& _inputFile) { for (png_uint_32 xxx = 0; xxx < width; ++xxx) { png_byte* ptr = &(row[xxx*3]); tmpColor.set(ptr[0], ptr[1], ptr[2]); - out.set(ivec2(xxx,height-yyy-1), tmpColor); + out.set(ivec2(xxx,yyy), tmpColor); } } break; @@ -235,7 +235,7 @@ egami::Image egami::loadPNG(const std::string& _inputFile) { for (png_uint_32 xxx = 0; xxx < width; ++xxx) { png_byte* ptr = &(row[xxx]); tmpColor.set(ptr[0], ptr[0], ptr[0]); - out.set(ivec2(xxx,height-yyy-1), tmpColor); + out.set(ivec2(xxx,yyy), tmpColor); } } break; @@ -247,7 +247,7 @@ egami::Image egami::loadPNG(const std::string& _inputFile) { for (png_uint_32 xxx = 0; xxx < width; ++xxx) { png_byte* ptr = &(row[xxx*2]); tmpColor.set(ptr[0], ptr[0], ptr[0], ptr[1]); - out.set(ivec2(xxx,height-yyy-1), tmpColor); + out.set(ivec2(xxx,yyy), tmpColor); } } break; diff --git a/lutinParseSubFolders.txt b/lutinParseSubFolders.txt new file mode 100644 index 0000000..89b1ecd --- /dev/null +++ b/lutinParseSubFolders.txt @@ -0,0 +1 @@ +tools/viewer \ No newline at end of file diff --git a/test/main.cpp b/test/main.cpp index c16c75a..41b02e7 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -20,9 +20,9 @@ int main(int argc, const char *argv[]) { return RUN_ALL_TESTS(); } -TEST(TestBMP, read) { - egami::Image image = egami::load("DATA:read.bmp"); - egami::store(image, "out/read.bmp.bmp"); +TEST(TestBMP, read_227x149) { + 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()); // check image correct size @@ -34,10 +34,38 @@ TEST(TestBMP, read) { EXPECT_EQ("3518a9693a349044d23c3a95262831144011086fdb339ef8532f9c6cebffe76b2c994b0a3e6d69addca15538a1cb559af3be445c5b622b5cf80c9291e7b8ca5b", sha512); } +TEST(TestBMP, read_128x128) { + 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()); + // check image correct size + EXPECT_EQ(ivec2(128,128), image.getSize()); + // check image correct type + EXPECT_EQ(egami::colorType::RGB8, image.getType()); + // check integrity + std::string sha512 = algue::stringConvert(algue::sha512::encode((const uint8_t *)image.getTextureDataPointer(), egami::getFormatColorSize(image.getType()) * image.getSize().x() * image.getSize().y())); + EXPECT_EQ("3518a9693a349044d23c3a95262831144011086fdb339ef8532f9c6cebffe76b2c994b0a3e6d69addca15538a1cb559af3be445c5b622b5cf80c9291e7b8ca5b", sha512); +} -TEST(TestPNG, read) { - egami::Image image = egami::load("DATA:read.png"); - egami::store(image, "out/read.png.bmp"); + +TEST(TestPNG, read_227x149) { + 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()); + // check image correct size + EXPECT_EQ(ivec2(227,149), image.getSize()); + // check image correct type + EXPECT_EQ(egami::colorType::RGB8, image.getType()); + // check integrity + std::string sha512 = algue::stringConvert(algue::sha512::encode((const uint8_t *)image.getTextureDataPointer(), egami::getFormatColorSize(image.getType()) * image.getSize().x() * image.getSize().y())); + EXPECT_EQ("42dbad7abf1e651da58c9df06521d63a878b5bd0db6e1cbe129db3c9782ce640a6709583ba9e6571d314f39b259321dcc392f98bf4412deb5ce8392566d2bc0f", sha512); +} + +TEST(TestPNG, read_128x128) { + 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()); // check image correct size @@ -64,9 +92,24 @@ TEST(TestSVG, read) { } -TEST(TestJPG, read) { - egami::Image image = egami::load("DATA:read.jpg"); - egami::store(image, "out/read.jpg.bmp"); +TEST(TestJPG, read_227x149) { + 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()); + // check image correct size + EXPECT_EQ(ivec2(227,149), image.getSize()); + // check image correct type + EXPECT_EQ(egami::colorType::RGB8, image.getType()); + // check integrity + std::string sha512 = algue::stringConvert(algue::sha512::encode((const uint8_t *)image.getTextureDataPointer(), egami::getFormatColorSize(image.getType()) * image.getSize().x() * image.getSize().y())); + EXPECT_EQ("42dbad7abf1e651da58c9df06521d63a878b5bd0db6e1cbe129db3c9782ce640a6709583ba9e6571d314f39b259321dcc392f98bf4412deb5ce8392566d2bc0f", sha512); +} + + +TEST(TestJPG, read_128x128) { + 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()); // check image correct size diff --git a/tools/viewer/appl/MainWindows.cpp b/tools/viewer/appl/MainWindows.cpp new file mode 100644 index 0000000..869a15d --- /dev/null +++ b/tools/viewer/appl/MainWindows.cpp @@ -0,0 +1,123 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2010, Edouard DUPIN, all right reserved + * @license BSD v3 (see license file) + */ + + +#include +#include + +#include +#include +#include +#include + +appl::MainWindows::MainWindows() : + m_idDisplayed(-1) { + APPL_DEBUG("CREATE WINDOWS ... "); + addObjectType("appl::MainWindows"); +} + +void appl::MainWindows::init() { + ewol::widget::Windows::init(); + m_image = ewol::widget::Image::create("src", std::string("DATA:icon.png"), + "expand", bvec2(true,true), + "fill", bvec2(true,true)); + propertyTitle.set("EVI"); + m_image->propertyExpand.set(bvec2(true,true)); + m_image->propertyFill.set(bvec2(true,true)); + setSubWidget(m_image); + shortCutAdd("F12", "menu:reloade-shader"); + signalShortcut.connect(sharedFromThis(), &appl::MainWindows::onCallbackShortCut); +} + +void appl::MainWindows::onCallbackShortCut(const std::string& _value) { + APPL_WARNING("Event from ShortCut : " << _value); + if (_value == "menu:reloade-shader") { + ewol::getContext().getResourcesManager().reLoadResources(); + ewol::getContext().forceRedrawAll(); + } else { + APPL_ERROR("Event from Menu UNKNOW : '" << _value << "'"); + } +} + +void appl::MainWindows::setListOfFiles(std::vector _listImages) { + m_listImages = _listImages; + if (m_listImages.size() == 0) { + m_idDisplayed = -1; + 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]); + } +} + +bool appl::MainWindows::onEventInput(const ewol::event::Input& _event) { + APPL_WARNING(" EVENT : " << _event); + return true; +} + +bool appl::MainWindows::onEventEntry(const ewol::event::Entry& _event) { + if (m_idDisplayed == -1) { + return false; + } + if (_event.getStatus() == gale::key::status::down) { + if ( ( _event.getType() == gale::key::keyboard::character + && _event.getChar() == ' ') + || _event.getType() == gale::key::keyboard::right) { + m_idDisplayed++; + if (m_idDisplayed >= m_listImages.size()) { + m_idDisplayed--; + return true; + } + m_image->propertySource.set(m_listImages[m_idDisplayed]); + propertyTitle.set("EVI:" + m_listImages[m_idDisplayed] + " " + etk::to_string(m_idDisplayed+1) + "/" + etk::to_string(m_listImages.size())); + return true; + } + if (_event.getType() == gale::key::keyboard::left) { + m_idDisplayed--; + if (m_idDisplayed < 0) { + m_idDisplayed++; + return true; + } + m_image->propertySource.set(m_listImages[m_idDisplayed]); + propertyTitle.set("EVI:" + m_listImages[m_idDisplayed] + " " + etk::to_string(m_idDisplayed+1) + "/" + etk::to_string(m_listImages.size())); + return true; + } + if (_event.getType() == gale::key::keyboard::down) { + m_idDisplayed += 10; + if (m_idDisplayed >= m_listImages.size()) { + m_idDisplayed = m_listImages.size()-1; + } + m_image->propertySource.set(m_listImages[m_idDisplayed]); + propertyTitle.set("EVI:" + m_listImages[m_idDisplayed] + " " + etk::to_string(m_idDisplayed+1) + "/" + etk::to_string(m_listImages.size())); + return true; + } + if (_event.getType() == gale::key::keyboard::up) { + m_idDisplayed -= 10; + if (m_idDisplayed < 0) { + m_idDisplayed = 0; + } + m_image->propertySource.set(m_listImages[m_idDisplayed]); + propertyTitle.set("EVI:" + m_listImages[m_idDisplayed] + " " + etk::to_string(m_idDisplayed+1) + "/" + etk::to_string(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::to_string(m_idDisplayed+1) + "/" + etk::to_string(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::to_string(m_idDisplayed+1) + "/" + etk::to_string(m_listImages.size())); + return true; + } + } + + return true; +} diff --git a/tools/viewer/appl/MainWindows.hpp b/tools/viewer/appl/MainWindows.hpp new file mode 100644 index 0000000..7354309 --- /dev/null +++ b/tools/viewer/appl/MainWindows.hpp @@ -0,0 +1,33 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2010, Edouard DUPIN, all right reserved + * @license BSD v3 (see license file) + */ +#pragma once + +#include +#include +#include +#include +namespace appl { + class MainWindows : public ewol::widget::Windows { + private: + ewol::widget::ImageShared m_image; + std::vector m_listImages; + int64_t m_idDisplayed; + public: + // Constructeur + MainWindows(); + void init() override; + public: + DECLARE_FACTORY(MainWindows); + ~MainWindows() {}; + void setListOfFiles(std::vector _listImages); + protected: + void onCallbackShortCut(const std::string& _value); + bool onEventInput(const ewol::event::Input& _event) override; + bool onEventEntry(const ewol::event::Entry& _event) override; + }; +}; + + diff --git a/tools/viewer/appl/debug.cpp b/tools/viewer/appl/debug.cpp new file mode 100644 index 0000000..8e5b2ee --- /dev/null +++ b/tools/viewer/appl/debug.cpp @@ -0,0 +1,13 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2010, Edouard DUPIN, all right reserved + * @license GPL v3 (see license file) + */ + + +#include + +int32_t appl::getLogId() { + static int32_t g_val = elog::registerInstance("egami-viewer"); + return g_val; +} diff --git a/tools/viewer/appl/debug.hpp b/tools/viewer/appl/debug.hpp new file mode 100644 index 0000000..5c66e6b --- /dev/null +++ b/tools/viewer/appl/debug.hpp @@ -0,0 +1,45 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license APACHE v2.0 (see license file) + */ +#pragma once + +#include +#include + +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) diff --git a/tools/viewer/appl/init.cpp b/tools/viewer/appl/init.cpp new file mode 100644 index 0000000..a1d791d --- /dev/null +++ b/tools/viewer/appl/init.cpp @@ -0,0 +1,117 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2010, Edouard DUPIN, all right reserved + * @license BSD v3 (see license file) + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +class MainApplication : public ewol::context::Application { + private: + std::vector m_listFiles; + public: + virtual void onCreate(ewol::Context& _context) { + APPL_INFO(" == > CREATE ... (START) [" << gale::getBoardType() << "] (" << gale::getCompilationMode() << ") (BEGIN)"); + for( int32_t iii=0 ; iii<_context.getCmd().size(); iii++) { + std::string tmpppp = _context.getCmd().get(iii); + if ( tmpppp == "-h" + || tmpppp == "--help") { + APPL_INFO(" -t c-flags-file-name" ); + APPL_INFO(" -h/--help display this help" ); + exit(0); + } + if ( tmpppp.size()>=2 + && tmpppp[0] == '-' + && tmpppp[1] == '-') { + continue; + } + // TODO : Check if it is a path ... + if (etk::FSNodeExist(tmpppp) == false) { + APPL_ERROR("element does not exist: '" << tmpppp << "' ==> rejected"); + } else { + etk::FSNode elem(tmpppp); + if (elem.getNodeType() == etk::typeNode_folder) { + std::vector tmp = elem.folderGetSub(false, true, ".*"); + std::sort(tmp.begin(), tmp.end()); + for (auto &it : tmp) { + m_listFiles.push_back(it); + } + } else { + // simple file: + m_listFiles.push_back(tmpppp); + } + } + } + //etk::theme::setName("COLOR", "color/black/"); + etk::theme::setName("COLOR", "color/white/"); + + _context.setSize(vec2(800, 600)); + + _context.setTitle("egami-viewer"); + + // select internal data for font ... + _context.getFontDefault().setUseExternal(true); + #ifdef __TARGET_OS__Android + _context.getFontDefault().set("FreeSerif", 19); + #else + _context.getFontDefault().set("FreeSerif;DejaVuSansMono",14); + #endif + + // set the application icon ... + _context.setIcon("DATA:icon.png"); + + APPL_INFO("==> CREATE ... (END)"); + } + + void onStart(ewol::Context& _context) { + APPL_INFO("==> START ... (BEGIN)"); + + ememory::SharedPtr basicWindows = appl::MainWindows::create(); + if (basicWindows == nullptr) { + APPL_ERROR("Can not allocate the basic windows"); + return; + } + basicWindows->setListOfFiles(m_listFiles); + // create the specific windows + _context.setWindows(basicWindows); + if (basicWindows == nullptr) { + APPL_ERROR("Can not allocate the basic windows"); + _context.exit(-1); + return; + } + + // create the specific windows + _context.setWindows(basicWindows); + + APPL_INFO("==> START ... (END)"); + return; + } + + void onStop(ewol::Context& _context) { + APPL_INFO("==> STOP ... (START)"); + APPL_INFO("==> STOP ... (END)"); + } +}; + + + +/** + * @brief Main of the program (This can be set in every case, but it is not used in Andoid...). + * @param std IO + * @return std IO + */ +int main(int _argc, const char *_argv[]) { + // second possibility + return ewol::run(new MainApplication(), _argc, _argv); +} + + diff --git a/tools/viewer/data/icon.png b/tools/viewer/data/icon.png new file mode 100644 index 0000000..d7b4860 Binary files /dev/null and b/tools/viewer/data/icon.png differ diff --git a/tools/viewer/lutin_egami-viewer.py b/tools/viewer/lutin_egami-viewer.py new file mode 100755 index 0000000..32cb15b --- /dev/null +++ b/tools/viewer/lutin_egami-viewer.py @@ -0,0 +1,61 @@ +#!/usr/bin/python +import lutin.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 viewer (visual)" + +def get_licence(): + return "APACHE-2" + +def get_compagny_type(): + return "com" + +def get_compagny_name(): + return "atria-soft" + +def get_maintainer(): + return ["Mr DUPIN Edouard "] + +def configure(target, my_module): + # add the file to compile: + my_module.add_src_file([ + 'appl/debug.cpp', + 'appl/init.cpp', + 'appl/MainWindows.cpp', + ]) + + my_module.add_depend(['ewol']) + + my_module.copy_file('data/icon.png','icon.png') + + my_module.add_path(".") + + """ + # set the package properties : + my_module.pkg_set("VERSION", versionID) + my_module.pkg_set("COMPAGNY_TYPE", "org") + my_module.pkg_set("COMPAGNY_NAME", "Edouard DUPIN") + my_module.pkg_set("MAINTAINER", ["Mr DUPIN Edouard "]) + my_module.pkg_set("ICON", tools.get_current_path(__file__) + "/../data/icon.png") + my_module.pkg_set("SECTION", ["Development"]) + my_module.pkg_set("PRIORITY", "optional") + my_module.pkg_set("DESCRIPTION", "ewol test software") + my_module.pkg_set("NAME", "test software") + + my_module.pkg_add("RIGHT", "SET_ORIENTATION") + my_module.pkg_add("RIGHT", "VIBRATE") + """ + + return True + + + +