FastLED 3.10.8
Loading...
Searching...
No Matches
upscale.h
Go to the documentation of this file.
1
4
5#pragma once
6
7#include "fl/stl/stdint.h"
8
9#include "fl/math/xymap.h"
10#include "fl/stl/noexcept.h"
11
12namespace fl {
13
21void upscaleArbitrary(const CRGB *input, CRGB *output, u16 inputWidth,
22 u16 inputHeight, const fl::XYMap& xyMap) FL_NO_EXCEPT;
23
31void upscalePowerOf2(const CRGB *input, CRGB *output, u8 inputWidth,
32 u8 inputHeight, const fl::XYMap& xyMap) FL_NO_EXCEPT;
33
42void upscaleRectangular(const CRGB *input, CRGB *output, u16 inputWidth,
43 u16 inputHeight, u16 outputWidth, u16 outputHeight) FL_NO_EXCEPT;
44
53void upscaleRectangularPowerOf2(const CRGB *input, CRGB *output, u8 inputWidth,
54 u8 inputHeight, u8 outputWidth, u8 outputHeight) FL_NO_EXCEPT;
55
56//
57inline void upscale(const CRGB *input, CRGB *output, u16 inputWidth,
58 u16 inputHeight, const fl::XYMap& xyMap) FL_NO_EXCEPT {
59 u16 outputWidth = xyMap.getWidth();
60 u16 outputHeight = xyMap.getHeight();
61 const bool wontFit =
62 (outputWidth != xyMap.getWidth() || outputHeight != xyMap.getHeight());
63
64 // Check if we can use the optimized rectangular version
65 const bool isRectangular = (xyMap.getType() == XYMap::kLineByLine);
66
67 if (isRectangular) {
68 // Use optimized rectangular version that bypasses XY mapping
69 if (wontFit || (inputWidth & (inputWidth - 1)) ||
70 (inputHeight & (inputHeight - 1))) {
71 upscaleRectangular(input, output, inputWidth, inputHeight,
72 outputWidth, outputHeight);
73 } else {
74 upscaleRectangularPowerOf2(input, output, inputWidth, inputHeight,
75 outputWidth, outputHeight);
76 }
77 } else {
78 // Use the original XY-mapped versions
79 if (wontFit || (inputWidth & (inputWidth - 1)) ||
80 (inputHeight & (inputHeight - 1))) {
81 upscaleArbitrary(input, output, inputWidth, inputHeight, xyMap);
82 } else {
83 upscalePowerOf2(input, output, inputWidth, inputHeight, xyMap);
84 }
85 }
86}
87
88// These are here for testing purposes and are slow. Their primary use
89// is to test against the fixed integer version above.
90void upscaleFloat(const CRGB *input, CRGB *output, u8 inputWidth,
91 u8 inputHeight, const fl::XYMap& xyMap) FL_NO_EXCEPT;
92
93void upscaleArbitraryFloat(const CRGB *input, CRGB *output, u16 inputWidth,
94 u16 inputHeight, const fl::XYMap& xyMap) FL_NO_EXCEPT;
95
96u8 upscaleFloat(u8 v00, u8 v10, u8 v01,
97 u8 v11, float dx, float dy) FL_NO_EXCEPT;
98
99} // namespace fl
fl::XYMap xyMap
@ kLineByLine
Definition xymap.h:43
fl::CRGB CRGB
Definition crgb.h:25
unsigned char u8
Definition stdint.h:131
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
void upscale(const CRGB *input, CRGB *output, u16 inputWidth, u16 inputHeight, const fl::XYMap &xyMap) FL_NO_EXCEPT
Definition upscale.h:57
void upscaleArbitraryFloat(const CRGB *input, CRGB *output, u16 inputWidth, u16 inputHeight, const XYMap &xyMap) FL_NO_EXCEPT
void upscaleRectangularPowerOf2(const CRGB *input, CRGB *output, u8 inputWidth, u8 inputHeight, u8 outputWidth, u8 outputHeight) FL_NO_EXCEPT
Optimized upscale for rectangular/line-by-line XY maps (power-of-2 version).
void upscaleRectangular(const CRGB *input, CRGB *output, u16 inputWidth, u16 inputHeight, u16 outputWidth, u16 outputHeight) FL_NO_EXCEPT
Optimized upscale for rectangular/line-by-line XY maps.
u8 upscaleFloat(u8 v00, u8 v10, u8 v01, u8 v11, float dx, float dy) FL_NO_EXCEPT
void upscaleArbitrary(const CRGB *input, CRGB *output, u16 inputWidth, u16 inputHeight, const XYMap &xyMap) FL_NO_EXCEPT
Performs bilinear interpolation for upscaling an image.
void upscalePowerOf2(const CRGB *input, CRGB *output, u8 inputWidth, u8 inputHeight, const XYMap &xyMap) FL_NO_EXCEPT
Performs bilinear interpolation for upscaling an image.
Base definition for an LED controller.
#define FL_NO_EXCEPT
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38