8000 desaturate: succeed on grayscale layers, explain indexed ones (#162) by tomerkon · Pull Request #192 · gimp-mcp/gimp-mcp · GitHub
[go: up one dir, main page]

Skip to content

desaturate: succeed on grayscale layers, explain indexed ones (#162) - #192

Merged
tomerkon merged 1 commit into
mainfrom
fix-162-desaturate-gray-indexed
Dec 3, 2026
Merged

tomerkon merged 1 commit into
mainfrom
fix-162-desaturate-gray-indexed

Conversation

@tomerkon
@tomerkon tomerkon commented Dec 3, 2026 •
Copy link
Copy Markdown
Collaborator

Fixes #162.

Problem

desaturate on a GRAY or INDEXED image failed with gimp-drawable-desaturate failed (execution-error), and the image was marked as changed. GIMP's gimp-drawable-desaturate only takes RGB layers; the tool called it inside its undo group, so the failure came after the group had dirtied the image, and the message didn't say why.

Change

_desaturate checks the layer before opening the undo group (after the mode check, so a typo is still an error):

  • GRAY: the layer is already gray, so it returns success and leaves the image alone (not marked as changed).
  • INDEXED: an error, layer 'X' is indexed; desaturate needs an RGB image, convert it first (convert_color_mode RGB), as adjust_curves already does for indexed layers.

The tool's description says both. CHANGELOG entry under [Unreleased] / Fixed. No result or parameter changes, so a patch-level fix.

Tests

  • tests/test_desaturate_modes_live.py (new): an RGB layer is still desaturated; a GRAY layer succeeds with pixels and dirty flag unchanged; a bad mode on a GRAY layer is still an error; an INDEXED layer gives the convert-to-RGB error and changes nothing. Fails with main's plugin (the GRAY case, with the issue's execution-error), passes with this one, on GIMP 3.2 (snap).
  • tests/test_pdb_status.py: its fake layer gains is_gray()/is_indexed() (an RGB layer), moved up from the curves-only fake, so the offline desaturate checks reach the PDB call.
  • test_locked_pixels_live.py and test_unknown_options_live.py (which also call desaturate) still pass live; uvx ruff@0.15.11 check and all offline tests pass. CodeRabbit CLI review: no findings.

Summary by CodeRabbit

  • Bug Fixes
    • Desaturation now succeeds on grayscale layers without changing their pixels or marking the image as changed.
    • Indexed images now receive a clear error when desaturation is attempted; convert the image to RGB first.
    • RGB images continue to be desaturated as expected.
  • Documentation
    • Clarified how desaturation behaves for RGB, grayscale, and indexed images.

gimp-drawable-desaturate only takes RGB layers, so desaturate failed on a
GRAY or INDEXED image with a bare "execution-error", after its undo group
had marked the image changed. Check the layer before the undo group: a
grayscale layer is already gray, so return success and leave it alone; an
indexed one is an error that says to convert the image to RGB first.
@github-actions github-actions Bot added the bug Something isn't working label Dec 3, 2026
@coderabbitai
coderabbitai Bot commented Dec 3, 2026 •
Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The desaturate tool now succeeds without changing grayscale drawables and rejects indexed drawables before opening an undo group. Live tests cover these cases and RGB desaturation. The tool documentation and changelog describe the behavior.

Changes

Desaturate mode handling

Layer / File(s) Summary
Handle drawable modes and verify results
gimp-mcp-plugin.py, tests/test_pdb_status.py, tests/test_desaturate_modes_live.py, gimp 8000 _mcp_server.py, CHANGELOG.md
The plugin handles grayscale and indexed drawables before the existing desaturation flow. Live tests verify RGB, grayscale, and indexed behavior, including image state. The documentation and changelog describe the outcomes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested labels: bug

Suggested reviewers: iyuzhang

Merge Risk: Minimal · up to 36fa0

The desaturate tool now succeeds without changes on grayscale layers and gives a clear convert-to-RGB error for indexed ones, instead of failing after marking the image changed. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main behavior change: GRAY layers succeed without changes, and INDEXED layers return an explanatory error. It matches the changeset in gimp-mcp-plugin.py, gimp_mcp_server.py, the c…
Linked Issues check Passed Directly linked issue #162 is open, so its coding requirements apply. The issue asks for three things: (1) GRAY or INDEXED input must not fail after marking the image changed; (2) the caller gets a cl…
Out of Scope Changes check Passed All changed areas connect to #162. gimp-mcp-plugin.py: the _desaturate guard for GRAY and INDEXED. gimp_mcp_server.py: tool description text only, with no logic change. CHANGELOG.md: a Fixed entry und…
Full details: Title check

Explanation

The title names the main behavior change: GRAY layers succeed without changes, and INDEXED layers return an explanatory error. It matches the changeset in gimp-mcp-plugin.py, gimp_mcp_server.py, the changelog, and the new live test. The title also cites issue #162, which the objectives link to this work.

Full details: Linked Issues check

Explanation

Directly linked issue #162 is open, so its coding requirements apply. The issue asks for three things: (1) GRAY or INDEXED input must not fail after marking the image changed; (2) the caller gets a clear outcome, either a clear error or success without changes for GRAY; (3) live tests cover both modes. The change summary for gimp-mcp-plugin.py states that _desaturate returns success without calling the desaturation procedure for grayscale drawables, and rejects indexed drawables with an error before opening the undo group. The PR description gives the exact INDEXED error text, which follows the 'Possible fix' wording in #162. tests/test_desaturate_modes_live.py covers RGB, GRAY (success, pixels and dirty flag unchanged), invalid mode on GRAY, and INDEXED (error, no state change). The tool description and CHANGELOG are updated. [#162] Limitation: I could not read the _desaturate diff, because the changed blobs were unavailable in the checkout. The check of the mode-before-layer order and the exact code rests on the change summary and PR description, not on a source read. The summary is consistent with both.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to #162. gimp-mcp-plugin.py: the _desaturate guard for GRAY and INDEXED. gimp_mcp_server.py: tool description text only, with no logic change. CHANGELOG.md: a Fixed entry under [Unreleased] for this bug. tests/test_desaturate_modes_live.py: new live tests for the issue's required cases. tests/test_pdb_status.py: FakeLayer gains is_gray() and is_indexed() so the offline desaturate checks reach the PDB call; this supports the change. The PR objectives also mention no changes to other adjustment tools, and the summary shows none. No unrelated change was found in the summary. Source-level confirmation of the plugin diff was not possible (see linked issue assessment).

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4e19ed2 and 36fa045.

Files selected for processing: 5

  • CHANGELOG.md
  • gimp-mcp-plugin.py
  • gimp_mcp_server.py
  • tests/test_desaturate_modes_live.py
  • tests/test_pdb_status.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@tomerkon
tomerkon merged commit 5d38397 into main Dec 3, 2026
6 checks passed
@tomerkon
tomerkon deleted the fix-162-desaturate-gray-indexed branch December 3, 2026 16:16
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.

desaturate on a grayscale or indexed image fails with "execution-error" after marking the image as changed

1 participant

0