Libpng troubles

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Libpng troubles

Post by MollenOS »

Hi, I know this is a very specific question, however it's been troubling me for a while now.
I'm at the stage in my OS development where I can begin porting libraries, and so far I'm trying to port zlib & libpng.

I have a very annoying problem when trying to load *.png files through my port of libpng, is that while small to medium png files
gets loaded, they all throw a warning, however they get loaded and produce no visible error when rendering the png files.
The warning they give me is something like "gAMA: Bad gamma value", however it seems like that warning hardly matters (since they look like they should).

Now, when trying to load larger png files, like in the size of 1024x768, I get errors every time, and they are in the style of "bad adaptive filter value"
and "CRC: BAD DATA". And I've checked the png files with pngcheck.exe, and it clears them to be fine, so the fault must be in my port of libpng.

So, Im just wondering if anyone has any trouble that is just a little bit like this, and if so, they had any solution to this? Or is it just my
c library that is full of errors.

Thanks in advance :)
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Libpng troubles

Post by sortie »

If you have written your own libc - Yes, it's full of errors. Your stdio is probably entirely all wrong, your ungetc routine probably too. Your heap isn't consistent and memory is corrupting all over. It's time to debug! I had lots of this kind of errors when I originally began porting software to my OS and in most cases, my libc was full of errors.

If you have ported an existent libc, it probably has errors, but I'd watch the kernel closely too. You should be wary of register corruptions/stack corruptions too if these errors are sporadic and unpredictable.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Libpng troubles

Post by bluemoon »

I suspect there is over sensitive warnings of newer version of libpng.
I upgrade libpng in one of my project and see warnings like color profile etc, while no visual defeats on the image.
And hey my image is created with photoshop, I can't blame photoshop generates bad file, huh.

There are few choice:
1. live with the warnings, although it output junks to stdout
2. disable the warnings
3. use tools such as imagemagick to process the images so that it looks good to libpng.
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Re: Libpng troubles

Post by MollenOS »

Yes, I know my LibC is very very far from good, but the memory routines are well tested, as well as large portions of the stdio part, and I have no problem loading large BMP pictures (> 3 mb) (which is my current solution, using *.bmp instead of *.png on large pictures, and libpng for rest).

It just annoys me that there does not seem to be an obvious cause to the problem (But yes, i suspect memory corruption or some function in libc that doesn't work as it should). Im considering trying an older version of libpng (everybody seems to use 1.5.13 anyway) to see if that makes a difference. Atm im using 1.6.6.
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Re: Libpng troubles

Post by MollenOS »

It is probably worth noting I'm building using VS2010 (Which, I know, VS is an inferior build-chain compared to GCC when it comes to osdev, I've just gotten way too far to make the switch).
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Libpng troubles

Post by sortie »

Don't confuse yourself. Visual Studio is a dead end. It's a blind alley. You can't port visual studio to your OS (unless you made a deal with Microsoft). You are forced to use another compiler sooner or later or to never go self-hosting - it's a horrible mistake to prevent yourself from going self-hosting even if you are not interested in it now.

Really, if you are that far with your OS, you will benefit doubly from setting up an OS-specific toolchain that targets your OS. You can customize gcc in any way you like.
Post Reply