# \[New Module\] Melatonin Blur

**URL:** <https://forum.juce.com/t/new-module-melatonin-blur/58756>\
**Category:** General JUCE discussion\
**Created:** [November 10, 2023, 12:04pm UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756 "2023-11-10T12:04:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudara](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sudara/32/8071_2.png) [@sudara](https://forum.juce.com/u/sudara)\
**Post date:** [November 10, 2023, 12:04pm UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/1 "2023-11-10T12:04:05Z")

</div>

Happy Friday, here’s a new JUCE module!

I worked hard on this the last few weeks. I wrote and benchmarked a couple dozen Stack Blur and convolution implementations. Need to give up for now 🙂

Hopefully this will encourage others to make modern vector UIs in JUCE. It should let you use as many drop shadows and inner shadows you like without compromising painting performance:

> **[GitHub - sudara/melatonin\_blur: Fast cross-platform CPU blurs and shadows for...](https://github.com/sudara/melatonin_blur)**
>
> Fast cross-platform CPU blurs and shadows for JUCE - sudara/melatonin\_blur

Let me know if you give it a try. I have a few ideas for how the API could be nicer, but would love feedback.

IPP isn’t a hard requirement for Windows: a lot of performance gains come from caching shadows/blurs for future repaints.

Big thanks to @RolandMR for letting me embed Gin for the Windows ARGB case (the one case I wasn’t able to improve upon Stack Blur!)

EDIT: @kunitoki pointed out the main macOS implementation [won’t work on macOS \< 11.0](https://github.com/sudara/melatonin_blur/issues/13), so I’ll get a fallback in there next week. Just not sure how to test that…

---

<div class="post-metadata">

**Author:** ![PeterRoos](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@PeterRoos](https://forum.juce.com/u/PeterRoos)\
**Post date:** [November 10, 2023, 12:30pm UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/2 "2023-11-10T12:30:52Z")

</div>

Thanks for your hard work, much appreciated!

---

<div class="post-metadata">

**Author:** ![bgporter](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/bgporter/32/12710_2.png) [@bgporter](https://forum.juce.com/u/bgporter)\
**Post date:** [November 10, 2023, 1:40pm UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/3 "2023-11-10T13:40:22Z")

</div>

Excellent! Looking forward to checking this out in detail.

---

<div class="post-metadata">

**Author:** ![PluginPenguin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pluginpenguin/32/10203_2.png) [@PluginPenguin](https://forum.juce.com/u/PluginPenguin)\
**Post date:** [November 10, 2023, 3:27pm UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/4 "2023-11-10T15:27:54Z")

</div>

> [@sudara](#):
>
> @kunitoki pointed out the main macOS implementation [won’t work on macOS \< 11.0](https://github.com/sudara/melatonin_blur/issues/13), so I’ll get a fallback in there next week. Just not sure how to test that…

Usually, if you specify an explicit macOS deployment target in your test project using e.g. `-DCMAKE_OSX_DEPLOYMENT_TARGET="10.14"` (or whatever minimal deployment target you are aiming for) you’ll get a compile time warning if you are using an API that is not supported for that macOS version. You can then use e.g.

```auto
if (__builtin_available (macOS 11, *))
{
   // code path for macOS 11 and higher
}
else
{
   // fallback implementation
}

```

I hope I didn’t tell you stuff that you already knew anyway 😉

---

<div class="post-metadata">

**Author:** ![sudara](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sudara/32/8071_2.png) [@sudara](https://forum.juce.com/u/sudara)\
**Post date:** [November 10, 2023, 4:01pm UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/5 "2023-11-10T16:01:30Z")

</div>

Yeah, strange, my main project has CMAKE\_OSX\_DEPLOYMENT\_TARGET set to 10.13, but I’m not seeing a warning!

> [@PluginPenguin](#):
>
> `__builtin_available`

Thanks, that’s useful. Haven’t wrastled much with macOS versions at runtime.

---

<div class="post-metadata">

**Author:** ![PluginPenguin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pluginpenguin/32/10203_2.png) [@PluginPenguin](https://forum.juce.com/u/PluginPenguin)\
**Post date:** [November 10, 2023, 4:24pm UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/6 "2023-11-10T16:24:43Z")

</div>

Glad I could help.

It might be worth inspecting the deployment target of the resulting binary using `otool -l`. I experienced two cases where the expected deployment did not match the actual one, first was not declaring the `CMAKE_OSX_DEPLOYMENT_TARGET` as a cache variable prior to the `project` call, the second one was when a subproject included from the top level CMakeLists also declared a deployment target and silently overwrote the top level target.

---

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [November 10, 2023, 5:20pm UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/7 "2023-11-10T17:20:53Z")

</div>

Congrats for the release, really nice and detailed work there !

---

<div class="post-metadata">

**Author:** ![evanberard](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/evanberard/32/14069_2.png) [@evanberard](https://forum.juce.com/u/evanberard)\
**Post date:** [November 11, 2023, 4:04am UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/8 "2023-11-11T04:04:32Z")

</div>

Amazing work!

---

<div class="post-metadata">

**Author:** ![Fandusss](https://avatars.discourse-cdn.com/v4/letter/f/a4c791/32.png) [@Fandusss](https://forum.juce.com/u/Fandusss)\
**Post date:** [November 11, 2023, 10:56am UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/9 "2023-11-11T10:56:19Z")

</div>

Fantastic work! Juce team, it makes me sad that this person had to suffer through this so that we can have a drop shadow in a gui in 2023.

---

<div class="post-metadata">

**Author:** ![sudara](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sudara/32/8071_2.png) [@sudara](https://forum.juce.com/u/sudara)\
**Post date:** [November 11, 2023, 11:26am UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/10 "2023-11-11T11:26:46Z")

</div>

Thanks for the support everyone. Just a heads up that I’m working on compatibility for older macOS versions now.

@Fandusss I don’t want to turn this thread into a general JUCE discussion, but I have to say that working on this gave me a new level of respect for how just much work goes into building and maintaining a foundational cross-platform framework like JUCE. Not only did I spent weeks auditing, testing and benchmarking available algorithms on multiple platforms, but I had to brush up on image compositing, package for release (still need to get tests in CI) and now there are all sorts of cross-platform and legacy version challenges.

So this one tiny piece of the pie basically took me 2 full time months of dev time. I honestly feel quite grateful that all the _really_ hard stuff in JUCE (compositing, painting, platform and DAW compatibility, parameters, audio APIs) is just handled — we never really see the details of that work or know how much time goes into getting it solid.

Perhaps it’s also ideal for little specialized pockets of things like blurs/shadows and other UI niceties to be open-source third-party modules. The JUCE team is quite small and they have a very large list of actually hard fundamentals that are constantly breaking! For example, I can’t imagine the time investment with something like unicode support (announced with JUCE 7). Based on my recent experience, I’m guessing a solid dev-year or more of work? (Looking forward to my emojis! 😀)

---

<div class="post-metadata">

**Author:** ![anthony-nicholls](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/anthony-nicholls/32/1246_2.png) [@anthony-nicholls](https://forum.juce.com/u/anthony-nicholls)\
**Post date:** [November 11, 2023, 11:30am UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/11 "2023-11-11T11:30:00Z")

</div>

@sudara (and all those that have been contributing to the blur investigations and improvements) this looks really interesting 👏.

@sudara I just went to try and run this and hit issues with it trying to use `vImageSepConvolve_ARGB8888` (and some other similar methods) these appear to be macOS 14.0+ and I’m running 13.5.2. Am I missing something?

---

<div class="post-metadata">

**Author:** ![sudara](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sudara/32/8071_2.png) [@sudara](https://forum.juce.com/u/sudara)\
**Post date:** [November 11, 2023, 11:32am UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/12 "2023-11-11T11:32:42Z")

</div>

Yes, turns out my top picks for macOS ended being [vImage calls that were 14.0+ for ARGB and 11.0+ for single channel](https://github.com/sudara/melatonin_blur/issues/13) — I’m working now on all the fallbacks! I was working in a vacuum getting the implementations running and benchmarking them, completely forgot about things like different versions of operating systems, lol.

---

<div class="post-metadata">

**Author:** ![Fandusss](https://avatars.discourse-cdn.com/v4/letter/f/a4c791/32.png) [@Fandusss](https://forum.juce.com/u/Fandusss)\
**Post date:** [November 11, 2023, 11:35am UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/13 "2023-11-11T11:35:28Z")

</div>

Alright, cool. If you aren’t sad about it I sure have no reason to be. Great work again, I respect the depth you went to here.

---

<div class="post-metadata">

**Author:** ![sudara](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sudara/32/8071_2.png) [@sudara](https://forum.juce.com/u/sudara)\
**Post date:** [November 11, 2023, 11:38am UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/14 "2023-11-11T11:38:42Z")

</div>

❤ I mean, the synth I was working on (that hasn’t been touched in 2 months) is sad, maybe a few of the alpha testers too… 🙂

But I’m very happy to be able to get back to UI iteration that isn’t compromised by performance concerns!

---

<div class="post-metadata">

**Author:** ![anthony-nicholls](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/anthony-nicholls/32/1246_2.png) [@anthony-nicholls](https://forum.juce.com/u/anthony-nicholls)\
**Post date:** [November 11, 2023, 11:42am UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/15 "2023-11-11T11:42:57Z")

</div>

No need to apologise at all, I get it it’s not easy to get this working for all platforms and OS versions!

---

<div class="post-metadata">

**Author:** ![sudara](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sudara/32/8071_2.png) [@sudara](https://forum.juce.com/u/sudara)\
**Post date:** [November 11, 2023, 1:32pm UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/16 "2023-11-11T13:32:45Z")

</div>

Oh also, the blog post about the module made the front page of hacker news yesterday, in case anyone wants to check the comments out there — some interesting implementation ideas (and amazingly nobody was rude/mean this time!)

> **[Implementing Mario's Stack Blur 15 times in C++ (with tests and benchmarks)](https://news.ycombinator.com/item?id=38217721)**
>
> 105 points —
> 36 comments —
> wlll —
> 11:46 AM - 10 Nov 2023

---

<div class="post-metadata">

**Author:** ![TheHim](https://avatars.discourse-cdn.com/v4/letter/t/94ad74/32.png) [@TheHim](https://forum.juce.com/u/TheHim)\
**Post date:** [November 12, 2023, 7:23am UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/17 "2023-11-12T07:23:42Z")

</div>

Awesome, gonna check this out dor sure!!

---

<div class="post-metadata">

**Author:** ![t0m](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/t0m/32/16413_2.png) [@t0m](https://forum.juce.com/u/t0m)\
**Post date:** [November 12, 2023, 11:42am UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/18 "2023-11-12T11:42:51Z")

</div>

> [@sudara](#):
>
> I have to say that working on this gave me a new level of respect for how just much work goes into building and maintaining a foundational cross-platform framework like JUCE

I don’t think we do a very good job of communicating how difficult the problems JUCE faces are, especially for tasks that appear relatively small. From the outside I suspect it often looks like we’re presented with fully-formed ideas or code and then it takes us months to actually implement any changes where we have spent weeks JUCE-ifying things unnecessarily. Having another voice saying it can be much more difficult than you expect is welcome.

I’m sure there are lots of exceptions to the above, please don’t derail this thread with your favourite grievance! I just wanted to thank Sudara for his support.

---

<div class="post-metadata">

**Author:** ![Stevezee](https://avatars.discourse-cdn.com/v4/letter/s/5f9b8f/32.png) [@Stevezee](https://forum.juce.com/u/Stevezee)\
**Post date:** [November 17, 2023, 4:57pm UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/19 "2023-11-17T16:57:52Z")

</div>

Really cool, thanks!

Any clue what could be causing these artifacts on the buttons? It works fine for the elements.

 ![gadfafa](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/3/4/3497d9bf514990b01103a63963ab4b3773003daa.jpeg)

 ![gafafgfdg](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/a/1/a1bda397f714ac84a7296a7ad3f858caee8da292.jpeg)

---

<div class="post-metadata">

**Author:** ![sudara](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sudara/32/8071_2.png) [@sudara](https://forum.juce.com/u/sudara)\
**Post date:** [November 17, 2023, 5:38pm UTC](https://forum.juce.com/t/new-module-melatonin-blur/58756/20 "2023-11-17T17:38:20Z")

</div>

I’ll take a look — are you on Windows using the fallback implementation by any chance (meaning, not using IPP)

[Next page](https://forum.juce.com/t/new-module-melatonin-blur/58756.md?page=2)
