ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
VerticalBlur.cpp
Go to the documentation of this file.
1#include "VerticalBlur.h"
2
3VerticalBlur::VerticalBlur(uint8_t pixels) : pixels(pixels) {}
4
6 RGBColor* pixelColors = pixelGroup->GetColors();
7 RGBColor* colorBuffer = pixelGroup->GetColorBuffer();
8
9 for (uint16_t i = 0; i < pixelGroup->GetPixelCount(); i++) {
10 uint16_t indexUp = i;
11 uint16_t indexDown = i;
12 uint16_t tIndexUp = 0;
13 uint16_t tIndexDown = 0;
14 bool validL = false;
15 bool validR = false;
16
17 uint16_t blurRange = uint16_t(Mathematics::Map(ratio, 0.0f, 1.0f, 1.0f, float(pixels / 2)));
18
19 uint16_t R, G, B;
20
21 R = (uint16_t)pixelColors[i].R;
22 G = (uint16_t)pixelColors[i].G;
23 B = (uint16_t)pixelColors[i].B;
24
25 for (uint8_t j = 1; j < blurRange + 1; j++) {
26 validL = pixelGroup->GetUpIndex(indexUp, &tIndexUp);
27 validR = pixelGroup->GetDownIndex(indexDown, &tIndexDown);
28
29 indexUp = tIndexUp;
30 indexDown = tIndexDown;
31
32 if (validL && validR) {
33 R = R + (uint16_t)pixelColors[indexUp].R + (uint16_t)pixelColors[indexDown].R;
34 G = G + (uint16_t)pixelColors[indexUp].G + (uint16_t)pixelColors[indexDown].G;
35 B = B + (uint16_t)pixelColors[indexUp].B + (uint16_t)pixelColors[indexDown].B;
36 }
37 }
38
39 colorBuffer[i].R = Mathematics::Constrain(R / (blurRange * 2), 0, 255);
40 colorBuffer[i].B = Mathematics::Constrain(G / (blurRange * 2), 0, 255);
41 colorBuffer[i].G = Mathematics::Constrain(B / (blurRange * 2), 0, 255);
42 }
43
44 for (uint16_t i = 0; i < pixelGroup->GetPixelCount(); i++) {
45 pixelColors[i].R = colorBuffer[i].R;
46 pixelColors[i].G = colorBuffer[i].G;
47 pixelColors[i].B = colorBuffer[i].B;
48 }
49}
Defines the VerticalBlur effect class for applying a vertical blur effect.
float ratio
A scaling ratio used for dynamic effect adjustments.
Definition Effect.h:28
Interface for managing and interacting with a collection of pixels.
Definition IPixelGroup.h:25
virtual RGBColor * GetColors()=0
Retrieves the array of colors for the pixel group.
virtual RGBColor * GetColorBuffer()=0
Retrieves the color buffer for the pixel group.
virtual uint16_t GetPixelCount()=0
Retrieves the total number of pixels in the group.
virtual bool GetUpIndex(uint16_t count, uint16_t *upIndex)=0
Retrieves the index of the pixel above a given pixel.
virtual bool GetDownIndex(uint16_t count, uint16_t *downIndex)=0
Retrieves the index of the pixel below a given pixel.
static T Map(T value, T inLow, T inMax, T outMin, T outMax)
Maps a value from one range to another.
static T Constrain(T value, T minimum, T maximum)
Constrains a value between minimum and maximum.
Represents an RGB color and provides methods for manipulation.
Definition RGBColor.h:23
uint8_t B
Blue component of the color (0-255).
Definition RGBColor.h:27
uint8_t G
Green component of the color (0-255).
Definition RGBColor.h:26
uint8_t R
Red component of the color (0-255).
Definition RGBColor.h:25
VerticalBlur(uint8_t pixels)
Constructs a VerticalBlur effect instance.
void ApplyEffect(IPixelGroup *pixelGroup) override
Applies the vertical blur effect to the given pixel group.
const uint8_t pixels
Number of pixels to include in the vertical blur radius.