[DEV] add egami-cutter

This commit is contained in:
Edouard DUPIN 2018-11-08 07:40:19 +01:00
parent 37c83f9728
commit 4e50a21fa5
4 changed files with 271 additions and 0 deletions

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::String input;
etk::String 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 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 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