Git Product home page Git Product logo

bpg-ww's Introduction

bpg-ww

BPG JavaScript Decoder on WebWorkers

Allows 8 bit depth BPG images and animations

Usage

var bpgw = new Worker('/static/bpgdec8a-ww.min.js');
bpgw.onmessage = function(e) {
    switch(e.data.type) {
        case 'log': console.log('Worker log:' + e.data.message); break;
        case 'debug': console.log('Worker debug:' + e.data.data); debugger; break;
        case 'res':
            var img = e.data.image;
            var frames = e.data.frames;
            var loop_count = e.data.loop_count;
            var cnv = document.getElementById(e.data.meta);
            cnv.width = img.width;
            cnv.height = img.height;
            
            var ctx = cnv.getContext('2d');

            (function() {
                function d() {
                    var a = img.n;
                    ++a >= frames.length && (0 == loop_count || img.q < loop_count ? (a = 0, img.q++) : a =- 1);
                    0 <= a && (img.n = a, ctx.putImageData(frames[a].img, 0, 0), setTimeout(d, frames[a].duration))
                };
                ctx.putImageData(img, 0, 0);
                frames.length > 1 && (img.n = 0, img.q = 0, setTimeout(d, frames[0].duration));
            }.bind(ctx,img,frames,loop_count))();

            console.log('Decode done');
            break;
        default: console.log('Unknown event:' + e.data);
    };
};

// arrayBuffer: BPG image
// container: id of canvas (DOM) for rendering
function decodeBpg(arrayBuffer,container) {
    bpgw.postMessage({type:'image', img:arrayBuffer, meta:container});
};

More info

bpg-ww's People

Contributors

m-2k avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.