Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCX format issue (incorrect palette) #210

Closed
Paril opened this issue May 11, 2024 · 3 comments
Closed

PCX format issue (incorrect palette) #210

Paril opened this issue May 11, 2024 · 3 comments

Comments

@Paril
Copy link

Paril commented May 11, 2024

Hey there.

This is a bit of an odd one, but the PCX plugin is incorrectly handling certain malformed PCXes. Essentially, there's a bit of a weirdness with the spec, because even if you specify the palette to be grayscale (the 16-bit palette type is "2"), the palette at the end of the file is still an RGB palette. Currently, SAIL is incorrectly handling this combination of parameters (8-bit image but marked as 'grayscale'), and interpreting the image to be shades of red.

From looking at other places that implement PCX, it seems like palette 1 and 2 are functionally identical (at least in the case of 8bpp): the only difference is that, for palette 2, the palette is usually grayscale colors, but in the wild this isn't always the case (see Quake II, which uses PCX for its images and has an RGB palette at the end of each PCX). I can provide a test file if necessary.

GIMP's implementation: https://github.com/GNOME/gimp/blob/1b29e77c17407adab208e1718525b8eba0baabac/plug-ins/common/file-pcx.c#L815

The bug is on this line: https://github.com/HappySeaFox/sail/blob/master/src/sail-codecs/pcx/helpers.c#L70 in both cases, the pixel format should be SAIL_PIXEL_FORMAT_BPP8_INDEXED and should be processed by pcx_private_build_palette (note that currently, BPP8_GRAYSCALE isn't even handled by that function even though it should be the same code). In theory, though, one could process the palette and then mark it as grayscale if the palette is actually grayscale but I don't know if that's premature or not.

@HappySeaFox
Copy link
Owner

Hi! Yes, please attach a test file.

@Paril
Copy link
Author

Paril commented May 11, 2024

skin.zip
Attached a simple gradient PCX.

@HappySeaFox
Copy link
Owner

Please try f3f8291

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

No branches or pull requests

2 participants