Skip to content

feat(harris0r): add Harris shutter effect - #302

Merged
jaromil merged 2 commits into
dyne:masterfrom
namikiri:harris0r
Nov 4, 2026
Merged

jaromil merged 2 commits into
dyne:masterfrom
namikiri:harris0r

Conversation

@namikiri

Copy link
Copy Markdown
Contributor

A Harris shutter effect.

When I was younger, cooler and funnier, I had a phone, Sony Xperia SP. Its camera app had an effect called Harris shutter. When I discovered it, I was so fascinated... so that effect has burnt into my brain and soul.

Finally, exactly the same effect, now on Frei0r.

This implementation supports simple and smooth mode.
The smooth mode looks exactly the same as on that Sony phone, but requires lots of RAM.

Simple mode requires only 8 MB of additional memory for 1080p, but drops framerate by three times (not because of intensive computing but because of simpler shutter implementation) and looks a bit stutter-ish, but may be suitable for some use-cases and resource-limited computer configurations.

Parameter are Delay (a Double clamped to 0..16 internally, 16 is the max history frames that can be used) and Simple (boolean), defines if we useing simple or smooth variant.

The effect uses smooth mode by default.

Unfortunately, this effect cannot be used in multi-threaded processing because it needs frame history while MLT for example processes frames independently.

A demo of Harris shutter effect, smooth mode

harris0r.mp4

@jaromil

jaromil commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Current CI passes. I also ran the filter under ASan/UBSan without finding an immediate memory-bounds violation. A deterministic 8×8 frame sequence reproduced the mapping, channel-order, counter, and alpha defects above.

I request changes before merging, or just confirm what I believe are issues they are intended filter behavior.

1. Medium: Delay does not round-trip

The setter maps normalized values into 1..16, but the getter performs integer division and omits the minimum offset.

For example, setting 0.5 produces an internal delay of 8, but the getter returns 0.0. The inverse mapping should be equivalent to:

*((double*)param) =
    (double)(inst->delay - HARRIS_DELAY_MIN) /
    (HARRIS_DELAY_MAX - HARRIS_DELAY_MIN);

2. Medium: simple mode advances twice after its first frame

The initialization path sets pos = 1, and the common f0r_update() path increments it again.

With delay 1, the second input frame updates channel index 1, skipping index 0. Removing the assignment inside the initialization path would let the common increment advance it once.

3. Medium: RGBA channel handling is endian-dependent and reverses red/blue on little-endian systems

Frei0r defines RGBA8888 by byte positions and explicitly makes it endian-independent. The integer masks here assume a particular byte order.

On common little-endian machines, 0x000000FF selects red rather than blue, while 0x00FF0000 selects blue rather than red. Smooth mode consequently produces current red and oldest blue, contrary to its comments. On big-endian systems, all component selection, including alpha, is incorrect. Processing the buffers as uint8_t RGBA components would be portable.

4. Medium: simple mode freezes alpha at the first frame

Each channel update preserves the remaining bytes from cur_frame, including its original alpha. Unlike smooth mode, current input alpha is never copied.

In a deterministic test, alpha remained 40 while subsequent input alpha values were 130 and 180. An RGB-only effect should normally pass the current alpha through.

5. Low: allocation failures can crash the host

f0r_construct() dereferences calloc() without checking it, while the simple-mode malloc() is also unchecked before memcpy() uses the result.

This is especially relevant because smooth mode can consume hundreds of megabytes and the filter supports switching modes.

@luzpaz

luzpaz commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

@namikiri 👆

namikiri and others added 2 commits November 4, 2026 18:16
A Harris shutter effect.
Supports switching between simple and smooth modes.  Simple mode is less resource-requiring but also less eye-pleasing; smooth one looks great but requires lots of RAM.
Fix normalized Delay reporting and simple-mode frame sequencing. Address RGBA components by byte position and pass current alpha through in both modes.

Check frame-size arithmetic and instance allocation. Retry failed frame-buffer allocations with passthrough output without advancing history, and reset buffers safely on mode changes.

Add frame-sequence, parameter, mode-change, in-place, and allocator-failure regression tests. Verified 185 selected native tests, focused GCC and ASan tests, and the ASan/UBSan contract test.
@jaromil
jaromil merged commit 1e73e33 into dyne:master Nov 4, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants