FastLED 3.9.15
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 1211 of file blur.cpp.hpp.

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

References fl::gfx::blur_detail::alpha_identity(), fl::gfx::CanvasMapped< RGB_T >::at(), blurGaussianImpl(), fl::gfx::blur_detail::compute_pad_size(), fl::span< T, Extent >::data(), FL_BUILTIN_MEMSET, fl::gfx::blur_detail::get_padbuf(), fl::gfx::CanvasMapped< RGB_T >::height, fl::XYMap::isRectangularGrid(), fl::P(), fl::gfx::CanvasMapped< RGB_T >::pixels, fl::gfx::CanvasMapped< RGB_T >::width, fl::x, fl::gfx::CanvasMapped< RGB_T >::xymap, and fl::y.

Referenced by blurGaussian(), and blurGaussian().

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