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

From browser Worker #30

Open
Noitidart opened this issue Sep 3, 2016 · 4 comments
Open

From browser Worker #30

Noitidart opened this issue Sep 3, 2016 · 4 comments

Comments

@Noitidart
Copy link

I am trying to use this from a Web Worker in a browser.

I get the image data by doing xhr with responseType arraybuffer. I then do var p = new PNG(arrbuf);

However this gets stuck into an infinite loop. I see this is because:

      while (true) {
        chunkSize = this.readUInt32();
        section = ((function() {
          var _i, _results;
          _results = [];
          for (i = _i = 0; _i < 4; i = ++_i) {
            _results.push(String.fromCharCode(this.data[this.pos++]));
          }
          return _results;
        }).call(this)).join('');

Can you please help me modify to use in Web Worker scope.

Thanks!

@Noitidart
Copy link
Author

Oh I got passed the infinite loop by doing:

var a = new PNG(new Uint8Array(xhr.response));

I need to now get the rgba pixel data. Working on that now.

@Noitidart
Copy link
Author

Hm ok so I was doing this now:

PNG.load('file:///C:/Users/Mercurius/Documents/GitHub/Firefox-PNG-Icon-Collections/_nightly/64.png', function(c) { C = c })

So C is set to an object but i dont see pixels (rgba array). Can you please advise?

@Noitidart
Copy link
Author

Noitidart commented Sep 3, 2016

Oh got it had to do this:

    PNG.load('...../64.png', function(pnginfo) {
        var imagedata = new ImageData(pnginfo.width, pnginfo.height);
        pnginfo.copyToImageData(imagedata, pnginfo.decodePixels());
        pnginfo.pixels = imagedata.data;
        deferred_loaded.resolve(pnginfo);
    });

May I submit a PR, i had to add an if statement, if its a worker, not to load that makeImage stuff as it uses document and then to set global instead of window.PNG we have to set DedicatedWorkerGlobalScope.PNG =

@guest271314
Copy link

@Noitidart

I am trying to use this from a Web Worker in a browser.

FWIW https://github.com/guest271314/decodePixelsFromOffscreenCanvas

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