Skip to content
Snippets Groups Projects
Commit 4b442b7e authored by lmaresz's avatar lmaresz
Browse files

Pixel és Frame osztályok hozzáadva

parent db9cbe9e
No related branches found
No related tags found
No related merge requests found
...@@ -2,39 +2,88 @@ ...@@ -2,39 +2,88 @@
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
#include <cstring> #include <cstring>
#include <vector>
using namespace std;
const uint8_t WIDTH = 40;
const uint8_t HEIGHT = 13;
class Pixel { class Pixel {
public: public:
Pixel(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0) : r(r), g(g), b(b) {} Pixel(uint8_t red = 0, uint8_t green = 0, uint8_t blue = 0);
uint8_t operator[](unsigned index);
private: private:
uint8_t r; uint8_t m_red;
uint8_t g; uint8_t m_green;
uint8_t b; uint8_t m_blue;
}; };
class Frame { class Frame {
private:
uint16_t duration;
Pixel data[HEIGHT][WIDTH];
public: public:
Frame(Pixel data[HEIGHT][WIDTH], uint16_t duration) {}// : data(data), duration(duration) {} Frame(unsigned height = 64, unsigned width = 13);
uint8_t* to_spi_data(); ~Frame();
std::vector<uint16_t> get_raw_data();
void transform();
private:
unsigned m_height;
unsigned m_width;
Pixel** m_data;
std::vector<uint16_t> m_raw_data;
}; };
uint8_t* to_spi_data() { Frame::Frame(unsigned height, unsigned width) : m_height(height), m_width(width)
uint8_t* spi_data = new uint8_t[24*WIDTH*2]; {
for (int x = 0; x < WIDTH; x++) { m_data = new Pixel*[height];
for (int y = 0; y < HEIGHT; y++) { for (int i = 0; i < height; i++) {
0; m_data[i] = new Pixel[width];
}
}
Frame::~Frame()
{
for (int i = 0; i < m_height; i++) {
delete[] m_data[i];
}
delete[] m_data;
}
std::vector<uint16_t> Frame::get_raw_data()
{
return m_raw_data;
}
void Frame::transform()
{
for (int x = 0; x < m_width; x++) {
for (int i = 0; i < 24; i++) {
uint16_t temp_data;
for (int y = 0; y < m_height; y++) {
temp_data += m_data[y][x][i] >> y;
}
m_raw_data.push_back(temp_data);
temp_data = 0;
} }
} }
} }
Pixel::Pixel(uint8_t red, uint8_t green, uint8_t blue) : m_red(red), m_green(green), m_blue(blue)
{
}
uint8_t Pixel::operator[](unsigned index)
{
if (index < 8) {
return m_red >> index;
}
else if (index < 16) {
return m_green >> (index - 8);
}
else if (index < 24) {
return m_blue >> (index - 16);
}
}
using namespace std;
const uint8_t WIDTH = 40;
const uint8_t HEIGHT = 13;
uint16_t dataRed[40*24] = {0}; uint16_t dataRed[40*24] = {0};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment