Giter Site home page Giter Site logo

Global color map about jsgif HOT 2 CLOSED

xiaozhuai avatar xiaozhuai commented on July 4, 2024
Global color map

from jsgif.

Comments (2)

joswhite avatar joswhite commented on July 4, 2024

Making the color map be the same for all frames is quite easy. In GIFEncoder.js, you can do:

// with variable declarations (line 61)
var nq = null;
exports.reuseColorTable = false;

// in analyzePixels (line 335)
indexedPixels = [];
if (!nq) {
    nq = new NeuQuant(pixels, len, sample); // initialize quantizer
    colorTab = nq.process(); // create reduced palette
}
// map image pixels to new or existing palette
var k = 0;
for (var j = 0; j < nPix; j++) {
    var index = nq.map(pixels[k++] & 0xff, pixels[k++] & 0xff, pixels[k++] & 0xff);
    usedEntry[index] = true;
    indexedPixels[j] = index;
}
if (!exports.reuseColorTable) {
    nq = null;
}
pixels = null;

This is what I'm doing in the application I'm writing. The only downside is that the global color map is based off of the first frame, so if the first frame is not representative of the colors in the rest of the frames, the colors in those frames will be wonky. Other than that it is quite nice because reusing the color map speeds up encoding by about 40%, and static objects no longer have the weird "glimmer" throughout the GIF from the colors changing slightly from frame-to-frame.

from jsgif.

xiaozhuai avatar xiaozhuai commented on July 4, 2024

@joswhite Thanks for your reply! Just like your said, based off the first frame will behaves incorrectly in some cases. It can be an option, but may not be the default behavior.

from jsgif.

Related Issues (20)

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.