From 16c9a5e31a20a49229a5e2dd6c2c04a999add9dc Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Sat, 26 Jan 2013 14:48:25 +0000 Subject: [PATCH] Allow builds without tracer (for non-x86) --- CMakeLists.txt | 4 + examples/27c3_slides/CMakeLists.txt | 4 +- libol/CMakeLists.txt | 12 +- python/CMakeLists.txt | 4 +- python/pylase.pyx | 203 ++++++++++++++-------------- tools/CMakeLists.txt | 4 +- tools/qplayvid/CMakeLists.txt | 4 +- 7 files changed, 126 insertions(+), 109 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1211496..455e35f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,10 @@ endif() add_definitions(-Wall) +if(NOT DEFINED BUILD_TRACER) + set(BUILD_TRACER "Y" CACHE BOOL "Build the image tracer (x86 only)" FORCE) +endif() + add_subdirectory (libol) add_subdirectory (output) add_subdirectory (tools) diff --git a/examples/27c3_slides/CMakeLists.txt b/examples/27c3_slides/CMakeLists.txt index f64f206..6563e18 100644 --- a/examples/27c3_slides/CMakeLists.txt +++ b/examples/27c3_slides/CMakeLists.txt @@ -16,7 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # -if(CURSES_FOUND AND FFMPEG_FOUND) +if(CURSES_FOUND AND FFMPEG_FOUND AND BUILD_TRACER) include_directories(${CMAKE_SOURCE_DIR}/tools ${CURSES_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIR}) add_executable(slides @@ -43,5 +43,5 @@ if(CURSES_FOUND AND FFMPEG_FOUND) svg2ild(jack-logo) svg2ild(output) else() - message(STATUS "Will NOT build 27c3_slides (curses or FFmpeg missing)") + message(STATUS "Will NOT build 27c3_slides (curses or FFmpeg or tracer missing)") endif() diff --git a/libol/CMakeLists.txt b/libol/CMakeLists.txt index 7fe2fcd..36caa08 100644 --- a/libol/CMakeLists.txt +++ b/libol/CMakeLists.txt @@ -24,8 +24,16 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DI include_directories (${CMAKE_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}) -enable_language(ASM_YASM) -add_library (openlase SHARED libol.c text.c ilda.c trace.c imgproc_sse2.asm ${CMAKE_CURRENT_BINARY_DIR}/fontdef.c) +set(TRACER_SOURCES "") +if(BUILD_TRACER) + set(TRACER_SOURCES trace.c imgproc_sse2.asm) + enable_language(ASM_YASM) + message(STATUS "Will build tracer (SSE2 version)") +else() + message(STATUS "Will NOT build tracer") +endif() + +add_library (openlase SHARED libol.c text.c ilda.c ${TRACER_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/fontdef.c) target_link_libraries (openlase ${CMAKE_THREAD_LIBS_INIT} m jack) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/fontdef.c diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 61dd925..5bd8815 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -8,9 +8,11 @@ else() ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.pxi.in ${CMAKE_CURRENT_BINARY_DIR}/config.pxi) + add_custom_command(OUTPUT pylase.c MAIN_DEPENDENCY pylase.pyx - COMMAND ${CYTHON_EXECUTABLE} -I ${CMAKE_SOURCE_DIR}/include -o pylase.c "${CMAKE_CURRENT_SOURCE_DIR}/pylase.pyx") + COMMAND ${CYTHON_EXECUTABLE} -I ${CMAKE_SOURCE_DIR}/include -I ${CMAKE_CURRENT_BINARY_DIR} -o pylase.c "${CMAKE_CURRENT_SOURCE_DIR}/pylase.pyx") list(APPEND ADDITIONAL_MAKE_CLEAN_FILES pylase.c) include_directories(${PYTHON_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/include) diff --git a/python/pylase.pyx b/python/pylase.pyx index 8cfc336..28661f7 100644 --- a/python/pylase.pyx +++ b/python/pylase.pyx @@ -15,6 +15,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +include "config.pxi" + from libc.stdint cimport * from libc.stdlib cimport malloc, free from libc.string cimport memcpy @@ -483,122 +485,123 @@ cpdef drawIlda3D(object ilda): cdef IldaFile f = ilda olDrawIlda3D(f.ilda) -cdef extern from "trace.h": - ctypedef struct OLTraceCtx +IF BUILD_TRACER == "Y": + cdef extern from "trace.h": + ctypedef struct OLTraceCtx - ctypedef enum OLTraceMode: - OL_TRACE_THRESHOLD - OL_TRACE_CANNY + ctypedef enum OLTraceMode: + OL_TRACE_THRESHOLD + OL_TRACE_CANNY - ctypedef struct OLTraceParams: - OLTraceMode mode - uint32_t width, height - float sigma - unsigned int threshold - unsigned int threshold2 + ctypedef struct OLTraceParams: + OLTraceMode mode + uint32_t width, height + float sigma + unsigned int threshold + unsigned int threshold2 - ctypedef struct OLTracePoint: - uint32_t x - uint32_t y + ctypedef struct OLTracePoint: + uint32_t x + uint32_t y - ctypedef struct OLTraceObject: - unsigned int count - OLTracePoint *points + ctypedef struct OLTraceObject: + unsigned int count + OLTracePoint *points - ctypedef struct OLTraceResult: - unsigned int count - OLTraceObject *objects + ctypedef struct OLTraceResult: + unsigned int count + OLTraceObject *objects - int olTraceInit(OLTraceCtx **ctx, OLTraceParams *params) - int olTraceReInit(OLTraceCtx *ctx, OLTraceParams *params) + int olTraceInit(OLTraceCtx **ctx, OLTraceParams *params) + int olTraceReInit(OLTraceCtx *ctx, OLTraceParams *params) - int olTrace(OLTraceCtx *ctx, uint8_t *src, uint32_t stride, OLTraceResult *result) nogil - void olTraceFree(OLTraceResult *result) + int olTrace(OLTraceCtx *ctx, uint8_t *src, uint32_t stride, OLTraceResult *result) nogil + void olTraceFree(OLTraceResult *result) - void olTraceDeinit(OLTraceCtx *ctx) + void olTraceDeinit(OLTraceCtx *ctx) -TRACE_THRESHOLD = OL_TRACE_THRESHOLD -TRACE_CANNY = OL_TRACE_CANNY + TRACE_THRESHOLD = OL_TRACE_THRESHOLD + TRACE_CANNY = OL_TRACE_CANNY -cdef class Tracer(object): - cdef OLTraceParams params - cdef OLTraceCtx *ctx + cdef class Tracer(object): + cdef OLTraceParams params + cdef OLTraceCtx *ctx - def __init__(self, width, height): - self.params.mode = OL_TRACE_THRESHOLD - self.params.width = width - self.params.height = height - self.params.sigma = 0 - self.params.threshold = 128 - self.params.threshold2 = 0 - olTraceInit(&self.ctx, &self.params) + def __init__(self, width, height): + self.params.mode = OL_TRACE_THRESHOLD + self.params.width = width + self.params.height = height + self.params.sigma = 0 + self.params.threshold = 128 + self.params.threshold2 = 0 + olTraceInit(&self.ctx, &self.params) - def __del__(self): - olTraceDeinit(self.ctx) + def __del__(self): + olTraceDeinit(self.ctx) - def trace(self, data, stride = None): - if stride is None: - stride = self.params.width - if stride < self.params.width: - raise ValueError("Invalid stride") - if len(data) != stride * self.params.height: - raise ValueError("Invalid frame size") - cdef uint8_t * _data = data - cdef uint8_t * _databuf - cdef uint32_t _stride = stride - cdef OLTraceResult result - _databuf = malloc(_stride * self.params.height) - try: - memcpy(_databuf, _data, _stride * self.params.height) - with nogil: - olTrace(self.ctx, _data, _stride, &result) - finally: - free(_databuf) - objects = [] - cdef OLTracePoint *ipoints - for i in xrange(result.count): - ipoints = result.objects[i].points - points = [] - for j in xrange(result.objects[i].count): - points.append((ipoints[j].x, ipoints[j].y)) - objects.append(points) - olTraceFree(&result) - return objects + def trace(self, data, stride = None): + if stride is None: + stride = self.params.width + if stride < self.params.width: + raise ValueError("Invalid stride") + if len(data) != stride * self.params.height: + raise ValueError("Invalid frame size") + cdef uint8_t * _data = data + cdef uint8_t * _databuf + cdef uint32_t _stride = stride + cdef OLTraceResult result + _databuf = malloc(_stride * self.params.height) + try: + memcpy(_databuf, _data, _stride * self.params.height) + with nogil: + olTrace(self.ctx, _data, _stride, &result) + finally: + free(_databuf) + objects = [] + cdef OLTracePoint *ipoints + for i in xrange(result.count): + ipoints = result.objects[i].points + points = [] + for j in xrange(result.objects[i].count): + points.append((ipoints[j].x, ipoints[j].y)) + objects.append(points) + olTraceFree(&result) + return objects - property mode: - def __get__(self): - return self.params.mode - def __set__(self, v): - if v not in (OL_TRACE_THRESHOLD, OL_TRACE_CANNY): - raise ValueError("Invalid mode") - self.params.mode = v - olTraceReInit(self.ctx, &self.params) + property mode: + def __get__(self): + return self.params.mode + def __set__(self, v): + if v not in (OL_TRACE_THRESHOLD, OL_TRACE_CANNY): + raise ValueError("Invalid mode") + self.params.mode = v + olTraceReInit(self.ctx, &self.params) - property threshold: - def __get__(self): - return self.params.threshold - def __set__(self, v): - self.params.threshold = v - olTraceReInit(self.ctx, &self.params) + property threshold: + def __get__(self): + return self.params.threshold + def __set__(self, v): + self.params.threshold = v + olTraceReInit(self.ctx, &self.params) - property threshold2: - def __get__(self): - return self.params.threshold2 - def __set__(self, v): - self.params.threshold2 = v - olTraceReInit(self.ctx, &self.params) + property threshold2: + def __get__(self): + return self.params.threshold2 + def __set__(self, v): + self.params.threshold2 = v + olTraceReInit(self.ctx, &self.params) - property sigma: - def __get__(self): - return self.params.sigma - def __set__(self, v): - self.params.sigma = v - olTraceReInit(self.ctx, &self.params) + property sigma: + def __get__(self): + return self.params.sigma + def __set__(self, v): + self.params.sigma = v + olTraceReInit(self.ctx, &self.params) - property width: - def __get__(self): - return self.params.width + property width: + def __get__(self): + return self.params.width - property height: - def __get__(self): - return self.params.height + property height: + def __get__(self): + return self.params.height diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index a80affa..472a1f7 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -22,12 +22,12 @@ link_directories (${CMAKE_BINARY_DIR}/libol) add_executable(playilda playilda.c) target_link_libraries(playilda ${JACK_LIBRARIES}) -if(FFMPEG_FOUND) +if(FFMPEG_FOUND AND BUILD_TRACER) include_directories(${FFMPEG_INCLUDE_DIR}) add_executable(playvid playvid.c) target_link_libraries(playvid openlase ${FFMPEG_LIBRARIES}) else() - message(STATUS "Will NOT build playvid (FFmpeg missing)") + message(STATUS "Will NOT build playvid (FFmpeg or tracer missing)") endif() if(OPENGL_FOUND AND GLUT_FOUND) diff --git a/tools/qplayvid/CMakeLists.txt b/tools/qplayvid/CMakeLists.txt index 8f719de..2fdb7b4 100644 --- a/tools/qplayvid/CMakeLists.txt +++ b/tools/qplayvid/CMakeLists.txt @@ -16,7 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # -if(QT4_FOUND AND FFMPEG_FOUND AND SWSCALE_FOUND) +if(QT4_FOUND AND FFMPEG_FOUND AND SWSCALE_FOUND AND BUILD_TRACER) include(${QT_USE_FILE}) QT4_WRAP_CPP(qplayvid_MOCS qplayvid_gui.h) @@ -26,5 +26,5 @@ if(QT4_FOUND AND FFMPEG_FOUND AND SWSCALE_FOUND) add_executable(qplayvid qplayvid.c qplayvid_gui.cpp ${qplayvid_MOCS}) target_link_libraries(qplayvid openlase ${FFMPEG_LIBRARIES} ${SWSCALE_LIBRARIES} ${QT_LIBRARIES}) else() - message(STATUS "Will NOT build qplayvid (Qt4 or FFmpeg missing)") + message(STATUS "Will NOT build qplayvid (Qt4 or FFmpeg or tracer missing)") endif()