-
Notifications
You must be signed in to change notification settings - Fork 0
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
Only use colors from the palette file #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.palette = b"" | ||
while len(self.palette) < 768: | ||
|
||
s = fp.readline() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, GIMP GPL files are not limited to 256 colors - a file with more than 256 colors is a valid resource: althoug indexed images can only use this many colors, the resources in the app can also function as color source for various painting tools and filters, which does not have this limitation.
Reading to the file end makes more sense - and later on we adjust the higher level ImagePalette to deal (or error) with larger palettes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will merge this and add a '.max_colors' class attribute. And also, take in acoount that a valid palette file might have comment lines in its body (I will have to revert to reading the file indefinetelly - and add some other internal state to stop a DoS on a malformed file.
Support saving JPEG comments
Suggestion for python-pillow#6640
As mentioned previously, python-pillow#5552 means that palettes don't need to have 256 colors anymore, so this changes GimpPaletteFile to only use colors from the palette file, removing the default palette.
That also means that
n_colors
is no longer necessary. If the user wants to know how many colors there are,len(palette_file.getpalette()[0]) // 3
can be used.