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

Is there some way to use the "builtin" blp converter alone? #3

Open
435352980 opened this issue Mar 3, 2020 · 2 comments
Open

Is there some way to use the "builtin" blp converter alone? #3

435352980 opened this issue Mar 3, 2020 · 2 comments

Comments

@435352980
Copy link

Very nice tool!!!
Is there some useful API in wasm module for converting blp files?
I tried some module, but allways loss quality.

wc3data

01aaccaf-6f82-44cc-94a7-91ae15b04c74

other

BTNAlchemy Material002

@d07RiV
Copy link
Owner

d07RiV commented Mar 3, 2020

You mean converting blp to png? I'm using libjpeg for conversion, the code is here: https://github.com/d07RiV/wc3data/blob/master/DataGen/image/imageblp.cpp

@435352980
Copy link
Author

435352980 commented Mar 4, 2020

Yes, thank you!
I'll try it. And it can be compiled to wasm module?
I build them with emscripten like blew but it seems not working.

EM_JS(void, write_output, (void const* ptr, int size), {
  window.postResult(HEAPU8.slice(ptr, ptr + size));
});
extern "C"{
EMSCRIPTEN_KEEPALIVE int convertImage(void const* data_ptr, uint32 data_size,ImageFormat::Type format) {
    File f;
    f = MemoryFile((uint8*)data_ptr, (size_t)data_size);
    Image image;
    image = ImagePrivate::imRead(f,format);

    if (image) {
      MemoryFile file;
      image.write(file);
      write_output(file.data(), file.size());
      return 1;
    }
    return 0;
  }
}

The html code

window.postResult = function(msg) {
  if (msg) {
    const blob = new Blob([msg], { type: 'image/png' });
    document.querySelector('#image').setAttribute('src', URL.createObjectURL(blob));
  } else {
    console.error(msg);
  }
};
setTimeout(() => {
  fetch('./aaa.blp').then(res =>
    res.arrayBuffer().then(data => {
      ImgParser().then(wasm => {
        const array = new Uint8Array(data);
        const addr = wasm._malloc(array.length);
        wasm.HEAPU8.set(array, addr);
        wasm._convertImage(addr, array.length, 3);
        wasm._free(addr);
      });
    })
  );
}, 1000);

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