photopea / UTIF.js

Fast and advanced TIFF decoder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make endianness a parameter in `encode`

chubei-urus opened this issue · comments

Currently the endianness is hardcoded as big endian. Can we add a parameter to encode to control the endian?

Hi, why would you need it? If some tool handles TIFF files, it should handle both little and big endian.

I have floating point image data (bit depth being 32) read back from a canvas and want to save it as tiff. I know the data is little endian and feel writing little endian to the header would be easier compared to fix the endianness of every sample.

UTIF.js can not encode floating point image data at the moment anyway.

How do you "read floating point data back from a canvas"? As far as I know, you can read only 8-bit integer color values from a canvas.

UTIF.js can not encode floating point image data at the moment anyway.

Why is this? I'm using the "SampleFormat" and "BitsPerSample" tags, and PhotoShop and Windows Photo Viewer are both loading the result image fine.

I'm calling UTIF.encode and then appending the raw image data.

How do you "read floating point data back from a canvas"?

I didn't make myself clear. I'm reading data back from a WebGL2 framebuffer, which is created from a canvas' rendering context.

Ok, I get it now. So you are working with 32-bit floats. But you can simple create var b = new Uint8Array(float32.buffer); and re-shift bytes in that buffer to a big endian.

Exactly, I just feel it'd be easier to write little endian to the header.

I never created Float32 TIFF files, so I am not sure how hard would it be. If it is only about the first two bytes, you can change the output of UTIF.js yourself.

Sure thing. Closing.