1

I have the following C function that takes in an array compressed by the zfp library, and attempts to decompress it.

int EMSCRIPTEN_KEEPALIVE zfpDecompress(int precision, float* array, int nx, int ny,int nz, unsigned char* buffer, int compressedSize) {
  int status = 0;    /* return value: 0 = success */
  zfp_type type;     /* array scalar type */
  zfp_field *field;  /* array meta data */
  zfp_stream *zfp;   /* compressed stream */
  bitstream *stream; /* bit stream to write to or read from */

  type = zfp_type_float;
  field = zfp_field_3d(array, type, nx, ny, nz);
  zfp = zfp_stream_open(NULL);

  zfp_stream_set_precision(zfp, precision);
  bufsize = zfp_stream_maximum_size(zfp, field);
 
  stream = stream_open(buffer, bufsize);
  zfp_stream_set_bit_stream(zfp, stream);
  zfp_stream_rewind(zfp);

  if (!zfp_decompress(zfp, field))
  {
    status = 1;
  }

  zfp_field_free(field);
  zfp_stream_close(zfp);
  stream_close(stream);

  return status;
}

I am attempting to call this function in Typescript (a React client), by passing it the compressed array received by the client. I have the communication set up correctly, since I can call more basic functions without a problem.

I am trying something like this:

floatArray = new Float32Array(size)
floatArray = response.getFloats()  // set array to some float32Array

ZFP.zfpDecompress(0.01, floatArray, dimensionX, dimensionY, dimensionZ, buffer, bufferSize)

However, it returns 1, meaning the decompression was not successful. I suspect that I am not passing in the array correctly. What is the correct way to pass in a pointer to an array in Javascript / Typecript using Emscripten?

Seeker
  • 262
  • 1
  • 5
  • 17
  • https://stackoverflow.com/questions/17883799/how-to-handle-passing-returning-array-pointers-to-emscripten-compiled-code/23917034#23917034 – zakki Sep 30 '20 at 04:45

0 Answers0