GIFter.js icon indicating copy to clipboard operation
GIFter.js copied to clipboard

Invalid code/color length thrown on render

Open takempf opened this issue 11 years ago • 13 comments

Every time I try to create a GIF with this library I'm confronted with the following error thrown by omggif:

Uncaught Invalid code/color length, must be power of 2 and 2 .. 256. omggif.js:40
check_palette_and_num_colors omggif.js:40
GifWriter omggif.js:52
encode gifter.js:48
render gifter.js:72
(anonymous function)

Any idea what's causing this issue?

takempf avatar Jul 08 '14 04:07 takempf

Hey, thanks for the report.

I don't have too much time until this weekend to look into this, but I will say that the README lies. A lot of those features are not in the current repo but are in the big rewrite which is mostly finished and needs cleanup. I'll try to push it public in a few days.

leeoniya avatar Jul 09 '14 07:07 leeoniya

Awesome! I've been looking for a javascript GIF lib that can properly handle frame disposal, and hopefully this is it :+1:

takempf avatar Jul 11 '14 06:07 takempf

Hi @leeoniya, just wondering if had any ideas on this. I see you're busy on other projects, but do you know if this might be an easy fix? I'm getting the same results as above.

I couldn't see any other branches or pr's, so I'm assuming the rewrite might still be local?

If you've got some of the work done and don't mind uploading it, I could even take a look if you like?

Cheers :D

lukebatchelor avatar Jun 22 '16 09:06 lukebatchelor

@lukebatchelor i'll try to get to it this week. I have some stuff working locally but have not touched it in quite some time. The original motivation for this lib was to losslessly record canvas anims because all generic screen cap software would either output enormous Gifs, or compress the colors, or dither or could not scale/crop properly. At some point i discovered the excellent (and new at the time) GifCam [1] which solved all the issues, so my personal need for GIFter diminished significantly.

Where I ended up was that there would be 2 explicit modes: a "sprite" mode and a "scene" mode that would govern how the diff handles pixel transparency and frame disposal settings. I could not think of a good/cheap way to automatically determine which mode to choose based on inter-frame heuristics.

[1] http://blog.bahraniapps.com/gifcam/

leeoniya avatar Jun 27 '16 19:06 leeoniya

@leeoniya no stress. Had to pause my project for now anyway, was lookin at using this or https://github.com/buzzfeed/libgif-js, this just seemed quite focused on what I needed, so no problem either way.

Cheers!

lukebatchelor avatar Jun 28 '16 23:06 lukebatchelor

Did this ever got fixed? I have the same problem: Uncaught Invalid code/color length, must be power of 2 and 2 .. 256

emmanuelulloa avatar Feb 24 '17 22:02 emmanuelulloa

hmm, apparently there's a non-zero number of people actually trying to use this project. that's a good motivator, as far as unpaid, open-source projects go :)

i'll push what i have over this weekend with some examples.

leeoniya avatar Feb 24 '17 22:02 leeoniya

Thank you man! Yours sound like a very promising project encoder. You got me at "Small output".

emmanuelulloa avatar Feb 24 '17 22:02 emmanuelulloa

if i had the time needed to acquire GLSL skills, i think that both RgbQuant and GIFter can be made massively faster. I've been wanting to experiment with [1] and [2].

alas, I dont have too much time these days to work on a million unpaid things :(

[1] https://github.com/regl-project/regl [2] https://github.com/gpujs/gpu.js

leeoniya avatar Feb 24 '17 22:02 leeoniya

If I were nearly 10% as smart as you I would help out. Looking forward to whatever you have though!

emmanuelulloa avatar Feb 24 '17 22:02 emmanuelulloa

pushed some WIP i had laying around and made a demo. disregard the outdated readme usage docs, read the demo [1] instead. there are some TODOs still in the source. i'm open to API changes if anyone wants to help push this lib to better state. i would be surprised if there are no bugs, so let me know if you stumble on one.

[1] https://github.com/leeoniya/GIFter.js/blob/master/demo/index.html

leeoniya avatar Feb 27 '17 08:02 leeoniya

So I think that the original error "Invalid code/color length thrown on render" is due to the fact that my buildPalette() method is creating an array of 257 colors while the examples do not go over the 128. According to the code a palette cannot be greater than 256 colors.

emmanuelulloa avatar Feb 27 '17 19:02 emmanuelulloa

yeah, that's probably the case.

while RgbQuant accepts any # of colors for the target palette, GIFs only support up to 256 per palette.

EDIT it's probably worth mentioning that prior to the last commit RgbQuant was not used at all, so it was likely a bug in the simplistic palette builder. RgbQuant's default cap is 256, but you can change that by passing through var opts = { quantOpts: { colors: 128 } }.

leeoniya avatar Feb 27 '17 19:02 leeoniya