Merged
Conversation
Adds `Grain` effect model for per-layer noise on background and image layers, `GrainLayer` for full-canvas grain via `canvas.grain()`, JSON serialization/deserialization, and Pillow-only rendering with optional `seed` for deterministic output. https://claude.ai/code/session_01PFg4VN4EBub4RUFz2aoYtw
Per product decision, grain is only exposed as a per-layer effect via `effects=[Grain(...)]` on background and image layers. The canvas-level `canvas.grain()` builder, `GrainLayer` model, and related tests/snapshot are removed. https://claude.ai/code/session_01PFg4VN4EBub4RUFz2aoYtw
- Extract _GRAIN_BLEND_MODES constant so allowed values live in one place - Replace per-pixel randint loop with rng.randbytes() for seeded path - Use Image.point() lookup table for scaling (avoids Python-level loop) - Make _generate_noise_image a @staticmethod (no self dependency) - Fix alpha handling in _blend_grain: blend only RGB channels to avoid fringing artifacts on semi-transparent images - Short-circuit _blend_grain when opacity == 0.0 - Remove lazy `import os` / `import random` inside method body https://claude.ai/code/session_01PFg4VN4EBub4RUFz2aoYtw
- Add Grain/noise section to README with API table and usage example - Add Grain row to Feature Matrix - Add two Grain gotchas - Mark CLI, Template System, and Noise/Grain Effect as done in SPEC.md https://claude.ai/code/session_01PFg4VN4EBub4RUFz2aoYtw
- api/effects.md: add Grain row to compatibility table + full Grain section - api/background.md: update effects param type and notes link - api/image.md: add Grain to effects list - api/index.md: add Grain to public imports and effects page description - json-schema.md: add Grain effect schema tab + update AI workflow prompt https://claude.ai/code/session_01PFg4VN4EBub4RUFz2aoYtw
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Graineffect model for per-layer noise on background and image layersGrainLayerandcanvas.grain()builder for full-canvas grain overlay"type": "grain"discriminatorseedparameter for deterministic output🔧 API
🧪 Test plan
Graindefaults contract + JSON round-trip (test_background_layers.py)ValidationErrorfor invalidintensityandopacitycanvas.grain()builder defaults + JSON round-trip (test_canvas.py)snapshots/canvas_grain.png)snapshots/grain_effect_on_background.png)https://claude.ai/code/session_01PFg4VN4EBub4RUFz2aoYtw