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

Palette needs to be power of 2 and multiple of 3? #1

Closed
mrdoob opened this issue Jan 21, 2013 · 10 comments
Closed

Palette needs to be power of 2 and multiple of 3? #1

mrdoob opened this issue Jan 21, 2013 · 10 comments

Comments

@mrdoob
Copy link

mrdoob commented Jan 21, 2013

So I thought that this could be handy for easily creating these hypnotic animated gifs that you can find on the internets and I decided to try to export a 3d animation with it.

After figuring out how to get a usable string out of the buffer (thus displaying the example gif on the page) I started to write my own images.

Then I realised that I need to build the palette, then remembering the 256 max colors. After crappily decimating the color values I got my palette down to 77 or so. But now I keep getting these errors:

Invalid code/color length, must be power of 2 and 2 .. 256.
Palette must be a multiple of 3 (RGB components).

I've tried to initialise the array with 256 values but it's not really helping.

https://gist.github.com/4582927

Any ideas?

@deanm
Copy link
Owner

deanm commented Jan 21, 2013

                var palette2 = new Uint8Array( 32 * 3 );

Seems to work fine. From what I saw in my test your palette was 24 colors.

Sorry, I will try to clarify the code up a bit. There is two different aspects.

  1. GIF format enforces a palette of power of 2 (8, 16, 32, 64, etc) number of colors.
  2. omggif takes 3 arrays elements for each color in the palette [r, g, b, r, g, b, ...]. This could (and maybe should / will) be changed to [rgb, rgb, ...].

So for now really what you need is palette.length / 3 to be a power of 2. omggif checks for both of those things.

So what you really want is to pass omggif something like 64*3, 32 * 3, etc, since there are separate elements for RGB.

I just wrote this code today, now that you mention it I will probably change the palettes to be RGB together, it's a bit more convenient when you are writing things out by hand to (0xff78fa vs 0xff, 0x78, 0xfa) and it means less array elements which is probably not a bad thing.

Hope that helps

@deanm deanm closed this as completed Jan 21, 2013
@mrdoob
Copy link
Author

mrdoob commented Jan 21, 2013

Oh damn. I was missing the * 3...

So now it kind of works:
https://gist.github.com/4582927

It shows the top half of the gif fine, the second half gets corrupted.

@deanm
Copy link
Owner

deanm commented Jan 21, 2013

I have a look at it tomorrow, thanks for the code to reproduce

@deanm
Copy link
Owner

deanm commented Jan 21, 2013

I think it should be fixed in 99faac4.

@mrdoob
Copy link
Author

mrdoob commented Jan 21, 2013

Cool! Works fine now :)

@mrdoob
Copy link
Author

mrdoob commented Jan 21, 2013

Some tests:

lines
cube

@deanm
Copy link
Owner

deanm commented Jan 21, 2013

I just spent a few hours optimizing (yesterday I just wrote the naive initial implementation). There is about a 4x performance increase in the LZW compressor. It made the code slightly trickier, so let me know if you see any problems. I will spend a little bit more time looking at optimizations, although I've tried a few and I think I am pretty close to the balance of making the code very ugly for only helping a few percent.

PS: Thanks for the examples! It works! ; )

@mrdoob
Copy link
Author

mrdoob commented Jan 21, 2013

Wow. It's much faster compared to this morning. It's almost realtime now.
http://mrdoob.com/lab/javascript/omggif/

@deanm
Copy link
Owner

deanm commented Jan 21, 2013

I just pushed another improvement of 15%, but it's getting to the manually unrolled/inlined point, so I think I'll call it good for now. Overall it's about 5x yesterday's code.

@mrdoob
Copy link
Author

mrdoob commented Jan 21, 2013

Impressed

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

2 participants