You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: render drop shadow layer effect (takes over #679) - #1069
Takes over #679, whose author has not replied to review. composite() read every drop shadow parameter but never drew the effect, so the shadow disappeared whenever a document was composited from its layers (force=True, ignore_preview=True, or after an edit). This renders it.
The commit keeps omar16100's authorship. It is rebased onto current main and addresses the open review items.
What the original PR does
composite/effects.py: draw_drop_shadow() grows the layer's silhouette by Spread (the drop shadow's Ckmt), blurs it with a gaussian that takes what is left of Size, and casts it away from the light angle. drop_shadow_bbox() sizes the canvas.
composite/composite.py: Compositor._apply_drop_shadows() paints each shadow beneath the layer, before the layer is resolved. It fades with layer opacity but not fill opacity, and "Layer Knocks Out Drop Shadow" cuts it by the layer's own alpha. _effect_reach() adds the shadow's reach to the cull and to a group's content box.
Unreadable or non-finite parameters drop the effect rather than the document.
Fidelity is held against the four fixtures in tests/psd_files that carry a Photoshop-rendered drop shadow (test_drop_shadow.py).
Addresses the two inline findings from the review there:
Unbounded shadow canvas. The canvas is cut to the part that can land in the viewport, and the size is held to Photoshop's 250 px maximum. A forged Blur or Distance no longer allocates a canvas of gigabytes for a shadow that cannot reach the viewport. The cut alone does not bound a huge Blur, which is why the size cap is there too.
Unclamped opacity. Opacity is clamped to 0-100%. A huge finite Opct overflowed float32 into NaN across the document, and 400 or -100 left alpha outside [0, 1]. Non-finite values are still dropped.
The nested-group "resolved once each" test now allows one extra resolve: a box cut to the viewport's reach misses the group cache once at the edge. Cost is still linear in depth.
Limits
Contour and noise are not applied; the blur approximates Photoshop's.
Spread on a very large soft-edged layer is slower.
composite() read every drop shadow parameter but never drew the effect,
so the shadow vanished whenever a document was composited from its
layers. Draw it: the layer's silhouette, grown by spread, blurred and
cast away from the light, painted beneath the layer before the layer is
resolved.
- draw_drop_shadow() and drop_shadow_bbox() in composite/effects.py.
For a drop shadow the Ckmt key is Photoshop's Spread, which grows the
matte before the blur (choke, which shrinks it, is the inner shadow's),
and the blur takes what is left of the size.
- The shadow fades with the layer's opacity but not its fill opacity,
and "layer knocks out drop shadow" cuts it away under the silhouette
it is cast from.
- The silhouette is the layer's alpha before opacity and fill, read on
the shadow's own box; a group's is its contents composited over
nothing.
- The cull and a group's content box include the shadow's reach.
- Painting before the layer is resolved puts the shadow under a
pass-through group's contents, which blend with it.
The blur sigma, 0.45 x size, is fitted against the four fixtures that
carry a drop shadow Photoshop rendered into its preview, and
test_drop_shadow.py holds each to it.
Rebased onto main and extended after review (#679):
- The shadow canvas is cut to the part that can land in the viewport, and
the size is held to Photoshop's 250 px maximum, so a forged Blur or
Distance no longer allocates gigabytes.
- Opacity is clamped to 0-100%; a huge finite value overflowed float32
into NaN across the document.
- Tests follow main: _resolve_source takes clip arguments, and an
unreadable Blur reads as 0 (#789) instead of dropping the shadow.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Adds drop-shadow rendering when PSD documents are composited from layers, taking over #679. Shadows were previously omitted from these renders; contour and noise remain unsupported.
Changes:
Implements shadow spread, blur, offset, color, and opacity handling.
Integrates shadows beneath layers and groups, including effect bounds and cached group alpha.
Adds parameter-validation, compositing, and Photoshop-preview regression tests, plus a changelog entry.
File
Description
tests/psd_tools/composite/test_drop_shadow.py
Adds shadow rendering, edge-case, and fixture-fidelity tests.
src/psd_tools/composite/effects.py
Implements shadow canvas sizing, spread, blur, and offset.
src/psd_tools/composite/composite.py
Integrates shadows into layer and group compositing.
docs/changelog.rst
Documents drop-shadow support and its limitations.
Skip a shadow that paints nothing so it cannot widen a group's shape, use is_group() in _cast_shape, and bring the cull and constant comments in line with what the code does. The changelog entry notes the scipy requirement.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The shadow canvas is checked against max_alloc_bytes before it is allocated, as a stroke canvas is, and an over-budget shadow is dropped. A redrawn shape with its fill off casts no shadow of its own, as it draws no fill.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The new test module can fail with ImportError when optional scipy is unavailable, and its source comment includes unstable measurement history that should be reduced to stable behavior.
This new source comment embeds measured MSE values and historical tuning details. The repository's prose policy asks source comments to keep current, stable behavior and move measurements/history to the PR or assertions; these figures will drift without changing what the test verifies. Please reduce this block to the stable fact that the cases cover the listed fixtures/regions, leaving the actual thresholds in _PREVIEWS.
Four fixtures authored in Photoshop lay one shadow per cell: opacity and
knockout, groups, spread, and blend modes. Each cell must remove at least
20x of the error that rendering without shadows leaves. Known departures
are strict xfails tied to #1075 and #1076.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The module draws shadows, which need the optional composite extra, so it
skips like the other composite tests. The preview comment keeps the stable
reasons and drops the measured figures.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ckdrop
A knockout grid authored in Photoshop shows the shadow surviving under a
layer as (1 - alpha) / (1 - alpha * paint opacity), paint opacity being fill
times layer opacity. The old rule cut by alpha alone, which was right at fill
0 and on hard edges but removed shadow Photoshop keeps under a feathered
layer or a group at full fill. The four knockout xfails in the grid tests
now pass and are removed.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟢 Approval recommended
No active review issues are reported, and the change is supported by comprehensive rendering, robustness, allocation, grouping, viewport, knockout, masking, and fidelity tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Takes over #679, whose author has not replied to review.
composite()read every drop shadow parameter but never drew the effect, so the shadow disappeared whenever a document was composited from its layers (force=True,ignore_preview=True, or after an edit). This renders it.The commit keeps omar16100's authorship. It is rebased onto current
mainand addresses the open review items.What the original PR does
composite/effects.py:draw_drop_shadow()grows the layer's silhouette by Spread (the drop shadow'sCkmt), blurs it with a gaussian that takes what is left of Size, and casts it away from the light angle.drop_shadow_bbox()sizes the canvas.composite/composite.py:Compositor._apply_drop_shadows()paints each shadow beneath the layer, before the layer is resolved. It fades with layer opacity but not fill opacity, and "Layer Knocks Out Drop Shadow" cuts it by the layer's own alpha._effect_reach()adds the shadow's reach to the cull and to a group's content box.tests/psd_filesthat carry a Photoshop-rendered drop shadow (test_drop_shadow.py).Changes in this PR on top of #679
Addresses the two inline findings from the review there:
BlurorDistanceno longer allocates a canvas of gigabytes for a shadow that cannot reach the viewport. The cut alone does not bound a hugeBlur, which is why the size cap is there too.Opctoverflowed float32 into NaN across the document, and 400 or -100 left alpha outside [0, 1]. Non-finite values are still dropped.main. Two tests changed with it:_resolve_sourcenow takes clip arguments, and an unreadableBlurreads as 0 (proposal: give psd_tools.api a typed boundary for descriptor access #789) instead of dropping the shadow.Limits
Checks
Full suite (5081 passed),
ruff check,ruff format --checkandmypypass locally.Supersedes #679.
🤖 Generated with Claude Code