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;
}