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

Add support for 64bit Float #23

Open
Samreay opened this issue Oct 30, 2014 · 5 comments
Open

Add support for 64bit Float #23

Samreay opened this issue Oct 30, 2014 · 5 comments

Comments

@Samreay
Copy link

Samreay commented Oct 30, 2014

At the moment, all 64bit floating point data gets converted to 32bit. The Image.prototype._getFrame function should have the bitpix<0 if condition updated to differentiate between values of -64 and -32.

Specifically, modifying image.coffee such that from line 88 the code reads:

      arr = new Uint32Array(buffer)

      swapEndian = (value) ->
        return ((value & 0xFF) << 24) | ((value & 0xFF00) << 8) | ((value >> 8) & 0xFF00) | ((value >> 24) & 0xFF)

      while i--
        value = arr[i]
        arr[i] = swapEndian(value)

      if bitpix == -64
        i = arr.length
        while i-=2
          tmp = arr[i]
          arr[i] = arr[i + 1]
          arr[i + 1] = tmp
        arr = new Float64Array(buffer)
      else       
        # Initialize a Float32 array using the same buffer
        arr = new Float32Array(buffer)
@kapadia
Copy link
Member

kapadia commented Oct 31, 2014

@Samreay It's been a while since I've thought about it, so my memory is a little fuzzy on this issue. I recall there being a limitation. I once tried to support 64 bit integers, but since javascript doesn't natively support that data type, it would require representing a Int64 array using 2 Uint32Arrays, along with some wacky endian flips.

As you point out, Float64 support should be easier. Do you mind submitting a PR? Adding a Float64 test would also be appreciated.

@Samreay
Copy link
Author

Samreay commented Oct 31, 2014

Yeah, Javascript can only represent ints up to 53 bits as it stores everything as floats.

I'll figure out how to make a pull request, a test, and submit it. Cheers.

@kapadia
Copy link
Member

kapadia commented Oct 31, 2014

Very true, but I believe the typed arrays are an exception to the 53 bit limitation.

Thanks!

@Samreay
Copy link
Author

Samreay commented Nov 10, 2014

I've been having some major problems building the code (coffeescript on windows is apparently temperamental) and I lack the knowledge of node and coffeescript to be able to figure out what is actually the problem.

I've thrown what I had as a patch into a gisthub (https://gist.github.com/Samreay/f9c519dc9bebd8e6f1cf), so hopefully it comes in use if you have time to add it in properly at a later date.

@kapadia
Copy link
Member

kapadia commented Nov 12, 2014

@Samreay Thanks for the gist. I should be able to incorporate it.

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