Only use colors from the palette file#1
Conversation
| self.palette = b"" | ||
| while len(self.palette) < 768: | ||
|
|
||
| s = fp.readline() |
There was a problem hiding this comment.
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.
jsbueno
left a comment
There was a problem hiding this comment.
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_colorsis no longer necessary. If the user wants to know how many colors there are,len(palette_file.getpalette()[0]) // 3can be used.