-
Notifications
You must be signed in to change notification settings - Fork 133
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
TinyEXR JavaScript version in a browser #43
Comments
TinyEXR JS is experimental and not maintained, so will not work well ATM. Related: #25 I will try to regenerate .js using recent emscripten. FYI, em++ on Ubuntu 16.04 results in the following error:
|
So, I manage to load an exr in a browser with tinyexr.js that shipped with this repo. However, when I compile it myself with Emscripten 1.37.21 on OSX 10.12.6 it give me I'm planing to setup a working demo but first I need to figure out why my build is not working :( |
API has been changed thus you need to rewrite JS code for reading EXR based on current API signature. Also, you could directly use |
Hi @syoyo, can you please help us to figure it out. We've been trying to make it work with the new API but we can make it work. Our current code looks something like this: var fs = require('fs');
var tinyexr = require('../../tinyexr')
var data = new Uint8Array(fs.readFileSync("../../asakusa.exr"))
FromMemory = tinyexr.cwrap(
'LoadEXRFromMemory', 'number', ['number', 'number', 'number', 'number', 'number', 'string']
);
var widthPtr = tinyexr._malloc(4);
var widthHeap = new Uint8Array(tinyexr.HEAPU8.buffer, widthPtr, 4);
var heightPtr = tinyexr._malloc(4);
var heightHeap = new Uint8Array(tinyexr.HEAPU8.buffer, heightPtr, 4);
var ptr = tinyexr._malloc(data.length)
var dataHeap = new Uint8Array(tinyexr.HEAPU8.buffer, ptr, data.length);
dataHeap.set(new Uint8Array(data.buffer))
dataHeap.byteOffset);
let width = 660;
let height = 440;
let filesize = 1127425;
var imgDataLen = width * height * 4 * 4;
var img = tinyexr._malloc(imgDataLen)
var imgHeap = new Float32Array(tinyexr.HEAPU8.buffer, img, imgDataLen/4);
ret = LoadEXRFromMemory(imgHeap.byteOffset, widthHeap.byteOffset, heightHeap.byteOffset, dataHeap.byteOffset, filesize, null); |
But I'm not sure how to handle such a function signature( |
It looks it is difficult to manage complex C function signature in pure JS layer, thus I am considering to write JS bindings in C++ layer. |
Hey @syoyo , I have been working with @Kif11 on trying to integrate the new tinyexr API with javascript. So far, I have found a way to use the new API, but it requires a few adjustments such as changing out_rgba from float ** to float * in LoadEXRFromMemory. It also requires pre-allocating the output image buffer. int LoadEXRFromMemory(float *out_rgba, int *width, int *height,
const unsigned char *memory, size_t size,
const char **err) {
if (out_rgba == NULL || memory == NULL) {
if (err) {
(*err) = "Invalid argument.\n";
}
return TINYEXR_ERROR_INVALID_ARGUMENT;
}
//---- break --- //
// out_rgba = reinterpret_cast<float *>(
// malloc(4 * sizeof(float) * static_cast<size_t>(exr_image.width) *
// static_cast<size_t>(exr_image.height)));
for (int i = 0; i < exr_image.width * exr_image.height; i++) {
out_rgba[4 * i + 0] =
reinterpret_cast<float **>(exr_image.images)[idxR][i];
out_rgba[4 * i + 1] =
reinterpret_cast<float **>(exr_image.images)[idxG][i];
out_rgba[4 * i + 2] =
reinterpret_cast<float **>(exr_image.images)[idxB][i];
if (idxA != -1) {
out_rgba[4 * i + 3] =
reinterpret_cast<float **>(exr_image.images)[idxA][i];
}
else {
out_rgba[4 * i + 3] = 1.0;
}
}
(*width) = exr_image.width;
(*height) = exr_image.height;
FreeEXRHeader(&exr_header);
FreeEXRImage(&exr_image);
return TINYEXR_SUCCESS;
} Is there a reason why you use double pointers and allocate memory inside LoadEXRFromMemory ? Thanks, Sneha |
For reference, here is the javascript side. var fs = require('fs');
var tinyexr = require('../../tinyexr')
var data = new Uint8Array(fs.readFileSync("../../asakusa.exr"))
LoadEXRFromMemory = tinyexr.cwrap(
'LoadEXRFromMemory', 'number', ['number', 'number', 'number', 'number', 'number', 'string']
);
var widthPtr = tinyexr._malloc(4);
var widthHeap = new Uint8Array(tinyexr.HEAPU8.buffer, widthPtr, 4);
var heightPtr = tinyexr._malloc(4);
var heightHeap = new Uint8Array(tinyexr.HEAPU8.buffer, heightPtr, 4);
var ptr = tinyexr._malloc(data.length)
var dataHeap = new Uint8Array(tinyexr.HEAPU8.buffer, ptr, data.length);
dataHeap.set(new Uint8Array(data.buffer))
let width = 660;
let height = 440;
var imgDataLen = width * height * 4 * 4;
var img = tinyexr._malloc(imgDataLen)
var imgHeap = new Float32Array(tinyexr.HEAPU8.buffer, img, imgDataLen/4);
ret = LoadEXRFromMemory(imgHeap.byteOffset, widthHeap.byteOffset, heightHeap.byteOffset, dataHeap.byteOffset, 1127425, null);
console.log('LoadEXRFromMemory return: ', ret);
// Now imgHeap contains HDR image: float x RGBA x width x height |
I am working on embind based implementation in https://github.com/syoyo/tinyexr/tree/emscripten/experimental/js And its near to get it work(probably by this weekend(22 Oct, 2017).
This is for matching similar behavior with |
I have finished initial embind-based implementation of TinyEXR. Apparently it works. Could you please write HTML5 Canvas example JS code so that the binding works well or not, @Kif11 @sneha-belkhale ? https://github.com/syoyo/tinyexr/tree/emscripten/experimental/js (FYI, regenerated |
@syoyo looks like the embind is still broken. The first pixel of the data image array is correct but the rest are zeroes. $: node test.js
1127425
true
660
440
Float32Array [
0.84716796875,
0.92529296875,
0.9609375,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0 ... I have a HTML canvas example ready. I just need a working embind... |
Now fixed in this commit: 2209ea4
Awesome! |
I have merged @Kif11's HTMT5 canvas example, and also merged |
I think so too. Closing... |
Thanks! |
Hello, Thanks @syoyo to ping me in #25 . Just tested it and it is loading something but it is looks wrong when displayed. Here the exrinfo of the image I am loading :
Did I miss something ? Works well when displaying in it ( Pixar ) ? Any idea ? Many thanks, Stephane |
Please attach .exr file to reproduce the issue. |
Sure : https://drive.google.com/open?id=0B4OKayijuI7xRVQyN2lOMlZwVjQ ( Github is blocking exr ) |
Thank you for the file. Hmm..., it looks Reading your
|
I've been trying to run JavaScript version provided in this repo in a browser, but I'm stuck on the step of converting image blob to a nodejs like Buffer. Please suggest
Here is my code:
The text was updated successfully, but these errors were encountered: