photopea / UPNG.js

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

[BUG]This image whose data length is not 1024 #49

Closed wood1986 closed 4 years ago

wood1986 commented 4 years ago

1

When I decode this png, the data is in Uint8Array and the length is 1025. The length should be 1024. This image is 256 x 1. If I use RGBA, the total length should be 256 x 4 1024

Use browser console to run this code

const arrayBuffer = fetch("https://user-images.githubusercontent.com/5212215/81272862-edab9200-9002-11ea-956e-5bbeb910a4ab.png")
      .then(res => res.blob())
      .then(blob => blob.arrayBuffer())
      .then(decode)
      // .then(toRGBA8)
      .then(console.log);
photopea commented 4 years ago

Hi, what do you mean by "data length"?

You should use toRGBA8() to decode PNG images, as it is described in README. The output of toRGBA() will be 1024 bytes long.

wood1986 commented 4 years ago

image

photopea commented 4 years ago

This array is used for the internal purposes of UPNG.js , just like "ctype" and some other properties. You should not use it for anything. You shoud use UPNG.js according to our README.

wood1986 commented 4 years ago

I did toRGBA8 before and it was expected. But I did not know it is necessary in order to get the right data.