Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Set C palette to be empty by default#7289

Merged
hugovk merged 3 commits into
python-pillow:mainfrom
radarhere:undefined_palette
Oct 5, 2023
Merged

Set C palette to be empty by default#7289
hugovk merged 3 commits into
python-pillow:mainfrom
radarhere:undefined_palette

Conversation

@radarhere

Copy link
Copy Markdown
Member

Resolves #7288

The image in the issue has indexes that occur outside of the palette. This PR ensures that they are black.

@Yay295

Yay295 commented Jul 17, 2023

Copy link
Copy Markdown
Contributor

This seems inefficient. ImagingPaletteNew already uses calloc to get its data, but then initializes it. It would be faster to just not initialize it in the first place. ImagingPaletteNew isn't used in very many places, so I think the cleaner solution would be to change ImagingPaletteNew to not initialize its values, and create a new function ImagingPaletteNewRamp that first calls ImagingPaletteNew and then initializes the data as ImagingPaletteNew does currently. There's another already existing function ImagingPaletteNewBrowser that does essentially that, but with different starting values.

https://github.com/python-pillow/Pillow/blob/b9451540973ca7915b0ce68e6bbacbed665caec2/src/libImaging/Palette.c#L23C1-L95

@radarhere

Copy link
Copy Markdown
Member Author

Ok, I've pushed a new commit to set the palette to be empty by default.

This is now a C sequel to 4d36fee

@radarhere radarhere changed the title Set undefined palette values to black Set C palette to be empty by default Jul 17, 2023
Comment thread src/libImaging/Palette.c Outdated
@@ -40,10 +40,8 @@ ImagingPaletteNew(const char *mode) {
palette->mode[IMAGING_MODE_LENGTH - 1] = 0;

/* Initialize to ramp */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment is now outdated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok, I've pushed a commit to remove it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect transparency after converting indexed image to RGB

3 participants