PDA

View Full Version : PNG Loader ?


Applewood
08-09-2004, 10:55 PM
Hi. Anyone got code or a link to something that can load .PNG files please ?

I've looked at the open source joke that is libpng but I really don't want to include 93,000 files into my BREW application that has around 10 game source files making 50k of executable!

Has anyone written something properly for those of us who like to keep our builds real ? I'm only interested in loading 8bit data (from whatever is save our by pro-motion). Whilst I'm asking for a rainbow, it'd be nice if it was vanilla c or at least not heavily obfuscated with C++ enrichment.

Many many thanks. Yeah, I know being grumpy isn't the best way to get people doing you favours, but I'm still shocked by the nightmares of looking at the GNU way of doing things. :)

princec
08-10-2004, 02:05 AM
Ditch PNG format if you can and use your own image format. Write a supremely efficient little loader for it.

Cas :)

SunAndGames
08-10-2004, 02:54 AM
SDL (http://www.libsdl.org/index.php) , or more specifically SDL_image (http://www.libsdl.org/projects/SDL_image/) will load PNGs. And as an extra bonus, I'm pretty sure it takes less than 93,000 file :D

Although, it probably would be overkill when all you need is an image loader.

Applewood
08-10-2004, 03:05 AM
SDL , or more specifically SDL_image will load PNGs
lol. Just look at that page. I can't see how people can work like this, I really can't. If I had a page on my own site containing source to something like an image-loader, it'd have one link - to a zip containing one .c file and one .h file. Instructions for building on the vax-1334-os-4-p v2 would be "If it don't compile, change the mallocs - that's why there's source. It's easier than asking the author to obfuscate more stuff and therfore make it even harder to read for everyone else"
</rant>

@prince:
I already use my own format generally, which is a flavour of RLE compression for fast blitting. The sad thing is that I have about 40 full-screen images to pack into a 500Kb game along with all the other code and data. PNG gave the smallest files for my style of output of these room backgrounds. If I need to add another 50K to my exe just to load em though, then I think plan b) gets a go.

Nemesis
08-10-2004, 04:28 AM
Ditch PNG format if you can and use your own image format. Write a supremely efficient little loader for it.

Cas :)
Own simple format yes.. and if file size is an issue, try combining with zlib to create your own compressed image format.

patrox
08-10-2004, 04:32 AM
StrechBlt under windows will depack a png. ( create a BITMAPINFOHEADER with BI_PNG , but that only works after windows 98 )

else i can only recommend the excellent cxImage lib.
http://www.xdp.it


pat.

MiCo Games
08-10-2004, 04:39 AM
SDL or more specifically SDL_image will load PNGs.

I thought SDL_image used libpng to load PNG files... or it might have changed since I last looked at it?

princec
08-10-2004, 04:41 AM
Try using delta planar gzip compression. Usually somewhat better than PNG compression for sprites.

Cas :)

ggambett
08-10-2004, 05:47 AM
I've looked at the open source joke that is libpng[...]but I'm still shocked by the nightmares of looking at the GNU way of doing things.
[...]
lol. Just look at that page. I can't see how people can work like this, I really can't.
Sorry, I think the difficulties exist between monitor and chair. SDL has an API as clean as it can get. For an example of libpng through SDL_Image in action, see http://www.MysteryStudio.com/info.php?id=bbb

elund
08-10-2004, 05:48 AM
I thought SDL_image used libpng to load PNG files... or it might have changed since I last looked at it?Yes, SDL_image (http://www.libsdl.org/projects/SDL_image/) uses libpng (http://www.libpng.org/pub/png/libpng.html). If you use SDL_image you have to use the whole set of SDL_image DLLs (which includes JPEG support, whether you want it or not). To save space, I wrote my own SDL/libpng wrapper instead and avoided SDL_image entirely.

Exotabe
08-10-2004, 06:54 AM
I've written a simple png loader using libpng that you're welcome to have when I get home from work. It hasn't been used or tested exhaustively, but it works for loading and rendering non-alpha png, if nothing else.

I don't believe that libpng itself is huge, it just has a not-so-pretty api. Anyway, if you're interested, leave me a PM.

-Nate

GameStudioD
08-10-2004, 08:31 AM
zlib or 7zip may be a good solution. If you go that route, they have a better compression performance when the image is not RLE compressed (usually). So, your RLE would need to be done at runtime for the faster blitting.

You could also just not compress the images and compress the installer exe with http://upx.sourceforge.net .

Applewood
08-10-2004, 09:22 AM
Sorry, I think the difficulties exist between monitor and chair. SDL has an API as clean as it can get
We'll have to agree to disagree then. The problem I see with SDL is that it even has an API. I just want one function that I can alter directly to work in the single environment it'll always be used in. I think the problem exists in peoples minds who like using sledgehammers to crack nuts.

StrechBlt under windows will depack a png
Just a shame I'm writing under BREW :) I didn't know that though, could be handy in later life, thanks.

You could also just not compress the images and compress the installer
Sadly, storage size is even more at a premium than installer size. I'd write a WAD file thing but file access is real slow and theres no ram on these things either. A couple of BREW phones only have 200Kb (thats *K*b) for everything.

If you use SDL_image you have to use the whole set of SDL_image DLLs
Not sure how BREW would load a dll. Maybe that problem is also twixt screen and chair :)

Thanks guys - it looks to me like there's no quick fix for this after all. I'm gonna spend a coupla days merging all the libpng fluff into one file that contains nothing but source to load a PNG. When I'm done, I'll post it on my website...

ggambett
08-10-2004, 09:47 AM
I just want one function that I can alter directly to work in the single environment it'll always be used in.
You mean like IMG_Load() (http://jcatki.no-ip.org/SDL_image/SDL_image_7.html#SEC7)?

Applewood
08-10-2004, 10:24 AM
You mean like IMG_Load()?
Not really. According to the docs, that function then calls another one which in turn must do some string manipulation and testing then branch off again to load a wide variety of other file types.

This sort of thing is all well and good if you dont care about size or speed, but what I really want is a single function to load a PNG.

I've already got about 60 lines of code in one file that loads .TGA files. Compare that to libX and you'll see where I'm coming from.

EpicBoy
08-10-2004, 10:54 AM
In the time you've spent arguing about it, you probably could have written one yourself. :P

MattInglot
08-10-2004, 10:57 AM
else i can only recommend the excellent cxImage lib.
http://www.xdp.it

I second this. cxImage is stupidly easy to use and there's compile options that let you decide what functionality gets compiled in. It also supports a LOT of image formats and the class itself is very clean.

Jim Buck
08-10-2004, 11:35 AM
Use FreeImage to convert from whatever format to whatever format is easiest for you to deal with (even a custom format).

Applewood
08-10-2004, 12:44 PM
Just took a look at the XDP thing. I reckon thats a pretty good place to start, thanks. :)

Sillysoft
08-10-2004, 01:45 PM
What exactly are you creating this application (game?) for? Are you with a company or as an indie? The wireless carriers guard their customers as much as they can, and they put further limitations on what applications they will offer. The word on the street is that Verizon (the biggest BREW carrier) starts to get ancy when apps get bigger than 100-120k in size. Not to mention the fact that they recently said they were going to start making the submission process optimized for preferred developers (read: shut out the little guys).

Just making sure you know what you are getting in to. If it a 'just for fun' project then go for the gold, but if you are trying to make money there are many issues in the way.

Nutter2000
08-11-2004, 02:27 AM
@Sillysoft
I could be wrong but I think that if Paul was writing a just for fun project he wouldn't be half as stressed about it as he appears to be ;)

@Applewood
Having had to recently impliment mng animations for a client's game using libmng I truely feel your pain :(
It does sound like rolling your own is best in this case possibly using some sort of compression lib (like what Cas said) although given the memory limitations of most BREW devices you might have some trouble there as well.

Incidently CxImage also uses the libpng source but also isn't it written for MFC applications or is that just the demo for it?

Applewood
08-11-2004, 12:45 PM
I think I'm ok given that my games (a saga of four) are actually being pushed by Verizon Wireless :)

Nutter - you're from Nottingham ? Cool - spent the first 21 years of my life in Bilborough. I'm with you on the roll-your-own front. Gonna use that XDP thing as reference and write my own - usually the best way.

Fish-Guy
08-11-2004, 01:48 PM
Hi. Anyone got code or a link to something that can load .PNG files please ?

I've looked at the open source joke that is libpng but I really don't want to include 93,000 files into my BREW application that has around 10 game source files making 50k of executable!

I made a customized version of the libpng code into a lib that was just compiled in with the rest of my game code. I merely have the lib as a quick way of converting PNG images to other formats, including the alpha layers. I guess it also depends on what platforms you are targetting, and what API you intend to use the processed data with. If using a commonly used API such as SDL, most image loading code is present. You should definately look into using another format, or have a go at creating something yourself. It isn't that difficult. Just don't expect to roll out a new JPEG replacement in a matter of a few hours :p

Andy Kellett
F1 Software
www.f1-software.com

Nutter2000
08-12-2004, 08:41 AM
Nutter - you're from Nottingham ? Cool - spent the first 21 years of my life in Bilborough. I'm with you on the roll-your-own front. Gonna use that XDP thing as reference and write my own - usually the best way.
bloody hell it's a small world!
What with me having worked in Southampton and you being on the island as well!

Applewood
08-12-2004, 09:44 AM
aye, lol.

You at IO ?

Nutter2000
08-13-2004, 01:09 AM
No, Smoking Gun Productions

Applewood
08-13-2004, 09:28 AM
Ah, that's right. We've had this conversation before :)

Anytime you need a spare adept in symbian/brew/j2me/ppc/anything like that, gimme a shout :) (I dont touch palmos on account of it being shite - lol).

Nutter2000
08-15-2004, 11:55 PM
Well, was at SG I should say

Well I'll certainly keep you in mind :D
Not sure what good that'll do though, I'm in the same position as you looking for contract work ;)

Applewood
08-16-2004, 05:30 AM
Right, ok.

We'll put this one on you scratch my back... then, I guess :)

Battman
10-05-2004, 06:50 AM
Hi. Anyone got code or a link to something that can load .PNG files please ?

I've looked at the open source joke that is libpng but I really don't want to include 93,000 files into my BREW application that has around 10 game source files making 50k of executable!


The Brew API 1.1 and newer supports png format on most devices.
Use ISHELL_LoadImage() or ISHELL_LoadResImage() ...
I have tested it on VX4400.

Applewood
10-05-2004, 06:57 AM
Yup, I saw that thanks.

The sad thing is I don't use bitmaps but write directly to the screen as doing so (using RLE) takes up about 1/3rd the space for your sprites. Therefore there'd be a lot of wasted overhead for me when the O/S does it's thing.

The good bit is that I'm nearly through porting the PD zip loading code over which is just as good for compression :)

Battman
10-05-2004, 07:47 AM
The sad thing is I don't use bitmaps but write directly to the screen (using RLE) ...
You mean, you are decoding the image on the fly?
Are you using DIB interface to do it? (Brew API 1.1 doesn't support it, unfortunately)

Applewood
10-05-2004, 08:17 AM
I'm decoding my RLE on the fly as I blit, yes - it's way more efficient in terms of both memory footprint and cache thrashing. Given how crap the ram is in these things, this does make a considerable difference.

I'm on 1.1 and don't use DIBs. It's real easy though - allocate your screen bitmap, then write directly into the pixels for that at an offset from the pointer you get back. At end of frame, just present your screen bitmap as normal.

Yes, it's a total hack but its worth the effort. All phones have the same format (16 bit 565) and the only gotchas are that on some phones the pixel data starts at a different offset from the bitmap pointer. You'll need a bit of trial and error on this one using brewlogger etc.

There's some stuff about this buried on the Qualcomm forums somewhere, but it's not well known and it will give you a big edge...

keethrus
10-06-2004, 05:33 AM
Just in case anybody is interested in a PNG file loader, I wrote a PNG file loader that is just one .c file and one .h file. It's small, straightforward, and simple; but only loads 32-bit images (since that what I use). If anybody would like it, Id be glad to share. It does require the ZLIB library (but I have it compiled already if you need it too; as a zlib.o file).

Just sharing...

- Jeremiah :)

neverever
11-02-2004, 08:40 AM
Can u email it to me? haunted@sio.midco.net

keethrus
11-02-2004, 08:46 AM
I'm at work now but I'll send you my PNG loader when I get home. :)

- Jeremiah

Battman
11-03-2004, 05:27 AM
Hi Jeremiah,
please send this png loader and zlib to me too: batt2man@yahoo.com
Many thanks,
Battman

Just in case anybody is interested in a PNG file loader, I wrote a PNG file loader that is just one .c file and one .h file. It's small, straightforward, and simple; but only loads 32-bit images (since that what I use). If anybody would like it, Id be glad to share. It does require the ZLIB library (but I have it compiled already if you need it too; as a zlib.o file).

Just sharing...

- Jeremiah :)

keethrus
11-03-2004, 04:15 PM
Hi Jeremiah,
please send this png loader and zlib to me too: batt2man@yahoo.com
Many thanks,
Battman

Just emailed it to you.

- Jeremiah