eugeneware / eugeneware/gifencoder
Transparency should not fail on neighboring colors
- Dominant language
- JavaScript
- Stars
- 476
- Forks
- 53
- PR merge metrics
- No merged PRs in 30d
Description
I was trying to make a gradient fading to black and also have black represent full transparency. It seems like the color mapping for this gradient scenario would sometimes make findClosest fail to select the correct color index to represent transparency... My proposed fix is to force the transparency color in the original image to ALWAYS map to the transparency color in the colormapped image.
Specifically,
```
// GIFEncoder.js @ analyzePixels
for (var pixelIndex = 0; pixelIndex < nPix; pixelIndex++) {
if (this.image[pixelIndex * 4 + 3] == 0) {
this.indexedPixels[pixelIndex] = this.transIndex;
}
if (
this.image[pixelIndex * 4 ] == ((this.transparent & 0xff0000) >> 16) &&
this.image[pixelIndex * 4 + 1] == ((this.transparent & 0xff00) >> 8) &&
this.image[pixelIndex * 4 + 2] == ((this.transparent & 0xff))
) {
this.indexedPixels[pixelIndex] = this.transIndex;
}
}
```
Maybe this is only useful for me... but figured I'd share my findings.
Contributor guide
Assessment
This issue has not been assessed yet.