Skip to content

fix(dither): indexed color mode palette handling - #4

Merged
willibrandon merged 1 commit into
mainfrom
fix/2-dither-transparency
Oct 15, 2025
Merged

fix(dither): indexed color mode palette handling#4
willibrandon merged 1 commit into
mainfrom
fix/2-dither-transparency

Conversation

@willibrandon

Copy link
Copy Markdown
Owner

Fixes #2

Problem

draw_with_dither created transparent pixels in indexed color mode instead of the expected dithering pattern.

Root Cause

The function used app.pixelColor.rgba() to create colors, but in indexed color mode img:drawPixel() expects palette indices (0-255), not pixel color values.

Solution

  • Added findNearestPaletteIndex() helper to find nearest palette color
  • Added color mode detection:
    • Indexed mode: uses palette indices for both dither colors
    • RGB/Grayscale: uses pixel color values (original behavior)

Testing

  • Added tests for both RGB and indexed color modes
  • Both modes now produce correct dithering patterns with no transparent pixels

Fixes #2

DrawWithDither now detects color mode and uses palette indices in indexed mode instead of pixel colors, preventing transparent pixels.
@willibrandon willibrandon self-assigned this Oct 15, 2025
@willibrandon willibrandon added the bug Something isn't working label Oct 15, 2025
@willibrandon
willibrandon merged commit 9465c09 into main Oct 15, 2025
2 checks passed
@willibrandon
willibrandon deleted the fix/2-dither-transparency branch October 15, 2025 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

draw_with_dither creates transparent pixels

1 participant