-
-
Save davschne/ffc85b4e79e8f326283caee4303f9583 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create a DataView for obtaining a value from the binary pixel data | |
const tileDataView = new DataView(pixelData.buffer); | |
// To find the byte index: | |
// (1) get the index of the start of the row in which the pixel is located | |
// (row index * number of columns) | |
// (2) add to that the column index | |
// (3) multiply by the number of bytes used for each pixel (4) | |
const byteIndex = (coordsInTile.y * tileSize + coordsInTile.x) * BYTES_PER_WORD; | |
// use the byte index and the machine's endianness to obtain the pixel value | |
const pixelValue = tileDataView.getFloat32(byteIndex, littleEndian); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment