photopea / UPNG.js

Fast and advanced PNG (APNG) decoder and encoder (lossy / lossless)
MIT License
2.1k stars 259 forks source link

cnum parameter = 0 produces grey image #27

Closed luastoned closed 5 years ago

luastoned commented 6 years ago

Not quite sure why this happens, but when I use

upng.encode([rawBuffer], imageWidth, imageHeight, 0);

it results a grey image.

luastoned commented 6 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

photopea commented 6 years ago

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"?

luastoned commented 6 years ago

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?

photopea commented 6 years ago

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).

photopea commented 5 years ago

I guess I can close it now.

luastoned commented 5 years ago

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.