NO

Author Topic: A question about libpng  (Read 6168 times)

eco11

  • Guest
A question about libpng
« on: September 15, 2012, 09:20:15 PM »
I have a simple understanding of Win32. I'm moving on to the next step in my learning and I would like to create an image viewer. To make sure I expand my knowledge, I would like to implement an external library for practice, but I have never done this before.

My goal is to create a png picture viewer (Just 1 file type for now), and I am going to be using libpng1512 and it's requirement zlib125 or greater - I have zlib127.

I have several questions about this. The first question is, how should I setup my project to make sure I have properly included everything.

Another question is, that libpng is a file format handler. In a win32 app, I would assume I would be manipulating a picturebox. I'm not sure I fully grasp, how raw images in memory are affected by the filetype I'm trying to load and save, so I was wondering if someone can help me get this basic concept out of the way. Maybe some example code, or how I should structure my win32 app.

CommonTater

  • Guest
Re: A question about libpng
« Reply #1 on: September 15, 2012, 09:34:27 PM »
I'm not familiar with the actual libraries and the functions in them... 

But in general what you want to do is make a workspace directory, place each of your libraries in separate folders under it.  DO NOT put these files in the Pelles C Include and Lib folders! In fact, don't even think about it... :D

Once you have the libs each in their own folders, you may need to make projects in POIDE to compile them... Compiling them to DLLs or Static libs (the latter is better) may take a bit of fudging with the code but it's a great learning experience. 
 
Once you have your libs compiled, you can create a project either directly in the workspace folder or in a separate folder inside it and you can then begin working on your picture viewer project.
 
In the picture viewer project select Project -> Project Options -> Folders and add your two library folders to the Include and Lib paths.  From there just include the necessary .h files in your source and add the libraries to your linker's library list... and you're off to the races.
 
Creating this setup will be a lot simpler if you use the Workspace Manager AddIn ... which you can get HERE

I'm not a graphics programmer, so I'll ask the others to help you with the actual code...
 

eco11

  • Guest
Re: A question about libpng
« Reply #2 on: September 15, 2012, 09:42:27 PM »
That's great, I'll be looking for the additional help you mentioned, but for now you gave me plenty to do. I will get the addin and try compiling the libs to start with.

eco11

  • Guest
Re: A question about libpng
« Reply #3 on: September 15, 2012, 10:01:00 PM »
I think, I'm going to scrap this. The libpng and zlib folders are a jungle. I think it's a little more complex to compile those libraries than I thought. Unfortunately only visualc and gcc projects are available for win32.

CommonTater

  • Guest
Re: A question about libpng
« Reply #4 on: September 16, 2012, 12:39:22 AM »
I think, I'm going to scrap this. The libpng and zlib folders are a jungle. I think it's a little more complex to compile those libraries than I thought. Unfortunately only visualc and gcc projects are available for win32.

Before you quit... try this.... 
 
Pick one of the libraries... say ZipLib... 
 
Find all the source files (*.c, *.h) and move them to a single directory.
 
Create project for a win32 static library, 
When you get into the project itself, add all the C files and try compiling it...
 
If you're like me, you'll love the challenge and will end up "lost in code" until you get it working. 
Giving up after only 15 minutes of effort (check your message times) is not the best way to learn :D
 
And before you ask ... that "jungle" probably made sense to someone someplace but then programmers are some of the most disorganized people I've ever met...
 
« Last Edit: September 16, 2012, 12:44:50 AM by CommonTater »

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: A question about libpng
« Reply #5 on: September 16, 2012, 03:35:27 AM »
Another question is, that libpng is a file format handler. In a win32 app, I would assume I would be manipulating a picturebox. I'm not sure I fully grasp, how raw images in memory are affected by the filetype I'm trying to load and save, so I was wondering if someone can help me get this basic concept out of the way. Maybe some example code, or how I should structure my win32 app.
Well, CommonTater has already tried to give a quick shot at the first part of your question(s), so let me take a quick stab at your last question (though I am not much of a graphics programmer myself).

The "raw images in memory" are in no direct relation to any filetype/format, certainly not to PNG. AFAIK, the Windows BMP format is the closest direct representation of the internal graphics structure/buffer. For all other (file) formats the "trick" in writing a graphics viewer as you intend would be to "translate" between the representation of the graphics in PNG (JPEG, GIF, TIFF, etc) format and the Windows internal "raw" format. I am not sure how much of that is already done in that library you referred to, but I am fairly certain that the internal structure of the "picture box" box in Windows is different than the one used in Linux or Mac OS for example. PNG isn't called "Portable Network Graphics" without reason...  ;)

Also, as a more general remark, if you refer to certain libraries in your questions, it might be a good idea to not only name them but also provide links to them so that everyone has a chance to talk about the same thing...

Ralf

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: A question about libpng
« Reply #6 on: September 16, 2012, 10:01:55 AM »
ZLib:
use -Ze -Go compilers options
This PellesC error
Code: [Select]
C:\code\PellesC\zlib-1.2.7\inftrees.c(39): error #2120: Redeclaration of 'inflate_table', previously declared at C:\code\PellesC\zlib-1.2.7\inftrees.h(60); expected 'int __cdecl function(codetype, unsigned short int *, unsigned int, code * *, unsigned int *, unsigned short int *)' but found 'int __cdecl function()'.That is bug in PellesC. Comment that out
Code: [Select]
int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work)
codetype type;
unsigned short FAR *lens;
unsigned codes;
code FAR * FAR *table;
unsigned FAR *bits;
unsigned short FAR *work;
use instead
Code: [Select]
int ZLIB_INTERNAL inflate_table(codetype type, unsigned short *lens, unsigned codes, code * *table, unsigned *bits, unsigned short *work)
Code: [Select]
pomake -f win32\Makefile.msc CC=pocc.exe CFLAGS="-Ze -Go" WFLAGS= AR=polib.exe RC=porc.exe zlib.lib

lpng:
for example:
Code: [Select]
pomake -f scripts/makefile.vcwin32 CC=pocc.exe CFLAGS="-I..\zlib-1.2.7 -Ze" AR=polib.exe libpng.lib
« Last Edit: September 16, 2012, 12:57:37 PM by timovjl »
May the source be with you