Comments (15)
The quantization algorithm puts multiple entries into the color table for the same color, so then there are different indices for the same color. Because of that, color that should be transparent, has different index than the transparency index.
I wrote a fix, that sets all the pixel indices, that should be transparent to transparency index.
GIFEncoder.js#L337
if (transparent != null) {
transIndex = findClosest(transparent);
var r = colorTab[transIndex*3];
var g = colorTab[transIndex*3+1];
var b = colorTab[transIndex*3+2];
var trans_indices = [];
for (var i=0; i<colorTab.length; i+=3)
{
var index = i / 3;
if (!usedEntry[index]) continue;
if (colorTab[i] == r && colorTab[i+1] == g && colorTab[i+2] == b)
trans_indices.push(index);
}
for (var i=0; i<indexedPixels.length; i++)
if (trans_indices.indexOf(indexedPixels[i]) >= 0)
indexedPixels[i] = transIndex;
}
from jsgif.
Also, to run, line 363 must use floor function here:
var index/int/ = Math.floor(i / 3);
from jsgif.
Note that there are TWO places that need to be changed from:
var index = i / 3;
To
var index = Math.floor(i / 3);
- In the code g-regor posted above
- In the implementation of findClosest
Without these two fixes the wrong color is chosen as the transparency color.
(I discovered this when debugging why 0x000000 worked as a transparency color but 0xFFFFFF did not)
from jsgif.
Like... what kind of number is it expecting for the color? I'm passing 0xFFFFFF
but white isn't transparent... sometimes a random other color is but I can't figure it out.
from jsgif.
Anybody want to hack on https://wiki.mozilla.org/APNG_Specification encoding with me?
from jsgif.
Here is one of the rare frames where transparency (0x00FF00) worked:
Most of the time it doesn't:
from jsgif.
This might be a bug: GIFEncoder.js#L351
for (var i/*int*/ = 0; i < len;) {
var dr/*int*/ = r - (colorTab[i++] & 0xff);
var dg/*int*/ = g - (colorTab[i++] & 0xff);
var db/*int*/ = b - (colorTab[i] & 0xff);
var d/*int*/ = dr * dr + dg * dg + db * db;
var index/*int*/ = i / 3;
if (usedEntry[index] && (d < dmin)) {
dmin = d;
minpos = index;
}
i++;
}
That var index/*int*/ = i / 3;
will be 2/3 the first time. I changed the block to:
for (var i/*int*/ = 0; i < len;) {
var dr/*int*/ = r - (colorTab[i++] & 0xff);
var dg/*int*/ = g - (colorTab[i++] & 0xff);
var db/*int*/ = b - (colorTab[i++] & 0xff);
var d/*int*/ = dr * dr + dg * dg + db * db;
var index/*int*/ = (i / 3) - 1;
if (usedEntry[index] && (d < dmin)) {
dmin = d;
minpos = index;
}
}
With this I'm getting better, but still random results:
from jsgif.
Testing it today... colors were crap at 200x200 and fine at 300x300... maybe has something to do with this. Will look more.
from jsgif.
Thanks @grego87, transparent works now:
There is still a huge difference in the color quality at 200x200 vs 300x300... any leads on that bug?
vs
(here is the meemoo app that I used to make this test)
from jsgif.
Have you tried out https://github.com/deanm/omggif
from jsgif.
It does look a little cleaner but you have to manually set the palette... I might port that part of yours to work with his...
from jsgif.
Hi,
Any idea when the quality depending on the canvas size may get fixed?
from jsgif.
I'm pretty sure the size/color bug #6 is in NeuQuant.js, because I got it working with OMGGIF and they bug is still there. I'm going to start a bounty on Stack Overflow.
from jsgif.
@raducostea This patch should fix the color/size issue: https://github.com/antimatter15/jsgif/pull/8/files
from jsgif.
You can try gifenc
Because my react-native-gifencoder is also some fork of gif.js
But in my react-native-runescape-text I replace react-native-gifencoder
with gifenc
for Fix when one color e.g. '#ff0000' only have 1 or 2 or 3 pixel in one frame, the generated gif pixel will be '#9f0000'; fix some frame not transparent but black; reduce gif size 10x
from jsgif.
Related Issues (20)
- No license information HOT 1
- `addFrame` with `is_imageData=true` makes Chrome hang up HOT 3
- Writing canvas to GIF outputs double speed GIF HOT 1
- License HOT 1
- last frame of addFrame is not added to gif HOT 1
- Data URI generates a black gif HOT 4
- jsapng? can you make convas into animated PNG? HOT 5
- GIF almost empty HOT 4
- Animated Gif comes out black w/ Web Workers HOT 6
- Pixel width black line on left edge of GIF
- Add git tag
- My webcam snapshot is being overlay by the gif ??
- No plugin.xml file
- Color Reproduction Issue HOT 2
- Fixes report HOT 1
- Global color map HOT 2
- Crashes at 300+ Frames HOT 2
- License? HOT 2
- The encoding of the Gif fails depending on the size of the canvas HOT 1
- Background image shown in canvas but not in image output HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsgif.