PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Image loader class

Hi all,

I've made an image loader and plan to release it for free, but I first need your help in testing it.

The purpose of the loader is to provide PocketHal users with a free and versatile loader. The main features are that it supports jpeg, png and bmp files without any dependencies on dlls or anything else. It works on PocketPC or desktop.

It can also correctly handle alpha channels in PNG and BMP files. For a list of all formats, see the formats.txt file in the zip file. And to conserve memory all images are loaded line by line, which requires very little space.

If anyone wants to help me, simply copy the content of the zip file to your ARM PPC. Place any images you have in the "Screens" directory and run the viewer.exe file.

Use the d-pad to move between images, use the stylus to move the image around, press button A to toggle the alpha channel on/off and button B to exit.

I included an image with alpha channel. Simply press button A to toggle it and see what it does. But I would like to know if it works with YOUR images in the formats I listed above. If it cannot load an image, you'll get a red screen.

Email any pictures that don't display properly or not at all to me and I'll fix the loader. Once Everything works as it should, I'll make it available in .LIB form. I already tested it with thousands of images, but my images are not your images.

If you use a format that is not listed, please let me know and I'll see what I can do.

Thanks, and any comments are welcome.

--Eric Fortier
efortier@techlogic.ca
Attachments:
viewer.zip (237 KB)
efortier wrote:

If you use a format that is not listed, please let me know and I'll see what I can do.

Thanks, and any comments are welcome.



Hello Eric,

If anyone want to use any kind of compressed archive containing all the data files of a game you should consider enabling your loader to work by passing a pointer to the file in memory, you should also add the support for TGA.

TGA is a very versatile and easy to read format, and it's not compressed, so it's useful when you want to use a compressed archive (no need to uncompress 2x).

TGA supports paletized images (8bits), hicolor (15bits), true color (24bits) and alpha channel (24 + 8 = 32bits).

A zipped or gzipped TGA is similar as a PNG if you look the compression ratio.

Also, you may want to add a dithering option to avoid the infamous banding effect when loading jpeg or >16bits per pixel images... ("bayer ordered" is the best algo for this job)

And it could be useful for the community to have a complete game oriented portable file loader, not only images but also binary files and .wav etc...

I've done all that for the int13 internal game engine and it's very useful.
Hi Steph,

Thanks for the comments. Loading from memory is definately on my list, and I'll add TGA.

As for dithering, I'm pretty sure I won't include that in the loader. Since the loader mainly deals with scanlines, dithering and other image processing will have to be offloaded to the user app.

My goal isn't to make something that will fix all, but rather provide a useful tool for people to build on.

And it could be useful for the community to have a complete game oriented portable file loader, not only images but also binary files and .wav etc...

I'm not sure I follow. Do you mean like an archive from which people could extract files?

--Eric

I'm not sure I follow. Do you mean like an archive from which people could extract files?


To write portable games it's necessary to not be dependant on function like fopen etc, because they are not supported on many platforms.
This is pretty cool, i just tested it out with images I use inside my GapiDraw games(almost all PNG's) and it works just fine for me. I am going to test out some more random pictures just for fun.

I was wondering, does this loader get rid of the double the filesize memory requirement for loading images?
errr forgot to log in.

Im writing an input class right now that will hopefully have direct X functionality to add to the community project. I am currently trying to decide how I can do this so it will support as many keys as you want..... What do you think about having a CKey class that you could then declare as many virtual buttons as you wanted with any name such as:


CKey UP;
CKey Down;
CKey Fire;

Im just trying to come up with ideas...
Anonymous wrote:I was wondering, does this loader get rid of the double the filesize memory requirement for loading images?


Yes it does. This was my second goal when writing the class. The first one was that it had to be easy to use by providing a single type of output for all type of images (ie: RGB, no palette).

I'm glad someone finally decided to try it ;)

Thanks, and let me know if you have any problems.

-Eric
StephC wrote:
Hello Eric,

If anyone want to use any kind of compressed archive containing all the data files of a game you should consider enabling your loader to work by passing a pointer to the file in memory, you should also add the support for TGA.


I'm using TGAs for my game (including alpha channel support), and then LZ-compress all my data files (which are packed into one big .wad-type file)

Not compared the data sizes to PNG, but it seems to compress quite well. I try to use 8bpp images whenever the alpha channel isn't needed

It was a very simple but effective solution compared to dealing with uber-complex image file formats (PNG or JPG), or using 3rd-party libs that would make it very hard to port to Symbian (and maybe PalmOS in the future)

(If you're looking for some data compression code, it's worth taking a look at BriefLZ from www.ibsensoftware.com. Very compact, portable, and easy to use, and with a suitable licence for most uses)
Is there something special I'm supposed to do with this program? The screen goes black for a second, then quits on my ipaq3835. You don't happen to be using an old version of PHal?
bluescrn wrote:
(If you're looking for some data compression code, it's worth taking a look at BriefLZ from www.ibsensoftware.com. Very compact, portable, and easy to use, and with a suitable licence for most uses)


Good, thanks for the link.

For now I use the zlib dll to uncompress my "data.pak", but I plan to replace it by a faster solution, one day....
Thanks a lot for trying this test viewer.

I'm currently using 0.5.

Here's an updated viewier. Now, here is what it will do:

If Initialize() fails, it will quit immediately. Evidently, there's not much I can do about it.

If GetBackBuffer() or Swap() fails, the screen will stay black but the viewer won't quit. Press button B to quit.

If all goes well with PHAL but the viewer cannot find the images in the Screen directory, the screen will turn blue and a message will be shown.

If while trying to load an image the surface cannot be created correctly, the screen will turn green.

And if all is fine with the above but an image cannot be loaded correctly, the screen will be red with the name of the image displayed.

I hope you can try this new one and report your findings.

Thanks!

--Eric
Attachments:
viewer2.zip (96 KB)
I'm an idiot, it works like a champ. Good work.
efortier wrote:

And if all is fine with the above but an image cannot be loaded correctly, the screen will be red with the name of the image displayed.



Why don't you create an error log ? (a file)
StephC wrote:
Good, thanks for the link.

For now I use the zlib dll to uncompress my "data.pak", but I plan to replace it by a faster solution, one day....


My approach is to compress all files in my "data.pak" equivalent individually, then decompress them on my 'fopen' and free that temporary storage space on my 'fclose'. Are you doing the same?

The C version of the BreifLZ decompressor isn't ultra-fast (optimized x86 versions are provided, not much use for PPC dev though) but it's quick enough for most uses. Its main advantages are the very small size of the decompression code, a simple interface, and portability (it worked first time on my Symbian build)
Hi Eric,

Do u want to donate .PNG loader code? I'm writing my own graphics library that sits on top of GX and I want to support .PNG format.

Thanks :-)
bluescrn wrote:

My approach is to compress all files in my "data.pak" equivalent individually, then decompress them on my 'fopen' and free that temporary storage space on my 'fclose'. Are you doing the same?



Yes.

I just added a cache layer on top of the zlib, and I use a prefix "*" to the name of the files to force the loader to search in the current directory and not in the compressed archive.

LZbrief seem very well written and concice, it could be rewritten in optimized ARM assembly in a few hours I think.
denthorq wrote:Do u want to donate .PNG loader code? I'm writing my own graphics library that sits on top of GX and I want to support .PNG format.
Hi!

The PNG code is not mine, I'm just using libpng. I thought it was hard at first, but after reading the manual it's pretty straightforward to use. Be sure to test it against the formats you want to support, because there are tons of flags you can set.

So, you'll need to have libjpng compiled on your target platforms as a prerequisite. Also zlib since libjpng uses that. After that it's just a matter of opening the file, setting up libjpng and getting the image.

Same thing for jpegs.

Email me if you need help. And do tell me about your library!

--Eric
efortier@techlogic.ca
Andy wrote:I'm an idiot, it works like a champ. Good work.

;) Thanks for trying it! I'm glad to see it works.

--Eric