Hello all Dear Challengers,
after spending too many weeks on the libpng.org website and many other resources like StackOverflow, Python programming challenges and in all corners of the web I managed to put hands on, I thought:
why not also post here? Talented people are everywhere.
Aim: my goal is becoming able to manipulate raw PNG data. I attached here a 3x3 png. And I would like with PIL to "
recycle", "
modify" and "
recreate" the 3x3 png. As far as I understand, in an RGB there are 3 bytes + 1 byte (the filter) every row.
Avoiding this post becoming too long or annoying, I would like to show my thoughts:
I download the image locally. After inspection with png-tools like pngcheck and further we will see something like:
1
2
3
4
56
7
8
9
10 | asdfasdf$ pngcheck -7cfpqstvvw test.png
Scanning: test.png
File: test-1
chunk IHDR at offset 0x0000c, length 13
3 x 3 image, 24-bit RGB, non-interlaced chunk IDAT at offset 0x00025, length 17
zlib: deflated, 256-byte window, maximum compression
row filters (0 none, 1 sub, 2 up, 3 avg, 4 paeth):
1 0 0 (3 out of 3)
chunk IEND at offset 0x00042, length 0 |
With
tweakpng we can error-free export the IDAT chunk. From this we remove the first 4 bytes ('IDAT'). Then with
cyberchef we inflate and download the output bytes as file. So we have the raw-png-data containing pixel triplets values and single filter bytes.
Here the steps and the bytes:
1
2
3
4
56
| 74 test.png
21 test.chunk
17 test.zlib # 21-4=17 (removed the IDAT tag)
30 test.dat # 3 * 3 = 9 pixels
# 9 * 3 = 27 (R,G,B) bytes # 27 + 3 = 30 filter byte |
We see the bytes in the following order. Let's say I would like to put the bottom-right corner BLUE pixel, and move it on top-left corner instead of the white one. Then after modifying tuples / lists etc. I would like to feed PIL as in all my scripts from the past in order to view the new image. Which is the best way to go on
Most important, usually in scripts I give PIL only pixel values, after long research I were not able to find an article which explains
how to tell PIL that the data I'm giving to him contains every nth a "special"
filter byte byte.
1
2
3
4
5 | 01 ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff 00 00 00 ff 00 00 00 ff
{01} (ff, ff, ff) (00, 00, 00) (00, 00, 00)
{00} (00, 00, 00) (00, 00, 00) (00, 00, 00)
{00} (ff, 00, 00) (00, ff, 00) (00, 00, ff) |
As you see, now my problems begin. I hope someone find this thread interesting because it could help also others who doesn't find the right articles after weeks...
I really desire improve my little PIL knowledge. By the way, as already stated I really put much efforts and many times the nights were just passed by... so the days become 72hours long during intense reads
Sincerely Yours