photopea / UPNG.js

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

Exhaustiv text chunks decoding support #52

Closed hbs closed 4 years ago

hbs commented 4 years ago

Added support for zTXt chunks decoding, thus fixing #28 for good.

The PNG spec states that keywords may appear multiple times in tEXt/iTXt/zTXt chunks, therefore the decoding of the chunks cannot yield a single map. This PR corrects the decoding of those chunks by yielding a list of maps.

photopea commented 4 years ago

Could you show a PNG file for which it is needed? I do believe that you can create such PNG, but can you prove, that someone else in the world is using zTXt chunks?

I am afraid, that if we implement all PNG chunks, our code would be 2x larger.

hbs commented 4 years ago

I did not implement the change out of boredom, we do include data in PNGs we generate and that may include multiple text chunks.

The change in this PR does not double the code size :-)

photopea commented 4 years ago

Can you share the PNG with us? I am keeping a sample PNG for every part of my library.

I know that it does not double the size, but several such changes could double it :/

hbs commented 4 years ago

Sure: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAE3RFWHR0RVh0Lmt3MQB0RVh0LnRleHQx4EeYxQAAABN0RVh0dEVYdC5rdzIAdEVYdC50ZXh0Mg7QG48AAAAXaVRYdGlUWHQua3cxAAAAAABpVFh0LnRleHQxBymcPAAAABdpVFh0aVRYdC5rdzIAAAAAAGlUWHQudGV4dDK36Hl0AAAAHHpUWHR6VFh0Lmt3MQAAeJyrCoko0StJrSgxBAAVGwO/8lrzdwAAABx6VFh0elRYdC5rdzIAAHicqwqJKNErSa0oMQIAFRwDwJro6KEAAAALSURBVHjaY2AAAgAABQAB6frc2AAAAABJRU5ErkJggg==

photopea commented 4 years ago

By the way, where did you find the information, that keywords may appear multiple times in tEXt/iTXt/zTXt chunks?

I think that the fact, that these chunks specify both a keyword and a text value, means, that they are defining a "map", where each value is indexed by a key.

Also, it is more comfortable to access out.tabs.zTXt.Author, than to loop through out.tabs.zTXt to find a value with a specific key.

hbs commented 4 years ago

PNG Specification (http://www.libpng.org/pub/png/spec/1.2/PNG-Contents.html), section 4.2.3:

"Any number of text chunks can appear, and more than one with the same keyword is permissible."

photopea commented 4 years ago

I still think it is nicer, when we represent these data as a map (the same keyword will redefine the old one, just like in JSON). As you are the only person I know using these chunks, I would ask you to use unique keywords.

The main version of UPNG is in my computer, and since I dont use git, I update this repository by uploading new files through a browser. The current version supports zTXt.

hbs commented 4 years ago

So basically you are telling me that you think a design you do not use and which is not conformant to the spec is better than one that at least one of your users uses and which does conform to the said spec? Interesting thought process.

photopea commented 4 years ago

I am sorry, but we need the UPNG.js to be really small, because millions of people are downloading it on our website Photopea.com every month. So I will probably delete the support for these chunks, as we do not need it. You can make your own branch of UPNG.js .

hbs commented 4 years ago

Will do, thanks for starting this project, wishing you the best.