Fixed memory overwrite bug. This fixes the png writer and led control.

This commit is contained in:
T. van der Zwan
2013-08-03 23:24:22 +02:00
parent 240218a6bd
commit cbbb1d740b
11 changed files with 167 additions and 166 deletions

View File

@@ -2,42 +2,44 @@
// STL includes
#include <iostream>
// Boblight includes
#include <boblight.h>
// HyperionPNG includes
#include <hyperionpng/HyperionPng.h>
template <typename Hyperion_T>
void process(Hyperion_T& hyperion)
{
hyperion.setInputSize(64, 64);
// Obtain reference to buffer
RgbImage& image = hyperion.image();
// Write some data to the image
std::cout << "Write data to buffer-image" << std::endl;
for (unsigned y=0; y<image.height(); ++y)
{
for (unsigned x=0; x<image.width(); ++x)
{
const RgbColor color = {255, 0, 0};
image(x,y) = color;
}
}
std::cout << "Commit image to write png" << std::endl;
for (unsigned i=0; i<40; ++i)
{
// Commit the image (writing first png)
hyperion.commit();
}
std::cout << "FINISHED" << std::endl;
}
int main()
{
std::cout << "Initialisaing Boblight" << std::endl;
void* blPng = boblight_init();
// Construct instance of Hyperion-PNG
std::cout << "Initialisaing Hyperion PNG" << std::endl;
HyperionPng hyperion;
int width = 112;
int height = 64;
std::cout << "Defining scan range (" << width << "x" << height << ")" << std::endl;
boblight_setscanrange(blPng, width, height);
int colorPtr[3];
colorPtr[0] = 255;
colorPtr[1] = 0;
colorPtr[2] = 0;
std::cout << "Using color [" << colorPtr[0] << "; " << colorPtr[1] << "; " << colorPtr[2] << "]" << std::endl;
int nrOfFrames = 150;
std::cout << "Generating " << nrOfFrames << " frames" << std::endl;
for (int iFrame=0; iFrame<nrOfFrames; ++iFrame)
{
for (int iWidth=0; iWidth<width; ++iWidth)
{
for (int iHeight=0; iHeight<height; ++iHeight)
{
boblight_addpixelxy(blPng, iWidth, iHeight, colorPtr);
}
}
boblight_sendrgb(blPng, 0, NULL);
}
std::cout << "Destroying Boblight" << std::endl;
boblight_destroy(blPng);
process(hyperion);
return 0;
}