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

The maximum number of distinct colors? #5

Open
bruce0715 opened this issue Dec 2, 2018 · 3 comments
Open

The maximum number of distinct colors? #5

bruce0715 opened this issue Dec 2, 2018 · 3 comments

Comments

@bruce0715
Copy link

"The maximum number of distinct colors in a GIF is 256 but this image has 4896 colors and can't be encoded properly."

I have printed my ndarray, and all the values in the array are the integers between 0 and 255, I don't understand why it always give me this error? my array shape is [3,128,128,32]. Please help, thanks

@stephkno
Copy link

stephkno commented Jan 2, 2019

Same problem, I'm getting a
RuntimeError: The maximum number of distinct colors in a GIF is 256 but this image has 9212 colors and can't be encoded properly.
when trying to save gif of numpy arrays of size [96, 96, 3].

@tanyaschlusser
Copy link
Owner

tanyaschlusser commented Jan 20, 2019

Hi there! Thank you for your comments. I am sorry I didn't notice these comments until today.
There are two possible issues here:

  1. There are no more than 256 colors per frame, but over the course of the animation there are more than 256 colors total.
  2. There are more than 256 colors per frame.

Option (2) is not allowable for a GIF because the GIF color lookup table for a single image has 256 slots, so even though there are 8 bits for each of R, G, and B (meaning 256 ** 3 possible colors available for a GIF), there can only ever be 256 distinct colors in a single GIF image, or a single frame of an animated GIF.

Option (1) is possible for a GIF, but is not implemented in this library yet: currently this library only uses one lookup table for the entire animated gif, so even though you could theoretically have 256 distinct colors per frame (e.g. {R=0, G=0, B=[0, ..., 255]} for one frame of the animation, and then {R=0, G=[0, ..., 255], B=0} for the next frame) it is not possible in this library.

Please let me know if there is interest in me implementing one lookup table per animation frame; I have not considered it but if lots of people want to I am happy to look into it — or of course would welcome a pull request!

@Eshan-Agarwal
Copy link

@tanyaschlusser Thanks for explanation I am also getting this error

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

4 participants