Git Product home page Git Product logo

Comments (7)

Krasjet avatar Krasjet commented on August 31, 2024

probably related to leeoniya/RgbQuant.js#7

from ditherit-v2.

alexharris avatar alexharris commented on August 31, 2024

Hi thanks for submitting this! This does seem like something obvious to resolve, maybe the RGBquant fork that is mentioned in that issue is something I should look into.

from ditherit-v2.

Krasjet avatar Krasjet commented on August 31, 2024

I think an easy solution could be just adding an option to copy the alpha channel from the input to the output, not sure how well it optimizes the size, but it can be optimized later using optipng or something.

from ditherit-v2.

alexharris avatar alexharris commented on August 31, 2024

that could work. I'll give it a try when i've got time!

from ditherit-v2.

alexharris avatar alexharris commented on August 31, 2024

I started to look into this, and I will just note that the Bayer (Ordered) dither mode does support transparency.

from ditherit-v2.

alexharris avatar alexharris commented on August 31, 2024

Worked on this a little more and it seems that it is too intensive to copy the alpha value of every pixel on the original image, and move that to the output, at least as far as I know how to do it. Using a simple for loop, I tried to copy the alpha values of a relatively small (500x400ish) image, and just that alone crashed the browser tab as it has to iterate through over a million RGBA values.

Maybe there is a more performant way to do it?

Also, this stack overflow is pretty interesting, it covers how to preserve transparency when copy a png to a canvas, which is what we are doing, but the problem is that rgbquant needs to do its thing on the image data, and so there is no way to not lose the alpha values from what I can tell.

This all continues to point towards needing to fix the issuein RGBQuant, or switch to the potentially more modern rgbquant alternative: https://github.com/ibezkrovnyi/image-quantization

from ditherit-v2.

alexharris avatar alexharris commented on August 31, 2024

OK I did finally resolve this issue using @Krasjet suggestion:

I think an easy solution could be just adding an option to copy the alpha channel from the input to the output, not sure how well it optimizes the size, but it can be optimized later using optipng or something.

I forked RGBQuant.js and added code to track the transparent pixels, and then re-transparent them after the dither. Seems to work fine? Havent tested anything about how it affects speed or size, but it seems fine for now.

from ditherit-v2.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.