-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
156 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,39 @@ | ||
cmake_minimum_required (VERSION 3.1) | ||
|
||
project(color) | ||
project(perception) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wconversion -Wno-unused-private-field -Wno-unused-variable -Wno-unused-parameter -fno-omit-frame-pointer -fsanitize=address") | ||
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_STATIC_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wno-unused-private-field -Wno-unused-variable -Wno-unused-parameter") | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") | ||
# set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") | ||
|
||
find_package(PythonLibs REQUIRED 3) | ||
find_package(PythonInterp REQUIRED 3) | ||
find_package(NumPy REQUIRED) | ||
# find_package(PythonInterp REQUIRED 3) | ||
# find_package(NumPy REQUIRED) | ||
|
||
add_library(color SHARED src/debug.cpp src/conversion.cpp src/CIEDE2000.cpp src/fitness.cpp) | ||
target_include_directories(color PUBLIC include PRIVATE ${PYTHON_INCLUDE_DIR} ${NUMPY_INCLUDE_DIR}) | ||
add_library(perception SHARED src/colorspace.cpp src/CIEDE2000.cpp src/fitness.cpp) | ||
target_include_directories(perception PUBLIC include) | ||
|
||
add_executable(testCIEDE2000 test/testCIEDE2000.cpp) | ||
target_link_libraries(testCIEDE2000 color) | ||
add_executable(testconversion test/testconversion.cpp) | ||
target_link_libraries(testconversion color) | ||
add_executable(testfitness test/testfitness.cpp) | ||
target_link_libraries(testfitness color) | ||
add_executable(testfitness2 test/testfitness2.cpp) | ||
target_link_libraries(testfitness2 color) | ||
add_library(pyperception MODULE src/python.cpp) | ||
target_link_libraries(pyperception perception ${PYTHON_LIBRARIES}) | ||
target_include_directories(pyperception PRIVATE include ${PYTHON_INCLUDE_DIR}) | ||
set_target_properties(pyperception PROPERTIES PREFIX "") | ||
|
||
add_executable(evo1 test/example1.cpp) | ||
target_link_libraries(evo1 color) | ||
add_executable(evo2 test/example2.cpp) | ||
target_link_libraries(evo2 color) | ||
add_executable(testevo1 test/example1.cpp) | ||
target_link_libraries(testevo1 perception) | ||
add_executable(testevo2 test/example2.cpp) | ||
target_link_libraries(testevo2 perception) | ||
|
||
add_executable(testlexi test/testlexi.cpp) | ||
target_link_libraries(testlexi color) | ||
target_link_libraries(testlexi perception) | ||
|
||
add_executable(testCIEDE2000 test/testCIEDE2000.cpp) | ||
target_link_libraries(testCIEDE2000 perception) | ||
add_executable(testcolorspace test/testcolorspace.cpp) | ||
target_link_libraries(testcolorspace perception) | ||
add_executable(testfitness test/testfitness.cpp) | ||
target_link_libraries(testfitness perception) | ||
add_executable(testfitness2 test/testfitness2.cpp) | ||
target_link_libraries(testfitness2 perception) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <Python.h> | ||
#include <color.h> | ||
#include <fitness.h> | ||
#include <iostream> | ||
|
||
//< RAII wrapper for PyObject | ||
class PyObj { | ||
public: | ||
PyObj() = delete; | ||
PyObj(PyObject *ptr) : ptr(ptr){}; | ||
PyObj(const PyObj &obj) : ptr(obj.ptr) { Py_XINCREF(obj.ptr); }; | ||
PyObj(PyObj &&obj) : ptr(obj.ptr) { obj.ptr = nullptr; }; | ||
PyObj &operator=(const PyObj &obj) { | ||
ptr = obj.ptr; | ||
Py_XINCREF(ptr); | ||
return *this; | ||
}; | ||
PyObj &operator=(PyObj &&obj) { | ||
ptr = obj.ptr; | ||
obj.ptr = nullptr; | ||
return *this; | ||
}; | ||
~PyObj() { Py_XDECREF(ptr); }; | ||
|
||
PyObject *ptr; | ||
}; | ||
|
||
static PyObject *perception(PyObject *self, PyObject *args) { | ||
color::LAB fg, bg; | ||
unsigned long M; | ||
bool quiet; | ||
|
||
if (!PyArg_ParseTuple(args, "(ddd)(ddd)k|p", &fg.l, &fg.a, &fg.b, &bg.l, | ||
&bg.a, &bg.b, &M, &quiet)) | ||
return NULL; | ||
|
||
const auto result = perceptionL(fg, bg, M, quiet); | ||
PyObj rgb = PyObj(PyList_New(0)); | ||
for (const auto &c : result.rgb) | ||
PyList_Append(rgb.ptr, PyObj(Py_BuildValue("(ddd)", c.r, c.g, c.b)).ptr); | ||
PyObj fitness = PyObj(PyList_New(0)); | ||
for (const auto d : result.fitness.prd) | ||
PyList_Append(fitness.ptr, PyObj(PyFloat_FromDouble(d)).ptr); | ||
|
||
return Py_BuildValue("{sksdsOsO}", "flags", result.flags, "L", result.L, | ||
"rgb", rgb.ptr, "fitness", fitness.ptr); | ||
} | ||
|
||
static PyMethodDef methods[] = { | ||
{"perception", perception, METH_VARARGS, | ||
"perception colors\n-----------------\n\n@param foreground " | ||
"(l,a,b)\n@param background (l,a,b)\n@param M number of colors\n@param " | ||
"quiet default:False"}, | ||
{NULL, NULL, 0, NULL}}; | ||
|
||
static struct PyModuleDef module = { | ||
PyModuleDef_HEAD_INIT, "pyperception", | ||
"Python interface for perception colors library", -1, methods}; | ||
|
||
PyMODINIT_FUNC PyInit_pyperception(void) { return PyModule_Create(&module); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.