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

Transparency should not fail on neighboring colors #18

Open
arikwex opened this issue Dec 21, 2017 · 1 comment
Open

Transparency should not fail on neighboring colors #18

arikwex opened this issue Dec 21, 2017 · 1 comment

Comments

@arikwex
Copy link

arikwex commented Dec 21, 2017

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.

@kurnal
Copy link

kurnal commented May 7, 2020

what's this.transparent?

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