library
library copied to clipboard
RGBLuminanceSource not working -> Readme Example is not working
Describe the bug
RGBLuminanceSource.getRow()
doesn't work.
i'm trying to decode an image on a service worker, so without document.
i'm getting data from the canvas for test purpose and passing it to the example as explained in the readme file.
the problem is that RBGLuminanceSource
saves the buffer as RGB (3 bytes for pixel) in an uint8clampedarray
, but when it serves them through getRow
it responds with only 640 bytes without making any kind of transformation.
i think that the correct behaviour is to respond with a grayscale row like in the toGrayscaleBuffer
method of HTMLCanvasElementLuminanceSource
btw a temorary workaround could be to instantiate like this:
ZXing.RGBLuminanceSource(toGrayscaleBuffer(data.data,data.width,data.height), data.width, data.height) function toGrayscaleBuffer(imageBuffer, width, height) { const grayscaleBuffer = new Uint8ClampedArray(width * height); for (let i = 0, j = 0, length = imageBuffer.length; i < length; i += 4, j++) { let gray; const alpha = imageBuffer[i + 3]; if (alpha === 0) { gray = 0xFF; } else { const pixelR = imageBuffer[i]; const pixelG = imageBuffer[i + 1]; const pixelB = imageBuffer[i + 2]; gray = (306 * pixelR + 601 * pixelG + 117 * pixelB + 0x200) >> 10; } grayscaleBuffer[j] = gray; } return grayscaleBuffer; }
To Reproduce See Attached file index - Copia.txt
you can do ZXing.RGBLuminanceSource(new Int32Array(data.data.buffer), data.width, data.height)
if data
is ImageData
Stale issue message