diff --git a/packages/server/src/utils/image-byte-array/index.js b/packages/server/src/utils/image-byte-array/index.js new file mode 100644 index 00000000..4c1e6454 --- /dev/null +++ b/packages/server/src/utils/image-byte-array/index.js @@ -0,0 +1,14 @@ +export default (image, numChannels) => { + const pixels = image.data + const numPixels = image.width * image.height + + const values = new Int32Array(numPixels * numChannels) + + for (let i = 0; i < numPixels; i++) { + for (let channel = 0; channel < numChannels; ++channel) { + values[i * numChannels + channel] = pixels[i * 4 + channel] + } + } + + return values +} \ No newline at end of file