FastLED 3.10.8
Loading...
Searching...
No Matches

◆ blurGaussianMappedImpl()

template<int hRadius, int vRadius, typename RGB_T, typename AlphaT>
FL_OPTIMIZE_FUNCTION void fl::gfx::blurGaussianMappedImpl ( CanvasMapped< RGB_T > & canvas,
AlphaT alpha )

Definition at line 1212 of file blur.cpp.hpp.

1212 {
1213 const int w = canvas.width;
1214 const int h = canvas.height;
1215 if (w <= 0 || h <= 0)
1216 return;
1217
1218 // Fast path: rectangular XYMap → delegate to optimized Canvas blur.
1219 if (canvas.xymap->isRectangularGrid()) {
1220 Canvas<RGB_T> rect(canvas.pixels, w, h);
1222 return;
1223 }
1224
1225 // Slow path: non-rectangular XYMap → per-pixel gather/scatter.
1226 using P = blur_detail::pixel_ops<RGB_T>;
1227 using acc_t = fl::conditional_t<sizeof(typename RGB_T::fp) == 1, u16, u32>;
1228
1229 const bool applyAlpha = !(alpha == blur_detail::alpha_identity<AlphaT>());
1230
1231 // Handle no-blur case.
1232 if (hRadius == 0 && vRadius == 0) {
1233 if (applyAlpha) {
1234 for (int y = 0; y < h; ++y) {
1235 for (int x = 0; x < w; ++x) {
1236 RGB_T &p = canvas.at(x, y);
1237 P ops;
1238 p = ops.make(ops.ch(p.r), ops.ch(p.g), ops.ch(p.b), alpha);
1239 }
1240 }
1241 }
1242 return;
1243 }
1244
1245 fl::span<RGB_T> padbuf = blur_detail::get_padbuf<RGB_T>(
1247 RGB_T *pad = padbuf.data();
1248
1249 // ── Horizontal pass: gather row via XYMap, convolve, scatter back ──
1250 if (hRadius > 0) {
1251 FL_BUILTIN_MEMSET(pad, 0, hRadius * sizeof(RGB_T));
1252 FL_BUILTIN_MEMSET(pad + hRadius + w, 0, hRadius * sizeof(RGB_T));
1253
1254 for (int y = 0; y < h; ++y) {
1255 for (int x = 0; x < w; ++x)
1256 pad[hRadius + x] = canvas.at(x, y);
1257
1258 constexpr int shift = 2 * hRadius;
1259 for (int x = 0; x < w; ++x) {
1260 acc_t r, g, b;
1262 RGB_T result;
1263 if (vRadius == 0 && applyAlpha)
1264 result = P().make(static_cast<acc_t>(r >> shift),
1265 static_cast<acc_t>(g >> shift),
1266 static_cast<acc_t>(b >> shift), alpha);
1267 else
1268 result = P().make(static_cast<acc_t>(r >> shift),
1269 static_cast<acc_t>(g >> shift),
1270 static_cast<acc_t>(b >> shift));
1271 canvas.at(x, y) = result;
1272 }
1273 }
1274 }
1275
1276 // ── Vertical pass: gather column via XYMap, convolve, scatter back ──
1277 if (vRadius > 0) {
1278 FL_BUILTIN_MEMSET(pad, 0, vRadius * sizeof(RGB_T));
1279 FL_BUILTIN_MEMSET(pad + vRadius + h, 0, vRadius * sizeof(RGB_T));
1280
1281 for (int x = 0; x < w; ++x) {
1282 for (int y = 0; y < h; ++y)
1283 pad[vRadius + y] = canvas.at(x, y);
1284
1285 constexpr int shift = 2 * vRadius;
1286 for (int y = 0; y < h; ++y) {
1287 acc_t r, g, b;
1289 RGB_T result;
1290 if (applyAlpha)
1291 result = P().make(static_cast<acc_t>(r >> shift),
1292 static_cast<acc_t>(g >> shift),
1293 static_cast<acc_t>(b >> shift), alpha);
1294 else
1295 result = P().make(static_cast<acc_t>(r >> shift),
1296 static_cast<acc_t>(g >> shift),
1297 static_cast<acc_t>(b >> shift));
1298 canvas.at(x, y) = result;
1299 }
1300 }
1301 }
1302}
bool isRectangularGrid() const FL_NO_EXCEPT
Definition xymap.h:114
const T * data() const FL_NO_EXCEPT
Definition span.h:486
#define FL_BUILTIN_MEMSET(dest, val, n)
static fl::span< RGB_T > get_padbuf(int minSize) FL_NO_EXCEPT
Definition blur.cpp.hpp:350
static int compute_pad_size(int w, int h) FL_NO_EXCEPT
constexpr AlphaT alpha_identity() FL_NO_EXCEPT
FL_OPTIMIZE_FUNCTION void blurGaussianImpl(Canvas< RGB_T > &canvas, AlphaT alpha) FL_NO_EXCEPT
typename conditional< B, T, F >::type conditional_t
FASTLED_FORCE_INLINE fl::u8 P(fl::u8 x) FL_NO_EXCEPT
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
InputGamut g
Definition rgbw.h:125
Simple rectangular canvas for graphics operations Combines a pixel buffer with dimensions for cache-o...
Definition canvas.h:66
const XYMap * xymap
Definition canvas.h:132
RGB_T & at(int x, int y) FL_NO_EXCEPT
Definition canvas.h:141
fl::span< RGB_T > pixels
Definition canvas.h:131

References fl::gfx::blur_detail::alpha_identity(), blurGaussianImpl(), fl::gfx::blur_detail::compute_pad_size(), fl::span< T, Extent >::data(), FL_BUILTIN_MEMSET, fl::FL_NO_EXCEPT, fl::g, fl::gfx::blur_detail::get_padbuf(), fl::P(), fl::x, and fl::y.

Referenced by blurGaussian(), and blurGaussian().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: