Skip to content

Fix select_by_color silently no-opping on GIMP 3.2 - #23

Merged
maorcc merged 1 commit into
maorcc:mainfrom
AnthonyHerman:fix-select-by-color-gimp32
May 29, 2026
Merged

Fix select_by_color silently no-opping on GIMP 3.2#23
maorcc merged 1 commit into
maorcc:mainfrom
AnthonyHerman:fix-select-by-color-gimp32

Conversation

@AnthonyHerman

@AnthonyHerman AnthonyHerman commented May 2, 2026

Copy link
Copy Markdown
Contributor

Summary

select_by_color looks up the PDB procedure gimp-by-color-select, which does not exist on GIMP 3.2 — it was renamed to gimp-image-select-color. The current code guards the call with if proc: and silently falls through to return {"status": "success", ...} when the lookup returns None, so no selection is ever created, but the caller is told the operation succeeded.

This is dangerous because downstream tools assume a selection exists. In particular, fill_selection with fill_type='transparent' calls Gimp.Drawable.edit_clear(drawable), which clears the entire layer when no selection is active. So a typical "remove black background" workflow

add_alpha → select_by_color('#000000') → fill_selection(transparent)

silently wipes the whole image instead of just the BG.

Fix

  • Use the GIMP 3.2 procedure name gimp-image-select-color.
  • Raise RuntimeError when the lookup returns None instead of silently no-opping, so future renames are caught immediately.
  • The new procedure config exposes only image / drawable / color / operation; threshold, antialias, feather, and sample-merged are read from the GIMP context. Set them via Gimp.context_* inside a context_push() / context_pop() pair so we don't leak settings into the rest of the session.

How I hit this

Running an MCP-driven "remove black background, export transparent PNG for a black t-shirt print" pipeline on a JPEG. After select_by_color('#000000', threshold=30) followed by fill_selection(fill_type='transparent'), every pixel ended up with alpha=0 (RGB preserved). Confirmed with pdb.procedure_exists('gimp-by-color-select')False and pdb.procedure_exists('gimp-image-select-color')True on GIMP 3.2.2.

Note on existing test coverage

run_tests.py:92 exercises select_by_color, but only checks that the response status is success. Since the buggy path returns success without doing anything, the test passes against a broken plugin. Worth a follow-up to assert the selection is non-empty (e.g. via Gimp.Selection.is_empty()), but I left test changes out of this PR to keep the diff minimal.

Test plan

  • On GIMP 3.2.2, run select_by_color({'color': '#000000', 'threshold': 30}) on a black-background image and verify the selection bounds are non-empty (Gimp.Selection.bounds(image) returns non_empty=True).
  • Run fill_selection({'fill_type': 'transparent'}) after the select and confirm only the BG pixels go to alpha=0; foreground pixels keep alpha=1.0.
  • ruff check gimp-mcp-plugin.py — clean.
  • Maintainer sanity-check on a non-snap / different-distro GIMP 3.2 build.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved the "Select by Color" tool's internal implementation for better stability and consistency.
    • Enhanced error handling to explicitly fail when the required procedure is unavailable.
    • Refined selection parameter handling with optimized defaults (antialias enabled, feather disabled, integer-based threshold).

@coderabbitai

coderabbitai Bot commented May 2, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e95e52bc-98e7-4df3-acb6-839294957c51

📥 Commits

Reviewing files that changed from the base of the PR and between 1e8ef90 and c14ec61.

📒 Files selected for processing (1)
  • gimp-mcp-plugin.py

Walkthrough

The _select_by_color function is refactored to use the GIMP PDB procedure gimp-image-select-color instead of gimp-by-color-select, with selection parameters moved from config properties to context settings managed via Gimp.context_push()/pop().

Changes

Color Selection API Update

Layer / File(s) Summary
Procedure Call & Error Handling
gimp-mcp-plugin.py (lines 2379–2398)
_select_by_color switches from gimp-by-color-select to gimp-image-select-color with explicit error if the procedure is unavailable.
Context Management
gimp-mcp-plugin.py (lines 2379–2398)
Call is wrapped in Gimp.context_push()/pop() to isolate selection sampling settings (antialias enabled, feather disabled, integer threshold, merged/transparent sampling disabled).
Config Payload
gimp-mcp-plugin.py (lines 2379–2398)
Procedure config is simplified to pass only image, drawable, color, and operation; prior properties (threshold, antialias, feather, feather-radius, sample-merged, sample-transparent) are removed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: addressing the silent no-op behavior of select_by_color on GIMP 3.2 by switching to the correct PDB procedure name.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

The PDB procedure 'gimp-by-color-select' does not exist in GIMP 3.2 —
it was renamed to 'gimp-image-select-color'. The previous code called
pdb.lookup_procedure() which returned None, then guarded the run with
`if proc:` and silently fell through to a successful return. No
selection ever got created, so any subsequent operation that depends
on the selection (notably fill_selection with fill_type='transparent',
which calls Gimp.Drawable.edit_clear) acted on the entire layer.

Switch to the GIMP 3.2 procedure name and raise if the lookup fails so
the failure is surfaced instead of swallowed. The new procedure config
exposes only image/drawable/color/operation; threshold, antialias, and
feather settings are now read from the GIMP context, so set them via
Gimp.context_* inside a context_push/pop pair.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@maorcc
maorcc merged commit 1a74bfb into maorcc:main May 29, 2026
2 checks passed
maorcc added a commit that referenced this pull request May 29, 2026
The existing select_by_color check only asserted response status, so the
pre-#23 bug (procedure lookup miss -> silent no-op returning success) went
undetected. Fill a known color, clear any prior selection, then assert the
selection is non-empty after select_by_color so a silent no-op fails.

Co-authored-by: maor <maor@Maors-MacBook-Pro.local>
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.

2 participants