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

Feature write float32array #106

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/geotiffwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,12 @@ const encodeImage = (values, width, height, metadata) => {

const prfx = new Uint8Array(encodeIfds([ifd]));

const img = new Uint8Array(values);
// This should allow other kinds of typed arrays to be used. Uint8 is just a view of the real underlying data.
const img = new Uint8Array(values.buffer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, values is sometimes a simple JavaScript array and not a buffer, so there is no .buffer property available in that case. Here's where this simple array is created: https://github.com/geotiffjs/geotiff.js/blob/master/src/geotiffwriter.js#L320

Copy link
Contributor

@DanielJDufour DanielJDufour Oct 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, on reviewing the code I wrote, I can see it's super confusing and it's not clear what type something is. I'm definitely open to have it being re-written to be more clear as long as people can still pass in a simple array :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • When it is a normal js array, does it assume that it is 8 bits?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m0ose yes, that is correct. That is an oversight on my part. My bad. Perhaps, you need to write some code to read metadata.BitsPerSample and metadata.SampleFormat and set what typed array to use based on that? I believe for Float32, BitsPerSample should equal 32 and SampleFormat should equal 3. @constantinius might have insight of the tiff tags, too.

References:


const samplesPerPixel = ifd[277];

const data = new Uint8Array(numBytesInIfd + (width * height * samplesPerPixel));
const data = new Uint8Array(numBytesInIfd + (img.length * samplesPerPixel));
m0ose marked this conversation as resolved.
Show resolved Hide resolved
times(prfx.length, (i) => { data[i] = prfx[i]; });
forEach(img, (value, i) => {
data[numBytesInIfd + i] = value;
Expand Down
2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<select id="bands">
</select>

<script src="geotiff.bundle.js"></script>
<script src="../dist/geotiff.bundle.js"></script>
<script src="lib/plotty.min.js"></script>

<script>
Expand Down