diff --git a/include/dispmanx-grabber/DispmanxWrapper.h b/include/dispmanx-grabber/DispmanxWrapper.h index b5487945..9fa45f7d 100644 --- a/include/dispmanx-grabber/DispmanxWrapper.h +++ b/include/dispmanx-grabber/DispmanxWrapper.h @@ -5,8 +5,9 @@ #include // Utils includes -#include -#include +#include +#include +#include #include // Forward class declaration @@ -15,8 +16,8 @@ class Hyperion; class ImageProcessor; /// -/// The DispmanxWrapper uses an instance of the DispmanxFrameGrabber to obtain RgbImage's from the -/// displayed content. This RgbImage is processed to a RgbColor for each led and commmited to the +/// The DispmanxWrapper uses an instance of the DispmanxFrameGrabber to obtain ImageRgb's from the +/// displayed content. This ImageRgb is processed to a ColorRgb for each led and commmited to the /// attached Hyperion. /// class DispmanxWrapper: public QObject @@ -72,14 +73,14 @@ private: QTimer _timer; /// The image used for grabbing frames - RgbImage _image; + Image _image; /// The actual grabber DispmanxFrameGrabber * _frameGrabber; /// The processor for transforming images to led colors ImageProcessor * _processor; /// The list with computed led colors - std::vector _ledColors; + std::vector _ledColors; /// Pointer to Hyperion for writing led values Hyperion * _hyperion; diff --git a/libsrc/hyperion/BlackBorderDetector.h b/include/hyperion/BlackBorderDetector.h similarity index 51% rename from libsrc/hyperion/BlackBorderDetector.h rename to include/hyperion/BlackBorderDetector.h index 7f0a0b59..ba71ebb4 100644 --- a/libsrc/hyperion/BlackBorderDetector.h +++ b/include/hyperion/BlackBorderDetector.h @@ -2,7 +2,7 @@ #pragma once // Utils includes -#include +#include namespace hyperion { @@ -58,7 +58,59 @@ namespace hyperion /// /// @return The detected (or not detected) black border info /// - BlackBorder process(const RgbImage& image); + template + BlackBorder process(const Image & image) + { + // only test the topleft third of the image + int width = image.width() /3; + int height = image.height() / 3; + int maxSize = std::max(width, height); + + int firstNonBlackXPixelIndex = -1; + int firstNonBlackYPixelIndex = -1; + + // find some pixel of the image + for (int i = 0; i < maxSize; ++i) + { + int x = std::min(i, width); + int y = std::min(i, height); + + const Pixel_T & color = image(x, y); + if (!isBlack(color)) + { + firstNonBlackXPixelIndex = x; + firstNonBlackYPixelIndex = y; + break; + } + } + + // expand image to the left + for(; firstNonBlackXPixelIndex > 0; --firstNonBlackXPixelIndex) + { + const Pixel_T & color = image(firstNonBlackXPixelIndex-1, firstNonBlackYPixelIndex); + if (isBlack(color)) + { + break; + } + } + + // expand image to the top + for(; firstNonBlackYPixelIndex > 0; --firstNonBlackYPixelIndex) + { + const Pixel_T & color = image(firstNonBlackXPixelIndex, firstNonBlackYPixelIndex-1); + if (isBlack(color)) + { + break; + } + } + + // Construct result + BlackBorder detectedBorder; + detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1; + detectedBorder.horizontalSize = firstNonBlackYPixelIndex; + detectedBorder.verticalSize = firstNonBlackXPixelIndex; + return detectedBorder; + } private: @@ -69,11 +121,11 @@ namespace hyperion /// /// @return True if the color is considered black else false /// - inline bool isBlack(const RgbColor& color) + template + inline bool isBlack(const Pixel_T & color) { // Return the simple compare of the color against black - return RgbColor::BLACK == color; - // TODO[TvdZ]: We could add a threshold to check that the color is close to black + return color.red+color.green+color.green == 0; } }; } // end namespace hyperion diff --git a/libsrc/hyperion/BlackBorderProcessor.h b/include/hyperion/BlackBorderProcessor.h similarity index 73% rename from libsrc/hyperion/BlackBorderProcessor.h rename to include/hyperion/BlackBorderProcessor.h index d785f696..3ec2fe42 100644 --- a/libsrc/hyperion/BlackBorderProcessor.h +++ b/include/hyperion/BlackBorderProcessor.h @@ -42,9 +42,35 @@ namespace hyperion /// /// @return True if a different border was detected than the current else false /// - bool process(const RgbImage& image); + template + bool process(const Image & image) + { + // get the border for the single image + BlackBorder imageBorder = _detector.process(image); + // add blur to the border + if (imageBorder.horizontalSize > 0) + { + imageBorder.horizontalSize += _blurRemoveCnt; + } + if (imageBorder.verticalSize > 0) + { + imageBorder.verticalSize += _blurRemoveCnt; + } + + const bool borderUpdated = updateBorder(imageBorder); + return borderUpdated; + } + private: + /// + /// Updates the current border based on the newly detected border. Returns true if the + /// current border has changed. + /// + /// @param newDetectedBorder The newly detected border + /// @return True if the current border changed else false + /// + bool updateBorder(const BlackBorder & newDetectedBorder); /// The number of unknown-borders detected before it becomes the current border const unsigned _unknownSwitchCnt; diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index 42ce51df..5026ef08 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -8,7 +8,7 @@ #include // hyperion-utils includes -#include +#include // Hyperion includes #include @@ -76,7 +76,7 @@ public: /// @param[in] ledColor The color to write to the leds /// @param[in] timeout_ms The time the leds are set to the given color [ms] /// - void setColor(int priority, const RgbColor &ledColor, const int timeout_ms); + void setColor(int priority, const ColorRgb &ledColor, const int timeout_ms); /// /// Writes the given colors to all leds for the given time and priority @@ -85,7 +85,7 @@ public: /// @param[in] ledColors The colors to write to the leds /// @param[in] timeout_ms The time the leds are set to the given colors [ms] /// - void setColors(int priority, const std::vector &ledColors, const int timeout_ms); + void setColors(int priority, const std::vector &ledColors, const int timeout_ms); /// /// Sets/Updates a part of the color transformation. @@ -162,7 +162,7 @@ private: /// /// @param colors The colors to be transformed /// - void applyTransform(std::vector& colors) const; + void applyTransform(std::vector& colors) const; /// The specifiation of the led frame construction and picture integration LedString _ledString; diff --git a/include/hyperion/ImageProcessor.h b/include/hyperion/ImageProcessor.h index 7e847dbe..be87982e 100644 --- a/include/hyperion/ImageProcessor.h +++ b/include/hyperion/ImageProcessor.h @@ -2,17 +2,13 @@ #pragma once // Utils includes -#include +#include // Hyperion includes #include #include - -// Forward class declaration -namespace hyperion { - class ImageToLedsMap; - class BlackBorderProcessor; -} +#include +#include /// /// The ImageProcessor translates an RGB-image to RGB-values for the leds. The processing is @@ -42,7 +38,21 @@ public: /// /// @return The color value per led /// - std::vector process(const RgbImage& image); + template + std::vector process(const Image& image) + { + // Ensure that the buffer-image is the proper size + setSize(image.width(), image.height()); + + // Check black border detection + verifyBorder(image); + + // Create a result vector and call the 'in place' functionl + std::vector colors = mImageToLeds->getMeanLedColor(image); + + // return the computed colors + return colors; + } /// /// Determines the led colors of the image in the buffer. @@ -50,7 +60,18 @@ public: /// @param[in] image The image to translate to led values /// @param[out] ledColors The color value per led /// - void process(const RgbImage& image, std::vector& ledColors); + template + void process(const Image& image, std::vector& ledColors) + { + // Ensure that the buffer-image is the proper size + setSize(image.width(), image.height()); + + // Check black border detection + verifyBorder(image); + + // Determine the mean-colors of each led (using the existing mapping) + mImageToLeds->getMeanLedColor(image, ledColors); + } /// /// Get the hscan and vscan parameters for a single led @@ -80,7 +101,33 @@ private: /// /// @param[in] image The image to perform black-border detection on /// - void verifyBorder(const RgbImage& image); + template + void verifyBorder(const Image & image) + { + if(_enableBlackBorderRemoval && _borderProcessor->process(image)) + { + std::cout << "BORDER SWITCH REQUIRED!!" << std::endl; + + const hyperion::BlackBorder border = _borderProcessor->getCurrentBorder(); + + // Clean up the old mapping + delete mImageToLeds; + + if (border.unknown) + { + // Construct a new buffer and mapping + mImageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), 0, 0, mLedString.leds()); + } + else + { + // Construct a new buffer and mapping + mImageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), border.horizontalSize, border.verticalSize, mLedString.leds()); + } + + std::cout << "CURRENT BORDER TYPE: unknown=" << border.unknown << " hor.size=" << border.horizontalSize << " vert.size=" << border.verticalSize << std::endl; + } + } + private: /// The Led-string specification const LedString mLedString; @@ -89,7 +136,7 @@ private: bool _enableBlackBorderRemoval; /// The processor for black border detection - hyperion::BlackBorderProcessor* _borderProcessor; + hyperion::BlackBorderProcessor * _borderProcessor; /// The mapping of image-pixels to leds hyperion::ImageToLedsMap* mImageToLeds; diff --git a/libsrc/hyperion/ImageToLedsMap.h b/include/hyperion/ImageToLedsMap.h similarity index 62% rename from libsrc/hyperion/ImageToLedsMap.h rename to include/hyperion/ImageToLedsMap.h index 59fb68a6..7c9f375a 100644 --- a/libsrc/hyperion/ImageToLedsMap.h +++ b/include/hyperion/ImageToLedsMap.h @@ -2,10 +2,11 @@ #pragma once // STL includes +#include #include // hyperion-utils includes -#include +#include // hyperion includes #include @@ -63,7 +64,13 @@ namespace hyperion /// /// @return ledColors The vector containing the output /// - std::vector getMeanLedColor(const RgbImage & image) const; + template + std::vector getMeanLedColor(const Image & image) const + { + std::vector colors(mColorsMap.size(), ColorRgb{0,0,0}); + getMeanLedColor(image, colors); + return colors; + } /// /// Determines the mean color for each led using the mapping the image given @@ -72,7 +79,20 @@ namespace hyperion /// @param[in] image The image from which to extract the led colors /// @param[out] ledColors The vector containing the output /// - void getMeanLedColor(const RgbImage & image, std::vector & ledColors) const; + template + void getMeanLedColor(const Image & image, std::vector & ledColors) const + { + // Sanity check for the number of leds + assert(mColorsMap.size() == ledColors.size()); + + // Iterate each led and compute the mean + auto led = ledColors.begin(); + for (auto ledColors = mColorsMap.begin(); ledColors != mColorsMap.end(); ++ledColors, ++led) + { + const ColorRgb color = calcMeanColor(image, *ledColors); + *led = color; + } + } private: /// The width of the indexed image @@ -91,7 +111,34 @@ namespace hyperion /// /// @return The mean of the given list of colors (or black when empty) /// - RgbColor calcMeanColor(const RgbImage & image, const std::vector & colors) const; + template + ColorRgb calcMeanColor(const Image & image, const std::vector & colors) const + { + if (colors.size() == 0) + { + return ColorRgb::BLACK; + } + + // Accumulate the sum of each seperate color channel + uint_fast16_t cummRed = 0; + uint_fast16_t cummGreen = 0; + uint_fast16_t cummBlue = 0; + for (const unsigned colorOffset : colors) + { + const Pixel_T& pixel = image.memptr()[colorOffset]; + cummRed += pixel.red; + cummGreen += pixel.green; + cummBlue += pixel.blue; + } + + // Compute the average of each color channel + const uint8_t avgRed = uint8_t(cummRed/colors.size()); + const uint8_t avgGreen = uint8_t(cummGreen/colors.size()); + const uint8_t avgBlue = uint8_t(cummBlue/colors.size()); + + // Return the computed color + return {avgRed, avgGreen, avgBlue}; + } }; } // end namespace hyperion diff --git a/include/hyperion/LedDevice.h b/include/hyperion/LedDevice.h index 4539fc28..548770c3 100644 --- a/include/hyperion/LedDevice.h +++ b/include/hyperion/LedDevice.h @@ -4,7 +4,7 @@ #include // Utility includes -#include +#include /// /// Interface (pure virtual base class) for LedDevices. @@ -28,7 +28,7 @@ public: /// /// @return Zero on success else negative /// - virtual int write(const std::vector& ledValues) = 0; + virtual int write(const std::vector& ledValues) = 0; /// Switch the leds off virtual int switchOff() = 0; diff --git a/include/hyperion/LedString.h b/include/hyperion/LedString.h index 3f7103e0..e6adc2c0 100644 --- a/include/hyperion/LedString.h +++ b/include/hyperion/LedString.h @@ -7,7 +7,7 @@ #include // Local includes -#include +#include // Forward class declarations namespace Json { class Value; } diff --git a/include/hyperion/PriorityMuxer.h b/include/hyperion/PriorityMuxer.h index 2536150a..bc2aaaaa 100644 --- a/include/hyperion/PriorityMuxer.h +++ b/include/hyperion/PriorityMuxer.h @@ -10,7 +10,7 @@ #include // Utils includes -#include +#include // Hyperion includes #include @@ -34,7 +34,7 @@ public: /// The absolute timeout of the channel int64_t timeoutTime_ms; /// The colors for each led of the channel - std::vector ledColors; + std::vector ledColors; }; /// @@ -89,7 +89,7 @@ public: /// @param[in] ledColors The led colors of the priority channel /// @param[in] timeoutTime_ms The absolute timeout time of the channel /// - void setInput(const int priority, const std::vector& ledColors, const int64_t timeoutTime_ms=-1); + void setInput(const int priority, const std::vector& ledColors, const int64_t timeoutTime_ms=-1); /// /// Clears the specified priority channel diff --git a/include/utils/ColorArgb.h b/include/utils/ColorArgb.h new file mode 100644 index 00000000..9b5bc364 --- /dev/null +++ b/include/utils/ColorArgb.h @@ -0,0 +1,52 @@ +#pragma once + +// STL includes +#include +#include + +struct ColorArgb; + +struct ColorArgb +{ + + /// The alpha mask channel + uint8_t alpha; + + /// The red color channel + uint8_t red; + /// The green color channel + uint8_t green; + /// The blue color channel + uint8_t blue; + + /// 'Black' RgbColor (255, 0, 0, 0) + static ColorArgb BLACK; + /// 'Red' RgbColor (255, 255, 0, 0) + static ColorArgb RED; + /// 'Green' RgbColor (255, 0, 255, 0) + static ColorArgb GREEN; + /// 'Blue' RgbColor (255, 0, 0, 255) + static ColorArgb BLUE; + /// 'Yellow' RgbColor (255, 255, 255, 0) + static ColorArgb YELLOW; + /// 'White' RgbColor (255, 255, 255, 255) + static ColorArgb WHITE; +}; + + +/// Assert to ensure that the size of the structure is 'only' 3 bytes +static_assert(sizeof(ColorArgb) == 4, "Incorrect size of ColorARGB"); + +/// +/// Stream operator to write ColorRgb to an outputstream (format "'{'[alpha]', '[red]','[green]','[blue]'}'") +/// +/// @param os The output stream +/// @param color The color to write +/// @return The output stream (with the color written to it) +/// +inline std::ostream& operator<<(std::ostream& os, const ColorArgb& color) +{ + os << "{" << unsigned(color.alpha) << "," << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}"; + return os; +} + diff --git a/include/utils/RgbColor.h b/include/utils/ColorRgb.h similarity index 57% rename from include/utils/RgbColor.h rename to include/utils/ColorRgb.h index ae42e0ce..c578d69f 100644 --- a/include/utils/RgbColor.h +++ b/include/utils/ColorRgb.h @@ -1,18 +1,16 @@ - #pragma once // STL includes -#include +#include #include -// Forward class declaration -struct RgbColor; +struct ColorRgb; /// /// Plain-Old-Data structure containing the red-green-blue color specification. Size of the /// structure is exactly 3-bytes for easy writing to led-device /// -struct RgbColor +struct ColorRgb { /// The red color channel uint8_t red; @@ -22,42 +20,30 @@ struct RgbColor uint8_t blue; /// 'Black' RgbColor (0, 0, 0) - static RgbColor BLACK; + static ColorRgb BLACK; /// 'Red' RgbColor (255, 0, 0) - static RgbColor RED; + static ColorRgb RED; /// 'Green' RgbColor (0, 255, 0) - static RgbColor GREEN; + static ColorRgb GREEN; /// 'Blue' RgbColor (0, 0, 255) - static RgbColor BLUE; + static ColorRgb BLUE; /// 'Yellow' RgbColor (255, 255, 0) - static RgbColor YELLOW; + static ColorRgb YELLOW; /// 'White' RgbColor (255, 255, 255) - static RgbColor WHITE; - - /// - /// Checks is this exactly matches another color - /// - /// @param other The other color - /// - /// @return True if the colors are identical - /// - inline bool operator==(const RgbColor& other) const - { - return red == other.red && green == other.green && blue == other.blue; - } + static ColorRgb WHITE; }; /// Assert to ensure that the size of the structure is 'only' 3 bytes -static_assert(sizeof(RgbColor) == 3, "Incorrect size of RgbColor"); +static_assert(sizeof(ColorRgb) == 3, "Incorrect size of ColorRgb"); /// -/// Stream operator to write RgbColor to an outputstream (format "'{'[red]','[green]','[blue]'}'") +/// Stream operator to write ColorRgb to an outputstream (format "'{'[red]','[green]','[blue]'}'") /// /// @param os The output stream /// @param color The color to write /// @return The output stream (with the color written to it) /// -inline std::ostream& operator<<(std::ostream& os, const RgbColor& color) +inline std::ostream& operator<<(std::ostream& os, const ColorRgb& color) { os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}"; return os; diff --git a/include/utils/ColorRgba.h b/include/utils/ColorRgba.h new file mode 100644 index 00000000..67be78a8 --- /dev/null +++ b/include/utils/ColorRgba.h @@ -0,0 +1,52 @@ +#pragma once + +// STL includes +#include +#include + +struct ColorRgba; + +struct ColorRgba +{ + + /// The red color channel + uint8_t red; + /// The green color channel + uint8_t green; + /// The blue color channel + uint8_t blue; + + /// The alpha mask channel + uint8_t alpha; + + /// 'Black' RgbColor (0, 0, 0, 255) + static ColorRgba BLACK; + /// 'Red' RgbColor (255, 0, 0, 255) + static ColorRgba RED; + /// 'Green' RgbColor (0, 255, 0, 255) + static ColorRgba GREEN; + /// 'Blue' RgbColor (0, 0, 255, 255) + static ColorRgba BLUE; + /// 'Yellow' RgbColor (255, 255, 0, 255) + static ColorRgba YELLOW; + /// 'White' RgbColor (255, 255, 255, 255 + static ColorRgba WHITE; +}; + + +/// Assert to ensure that the size of the structure is 'only' 3 bytes +static_assert(sizeof(ColorRgba) == 4, "Incorrect size of ColorARGB"); + +/// +/// Stream operator to write ColorRgb to an outputstream (format "'{'[alpha]', '[red]','[green]','[blue]'}'") +/// +/// @param os The output stream +/// @param color The color to write +/// @return The output stream (with the color written to it) +/// +inline std::ostream& operator<<(std::ostream& os, const ColorRgba& color) +{ + os << "{" << unsigned(color.alpha) << "," << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}"; + return os; +} + diff --git a/include/utils/RgbImage.h b/include/utils/Image.h similarity index 52% rename from include/utils/RgbImage.h rename to include/utils/Image.h index cdc6539e..6c847372 100644 --- a/include/utils/RgbImage.h +++ b/include/utils/Image.h @@ -1,34 +1,56 @@ - #pragma once -#include -#include +// STL includes #include +#include +#include +#include -// Local includes -#include "RgbColor.h" - -/// -/// The RgbImage holds a 2D matrix of RgbColors's (or image). Width and height of the image are -/// fixed at construction. -/// -class RgbImage +template +class Image { public: + typedef Pixel_T pixel_type; + /// /// Constructor for an image with specified width and height /// /// @param width The width of the image /// @param height The height of the image - /// @param background The color of the image (default = BLACK) /// - RgbImage(const unsigned width, const unsigned height, const RgbColor background = RgbColor::BLACK); + Image(const unsigned width, const unsigned height) : + _width(width), + _height(height), + _pixels(new Pixel_T[width*height + 1]), + _endOfPixels(_pixels + width*height) + { + memset(_pixels, 0, (_width*_height+1)*sizeof(Pixel_T)); + } + + /// + /// Constructor for an image with specified width and height + /// + /// @param width The width of the image + /// @param height The height of the image + /// @param background The color of the image + /// + Image(const unsigned width, const unsigned height, const Pixel_T background) : + _width(width), + _height(height), + _pixels(new Pixel_T[width*height + 1]), + _endOfPixels(_pixels + width*height) + { + std::fill(_pixels, _endOfPixels, background); + } /// /// Destructor /// - ~RgbImage(); + ~Image() + { + delete[] _pixels; + } /// /// Returns the width of the image @@ -50,14 +72,25 @@ public: return _height; } - /// - /// Sets the color of a specific pixel in the image - /// - /// @param x The x index - /// @param y The y index - /// @param color The new color - /// - void setPixel(const unsigned x, const unsigned y, const RgbColor color); + uint8_t alpha(const unsigned pixel) const + { + return (_pixels + pixel)->red; + } + + uint8_t red(const unsigned pixel) const + { + return (_pixels + pixel)->red; + } + + uint8_t green(const unsigned pixel) const + { + return (_pixels + pixel)->green; + } + + uint8_t blue(const unsigned pixel) const + { + return (_pixels + pixel)->blue; + } /// /// Returns a const reference to a specified pixel in the image @@ -67,7 +100,10 @@ public: /// /// @return const reference to specified pixel /// - const RgbColor& operator()(const unsigned x, const unsigned y) const; + const Pixel_T& operator()(const unsigned x, const unsigned y) const + { + return _pixels[toIndex(x,y)]; + } /// /// Returns a reference to a specified pixel in the image @@ -77,37 +113,40 @@ public: /// /// @return reference to specified pixel /// - RgbColor& operator()(const unsigned x, const unsigned y); + Pixel_T& operator()(const unsigned x, const unsigned y) + { + return _pixels[toIndex(x,y)]; + } /// /// Copies another image into this image. The images should have exactly the same size. /// /// @param other The image to copy into this /// - inline void copy(const RgbImage& other) + void copy(const Image& other) { assert(other._width == _width); assert(other._height == _height); - memcpy(mColors, other.mColors, _width*_height*sizeof(RgbColor)); + memcpy(_pixels, other._pixels, _width*_height*sizeof(Pixel_T)); } /// /// Returns a memory pointer to the first pixel in the image /// @return The memory pointer to the first pixel /// - RgbColor* memptr() + Pixel_T* memptr() { - return mColors; + return _pixels; } /// /// Returns a const memory pointer to the first pixel in the image /// @return The const memory pointer to the first pixel /// - const RgbColor* memptr() const + const Pixel_T* memptr() const { - return mColors; + return _pixels; } private: @@ -130,6 +169,9 @@ private: /// The height of the image const unsigned _height; - /** The colors of the image */ - RgbColor* mColors; + /// The pixels of the image + Pixel_T* _pixels; + + /// Pointer to the last(extra) pixel + Pixel_T* _endOfPixels; }; diff --git a/libsrc/boblightserver/BoblightClientConnection.cpp b/libsrc/boblightserver/BoblightClientConnection.cpp index 636cedda..75e61451 100644 --- a/libsrc/boblightserver/BoblightClientConnection.cpp +++ b/libsrc/boblightserver/BoblightClientConnection.cpp @@ -16,7 +16,7 @@ // hyperion util includes #include "hyperion/ImageProcessorFactory.h" #include "hyperion/ImageProcessor.h" -#include "utils/RgbColor.h" +#include "utils/ColorRgb.h" // project includes #include "BoblightClientConnection.h" @@ -29,7 +29,7 @@ BoblightClientConnection::BoblightClientConnection(QTcpSocket *socket, Hyperion _hyperion(hyperion), _receiveBuffer(), _priority(255), - _ledColors(hyperion->getLedCount(), RgbColor::BLACK) + _ledColors(hyperion->getLedCount(), ColorRgb::BLACK) { // initalize the locale. Start with the default C-locale _locale.setNumberOptions(QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator); @@ -149,7 +149,7 @@ void BoblightClientConnection::handleMessage(const QString & message) if (rc1 && rc2 && rc3) { - RgbColor & rgb = _ledColors[ledIndex]; + ColorRgb & rgb = _ledColors[ledIndex]; rgb.red = red; rgb.green = green; rgb.blue = blue; diff --git a/libsrc/boblightserver/BoblightClientConnection.h b/libsrc/boblightserver/BoblightClientConnection.h index 6bdbdac4..ce866469 100644 --- a/libsrc/boblightserver/BoblightClientConnection.h +++ b/libsrc/boblightserver/BoblightClientConnection.h @@ -99,5 +99,5 @@ private: int _priority; /// The latest led color data - std::vector _ledColors; + std::vector _ledColors; }; diff --git a/libsrc/bootsequence/AbstractBootSequence.cpp b/libsrc/bootsequence/AbstractBootSequence.cpp index 585ebb8c..2342eda5 100644 --- a/libsrc/bootsequence/AbstractBootSequence.cpp +++ b/libsrc/bootsequence/AbstractBootSequence.cpp @@ -26,7 +26,7 @@ void AbstractBootSequence::update() } // Obtain the next led-colors from the child-class - const std::vector& colors = nextColors(); + const std::vector& colors = nextColors(); // Write the colors to hyperion _hyperion->setColors(_priority, colors, -1); diff --git a/libsrc/bootsequence/AbstractBootSequence.h b/libsrc/bootsequence/AbstractBootSequence.h index 8ef7e712..224619b9 100644 --- a/libsrc/bootsequence/AbstractBootSequence.h +++ b/libsrc/bootsequence/AbstractBootSequence.h @@ -45,7 +45,7 @@ protected: /// /// @return The next led colors in the boot sequence /// - virtual const std::vector& nextColors() = 0; + virtual const std::vector& nextColors() = 0; private: /// The timer used to generate an 'update' signal every interval diff --git a/libsrc/bootsequence/KittBootSequence.cpp b/libsrc/bootsequence/KittBootSequence.cpp index b40e1e0e..d72e9d31 100644 --- a/libsrc/bootsequence/KittBootSequence.cpp +++ b/libsrc/bootsequence/KittBootSequence.cpp @@ -8,8 +8,8 @@ KittBootSequence::KittBootSequence(Hyperion * hyperion, const unsigned duration_ms) : AbstractBootSequence(hyperion, 100, duration_ms/100), _processor(ImageProcessorFactory::getInstance().newImageProcessor()), - _image(9, 1), - _ledColors(hyperion->getLedCount(), RgbColor::BLACK), + _image(9, 1, ColorRgb{0,0,0}), + _ledColors(hyperion->getLedCount(), ColorRgb{0,0,0}), _forwardMove(false), _currentLight(0) { @@ -21,17 +21,17 @@ KittBootSequence::~KittBootSequence() delete _processor; } -const std::vector& KittBootSequence::nextColors() +const std::vector& KittBootSequence::nextColors() { // Switch the previous light 'off' - _image(_currentLight, 0) = RgbColor::BLACK; + _image(_currentLight, 0) = ColorRgb{0,0,0}; // Move the current to the next light moveNextLight(); // Switch the current light 'on' - _image(_currentLight, 0) = RgbColor::RED; + _image(_currentLight, 0) = ColorRgb{255,0,0}; // Translate the 'image' to led colors diff --git a/libsrc/bootsequence/KittBootSequence.h b/libsrc/bootsequence/KittBootSequence.h index ccd26845..e6aba761 100644 --- a/libsrc/bootsequence/KittBootSequence.h +++ b/libsrc/bootsequence/KittBootSequence.h @@ -33,17 +33,17 @@ public: /// /// @return The next colors for the leds /// - virtual const std::vector& nextColors(); + virtual const std::vector& nextColors(); private: /// Image processor to compute led-colors from the image ImageProcessor * _processor; /// 1D-Image of the KITT-grill contains a single red pixel and the rest black - RgbImage _image; + Image _image; /// The vector with led-colors - std::vector _ledColors; + std::vector _ledColors; /// Direction the red-light is currently moving bool _forwardMove = true; diff --git a/libsrc/bootsequence/RainbowBootSequence.cpp b/libsrc/bootsequence/RainbowBootSequence.cpp index d976b70d..d04a14ab 100644 --- a/libsrc/bootsequence/RainbowBootSequence.cpp +++ b/libsrc/bootsequence/RainbowBootSequence.cpp @@ -11,15 +11,15 @@ RainbowBootSequence::RainbowBootSequence(Hyperion * hyperion, const unsigned dur { for (unsigned iLed=0; iLedgetLedCount(); ++iLed) { - RgbColor& color = _ledColors[iLed]; + ColorRgb& color = _ledColors[iLed]; HsvTransform::hsv2rgb(iLed*360/hyperion->getLedCount(), 255, 255, color.red, color.green, color.blue); } } -const std::vector& RainbowBootSequence::nextColors() +const std::vector& RainbowBootSequence::nextColors() { // Rotate the colors left - const RgbColor headColor = _ledColors.front(); + const ColorRgb headColor = _ledColors.front(); for (unsigned i=1; i<_ledColors.size(); ++i) { _ledColors[i-1] = _ledColors[i]; diff --git a/libsrc/bootsequence/RainbowBootSequence.h b/libsrc/bootsequence/RainbowBootSequence.h index e227febf..8b60a9b6 100644 --- a/libsrc/bootsequence/RainbowBootSequence.h +++ b/libsrc/bootsequence/RainbowBootSequence.h @@ -27,11 +27,11 @@ protected: /// /// Moves the rainbow one led further /// - const std::vector& nextColors(); + const std::vector& nextColors(); private: /// The current color of the boot sequence (the rainbow) - std::vector _ledColors; + std::vector _ledColors; /// The counter of the number of iterations left int _iterationCounter; }; diff --git a/libsrc/dispmanx-grabber/DispmanxFrameGrabber.cpp b/libsrc/dispmanx-grabber/DispmanxFrameGrabber.cpp index 3bdc4bdf..4681e8ff 100644 --- a/libsrc/dispmanx-grabber/DispmanxFrameGrabber.cpp +++ b/libsrc/dispmanx-grabber/DispmanxFrameGrabber.cpp @@ -1,4 +1,9 @@ +// STL includes +#include +#include + +// Local includes #include "DispmanxFrameGrabber.h" DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned height) : @@ -32,7 +37,7 @@ DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned // Create the resources for capturing image uint32_t vc_nativeImageHandle; _vc_resource = vc_dispmanx_resource_create( - VC_IMAGE_RGB888, + VC_IMAGE_RGBA32, width, height, &vc_nativeImageHandle); @@ -56,7 +61,7 @@ void DispmanxFrameGrabber::setFlags(const int vc_flags) _vc_flags = vc_flags; } -void DispmanxFrameGrabber::grabFrame(RgbImage& image) +void DispmanxFrameGrabber::grabFrame(Image & image) { // Sanity check of the given image size assert(image.width() == _width && image.height() == _height); @@ -69,7 +74,7 @@ void DispmanxFrameGrabber::grabFrame(RgbImage& image) // Read the snapshot into the memory void* image_ptr = image.memptr(); - const unsigned destPitch = _width * 3; + const unsigned destPitch = _width * sizeof(ColorRgba); vc_dispmanx_resource_read_data(_vc_resource, &_rectangle, image_ptr, destPitch); // Close the displaye diff --git a/libsrc/dispmanx-grabber/DispmanxFrameGrabber.h b/libsrc/dispmanx-grabber/DispmanxFrameGrabber.h index fee6be91..f7a0b07f 100644 --- a/libsrc/dispmanx-grabber/DispmanxFrameGrabber.h +++ b/libsrc/dispmanx-grabber/DispmanxFrameGrabber.h @@ -8,7 +8,8 @@ #include // Utils includes -#include +#include +#include /// /// The DispmanxFrameGrabber is used for creating snapshots of the display (screenshots) with a @@ -41,7 +42,7 @@ public: /// @param[out] image The snapped screenshot (should be initialized with correct width and /// height) /// - void grabFrame(RgbImage& image); + void grabFrame(Image & image); private: /// Handle to the display that is being captured diff --git a/libsrc/dispmanx-grabber/DispmanxWrapper.cpp b/libsrc/dispmanx-grabber/DispmanxWrapper.cpp index ba4bd1f1..29754b5f 100644 --- a/libsrc/dispmanx-grabber/DispmanxWrapper.cpp +++ b/libsrc/dispmanx-grabber/DispmanxWrapper.cpp @@ -20,7 +20,7 @@ DispmanxWrapper::DispmanxWrapper(const unsigned grabWidth, const unsigned grabHe _image(grabWidth, grabHeight), _frameGrabber(new DispmanxFrameGrabber(grabWidth, grabHeight)), _processor(ImageProcessorFactory::getInstance().newImageProcessor()), - _ledColors(hyperion->getLedCount(), RgbColor::BLACK), + _ledColors(hyperion->getLedCount(), ColorRgb{0,0,0}), _hyperion(hyperion) { // Configure the timer to generate events every n milliseconds diff --git a/libsrc/hyperion/BlackBorderDetector.cpp b/libsrc/hyperion/BlackBorderDetector.cpp index 3fe34c08..e86ba9ed 100644 --- a/libsrc/hyperion/BlackBorderDetector.cpp +++ b/libsrc/hyperion/BlackBorderDetector.cpp @@ -1,6 +1,6 @@ // Local-Hyperion includes -#include "BlackBorderDetector.h" +#include using namespace hyperion; @@ -8,56 +8,3 @@ BlackBorderDetector::BlackBorderDetector() { // empty } - -BlackBorder BlackBorderDetector::process(const RgbImage& image) -{ - // only test the topleft third of the image - int width = image.width() /3; - int height = image.height() / 3; - int maxSize = std::max(width, height); - - int firstNonBlackXPixelIndex = -1; - int firstNonBlackYPixelIndex = -1; - - // find some pixel of the image - for (int i = 0; i < maxSize; ++i) - { - int x = std::min(i, width); - int y = std::min(i, height); - - const RgbColor& color = image(x, y); - if (!isBlack(color)) - { - firstNonBlackXPixelIndex = x; - firstNonBlackYPixelIndex = y; - break; - } - } - - // expand image to the left - for(; firstNonBlackXPixelIndex > 0; --firstNonBlackXPixelIndex) - { - const RgbColor& color = image(firstNonBlackXPixelIndex-1, firstNonBlackYPixelIndex); - if (isBlack(color)) - { - break; - } - } - - // expand image to the top - for(; firstNonBlackYPixelIndex > 0; --firstNonBlackYPixelIndex) - { - const RgbColor& color = image(firstNonBlackXPixelIndex, firstNonBlackYPixelIndex-1); - if (isBlack(color)) - { - break; - } - } - - // Construct result - BlackBorder detectedBorder; - detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1; - detectedBorder.horizontalSize = firstNonBlackYPixelIndex; - detectedBorder.verticalSize = firstNonBlackXPixelIndex; - return detectedBorder; -} diff --git a/libsrc/hyperion/BlackBorderProcessor.cpp b/libsrc/hyperion/BlackBorderProcessor.cpp index 6d355cb7..87ada03f 100644 --- a/libsrc/hyperion/BlackBorderProcessor.cpp +++ b/libsrc/hyperion/BlackBorderProcessor.cpp @@ -1,6 +1,6 @@ // Local-Hyperion includes -#include "BlackBorderProcessor.h" +#include using namespace hyperion; @@ -16,6 +16,7 @@ BlackBorderProcessor::BlackBorderProcessor( _previousDetectedBorder({true, -1, -1}), _consistentCnt(0) { + // empty } BlackBorder BlackBorderProcessor::getCurrentBorder() const @@ -23,46 +24,33 @@ BlackBorder BlackBorderProcessor::getCurrentBorder() const return _currentBorder; } -bool BlackBorderProcessor::process(const RgbImage& image) +bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder) { - // get the border for the single image - BlackBorder imageBorder = _detector.process(image); - - // add blur to the border - if (imageBorder.horizontalSize > 0) - { - imageBorder.horizontalSize += _blurRemoveCnt; - } - if (imageBorder.verticalSize > 0) - { - imageBorder.verticalSize += _blurRemoveCnt; - } - // set the consistency counter - if (imageBorder == _previousDetectedBorder) + if (newDetectedBorder == _previousDetectedBorder) { ++_consistentCnt; } else { - _previousDetectedBorder = imageBorder; + _previousDetectedBorder = newDetectedBorder; _consistentCnt = 0; } // check if there is a change - if (_currentBorder == imageBorder) + if (_currentBorder == newDetectedBorder) { // No change required return false; } bool borderChanged = false; - if (imageBorder.unknown) + if (newDetectedBorder.unknown) { // apply the unknown border if we consistently can't determine a border if (_consistentCnt == _unknownSwitchCnt) { - _currentBorder = imageBorder; + _currentBorder = newDetectedBorder; borderChanged = true; } } @@ -71,21 +59,21 @@ bool BlackBorderProcessor::process(const RgbImage& image) // apply the detected border if it has been detected consistently if (_currentBorder.unknown || _consistentCnt == _borderSwitchCnt) { - _currentBorder = imageBorder; + _currentBorder = newDetectedBorder; borderChanged = true; } else { // apply smaller borders immediately - if (imageBorder.verticalSize < _currentBorder.verticalSize) + if (newDetectedBorder.verticalSize < _currentBorder.verticalSize) { - _currentBorder.verticalSize = imageBorder.verticalSize; + _currentBorder.verticalSize = newDetectedBorder.verticalSize; borderChanged = true; } - if (imageBorder.horizontalSize < _currentBorder.horizontalSize) + if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize) { - _currentBorder.horizontalSize = imageBorder.horizontalSize; + _currentBorder.horizontalSize = newDetectedBorder.horizontalSize; borderChanged = true; } } diff --git a/libsrc/hyperion/CMakeLists.txt b/libsrc/hyperion/CMakeLists.txt index 6b1b424e..6234f33c 100644 --- a/libsrc/hyperion/CMakeLists.txt +++ b/libsrc/hyperion/CMakeLists.txt @@ -13,13 +13,13 @@ SET(Hyperion_QT_HEADERS SET(Hyperion_HEADERS ${CURRENT_HEADER_DIR}/ImageProcessor.h ${CURRENT_HEADER_DIR}/ImageProcessorFactory.h + ${CURRENT_HEADER_DIR}/ImageToLedsMap.h ${CURRENT_HEADER_DIR}/LedDevice.h ${CURRENT_HEADER_DIR}/LedString.h ${CURRENT_HEADER_DIR}/PriorityMuxer.h - ${CURRENT_SOURCE_DIR}/BlackBorderDetector.h - ${CURRENT_SOURCE_DIR}/BlackBorderProcessor.h - ${CURRENT_SOURCE_DIR}/ImageToLedsMap.h + ${CURRENT_HEADER_DIR}/BlackBorderDetector.h + ${CURRENT_HEADER_DIR}/BlackBorderProcessor.h ${CURRENT_SOURCE_DIR}/device/LedSpiDevice.h ${CURRENT_SOURCE_DIR}/device/LedRs232Device.h diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index bd906d2d..67e1fc70 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -1,4 +1,7 @@ +// STL includes +#include + // QT includes #include @@ -249,16 +252,16 @@ unsigned Hyperion::getLedCount() const return _ledString.leds().size(); } -void Hyperion::setColor(int priority, const RgbColor &color, const int timeout_ms) +void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_ms) { // create led output - std::vector ledColors(_ledString.leds().size(), color); + std::vector ledColors(_ledString.leds().size(), color); // set colors setColors(priority, ledColors, timeout_ms); } -void Hyperion::setColors(int priority, const std::vector& ledColors, const int timeout_ms) +void Hyperion::setColors(int priority, const std::vector& ledColors, const int timeout_ms) { if (timeout_ms > 0) { @@ -415,8 +418,8 @@ void Hyperion::update() const PriorityMuxer::InputInfo & priorityInfo = _muxer.getInputInfo(priority); // Apply the transform to each led and color-channel - std::vector ledColors(priorityInfo.ledColors); - for (RgbColor& color : ledColors) + std::vector ledColors(priorityInfo.ledColors); + for (ColorRgb& color : ledColors) { _hsvTransform->transform(color.red, color.green, color.blue); color.red = _redTransform->transform(color.red); diff --git a/libsrc/hyperion/ImageProcessor.cpp b/libsrc/hyperion/ImageProcessor.cpp index 6300c4f0..d3bfba3d 100644 --- a/libsrc/hyperion/ImageProcessor.cpp +++ b/libsrc/hyperion/ImageProcessor.cpp @@ -1,13 +1,11 @@ // Hyperion includes #include +#include +#include #include -// Local-Hyperion includes -#include "BlackBorderProcessor.h" -#include "ImageToLedsMap.h" - using namespace hyperion; ImageProcessor::ImageProcessor(const LedString& ledString, bool enableBlackBorderDetector) : @@ -40,33 +38,6 @@ void ImageProcessor::setSize(const unsigned width, const unsigned height) mImageToLeds = new ImageToLedsMap(width, height, 0, 0, mLedString.leds()); } -std::vector ImageProcessor::process(const RgbImage& image) -{ - // Ensure that the buffer-image is the proper size - setSize(image.width(), image.height()); - - // Check black border detection - verifyBorder(image); - - // Create a result vector and call the 'in place' functionl - std::vector colors = mImageToLeds->getMeanLedColor(image); - - // return the computed colors - return colors; -} - -void ImageProcessor::process(const RgbImage& image, std::vector& ledColors) -{ - // Ensure that the buffer-image is the proper size - setSize(image.width(), image.height()); - - // Check black border detection - verifyBorder(image); - - // Determine the mean-colors of each led (using the existing mapping) - mImageToLeds->getMeanLedColor(image, ledColors); -} - bool ImageProcessor::getScanParameters(size_t led, double &hscanBegin, double &hscanEnd, double &vscanBegin, double &vscanEnd) const { if (led < mLedString.leds().size()) @@ -81,29 +52,3 @@ bool ImageProcessor::getScanParameters(size_t led, double &hscanBegin, double &h return false; } -void ImageProcessor::verifyBorder(const RgbImage& image) -{ - if(_enableBlackBorderRemoval && _borderProcessor->process(image)) - { - std::cout << "BORDER SWITCH REQUIRED!!" << std::endl; - - const BlackBorder border = _borderProcessor->getCurrentBorder(); - - // Clean up the old mapping - delete mImageToLeds; - - if (border.unknown) - { - // Construct a new buffer and mapping - mImageToLeds = new ImageToLedsMap(image.width(), image.height(), 0, 0, mLedString.leds()); - } - else - { - // Construct a new buffer and mapping - mImageToLeds = new ImageToLedsMap(image.width(), image.height(), border.horizontalSize, border.verticalSize, mLedString.leds()); - } - - std::cout << "CURRENT BORDER TYPE: unknown=" << border.unknown << " hor.size=" << border.horizontalSize << " vert.size=" << border.verticalSize << std::endl; - } - -} diff --git a/libsrc/hyperion/ImageToLedsMap.cpp b/libsrc/hyperion/ImageToLedsMap.cpp index 9d9862c7..2db8f8ed 100644 --- a/libsrc/hyperion/ImageToLedsMap.cpp +++ b/libsrc/hyperion/ImageToLedsMap.cpp @@ -1,9 +1,10 @@ // STL includes #include +#include // hyperion includes -#include "ImageToLedsMap.h" +#include using namespace hyperion; @@ -61,52 +62,3 @@ unsigned ImageToLedsMap::height() const { return _height; } - -std::vector ImageToLedsMap::getMeanLedColor(const RgbImage & image) const -{ - std::vector colors(mColorsMap.size(), RgbColor::BLACK); - getMeanLedColor(image, colors); - return colors; -} - -void ImageToLedsMap::getMeanLedColor(const RgbImage & image, std::vector & ledColors) const -{ - // Sanity check for the number of leds - assert(mColorsMap.size() == ledColors.size()); - - // Iterate each led and compute the mean - auto led = ledColors.begin(); - for (auto ledColors = mColorsMap.begin(); ledColors != mColorsMap.end(); ++ledColors, ++led) - { - const RgbColor color = calcMeanColor(image, *ledColors); - *led = color; - } -} - -RgbColor ImageToLedsMap::calcMeanColor(const RgbImage & image, const std::vector & colors) const -{ - if (colors.size() == 0) - { - return RgbColor::BLACK; - } - - // Accumulate the sum of each seperate color channel - uint_fast16_t cummRed = 0; - uint_fast16_t cummGreen = 0; - uint_fast16_t cummBlue = 0; - for (const unsigned colorOffset : colors) - { - const RgbColor& color = image.memptr()[colorOffset]; - cummRed += color.red; - cummGreen += color.green; - cummBlue += color.blue; - } - - // Compute the average of each color channel - const uint8_t avgRed = uint8_t(cummRed/colors.size()); - const uint8_t avgGreen = uint8_t(cummGreen/colors.size()); - const uint8_t avgBlue = uint8_t(cummBlue/colors.size()); - - // Return the computed color - return {avgRed, avgGreen, avgBlue}; -} diff --git a/libsrc/hyperion/LinearColorSmoothing.cpp b/libsrc/hyperion/LinearColorSmoothing.cpp index e484688f..0fe3e208 100644 --- a/libsrc/hyperion/LinearColorSmoothing.cpp +++ b/libsrc/hyperion/LinearColorSmoothing.cpp @@ -22,7 +22,7 @@ LinearColorSmoothing::~LinearColorSmoothing() delete _ledDevice; } -int LinearColorSmoothing::write(const std::vector &ledValues) +int LinearColorSmoothing::write(const std::vector &ledValues) { // received a new target color if (_previousValues.size() == 0) @@ -38,7 +38,7 @@ int LinearColorSmoothing::write(const std::vector &ledValues) else { _targetTime = QDateTime::currentMSecsSinceEpoch() + _settlingTime; - memcpy(_targetValues.data(), ledValues.data(), ledValues.size() * sizeof(RgbColor)); + memcpy(_targetValues.data(), ledValues.data(), ledValues.size() * sizeof(ColorRgb)); } return 0; @@ -66,7 +66,7 @@ void LinearColorSmoothing::updateLeds() if (deltaTime < 0) { - memcpy(_previousValues.data(), _targetValues.data(), _targetValues.size() * sizeof(RgbColor)); + memcpy(_previousValues.data(), _targetValues.data(), _targetValues.size() * sizeof(ColorRgb)); _previousTime = now; _ledDevice->write(_previousValues); @@ -77,8 +77,8 @@ void LinearColorSmoothing::updateLeds() for (size_t i = 0; i < _previousValues.size(); ++i) { - RgbColor & prev = _previousValues[i]; - RgbColor & target = _targetValues[i]; + ColorRgb & prev = _previousValues[i]; + ColorRgb & target = _targetValues[i]; prev.red += k * (target.red - prev.red); prev.green += k * (target.green - prev.green); diff --git a/libsrc/hyperion/LinearColorSmoothing.h b/libsrc/hyperion/LinearColorSmoothing.h index 9380c655..a0b706a0 100644 --- a/libsrc/hyperion/LinearColorSmoothing.h +++ b/libsrc/hyperion/LinearColorSmoothing.h @@ -36,7 +36,7 @@ public: /// @param ledValues The color-value per led /// @return Zero on succes else negative /// - virtual int write(const std::vector &ledValues); + virtual int write(const std::vector &ledValues); /// Switch the leds off virtual int switchOff(); @@ -62,11 +62,11 @@ private: int64_t _targetTime; /// The target led data - std::vector _targetValues; + std::vector _targetValues; /// The timestamp of the previously written led data int64_t _previousTime; /// The previously written led data - std::vector _previousValues; + std::vector _previousValues; }; diff --git a/libsrc/hyperion/PriorityMuxer.cpp b/libsrc/hyperion/PriorityMuxer.cpp index c8aa98a3..06c951f0 100644 --- a/libsrc/hyperion/PriorityMuxer.cpp +++ b/libsrc/hyperion/PriorityMuxer.cpp @@ -13,7 +13,7 @@ PriorityMuxer::PriorityMuxer(int ledCount) : { _lowestPriorityInfo.priority = LOWEST_PRIORITY; _lowestPriorityInfo.timeoutTime_ms = -1; - _lowestPriorityInfo.ledColors = std::vector(ledCount, {0, 0, 0}); + _lowestPriorityInfo.ledColors = std::vector(ledCount, {0, 0, 0}); } PriorityMuxer::~PriorityMuxer() @@ -51,7 +51,7 @@ const PriorityMuxer::InputInfo& PriorityMuxer::getInputInfo(const int priority) return elemIt.value(); } -void PriorityMuxer::setInput(const int priority, const std::vector& ledColors, const int64_t timeoutTime_ms) +void PriorityMuxer::setInput(const int priority, const std::vector& ledColors, const int64_t timeoutTime_ms) { InputInfo& input = _activeInputs[priority]; input.priority = priority; diff --git a/libsrc/hyperion/device/LedDeviceLpd6803.cpp b/libsrc/hyperion/device/LedDeviceLpd6803.cpp index 385c7c34..bf35a291 100644 --- a/libsrc/hyperion/device/LedDeviceLpd6803.cpp +++ b/libsrc/hyperion/device/LedDeviceLpd6803.cpp @@ -17,7 +17,7 @@ LedDeviceLdp6803::LedDeviceLdp6803(const std::string& outputDevice, const unsign // empty } -int LedDeviceLdp6803::write(const std::vector &ledValues) +int LedDeviceLdp6803::write(const std::vector &ledValues) { // Reconfigure if the current connfiguration does not match the required configuration if (4 + 2*ledValues.size() != _ledBuffer.size()) @@ -26,10 +26,10 @@ int LedDeviceLdp6803::write(const std::vector &ledValues) _ledBuffer.resize(4 + 2*ledValues.size(), 0x00); } - // Copy the colors from the RgbColor vector to the Ldp6803 data vector + // Copy the colors from the ColorRgb vector to the Ldp6803 data vector for (unsigned iLed=0; iLed> 1) | (rgb.green >> 6); _ledBuffer[5 + 2 * iLed] = ((rgb.green & 0x38) << 2) | (rgb.blue >> 3); @@ -45,5 +45,5 @@ int LedDeviceLdp6803::write(const std::vector &ledValues) int LedDeviceLdp6803::switchOff() { - return write(std::vector(_ledBuffer.size(), RgbColor::BLACK)); + return write(std::vector(_ledBuffer.size(), ColorRgb{0,0,0})); } diff --git a/libsrc/hyperion/device/LedDeviceLpd6803.h b/libsrc/hyperion/device/LedDeviceLpd6803.h index 096468c2..54302d0e 100644 --- a/libsrc/hyperion/device/LedDeviceLpd6803.h +++ b/libsrc/hyperion/device/LedDeviceLpd6803.h @@ -31,7 +31,7 @@ public: /// @param ledValues The color-value per led /// @return Zero on succes else negative /// - virtual int write(const std::vector &ledValues); + virtual int write(const std::vector &ledValues); /// Switch the leds off virtual int switchOff(); diff --git a/libsrc/hyperion/device/LedDeviceSedu.cpp b/libsrc/hyperion/device/LedDeviceSedu.cpp index 02517624..71ace421 100644 --- a/libsrc/hyperion/device/LedDeviceSedu.cpp +++ b/libsrc/hyperion/device/LedDeviceSedu.cpp @@ -24,13 +24,13 @@ LedDeviceSedu::LedDeviceSedu(const std::string& outputDevice, const unsigned bau // empty } -int LedDeviceSedu::write(const std::vector &ledValues) +int LedDeviceSedu::write(const std::vector &ledValues) { if (_ledBuffer.size() == 0) { std::vector frameSpecs{{0xA0, 96}, {0xA1, 256}, {0xA2, 512}, {0xB0, 768}, {0xB1, 1536}, {0xB2, 3072} }; - const unsigned reqColorChannels = ledValues.size() * sizeof(RgbColor); + const unsigned reqColorChannels = ledValues.size() * sizeof(ColorRgb); for (const FrameSpec& frameSpec : frameSpecs) { @@ -52,7 +52,7 @@ int LedDeviceSedu::write(const std::vector &ledValues) } } - memcpy(_ledBuffer.data()+2, ledValues.data(), ledValues.size() * sizeof(RgbColor)); + memcpy(_ledBuffer.data()+2, ledValues.data(), ledValues.size() * sizeof(ColorRgb)); return writeBytes(_ledBuffer.size(), _ledBuffer.data()); } diff --git a/libsrc/hyperion/device/LedDeviceSedu.h b/libsrc/hyperion/device/LedDeviceSedu.h index 37685f6a..a7f10f65 100644 --- a/libsrc/hyperion/device/LedDeviceSedu.h +++ b/libsrc/hyperion/device/LedDeviceSedu.h @@ -26,7 +26,7 @@ public: /// @param ledValues The color-value per led /// @return Zero on succes else negative /// - virtual int write(const std::vector &ledValues); + virtual int write(const std::vector &ledValues); /// Switch the leds off virtual int switchOff(); diff --git a/libsrc/hyperion/device/LedDeviceTest.cpp b/libsrc/hyperion/device/LedDeviceTest.cpp index c265f2ac..4a616d2e 100644 --- a/libsrc/hyperion/device/LedDeviceTest.cpp +++ b/libsrc/hyperion/device/LedDeviceTest.cpp @@ -13,10 +13,10 @@ LedDeviceTest::~LedDeviceTest() // empty } -int LedDeviceTest::write(const std::vector & ledValues) +int LedDeviceTest::write(const std::vector & ledValues) { _ofs << "["; - for (const RgbColor& color : ledValues) + for (const ColorRgb& color : ledValues) { _ofs << color; } diff --git a/libsrc/hyperion/device/LedDeviceTest.h b/libsrc/hyperion/device/LedDeviceTest.h index 38749daf..dbe84940 100644 --- a/libsrc/hyperion/device/LedDeviceTest.h +++ b/libsrc/hyperion/device/LedDeviceTest.h @@ -30,7 +30,7 @@ public: /// /// @return Zero on success else negative /// - virtual int write(const std::vector & ledValues); + virtual int write(const std::vector & ledValues); /// Switch the leds off virtual int switchOff(); diff --git a/libsrc/hyperion/device/LedDeviceWs2801.cpp b/libsrc/hyperion/device/LedDeviceWs2801.cpp index 05d06119..31bb43cd 100644 --- a/libsrc/hyperion/device/LedDeviceWs2801.cpp +++ b/libsrc/hyperion/device/LedDeviceWs2801.cpp @@ -18,11 +18,11 @@ LedDeviceWs2801::LedDeviceWs2801(const std::string& outputDevice, const unsigned // empty } -int LedDeviceWs2801::write(const std::vector &ledValues) +int LedDeviceWs2801::write(const std::vector &ledValues) { mLedCount = ledValues.size(); - const unsigned dataLen = ledValues.size() * sizeof(RgbColor); + const unsigned dataLen = ledValues.size() * sizeof(ColorRgb); const uint8_t * dataPtr = reinterpret_cast(ledValues.data()); return writeBytes(dataLen, dataPtr); @@ -30,5 +30,5 @@ int LedDeviceWs2801::write(const std::vector &ledValues) int LedDeviceWs2801::switchOff() { - return write(std::vector(mLedCount, RgbColor::BLACK)); + return write(std::vector(mLedCount, ColorRgb{0,0,0})); } diff --git a/libsrc/hyperion/device/LedDeviceWs2801.h b/libsrc/hyperion/device/LedDeviceWs2801.h index 833abe6d..e7ff6998 100644 --- a/libsrc/hyperion/device/LedDeviceWs2801.h +++ b/libsrc/hyperion/device/LedDeviceWs2801.h @@ -27,7 +27,7 @@ public: /// @param ledValues The color-value per led /// @return Zero on succes else negative /// - virtual int write(const std::vector &ledValues); + virtual int write(const std::vector &ledValues); /// Switch the leds off virtual int switchOff(); diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 757eed66..4af1b4dd 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -14,7 +14,7 @@ // hyperion util includes #include "hyperion/ImageProcessorFactory.h" #include "hyperion/ImageProcessor.h" -#include "utils/RgbColor.h" +#include "utils/ColorRgb.h" // project includes #include "JsonClientConnection.h" @@ -111,7 +111,7 @@ void JsonClientConnection::handleColorCommand(const Json::Value &message) // extract parameters int priority = message["priority"].asInt(); int duration = message.get("duration", -1).asInt(); - RgbColor color = {uint8_t(message["color"][0u].asInt()), uint8_t(message["color"][1u].asInt()), uint8_t(message["color"][2u].asInt())}; + ColorRgb color = {uint8_t(message["color"][0u].asInt()), uint8_t(message["color"][1u].asInt()), uint8_t(message["color"][2u].asInt())}; // set output _hyperion->setColor(priority, color, duration); @@ -139,12 +139,12 @@ void JsonClientConnection::handleImageCommand(const Json::Value &message) // set width and height of the image processor _imageProcessor->setSize(width, height); - // create RgbImage - RgbImage image(width, height); + // create ImageRgb + Image image(width, height); memcpy(image.memptr(), data.data(), data.size()); // process the image - std::vector ledColors = _imageProcessor->process(image); + std::vector ledColors = _imageProcessor->process(image); _hyperion->setColors(priority, ledColors, duration); // send reply diff --git a/libsrc/protoserver/ProtoClientConnection.cpp b/libsrc/protoserver/ProtoClientConnection.cpp index f7deb85d..165315f7 100644 --- a/libsrc/protoserver/ProtoClientConnection.cpp +++ b/libsrc/protoserver/ProtoClientConnection.cpp @@ -15,7 +15,7 @@ // hyperion util includes #include "hyperion/ImageProcessorFactory.h" #include "hyperion/ImageProcessor.h" -#include "utils/RgbColor.h" +#include "utils/ColorRgb.h" // project includes #include "ProtoClientConnection.h" @@ -120,7 +120,7 @@ void ProtoClientConnection::handleColorCommand(const proto::ColorRequest &messag // extract parameters int priority = message.priority(); int duration = message.has_duration() ? message.duration() : -1; - RgbColor color; + ColorRgb color; color.red = qRed(message.rgbcolor()); color.green = qGreen(message.rgbcolor()); color.blue = qBlue(message.rgbcolor()); @@ -151,12 +151,12 @@ void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &messag // set width and height of the image processor _imageProcessor->setSize(width, height); - // create RgbImage - RgbImage image(width, height); + // create ImageRgb + Image image(width, height); memcpy(image.memptr(), imageData.c_str(), imageData.size()); // process the image - std::vector ledColors = _imageProcessor->process(image); + std::vector ledColors = _imageProcessor->process(image); _hyperion->setColors(priority, ledColors, duration); // send reply diff --git a/libsrc/protoserver/message.proto b/libsrc/protoserver/message.proto index cd1f087c..ebc7cba2 100644 --- a/libsrc/protoserver/message.proto +++ b/libsrc/protoserver/message.proto @@ -24,7 +24,7 @@ message ColorRequest { required int32 priority = 1; // integer value containing the rgb color (0x00RRGGBB) - required int32 rgbColor = 2; + required int32 RgbColor = 2; // duration of the request (negative results in infinite) optional int32 duration = 3; diff --git a/libsrc/utils/CMakeLists.txt b/libsrc/utils/CMakeLists.txt index 806d0b9f..18dfd98c 100644 --- a/libsrc/utils/CMakeLists.txt +++ b/libsrc/utils/CMakeLists.txt @@ -4,13 +4,16 @@ SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/utils) SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/utils) add_library(hyperion-utils - ${CURRENT_HEADER_DIR}/RgbColor.h - ${CURRENT_HEADER_DIR}/RgbImage.h + ${CURRENT_HEADER_DIR}/ColorArgb.h + ${CURRENT_SOURCE_DIR}/ColorArgb.cpp + ${CURRENT_HEADER_DIR}/ColorRgb.h + ${CURRENT_SOURCE_DIR}/ColorRgb.cpp + ${CURRENT_HEADER_DIR}/ColorRgba.h + ${CURRENT_SOURCE_DIR}/ColorRgba.cpp + ${CURRENT_HEADER_DIR}/Image.h ${CURRENT_HEADER_DIR}/ColorTransform.h ${CURRENT_HEADER_DIR}/HsvTransform.h - ${CURRENT_SOURCE_DIR}/RgbColor.cpp - ${CURRENT_SOURCE_DIR}/RgbImage.cpp ${CURRENT_SOURCE_DIR}/ColorTransform.cpp ${CURRENT_SOURCE_DIR}/HsvTransform.cpp diff --git a/libsrc/utils/ColorArgb.cpp b/libsrc/utils/ColorArgb.cpp new file mode 100644 index 00000000..5a9f0c05 --- /dev/null +++ b/libsrc/utils/ColorArgb.cpp @@ -0,0 +1,10 @@ + +// Utils includes +#include + +ColorArgb ColorArgb::BLACK = { 255, 0, 0, 0 }; +ColorArgb ColorArgb::RED = { 255, 255, 0, 0 }; +ColorArgb ColorArgb::GREEN = { 255, 0, 255, 0 }; +ColorArgb ColorArgb::BLUE = { 255, 0, 0, 255 }; +ColorArgb ColorArgb::YELLOW= { 255, 255, 255, 0 }; +ColorArgb ColorArgb::WHITE = { 255, 255, 255, 255 }; diff --git a/libsrc/utils/ColorRgb.cpp b/libsrc/utils/ColorRgb.cpp new file mode 100644 index 00000000..7e8c8769 --- /dev/null +++ b/libsrc/utils/ColorRgb.cpp @@ -0,0 +1,10 @@ + +// Local includes +#include + +ColorRgb ColorRgb::BLACK = { 0, 0, 0 }; +ColorRgb ColorRgb::RED = { 255, 0, 0 }; +ColorRgb ColorRgb::GREEN = { 0, 255, 0 }; +ColorRgb ColorRgb::BLUE = { 0, 0, 255 }; +ColorRgb ColorRgb::YELLOW= { 255, 255, 0 }; +ColorRgb ColorRgb::WHITE = { 255, 255, 255 }; diff --git a/libsrc/utils/ColorRgba.cpp b/libsrc/utils/ColorRgba.cpp new file mode 100644 index 00000000..a14f1e4c --- /dev/null +++ b/libsrc/utils/ColorRgba.cpp @@ -0,0 +1,10 @@ + +// Utils includes +#include + +ColorRgba ColorRgba::BLACK = { 0, 0, 0, 255 }; +ColorRgba ColorRgba::RED = { 255, 0, 0, 255 }; +ColorRgba ColorRgba::GREEN = { 0, 255, 0, 255 }; +ColorRgba ColorRgba::BLUE = { 0, 0, 255, 255 }; +ColorRgba ColorRgba::YELLOW= { 255, 255, 0, 255 }; +ColorRgba ColorRgba::WHITE = { 255, 255, 255, 255 }; diff --git a/libsrc/utils/RgbColor.cpp b/libsrc/utils/RgbColor.cpp deleted file mode 100644 index c26d3a45..00000000 --- a/libsrc/utils/RgbColor.cpp +++ /dev/null @@ -1,10 +0,0 @@ - -// Local includes -#include - -RgbColor RgbColor::BLACK = { 0, 0, 0 }; -RgbColor RgbColor::RED = { 255, 0, 0 }; -RgbColor RgbColor::GREEN = { 0, 255, 0 }; -RgbColor RgbColor::BLUE = { 0, 0, 255 }; -RgbColor RgbColor::YELLOW= { 255, 255, 0 }; -RgbColor RgbColor::WHITE = { 255, 255, 255 }; diff --git a/libsrc/utils/RgbImage.cpp b/libsrc/utils/RgbImage.cpp deleted file mode 100644 index d79ef0e5..00000000 --- a/libsrc/utils/RgbImage.cpp +++ /dev/null @@ -1,50 +0,0 @@ - -// STL includes -#include -#include - -// hyperion Utils includes -#include - - -RgbImage::RgbImage(const unsigned width, const unsigned height, const RgbColor background) : - _width(width), - _height(height), - mColors(new RgbColor[width*height]) -{ - for (unsigned i=0; i #include // QT includes diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f35f9c94..35f7a65b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,9 +12,9 @@ add_executable(test_configfile target_link_libraries(test_configfile hyperion) -add_executable(test_rgbimage +add_executable(test_ImageRgb TestRgbImage.cpp) -target_link_libraries(test_rgbimage +target_link_libraries(test_ImageRgb hyperion-utils) add_executable(test_colortransform diff --git a/test/TestBlackBorderDetector.cpp b/test/TestBlackBorderDetector.cpp index 63954fc5..8a92cba9 100644 --- a/test/TestBlackBorderDetector.cpp +++ b/test/TestBlackBorderDetector.cpp @@ -3,11 +3,12 @@ #include // Hyperion includes -#include "hyperion/BlackBorderDetector.h" +#include +#include using namespace hyperion; -RgbColor randomColor() +ColorRgb randomColor() { const uint8_t randomRedValue = uint8_t(rand() % (std::numeric_limits::max() + 1)); const uint8_t randomGreenValue = uint8_t(rand() % (std::numeric_limits::max() + 1)); @@ -16,16 +17,16 @@ RgbColor randomColor() return {randomRedValue, randomGreenValue, randomBlueValue}; } -RgbImage createImage(unsigned width, unsigned height, unsigned topBorder, unsigned leftBorder) +Image createImage(unsigned width, unsigned height, unsigned topBorder, unsigned leftBorder) { - RgbImage image(width, height); + Image image(width, height); for (unsigned x=0; x image = createImage(64, 64, 0, 0); BlackBorder border = detector.process(image); if (border.unknown != false && border.horizontalSize != 0 && border.verticalSize != 0) { @@ -62,7 +63,7 @@ int TC_TOP_BORDER() BlackBorderDetector detector; { - RgbImage image = createImage(64, 64, 12, 0); + Image image = createImage(64, 64, 12, 0); BlackBorder border = detector.process(image); if (border.unknown != false && border.horizontalSize != 12 && border.verticalSize != 0) { @@ -81,7 +82,7 @@ int TC_LEFT_BORDER() BlackBorderDetector detector; { - RgbImage image = createImage(64, 64, 0, 12); + Image image = createImage(64, 64, 0, 12); BlackBorder border = detector.process(image); if (border.unknown != false && border.horizontalSize != 0 && border.verticalSize != 12) { @@ -100,7 +101,7 @@ int TC_DUAL_BORDER() BlackBorderDetector detector; { - RgbImage image = createImage(64, 64, 12, 12); + Image image = createImage(64, 64, 12, 12); BlackBorder border = detector.process(image); if (border.unknown != false && border.horizontalSize != 12 && border.verticalSize != 12) { @@ -118,7 +119,7 @@ int TC_UNKNOWN_BORDER() BlackBorderDetector detector; { - RgbImage image = createImage(64, 64, 30, 30); + Image image = createImage(64, 64, 30, 30); BlackBorder border = detector.process(image); if (border.unknown != true) { diff --git a/test/TestBlackBorderProcessor.cpp b/test/TestBlackBorderProcessor.cpp index b8cda172..beb018f0 100644 --- a/test/TestBlackBorderProcessor.cpp +++ b/test/TestBlackBorderProcessor.cpp @@ -1,16 +1,19 @@ // STL includes +#include #include +#include // Utils includes -#include +#include +#include // Local-Hyperion includes #include "hyperion/BlackBorderProcessor.h" using namespace hyperion; -RgbColor randomColor() +ColorRgb randomColor() { const uint8_t randomRedValue = uint8_t(rand() % (std::numeric_limits::max() + 1)); const uint8_t randomGreenValue = uint8_t(rand() % (std::numeric_limits::max() + 1)); @@ -19,16 +22,16 @@ RgbColor randomColor() return {randomRedValue, randomGreenValue, randomBlueValue}; } -RgbImage createImage(unsigned width, unsigned height, unsigned topBorder, unsigned leftBorder) +Image createImage(unsigned width, unsigned height, unsigned topBorder, unsigned leftBorder) { - RgbImage image(width, height); + Image image(width, height); for (unsigned x=0; x noBorderImage = createImage(64, 64, 0, 0); for (unsigned i=0; i<10; ++i) { bool newBorder = processor.process(noBorderImage); @@ -79,7 +82,7 @@ int main() } int borderSize = 12; - RgbImage horzImage = createImage(64, 64, borderSize, 0); + Image horzImage = createImage(64, 64, borderSize, 0); for (unsigned i=0; i vertImage = createImage(64, 64, 0, borderSize); for (unsigned i=0; i +#include #include // Hyperion includes @@ -25,16 +25,16 @@ int main() const LedString ledString = Hyperion::createLedString(config["leds"]); - const RgbColor testColor = {64, 123, 12}; + const ColorRgb testColor = {64, 123, 12}; - RgbImage image(64, 64, testColor); + Image image(64, 64, testColor); ImageToLedsMap map(64, 64, 0, 0, ledString.leds()); - std::vector ledColors(ledString.leds().size()); + std::vector ledColors(ledString.leds().size()); map.getMeanLedColor(image, ledColors); std::cout << "["; - for (const RgbColor & color : ledColors) + for (const ColorRgb & color : ledColors) { std::cout << color; } diff --git a/test/TestRgbImage.cpp b/test/TestRgbImage.cpp index 991cdbf2..374408f5 100644 --- a/test/TestRgbImage.cpp +++ b/test/TestRgbImage.cpp @@ -1,18 +1,22 @@ +// STL includes +#include + // Utils includes -#include +#include +#include int main() { std::cout << "Constructing image" << std::endl; - RgbImage image(64, 64, RgbColor::BLACK); + Image image(64, 64, ColorRgb::BLACK); std::cout << "Writing image" << std::endl; for (unsigned y=0; y<64; ++y) { for (unsigned x=0; x<64; ++x) { - image(x,y) = RgbColor::RED; + image(x,y) = ColorRgb::RED; } } diff --git a/test/TestSpi.cpp b/test/TestSpi.cpp index 008966d1..dd139f80 100644 --- a/test/TestSpi.cpp +++ b/test/TestSpi.cpp @@ -8,28 +8,28 @@ #include // Local includes -#include +#include #include "../libsrc/hyperion/device/LedDeviceWs2801.h" void setColor(char* colorStr) { - RgbColor color = RgbColor::BLACK; + ColorRgb color = ColorRgb::BLACK; std::cout << "Switching all leds to: "; if (strncmp("red", colorStr, 3) == 0) { std::cout << "red"; - color = RgbColor::RED; + color = ColorRgb::RED; } else if (strncmp("green", colorStr, 5) == 0) { std::cout << "green"; - color = RgbColor::GREEN; + color = ColorRgb::GREEN; } else if (strncmp("blue", colorStr, 5) == 0) { std::cout << "blue"; - color = RgbColor::BLUE; + color = ColorRgb::BLUE; } else if (strncmp("cyan", colorStr, 5) == 0) { @@ -42,17 +42,17 @@ void setColor(char* colorStr) else if (strncmp("white", colorStr, 5) == 0) { std::cout << "white"; - color = RgbColor::WHITE; + color = ColorRgb::WHITE; } else if (strncmp("black", colorStr, 5) == 0) { std::cout << "black"; - color = RgbColor::BLACK; + color = ColorRgb::BLACK; } std::cout << std::endl; unsigned ledCnt = 50; - std::vector buff(ledCnt, color); + std::vector buff(ledCnt, color); LedDeviceWs2801 ledDevice("/dev/spidev0.0", 40000); ledDevice.open(); @@ -62,11 +62,11 @@ void setColor(char* colorStr) bool _running = true; void doCircle() { - RgbColor color_1 = RgbColor::RED; - RgbColor color_2 = RgbColor::YELLOW; + ColorRgb color_1 = ColorRgb::RED; + ColorRgb color_2 = ColorRgb::YELLOW; unsigned ledCnt = 50; - std::vector data(ledCnt, RgbColor::BLACK); + std::vector data(ledCnt, ColorRgb::BLACK); LedDeviceWs2801 ledDevice("/dev/spidev0.0", 40000); ledDevice.open(); @@ -84,8 +84,8 @@ void doCircle() while (_running) { - data[curLed_1] = RgbColor::BLACK; - data[curLed_2] = RgbColor::BLACK; + data[curLed_1] = ColorRgb::BLACK; + data[curLed_2] = ColorRgb::BLACK; // Move the current and the next pointer curLed_1 = nextLed_1; @@ -111,8 +111,8 @@ void doCircle() } // Switch the current leds off - data[curLed_1] = RgbColor::BLACK; - data[curLed_2] = RgbColor::BLACK; + data[curLed_1] = ColorRgb::BLACK; + data[curLed_2] = ColorRgb::BLACK; ledDevice.write(data); } @@ -126,9 +126,9 @@ void signal_handler(int signum) int main(int argc, char** argv) { - if (sizeof(RgbColor) != 3) + if (sizeof(ColorRgb) != 3) { - std::cout << "sizeof(RgbColor) = " << sizeof(RgbColor) << std::endl; + std::cout << "sizeof(ColorRgb) = " << sizeof(ColorRgb) << std::endl; return -1; } diff --git a/test/dispmanx2png/dispmanx2png.cpp b/test/dispmanx2png/dispmanx2png.cpp index d7db03d7..e354c681 100644 --- a/test/dispmanx2png/dispmanx2png.cpp +++ b/test/dispmanx2png/dispmanx2png.cpp @@ -22,19 +22,20 @@ int main() signal(SIGINT, signal_handler); DispmanxFrameGrabber frameGrabber(64, 64); + frameGrabber.setFlags(DISPMANX_SNAPSHOT_NO_RGB|DISPMANX_SNAPSHOT_FILL); unsigned iFrame = 0; - QImage qImage(64, 64, QImage::Format_RGB888); - RgbImage rgbImage(64, 64); + QImage qImage(64, 64, QImage::Format_ARGB32); + Image imageRgba(64, 64); while(running) { - frameGrabber.grabFrame(rgbImage); + frameGrabber.grabFrame(imageRgba); for (int iScanline=0; iScanline