FastLED 3.9.7
Loading...
Searching...
No Matches
framebuffer.cpp
1
2
3#include <Arduino.h>
4
5
6#include "./framebuffer.h"
7
8#include "./color.h"
9
10FrameBufferBase::FrameBufferBase(Color3i* array, int n_pixels)
11 : color_array_(array), n_color_array_(n_pixels) {}
12
13FrameBufferBase::~FrameBufferBase() {}
14
15void FrameBufferBase::Set(int i, const Color3i& c) {
16 color_array_[i] = c;
17}
18void FrameBufferBase::Set(int i, int length, const Color3i& color) {
19 for (int j = 0; j < length; ++j) {
20 Set(i + j, color);
21 }
22}
23void FrameBufferBase::FillColor(const Color3i& color) {
24 for (int i = 0; i < n_color_array_; ++i) {
25 color_array_[i] = color;
26 }
27}
28void FrameBufferBase::ApplyBlendSubtract(const Color3i& color) {
29 for (int i = 0; i < n_color_array_; ++i) {
30 color_array_[i].Sub(color);
31 }
32}
33void FrameBufferBase::ApplyBlendAdd(const Color3i& color) {
34 for (int i = 0; i < n_color_array_; ++i) {
35 color_array_[i].Add(color);
36 }
37}
38void FrameBufferBase::ApplyBlendMultiply(const Color3i& color) {
39 for (int i = 0; i < n_color_array_; ++i) {
40 color_array_[i].Mul(color);
41 }
42}
43Color3i* FrameBufferBase::GetIterator(int i) {
44 return color_array_ + i;
45}
46// Length in pixels.
47int FrameBufferBase::length() const { return n_color_array_; }
48
49FrameBuffer::FrameBuffer(int n_pixels)
50 : FrameBufferBase(static_cast<Color3i*>(malloc(sizeof(Color3i) * n_pixels)),
51 n_pixels) {
52}
53
54FrameBuffer::~FrameBuffer() {
55 free(color_array_);
56 color_array_ = NULL;
57 n_color_array_ = 0;
58}
Definition color.h:8