From 39b98386ddd73fc91318862a966935d345b34c9e Mon Sep 17 00:00:00 2001 From: "T. van der Zwan" Date: Tue, 13 Aug 2013 11:10:45 +0200 Subject: [PATCH 1/2] Added simple QT-based grabber. Moved ImageToLedsMap from include to libsrc. Moved instantiation of objects to Hyperion (no JSON required outside this class). --- CMakeLists.txt | 11 +- include/hyperion/DispmanxWrapper.h | 32 +++ include/hyperion/Hyperion.h | 26 +- include/hyperion/ImageProcessor.h | 72 ++++++ include/hyperion/ImageProcessorFactory.h | 26 ++ include/hyperion/ImageToLedsMap.h | 27 --- include/hyperion/LedString.h | 18 +- include/hyperion/PriorityMuxer.h | 55 +++++ include/utils/RgbColor.h | 5 +- libsrc/CMakeLists.txt | 22 +- libsrc/bob2hyperion.cpp | 8 +- libsrc/hyperion/CMakeLists.txt | 44 +++- libsrc/hyperion/ColorTransform.cpp | 97 ++++---- libsrc/hyperion/ColorTransform.h | 52 ++-- libsrc/hyperion/DispmanxFrameGrabber.cpp | 54 +++++ libsrc/hyperion/DispmanxFrameGrabber.h | 35 +++ libsrc/hyperion/DispmanxWrapper.cpp | 46 ++++ libsrc/hyperion/Hyperion.cpp | 104 ++++---- libsrc/hyperion/ImageProcessor.cpp | 65 +++++ libsrc/hyperion/ImageProcessorFactory.cpp | 21 ++ libsrc/hyperion/ImageToLedsMap.cpp | 46 ++-- libsrc/hyperion/ImageToLedsMap.h | 57 +++++ libsrc/hyperion/LedString.cpp | 40 +--- libsrc/hyperion/PriorityMuxer.cpp | 94 ++++++++ src/CMakeLists.txt | 16 +- src/HyperionDispmanX.cpp | 2 +- src/HyperionMain.cpp | 17 ++ src/ViewPng.cpp | 4 +- src/flagmanager.cpp | 274 +++++++++++----------- src/misc.h | 42 ++-- test/TestColorTransform.cpp | 159 +++++++------ test/TestConfigFile.cpp | 2 +- 32 files changed, 1065 insertions(+), 508 deletions(-) create mode 100644 include/hyperion/DispmanxWrapper.h create mode 100644 include/hyperion/ImageProcessor.h create mode 100644 include/hyperion/ImageProcessorFactory.h delete mode 100644 include/hyperion/ImageToLedsMap.h create mode 100644 include/hyperion/PriorityMuxer.h create mode 100644 libsrc/hyperion/DispmanxFrameGrabber.cpp create mode 100644 libsrc/hyperion/DispmanxFrameGrabber.h create mode 100644 libsrc/hyperion/DispmanxWrapper.cpp create mode 100644 libsrc/hyperion/ImageProcessor.cpp create mode 100644 libsrc/hyperion/ImageProcessorFactory.cpp create mode 100644 libsrc/hyperion/ImageToLedsMap.h create mode 100644 libsrc/hyperion/PriorityMuxer.cpp create mode 100644 src/HyperionMain.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d42a4d63..5c5759ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # define the minimum cmake version (as required by cmake) cmake_minimum_required(VERSION 2.8) -#set(CMAKE_TOOLCHAIN_FILE /opt/raspberrypi/Toolchain-RaspberryPi.cmake) +set(CMAKE_TOOLCHAIN_FILE /opt/raspberrypi/Toolchain-RaspberryPi.cmake) # Define the main-project name project(Hyperion) @@ -28,6 +28,15 @@ set(CMAKE_BUILD_TYPE "Release") # enable C++11 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall") +# Configure the use of QT4 +find_package(Qt4 COMPONENTS QtCore REQUIRED QUIET) + +SET(QT_DONT_USE_QTGUI TRUE) +SET(QT_USE_QTCONSOLE TRUE) +include(${QT_USE_FILE}) +add_definitions(${QT_DEFINITIONS}) +link_directories(${CMAKE_FIND_ROOT_PATH}/lib/arm-linux-gnueabihf) + configure_file(bin/install_hyperion.sh ${LIBRARY_OUTPUT_PATH} @ONLY) configure_file(config/hyperion.config.json ${LIBRARY_OUTPUT_PATH} @ONLY) configure_file(config/hyperion.schema.json ${LIBRARY_OUTPUT_PATH} @ONLY) diff --git a/include/hyperion/DispmanxWrapper.h b/include/hyperion/DispmanxWrapper.h new file mode 100644 index 00000000..4d9b5649 --- /dev/null +++ b/include/hyperion/DispmanxWrapper.h @@ -0,0 +1,32 @@ +#pragma once + +// QT includes +#include +#include + +// Forward class declaration +class ImageProcessor; +class DispmanxFrameGrabber; + +class DispmanxWrapper: public QObject +{ + Q_OBJECT +public: + DispmanxWrapper(); + + virtual ~DispmanxWrapper(); + +public slots: + void start(); + + void action(); + + void stop(); + +private: + QTimer _timer; + + DispmanxFrameGrabber* _frameGrabber; + ImageProcessor* _processor; +}; + diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index 1f3113de..e278bef3 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -4,9 +4,14 @@ // hyperion-utils includes #include +// Hyperion includes #include -#include #include +#include + +// Forward class declaration +namespace hyperion { class ColorTransform; } + class Hyperion { @@ -15,27 +20,18 @@ public: ~Hyperion(); - void setInputSize(const unsigned width, const unsigned height); - - RgbImage& image() - { - return *mImage; - } - - void commit(); - - void operator() (const RgbImage& inputImage); - - void setColor(const RgbColor& color); + void setValue(int priority, std::vector &ledColors); private: void applyTransform(std::vector& colors) const; LedString mLedString; - RgbImage* mImage; + PriorityMuxer mMuxer; - ImageToLedsMap mLedsMap; + hyperion::ColorTransform* mRedTransform; + hyperion::ColorTransform* mGreenTransform; + hyperion::ColorTransform* mBlueTransform; LedDevice* mDevice; }; diff --git a/include/hyperion/ImageProcessor.h b/include/hyperion/ImageProcessor.h new file mode 100644 index 00000000..26abaa8b --- /dev/null +++ b/include/hyperion/ImageProcessor.h @@ -0,0 +1,72 @@ + +#pragma once + +// Utils includes +#include + +#include +#include + +// Forward class declaration +namespace hyperion { class ImageToLedsMap; + class ColorTransform; } + +/** + * The ImageProcessor translates an RGB-image to RGB-values for the leds. The processing is + * performed in two steps. First the average color per led-region is computed. Second a + * color-tranform is applied based on a gamma-correction. + */ +class ImageProcessor +{ +public: + /** + * Processes the image to a list of led colors. This will update the size of the buffer-image + * if required and call the image-to-leds mapping to determine the mean color per led. + * + * @param[in] image The image to translate to led values + * + * @return The color value per led + */ + std::vector process(const RgbImage& image); + + // 'IN PLACE' processing functions + + /** + * Specifies the width and height of 'incomming' images. This will resize the buffer-image to + * match the given size. + * NB All earlier obtained references will be invalid. + * + * @param[in] width The new width of the buffer-image + * @param[in] height The new height of the buffer-image + */ + void setSize(const unsigned width, const unsigned height); + + /** + * Returns a reference of the underlying image-buffer. This can be used to write data directly + * into the buffer, avoiding a copy inside the process method. + * + * @return The reference of the underlying image-buffer. + */ + RgbImage& image(); + + /** + * Determines the led colors of the image in the buffer. + * + * @param[out] ledColors The color value per led + */ + void inplace_process(std::vector& ledColors); + +private: + friend class ImageProcessorFactory; + + ImageProcessor(const LedString &ledString); + + ~ImageProcessor(); + +private: + const LedString mLedString; + + RgbImage *mBuffer; + hyperion::ImageToLedsMap* mImageToLeds; +}; + diff --git a/include/hyperion/ImageProcessorFactory.h b/include/hyperion/ImageProcessorFactory.h new file mode 100644 index 00000000..dc558371 --- /dev/null +++ b/include/hyperion/ImageProcessorFactory.h @@ -0,0 +1,26 @@ +#pragma once + +// STL includes +#include + +// Jsoncpp includes +#include + +#include + +// Forward class declaration +class ImageProcessor; + +class ImageProcessorFactory +{ +public: + static ImageProcessorFactory& getInstance(); + +public: + void init(const LedString& ledString); + + ImageProcessor* newImageProcessor() const; + +private: + LedString _ledString; +}; diff --git a/include/hyperion/ImageToLedsMap.h b/include/hyperion/ImageToLedsMap.h deleted file mode 100644 index cc00972e..00000000 --- a/include/hyperion/ImageToLedsMap.h +++ /dev/null @@ -1,27 +0,0 @@ - -#pragma once - -// hyperion-utils includes -#include - -// hyperion includes -#include - -class ImageToLedsMap -{ -public: - - ImageToLedsMap(); - - void createMapping(const RgbImage& image, const std::vector& leds); - - std::vector getMeanLedColor(); - - RgbColor findMeanColor(const std::vector& colors); - - std::vector getMedianLedColor(); - - RgbColor findMedianColor(std::vector& colors); -private: - std::vector > mColorsMap; -}; diff --git a/include/hyperion/LedString.h b/include/hyperion/LedString.h index cc105b38..cc4962ff 100644 --- a/include/hyperion/LedString.h +++ b/include/hyperion/LedString.h @@ -45,28 +45,16 @@ struct Led class LedString { public: - static LedString construct(const Json::Value& ledConfig, const Json::Value& colorConfig); + static LedString construct(const Json::Value& ledConfig); LedString(); ~LedString(); + std::vector& leds(); + const std::vector& leds() const; private: std::vector mLeds; - -public: - /** - * Color adjustements per color - */ - struct - { - /** The color gradient */ - double gamma; - /** The color offset */ - double adjust; - /** The minimum required level for the led to turn on */ - double blacklevel; - } red, green, blue; }; diff --git a/include/hyperion/PriorityMuxer.h b/include/hyperion/PriorityMuxer.h new file mode 100644 index 00000000..c2e05fdf --- /dev/null +++ b/include/hyperion/PriorityMuxer.h @@ -0,0 +1,55 @@ +#pragma once + +// STL includes +#include +#include +#include +#include + +// QT includes +#include + +// Utils includes +#include + +// Hyperion includes +#include + +class PriorityMuxer +{ +public: + struct InputInfo + { + int priority; + + int64_t timeoutTime_ms; + std::vector ledColors; + }; + + PriorityMuxer(); + + ~PriorityMuxer(); + + int getCurrentPriority() const; + + bool hasPriority(const int priority) const; + + QList getPriorities() const; + + const InputInfo& getInputInfo(const int priority) const; + + void setInput(const int priority, const std::vector& ledColors, const int64_t timeoutTime_ms=-1); + + void clearInput(const int priority); + + void clearAll(); + + void setCurrentTime(const int64_t& now); + +private: + int mCurrentPriority; + + QMap mActiveInputs; + + const static int MAX_PRIORITY = std::numeric_limits::max(); +}; diff --git a/include/utils/RgbColor.h b/include/utils/RgbColor.h index 2b982aa0..50825431 100644 --- a/include/utils/RgbColor.h +++ b/include/utils/RgbColor.h @@ -5,7 +5,6 @@ #include #include - // Forward class declaration struct RgbColor; @@ -21,8 +20,12 @@ struct RgbColor static RgbColor BLUE; static RgbColor YELLOW; static RgbColor WHITE; + }; +static_assert(sizeof(RgbColor) == 3, "Incorrect size of RgbColor"); + + inline std::ostream& operator<<(std::ostream& os, const RgbColor& color) { os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}"; diff --git a/libsrc/CMakeLists.txt b/libsrc/CMakeLists.txt index 06ea26d4..ac0c6c2b 100644 --- a/libsrc/CMakeLists.txt +++ b/libsrc/CMakeLists.txt @@ -10,18 +10,22 @@ target_link_libraries(bob2hyperion hyperion hyperion-utils) +add_subdirectory(hyperion) +add_subdirectory(utils) + # Find the libPNG find_package(PNG REQUIRED QUIET) -# Add additional includes dirs -include_directories(${PNG_INCLUDE_DIR}) +if (PNG_FOUND) + # Add additional includes dirs + include_directories(${PNG_INCLUDE_DIR}) -add_library(bob2hyperion-png SHARED - hyperion-png.cpp) + add_library(bob2hyperion-png SHARED + hyperion-png.cpp) -target_link_libraries(bob2hyperion-png - hyperion-png) + target_link_libraries(bob2hyperion-png + hyperion-png) + + add_subdirectory(hyperionpng) +endif(PNG_FOUND) -add_subdirectory(hyperion) -add_subdirectory(hyperionpng) -add_subdirectory(utils) diff --git a/libsrc/bob2hyperion.cpp b/libsrc/bob2hyperion.cpp index f46fb251..f76ed71e 100644 --- a/libsrc/bob2hyperion.cpp +++ b/libsrc/bob2hyperion.cpp @@ -51,7 +51,7 @@ void boblight_destroy(void* hyperion_ptr) Hyperion* raspiLight = rasp_cast(hyperion_ptr); // Switch all leds to black (off) - raspiLight->setColor(RgbColor::BLACK); +// raspiLight->setColor(RgbColor::BLACK); delete raspiLight; @@ -64,20 +64,20 @@ void boblight_setscanrange(void* hyperion_ptr, int width, int height) syslog(LOG_INFO, "Configuring scan range [%dx%d]", width, height); Hyperion* raspiLight = rasp_cast(hyperion_ptr); - raspiLight->setInputSize(width, height); +// raspiLight->setInputSize(width, height); } void boblight_addpixelxy(void* hyperion_ptr, int x, int y, int* rgb) { Hyperion* raspiLight = rasp_cast(hyperion_ptr); const RgbColor color = {uint8_t(rgb[0]), uint8_t(rgb[1]), uint8_t(rgb[2])}; - raspiLight->image().setPixel(x, y, color); +// raspiLight->image().setPixel(x, y, color); } int boblight_sendrgb(void* hyperion_ptr, int sync, int* outputused) { Hyperion* raspiLight = rasp_cast(hyperion_ptr); - raspiLight->commit(); +// raspiLight->commit(); return 1; } diff --git a/libsrc/hyperion/CMakeLists.txt b/libsrc/hyperion/CMakeLists.txt index 94ab7525..eedf202e 100644 --- a/libsrc/hyperion/CMakeLists.txt +++ b/libsrc/hyperion/CMakeLists.txt @@ -1,22 +1,52 @@ +# Find the BCM-package (VC control) +find_package(BCM REQUIRED) +include_directories(${BCM_INCLUDE_DIRS}) + # Define the current source locations SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/hyperion) SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/hyperion) -add_library(hyperion +SET(Hyperion_HEADERS ${CURRENT_HEADER_DIR}/Hyperion.h ${CURRENT_HEADER_DIR}/LedDevice.h ${CURRENT_HEADER_DIR}/LedString.h - ${CURRENT_HEADER_DIR}/ImageToLedsMap.h + ${CURRENT_HEADER_DIR}/ImageProcessor.h + ${CURRENT_HEADER_DIR}/ImageProcessorFactory.h + ${CURRENT_HEADER_DIR}/PriorityMuxer.h + ${CURRENT_HEADER_DIR}/DispmanxWrapper.h + + ${CURRENT_SOURCE_DIR}/DispmanxFrameGrabber.h ${CURRENT_SOURCE_DIR}/LedDeviceWs2801.h - ${CURRENT_SOURCE_DIR}/LedDeviceWs2801.cpp + ${CURRENT_SOURCE_DIR}/ImageToLedsMap.h + ${CURRENT_SOURCE_DIR}/ColorTransform.h +) + +SET(Hyperion_SOURCES ${CURRENT_SOURCE_DIR}/LedString.cpp ${CURRENT_SOURCE_DIR}/Hyperion.cpp - ${CURRENT_SOURCE_DIR}/ImageToLedsMap.cpp - ${CURRENT_SOURCE_DIR}/ColorTransform.h - ${CURRENT_SOURCE_DIR}/ColorTransform.cpp + ${CURRENT_SOURCE_DIR}/ImageProcessor.cpp + ${CURRENT_SOURCE_DIR}/ImageProcessorFactory.cpp + ${CURRENT_SOURCE_DIR}/PriorityMuxer.cpp + + ${CURRENT_SOURCE_DIR}/DispmanxWrapper.cpp + ${CURRENT_SOURCE_DIR}/DispmanxFrameGrabber.cpp + + ${CURRENT_SOURCE_DIR}/LedDeviceWs2801.cpp + ${CURRENT_SOURCE_DIR}/ImageToLedsMap.cpp + ${CURRENT_SOURCE_DIR}/ColorTransform.cpp +) + +QT4_WRAP_CPP(Hyperion_HEADERS_MOC ${Hyperion_HEADERS}) + +add_library(hyperion + ${Hyperion_HEADERS} + ${Hyperion_HEADERS_MOC} + ${Hyperion_SOURCES} ) target_link_libraries(hyperion - hyperion-utils) + hyperion-utils + ${QT_LIBRARIES} + ${BCM_LIBRARIES}) diff --git a/libsrc/hyperion/ColorTransform.cpp b/libsrc/hyperion/ColorTransform.cpp index 7a02fc0d..b77b8b24 100644 --- a/libsrc/hyperion/ColorTransform.cpp +++ b/libsrc/hyperion/ColorTransform.cpp @@ -1,23 +1,26 @@ +// STL includes #include #include "ColorTransform.h" +using namespace hyperion; + ColorTransform::ColorTransform() : - _threshold(0), - _gamma(1.0), - _blacklevel(0.0), - _whitelevel(1.0) + _threshold(0), + _gamma(1.0), + _blacklevel(0.0), + _whitelevel(1.0) { - initializeMapping(); + initializeMapping(); } ColorTransform::ColorTransform(double threshold, double gamma, double blacklevel, double whitelevel) : - _threshold(threshold), - _gamma(gamma), - _blacklevel(blacklevel), - _whitelevel(whitelevel) + _threshold(threshold), + _gamma(gamma), + _blacklevel(blacklevel), + _whitelevel(whitelevel) { - initializeMapping(); + initializeMapping(); } ColorTransform::~ColorTransform() @@ -26,77 +29,77 @@ ColorTransform::~ColorTransform() double ColorTransform::getThreshold() const { - return _threshold; + return _threshold; } void ColorTransform::setThreshold(double threshold) { - _threshold = threshold; - initializeMapping(); + _threshold = threshold; + initializeMapping(); } double ColorTransform::getGamma() const { - return _gamma; + return _gamma; } void ColorTransform::setGamma(double gamma) { - _gamma = gamma; - initializeMapping(); + _gamma = gamma; + initializeMapping(); } double ColorTransform::getBlacklevel() const { - return _blacklevel; + return _blacklevel; } void ColorTransform::setBlacklevel(double blacklevel) { - _blacklevel = blacklevel; - initializeMapping(); + _blacklevel = blacklevel; + initializeMapping(); } double ColorTransform::getWhitelevel() const { - return _whitelevel; + return _whitelevel; } void ColorTransform::setWhitelevel(double whitelevel) { - _whitelevel = whitelevel; - initializeMapping(); + _whitelevel = whitelevel; + initializeMapping(); } void ColorTransform::initializeMapping() { - // initialize the mapping as a linear array - for (int i = 0; i < 256; ++i) - { - double output = i / 255.0; + // initialize the mapping as a linear array + for (int i = 0; i < 256; ++i) + { + double output = i / 255.0; - // apply linear transform - if (output < _threshold) - { - output = 0.0; - } + // apply linear transform + if (output < _threshold) + { + output = 0.0; + } - // apply gamma correction - output = std::pow(output, _gamma); + // apply gamma correction + output = std::pow(output, _gamma); - // apply blacklevel and whitelevel - output = _blacklevel + (_whitelevel - _blacklevel) * output; + // apply blacklevel and whitelevel + output = _blacklevel + (_whitelevel - _blacklevel) * output; - // calc mapping - int mappingValue = output * 255; - if (mappingValue < 0) - { - mappingValue = 0; - } - else if (mappingValue > 255) - { - mappingValue = 255; - } - _mapping[i] = mappingValue; - } + // calc mapping + int mappingValue = output * 255; + if (mappingValue < 0) + { + mappingValue = 0; + } + else if (mappingValue > 255) + { + mappingValue = 255; + } + _mapping[i] = mappingValue; + } } diff --git a/libsrc/hyperion/ColorTransform.h b/libsrc/hyperion/ColorTransform.h index 7a67e36e..946665d4 100644 --- a/libsrc/hyperion/ColorTransform.h +++ b/libsrc/hyperion/ColorTransform.h @@ -1,6 +1,10 @@ #pragma once -#include "stdint.h" +// STL includes +#include + +namespace hyperion +{ /// Transform for a single color byte value /// @@ -14,36 +18,38 @@ class ColorTransform { public: - ColorTransform(); - ColorTransform(double threshold, double gamma, double whitelevel, double blacklevel); - ~ColorTransform(); + ColorTransform(); + ColorTransform(double threshold, double gamma, double blacklevel, double whitelevel); + ~ColorTransform(); - double getThreshold() const; - void setThreshold(double threshold); + double getThreshold() const; + void setThreshold(double threshold); - double getGamma() const; - void setGamma(double gamma); + double getGamma() const; + void setGamma(double gamma); - double getBlacklevel() const; - void setBlacklevel(double blacklevel); + double getBlacklevel() const; + void setBlacklevel(double blacklevel); - double getWhitelevel() const; - void setWhitelevel(double whitelevel); + double getWhitelevel() const; + void setWhitelevel(double whitelevel); - /// get the transformed value for the given byte value - uint8_t transform(uint8_t input) const - { - return _mapping[input]; - } + /// get the transformed value for the given byte value + uint8_t transform(uint8_t input) const + { + return _mapping[input]; + } private: - void initializeMapping(); + void initializeMapping(); private: - double _threshold; - double _gamma; - double _blacklevel; - double _whitelevel; + double _threshold; + double _gamma; + double _blacklevel; + double _whitelevel; - uint8_t _mapping[256]; + uint8_t _mapping[256]; }; + +} // end namespace hyperion diff --git a/libsrc/hyperion/DispmanxFrameGrabber.cpp b/libsrc/hyperion/DispmanxFrameGrabber.cpp new file mode 100644 index 00000000..27d67f96 --- /dev/null +++ b/libsrc/hyperion/DispmanxFrameGrabber.cpp @@ -0,0 +1,54 @@ + +#include "DispmanxFrameGrabber.h" + +DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned height) : + _display(0), + _resource(0), + _width(width), + _height(height) +{ + // Initiase BCM + bcm_host_init(); + + // Open the connection to the displaydisplay + _display = vc_dispmanx_display_open(0); + int ret = vc_dispmanx_display_get_info(_display, &_info); + assert(ret == 0); + + // Create the resources for capturing image + _resource = vc_dispmanx_resource_create( + VC_IMAGE_RGB888, + width, + height, + &_vc_image_ptr); + assert(_resource); + + // Define the capture rectangle with the same size + vc_dispmanx_rect_set(&_rectangle, 0, 0, width, height); + _pitch = width * 3; +} + +DispmanxFrameGrabber::~DispmanxFrameGrabber() +{ + // Clean up resources + vc_dispmanx_resource_delete(_resource); + + // Close the displaye + vc_dispmanx_display_close(_display); + + // De-init BCM + bcm_host_deinit(); +} + +void DispmanxFrameGrabber::grabFrame(RgbImage& image) +{ + // Sanity check of the given image size + assert(image.width() == _width && image.height() == _height); + + void* image_ptr = image.memptr(); + + // Create the snapshot + vc_dispmanx_snapshot(_display, _resource, VC_IMAGE_ROT0); + // Read the snapshot into the memory (incl down-scaling) + vc_dispmanx_resource_read_data(_resource, &_rectangle, image_ptr, _pitch); +} diff --git a/libsrc/hyperion/DispmanxFrameGrabber.h b/libsrc/hyperion/DispmanxFrameGrabber.h new file mode 100644 index 00000000..088f6189 --- /dev/null +++ b/libsrc/hyperion/DispmanxFrameGrabber.h @@ -0,0 +1,35 @@ +#pragma once + +// BCM includes +#include + +// STL includes +#include + +// Utils includes +#include + +/// +/// The DispmanxFrameGrabber grabs +/// +class DispmanxFrameGrabber +{ +public: + DispmanxFrameGrabber(const unsigned width, const unsigned height); + ~DispmanxFrameGrabber(); + + void grabFrame(RgbImage& image); + +private: + DISPMANX_DISPLAY_HANDLE_T _display; + DISPMANX_MODEINFO_T _info; + + DISPMANX_RESOURCE_HANDLE_T _resource; + + uint32_t _vc_image_ptr; + + VC_RECT_T _rectangle; + unsigned _width; + unsigned _height; + uint32_t _pitch; +}; diff --git a/libsrc/hyperion/DispmanxWrapper.cpp b/libsrc/hyperion/DispmanxWrapper.cpp new file mode 100644 index 00000000..ed73c728 --- /dev/null +++ b/libsrc/hyperion/DispmanxWrapper.cpp @@ -0,0 +1,46 @@ +// QT includes +#include +#include + +// Hyperion includes +#include +#include + + +// Local-Hyperion includes +#include "DispmanxFrameGrabber.h" + +DispmanxWrapper::DispmanxWrapper() : + _timer(), + _processor(ImageProcessorFactory::getInstance().newImageProcessor()), + _frameGrabber(new DispmanxFrameGrabber(64, 64)) +{ + _timer.setInterval(100); + _timer.setSingleShot(false); + + QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action())); +} + +DispmanxWrapper::~DispmanxWrapper() +{ + delete _frameGrabber; + delete _processor; +} + +void DispmanxWrapper::start() +{ + _timer.start(); +} + +void DispmanxWrapper::action() +{ + qDebug() << "[" << QDateTime::currentDateTimeUtc() << "] Grabbing frame"; + RgbImage image(64, 64); + _frameGrabber->grabFrame(image); + + //_processor-> +} +void DispmanxWrapper::stop() +{ + _timer.stop(); +} diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index dcc83e54..182e024e 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -10,6 +10,9 @@ #include #include "LedDeviceWs2801.h" +#include "ColorTransform.h" + +using namespace hyperion; LedDevice* constructDevice(const Json::Value& deviceConfig) { @@ -34,9 +37,41 @@ LedDevice* constructDevice(const Json::Value& deviceConfig) return device; } +ColorTransform* createColorTransform(const Json::Value& colorConfig) +{ + const double threshold = colorConfig["threshold"].asDouble(); + const double gamma = colorConfig["gamma"].asDouble(); + const double blacklevel = colorConfig["blacklevel"].asDouble(); + const double whitelevel = colorConfig["whitelevel"].asDouble(); + + ColorTransform* transform = new ColorTransform(threshold, gamma, blacklevel, whitelevel); + return transform; +} +LedString createLedString(const Json::Value& ledsConfig) +{ + LedString ledString; + + for (const Json::Value& ledConfig : ledsConfig) + { + Led led; + led.index = ledConfig["index"].asInt(); + const Json::Value& hscanConfig = ledConfig["hscan"]; + const Json::Value& vscanConfig = ledConfig["vscan"]; + led.minX_frac = std::max(0.0, std::min(100.0, hscanConfig["minimum"].asDouble()))/100.0; + led.maxX_frac = std::max(0.0, std::min(100.0, hscanConfig["maximum"].asDouble()))/100.0; + led.minY_frac = 1.0 - std::max(0.0, std::min(100.0, vscanConfig["maximum"].asDouble()))/100.0; + led.maxY_frac = 1.0 - std::max(0.0, std::min(100.0, vscanConfig["minimum"].asDouble()))/100.0; + + ledString.leds().push_back(led); + } + return ledString; +} + Hyperion::Hyperion(const Json::Value &jsonConfig) : - mLedString(LedString::construct(jsonConfig["leds"], jsonConfig["color"])), - mImage(nullptr), + mLedString(createLedString(jsonConfig["leds"])), + mRedTransform( createColorTransform(jsonConfig["color"]["red"])), + mGreenTransform(createColorTransform(jsonConfig["color"]["green"])), + mBlueTransform( createColorTransform(jsonConfig["color"]["blue"])), mDevice(constructDevice(jsonConfig["device"])) { // empty @@ -45,58 +80,29 @@ Hyperion::Hyperion(const Json::Value &jsonConfig) : Hyperion::~Hyperion() { - // Delete the existing image (or delete nullptr) - delete mImage; - // Delete the Led-String delete mDevice; + + // Delete the color-transform + delete mBlueTransform; + delete mGreenTransform; + delete mRedTransform; } -void Hyperion::setInputSize(const unsigned width, const unsigned height) +void Hyperion::setValue(int priority, std::vector& ledColors) { - // Delete the existing image (or delete nullptr) - delete mImage; - - // Create the new image with the mapping to the leds - mImage = new RgbImage(width, height); - mLedsMap.createMapping(*mImage, mLedString.leds()); -} - -void Hyperion::commit() -{ - // Derive the color per led - std::vector ledColors = mLedsMap.getMeanLedColor(); -// const std::vector ledColors = mLedsMap.getMedianLedColor(); - - // Write the Led colors to the led-string - mDevice->write(ledColors); -} - -void Hyperion::operator() (const RgbImage& inputImage) -{ - // Copy the input-image into the buffer - mImage->copy(inputImage); - - // Derive the color per led - std::vector ledColors = mLedsMap.getMeanLedColor(); -// std::vector ledColors = mLedsMap.getMedianLedColor(); - applyTransform(ledColors); - - // Write the Led colors to the led-string - mDevice->write(ledColors); -} - -void Hyperion::setColor(const RgbColor& color) -{ - mDevice->write(std::vector(mLedString.leds().size(), color)); -} - -void Hyperion::applyTransform(std::vector& colors) const -{ - for (RgbColor& color : colors) + // Apply the transform to each led and color-channel + for (RgbColor& color : ledColors) { - color.red = (color.red < mLedString.red.blacklevel)? 0 : mLedString.red.adjust + mLedString.red.gamma * color.red; - color.green = (color.green < mLedString.green.blacklevel)? 0 : mLedString.green.adjust + mLedString.green.gamma * color.green; - color.blue = (color.blue < mLedString.blue.blacklevel)? 0 : mLedString.blue.adjust + mLedString.blue.gamma * color.blue; + color.red = mRedTransform->transform(color.red); + color.green = mGreenTransform->transform(color.green); + color.blue = mBlueTransform->transform(color.blue); + } + + mMuxer.setInput(priority, ledColors); + + if (priority == mMuxer.getCurrentPriority()) + { + mDevice->write(ledColors); } } diff --git a/libsrc/hyperion/ImageProcessor.cpp b/libsrc/hyperion/ImageProcessor.cpp new file mode 100644 index 00000000..df508212 --- /dev/null +++ b/libsrc/hyperion/ImageProcessor.cpp @@ -0,0 +1,65 @@ +#include + + +#include "ImageToLedsMap.h" +#include "ColorTransform.h" + +using namespace hyperion; + +ImageProcessor::ImageProcessor(const LedString& ledString) : + mLedString(ledString), + mBuffer(nullptr), + mImageToLeds(nullptr) +{ + // empty +} + +ImageProcessor::~ImageProcessor() +{ + delete mImageToLeds; + delete mBuffer; +} + +std::vector ImageProcessor::process(const RgbImage& image) +{ + // Ensure that the buffer-image is the proper size + setSize(image.width(), image.height()); + + // Copy the data of the given image into the mapped-image + mBuffer->copy(image); + + // Create a result vector and call the 'in place' functionl + std::vector colors(mLedString.leds().size(), RgbColor::BLACK); + inplace_process(colors); + + // return the computed colors + return colors; +} + +void ImageProcessor::setSize(const unsigned width, const unsigned height) +{ + // Check if the existing buffer-image is already the correct dimensions + if (mBuffer && mBuffer->width() == width && mBuffer->height() == height) + { + return; + } + + // Clean up the old buffer and mapping + delete mImageToLeds; + delete mBuffer; + + // Construct a new buffer and mapping + mBuffer = new RgbImage(width, height); + mImageToLeds = new ImageToLedsMap(*mBuffer, mLedString.leds()); +} + +RgbImage& ImageProcessor::image() +{ + return *mBuffer; +} + +void ImageProcessor::inplace_process(std::vector& ledColors) +{ + // Determine the mean-colors of each led (using the existing mapping) + mImageToLeds->getMeanLedColor(ledColors); +} diff --git a/libsrc/hyperion/ImageProcessorFactory.cpp b/libsrc/hyperion/ImageProcessorFactory.cpp new file mode 100644 index 00000000..52837c6a --- /dev/null +++ b/libsrc/hyperion/ImageProcessorFactory.cpp @@ -0,0 +1,21 @@ + +// Hyperion includes +#include +#include + +ImageProcessorFactory& ImageProcessorFactory::getInstance() +{ + static ImageProcessorFactory instance; + // Return the singleton instance + return instance; +} + +void ImageProcessorFactory::init(const LedString& ledString) +{ + _ledString = ledString; +} + +ImageProcessor* ImageProcessorFactory::newImageProcessor() const +{ + return new ImageProcessor(_ledString); +} diff --git a/libsrc/hyperion/ImageToLedsMap.cpp b/libsrc/hyperion/ImageToLedsMap.cpp index 2acd9a17..98e25425 100644 --- a/libsrc/hyperion/ImageToLedsMap.cpp +++ b/libsrc/hyperion/ImageToLedsMap.cpp @@ -3,14 +3,11 @@ #include // hyperion includes -#include +#include "ImageToLedsMap.h" -ImageToLedsMap::ImageToLedsMap() -{ - // empty -} +using namespace hyperion; -void ImageToLedsMap::createMapping(const RgbImage& image, const std::vector& leds) +ImageToLedsMap::ImageToLedsMap(const RgbImage& image, const std::vector& leds) { mColorsMap.resize(leds.size(), std::vector()); @@ -46,6 +43,19 @@ std::vector ImageToLedsMap::getMeanLedColor() return colors; } +void ImageToLedsMap::getMeanLedColor(std::vector& ledColors) +{ + // Sanity check for the number of leds + assert(mColorsMap.size() == ledColors.size()); + + auto led = ledColors.begin(); + for (auto ledColors = mColorsMap.begin(); ledColors != mColorsMap.end(); ++ledColors, ++led) + { + const RgbColor color = findMeanColor(*ledColors); + *led = color; + } +} + RgbColor ImageToLedsMap::findMeanColor(const std::vector& colors) { uint_fast16_t cummRed = 0; @@ -64,27 +74,3 @@ RgbColor ImageToLedsMap::findMeanColor(const std::vector& color return {avgRed, avgGreen, avgBlue}; } - -std::vector ImageToLedsMap::getMedianLedColor() -{ - std::vector ledColors; - for (std::vector& colors : mColorsMap) - { - const RgbColor color = findMedianColor(colors); - ledColors.push_back(color); - } - - return ledColors; -} - -RgbColor ImageToLedsMap::findMedianColor(std::vector& colors) -{ - std::sort(colors.begin(), colors.end(), [](const RgbColor* lhs, const RgbColor* rhs){ return lhs->red < rhs->red; }); - const uint8_t red = colors.at(colors.size()/2)->red; - std::sort(colors.begin(), colors.end(), [](const RgbColor* lhs, const RgbColor* rhs){ return lhs->green < rhs->green; }); - const uint8_t green = colors.at(colors.size()/2)->green; - std::sort(colors.begin(), colors.end(), [](const RgbColor* lhs, const RgbColor* rhs){ return lhs->blue < rhs->blue; }); - const uint8_t blue = colors.at(colors.size()/2)->blue; - - return {red, green, blue}; -} diff --git a/libsrc/hyperion/ImageToLedsMap.h b/libsrc/hyperion/ImageToLedsMap.h new file mode 100644 index 00000000..5e4a4e9c --- /dev/null +++ b/libsrc/hyperion/ImageToLedsMap.h @@ -0,0 +1,57 @@ + +#pragma once + +// hyperion-utils includes +#include + +// hyperion includes +#include + +namespace hyperion +{ + +class ImageToLedsMap +{ +public: + + /** + * Constructs an mapping from the colors in the image to each led based on the border + * definition given in the list of leds. The map holds pointers to the given image and its + * lifetime should never exceed that of the given image + * + * @param[in] image The RGB image + * @param[in] leds The list with led specifications + */ + ImageToLedsMap(const RgbImage& image, const std::vector& leds); + + /** + * Determines the mean-color for each led using the mapping the image given + * at construction. + * + * @return ledColors The vector containing the output + */ + std::vector getMeanLedColor(); + + /** + * Determines the mean-color for each led using the mapping the image given + * at construction. + * + * @param[out] ledColors The vector containing the output + */ + void getMeanLedColor(std::vector& ledColors); + +private: + std::vector > mColorsMap; + + /** + * Finds the 'mean color' of the given list. This is the mean over each color-channel (red, + * green, blue) + * + * @param colors The list with colors + * + * @return The mean of the given list of colors (or black when empty) + */ + RgbColor findMeanColor(const std::vector& colors); +}; + +} // end namespace hyperion diff --git a/libsrc/hyperion/LedString.cpp b/libsrc/hyperion/LedString.cpp index fadb260e..38c1b8f9 100644 --- a/libsrc/hyperion/LedString.cpp +++ b/libsrc/hyperion/LedString.cpp @@ -9,41 +9,6 @@ // hyperion includes #include -LedString LedString::construct(const Json::Value& ledsConfig, const Json::Value& colorConfig) -{ - LedString ledString; - - const Json::Value& redConfig = colorConfig["red"]; - const Json::Value& greenConfig = colorConfig["greem"]; - const Json::Value& blueConfig = colorConfig["blue"]; - - ledString.red.gamma = redConfig["gamma"].asDouble(); - ledString.red.adjust = redConfig["adjust"].asDouble(); - ledString.red.blacklevel = redConfig["blacklevel"].asDouble(); - - ledString.green.gamma = greenConfig["gamma"].asDouble(); - ledString.green.adjust = colorConfig["adjust"].asDouble(); - ledString.green.blacklevel = colorConfig["blacklevel"].asDouble(); - - ledString.blue.gamma = blueConfig["gamma"].asDouble(); - ledString.blue.adjust = blueConfig["adjust"].asDouble(); - ledString.blue.blacklevel = blueConfig["blacklevel"].asDouble(); - - for (const Json::Value& ledConfig : ledsConfig) - { - Led led; - led.index = ledConfig["index"].asInt(); - const Json::Value& hscanConfig = ledConfig["hscan"]; - const Json::Value& vscanConfig = ledConfig["vscan"]; - led.minX_frac = std::max(0.0, std::min(100.0, hscanConfig["minimum"].asDouble()))/100.0; - led.maxX_frac = std::max(0.0, std::min(100.0, hscanConfig["maximum"].asDouble()))/100.0; - led.minY_frac = 1.0 - std::max(0.0, std::min(100.0, vscanConfig["maximum"].asDouble()))/100.0; - led.maxY_frac = 1.0 - std::max(0.0, std::min(100.0, vscanConfig["minimum"].asDouble()))/100.0; - - ledString.mLeds.push_back(led); - } - return ledString; -} LedString::LedString() { @@ -54,6 +19,11 @@ LedString::~LedString() { } +std::vector& LedString::leds() +{ + return mLeds; +} + const std::vector& LedString::leds() const { return mLeds; diff --git a/libsrc/hyperion/PriorityMuxer.cpp b/libsrc/hyperion/PriorityMuxer.cpp new file mode 100644 index 00000000..2321cccd --- /dev/null +++ b/libsrc/hyperion/PriorityMuxer.cpp @@ -0,0 +1,94 @@ + +// STL includes +#include +#include + +// Hyperion includes +#include + +PriorityMuxer::PriorityMuxer() : + mCurrentPriority(MAX_PRIORITY) +{ + // empty +} + +PriorityMuxer::~PriorityMuxer() +{ + // empty +} + +int PriorityMuxer::getCurrentPriority() const +{ + return mCurrentPriority; +} + +QList PriorityMuxer::getPriorities() const +{ + return mActiveInputs.keys(); +} + +bool PriorityMuxer::hasPriority(const int priority) const +{ + return mActiveInputs.contains(priority); +} + +const PriorityMuxer::InputInfo& PriorityMuxer::getInputInfo(const int priority) const +{ + auto elemIt = mActiveInputs.find(priority); + if (elemIt == mActiveInputs.end()) + { + throw std::runtime_error("no such priority"); + } + return elemIt.value(); +} + +void PriorityMuxer::setInput(const int priority, const std::vector& ledColors, const int64_t timeoutTime_ms) +{ + InputInfo& input = mActiveInputs[priority]; + input.priority = priority; + input.timeoutTime_ms = timeoutTime_ms; + input.ledColors = ledColors; + + mCurrentPriority = std::min(mCurrentPriority, priority); +} + +void PriorityMuxer::clearInput(const int priority) +{ + mActiveInputs.remove(priority); + if (mCurrentPriority == priority) + { + if (mActiveInputs.empty()) + { + mCurrentPriority = MAX_PRIORITY; + } + else + { + QList keys = mActiveInputs.keys(); + mCurrentPriority = *std::min_element(keys.begin(), keys.end()); + } + } +} + +void PriorityMuxer::clearAll() +{ + mActiveInputs.clear(); + mCurrentPriority = MAX_PRIORITY; +} + +void PriorityMuxer::setCurrentTime(const int64_t& now) +{ + mCurrentPriority = MAX_PRIORITY; + + for (auto infoIt = mActiveInputs.begin(); infoIt != mActiveInputs.end();) + { + if (infoIt->timeoutTime_ms != -1 && infoIt->timeoutTime_ms <= now) + { + infoIt = mActiveInputs.erase(infoIt); + } + else + { + mCurrentPriority = std::min(mCurrentPriority, infoIt->priority); + ++infoIt; + } + } +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dbf76456..a6083718 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,12 @@ add_executable(WriteConfig WriteConfig.cpp) +add_executable(HyperionDispmanx + HyperionMain.cpp) + +target_link_libraries(HyperionDispmanx + hyperion) + add_executable(boblight-dispmanx boblight-dispmanx.cpp flagmanager.h @@ -27,12 +33,12 @@ target_link_libraries(boblight-dispmanx bob2hyperion ${BCM_LIBRARIES}) -add_executable(HyperionDispmanX - HyperionDispmanX.cpp) +#add_executable(HyperionDispmanX +# HyperionDispmanX.cpp) -target_link_libraries(HyperionDispmanX - hyperion - ${BCM_LIBRARIES}) +#target_link_libraries(HyperionDispmanX +# hyperion +# ${BCM_LIBRARIES}) # Find the libPNG diff --git a/src/HyperionDispmanX.cpp b/src/HyperionDispmanX.cpp index 69b5c942..8af333eb 100644 --- a/src/HyperionDispmanX.cpp +++ b/src/HyperionDispmanX.cpp @@ -43,7 +43,7 @@ int main(int /*argc*/, char** /*argv*/) } Hyperion hyperion(raspiConfig); - dispmanx_process(hyperion, sRunning); +// dispmanx_process(hyperion, sRunning); return 0; } diff --git a/src/HyperionMain.cpp b/src/HyperionMain.cpp new file mode 100644 index 00000000..988db273 --- /dev/null +++ b/src/HyperionMain.cpp @@ -0,0 +1,17 @@ + +// QT includes +#include + +// Hyperion includes +#include + +int main(int argc, char** argv) +{ + QCoreApplication app(argc, argv); + + + DispmanxWrapper dispmanx; + dispmanx.start(); + + app.exec(); +} diff --git a/src/ViewPng.cpp b/src/ViewPng.cpp index 917a4976..04e0ccd1 100644 --- a/src/ViewPng.cpp +++ b/src/ViewPng.cpp @@ -144,10 +144,10 @@ int main(int argc, char** argv) FbWriter fbWriter; Hyperion raspiLight(raspiConfig); - raspiLight.setInputSize(image->width(), image->height()); +// raspiLight.setInputSize(image->width(), image->height()); fbWriter.writeImage(*image); - raspiLight(*image); +// raspiLight(*image); sleep(5); diff --git a/src/flagmanager.cpp b/src/flagmanager.cpp index de5623e8..cf3a608b 100644 --- a/src/flagmanager.cpp +++ b/src/flagmanager.cpp @@ -1,17 +1,17 @@ /* * boblight - * Copyright (C) Bob 2009 - * + * Copyright (C) Bob 2009 + * * boblight is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * boblight is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -35,16 +35,16 @@ CArguments::CArguments(int argc, char** argv) if (m_argc == 0) { - m_argv = NULL; + m_argv = NULL; } else { - m_argv = new char*[m_argc]; - for (int i = 0; i < m_argc; i++) - { - m_argv[i] = new char[strlen(argv[i]) + 1]; - strcpy(m_argv[i], argv[i]); - } + m_argv = new char*[m_argc]; + for (int i = 0; i < m_argc; i++) + { + m_argv[i] = new char[strlen(argv[i]) + 1]; + strcpy(m_argv[i], argv[i]); + } } } @@ -53,11 +53,11 @@ CArguments::~CArguments() { if (m_argv) { - for (int i = 0; i < m_argc; i++) - { - delete[] m_argv[i]; - } - delete[] m_argv; + for (int i = 0; i < m_argc; i++) + { + delete[] m_argv[i]; + } + delete[] m_argv; } } @@ -87,75 +87,75 @@ void CFlagManager::ParseFlags(int tempargc, char** tempargv) int c; opterr = 0; //we don't want to print error messages - + while ((c = getopt(argc, argv, m_flags.c_str())) != -1) { - if (c == 'p') //priority - { - option = optarg; - if (!StrToInt(option, m_priority) || m_priority < 0 || m_priority > 255) - { - throw string("Wrong option " + string(optarg) + " for argument -p"); - } - } - else if (c == 's') //address[:port] - { - option = optarg; - //store address in string and set the char* to it - m_straddress = option.substr(0, option.find(':')); - m_address = m_straddress.c_str(); + if (c == 'p') //priority + { + option = optarg; + if (!StrToInt(option, m_priority) || m_priority < 0 || m_priority > 255) + { + throw string("Wrong option " + string(optarg) + " for argument -p"); + } + } + else if (c == 's') //address[:port] + { + option = optarg; + //store address in string and set the char* to it + m_straddress = option.substr(0, option.find(':')); + m_address = m_straddress.c_str(); - if (option.find(':') != string::npos) //check if we have a port - { - option = option.substr(option.find(':') + 1); - string word; - if (!StrToInt(option, m_port) || m_port < 0 || m_port > 65535) - { - throw string("Wrong option " + string(optarg) + " for argument -s"); - } - } - } - else if (c == 'o') //option for libboblight - { - m_options.push_back(optarg); - } - else if (c == 'l') //list libboblight options - { - m_printboblightoptions = true; - return; - } - else if (c == 'h') //print help message - { - m_printhelp = true; - return; - } - else if (c == 'f') - { - m_fork = true; - } - else if (c == 'y') - { - if (!StrToBool(optarg, m_sync)) - { - throw string("Wrong value " + string(optarg) + " for sync mode"); - } - } - else if (c == '?') //unknown option - { - //check if we know this option, but expected an argument - if (m_flags.find(ToString((char)optopt) + ":") != string::npos) - { - throw string("Option " + ToString((char)optopt) + "requires an argument"); - } - else - { - throw string("Unkown option " + ToString((char)optopt)); - } - } - else - { - ParseFlagsExtended(argc, argv, c, optarg); //pass our argument to a derived class - } + if (option.find(':') != string::npos) //check if we have a port + { + option = option.substr(option.find(':') + 1); + string word; + if (!StrToInt(option, m_port) || m_port < 0 || m_port > 65535) + { + throw string("Wrong option " + string(optarg) + " for argument -s"); + } + } + } + else if (c == 'o') //option for libboblight + { + m_options.push_back(optarg); + } + else if (c == 'l') //list libboblight options + { + m_printboblightoptions = true; + return; + } + else if (c == 'h') //print help message + { + m_printhelp = true; + return; + } + else if (c == 'f') + { + m_fork = true; + } + else if (c == 'y') + { + if (!StrToBool(optarg, m_sync)) + { + throw string("Wrong value " + string(optarg) + " for sync mode"); + } + } + else if (c == '?') //unknown option + { + //check if we know this option, but expected an argument + if (m_flags.find(ToString((char)optopt) + ":") != string::npos) + { + throw string("Option " + ToString((char)optopt) + "requires an argument"); + } + else + { + throw string("Unkown option " + ToString((char)optopt)); + } + } + else + { + ParseFlagsExtended(argc, argv, c, optarg); //pass our argument to a derived class + } } PostGetopt(optind, argc, argv); //some postprocessing @@ -169,7 +169,7 @@ void CFlagManager::PrintBoblightOptions() for (int i = 0; i < nroptions; i++) { - cout << boblight_getoptiondescript(boblight, i) << "\n"; + cout << boblight_getoptiondescript(boblight, i) << "\n"; } boblight_destroy(boblight); @@ -178,74 +178,74 @@ void CFlagManager::PrintBoblightOptions() void CFlagManager::ParseBoblightOptions(void* boblight) { int nrlights = boblight_getnrlights(boblight); - - for (int i = 0; i < m_options.size(); i++) + + for (size_t i = 0; i < m_options.size(); i++) { - string option = m_options[i]; - string lightname; - string optionname; - string optionvalue; - int lightnr = -1; + string option = m_options[i]; + string lightname; + string optionname; + string optionvalue; + int lightnr = -1; - //check if we have a lightname, otherwise we use all lights - if (option.find(':') != string::npos) - { - lightname = option.substr(0, option.find(':')); - if (option.find(':') == option.size() - 1) //check if : isn't the last char in the string - { - throw string("wrong option \"" + option + "\", syntax is [light:]option=value"); - } - option = option.substr(option.find(':') + 1); //shave off the lightname + //check if we have a lightname, otherwise we use all lights + if (option.find(':') != string::npos) + { + lightname = option.substr(0, option.find(':')); + if (option.find(':') == option.size() - 1) //check if : isn't the last char in the string + { + throw string("wrong option \"" + option + "\", syntax is [light:]option=value"); + } + option = option.substr(option.find(':') + 1); //shave off the lightname - //check which light this is - bool lightfound = false; - for (int j = 0; j < nrlights; j++) - { - if (lightname == boblight_getlightname(boblight, j)) - { - lightfound = true; - lightnr = j; - break; - } - } - if (!lightfound) - { - throw string("light \"" + lightname + "\" used in option \"" + m_options[i] + "\" doesn't exist"); - } - } + //check which light this is + bool lightfound = false; + for (int j = 0; j < nrlights; j++) + { + if (lightname == boblight_getlightname(boblight, j)) + { + lightfound = true; + lightnr = j; + break; + } + } + if (!lightfound) + { + throw string("light \"" + lightname + "\" used in option \"" + m_options[i] + "\" doesn't exist"); + } + } - //check if '=' exists and it's not at the end of the string - if (option.find('=') == string::npos || option.find('=') == option.size() - 1) - { - throw string("wrong option \"" + option + "\", syntax is [light:]option=value"); - } + //check if '=' exists and it's not at the end of the string + if (option.find('=') == string::npos || option.find('=') == option.size() - 1) + { + throw string("wrong option \"" + option + "\", syntax is [light:]option=value"); + } - optionname = option.substr(0, option.find('=')); //option name is everything before = (already shaved off the lightname here) - optionvalue = option.substr(option.find('=') + 1); //value is everything after = + optionname = option.substr(0, option.find('=')); //option name is everything before = (already shaved off the lightname here) + optionvalue = option.substr(option.find('=') + 1); //value is everything after = - option = optionname + " " + optionvalue; //libboblight wants syntax without = + option = optionname + " " + optionvalue; //libboblight wants syntax without = - //bitch if we can't set this option - if (!boblight_setoption(boblight, lightnr, option.c_str())) - { - throw string(boblight_geterror(boblight)); - } + //bitch if we can't set this option + if (!boblight_setoption(boblight, lightnr, option.c_str())) + { + throw string(boblight_geterror(boblight)); + } } } bool CFlagManager::SetVideoGamma() { - for (int i = 0; i < m_options.size(); i++) + for (size_t i = 0; i < m_options.size(); i++) { - string option = m_options[i]; - if (option.find(':') != string::npos) - option = option.substr(option.find(':') + 1); //shave off the lightname + string option = m_options[i]; + if (option.find(':') != string::npos) + option = option.substr(option.find(':') + 1); //shave off the lightname - if (option.find('=') != string::npos) - { - if (option.substr(0, option.find('=')) == "gamma") - return false; //gamma set by user, don't override - } + if (option.find('=') != string::npos) + { + if (option.substr(0, option.find('=')) == "gamma") + return false; //gamma set by user, don't override + } } m_options.push_back("gamma=" + ToString(VIDEOGAMMA)); diff --git a/src/misc.h b/src/misc.h index f6ef4f3c..76593a46 100644 --- a/src/misc.h +++ b/src/misc.h @@ -1,17 +1,17 @@ /* * boblight - * Copyright (C) Bob 2009 - * + * Copyright (C) Bob 2009 + * * boblight is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * boblight is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -96,15 +96,15 @@ inline A Round(B value) { if (value == 0.0) { - return 0; + return 0; } else if (value > 0.0) { - return (A)(value + 0.5); + return (A)(value + 0.5); } else { - return (A)(value - 0.5); + return (A)(value - 0.5); } } @@ -135,7 +135,7 @@ inline bool StrToInt(const std::string& data, int& value) inline bool StrToInt(const std::string& data, int64_t& value) { - return sscanf(data.c_str(), "%ld", &value) == 1; + return sscanf(data.c_str(), "%lld", &value) == 1; } inline bool HexStrToInt(const std::string& data, int& value) @@ -145,7 +145,7 @@ inline bool HexStrToInt(const std::string& data, int& value) inline bool HexStrToInt(const std::string& data, int64_t& value) { - return sscanf(data.c_str(), "%x", &value) == 1; + return sscanf(data.c_str(), "%llx", &value) == 1; } inline bool StrToFloat(const std::string& data, float& value) @@ -163,26 +163,26 @@ inline bool StrToBool(const std::string& data, bool& value) std::string data2 = data; std::string word; if (!GetWord(data2, word)) - return false; - + return false; + if (word == "1" || word == "true" || word == "on" || word == "yes") { - value = true; - return true; + value = true; + return true; } else if (word == "0" || word == "false" || word == "off" || word == "no") { - value = false; - return true; + value = false; + return true; } else { - int ivalue; - if (StrToInt(word, ivalue)) - { - value = ivalue != 0; - return true; - } + int ivalue; + if (StrToInt(word, ivalue)) + { + value = ivalue != 0; + return true; + } } return false; diff --git a/test/TestColorTransform.cpp b/test/TestColorTransform.cpp index 376ac6bd..ebaaf475 100644 --- a/test/TestColorTransform.cpp +++ b/test/TestColorTransform.cpp @@ -1,93 +1,96 @@ +// STL includes #include #include -#include +#include <../../libsrc/hyperion/ColorTransform.h> + +using namespace hyperion; int main() { - { - std::cout << "Testing linear transform" << std::endl; - ColorTransform t; - for (int i = 0; i < 256; ++i) - { - uint8_t input = i; - uint8_t output = t.transform(input); - uint8_t expected = input; + { + std::cout << "Testing linear transform" << std::endl; + ColorTransform t; + for (int i = 0; i < 256; ++i) + { + uint8_t input = i; + uint8_t output = t.transform(input); + uint8_t expected = input; - if (output != expected) - { - std::cerr << "ERROR: input (" << (int)input << ") => output (" << (int)output << ") : expected (" << (int) expected << ")" << std::endl; - return 1; - } - else - { - std::cerr << "OK: input (" << (int)input << ") => output (" << (int)output << ")" << std::endl; - } - } - } + if (output != expected) + { + std::cerr << "ERROR: input (" << (int)input << ") => output (" << (int)output << ") : expected (" << (int) expected << ")" << std::endl; + return 1; + } + else + { + std::cerr << "OK: input (" << (int)input << ") => output (" << (int)output << ")" << std::endl; + } + } + } - { - std::cout << "Testing threshold" << std::endl; - ColorTransform t(.10, 1.0, 0.0, 1.0); - for (int i = 0; i < 256; ++i) - { - uint8_t input = i; - uint8_t output = t.transform(input); - uint8_t expected = ((i/255.0) < t.getThreshold() ? 0 : output); + { + std::cout << "Testing threshold" << std::endl; + ColorTransform t(.10, 1.0, 0.0, 1.0); + for (int i = 0; i < 256; ++i) + { + uint8_t input = i; + uint8_t output = t.transform(input); + uint8_t expected = ((i/255.0) < t.getThreshold() ? 0 : output); - if (output != expected) - { - std::cerr << "ERROR: input (" << (int)input << ") => output (" << (int)output << ") : expected (" << (int) expected << ")" << std::endl; - return 1; - } - else - { - std::cerr << "OK: input (" << (int)input << ") => output (" << (int)output << ")" << std::endl; - } - } - } + if (output != expected) + { + std::cerr << "ERROR: input (" << (int)input << ") => output (" << (int)output << ") : expected (" << (int) expected << ")" << std::endl; + return 1; + } + else + { + std::cerr << "OK: input (" << (int)input << ") => output (" << (int)output << ")" << std::endl; + } + } + } - { - std::cout << "Testing blacklevel and whitelevel" << std::endl; - ColorTransform t(0, 1.0, 0.2, 0.8); - for (int i = 0; i < 256; ++i) - { - uint8_t input = i; - uint8_t output = t.transform(input); - uint8_t expected = (uint8_t)(input * (t.getWhitelevel()-t.getBlacklevel()) + 255 * t.getBlacklevel()); + { + std::cout << "Testing blacklevel and whitelevel" << std::endl; + ColorTransform t(0, 1.0, 0.2, 0.8); + for (int i = 0; i < 256; ++i) + { + uint8_t input = i; + uint8_t output = t.transform(input); + uint8_t expected = (uint8_t)(input * (t.getWhitelevel()-t.getBlacklevel()) + 255 * t.getBlacklevel()); - if (output != expected) - { - std::cerr << "ERROR: input (" << (int)input << ") => output (" << (int)output << ") : expected (" << (int) expected << ")" << std::endl; - return 1; - } - else - { - std::cerr << "OK: input (" << (int)input << ") => output (" << (int)output << ")" << std::endl; - } - } - } + if (output != expected) + { + std::cerr << "ERROR: input (" << (int)input << ") => output (" << (int)output << ") : expected (" << (int) expected << ")" << std::endl; + return 1; + } + else + { + std::cerr << "OK: input (" << (int)input << ") => output (" << (int)output << ")" << std::endl; + } + } + } - { - std::cout << "Testing gamma" << std::endl; - ColorTransform t(0, 2.0, 0.0, 1.0); - for (int i = 0; i < 256; ++i) - { - uint8_t input = i; - uint8_t output = t.transform(input); - uint8_t expected = (uint8_t)(255 * std::pow(i / 255.0, 2)); + { + std::cout << "Testing gamma" << std::endl; + ColorTransform t(0, 2.0, 0.0, 1.0); + for (int i = 0; i < 256; ++i) + { + uint8_t input = i; + uint8_t output = t.transform(input); + uint8_t expected = (uint8_t)(255 * std::pow(i / 255.0, 2)); - if (output != expected) - { - std::cerr << "ERROR: input (" << (int)input << ") => output (" << (int)output << ") : expected (" << (int) expected << ")" << std::endl; - return 1; - } - else - { - std::cerr << "OK: input (" << (int)input << ") => output (" << (int)output << ")" << std::endl; - } - } - } + if (output != expected) + { + std::cerr << "ERROR: input (" << (int)input << ") => output (" << (int)output << ") : expected (" << (int) expected << ")" << std::endl; + return 1; + } + else + { + std::cerr << "OK: input (" << (int)input << ") => output (" << (int)output << ")" << std::endl; + } + } + } - return 0; + return 0; } diff --git a/test/TestConfigFile.cpp b/test/TestConfigFile.cpp index cb330de3..41e9d5cf 100644 --- a/test/TestConfigFile.cpp +++ b/test/TestConfigFile.cpp @@ -32,7 +32,7 @@ int main() double redGamma = redConfig["gamma"].asDouble(); std::cout << "RED GAMMA = " << redGamma << std::endl; std::cout << "RED GAMMA = " << colorConfig["red.gamma"].asDouble() << std::endl; - LedString ledString = LedString::construct(ledConfig, colorConfig); +// LedString ledString = LedString::construct(ledConfig, colorConfig); return 0; } From 2ec9f9202e13b9a51bc5399ea8a086a91328d73c Mon Sep 17 00:00:00 2001 From: "T. van der Zwan" Date: Tue, 13 Aug 2013 10:03:00 +0000 Subject: [PATCH 2/2] Deleted all files referencing/using boblight --- include/boblight-functions.h | 41 - include/boblight.h | 103 - include/hyperion/ImageProcessor.h | 4 +- libsrc/CMakeLists.txt | 24 +- libsrc/bob2hyperion.cpp | 141 -- libsrc/hyperion-png.cpp | 174 -- libsrc/hyperion/CMakeLists.txt | 11 +- libsrc/hyperion/DispmanxFrameGrabber.cpp | 2 + libsrc/hyperion/DispmanxFrameGrabber.h | 1 + libsrc/hyperion/DispmanxWrapper.cpp | 9 +- libsrc/hyperionpng/pngwriter.cc | 2258 +++++++++++----------- src/CMakeLists.txt | 42 +- src/HyperionDispmanX.cpp | 49 - src/boblight-dispmanx.cpp | 179 -- src/dispmanx-helper.h | 59 - src/dispmanx-png/CMakeLists.txt | 13 - src/dispmanx-png/dispmanx-png.cpp | 28 - src/flagmanager-dispmanx.cpp | 106 - src/flagmanager-dispmanx.h | 44 - src/flagmanager.cpp | 257 --- src/flagmanager.h | 72 - src/grabber-dispmanx.cpp | 165 -- src/grabber-dispmanx.h | 90 - src/{HyperionMain.cpp => hyperion-d.cpp} | 0 src/misc.cpp | 81 - src/misc.h | 191 -- src/timer.cpp | 69 - src/timer.h | 42 - src/timeutils.cpp | 56 - src/timeutils.h | 49 - test/CMakeLists.txt | 31 +- test/Test2BobLight.cpp | 39 - test/TestBoblightOrig.cpp | 16 - test/TestConfigFile.cpp | 28 +- 34 files changed, 1183 insertions(+), 3291 deletions(-) delete mode 100644 include/boblight-functions.h delete mode 100644 include/boblight.h delete mode 100644 libsrc/bob2hyperion.cpp delete mode 100644 libsrc/hyperion-png.cpp delete mode 100644 src/HyperionDispmanX.cpp delete mode 100644 src/boblight-dispmanx.cpp delete mode 100644 src/dispmanx-helper.h delete mode 100644 src/dispmanx-png/CMakeLists.txt delete mode 100644 src/dispmanx-png/dispmanx-png.cpp delete mode 100644 src/flagmanager-dispmanx.cpp delete mode 100644 src/flagmanager-dispmanx.h delete mode 100644 src/flagmanager.cpp delete mode 100644 src/flagmanager.h delete mode 100644 src/grabber-dispmanx.cpp delete mode 100644 src/grabber-dispmanx.h rename src/{HyperionMain.cpp => hyperion-d.cpp} (100%) delete mode 100644 src/misc.cpp delete mode 100644 src/misc.h delete mode 100644 src/timer.cpp delete mode 100644 src/timer.h delete mode 100644 src/timeutils.cpp delete mode 100644 src/timeutils.h delete mode 100644 test/Test2BobLight.cpp delete mode 100644 test/TestBoblightOrig.cpp diff --git a/include/boblight-functions.h b/include/boblight-functions.h deleted file mode 100644 index 0e0731e0..00000000 --- a/include/boblight-functions.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -//these definitions can be expanded to make normal prototypes, or functionpointers and dlsym lines - -BOBLIGHT_FUNCTION(void*, boblight_init, ()); -BOBLIGHT_FUNCTION(void, boblight_destroy, (void* vpboblight)); - -BOBLIGHT_FUNCTION(int, boblight_connect, (void* vpboblight, const char* address, int port, int usectimeout)); -BOBLIGHT_FUNCTION(int, boblight_setpriority, (void* vpboblight, int priority)); -BOBLIGHT_FUNCTION(const char*, boblight_geterror, (void* vpboblight)); -BOBLIGHT_FUNCTION(int, boblight_getnrlights, (void* vpboblight)); -BOBLIGHT_FUNCTION(const char*, boblight_getlightname, (void* vpboblight, int lightnr)); - -BOBLIGHT_FUNCTION(int, boblight_getnroptions, (void* vpboblight)); -BOBLIGHT_FUNCTION(const char*, boblight_getoptiondescript,(void* vpboblight, int option)); -BOBLIGHT_FUNCTION(int, boblight_setoption, (void* vpboblight, int lightnr, const char* option)); -BOBLIGHT_FUNCTION(int, boblight_getoption, (void* vpboblight, int lightnr, const char* option, const char** output)); - -BOBLIGHT_FUNCTION(void, boblight_setscanrange, (void* vpboblight, int width, int height)); - -BOBLIGHT_FUNCTION(int, boblight_addpixel, (void* vpboblight, int lightnr, int* rgb)); -BOBLIGHT_FUNCTION(void, boblight_addpixelxy, (void* vpboblight, int x, int y, int* rgb)); - -BOBLIGHT_FUNCTION(int, boblight_sendrgb, (void* vpboblight, int sync, int* outputused)); -BOBLIGHT_FUNCTION(int, boblight_ping, (void* vpboblight, int* outputused)); diff --git a/include/boblight.h b/include/boblight.h deleted file mode 100644 index c5963570..00000000 --- a/include/boblight.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -//if you define BOBLIGHT_DLOPEN, all boblight functions are defined as pointers -//you can then call boblight_loadlibrary to load libboblight with dlopen and the function pointers with dlsym -//if you pass NULL to boblight_loadlibrary's first argument, the default filename for libboblight is used -//if boblight_loadlibrary returns NULL, dlopen and dlsym went ok, if not it returns a char* from dlerror - -//if you want to use the boblight functions from multiple files, you can define BOBLIGHT_DLOPEN in one file, -//and define BOBLIGHT_DLOPEN_EXTERN in the other file, the functionpointers are then defined as extern - -#ifndef LIBBOBLIGHT -#define LIBBOBLIGHT - - #if !defined(BOBLIGHT_DLOPEN) && !defined(BOBLIGHT_DLOPEN_EXTERN) - - #ifdef __cplusplus - extern "C" { - #endif - - //generate normal prototypes - #define BOBLIGHT_FUNCTION(returnvalue, name, arguments) returnvalue name arguments - #include "boblight-functions.h" - #undef BOBLIGHT_FUNCTION - - #ifdef __cplusplus - } - #endif - - #elif defined(BOBLIGHT_DLOPEN) - - #include - #include - - //generate function pointers - #define BOBLIGHT_FUNCTION(returnvalue, name, arguments) returnvalue (* name ) arguments = NULL - #include "boblight-functions.h" - #undef BOBLIGHT_FUNCTION - - #ifdef __cplusplus - #define BOBLIGHT_CAST(value) reinterpret_cast - #else - #define BOBLIGHT_CAST(value) (value) - #endif - - //gets a functionpointer from dlsym, and returns char* from dlerror if it didn't work - #define BOBLIGHT_FUNCTION(returnvalue, name, arguments) \ - name = BOBLIGHT_CAST(returnvalue (*) arguments)(dlsym(p_boblight, #name)); \ - { char* error = dlerror(); if (error) return error; } - - void* p_boblight = NULL; //where we put the lib - - //load function pointers - char* boblight_loadlibrary(const char* filename) - { - if (filename == NULL) - filename = "libboblight.so"; - - if (p_boblight != NULL) - { - dlclose(p_boblight); - p_boblight = NULL; - } - - p_boblight = dlopen(filename, RTLD_NOW); - if (p_boblight == NULL) - return dlerror(); - - //generate dlsym lines - #include "boblight-functions.h" - - return NULL; - } - #undef BOBLIGHT_FUNCTION - #undef BOBLIGHT_CAST - - //you can define BOBLIGHT_DLOPEN_EXTERN when you load the library in another file - #elif defined(BOBLIGHT_DLOPEN_EXTERN) - - extern char* boblight_loadlibrary(const char* filename); - extern void* p_boblight; - #define BOBLIGHT_FUNCTION(returnvalue, name, arguments) extern returnvalue (* name ) arguments - #include "boblight-functions.h" - #undef BOBLIGHT_FUNCTION - - #endif //BOBLIGHT_DLOPEN_EXTERN -#endif //LIBBOBLIGHT - diff --git a/include/hyperion/ImageProcessor.h b/include/hyperion/ImageProcessor.h index 26abaa8b..7ee06006 100644 --- a/include/hyperion/ImageProcessor.h +++ b/include/hyperion/ImageProcessor.h @@ -19,6 +19,8 @@ namespace hyperion { class ImageToLedsMap; class ImageProcessor { public: + ~ImageProcessor(); + /** * Processes the image to a list of led colors. This will update the size of the buffer-image * if required and call the image-to-leds mapping to determine the mean color per led. @@ -61,8 +63,6 @@ private: ImageProcessor(const LedString &ledString); - ~ImageProcessor(); - private: const LedString mLedString; diff --git a/libsrc/CMakeLists.txt b/libsrc/CMakeLists.txt index ac0c6c2b..c468630e 100644 --- a/libsrc/CMakeLists.txt +++ b/libsrc/CMakeLists.txt @@ -3,29 +3,7 @@ SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include) SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc) -add_library(bob2hyperion SHARED - bob2hyperion.cpp) - -target_link_libraries(bob2hyperion - hyperion - hyperion-utils) - add_subdirectory(hyperion) add_subdirectory(utils) -# Find the libPNG -find_package(PNG REQUIRED QUIET) - -if (PNG_FOUND) - # Add additional includes dirs - include_directories(${PNG_INCLUDE_DIR}) - - add_library(bob2hyperion-png SHARED - hyperion-png.cpp) - - target_link_libraries(bob2hyperion-png - hyperion-png) - - add_subdirectory(hyperionpng) -endif(PNG_FOUND) - +add_subdirectory(hyperionpng) diff --git a/libsrc/bob2hyperion.cpp b/libsrc/bob2hyperion.cpp deleted file mode 100644 index f76ed71e..00000000 --- a/libsrc/bob2hyperion.cpp +++ /dev/null @@ -1,141 +0,0 @@ - -// SysLog includes -#include - -// Boblight includes -#include "boblight.h" - -// JsonSchema includes -#include - -// Raspilight includes -#include - -static std::ofstream sDebugStream; - -inline Hyperion* rasp_cast(void* hyperion_ptr) -{ - return reinterpret_cast(hyperion_ptr); -} - -void* boblight_init() -{ - std::cout << __PRETTY_FUNCTION__ << std::endl; -// syslog(LOG_INFO, __PRETTY_FUNCTION__); - - const char* homeDir = getenv("RASPILIGHT_HOME"); - if (!homeDir) - { - homeDir = "/etc"; - } - syslog(LOG_INFO, "RASPILIGHT HOME DIR: %s", homeDir); - - const std::string schemaFile = std::string(homeDir) + "/hyperion.schema.json"; - const std::string configFile = std::string(homeDir) + "/hyperion.config.json"; - - Json::Value raspiConfig; - if (JsonFactory::load(schemaFile, configFile, raspiConfig) < 0) - { - syslog(LOG_WARNING, "UNABLE TO LOAD CONFIGURATION"); - return 0; - } - - Hyperion* raspiLight = new Hyperion(raspiConfig); - return reinterpret_cast(raspiLight); -} - -void boblight_destroy(void* hyperion_ptr) -{ - syslog(LOG_INFO, __PRETTY_FUNCTION__); - - Hyperion* raspiLight = rasp_cast(hyperion_ptr); - - // Switch all leds to black (off) -// raspiLight->setColor(RgbColor::BLACK); - - delete raspiLight; - - sDebugStream.close(); -} - -void boblight_setscanrange(void* hyperion_ptr, int width, int height) -{ - syslog(LOG_INFO, __PRETTY_FUNCTION__); - syslog(LOG_INFO, "Configuring scan range [%dx%d]", width, height); - - Hyperion* raspiLight = rasp_cast(hyperion_ptr); -// raspiLight->setInputSize(width, height); -} - -void boblight_addpixelxy(void* hyperion_ptr, int x, int y, int* rgb) -{ - Hyperion* raspiLight = rasp_cast(hyperion_ptr); - const RgbColor color = {uint8_t(rgb[0]), uint8_t(rgb[1]), uint8_t(rgb[2])}; -// raspiLight->image().setPixel(x, y, color); -} - -int boblight_sendrgb(void* hyperion_ptr, int sync, int* outputused) -{ - Hyperion* raspiLight = rasp_cast(hyperion_ptr); -// raspiLight->commit(); - - return 1; -} - -int boblight_connect(void* hyperion_ptr, const char* address, int port, int usectimeout) -{ - std::cout << "SUCCESFULL NO CONNECTION WITH BOBLIGHT" << std::endl; - return 1; -} - -const char* boblight_geterror(void* hyperion_ptr) -{ - return "ERROR"; -} - -int boblight_setpriority(void* hyperion_ptr, int priority) -{ - std::cout << __PRETTY_FUNCTION__ << std::endl; - return 1; -} - - -int boblight_getnrlights(void* hyperion_ptr) -{ - return 1; -} - -const char* boblight_getlightname(void* hyperion_ptr, int lightnr) -{ - return "LIGHT_NAME"; -} - -int boblight_getnroptions(void* hyperion_ptr) -{ - return 1; -} - -const char* boblight_getoptiondescript(void* hyperion_ptr, int option) -{ - return "OPTION-DESCRIPTION"; -} - -int boblight_setoption(void* hyperion_ptr, int lightnr, const char* option) -{ - return 1; -} - -int boblight_getoption(void* hyperion_ptr, int lightnr, const char* option, const char** output) -{ - return 1; -} - -int boblight_addpixel(void* hyperion_ptr, int lightnr, int* rgb) -{ - return 1; -} - -int boblight_ping(void* hyperion_ptr, int* outputused) -{ - return 1; -} diff --git a/libsrc/hyperion-png.cpp b/libsrc/hyperion-png.cpp deleted file mode 100644 index 318431e1..00000000 --- a/libsrc/hyperion-png.cpp +++ /dev/null @@ -1,174 +0,0 @@ - -// STL includes -#include -#include -#include - -// Boblight includes -#include - -// PNGWriter includes -#define NO_FREETYPE -#include "hyperionpng/pngwriter.h" - -struct RaspiPng -{ - pngwriter writer; - unsigned long fileIndex; - - unsigned frameCnt; - - std::ofstream logFile; -}; - -void* boblight_init() -{ - RaspiPng* raspiPng = new RaspiPng(); - - raspiPng->writer.pngwriter_rename("/home/pi/RASPI_0000.png"); - raspiPng->fileIndex = 0; - raspiPng->frameCnt = 0; - raspiPng->logFile.open("/home/pi/raspipng.log"); - - raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl; - - return reinterpret_cast(raspiPng); -} - -void boblight_destroy(void* vpboblight) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl; - - raspiPng->logFile.close(); - delete raspiPng; -} - -void boblight_setscanrange(void* vpboblight, int width, int height) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - raspiPng->logFile << __PRETTY_FUNCTION__ << "(" << width << ", " << height << ")" << std::endl; - - raspiPng->writer.resize(width, height); -} - -void boblight_addpixelxy(void* vpboblight, int x, int y, int* rgb) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - - if (raspiPng->frameCnt%50 == 0) - { - // NB libpngwriter uses a one-based indexing scheme - raspiPng->writer.plot(x+1,y+1, rgb[0]/255.0, rgb[1]/255.0, rgb[2]/255.0); - } -} - -int boblight_sendrgb(void* vpboblight, int sync, int* outputused) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - raspiPng->logFile << __PRETTY_FUNCTION__ << "(" << sync << ", outputused) FRAME " << raspiPng->frameCnt++ << std::endl; - - if (raspiPng->frameCnt%50 == 0) - { - // Write-out the current frame and prepare for the next - raspiPng->writer.write_png(); - - ++raspiPng->fileIndex; - char filename[64]; - - sprintf(filename, "/home/pi/RASPI_%04ld.png", raspiPng->fileIndex); - - raspiPng->writer.pngwriter_rename(filename); - } - - return 1; -} - -int boblight_connect(void* vpboblight, const char* address, int port, int usectimeout) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl; - - return 1; -} - -int boblight_setpriority(void* vpboblight, int priority) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl; - - return 1; -} - -const char* boblight_geterror(void* vpboblight) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl; - - return "ERROR"; -} - -int boblight_getnrlights(void* vpboblight) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl; - - return 50; -} - -const char* boblight_getlightname(void* vpboblight, int lightnr) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl; - - return "LIGHT"; -} - -int boblight_getnroptions(void* vpboblight) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl; - - return 1; -} - -const char* boblight_getoptiondescript(void* vpboblight, int option) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl; - - return ""; -} - -int boblight_setoption(void* vpboblight, int lightnr, const char* option) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl; - - return 1; -} - -int boblight_getoption(void* vpboblight, int lightnr, const char* option, const char** output) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl; - - return 1; -} - -int boblight_addpixel(void* vpboblight, int lightnr, int* rgb) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl; - - return 1; -} - - -int boblight_ping(void* vpboblight, int* outputused) -{ - RaspiPng* raspiPng = reinterpret_cast(vpboblight); - raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl; - - return 1; -} diff --git a/libsrc/hyperion/CMakeLists.txt b/libsrc/hyperion/CMakeLists.txt index eedf202e..e684e617 100644 --- a/libsrc/hyperion/CMakeLists.txt +++ b/libsrc/hyperion/CMakeLists.txt @@ -7,14 +7,18 @@ include_directories(${BCM_INCLUDE_DIRS}) SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/hyperion) SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/hyperion) +# Group the headers that go through the MOC compiler +SET(Hyperion_QT_HEADERS + ${CURRENT_HEADER_DIR}/DispmanxWrapper.h +) + SET(Hyperion_HEADERS + ${CURRENT_HEADER_DIR}/LedString.h ${CURRENT_HEADER_DIR}/Hyperion.h ${CURRENT_HEADER_DIR}/LedDevice.h - ${CURRENT_HEADER_DIR}/LedString.h ${CURRENT_HEADER_DIR}/ImageProcessor.h ${CURRENT_HEADER_DIR}/ImageProcessorFactory.h ${CURRENT_HEADER_DIR}/PriorityMuxer.h - ${CURRENT_HEADER_DIR}/DispmanxWrapper.h ${CURRENT_SOURCE_DIR}/DispmanxFrameGrabber.h @@ -38,10 +42,11 @@ SET(Hyperion_SOURCES ${CURRENT_SOURCE_DIR}/ColorTransform.cpp ) -QT4_WRAP_CPP(Hyperion_HEADERS_MOC ${Hyperion_HEADERS}) +QT4_WRAP_CPP(Hyperion_HEADERS_MOC ${Hyperion_QT_HEADERS}) add_library(hyperion ${Hyperion_HEADERS} + ${Hyperion_QT_HEADERS} ${Hyperion_HEADERS_MOC} ${Hyperion_SOURCES} ) diff --git a/libsrc/hyperion/DispmanxFrameGrabber.cpp b/libsrc/hyperion/DispmanxFrameGrabber.cpp index 27d67f96..b4cfaf98 100644 --- a/libsrc/hyperion/DispmanxFrameGrabber.cpp +++ b/libsrc/hyperion/DispmanxFrameGrabber.cpp @@ -13,6 +13,8 @@ DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned // Open the connection to the displaydisplay _display = vc_dispmanx_display_open(0); int ret = vc_dispmanx_display_get_info(_display, &_info); + // Make the compiler (in release mode) happy by 'using' ret + (void)ret; assert(ret == 0); // Create the resources for capturing image diff --git a/libsrc/hyperion/DispmanxFrameGrabber.h b/libsrc/hyperion/DispmanxFrameGrabber.h index 088f6189..9ec7e859 100644 --- a/libsrc/hyperion/DispmanxFrameGrabber.h +++ b/libsrc/hyperion/DispmanxFrameGrabber.h @@ -1,6 +1,7 @@ #pragma once // BCM includes +#pragma GCC system_header #include // STL includes diff --git a/libsrc/hyperion/DispmanxWrapper.cpp b/libsrc/hyperion/DispmanxWrapper.cpp index ed73c728..185b96d5 100644 --- a/libsrc/hyperion/DispmanxWrapper.cpp +++ b/libsrc/hyperion/DispmanxWrapper.cpp @@ -5,6 +5,7 @@ // Hyperion includes #include #include +#include // Local-Hyperion includes @@ -12,19 +13,21 @@ DispmanxWrapper::DispmanxWrapper() : _timer(), - _processor(ImageProcessorFactory::getInstance().newImageProcessor()), - _frameGrabber(new DispmanxFrameGrabber(64, 64)) + _frameGrabber(new DispmanxFrameGrabber(64, 64)), + _processor(ImageProcessorFactory::getInstance().newImageProcessor()) { _timer.setInterval(100); _timer.setSingleShot(false); + _processor->setSize(64, 64); + QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(action())); } DispmanxWrapper::~DispmanxWrapper() { - delete _frameGrabber; delete _processor; + delete _frameGrabber; } void DispmanxWrapper::start() diff --git a/libsrc/hyperionpng/pngwriter.cc b/libsrc/hyperionpng/pngwriter.cc index ac1b88b4..72db5177 100644 --- a/libsrc/hyperionpng/pngwriter.cc +++ b/libsrc/hyperionpng/pngwriter.cc @@ -10,7 +10,7 @@ // then be opened with a graphics program. // // License: GNU General Public License -// Copyright 2002, 2003, 2004, 2005, 2006, 2007, +// Copyright 2002, 2003, 2004, 2005, 2006, 2007, // 2008, 2009 Paul Blackburn // // Website: Main: http://pngwriter.sourceforge.net/ @@ -75,39 +75,39 @@ pngwriter::pngwriter() graph_ = (png_bytepp)malloc(height_ * sizeof(png_bytep)); if(graph_ == NULL) - { + { std::cerr << " PNGwriter::pngwriter - ERROR **: Not able to allocate memory for image." << std::endl; - } + } for (kkkk = 0; kkkk < height_; kkkk++) - { - graph_[kkkk] = (png_bytep)malloc(6*width_ * sizeof(png_byte)); + { + graph_[kkkk] = (png_bytep)malloc(6*width_ * sizeof(png_byte)); if(graph_[kkkk] == NULL) { - std::cerr << " PNGwriter::pngwriter - ERROR **: Not able to allocate memory for image." << std::endl; + std::cerr << " PNGwriter::pngwriter - ERROR **: Not able to allocate memory for image." << std::endl; } - } + } if(graph_ == NULL) - { + { std::cerr << " PNGwriter::pngwriter - ERROR **: Not able to allocate memory for image." << std::endl; - } + } int tempindex; for(int hhh = 0; hhh65535) - { + { std::cerr << " PNGwriter::pngwriter - WARNING **: Constructor called with background colour greater than 65535. Setting to 65535."<65535) - { + { std::cerr << " PNGwriter::pngwriter - WARNING **: Constructor called with background colour greater than 1.0. Setting to 1.0."<65535) - { + { std::cerr << " PNGwriter::pngwriter - WARNING **: Constructor called with background colour greater than 65535. Setting to 65535."<65535) - { + { std::cerr << " PNGwriter::pngwriter - WARNING **: Constructor called with background colour greater than 65535. Setting to 65535."< 65535) - { + { red = 65535; - } + } if(green > 65535) - { + { green = 65535; - } + } if(blue > 65535) - { + { blue = 65535; - } + } if(red < 0) - { + { red = 0; - } + } if(green < 0) - { + { green = 0; - } + } if(blue < 0) - { + { blue = 0; - } + } if((bit_depth_ == 16)) - { + { // if( (height_-y >-1) && (height_-y -1) && (6*(x-1)+5<6*width_) ) if( (y<=height_) && (y>0) && (x>0) && (x<=width_) ) { - //graph_[height_-y][6*(x-1) + i] where i goes from 0 to 5 - tempindex= 6*x-6; - graph_[height_-y][tempindex] = (char) floor(((double)red)/256); - graph_[height_-y][tempindex+1] = (char)(red%256); - graph_[height_-y][tempindex+2] = (char) floor(((double)green)/256); - graph_[height_-y][tempindex+3] = (char)(green%256); - graph_[height_-y][tempindex+4] = (char) floor(((double)blue)/256); - graph_[height_-y][tempindex+5] = (char)(blue%256); + //graph_[height_-y][6*(x-1) + i] where i goes from 0 to 5 + tempindex= 6*x-6; + graph_[height_-y][tempindex] = (char) floor(((double)red)/256); + graph_[height_-y][tempindex+1] = (char)(red%256); + graph_[height_-y][tempindex+2] = (char) floor(((double)green)/256); + graph_[height_-y][tempindex+3] = (char)(green%256); + graph_[height_-y][tempindex+4] = (char) floor(((double)blue)/256); + graph_[height_-y][tempindex+5] = (char)(blue%256); }; /* @@ -659,18 +659,18 @@ void pngwriter::plot(int x, int y, int red, int green, int blue) std::cerr << " PNGwriter::plot-- Plotting out of range! " << y << " " << x << std::endl; } */ - } + } if((bit_depth_ == 8)) - { + { // if( (height_-y >-1) && (height_-y -1) && (3*(x-1)+5<3*width_) ) if( (y0) && (x>0) && (x0 ) && ( x <= (this->width_) ) && ( y>0 ) && ( y <= (this->height_) ) ) - { + { if(bit_depth_ == 16) { - temp2=6*(x-1); - if(colour == 1) - { + temp2=6*(x-1); + if(colour == 1) + { temp1 = (graph_[(height_-y)][temp2])*256 + graph_[height_-y][temp2+1]; return temp1; - } + } - if(colour == 2) - { + if(colour == 2) + { temp1 = (graph_[height_-y][temp2+2])*256 + graph_[height_-y][temp2+3]; return temp1; - } + } - if(colour == 3) - { + if(colour == 3) + { temp1 = (graph_[height_-y][temp2+4])*256 + graph_[height_-y][temp2+5]; return temp1; - } + } } if(bit_depth_ == 8) { - temp2=3*(x-1); - if(colour == 1) - { + temp2=3*(x-1); + if(colour == 1) + { temp1 = graph_[height_-y][temp2]; return temp1*256; - } + } - if(colour == 2) - { + if(colour == 2) + { temp1 = graph_[height_-y][temp2+1]; return temp1*256; - } + } - if(colour == 3) - { + if(colour == 3) + { temp1 = graph_[height_-y][temp2+2]; return temp1*256; - } + } } - } + } else - { + { return 0; - } + } std::cerr << " PNGwriter::read - WARNING **: Returning 0 because of bitdepth/colour type mismatch."<< std::endl; return 0; @@ -761,43 +761,43 @@ int pngwriter::read(int xxx, int yyy) int temp1,temp2,temp3,temp4,temp5; if( - ( xxx>0 ) && - ( xxx <= (this->width_) ) && - ( yyy>0 ) && - ( yyy <= (this->height_) ) - ) - { + ( xxx>0 ) && + ( xxx <= (this->width_) ) && + ( yyy>0 ) && + ( yyy <= (this->height_) ) + ) + { if(bit_depth_ == 16) { - // temp1 = (graph_[(height_-yyy)][6*(xxx-1)])*256 + graph_[height_-yyy][6*(xxx-1)+1]; - temp5=6*xxx; - temp1 = (graph_[(height_-yyy)][temp5-6])*256 + graph_[height_-yyy][temp5-5]; - temp2 = (graph_[height_-yyy][temp5-4])*256 + graph_[height_-yyy][temp5-3]; - temp3 = (graph_[height_-yyy][temp5-2])*256 + graph_[height_-yyy][temp5-1]; - temp4 = int((temp1+temp2+temp3)/3.0); + // temp1 = (graph_[(height_-yyy)][6*(xxx-1)])*256 + graph_[height_-yyy][6*(xxx-1)+1]; + temp5=6*xxx; + temp1 = (graph_[(height_-yyy)][temp5-6])*256 + graph_[height_-yyy][temp5-5]; + temp2 = (graph_[height_-yyy][temp5-4])*256 + graph_[height_-yyy][temp5-3]; + temp3 = (graph_[height_-yyy][temp5-2])*256 + graph_[height_-yyy][temp5-1]; + temp4 = int((temp1+temp2+temp3)/3.0); } else if(bit_depth_ == 8) { - // temp1 = graph_[height_-yyy][3*(xxx-1)]; - temp5 = 3*xxx; - temp1 = graph_[height_-yyy][temp5-3]; - temp2 = graph_[height_-yyy][temp5-2]; - temp3 = graph_[height_-yyy][temp5-1]; - temp4 = int((temp1+temp2+temp3)/3.0); + // temp1 = graph_[height_-yyy][3*(xxx-1)]; + temp5 = 3*xxx; + temp1 = graph_[height_-yyy][temp5-3]; + temp2 = graph_[height_-yyy][temp5-2]; + temp3 = graph_[height_-yyy][temp5-1]; + temp4 = int((temp1+temp2+temp3)/3.0); } else { - std::cerr << " PNGwriter::read - WARNING **: Invalid bit depth! Returning 0 as average value." << std::endl; - temp4 = 0; + std::cerr << " PNGwriter::read - WARNING **: Invalid bit depth! Returning 0 as average value." << std::endl; + temp4 = 0; } return temp4; - } + } else - { + { return 0; - } + } } ///////////////////////////////////////////////////// @@ -819,11 +819,11 @@ void pngwriter::clear() int tempindex; if(bit_depth_==16) - { + { for(pen = 0; pen 999999999)||(index < 0)) - { + { std::cerr << " PNGwriter::pngwriter_rename - ERROR **: Numerical name is out of 0 - 999 999 999 range (" << index <<")." << std::endl; return; - } + } if( 0> sprintf(buffer, "%9.9lu.png",index)) - { + { std::cerr << " PNGwriter::pngwriter_rename - ERROR **: Error creating numerical filename." << std::endl; return; - } + } delete [] filename_; delete [] texttitle_; @@ -954,32 +954,32 @@ void pngwriter::close() fp = fopen(filename_, "wb"); if( fp == NULL) - { + { std::cerr << " PNGwriter::close - ERROR **: Error creating file (fopen() returned NULL pointer)." << std::endl; perror(" PNGwriter::close - ERROR **"); return; - } + } png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); info_ptr = png_create_info_struct(png_ptr); png_init_io(png_ptr, fp); if(compressionlevel_ != -2) - { + { png_set_compression_level(png_ptr, compressionlevel_); - } + } else - { + { png_set_compression_level(png_ptr, PNGWRITER_DEFAULT_COMPRESSION); - } + } png_set_IHDR(png_ptr, info_ptr, width_, height_, bit_depth_, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); if(filegamma_ < 1.0e-1) - { + { filegamma_ = 0.5; // Modified in 0.5.4 so as to be the same as the usual gamma. - } + } png_set_gAMA(png_ptr, info_ptr, filegamma_); @@ -989,19 +989,19 @@ void pngwriter::close() time(&gmt); png_convert_from_time_t(&mod_time, gmt); png_set_tIME(png_ptr, info_ptr, &mod_time); - text_ptr[0].key = "Title"; + text_ptr[0].key = (char *)"Title"; text_ptr[0].text = texttitle_; text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE; - text_ptr[1].key = "Author"; + text_ptr[1].key = (char *)"Author"; text_ptr[1].text = textauthor_; text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE; - text_ptr[2].key = "Description"; + text_ptr[2].key = (char *)"Description"; text_ptr[2].text = textdescription_; text_ptr[2].compression = PNG_TEXT_COMPRESSION_NONE; - text_ptr[3].key = "Creation Time"; + text_ptr[3].key = (char *)"Creation Time"; text_ptr[3].text = png_convert_to_rfc1123(png_ptr, &mod_time); text_ptr[3].compression = PNG_TEXT_COMPRESSION_NONE; - text_ptr[4].key = "Software"; + text_ptr[4].key = (char *)"Software"; text_ptr[4].text = textsoftware_; text_ptr[4].compression = PNG_TEXT_COMPRESSION_NONE; png_set_text(png_ptr, info_ptr, text_ptr, 5); @@ -1023,71 +1023,71 @@ void pngwriter::line(int xfrom, int yfrom, int xto, int yto, int red, int green, int stepx, stepy; if (dy < 0) - { + { dy = -dy; stepy = -1; - } + } else - { + { stepy = 1; - } + } if (dx < 0) - { + { dx = -dx; stepx = -1; - } + } else - { + { stepx = 1; - } + } dy <<= 1; // dy is now 2*dy dx <<= 1; // dx is now 2*dx this->plot(xfrom,yfrom,red,green,blue); if (dx > dy) - { + { int fraction = dy - (dx >> 1); while (xfrom != xto) { - if (fraction >= 0) - { + if (fraction >= 0) + { yfrom += stepy; fraction -= dx; - } - xfrom += stepx; - fraction += dy; - this->plot(xfrom,yfrom,red,green,blue); + } + xfrom += stepx; + fraction += dy; + this->plot(xfrom,yfrom,red,green,blue); } - } + } else - { + { int fraction = dx - (dy >> 1); while (yfrom != yto) { - if (fraction >= 0) - { + if (fraction >= 0) + { xfrom += stepx; fraction -= dy; - } - yfrom += stepy; - fraction += dx; - this->plot(xfrom,yfrom,red,green,blue); + } + yfrom += stepy; + fraction += dx; + this->plot(xfrom,yfrom,red,green,blue); } - } + } } void pngwriter::line(int xfrom, int yfrom, int xto, int yto, double red, double green,double blue) { this->line( xfrom, - yfrom, - xto, - yto, - int (red*65535), - int (green*65535), - int (blue*65535) - ); + yfrom, + xto, + yto, + int (red*65535), + int (green*65535), + int (blue*65535) + ); } /////////////////////////////////////////////////////////////////////////////////////////// @@ -1108,9 +1108,9 @@ void pngwriter::square(int xfrom, int yfrom, int xto, int yto, double red, doubl void pngwriter::filledsquare(int xfrom, int yfrom, int xto, int yto, int red, int green, int blue) { for(int caca = xfrom; caca line(caca, yfrom, caca, yto, red, green, blue); - } + } } void pngwriter::filledsquare(int xfrom, int yfrom, int xto, int yto, double red, double green, double blue) @@ -1127,19 +1127,19 @@ void pngwriter::circle(int xcentre, int ycentre, int radius, int red, int green, circle_aux(xcentre, ycentre, x, y, red, green, blue); while (x < y) - { + { x++; if (p < 0) { - p += 2*x+1; + p += 2*x+1; } else { - y--; - p += 2*(x-y)+1; + y--; + p += 2*(x-y)+1; } circle_aux(xcentre, ycentre, x, y, red, green, blue); - } + } } void pngwriter::circle(int xcentre, int ycentre, int radius, double red, double green, double blue) @@ -1152,23 +1152,23 @@ void pngwriter::circle(int xcentre, int ycentre, int radius, double red, double void pngwriter::circle_aux(int xcentre, int ycentre, int x, int y, int red, int green, int blue) { if (x == 0) - { + { this->plot( xcentre, ycentre + y, red, green, blue); this->plot( xcentre, ycentre - y, red, green, blue); this->plot( xcentre + y, ycentre, red, green, blue); this->plot( xcentre - y, ycentre, red, green, blue); - } + } else - if (x == y) - { + if (x == y) + { this->plot( xcentre + x, ycentre + y, red, green, blue); this->plot( xcentre - x, ycentre + y, red, green, blue); this->plot( xcentre + x, ycentre - y, red, green, blue); this->plot( xcentre - x, ycentre - y, red, green, blue); - } + } else - if (x < y) - { + if (x < y) + { this->plot( xcentre + x, ycentre + y, red, green, blue); this->plot( xcentre - x, ycentre + y, red, green, blue); this->plot( xcentre + x, ycentre - y, red, green, blue); @@ -1177,7 +1177,7 @@ void pngwriter::circle_aux(int xcentre, int ycentre, int x, int y, int red, int this->plot( xcentre - y, ycentre + x, red, green, blue); this->plot( xcentre + y, ycentre - x, red, green, blue); this->plot( xcentre - y, ycentre - x, red, green, blue); - } + } } @@ -1185,10 +1185,10 @@ void pngwriter::circle_aux(int xcentre, int ycentre, int x, int y, int red, int void pngwriter::filledcircle(int xcentre, int ycentre, int radius, int red, int green, int blue) { for(int jjj = ycentre-radius; jjj< ycentre+radius+1; jjj++) - { + { this->line(xcentre - int(sqrt((double)(radius*radius) - (-ycentre + jjj)*(-ycentre + jjj ))), jjj, xcentre + int(sqrt((double)(radius*radius) - (-ycentre + jjj)*(-ycentre + jjj ))),jjj,red,green,blue); - } + } } void pngwriter::filledcircle(int xcentre, int ycentre, int radius, double red, double green, double blue) @@ -1212,160 +1212,160 @@ void pngwriter::readfromfile(char * name) // fp = fopen (name,"rb"); if (fp==NULL) - { + { std::cerr << " PNGwriter::readfromfile - ERROR **: Error opening file \"" << std::flush; std::cerr << name <jmpbuf)) /*(setjmp(png_jmpbuf(*png_ptr)) )*////////////////////////////////////// - { + { png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL); std::cerr << " PNGwriter::read_png_info - ERROR **: This file may be a corrupted PNG file. (setjmp(*png_ptr)->jmpbf) failed)." << std::endl; fclose(fp); return 0; //exit(EXIT_FAILURE); - } + } png_init_io(*png_ptr, fp); png_set_sig_bytes(*png_ptr, PNG_BYTES_TO_CHECK); png_read_info(*png_ptr, *info_ptr); @@ -1548,7 +1548,7 @@ int pngwriter::read_png_info(FILE *fp, png_structp *png_ptr, png_infop *info_ptr //////////////////////////////////////////////////////////// int pngwriter::read_png_image(FILE *fp, png_structp png_ptr, png_infop info_ptr, - png_bytepp *image, png_uint_32 *width, png_uint_32 *height) + png_bytepp *image, png_uint_32 *width, png_uint_32 *height) { unsigned int i,j; @@ -1556,39 +1556,39 @@ int pngwriter::read_png_image(FILE *fp, png_structp png_ptr, png_infop info_ptr, *height = png_get_image_height(png_ptr, info_ptr); if( width == NULL) - { + { std::cerr << " PNGwriter::read_png_image - ERROR **: png_get_image_width() returned NULL pointer." << std::endl; fclose(fp); return 0; - } + } if( height == NULL) - { + { std::cerr << " PNGwriter::read_png_image - ERROR **: png_get_image_height() returned NULL pointer." << std::endl; fclose(fp); return 0; - } + } if ((*image = (png_bytepp)malloc(*height * sizeof(png_bytep))) == NULL) - { + { std::cerr << " PNGwriter::read_png_image - ERROR **: Could not allocate memory for reading image." << std::endl; fclose(fp); return 0; //exit(EXIT_FAILURE); - } + } for (i = 0; i < *height; i++) - { + { (*image)[i] = (png_bytep)malloc(png_get_rowbytes(png_ptr, info_ptr)); if ((*image)[i] == NULL) { - for (j = 0; j < i; j++) free((*image)[j]); - free(*image); - fclose(fp); - std::cerr << " PNGwriter::read_png_image - ERROR **: Could not allocate memory for reading image." << std::endl; - return 0; - //exit(EXIT_FAILURE); + for (j = 0; j < i; j++) free((*image)[j]); + free(*image); + fclose(fp); + std::cerr << " PNGwriter::read_png_image - ERROR **: Could not allocate memory for reading image." << std::endl; + return 0; + //exit(EXIT_FAILURE); } - } + } png_read_image(png_ptr, *image); return 1; @@ -1641,11 +1641,11 @@ void pngwriter::HSVtoRGB( double *r, double *g, double *b, double h, double s, d int i; double f, p, q, t; if( s == 0 ) - { + { // achromatic (grey) *r = *g = *b = v; return; - } + } h /= 60; // sector 0 to 5 i = int(floor( h )); @@ -1655,38 +1655,38 @@ void pngwriter::HSVtoRGB( double *r, double *g, double *b, double h, double s, d t = v * ( 1 - s * ( 1 - f ) ); switch( i ) - { - case 0: + { + case 0: *r = v; *g = t; *b = p; break; - case 1: + case 1: *r = q; *g = v; *b = p; break; - case 2: + case 2: *r = p; *g = v; *b = t; break; - case 3: + case 3: *r = p; *g = q; *b = v; break; - case 4: + case 4: *r = t; *g = p; *b = v; break; - default: // case 5: + default: // case 5: *r = v; *g = p; *b = q; break; - } + } } void pngwriter::RGBtoHSV( float r, float g, float b, float *h, float *s, float *v ) @@ -1697,56 +1697,56 @@ void pngwriter::RGBtoHSV( float r, float g, float b, float *h, float *s, float * float delta; if( (r>=g)&&(r>=b) ) - { + { max = r; - } + } if( (g>=r)&&(g>=b) ) - { + { max = g; - } + } if( (b>=g)&&(b>=r) ) - { + { max = b; - } + } if( (r<=g)&&(r<=b) ) - { + { min = r; - } + } if( (g<=r)&&(g<=b) ) - { + { min = g; - } + } if( (b<=g)&&(b<=r) ) - { + { min = b; - } + } *v = max; // v delta = max - min; if( max != 0 ) - *s = delta / max; // s + *s = delta / max; // s else - { + { r = g = b = 0; // s = 0, v is undefined *s = 0; *h = -1; return; - } + } if( r == max ) - *h = ( g - b ) / delta; // between yellow & magenta + *h = ( g - b ) / delta; // between yellow & magenta else if( g == max ) - *h = 2 + ( b - r ) / delta; // between cyan & yellow + *h = 2 + ( b - r ) / delta; // between cyan & yellow else - *h = 4 + ( r - g ) / delta; // between magenta & cyan + *h = 4 + ( r - g ) / delta; // between magenta & cyan *h *= 60; // degrees if( *h < 0 ) - *h += 360; + *h += 360; } @@ -1777,7 +1777,7 @@ void pngwriter::plotHSV(int x, int y, int hue, int saturation, int value) double pngwriter::dreadHSV(int x, int y, int colour) { if( (x>0)&&(x<=width_)&&(y>0)&&(y<=height_) ) - { + { float * huep; float * saturationp; @@ -1797,21 +1797,21 @@ double pngwriter::dreadHSV(int x, int y, int colour) if(colour == 1) { - return double(hue)/360.0; + return double(hue)/360.0; } else if(colour == 2) { - return saturation; + return saturation; } else if(colour == 3) { - return value; + return value; } std::cerr << " PNGwriter::dreadHSV - ERROR **: Called with wrong colour argument: should be 1, 2 or 3; was: " << colour << "." << std::endl; - } + } return 0.0; } @@ -1820,7 +1820,7 @@ double pngwriter::dreadHSV(int x, int y, int colour) int pngwriter::readHSV(int x, int y, int colour) { if( (x>0)&&(x<=width_)&&(y>0)&&(y<=height_) ) - { + { float * huep; float * saturationp; @@ -1840,34 +1840,34 @@ int pngwriter::readHSV(int x, int y, int colour) if(colour == 1) { - return int(65535*(double(hue)/360.0)); + return int(65535*(double(hue)/360.0)); } else if(colour == 2) { - return int(65535*saturation); + return int(65535*saturation); } else if(colour == 3) { - return int(65535*value); + return int(65535*value); } std::cerr << " PNGwriter::readHSV - ERROR **: Called with wrong colour argument: should be 1, 2 or 3; was: " << colour << "." << std::endl; return 0; - } + } else - { + { return 0; - } + } } void pngwriter::setcompressionlevel(int level) { if( (level < -1)||(level > 9) ) - { + { std::cerr << " PNGwriter::setcompressionlevel - ERROR **: Called with wrong compression level: should be -1 to 9, was: " << level << "." << std::endl; - } + } compressionlevel_ = level; } @@ -1892,13 +1892,13 @@ void pngwriter::bezier( int startPtX, int startPtY, y = startPtY; for(double t = 0.0; t<=1.005; t += 0.005) - { + { newx = startPtX + t*(double(cx) + t*(double(bx) + t*(double(ax)))); newy = startPtY + t*(double(cy) + t*(double(by) + t*(double(ay)))); this->line(int(x),int(y),int(newx),int(newy),red,green,blue); x = newx; y = newy; - } + } } //int version of bezier @@ -1975,10 +1975,10 @@ void pngwriter::plot_text( char * face_path, int fontsize, int x_start, int y_st /* Set the Char size */ error = FT_Set_Char_Size( face, /* handle to face object */ - 0, /* char_width in 1/64th of points */ - fontsize*64, /* char_height in 1/64th of points */ - 100, /* horizontal device resolution */ - 100 ); /* vertical device resolution */ + 0, /* char_width in 1/64th of points */ + fontsize*64, /* char_height in 1/64th of points */ + 100, /* horizontal device resolution */ + 100 ); /* vertical device resolution */ /* A way of accesing the glyph directly */ FT_GlyphSlot slot = face->glyph; // a small shortcut @@ -1988,23 +1988,23 @@ void pngwriter::plot_text( char * face_path, int fontsize, int x_start, int y_st int n; for ( n = 0; n < num_chars; n++ ) - { + { /* Convert character code to glyph index */ glyph_index = FT_Get_Char_Index( face, text[n] ); /* Retrieve kerning distance and move pen position */ if ( use_kerning && previous&& glyph_index ) { - FT_Vector delta; - FT_Get_Kerning( face, - previous, - glyph_index, - ft_kerning_default, //FT_KERNING_DEFAULT, - &delta ); + FT_Vector delta; + FT_Get_Kerning( face, + previous, + glyph_index, + ft_kerning_default, //FT_KERNING_DEFAULT, + &delta ); - /* Transform this kerning distance into rotated space */ - pen.x += (int) (((double) delta.x)*cos(angle)); - pen.y += (int) (((double) delta.x)*( sin(angle))); + /* Transform this kerning distance into rotated space */ + pen.x += (int) (((double) delta.x)*cos(angle)); + pen.y += (int) (((double) delta.x)*( sin(angle))); } /* Set transform */ @@ -2040,7 +2040,7 @@ void pngwriter::plot_text( char * face_path, int fontsize, int x_start, int y_st /* record current glyph index */ previous = glyph_index; - } + } /* Free the face and the library objects */ FT_Done_Face ( face ); @@ -2073,9 +2073,9 @@ void pngwriter::plot_text_utf8( char * face_path, int fontsize, int x_start, int /*Count the length of the string */ int num_bytes=0; while(text[num_bytes]!=0) - { + { num_bytes++; - } + } /* std::cout << "Num bytes is: "<< num_bytes << std::endl; @@ -2092,63 +2092,63 @@ void pngwriter::plot_text_utf8( char * face_path, int fontsize, int x_start, int long iii=0; while(iiiglyph; // a small shortcut @@ -2178,23 +2178,23 @@ void pngwriter::plot_text_utf8( char * face_path, int fontsize, int x_start, int int n; for ( n = 0; n < num_chars; n++ ) - { + { /* Convert character code to glyph index */ glyph_index = FT_Get_Char_Index( face, ucs4text[n] ); /* Retrieve kerning distance and move pen position */ if ( use_kerning && previous&& glyph_index ) { - FT_Vector delta; - FT_Get_Kerning( face, - previous, - glyph_index, - ft_kerning_default, //FT_KERNING_DEFAULT, - &delta ); + FT_Vector delta; + FT_Get_Kerning( face, + previous, + glyph_index, + ft_kerning_default, //FT_KERNING_DEFAULT, + &delta ); - /* Transform this kerning distance into rotated space */ - pen.x += (int) (((double) delta.x)*cos(angle)); - pen.y += (int) (((double) delta.x)*( sin(angle))); + /* Transform this kerning distance into rotated space */ + pen.x += (int) (((double) delta.x)*cos(angle)); + pen.y += (int) (((double) delta.x)*( sin(angle))); } /* Set transform */ @@ -2229,7 +2229,7 @@ void pngwriter::plot_text_utf8( char * face_path, int fontsize, int x_start, int /* record current glyph index */ previous = glyph_index; - } + } /* Free the face and the library objects */ FT_Done_Face ( face ); @@ -2252,22 +2252,22 @@ void pngwriter::my_draw_bitmap( FT_Bitmap * bitmap, int x, int y, double red, do { double temp; for(int j=1; jrows+1; j++) - { + { for(int i=1; i< bitmap->width + 1; i++) { - temp = (double)(bitmap->buffer[(j-1)*bitmap->width + (i-1)] )/255.0; + temp = (double)(bitmap->buffer[(j-1)*bitmap->width + (i-1)] )/255.0; - if(temp) - { + if(temp) + { this->plot(x + i, - y - j, - temp*red + (1-temp)*(this->dread(x+i,y-j,1)), - temp*green + (1-temp)*(this->dread(x+i,y-j,2)), - temp*blue + (1-temp)*(this->dread(x+i,y-j,3)) - ); - } + y - j, + temp*red + (1-temp)*(this->dread(x+i,y-j,1)), + temp*green + (1-temp)*(this->dread(x+i,y-j,2)), + temp*blue + (1-temp)*(this->dread(x+i,y-j,3)) + ); + } } - } + } } @@ -2278,7 +2278,7 @@ void pngwriter::my_draw_bitmap( FT_Bitmap * bitmap, int x, int y, double red, do int pngwriter::get_text_width(char * face_path, int fontsize, char * text) { - + FT_Library library; FT_Face face; FT_Matrix matrix; // transformation matrix @@ -2313,10 +2313,10 @@ int pngwriter::get_text_width(char * face_path, int fontsize, char * text) /* Set the Char size */ error = FT_Set_Char_Size( face, /* handle to face object */ - 0, /* char_width in 1/64th of points */ - fontsize*64, /* char_height in 1/64th of points */ - 100, /* horizontal device resolution */ - 100 ); /* vertical device resolution */ + 0, /* char_width in 1/64th of points */ + fontsize*64, /* char_height in 1/64th of points */ + 100, /* horizontal device resolution */ + 100 ); /* vertical device resolution */ /* A way of accesing the glyph directly */ FT_GlyphSlot slot = face->glyph; // a small shortcut @@ -2326,23 +2326,23 @@ int pngwriter::get_text_width(char * face_path, int fontsize, char * text) int n; for ( n = 0; n < num_chars; n++ ) - { + { /* Convert character code to glyph index */ glyph_index = FT_Get_Char_Index( face, text[n] ); /* Retrieve kerning distance and move pen position */ if ( use_kerning && previous&& glyph_index ) { - FT_Vector delta; - FT_Get_Kerning( face, - previous, - glyph_index, - ft_kerning_default, //FT_KERNING_DEFAULT, - &delta ); + FT_Vector delta; + FT_Get_Kerning( face, + previous, + glyph_index, + ft_kerning_default, //FT_KERNING_DEFAULT, + &delta ); - /* Transform this kerning distance into rotated space */ - pen.x += (int) ( delta.x); - pen.y += 0; + /* Transform this kerning distance into rotated space */ + pen.x += (int) ( delta.x); + pen.y += 0; } /* Set transform */ @@ -2379,13 +2379,13 @@ int pngwriter::get_text_width(char * face_path, int fontsize, char * text) /* record current glyph index */ previous = glyph_index; - } + } + - /* Free the face and the library objects */ FT_Done_Face ( face ); FT_Done_FreeType( library ); - + return (int)( ((double)pen.x)/64.0 ); } @@ -2416,9 +2416,9 @@ int pngwriter::get_text_width_utf8(char * face_path, int fontsize, char * text) /*Count the length of the string */ int num_bytes=0; while(text[num_bytes]!=0) - { + { num_bytes++; - } + } /* std::cout << "Num bytes is: "<< num_bytes << std::endl; @@ -2435,63 +2435,63 @@ int pngwriter::get_text_width_utf8(char * face_path, int fontsize, char * text) long iii=0; while(iiiglyph; // a small shortcut @@ -2521,23 +2521,23 @@ int pngwriter::get_text_width_utf8(char * face_path, int fontsize, char * text) int n; for ( n = 0; n < num_chars; n++ ) - { + { /* Convert character code to glyph index */ glyph_index = FT_Get_Char_Index( face, ucs4text[n] ); /* Retrieve kerning distance and move pen position */ if ( use_kerning && previous&& glyph_index ) { - FT_Vector delta; - FT_Get_Kerning( face, - previous, - glyph_index, - ft_kerning_default, //FT_KERNING_DEFAULT, - &delta ); + FT_Vector delta; + FT_Get_Kerning( face, + previous, + glyph_index, + ft_kerning_default, //FT_KERNING_DEFAULT, + &delta ); - /* Transform this kerning distance into rotated space */ - pen.x += (int) (delta.x); - pen.y += 0; + /* Transform this kerning distance into rotated space */ + pen.x += (int) (delta.x); + pen.y += 0; } /* Set transform */ @@ -2572,14 +2572,14 @@ int pngwriter::get_text_width_utf8(char * face_path, int fontsize, char * text) /* record current glyph index */ previous = glyph_index; - } + } /* Free the face and the library objects */ FT_Done_Face ( face ); FT_Done_FreeType( library ); delete[] ucs4text; - + return (int) (((double) pen.x)/64.0); } @@ -2645,22 +2645,22 @@ int pngwriter::bilinear_interpolation_read(double x, double y, int colour) atright = intx==this->width_; /* if( intx==this->width_ +1) - { + { intx--; // std::cout << "intx--" << std::endl; - } + } */ /* if(inty == this->height_ +1) - { + { inty--; // std::cout << "inty--" << std::endl; - } + } */ if( (!attop)&&(!atright) ) - { + { double f,g,f1,g1; f = 1.0 + x - ((double) intx); @@ -2669,15 +2669,15 @@ int pngwriter::bilinear_interpolation_read(double x, double y, int colour) g1 = 1.0 - g; return (int) ( - f1*g1*this->read(intx, inty,colour) - + f*g1*this->read(intx+1,inty,colour) - +f1*g*this->read(intx,inty+1,colour) - + f*g*(this->read(intx+1,inty+1,colour)) - ); - } + f1*g1*this->read(intx, inty,colour) + + f*g1*this->read(intx+1,inty,colour) + +f1*g*this->read(intx,inty+1,colour) + + f*g*(this->read(intx+1,inty+1,colour)) + ); + } if( (atright)&&(!attop)) - { + { double f,g,f1,g1; f = 1.0 + x - ((double) intx); @@ -2686,15 +2686,15 @@ int pngwriter::bilinear_interpolation_read(double x, double y, int colour) g1 = 1.0 - g; return (int) ( - f1*g1*this->read(intx, inty,colour) - + f*g1*( 2*(this->read(intx,inty,colour)) - (this->read(intx-1,inty,colour)) ) - +f1*g*this->read(intx,inty+1,colour) - + f*g*(2*(this->read(intx,inty+1,colour)) - (this->read(intx-1,inty+1,colour))) - ); - } + f1*g1*this->read(intx, inty,colour) + + f*g1*( 2*(this->read(intx,inty,colour)) - (this->read(intx-1,inty,colour)) ) + +f1*g*this->read(intx,inty+1,colour) + + f*g*(2*(this->read(intx,inty+1,colour)) - (this->read(intx-1,inty+1,colour))) + ); + } if((attop)&&(!atright)) - { + { double f,g,f1,g1; f = 1.0 + x - ((double) intx); g = 1.0 + y - ((double) inty); @@ -2702,12 +2702,12 @@ int pngwriter::bilinear_interpolation_read(double x, double y, int colour) g1 = 1.0 - g; return (int) ( - f1*g1*this->read(intx, inty,colour) - + f*g1*this->read(intx+1,inty,colour) - +f1*g*( 2*(this->read(intx,inty,colour)) - this->read(intx,inty-1,colour) ) - + f*g*( 2*(this->read(intx+1,inty,colour)) - this->read(intx+1,inty-1,colour)) - ); - } + f1*g1*this->read(intx, inty,colour) + + f*g1*this->read(intx+1,inty,colour) + +f1*g*( 2*(this->read(intx,inty,colour)) - this->read(intx,inty-1,colour) ) + + f*g*( 2*(this->read(intx+1,inty,colour)) - this->read(intx+1,inty-1,colour)) + ); + } double f,g,f1,g1; f = 1.0 + x - ((double) intx); @@ -2723,13 +2723,13 @@ int pngwriter::bilinear_interpolation_read(double x, double y, int colour) ); /* - return (int) ( - f1*g1*this->read(intx, inty,colour) - + f*g1*this->read(intx+1,inty,colour) - +f1*g*this->read(intx,inty+1,colour) - + f*g*this->read(intx+1, inty+1,colour) - ); - * */ + return (int) ( + f1*g1*this->read(intx, inty,colour) + + f*g1*this->read(intx+1,inty,colour) + +f1*g*this->read(intx,inty+1,colour) + + f*g*this->read(intx+1, inty+1,colour) + ); + * */ }; @@ -2741,10 +2741,10 @@ double pngwriter::bilinear_interpolation_dread(double x, double y, int colour) void pngwriter::plot_blend(int x, int y, double opacity, int red, int green, int blue) { this->plot(x, y, - (int)( opacity*red + this->read(x,y,1)*(1.0-opacity)), - (int)( opacity*green + this->read(x,y,2)*(1.0-opacity)), - (int)( opacity*blue + this->read(x,y,3)*(1.0-opacity)) - ); + (int)( opacity*red + this->read(x,y,1)*(1.0-opacity)), + (int)( opacity*green + this->read(x,y,2)*(1.0-opacity)), + (int)( opacity*blue + this->read(x,y,3)*(1.0-opacity)) + ); }; void pngwriter::plot_blend(int x, int y, double opacity, double red, double green, double blue) @@ -2758,32 +2758,32 @@ void pngwriter::invert(void) double temp11, temp22, temp33; for(int jjj = 1; jjj <= (this->height_); jjj++) - { + { for(int iii = 1; iii <= (this->width_); iii++) { - /* temp11 = (this->read(iii,jjj,1)); - temp22 = (this->read(iii,jjj,2)); - temp33 = (this->read(iii,jjj,3)); - * - this->plot(iii,jjj, - ((double)(65535 - temp11))/65535.0, - ((double)(65535 - temp22))/65535.0, - ((double)(65535 - temp33))/65535.0 - ); - * - */ - temp11 = (this->read(iii,jjj,1)); - temp22 = (this->read(iii,jjj,2)); - temp33 = (this->read(iii,jjj,3)); + /* temp11 = (this->read(iii,jjj,1)); + temp22 = (this->read(iii,jjj,2)); + temp33 = (this->read(iii,jjj,3)); + * + this->plot(iii,jjj, + ((double)(65535 - temp11))/65535.0, + ((double)(65535 - temp22))/65535.0, + ((double)(65535 - temp33))/65535.0 + ); + * + */ + temp11 = (this->read(iii,jjj,1)); + temp22 = (this->read(iii,jjj,2)); + temp33 = (this->read(iii,jjj,3)); - this->plot(iii,jjj, + this->plot(iii,jjj, (int)(65535 - temp11), (int)(65535 - temp22), (int)(65535 - temp33) ); } - } + } } void pngwriter::resize(int width, int height) @@ -2798,39 +2798,39 @@ void pngwriter::resize(int width, int height) graph_ = (png_bytepp)malloc(height_ * sizeof(png_bytep)); if(graph_ == NULL) - { + { std::cerr << " PNGwriter::resize - ERROR **: Not able to allocate memory for image." << std::endl; - } + } for (int kkkk = 0; kkkk < height_; kkkk++) - { + { graph_[kkkk] = (png_bytep)malloc(6*width_ * sizeof(png_byte)); if(graph_[kkkk] == NULL) { - std::cerr << " PNGwriter::resize - ERROR **: Not able to allocate memory for image." << std::endl; + std::cerr << " PNGwriter::resize - ERROR **: Not able to allocate memory for image." << std::endl; } - } + } if(graph_ == NULL) - { + { std::cerr << " PNGwriter::resize - ERROR **: Not able to allocate memory for image." << std::endl; - } + } int tempindex; for(int hhh = 0; hhhdread(xstart,ystart,2) != boundary_green) || (this->dread(xstart,ystart,3) != boundary_blue) ) - && - ( + && + ( (this->dread(xstart,ystart,1) != fill_red) || (this->dread(xstart,ystart,2) != fill_green) || (this->dread(xstart,ystart,3) != fill_blue) ) - && - (xstart >0)&&(xstart <= width_)&&(ystart >0)&&(ystart <= height_) - ) - { + && + (xstart >0)&&(xstart <= width_)&&(ystart >0)&&(ystart <= height_) + ) + { this->plot(xstart, ystart, fill_red, fill_green, fill_blue); boundary_fill(xstart+1, ystart, boundary_red, boundary_green, boundary_blue, fill_red, fill_green, fill_blue) ; boundary_fill(xstart, ystart+1, boundary_red, boundary_green, boundary_blue, fill_red, fill_green, fill_blue) ; boundary_fill(xstart, ystart-1, boundary_red, boundary_green, boundary_blue, fill_red, fill_green, fill_blue) ; boundary_fill(xstart-1, ystart, boundary_red, boundary_green, boundary_blue, fill_red, fill_green, fill_blue) ; - } + } } //no int version needed @@ -2866,22 +2866,22 @@ void pngwriter::flood_fill_internal(int xstart, int ystart, double start_red, d (this->dread(xstart,ystart,2) == start_green) && (this->dread(xstart,ystart,3) == start_blue) ) - && - ( + && + ( (this->dread(xstart,ystart,1) != fill_red) || (this->dread(xstart,ystart,2) != fill_green) || (this->dread(xstart,ystart,3) != fill_blue) ) - && - (xstart >0)&&(xstart <= width_)&&(ystart >0)&&(ystart <= height_) - ) - { + && + (xstart >0)&&(xstart <= width_)&&(ystart >0)&&(ystart <= height_) + ) + { this->plot(xstart, ystart, fill_red, fill_green, fill_blue); flood_fill_internal( xstart+1, ystart, start_red, start_green, start_blue, fill_red, fill_green, fill_blue); flood_fill_internal( xstart-1, ystart, start_red, start_green, start_blue, fill_red, fill_green, fill_blue); flood_fill_internal( xstart, ystart+1, start_red, start_green, start_blue, fill_red, fill_green, fill_blue); flood_fill_internal( xstart, ystart-1, start_red, start_green, start_blue, fill_red, fill_green, fill_blue); - } + } } @@ -2908,24 +2908,24 @@ void pngwriter::flood_fill(int xstart, int ystart, double fill_red, double fill_ void pngwriter::flood_fill(int xstart, int ystart, int fill_red, int fill_green, int fill_blue) { this->flood_fill( xstart, ystart, - ((double) fill_red)/65535.0, - ((double) fill_green)/65535.0, - ((double) fill_blue)/65535.0 - ); + ((double) fill_red)/65535.0, + ((double) fill_green)/65535.0, + ((double) fill_blue)/65535.0 + ); } void pngwriter::polygon( int * points, int number_of_points, double red, double green, double blue) { if( (number_of_points<1)||(points ==NULL)) - { + { std::cerr << " PNGwriter::polygon - ERROR **: Number of points is zero or negative, or array is NULL." << std::endl; return; - } + } for(int k=0;k< number_of_points-1; k++) - { + { this->line(points[2*k],points[2*k+1],points[2*k+2],points[2*k+3], red, green, blue); - } + } } //int version @@ -2948,38 +2948,38 @@ void pngwriter::plotCMYK(int x, int y, double cyan, double magenta, double yello * */ if(cyan<0.0) - { + { cyan = 0.0; - } + } if(magenta<0.0) - { + { magenta = 0.0; - } + } if(yellow<0.0) - { + { yellow = 0.0; - } + } if(black<0.0) - { + { black = 0.0; - } + } if(cyan>1.0) - { + { cyan = 1.0; - } + } if(magenta>1.0) - { + { magenta = 1.0; - } + } if(yellow>1.0) - { + { yellow = 1.0; - } + } if(black>1.0) - { + { black = 1.0; - } + } double red, green, blue, minr, ming, minb, iblack; @@ -2990,19 +2990,19 @@ void pngwriter::plotCMYK(int x, int y, double cyan, double magenta, double yello minb = 1.0; if( (cyan*iblack + black)<1.0 ) - { + { minr = cyan*iblack + black; - } + } if( (magenta*iblack + black)<1.0 ) - { + { ming = magenta*iblack + black; - } + } if( (yellow*iblack + black)<1.0 ) - { + { minb = yellow*iblack + black; - } + } red = 1.0 - minr; green = 1.0 - ming; @@ -3033,10 +3033,10 @@ double pngwriter::dreadCMYK(int x, int y, int colour) * * */ if((colour !=1)&&(colour !=2)&&(colour !=3)&&(colour !=4)) - { + { std::cerr << " PNGwriter::dreadCMYK - WARNING **: Invalid argument: should be 1, 2, 3 or 4, is " << colour << std::endl; return 0; - } + } double black, red, green, blue, ired, igreen, iblue, iblack; //add error detection here @@ -3053,36 +3053,36 @@ double pngwriter::dreadCMYK(int x, int y, int colour) //black is the mimimum of inverse RGB colours, and if they are all equal, it is the inverse of red. if( (igreenbilinear_interpolation_read(readx, ready, 1); - green = this->bilinear_interpolation_read(readx, ready, 2); - blue = this->bilinear_interpolation_read(readx, ready, 3); - temp.plot(x, y, red, green, blue); + readx = (2*x-1)*spacingx; + ready = (2*y-1)*spacingy; + red = this->bilinear_interpolation_read(readx, ready, 1); + green = this->bilinear_interpolation_read(readx, ready, 2); + blue = this->bilinear_interpolation_read(readx, ready, 3); + temp.plot(x, y, red, green, blue); } - } + } // From here on, the process is the same for all scale functions. //Get data out of temp and into this's storage. @@ -3206,41 +3206,41 @@ void pngwriter::scale_k(double k) graph_ = (png_bytepp)malloc(height_ * sizeof(png_bytep)); if(graph_ == NULL) - { + { std::cerr << " PNGwriter::scale_k - ERROR **: Not able to allocate memory for image." << std::endl; - } + } for (int kkkk = 0; kkkk < height_; kkkk++) - { + { graph_[kkkk] = (png_bytep)malloc(6*width_ * sizeof(png_byte)); if(graph_[kkkk] == NULL) { - std::cerr << " PNGwriter::scale_k - ERROR **: Not able to allocate memory for image." << std::endl; + std::cerr << " PNGwriter::scale_k - ERROR **: Not able to allocate memory for image." << std::endl; } - } + } if(graph_ == NULL) - { + { std::cerr << " PNGwriter::scale_k - ERROR **: Not able to allocate memory for image." << std::endl; - } + } //This instance now has a new, resized storage space. //Copy the temp date into this's storage. int tempindex; for(int hhh = 0; hhhbilinear_interpolation_read(readx, ready, 1); - green = this->bilinear_interpolation_read(readx, ready, 2); - blue = this->bilinear_interpolation_read(readx, ready, 3); - temp.plot(x, y, red, green, blue); + readx = (2*x-1)*spacingx; + ready = (2*y-1)*spacingy; + red = this->bilinear_interpolation_read(readx, ready, 1); + green = this->bilinear_interpolation_read(readx, ready, 2); + blue = this->bilinear_interpolation_read(readx, ready, 3); + temp.plot(x, y, red, green, blue); } - } + } // From here on, the process is the same for all scale functions. //Get data out of temp and into this's storage. @@ -3297,41 +3297,41 @@ void pngwriter::scale_kxky(double kx, double ky) graph_ = (png_bytepp)malloc(height_ * sizeof(png_bytep)); if(graph_ == NULL) - { + { std::cerr << " PNGwriter::scale_kxky - ERROR **: Not able to allocate memory for image." << std::endl; - } + } for (int kkkk = 0; kkkk < height_; kkkk++) - { + { graph_[kkkk] = (png_bytep)malloc(6*width_ * sizeof(png_byte)); if(graph_[kkkk] == NULL) { - std::cerr << " PNGwriter::scale_kxky - ERROR **: Not able to allocate memory for image." << std::endl; + std::cerr << " PNGwriter::scale_kxky - ERROR **: Not able to allocate memory for image." << std::endl; } - } + } if(graph_ == NULL) - { + { std::cerr << " PNGwriter::scale_kxky - ERROR **: Not able to allocate memory for image." << std::endl; - } + } //This instance now has a new, resized storage space. //Copy the temp date into this's storage. int tempindex; for(int hhh = 0; hhhbilinear_interpolation_read(readx, ready, 1); - green = this->bilinear_interpolation_read(readx, ready, 2); - blue = this->bilinear_interpolation_read(readx, ready, 3); - temp.plot(x, y, red, green, blue); + readx = (2*x-1)*spacingx; + ready = (2*y-1)*spacingy; + red = this->bilinear_interpolation_read(readx, ready, 1); + green = this->bilinear_interpolation_read(readx, ready, 2); + blue = this->bilinear_interpolation_read(readx, ready, 3); + temp.plot(x, y, red, green, blue); } - } + } // From here on, the process is the same for all scale functions. //Get data out of temp and into this's storage. @@ -3392,41 +3392,41 @@ void pngwriter::scale_wh(int finalwidth, int finalheight) graph_ = (png_bytepp)malloc(height_ * sizeof(png_bytep)); if(graph_ == NULL) - { + { std::cerr << " PNGwriter::scale_wh - ERROR **: Not able to allocate memory for image." << std::endl; - } + } for (int kkkk = 0; kkkk < height_; kkkk++) - { + { graph_[kkkk] = (png_bytep)malloc(6*width_ * sizeof(png_byte)); if(graph_[kkkk] == NULL) { - std::cerr << " PNGwriter::scale_wh - ERROR **: Not able to allocate memory for image." << std::endl; + std::cerr << " PNGwriter::scale_wh - ERROR **: Not able to allocate memory for image." << std::endl; } - } + } if(graph_ == NULL) - { + { std::cerr << " PNGwriter::scale_wh - ERROR **: Not able to allocate memory for image." << std::endl; - } + } //This instance now has a new, resized storage space. //Copy the temp date into this's storage. int tempindex; for(int hhh = 0; hhhplot_blend(xfrom,yfrom,opacity, red,green,blue); if (dx > dy) - { + { int fraction = dy - (dx >> 1); while (xfrom != xto) { - if (fraction >= 0) - { + if (fraction >= 0) + { yfrom += stepy; fraction -= dx; - } - xfrom += stepx; - fraction += dy; - this->plot_blend(xfrom,yfrom,opacity, red,green,blue); + } + xfrom += stepx; + fraction += dy; + this->plot_blend(xfrom,yfrom,opacity, red,green,blue); } - } + } else - { + { int fraction = dx - (dy >> 1); while (yfrom != yto) { - if (fraction >= 0) - { + if (fraction >= 0) + { xfrom += stepx; fraction -= dy; - } - yfrom += stepy; - fraction += dx; - this->plot_blend(xfrom,yfrom, opacity, red,green,blue); + } + yfrom += stepy; + fraction += dx; + this->plot_blend(xfrom,yfrom, opacity, red,green,blue); } - } + } } void pngwriter::line_blend(int xfrom, int yfrom, int xto, int yto, double opacity, double red, double green,double blue) { this->line_blend( xfrom, - yfrom, - xto, - yto, - opacity, - int (red*65535), - int (green*65535), - int (blue*65535) - ); + yfrom, + xto, + yto, + opacity, + int (red*65535), + int (green*65535), + int (blue*65535) + ); } @@ -3550,9 +3550,9 @@ void pngwriter::square_blend(int xfrom, int yfrom, int xto, int yto, double opac void pngwriter::filledsquare_blend(int xfrom, int yfrom, int xto, int yto, double opacity, int red, int green,int blue) { for(int caca = xfrom; caca line_blend(caca, yfrom, caca, yto, opacity, red, green, blue); - } + } } @@ -3564,23 +3564,23 @@ void pngwriter::filledsquare_blend(int xfrom, int yfrom, int xto, int yto, doubl void pngwriter::circle_aux_blend(int xcentre, int ycentre, int x, int y, double opacity, int red, int green, int blue) { if (x == 0) - { + { this->plot_blend( xcentre, ycentre + y, opacity, red, green, blue); this->plot_blend( xcentre, ycentre - y, opacity, red, green, blue); this->plot_blend( xcentre + y, ycentre, opacity, red, green, blue); this->plot_blend( xcentre - y, ycentre, opacity, red, green, blue); - } + } else - if (x == y) - { + if (x == y) + { this->plot_blend( xcentre + x, ycentre + y, opacity, red, green, blue); this->plot_blend( xcentre - x, ycentre + y, opacity, red, green, blue); this->plot_blend( xcentre + x, ycentre - y, opacity, red, green, blue); this->plot_blend( xcentre - x, ycentre - y, opacity, red, green, blue); - } + } else - if (x < y) - { + if (x < y) + { this->plot_blend( xcentre + x, ycentre + y, opacity, red, green, blue); this->plot_blend( xcentre - x, ycentre + y, opacity, red, green, blue); this->plot_blend( xcentre + x, ycentre - y, opacity, red, green, blue); @@ -3589,7 +3589,7 @@ void pngwriter::circle_aux_blend(int xcentre, int ycentre, int x, int y, double this->plot_blend( xcentre - y, ycentre + x, opacity, red, green, blue); this->plot_blend( xcentre + y, ycentre - x, opacity, red, green, blue); this->plot_blend( xcentre - y, ycentre - x, opacity, red, green, blue); - } + } } // @@ -3602,19 +3602,19 @@ void pngwriter::circle_blend(int xcentre, int ycentre, int radius, double opacit circle_aux_blend(xcentre, ycentre, x, y, opacity, red, green, blue); while (x < y) - { + { x++; if (p < 0) { - p += 2*x+1; + p += 2*x+1; } else { - y--; - p += 2*(x-y)+1; + y--; + p += 2*(x-y)+1; } circle_aux_blend(xcentre, ycentre, x, y, opacity, red, green, blue); - } + } } @@ -3626,10 +3626,10 @@ void pngwriter::circle_blend(int xcentre, int ycentre, int radius, double opacit void pngwriter::filledcircle_blend(int xcentre, int ycentre, int radius, double opacity, int red, int green, int blue) { for(int jjj = ycentre-radius; jjj< ycentre+radius+1; jjj++) - { + { this->line_blend(xcentre - int(sqrt((double)(radius*radius) - (-ycentre + jjj)*(-ycentre + jjj ))), jjj, xcentre + int(sqrt((double)(radius*radius) - (-ycentre + jjj)*(-ycentre + jjj ))),jjj, opacity, red,green,blue); - } + } } @@ -3639,11 +3639,11 @@ void pngwriter::filledcircle_blend(int xcentre, int ycentre, int radius, double } void pngwriter::bezier_blend( int startPtX, int startPtY, - int startControlX, int startControlY, - int endPtX, int endPtY, - int endControlX, int endControlY, - double opacity, - double red, double green, double blue) + int startControlX, int startControlY, + int endPtX, int endPtY, + int endControlX, int endControlY, + double opacity, + double red, double green, double blue) { double cx = 3.0*(startControlX - startPtX); @@ -3659,21 +3659,21 @@ void pngwriter::bezier_blend( int startPtX, int startPtY, y = startPtY; for(double t = 0.0; t<=1.005; t += 0.005) - { + { newx = startPtX + t*(double(cx) + t*(double(bx) + t*(double(ax)))); newy = startPtY + t*(double(cy) + t*(double(by) + t*(double(ay)))); this->line_blend(int(x),int(y),int(newx),int(newy),opacity, red,green,blue); x = newx; y = newy; - } + } } void pngwriter::bezier_blend( int startPtX, int startPtY, - int startControlX, int startControlY, - int endPtX, int endPtY, - int endControlX, int endControlY, - double opacity, - int red, int green, int blue) + int startControlX, int startControlY, + int endPtX, int endPtY, + int endControlX, int endControlY, + double opacity, + int red, int green, int blue) { this->bezier_blend( startPtX, startPtY, startControlX, startControlY, @@ -3725,10 +3725,10 @@ void pngwriter::plot_text_blend( char * face_path, int fontsize, int x_start, in /* Set the Char size */ error = FT_Set_Char_Size( face, /* handle to face object */ - 0, /* char_width in 1/64th of points */ - fontsize*64, /* char_height in 1/64th of points */ - 100, /* horizontal device resolution */ - 100 ); /* vertical device resolution */ + 0, /* char_width in 1/64th of points */ + fontsize*64, /* char_height in 1/64th of points */ + 100, /* horizontal device resolution */ + 100 ); /* vertical device resolution */ /* A way of accesing the glyph directly */ FT_GlyphSlot slot = face->glyph; // a small shortcut @@ -3738,23 +3738,23 @@ void pngwriter::plot_text_blend( char * face_path, int fontsize, int x_start, in int n; for ( n = 0; n < num_chars; n++ ) - { + { /* Convert character code to glyph index */ glyph_index = FT_Get_Char_Index( face, text[n] ); /* Retrieve kerning distance and move pen position */ if ( use_kerning && previous&& glyph_index ) { - FT_Vector delta; - FT_Get_Kerning( face, - previous, - glyph_index, - ft_kerning_default, //FT_KERNING_DEFAULT, - &delta ); + FT_Vector delta; + FT_Get_Kerning( face, + previous, + glyph_index, + ft_kerning_default, //FT_KERNING_DEFAULT, + &delta ); - /* Transform this kerning distance into rotated space */ - pen.x += (int) (((double) delta.x)*cos(angle)); - pen.y += (int) (((double) delta.x)*( sin(angle))); + /* Transform this kerning distance into rotated space */ + pen.x += (int) (((double) delta.x)*cos(angle)); + pen.y += (int) (((double) delta.x)*( sin(angle))); } /* Set transform */ @@ -3778,12 +3778,12 @@ void pngwriter::plot_text_blend( char * face_path, int fontsize, int x_start, in /* Now, draw to our target surface */ my_draw_bitmap_blend( &slot->bitmap, - slot->bitmap_left, - y_start + slot->bitmap_top, - opacity, - red, - green, - blue ); + slot->bitmap_left, + y_start + slot->bitmap_top, + opacity, + red, + green, + blue ); /* Advance to the next position */ pen.x += slot->advance.x; @@ -3791,7 +3791,7 @@ void pngwriter::plot_text_blend( char * face_path, int fontsize, int x_start, in /* record current glyph index */ previous = glyph_index; - } + } /* Free the face and the library objects */ FT_Done_Face ( face ); @@ -3824,9 +3824,9 @@ void pngwriter::plot_text_utf8_blend( char * face_path, int fontsize, int x_star /*Count the length of the string */ int num_bytes=0; while(text[num_bytes]!=0) - { + { num_bytes++; - } + } /* std::cout << "Num bytes is: "<< num_bytes << std::endl; @@ -3843,63 +3843,63 @@ void pngwriter::plot_text_utf8_blend( char * face_path, int fontsize, int x_star long iii=0; while(iiiglyph; // a small shortcut @@ -3929,23 +3929,23 @@ void pngwriter::plot_text_utf8_blend( char * face_path, int fontsize, int x_star int n; for ( n = 0; n < num_chars; n++ ) - { + { /* Convert character code to glyph index */ glyph_index = FT_Get_Char_Index( face, ucs4text[n] ); /* Retrieve kerning distance and move pen position */ if ( use_kerning && previous&& glyph_index ) { - FT_Vector delta; - FT_Get_Kerning( face, - previous, - glyph_index, - ft_kerning_default, //FT_KERNING_DEFAULT, - &delta ); + FT_Vector delta; + FT_Get_Kerning( face, + previous, + glyph_index, + ft_kerning_default, //FT_KERNING_DEFAULT, + &delta ); - /* Transform this kerning distance into rotated space */ - pen.x += (int) (((double) delta.x)*cos(angle)); - pen.y += (int) (((double) delta.x)*( sin(angle))); + /* Transform this kerning distance into rotated space */ + pen.x += (int) (((double) delta.x)*cos(angle)); + pen.y += (int) (((double) delta.x)*( sin(angle))); } /* Set transform */ @@ -3968,12 +3968,12 @@ void pngwriter::plot_text_utf8_blend( char * face_path, int fontsize, int x_star /* Now, draw to our target surface */ my_draw_bitmap_blend( &slot->bitmap, - slot->bitmap_left, - y_start + slot->bitmap_top, - opacity, - red, - green, - blue ); + slot->bitmap_left, + y_start + slot->bitmap_top, + opacity, + red, + green, + blue ); /* Advance to the next position */ pen.x += slot->advance.x; @@ -3981,7 +3981,7 @@ void pngwriter::plot_text_utf8_blend( char * face_path, int fontsize, int x_star /* record current glyph index */ previous = glyph_index; - } + } /* Free the face and the library objects */ FT_Done_Face ( face ); @@ -4004,13 +4004,13 @@ void pngwriter::my_draw_bitmap_blend( FT_Bitmap * bitmap, int x, int y, double o { double temp; for(int j=1; jrows+1; j++) - { + { for(int i=1; i< bitmap->width + 1; i++) { - temp = (double)(bitmap->buffer[(j-1)*bitmap->width + (i-1)] )/255.0; + temp = (double)(bitmap->buffer[(j-1)*bitmap->width + (i-1)] )/255.0; - if(temp) - { + if(temp) + { this->plot_blend(x + i, y - j, opacity, @@ -4018,9 +4018,9 @@ void pngwriter::my_draw_bitmap_blend( FT_Bitmap * bitmap, int x, int y, double o temp*green + (1-temp)*(this->dread(x+i,y-j,2)), temp*blue + (1-temp)*(this->dread(x+i,y-j,3)) ); - } + } } - } + } } #endif @@ -4062,22 +4062,22 @@ void pngwriter::boundary_fill_blend(int xstart, int ystart, double opacity, doub (this->dread(xstart,ystart,2) != boundary_green) || (this->dread(xstart,ystart,3) != boundary_blue) ) - && - ( + && + ( (this->dread(xstart,ystart,1) != fill_red) || (this->dread(xstart,ystart,2) != fill_green) || (this->dread(xstart,ystart,3) != fill_blue) ) - && - (xstart >0)&&(xstart <= width_)&&(ystart >0)&&(ystart <= height_) - ) - { + && + (xstart >0)&&(xstart <= width_)&&(ystart >0)&&(ystart <= height_) + ) + { this->plot_blend(xstart, ystart, opacity, fill_red, fill_green, fill_blue); boundary_fill_blend(xstart+1, ystart, opacity, boundary_red, boundary_green, boundary_blue, fill_red, fill_green, fill_blue) ; boundary_fill_blend(xstart, ystart+1, opacity, boundary_red, boundary_green, boundary_blue, fill_red, fill_green, fill_blue) ; boundary_fill_blend(xstart, ystart-1, opacity, boundary_red, boundary_green, boundary_blue, fill_red, fill_green, fill_blue) ; boundary_fill_blend(xstart-1, ystart, opacity, boundary_red, boundary_green, boundary_blue, fill_red, fill_green, fill_blue) ; - } + } } //no int version needed @@ -4088,22 +4088,22 @@ void pngwriter::flood_fill_internal_blend(int xstart, int ystart, double opacity (this->dread(xstart,ystart,2) == start_green) && (this->dread(xstart,ystart,3) == start_blue) ) - && - ( + && + ( (this->dread(xstart,ystart,1) != fill_red) || (this->dread(xstart,ystart,2) != fill_green) || (this->dread(xstart,ystart,3) != fill_blue) ) - && - (xstart >0)&&(xstart <= width_)&&(ystart >0)&&(ystart <= height_) - ) - { + && + (xstart >0)&&(xstart <= width_)&&(ystart >0)&&(ystart <= height_) + ) + { this->plot_blend(xstart, ystart, opacity, fill_red, fill_green, fill_blue); flood_fill_internal_blend( xstart+1, ystart, opacity, start_red, start_green, start_blue, fill_red, fill_green, fill_blue); flood_fill_internal_blend( xstart-1, ystart,opacity, start_red, start_green, start_blue, fill_red, fill_green, fill_blue); flood_fill_internal_blend( xstart, ystart+1, opacity, start_red, start_green, start_blue, fill_red, fill_green, fill_blue); flood_fill_internal_blend( xstart, ystart-1, opacity, start_red, start_green, start_blue, fill_red, fill_green, fill_blue); - } + } } @@ -4112,14 +4112,14 @@ void pngwriter::boundary_fill_blend(int xstart, int ystart, double opacity, int { this->boundary_fill_blend( xstart, ystart, - opacity, - ((double) boundary_red)/65535.0, - ((double) boundary_green)/65535.0, - ((double) boundary_blue)/65535.0, - ((double) fill_red)/65535.0, - ((double) fill_green)/65535.0, - ((double) fill_blue)/65535.0 - ); + opacity, + ((double) boundary_red)/65535.0, + ((double) boundary_green)/65535.0, + ((double) boundary_blue)/65535.0, + ((double) fill_red)/65535.0, + ((double) fill_green)/65535.0, + ((double) fill_blue)/65535.0 + ); } void pngwriter::flood_fill_blend(int xstart, int ystart, double opacity, double fill_red, double fill_green, double fill_blue) @@ -4141,26 +4141,26 @@ void pngwriter::flood_fill_blend(int xstart, int ystart, double opacity, int fil void pngwriter::polygon_blend( int * points, int number_of_points, double opacity, double red, double green, double blue) { if( (number_of_points<1)||(points ==NULL)) - { + { std::cerr << " PNGwriter::polygon_blend - ERROR **: Number of points is zero or negative, or array is NULL." << std::endl; return; - } + } for(int k=0;k< number_of_points-1; k++) - { + { this->line_blend(points[2*k],points[2*k+1],points[2*k+2],points[2*k+3], opacity, red, green, blue); - } + } } //int version void pngwriter::polygon_blend( int * points, int number_of_points, double opacity, int red, int green, int blue) { this->polygon_blend(points, number_of_points, - opacity, - ((double) red)/65535.0, - ((double) green)/65535.0, - ((double) blue)/65535.0 - ); + opacity, + ((double) red)/65535.0, + ((double) green)/65535.0, + ((double) blue)/65535.0 + ); } void pngwriter::plotCMYK_blend(int x, int y, double opacity, double cyan, double magenta, double yellow, double black) @@ -4173,38 +4173,38 @@ void pngwriter::plotCMYK_blend(int x, int y, double opacity, double cyan, double * */ if(cyan<0.0) - { + { cyan = 0.0; - } + } if(magenta<0.0) - { + { magenta = 0.0; - } + } if(yellow<0.0) - { + { yellow = 0.0; - } + } if(black<0.0) - { + { black = 0.0; - } + } if(cyan>1.0) - { + { cyan = 1.0; - } + } if(magenta>1.0) - { + { magenta = 1.0; - } + } if(yellow>1.0) - { + { yellow = 1.0; - } + } if(black>1.0) - { + { black = 1.0; - } + } double red, green, blue, minr, ming, minb, iblack; @@ -4215,19 +4215,19 @@ void pngwriter::plotCMYK_blend(int x, int y, double opacity, double cyan, double minb = 1.0; if( (cyan*iblack + black)<1.0 ) - { + { minr = cyan*iblack + black; - } + } if( (magenta*iblack + black)<1.0 ) - { + { ming = magenta*iblack + black; - } + } if( (yellow*iblack + black)<1.0 ) - { + { minb = yellow*iblack + black; - } + } red = 1.0 - minr; green = 1.0 - ming; @@ -4258,12 +4258,12 @@ void pngwriter::laplacian(double k, double offset) double red, green, blue; for(int x = 1; x <= width_; x++) - { + { for(int y = 1; y <= height_; y++) { - red = - 8.0*this->dread(x,y,1) - - ( this->dread(x+1, y-1, 1) + + red = + 8.0*this->dread(x,y,1) - + ( this->dread(x+1, y-1, 1) + this->dread(x, y-1, 1) + this->dread(x-1, y-1, 1) + this->dread(x-1, y, 1) + @@ -4272,9 +4272,9 @@ void pngwriter::laplacian(double k, double offset) this->dread(x, y+1, 1) + this->dread(x-1, y+1, 1) ); - green = - 8.0*this->dread(x,y,2) - - ( this->dread(x+1, y-1, 2) + + green = + 8.0*this->dread(x,y,2) - + ( this->dread(x+1, y-1, 2) + this->dread(x, y-1, 2) + this->dread(x-1, y-1, 2) + this->dread(x-1, y, 2) + @@ -4283,9 +4283,9 @@ void pngwriter::laplacian(double k, double offset) this->dread(x, y+1, 2) + this->dread(x-1, y+1, 2)); - blue = - 8.0*this->dread(x,y,3) - - ( this->dread(x+1, y-1, 3) + + blue = + 8.0*this->dread(x,y,3) - + ( this->dread(x+1, y-1, 3) + this->dread(x, y-1, 3) + this->dread(x-1, y-1, 3) + this->dread(x-1, y, 3) + @@ -4294,18 +4294,18 @@ void pngwriter::laplacian(double k, double offset) this->dread(x, y+1, 3) + this->dread(x-1, y+1, 3)); - temp.plot(x,y,offset+k*red,offset+k*green,offset+k*blue); + temp.plot(x,y,offset+k*red,offset+k*green,offset+k*blue); } - } + } for(int xx = 1; xx <= width_; xx++) - { + { for(int yy = 1; yy <= height_; yy++) { - this->plot(xx,yy, temp.read(xx,yy,1), temp.read(xx,yy,2), temp.read(xx,yy,3)); + this->plot(xx,yy, temp.read(xx,yy,1), temp.read(xx,yy,2), temp.read(xx,yy,3)); } - } + } } @@ -4330,11 +4330,11 @@ void pngwriter::drawtop(long x1,long y1,long x2,long y2,long x3, int red, int gr long cr=((x3-x1)*256)/(y2-y1); for(int y=y1; yline(posl/256, y, posr/256, y, red, green, blue); posl+=cl; posr+=cr; - } + } } // drwatop(), drawbottom() and filledtriangle() were contributed by Gurkan Sengun @@ -4348,7 +4348,7 @@ void pngwriter::drawbottom(long x1,long y1,long x2,long x3,long y3, int red, int x2^=x1; x1^=x2; x2^=x1; - } + } long posl=x1*256; long posr=x2*256; @@ -4357,12 +4357,12 @@ void pngwriter::drawbottom(long x1,long y1,long x2,long x3,long y3, int red, int long cr=((x3-x2)*256)/(y3-y1); for(int y=y1; yline(posl/256, y, posr/256, y, red, green, blue); posl+=cl; posr+=cr; - } + } } // drwatop(), drawbottom() and filledtriangle() were contributed by Gurkan Sengun @@ -4372,7 +4372,7 @@ void pngwriter::filledtriangle(int x1,int y1,int x2,int y2,int x3,int y3, int re if((x1==x2 && x2==x3) || (y1==y2 && y2==y3)) return; if(y2drawtop(x1, y1, x2, y2, x3, red, green, blue); - } + } else - { + { if(y1==y3 || y1==y2) { - this->drawbottom(x1, y1, x2, x3, y3, red, green, blue); + this->drawbottom(x1, y1, x2, x3, y3, red, green, blue); } else { - int new_x = x1 + (int)((double)(y2-y1)*(double)(x3-x1)/(double)(y3-y1)); - this->drawtop(x1, y1, new_x, y2, x2, red, green, blue); - this->drawbottom(x2, y2, new_x, x3, y3, red, green, blue); + int new_x = x1 + (int)((double)(y2-y1)*(double)(x3-x1)/(double)(y3-y1)); + this->drawtop(x1, y1, new_x, y2, x2, red, green, blue); + this->drawbottom(x2, y2, new_x, x3, y3, red, green, blue); } - } + } } //Double (bug found by Dave Wilks. Was: (int) red*65535, should have been (int) (red*65535). void pngwriter::filledtriangle(int x1,int y1,int x2,int y2,int x3,int y3, double red, double green, double blue) { - this->filledtriangle(x1, y1, x2, y2, x3, y3, (int) (red*65535), (int) (green*65535), (int) (blue*65535)); + this->filledtriangle(x1, y1, x2, y2, x3, y3, (int) (red*65535), (int) (green*65535), (int) (blue*65535)); } //Blend, double. (bug found by Dave Wilks. Was: (int) red*65535, should have been (int) (red*65535). void pngwriter::filledtriangle_blend(int x1,int y1,int x2,int y2,int x3,int y3, double opacity, double red, double green, double blue) { - this->filledtriangle_blend( x1, y1, x2, y2, x3, y3, opacity, (int) (red*65535), (int) (green*65535), (int) (blue*65535)); + this->filledtriangle_blend( x1, y1, x2, y2, x3, y3, opacity, (int) (red*65535), (int) (green*65535), (int) (blue*65535)); } //Blend, int @@ -4445,26 +4445,26 @@ void pngwriter::filledtriangle_blend(int x1,int y1,int x2,int y2,int x3,int y3, if((x1==x2 && x2==x3) || (y1==y2 && y2==y3)) return; /*if(y2drawtop_blend(x1, y1, x2, y2, x3, opacity, red, green, blue); - } + } else - { + { if(y1==y3 || y1==y2) { - this->drawbottom_blend(x1, y1, x2, x3, y3, opacity, red, green, blue); + this->drawbottom_blend(x1, y1, x2, x3, y3, opacity, red, green, blue); } else { - int new_x = x1 + (int)((double)(y2-y1)*(double)(x3-x1)/(double)(y3-y1)); - this->drawtop_blend(x1, y1, new_x, y2, x2, opacity, red, green, blue); - this->drawbottom_blend(x2, y2, new_x, x3, y3, opacity, red, green, blue); + int new_x = x1 + (int)((double)(y2-y1)*(double)(x3-x1)/(double)(y3-y1)); + this->drawtop_blend(x1, y1, new_x, y2, x2, opacity, red, green, blue); + this->drawbottom_blend(x2, y2, new_x, x3, y3, opacity, red, green, blue); } - } + } } @@ -4538,12 +4538,12 @@ void pngwriter::drawbottom_blend(long x1,long y1,long x2,long x3,long y3, double long cr=((x3-x2)*256)/(y3-y1); for(int y=y1; yline_blend(posl/256, y, posr/256, y, opacity, red, green, blue); posl+=cl; posr+=cr; - } + } } @@ -4565,11 +4565,11 @@ void pngwriter::drawtop_blend(long x1,long y1,long x2,long y2,long x3, double op long cr=((x3-x1)*256)/(y2-y1); for(int y=y1; yline_blend(posl/256, y, posr/256, y, opacity, red, green, blue); posl+=cl; posr+=cr; - } + } } @@ -4582,11 +4582,11 @@ void pngwriter::triangle(int x1, int y1, int x2, int y2, int x3, int y3, int red void pngwriter::triangle(int x1, int y1, int x2, int y2, int x3, int y3, double red, double green, double blue) { - + this->line(x1, y1, x2, y2, ((int)65535*red), ((int)65535*green), ((int)65535*blue)); this->line(x2, y2, x3, y3, ((int)65535*red), ((int)65535*green), ((int)65535*blue)); this->line(x3, y3, x1, y1, ((int)65535*red), ((int)65535*green), ((int)65535*blue)); - + } @@ -4601,7 +4601,7 @@ void pngwriter::arrow( int x1,int y1,int x2,int y2,int size, double head_angle, double th = 3.141592653589793 + head_angle; double costh = cos(th); double sinth = sin(th); - double t1, t2, r; + double t1, t2, r; t1 = ((x2-x1)*costh - (y2-y1)*sinth); t2 = ((x2-x1)*sinth + (y2-y1)*costh); r = sqrt(t1*t1 + t2*t2); @@ -4611,16 +4611,16 @@ void pngwriter::arrow( int x1,int y1,int x2,int y2,int size, double head_angle, this->line(x2, y2, int(x2 + advancex), int(y2 + advancey), red, green, blue); t1 = (x2-x1)*costh + (y2-y1)*sinth; t2 = (y2-y1)*costh - (x2-x1)*sinth; - + advancex = size*t1/r; advancey = size*t2/r; this->line(x2, y2, int(x2 + advancex), int(y2 + advancey), red, green, blue); } - + void pngwriter::filledarrow( int x1,int y1,int x2,int y2,int size, double head_angle, double red, double green, double blue) { int p1x, p2x, p3x, p1y, p2y, p3y; - + this->line(x1, y1, x2, y2, red, green, blue); double th = 3.141592653589793 + head_angle; double costh = cos(th); @@ -4633,7 +4633,7 @@ void pngwriter::filledarrow( int x1,int y1,int x2,int y2,int size, double head_a r1 = sqrt(t11*t11 + t21*t21); r2 = sqrt(t12*t12 + t22*t22); - + double advancex1 = size*t11/r1; double advancey1 = size*t21/r1; double advancex2 = size*t12/r2; @@ -4641,16 +4641,16 @@ void pngwriter::filledarrow( int x1,int y1,int x2,int y2,int size, double head_a p1x = x2; p1y = y2; - + p2x = int(x2 + advancex1); p2y = int(y2 + advancey1); p3x = int(x2 + advancex2); p3y = int(y2 + advancey2); - + this->filledtriangle( p1x, p1y, p2x, p2y, p3x, p3y, red, green, blue); - + } void pngwriter::arrow( int x1,int y1,int x2,int y2,int size, double head_angle, int red, int green, int blue) @@ -4684,12 +4684,12 @@ void pngwriter::maltesecross( int x, int y, int xwidth, int yheight, int x_bar_h void pngwriter::cross( int x, int y, int xwidth, int yheight, double red, double green, double blue) { - this->cross( x, y, xwidth, yheight, int(65535*red), int(65535*green), int(65535*blue)); + this->cross( x, y, xwidth, yheight, int(65535*red), int(65535*green), int(65535*blue)); } void pngwriter::maltesecross( int x, int y, int xwidth, int yheight, int x_bar_height, int y_bar_width, double red, double green, double blue) { - this->maltesecross( x, y, xwidth, yheight, x_bar_height, y_bar_width, int(65535*red), int(65535*green), int(65535*blue)); + this->maltesecross( x, y, xwidth, yheight, x_bar_height, y_bar_width, int(65535*red), int(65535*green), int(65535*blue)); } @@ -4712,11 +4712,11 @@ void pngwriter::diamond( int x, int y, int width, int height, int red, int green void pngwriter::filleddiamond( int x, int y, int width, int height, double red, double green, double blue) { - this->filleddiamond( x, y, width, height, int(red*65535), int(green*65535), int(blue*65535) ); + this->filleddiamond( x, y, width, height, int(red*65535), int(green*65535), int(blue*65535) ); } void pngwriter::diamond( int x, int y, int width, int height, double red, double green, double blue) { - this->diamond( x, y, width, height, int(red*65535), int(green*65535), int(blue*65535) ); + this->diamond( x, y, width, height, int(red*65535), int(green*65535), int(blue*65535) ); } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a6083718..6f960b97 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,45 +2,12 @@ add_executable(WriteConfig WriteConfig.cpp) -add_executable(HyperionDispmanx - HyperionMain.cpp) +add_executable(hyperion-d + hyperion-d.cpp) -target_link_libraries(HyperionDispmanx +target_link_libraries(hyperion-d hyperion) -add_executable(boblight-dispmanx - boblight-dispmanx.cpp - flagmanager.h - flagmanager.cpp - flagmanager-dispmanx.h - flagmanager-dispmanx.cpp - grabber-dispmanx.h - grabber-dispmanx.cpp - misc.h - misc.cpp - timer.h - timer.cpp - timeutils.h - timeutils.cpp) - -# Find the BCM-package (VC control) -find_package(BCM REQUIRED) - -include_directories(${BCM_INCLUDE_DIRS}) - -target_link_libraries(boblight-dispmanx -# hyperion-png - bob2hyperion - ${BCM_LIBRARIES}) - -#add_executable(HyperionDispmanX -# HyperionDispmanX.cpp) - -#target_link_libraries(HyperionDispmanX -# hyperion -# ${BCM_LIBRARIES}) - - # Find the libPNG find_package(PNG QUIET) @@ -53,8 +20,5 @@ if(PNG_FOUND) target_link_libraries(ViewPng hyperion - hyperion-utils ${PNG_LIBRARIES}) endif(PNG_FOUND) - -add_subdirectory(dispmanx-png) diff --git a/src/HyperionDispmanX.cpp b/src/HyperionDispmanX.cpp deleted file mode 100644 index 8af333eb..00000000 --- a/src/HyperionDispmanX.cpp +++ /dev/null @@ -1,49 +0,0 @@ - -// VC includes -#include - -// Hyperion includes -#include - -#include -#include - - -#include "dispmanx-helper.h" - -static volatile bool sRunning = true; - -void signal_handler(int signum) -{ - std::cout << "RECEIVED SIGNAL: " << signum << std::endl; - sRunning = false; -} - -int main(int /*argc*/, char** /*argv*/) -{ - // Install signal-handlers to exit the processing loop - signal(SIGTERM, signal_handler); - signal(SIGINT, signal_handler); - - const char* homeDir = getenv("RASPILIGHT_HOME"); - if (!homeDir) - { - homeDir = "/etc"; - } - std::cout << "RASPILIGHT HOME DIR: " << homeDir << std::endl; - - const std::string schemaFile = std::string(homeDir) + "/hyperion.schema.json"; - const std::string configFile = std::string(homeDir) + "/hyperion.config.json"; - - Json::Value raspiConfig; - if (JsonFactory::load(schemaFile, configFile, raspiConfig) < 0) - { - std::cerr << "UNABLE TO LOAD CONFIGURATION" << std::endl; - return -1; - } - Hyperion hyperion(raspiConfig); - -// dispmanx_process(hyperion, sRunning); - - return 0; -} diff --git a/src/boblight-dispmanx.cpp b/src/boblight-dispmanx.cpp deleted file mode 100644 index 720d4fdf..00000000 --- a/src/boblight-dispmanx.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -//#define BOBLIGHT_DLOPEN -#include "boblight.h" - -#include -#include -#include -#include -#include - -//#include "config.h" -#include "misc.h" -#include "flagmanager-dispmanx.h" -#include "grabber-dispmanx.h" - -//OpenMax includes -#include "bcm_host.h" -#include - -using namespace std; - -#define TEST_SAVE_IMAGE 0 -#define PRINT_RET_VAL(ret, func, ...) ret = func(__VA_ARGS__); printf(#func " returned %d\n", ret); - -int Run(); -void SignalHandler(int signum); - -volatile bool stop = false; - -CFlagManagerDispmanX g_flagmanager; - -int main(int argc, char *argv[]) -{ - std::cout << "HACKED VERSION WITH TIMOLIGHT" << std::endl; - //load the boblight lib, if it fails we get a char* from dlerror() -// char* boblight_error = boblight_loadlibrary(NULL); -// if (boblight_error) -// { -// PrintError(boblight_error); -// return 1; -// } - - //try to parse the flags and bitch to stderr if there's an error - try - { - g_flagmanager.ParseFlags(argc, argv); - } - catch (string error) - { - PrintError(error); - g_flagmanager.PrintHelpMessage(); - return 1; - } - - if (g_flagmanager.m_printhelp) //print help message - { - g_flagmanager.PrintHelpMessage(); - return 1; - } - - if (g_flagmanager.m_printboblightoptions) //print boblight options (-o [light:]option=value) - { - g_flagmanager.PrintBoblightOptions(); - return 1; - } - - if (g_flagmanager.m_fork) - { - if (fork()) - return 0; - } - - //set up signal handlers - signal(SIGTERM, SignalHandler); - signal(SIGINT, SignalHandler); - - //keep running until we want to quit - return Run(); -} - -int Run() -{ - while(!stop) - { - //init boblight - void* boblight = boblight_init(); - - cout << "Connecting to boblightd\n"; - - //try to connect, if we can't then bitch to stderr and destroy boblight - if (!boblight_connect(boblight, g_flagmanager.m_address, g_flagmanager.m_port, 5000000) || - !boblight_setpriority(boblight, g_flagmanager.m_priority)) - { - PrintError(boblight_geterror(boblight)); - cout << "Waiting 10 seconds before trying again\n"; - boblight_destroy(boblight); - sleep(10); - continue; - } - - cout << "Connection to boblightd opened\n"; - - //try to parse the boblight flags and bitch to stderr if we can't - try - { - g_flagmanager.ParseBoblightOptions(boblight); - } - catch (string error) - { - PrintError(error); - return 1; - } - - CGrabberDispmanX *grabber = new CGrabberDispmanX(boblight, stop, g_flagmanager.m_sync); - - grabber->SetInterval(g_flagmanager.m_interval); - grabber->SetSize(g_flagmanager.m_pixels); - - if (!grabber->Setup()) //just exit if we can't set up the grabber - { - PrintError(grabber->GetError()); - delete grabber; - boblight_destroy(boblight); - return 1; - } - - if (!grabber->Run()) //just exit if some unrecoverable error happens - { - PrintError(grabber->GetError()); - delete grabber; - boblight_destroy(boblight); - return 1; - } - else //boblightd probably timed out, so just try to reconnect - { - if (!grabber->GetError().empty()) - PrintError(grabber->GetError()); - } - - delete grabber; - - boblight_destroy(boblight); - } - - cout << "Exiting\n"; - - return 0; -} - -void SignalHandler(int signum) -{ - if (signum == SIGTERM) - { - cout << "caught SIGTERM\n"; - stop = true; - } - else if (signum == SIGINT) - { - cout << "caught SIGINT\n"; - stop = true; - } -} diff --git a/src/dispmanx-helper.h b/src/dispmanx-helper.h deleted file mode 100644 index 6e079fca..00000000 --- a/src/dispmanx-helper.h +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once - -// VC includes -#include - -template -int dispmanx_process(Hyperion_T& hyperion, volatile bool& running) -{ - // Configure the used image size - const unsigned width = 64; - const unsigned height = 64; - hyperion.setInputSize(width, height); - - // Initiase BCM - bcm_host_init(); - - // Open the connection to the displaydisplay - DISPMANX_DISPLAY_HANDLE_T display = vc_dispmanx_display_open(0); - DISPMANX_MODEINFO_T info; - int ret = vc_dispmanx_display_get_info(display, &info); - assert(ret == 0); - - // Create the resources for capturing image - uint32_t vc_image_ptr; - DISPMANX_RESOURCE_HANDLE_T resource = vc_dispmanx_resource_create( - VC_IMAGE_RGB888, - width, - height, - &vc_image_ptr); - assert(resource); - - VC_RECT_T rectangle; - vc_dispmanx_rect_set(&rectangle, 0, 0, width, height); - - void* image_ptr = hyperion.image().memptr(); - const uint32_t pitch = width * 3; - - timespec updateInterval; - updateInterval.tv_sec = 0; - updateInterval.tv_nsec = 100000000; - while(running) - { - vc_dispmanx_snapshot(display, resource, VC_IMAGE_ROT0); - vc_dispmanx_resource_read_data(resource, &rectangle, image_ptr, pitch); - - hyperion.commit(); - - nanosleep(&updateInterval, NULL); - } - - // Clean up resources - vc_dispmanx_resource_delete(resource); - vc_dispmanx_display_close(display); - - // De-init BCM - bcm_host_deinit(); - - return 0; -} diff --git a/src/dispmanx-png/CMakeLists.txt b/src/dispmanx-png/CMakeLists.txt deleted file mode 100644 index 8d4a75b6..00000000 --- a/src/dispmanx-png/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ - -# Find the BCM-package (VC control) -find_package(BCM REQUIRED) - -# Add the include dirs to the search path -include_directories(${BCM_INCLUDE_DIRS}) - -add_executable(dispmanx-png - dispmanx-png.cpp) - -target_link_libraries(dispmanx-png - hyperion-png - ${BCM_LIBRARIES}) diff --git a/src/dispmanx-png/dispmanx-png.cpp b/src/dispmanx-png/dispmanx-png.cpp deleted file mode 100644 index 8aa2c6b8..00000000 --- a/src/dispmanx-png/dispmanx-png.cpp +++ /dev/null @@ -1,28 +0,0 @@ - -// STL includes -#include - -// Hyperion includes -#include - -#include "../dispmanx-helper.h" - -static volatile bool sRunning = true; - -void signal_handler(int signum) -{ - std::cout << "RECEIVED SIGNAL: " << signum << std::endl; - sRunning = false; -} - - -int main(int /*argc*/, char** /*argv*/) -{ - // Install signal-handlers to exit the processing loop - signal(SIGTERM, signal_handler); - signal(SIGINT, signal_handler); - - // Construct and initialise the PNG creator with preset size - HyperionPng hyperion; - return dispmanx_process(hyperion, sRunning); -} diff --git a/src/flagmanager-dispmanx.cpp b/src/flagmanager-dispmanx.cpp deleted file mode 100644 index 83bcaf66..00000000 --- a/src/flagmanager-dispmanx.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#include - -#include "flagmanager-dispmanx.h" -//#include "config.h" -#include "misc.h" - -using namespace std; - -CFlagManagerDispmanX::CFlagManagerDispmanX() -{ - //extend the base getopt flags - //i = interval, u = pixels, x = xgetimage, d = debug - m_flags += "i:u:d::"; - - m_interval = 0.1; //default interval is 100 milliseconds - m_pixels = 64; //-1 says to the capture classes to use default - m_debug = false; //no debugging by default - m_debugdpy = NULL; //default debug dpy is system default - m_sync = true; //sync mode enabled by default -} - -void CFlagManagerDispmanX::ParseFlagsExtended(int& argc, char**& argv, int& c, char*& optarg) //we load our own flags here -{ - if (c == 'i') //interval - { - bool vblank = false; - - if (optarg[0] == 'v') //starting interval with v means vblank interval - { - #ifdef HAVE_LIBGL - optarg++; - vblank = true; - #else - throw string("Compiled without opengl support"); - #endif - } - - if (!StrToFloat(optarg, m_interval) || m_interval <= 0.0) - { - throw string("Wrong value " + string(optarg) + " for interval"); - } - - if (vblank) - { - if (m_interval < 1.0) - { - throw string("Wrong value " + string(optarg) + " for vblank interval"); - } - m_interval *= -1.0; //negative interval means vblank - optarg--; - } - } - else if (c == 'u') //nr of pixels to use - { - if (!StrToInt(optarg, m_pixels) || m_pixels <= 0) - { - throw string("Wrong value " + string(optarg) + " for pixels"); - } - } - else if (c == 'd') //turn on debug mode - { - m_debug = true; - if (optarg) //optional debug dpy - { - m_strdebugdpy = optarg; - m_debugdpy = m_strdebugdpy.c_str(); - } - } -} - -void CFlagManagerDispmanX::PrintHelpMessage() -{ - cout << "Usage: boblight-dispmanx [OPTION]\n"; - cout << "\n"; - cout << " options:\n"; - cout << "\n"; - cout << " -p priority, from 0 to 255, default is 128\n"; - cout << " -s address:[port], set the address and optional port to connect to\n"; - cout << " -o add libboblight option, syntax: [light:]option=value\n"; - cout << " -l list libboblight options\n"; - cout << " -i set the interval in seconds, default is 0.1\n"; - cout << " -u set the number of pixels/rows to use\n"; - cout << " default is 64 for xrender and 16 for xgetimage\n"; - cout << " -d debug mode\n"; - cout << " -f fork\n"; - cout << " -y set the sync mode, default is on, valid options are \"on\" and \"off\"\n"; - cout << "\n"; -} diff --git a/src/flagmanager-dispmanx.h b/src/flagmanager-dispmanx.h deleted file mode 100644 index f91381f1..00000000 --- a/src/flagmanager-dispmanx.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef FLAGMANAGERDISPMANX -#define FLAGMANAGERDISPMANX - -#include "flagmanager.h" - -class CFlagManagerDispmanX : public CFlagManager -{ -public: - CFlagManagerDispmanX(); - - int m_color; - - void ParseFlagsExtended(int& argc, char**& argv, int& c, char*& optarg); //we load our own flags here - void PrintHelpMessage(); - - double m_interval; //grab interval in seconds, or vertical blanks when negative - int m_pixels; //number of pixels on lines to capture - bool m_debug; //if true we make a little window where we put our captured output on, looks pretty - const char* m_debugdpy; //display to place the debug window on, default is NULL - -private: - - std::string m_strdebugdpy; //place to store the debug dpy, cause our copied argv is destroyed -}; - -#endif //FLAGMANAGEROPENMAX diff --git a/src/flagmanager.cpp b/src/flagmanager.cpp deleted file mode 100644 index cf3a608b..00000000 --- a/src/flagmanager.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#include -#include -#include - -#include "flagmanager.h" -#include "misc.h" - -//#define BOBLIGHT_DLOPEN_EXTERN -#include "boblight.h" - -using namespace std; - -//very simple, store a copy of argc and argv -CArguments::CArguments(int argc, char** argv) -{ - m_argc = argc; - - if (m_argc == 0) - { - m_argv = NULL; - } - else - { - m_argv = new char*[m_argc]; - for (int i = 0; i < m_argc; i++) - { - m_argv[i] = new char[strlen(argv[i]) + 1]; - strcpy(m_argv[i], argv[i]); - } - } -} - -//delete the copy of argv -CArguments::~CArguments() -{ - if (m_argv) - { - for (int i = 0; i < m_argc; i++) - { - delete[] m_argv[i]; - } - delete[] m_argv; - } -} - -CFlagManager::CFlagManager() -{ - m_port = -1; //-1 tells libboblight to use default port - m_address = NULL; //NULL tells libboblight to use default address - m_priority = 128; //default priority - m_printhelp = false; //don't print helpmessage unless asked to - m_printboblightoptions = false; //same for libboblight options - m_fork = false; //don't fork by default - m_sync = false; //sync mode disabled by default - - // default getopt flags, can be extended in derived classes - // p = priority, s = address[:port], o = boblight option, l = list boblight options, h = print help message, f = fork - m_flags = "p:s:o:lhfy:"; -} - -void CFlagManager::ParseFlags(int tempargc, char** tempargv) -{ - //that copy class sure comes in handy now! - CArguments arguments(tempargc, tempargv); - int argc = arguments.m_argc; - char** argv = arguments.m_argv; - - string option; - int c; - - opterr = 0; //we don't want to print error messages - - while ((c = getopt(argc, argv, m_flags.c_str())) != -1) - { - if (c == 'p') //priority - { - option = optarg; - if (!StrToInt(option, m_priority) || m_priority < 0 || m_priority > 255) - { - throw string("Wrong option " + string(optarg) + " for argument -p"); - } - } - else if (c == 's') //address[:port] - { - option = optarg; - //store address in string and set the char* to it - m_straddress = option.substr(0, option.find(':')); - m_address = m_straddress.c_str(); - - if (option.find(':') != string::npos) //check if we have a port - { - option = option.substr(option.find(':') + 1); - string word; - if (!StrToInt(option, m_port) || m_port < 0 || m_port > 65535) - { - throw string("Wrong option " + string(optarg) + " for argument -s"); - } - } - } - else if (c == 'o') //option for libboblight - { - m_options.push_back(optarg); - } - else if (c == 'l') //list libboblight options - { - m_printboblightoptions = true; - return; - } - else if (c == 'h') //print help message - { - m_printhelp = true; - return; - } - else if (c == 'f') - { - m_fork = true; - } - else if (c == 'y') - { - if (!StrToBool(optarg, m_sync)) - { - throw string("Wrong value " + string(optarg) + " for sync mode"); - } - } - else if (c == '?') //unknown option - { - //check if we know this option, but expected an argument - if (m_flags.find(ToString((char)optopt) + ":") != string::npos) - { - throw string("Option " + ToString((char)optopt) + "requires an argument"); - } - else - { - throw string("Unkown option " + ToString((char)optopt)); - } - } - else - { - ParseFlagsExtended(argc, argv, c, optarg); //pass our argument to a derived class - } - } - - PostGetopt(optind, argc, argv); //some postprocessing -} - -//go through all options and print the descriptions to stdout -void CFlagManager::PrintBoblightOptions() -{ - void* boblight = boblight_init(); - int nroptions = boblight_getnroptions(boblight); - - for (int i = 0; i < nroptions; i++) - { - cout << boblight_getoptiondescript(boblight, i) << "\n"; - } - - boblight_destroy(boblight); -} - -void CFlagManager::ParseBoblightOptions(void* boblight) -{ - int nrlights = boblight_getnrlights(boblight); - - for (size_t i = 0; i < m_options.size(); i++) - { - string option = m_options[i]; - string lightname; - string optionname; - string optionvalue; - int lightnr = -1; - - //check if we have a lightname, otherwise we use all lights - if (option.find(':') != string::npos) - { - lightname = option.substr(0, option.find(':')); - if (option.find(':') == option.size() - 1) //check if : isn't the last char in the string - { - throw string("wrong option \"" + option + "\", syntax is [light:]option=value"); - } - option = option.substr(option.find(':') + 1); //shave off the lightname - - //check which light this is - bool lightfound = false; - for (int j = 0; j < nrlights; j++) - { - if (lightname == boblight_getlightname(boblight, j)) - { - lightfound = true; - lightnr = j; - break; - } - } - if (!lightfound) - { - throw string("light \"" + lightname + "\" used in option \"" + m_options[i] + "\" doesn't exist"); - } - } - - //check if '=' exists and it's not at the end of the string - if (option.find('=') == string::npos || option.find('=') == option.size() - 1) - { - throw string("wrong option \"" + option + "\", syntax is [light:]option=value"); - } - - optionname = option.substr(0, option.find('=')); //option name is everything before = (already shaved off the lightname here) - optionvalue = option.substr(option.find('=') + 1); //value is everything after = - - option = optionname + " " + optionvalue; //libboblight wants syntax without = - - //bitch if we can't set this option - if (!boblight_setoption(boblight, lightnr, option.c_str())) - { - throw string(boblight_geterror(boblight)); - } - } -} - -bool CFlagManager::SetVideoGamma() -{ - for (size_t i = 0; i < m_options.size(); i++) - { - string option = m_options[i]; - if (option.find(':') != string::npos) - option = option.substr(option.find(':') + 1); //shave off the lightname - - if (option.find('=') != string::npos) - { - if (option.substr(0, option.find('=')) == "gamma") - return false; //gamma set by user, don't override - } - } - - m_options.push_back("gamma=" + ToString(VIDEOGAMMA)); - - cout << "Gamma not set, using " << VIDEOGAMMA << " since this is default for video\n"; - - return true; -} - diff --git a/src/flagmanager.h b/src/flagmanager.h deleted file mode 100644 index 8a3b327d..00000000 --- a/src/flagmanager.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef FLAGMANAGER -#define FLAGMANAGER - -#define VIDEOGAMMA 2.2 - -#include -#include - -//class for making a copy of argc and argv -class CArguments -{ - public: - CArguments(int argc, char** argv); - ~CArguments(); - - int m_argc; - char** m_argv; -}; - -class CFlagManager -{ - public: - CFlagManager(); - - bool m_printhelp; //if we need to print the help message - bool m_printboblightoptions; //if we need to print the boblight options - - const char* m_address; //address to connect to, set to NULL if none given for default - int m_port; //port to connect to, set to -1 if none given for default - int m_priority; //priority, set to 128 if none given for default - bool m_fork; //if we should fork - bool m_sync; //if sync mode is enabled - - void ParseFlags(int tempargc, char** tempargv); //parsing commandline flags - virtual void PrintHelpMessage() {}; - - void PrintBoblightOptions(); //printing of boblight options (-o [light:]option=value) - void ParseBoblightOptions(void* boblight); //parsing of boblight options - bool SetVideoGamma(); //set gamma to 2.2 if not given, returns true if done - - protected: - - std::string m_flags; //string to pass to getopt, for example "c:r:a:p" - std::string m_straddress; //place to store address to connect to, because CArguments deletes argv - - std::vector m_options; //place to store boblight options - - //gets called from ParseFlags, for derived classes - virtual void ParseFlagsExtended(int& argc, char**& argv, int& c, char*& optarg){}; - //gets called after getopt - virtual void PostGetopt(int optind, int argc, char** argv) {}; -}; - -#endif //FLAGMANAGER diff --git a/src/grabber-dispmanx.cpp b/src/grabber-dispmanx.cpp deleted file mode 100644 index 04cd1bb8..00000000 --- a/src/grabber-dispmanx.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#include "stdint.h" - -#include "grabber-dispmanx.h" - -#include -#include - -#include "misc.h" - -//#define BOBLIGHT_DLOPEN_EXTERN -#include "boblight.h" - -using namespace std; - -CGrabberDispmanX::CGrabberDispmanX(void* boblight, volatile bool& stop, bool sync) : m_stop(stop), m_timer(&stop) -{ - int ret; - - bcm_host_init(); - - m_boblight = boblight; - m_debug = false; - m_sync = sync; - - type = VC_IMAGE_RGB888; - - display = vc_dispmanx_display_open(0); - - ret = vc_dispmanx_display_get_info(display, &info); - assert(ret == 0); -} - -CGrabberDispmanX::~CGrabberDispmanX() -{ - int ret; - - free(image); - - ret = vc_dispmanx_resource_delete(resource); - assert( ret == 0 ); - ret = vc_dispmanx_display_close(display); - assert( ret == 0 ); - - bcm_host_deinit(); -} - -bool CGrabberDispmanX::Setup() -{ - if (m_interval > 0.0) //set up timer - { - m_timer.SetInterval(Round64(m_interval * 1000000.0)); - } - - pitch = ALIGN_UP(m_size*3, 32); - - image = new char[m_size * m_size * 3]; - - resource = vc_dispmanx_resource_create(type, - m_size, - m_size, - &vc_image_ptr ); - assert(resource); - - m_error.clear(); - - return ExtendedSetup(); //run stuff from derived classes -} - -bool CGrabberDispmanX::ExtendedSetup() -{ - if (!CheckExtensions()) - return false; - - return true; -} - -bool CGrabberDispmanX::CheckExtensions() -{ - return true; -} - -bool CGrabberDispmanX::Run() -{ - int rgb[3]; - VC_RECT_T rectangle; - char* image_ptr; - - boblight_setscanrange(m_boblight, m_size, m_size); - - while(!m_stop) - { - vc_dispmanx_snapshot(display,resource, VC_IMAGE_ROT0); - - vc_dispmanx_rect_set(&rectangle, 0, 0, m_size, m_size); - - vc_dispmanx_resource_read_data(resource, &rectangle, image, m_size*3); - - image_ptr = (char *)image; - //read out the pixels - for (int y = 0; y < m_size && !m_stop; y++) - { -// image_ptr += y*m_size*3; - for (int x = 0; x < m_size && !m_stop; x++) - { - rgb[0] = image_ptr[y*m_size*3+x*3]; - rgb[1] = image_ptr[y*m_size*3+x*3 + 1]; - rgb[2] = image_ptr[y*m_size*3+x*3 + 2]; - - boblight_addpixelxy(m_boblight, x, y, rgb); - } - } - - - //send pixeldata to boblight - if (!boblight_sendrgb(m_boblight, m_sync, NULL)) - { - m_error = boblight_geterror(m_boblight); - return true; //recoverable error - } - - //when in debug mode, put the captured image on the debug window - if (m_debug) - { - printf("Debug not supproted!\n"); - m_debug = false; - } - - if (!Wait()) - { - return false; //unrecoverable error - } - } - - m_error.clear(); - - return true; -} - -bool CGrabberDispmanX::Wait() -{ - if (m_interval > 0.0) //wait for timer - { - m_timer.Wait(); - } - return true; -} - diff --git a/src/grabber-dispmanx.h b/src/grabber-dispmanx.h deleted file mode 100644 index 3783b101..00000000 --- a/src/grabber-dispmanx.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef GRABBERDISPMANX -#define GRABBERDISPMANX - -#include "bcm_host.h" - -#include - -//#include "config.h" -#include "timer.h" - -#ifndef ALIGN_UP -#define ALIGN_UP(x,y) ((x + (y)-1) & ~((y)-1)) -#endif - -//class for grabbing with DispmanX -class CGrabberDispmanX -{ - public: - CGrabberDispmanX(void* boblight, volatile bool& stop, bool sync); - ~CGrabberDispmanX(); - - bool ExtendedSetup(); - bool Run(); - - std::string& GetError() { return m_error; } //retrieves the latest error - - void SetInterval(double interval) { m_interval = interval; } //sets interval, negative means vblanks - void SetSize(int size) { m_size = size; } //sets how many pixels we want to grab - - bool Setup(); //base setup function - - void SetDebug(const char* display); //turn on debug window - - protected: - - bool Wait(); //wait for the timer or on the vblank - volatile bool& m_stop; - - std::string m_error; //latest error - - void* m_boblight; //our handle from libboblight - - int m_size; //nr of pixels on lines to grab - - bool m_debug; //if we have debug mode on - - long double m_lastupdate; - long double m_lastmeasurement; - long double m_measurements; - int m_nrmeasurements; - - double m_interval; //interval in seconds, or negative for vblanks - CTimer m_timer; //our timer - bool m_sync; //sync mode for libboblight - - - private: - - bool CheckExtensions(); - - DISPMANX_DISPLAY_HANDLE_T display; - DISPMANX_MODEINFO_T info; - void *image; - DISPMANX_UPDATE_HANDLE_T update; - DISPMANX_RESOURCE_HANDLE_T resource; - DISPMANX_ELEMENT_HANDLE_T element; - uint32_t vc_image_ptr; - VC_IMAGE_TYPE_T type; - int pitch; -}; - -#endif //GRABBEROPENMAX diff --git a/src/HyperionMain.cpp b/src/hyperion-d.cpp similarity index 100% rename from src/HyperionMain.cpp rename to src/hyperion-d.cpp diff --git a/src/misc.cpp b/src/misc.cpp deleted file mode 100644 index 3cf71bd0..00000000 --- a/src/misc.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#include -#include -#include "misc.h" - -using namespace std; - -void PrintError(const std::string& error) -{ - std::cerr << "ERROR: " << error << "\n"; -} - -//get the first word (separated by whitespace) from string data and place that in word -//then remove that word from string data -bool GetWord(string& data, string& word) -{ - stringstream datastream(data); - string end; - - datastream >> word; - if (datastream.fail()) - { - data.clear(); - return false; - } - - size_t pos = data.find(word) + word.length(); - - if (pos >= data.length()) - { - data.clear(); - return true; - } - - data = data.substr(pos); - - datastream.clear(); - datastream.str(data); - - datastream >> end; - if (datastream.fail()) - data.clear(); - - return true; -} - -//convert . or , to the current locale for correct conversion of ascii float -void ConvertFloatLocale(std::string& strfloat) -{ - static struct lconv* locale = localeconv(); - - size_t pos = strfloat.find_first_of(",."); - - while (pos != string::npos) - { - strfloat.replace(pos, 1, 1, *locale->decimal_point); - pos++; - - if (pos >= strfloat.size()) - break; - - pos = strfloat.find_first_of(",.", pos); - } -} diff --git a/src/misc.h b/src/misc.h deleted file mode 100644 index 76593a46..00000000 --- a/src/misc.h +++ /dev/null @@ -1,191 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef MISCUTIL -#define MISCUTIL - -#include "stdint.h" - -#include -#include -#include -#include - -#include -#include -#include -#include - -void PrintError(const std::string& error); -bool GetWord(std::string& data, std::string& word); -void ConvertFloatLocale(std::string& strfloat); - -template -inline std::string ToString(Value value) -{ - std::string data; - std::stringstream valuestream; - valuestream << value; - valuestream >> data; - return data; -} - -inline std::string GetErrno() -{ - return strerror(errno); -} - -inline std::string GetErrno(int err) -{ - return strerror(err); -} - -template -inline A Clamp(A value, B min, C max) -{ - return value < max ? (value > min ? value : min) : max; -} - -template -inline A Max(A value1, B value2) -{ - return value1 > value2 ? value1 : value2; -} - -template -inline A Max(A value1, B value2, C value3) -{ - return (value1 > value2) ? (value1 > value3 ? value1 : value3) : (value2 > value3 ? value2 : value3); -} - -template -inline A Min(A value1, B value2) -{ - return value1 < value2 ? value1 : value2; -} - -template -inline A Min(A value1, B value2, C value3) -{ - return (value1 < value2) ? (value1 < value3 ? value1 : value3) : (value2 < value3 ? value2 : value3); -} - -template -inline T Abs(T value) -{ - return value > 0 ? value : -value; -} - -template -inline A Round(B value) -{ - if (value == 0.0) - { - return 0; - } - else if (value > 0.0) - { - return (A)(value + 0.5); - } - else - { - return (A)(value - 0.5); - } -} - -inline int32_t Round32(float value) -{ - return lroundf(value); -} - -inline int32_t Round32(double value) -{ - return lround(value); -} - -inline int64_t Round64(float value) -{ - return llroundf(value); -} - -inline int64_t Round64(double value) -{ - return llround(value); -} - -inline bool StrToInt(const std::string& data, int& value) -{ - return sscanf(data.c_str(), "%i", &value) == 1; -} - -inline bool StrToInt(const std::string& data, int64_t& value) -{ - return sscanf(data.c_str(), "%lld", &value) == 1; -} - -inline bool HexStrToInt(const std::string& data, int& value) -{ - return sscanf(data.c_str(), "%x", &value) == 1; -} - -inline bool HexStrToInt(const std::string& data, int64_t& value) -{ - return sscanf(data.c_str(), "%llx", &value) == 1; -} - -inline bool StrToFloat(const std::string& data, float& value) -{ - return sscanf(data.c_str(), "%f", &value) == 1; -} - -inline bool StrToFloat(const std::string& data, double& value) -{ - return sscanf(data.c_str(), "%lf", &value) == 1; -} - -inline bool StrToBool(const std::string& data, bool& value) -{ - std::string data2 = data; - std::string word; - if (!GetWord(data2, word)) - return false; - - if (word == "1" || word == "true" || word == "on" || word == "yes") - { - value = true; - return true; - } - else if (word == "0" || word == "false" || word == "off" || word == "no") - { - value = false; - return true; - } - else - { - int ivalue; - if (StrToInt(word, ivalue)) - { - value = ivalue != 0; - return true; - } - } - - return false; -} - -#endif //MISCUTIL diff --git a/src/timer.cpp b/src/timer.cpp deleted file mode 100644 index 343062ca..00000000 --- a/src/timer.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#include "timer.h" -#include "misc.h" -#include "timeutils.h" - -#include -using namespace std; - -CTimer::CTimer(volatile bool* stop /*=NULL*/) -{ - m_interval = -1; - m_timerstop = stop; -} - -void CTimer::SetInterval(int64_t usecs) -{ - m_interval = usecs; - Reset(); -} - -int64_t CTimer::GetInterval() -{ - return m_interval; -} - -void CTimer::Reset() -{ - m_time = GetTimeUs(); -} - -void CTimer::Wait() -{ - int64_t sleeptime; - - //keep looping until we have a timestamp that's not too old - int64_t now = GetTimeUs(); - do - { - m_time += m_interval; - sleeptime = m_time - now; - } - while(sleeptime <= m_interval * -2LL); - - if (sleeptime > m_interval * 2LL) //failsafe, m_time must be bork if we get here - { - sleeptime = m_interval * 2LL; - Reset(); - } - - USleep(sleeptime, m_timerstop); -} - diff --git a/src/timer.h b/src/timer.h deleted file mode 100644 index 28bac58b..00000000 --- a/src/timer.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef CTIMER -#define CTIMER - -#include "stdint.h" - -#include - -class CTimer -{ - public: - CTimer(volatile bool* stop = NULL); - void SetInterval(int64_t usecs); - virtual void Wait(); - void Reset(); - - int64_t GetInterval(); - - protected: - int64_t m_time; - int64_t m_interval; - volatile bool* m_timerstop; -}; - -#endif diff --git a/src/timeutils.cpp b/src/timeutils.cpp deleted file mode 100644 index b5f67f53..00000000 --- a/src/timeutils.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#include "timeutils.h" - -void USleep(int64_t usecs, volatile bool* stop /*= NULL*/) -{ - if (usecs <= 0) - { - return; - } - else if (stop && usecs > 1000000) //when a pointer to a bool is passed, check it every second and stop when it's true - { - int64_t now = GetTimeUs(); - int64_t end = now + usecs; - - while (now < end) - { - struct timespec sleeptime = {}; - - if (*stop) - return; - else if (end - now >= 1000000) - sleeptime.tv_sec = 1; - else - sleeptime.tv_nsec = ((end - now) % 1000000) * 1000; - - nanosleep(&sleeptime, NULL); - now = GetTimeUs(); - } - } - else - { - struct timespec sleeptime; - sleeptime.tv_sec = usecs / 1000000; - sleeptime.tv_nsec = (usecs % 1000000) * 1000; - - nanosleep(&sleeptime, NULL); - } -} - diff --git a/src/timeutils.h b/src/timeutils.h deleted file mode 100644 index 9c9bd689..00000000 --- a/src/timeutils.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * boblight - * Copyright (C) Bob 2009 - * - * boblight is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * boblight is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef TIMEUTILS -#define TIMEUTILS - -#include "stdint.h" -//#include "config.h" - -#include -#include - -inline int64_t GetTimeUs() -{ -#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) - struct timespec time; - clock_gettime(CLOCK_MONOTONIC, &time); - return ((int64_t)time.tv_sec * 1000000LL) + (int64_t)(time.tv_nsec + 500) / 1000LL; -#else - struct timeval time; - gettimeofday(&time, NULL); - return ((int64_t)time.tv_sec * 1000000LL) + (int64_t)time.tv_usec; -#endif -} - -template -inline T GetTimeSec() -{ - return (T)GetTimeUs() / (T)1000000.0; -} - -void USleep(int64_t usecs, volatile bool* stop = NULL); - -#endif //TIMEUTILS diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0a6e87b9..6bcb32c6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,44 +4,33 @@ include_directories(../libsrc) # Add the simple test executable 'TestSpi' add_executable(TestSpi TestSpi.cpp) - target_link_libraries(TestSpi - hyperion - hyperion-utils) + hyperion) + add_executable(TestConfigFile TestConfigFile.cpp) - target_link_libraries(TestConfigFile - hyperion-utils hyperion) -add_executable(Test2BobLight - Test2BobLight.cpp) - -target_link_libraries(Test2BobLight - bob2hyperion) - add_executable(TestRgbImage TestRgbImage.cpp) target_link_libraries(TestRgbImage hyperion-utils) add_executable(TestColorTransform - TestColorTransform.cpp) + TestColorTransform.cpp) target_link_libraries(TestColorTransform - hyperion) + hyperion) # Find the libPNG find_package(PNG REQUIRED QUIET) -#if(PNG_FOUND) - # Add additional includes dirs - include_directories(${PNG_INCLUDE_DIR}) +# Add additional includes dirs +include_directories(${PNG_INCLUDE_DIR}) - add_executable(TestHyperionPng - TestHyperionPng.cpp) +add_executable(TestHyperionPng + TestHyperionPng.cpp) - target_link_libraries(TestHyperionPng - hyperion-png) -#endif(PNG_FOUND) +target_link_libraries(TestHyperionPng + hyperion-png) diff --git a/test/Test2BobLight.cpp b/test/Test2BobLight.cpp deleted file mode 100644 index de5262af..00000000 --- a/test/Test2BobLight.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// STL includes -#include -#include - -#include - -// Boblight includes -#include - -int main() -{ - void* boblight_ptr = boblight_init(); - if (!boblight_ptr) - { - std::cerr << "Failed to initialise bob-light" << std::endl; - return -1; - } - - const unsigned width = 112; - const unsigned height = 63; - - boblight_setscanrange(boblight_ptr, width, height); - - std::vector rgbColor = { 255, 255, 0 }; - for (unsigned iY=0; iY - -// Boblight includes -#include - -int main() -{ - std::cout << "TestBoblightOrig started" << std::endl; - - std::cout << "TestBoblightOrig finished" << std::endl; - - return 0; -} - diff --git a/test/TestConfigFile.cpp b/test/TestConfigFile.cpp index 41e9d5cf..afe71143 100644 --- a/test/TestConfigFile.cpp +++ b/test/TestConfigFile.cpp @@ -23,16 +23,30 @@ int main() } const Json::Value& deviceConfig = config["device"]; + if (deviceConfig.empty()) + { + std::cout << "Missing DEVICE configuration 'device'" << std::endl; + } const Json::Value& ledConfig = config["leds"]; + if (ledConfig.empty()) + { + std::cout << "Missing LEDS configuration 'leds'" << std::endl; + } + const Json::Value& colorConfig = config["color"]; + if (colorConfig.empty()) + { + std::cout << "Missing COLORS configuration 'colors'" << std::endl; + } + else + { + std::cout << "COLOR CONFIGURATION: " << colorConfig.toStyledString() << std::endl; - std::cout << "COLOR CONFIGURATION: " << colorConfig.toStyledString() << std::endl; - - const Json::Value& redConfig = colorConfig["red"]; - double redGamma = redConfig["gamma"].asDouble(); - std::cout << "RED GAMMA = " << redGamma << std::endl; - std::cout << "RED GAMMA = " << colorConfig["red.gamma"].asDouble() << std::endl; -// LedString ledString = LedString::construct(ledConfig, colorConfig); + const Json::Value& redConfig = colorConfig["red"]; + double redGamma = redConfig["gamma"].asDouble(); + std::cout << "RED GAMMA = " << redGamma << std::endl; + std::cout << "RED GAMMA = " << colorConfig["red.gamma"].asDouble() << std::endl; + } return 0; }