leeoniya / GIFter.js

<canvas> to GIF recorder
45 stars 3 forks source link

Invalid code/color length thrown on render #7

Open Fauntleroy opened 10 years ago

Fauntleroy commented 10 years ago

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?

leeoniya commented 10 years ago

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.

Fauntleroy commented 10 years ago

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

lukebatchelor commented 8 years ago

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

leeoniya commented 8 years ago

@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/

lukebatchelor commented 8 years ago

@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!

emmanuelulloa commented 7 years ago

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

leeoniya commented 7 years ago

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.

emmanuelulloa commented 7 years ago

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

leeoniya commented 7 years ago

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

emmanuelulloa commented 7 years ago

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

leeoniya commented 7 years ago

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

emmanuelulloa commented 7 years ago

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.

leeoniya commented 7 years ago

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 } }.