handmade.network » Forums » Work-in-Progress » Implementing a Basic PNG reader the handmade way
abnercoimbre
Abner Coimbre
217 posts
2 projects

Community Manager

#12484 Implementing a Basic PNG reader the handmade way
4 months, 1 week ago

godratio
These kinds of post and writes up should be put somehwhere along with the learning materials being developed.


Created a feature request for the team and I to work on.
brothir
Thomas Kingsvik
10 posts

None

#12800 Implementing a Basic PNG reader the handmade way
3 months, 2 weeks ago

Can't get this working at all. 'decompressed_png' and 'image' are just 0s after sh_zlib_decompress and sh_png_defilter.

None
Sharlock93
Sharo Qadir
11 posts

This isn't twitter.

#12940 Implementing a Basic PNG reader the handmade way
2 months, 3 weeks ago

brothir
Can't get this working at all. 'decompressed_png' and 'image' are just 0s after sh_zlib_decompress and sh_png_defilter.


hey, really sorry for the late reply, did you copy paste the code or write your own? if its a copy paste, can you tell me how to reproduce the error? I wanna fix it. last time I ran this code, it was working when I compiled it, I made sure of it many times. and I just ran it again, and it works, I compiled it on Visual Studio 2015 and I haven't tried GNU C compilers so if you used that please tell me.


memes & pepe will be the downfall of mankind.
Enyo Enev
4 posts
#13295 Implementing a Basic PNG reader the handmade way
1 month ago

Hello,

Well I need some suggestions in order to continue debugging the proper way!

First of all I tried to install ImageWatch on Visual Studio 2017 15.3.0.
It did not work out, even though I have changed extension.vsixmanifest to "support" the 2017 version, because it is currently unavailable for the latest version of Visual Studio.

However I managed to get the reader working in my project. The issue appears when I try to draw it with OpenGL on the screen. In order to see if I have not made any mistakes. The "picturesque" alphabet appears:

https://imgur.com/a/n3LAE

According to the color type it says "2" that translated from PNG Doc means it is RGB triplet.
So I used the following OpenGL call...
1
2
  
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, Image); <-----


Now after I see that something obviously is wrong. I am looking for possible suggestions where the issue might be.
Is it something wrong in how I set up the texture? Or it is decompression and filtering?

Also I want to examine the raw data... Is it possible to writefile() and then read it with another program somehow without adding a specific header say BMP or whatever.

Or I have to examine it byte by byte in hex after using libpng and compare manually both results?

Appreciate your help!





Sharlock93
Sharo Qadir
11 posts

This isn't twitter.

#13301 Implementing a Basic PNG reader the handmade way
1 month ago

Enyo Enev

According to the color type it says "2" that translated from PNG Doc means it is RGB triplet.


The implementation I provided in the tutorial doesn't take into account color types other than 0 and images that might have more than one IDATA chunk, both are very simple to implement:
  1. Color types other than 0 will need changes in the de-filtering code, its basically related to "how many bytes" you should move by when you defilter.
  2. an image could contain (n) chunks, thus the best way to extract them is to loop until you hit IEND, if an image contains more than one IDATA chunk, you must extract them and combine them to one contiguous chunk for the decompressor.
  3. I have both of those "almost" implemented in my own local copy but haven't fully tested extensively and don't have any writing to go along with it.

memes & pepe will be the downfall of mankind.
Enyo Enev
4 posts
#13302 Implementing a Basic PNG reader the handmade way
1 month ago Edited by Enyo Enev on Oct. 20, 2017, 7:28 a.m.

Thank you! Saved me a lot of time...

I just misunderstood the zlib type with the color type. HOW could I ?!? :D

#define Z_HUFFMAN_ONLY 2

Have a nice day.
Sharlock93
Sharo Qadir
11 posts

This isn't twitter.

#13303 Implementing a Basic PNG reader the handmade way
1 month ago

glad you made it work :D

memes & pepe will be the downfall of mankind.