Closed luastoned closed 5 years ago
On a side note, why does a 16x16 png decoded produce 272 data points?
png.width and png.height are both at 16
Hi, could you tell us, what your "rawBuffer" is? Maybe you have a gray image in it (R=G=B).
What do you mean by "data points"?
rawBuffer is a regular colored image generated from rasterdata.
When I change cnum to 10 or 100 it produces the desired image, there are approx ~40 different colors in the image.
const png = upng.decode(fs.readFileSync(imagePath));
// png.width = 16
// png.height = 16
// png.data.length = 272
I'm rather confused why it isn't 256?
cnum > 0 is for compressing PNG images. cnum = 0 should preserve original colors. If you show us your buffer or image somehow, I can investigate it.
png.data contains the raw image data. You should read the PNG spec to understand what is inside. We recommend using UPNG.toRGBA8() to get 8-bit RGBA data (would give you 16 x 16 x 4 bytes).
I guess I can close it now.
I feel really dumb, apparently upng
on npm is not upng-js
.
Case closed, I did not encounter any of the above with the proper lib.
Not quite sure why this happens, but when I use
upng.encode([rawBuffer], imageWidth, imageHeight, 0);
it results a grey image.