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