Skip to content

Comments

added CMYK/YCCK support for JPGs#1731

Open
chruffins wants to merge 2 commits intoliballeg:masterfrom
chruffins:cmyk-jpg
Open

added CMYK/YCCK support for JPGs#1731
chruffins wants to merge 2 commits intoliballeg:masterfrom
chruffins:cmyk-jpg

Conversation

@chruffins
Copy link

@chruffins chruffins commented Feb 19, 2026

Addresses #1720 by adding color space conversion for CMYK/YCCK. Also, add automatic color space conversion for other color spaces through libjpeg. Added a CMYK conversion of the Alex logo for testing.

image

Summary by CodeRabbit

  • Bug Fixes
    • Improved JPEG color-space handling to correctly detect and convert CMYK and YCCK images to RGB, preserving accurate colors.
    • Expanded component validation to accept 3- and 4-component JPEGs for broader file compatibility.
    • Enhanced multi-component JPEG processing for more consistent image loading and color accuracy.

@coderabbitai
Copy link

coderabbitai bot commented Feb 19, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Adds CMYK handling to JPEG decompression: after reading the JPEG header the code detects color space, sets output to CMYK for CMYK/YCCK or RGB otherwise, accepts 3 or 4 components, and implements a 4-component CMYK->RGB per-pixel conversion while keeping the existing 3-component RGB path.

Changes

Cohort / File(s) Summary
JPEG CMYK support
addons/image/jpg.c
Detect color space after header read; accept 3 or 4 components; add a dedicated 4-component path that reads 4 bytes/pixel and converts inverted libjpeg CMYK to 3-byte RGB per pixel; retain existing 3-component RGB scanline handling.

Sequence Diagram(s)

sequenceDiagram
    participant JPEG_Header as JPEG Header Reader
    participant Decompress as Decompressor
    participant Bitmap as Destination Bitmap

    JPEG_Header->>Decompress: read_header()
    Decompress->>Decompress: detect_color_space (RGB / CMYK/YCCK)
    alt CMYK (4 components)
        Decompress->>Decompress: allocate 4-byte row buffer
        Decompress->>Decompress: read_scanline_4c()
        Decompress->>Decompress: convert_CMYK_to_RGB_per_pixel()
        Decompress->>Bitmap: write_RGB_row()
    else RGB (3 components)
        Decompress->>Decompress: read_scanline_3c()
        Decompress->>Bitmap: write_RGB_row()
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Four inks tumble, flipped and bright,
CMYK hops into RGB light,
Scanlines stretch, pixels reform,
A rabbit hums through color storm,
My palette grows — what a sight!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'added CMYK/YCCK support for JPGs' directly and clearly describes the main change in the pull request, which adds CMYK and YCCK color space support to JPEG handling.

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

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@addons/image/jpg.c`:
- Line 256: The allocation for data->row using al_malloc(w * 4) lacks a NULL
check; after the call to al_malloc (where data->row is assigned) add a check if
data->row == NULL and handle the failure by performing appropriate cleanup (free
any previously allocated resources), log or propagate an error, and return an
error code or goto the existing error/cleanup label so the subsequent writes to
data->row (currently at the code that writes data->row[x * 4 + ...]) cannot
dereference a NULL pointer.

@SiegeLord
Copy link
Member

Thanks! This looks pretty good, I'll double check it later and we can merge it.

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