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

libeheif.js very slow #545

Open
mandys opened this issue Sep 2, 2021 · 1 comment
Open

libeheif.js very slow #545

mandys opened this issue Sep 2, 2021 · 1 comment

Comments

@mandys
Copy link

mandys commented Sep 2, 2021

Hey Team,

I am playing with the javascript version.

Using the library from here:
https://strukturag.github.io/libheif/libheif.js

When I am trying to convert 1.6MB heic image ( taken from iPhone 11 ) into jpeg, it's taking a minimum of 6 secs ( on my iMac ). This is a little too slow for just 1 image.

Looking at the below code:

This particular line is taking about 6 seconds
this.image_data = this.ctx.createImageData(w, h);

Is there a way to speed this up ?

CanvasDrawer.prototype.draw = function(image) {
    **const start = Date.now();**
    var w = image.get_width();
    var h = image.get_height();
    if (w != this.canvas.width || h != this.canvas.height ||
            !this.image_data) {
        this.canvas.width = w;
        this.canvas.height = h;
        if (w > document.body.clientWidth) {
            addClass(this.container, "flexible-size");
            this.container.style["padding-bottom"] = String(100 * (h / w)) + "%";
        } else {
            removeClass(this.container, "flexible-size");
            this.container.style["padding-bottom"] = "";
        }
       
        _this.image_data = this.ctx.createImageData(w, h);_
    **const millis = Date.now() - start;
    console.log(`seconds elapsed = ${Math.floor(millis / 1000)}`);**
        var image_data = this.image_data.data;
        // Start with a white image.
        for (var i=0; i<w*h; i++) {
            image_data[i*4+3] = 255;
        }
    }

    image.display(this.image_data, function(display_image_data) {
        hide("decoding");
        if (!display_image_data) {
            show("error-format");
            return;
        }

        show("container");
        if (saveSupported) {
            show("save-container");
        } else {
            hide("save-container");
        }
        if (window.requestAnimationFrame) {
            this.pending_image_data = display_image_data;
            window.requestAnimationFrame(function() {
                if (this.pending_image_data) {
                    this.ctx.putImageData(this.pending_image_data, 0, 0);
                    this.pending_image_data = null;
                }
            }.bind(this));
        } else {
            this.ctx.putImageData(display_image_data, 0, 0);
        }
    }.bind(this));
};

Thank you,
Mandy

@vaclavbenes
Copy link

Is it possible get image array without processing ImageData?

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