icculus.org/quake3 PNG patch
This patch adds support for PNG images to icculus.org/quake3.
It doesn't need any external libraries. The PNG parser was written by myself
so no libpng is needed. The zlib decompression is done by the puff() function,
a small, self-contained inflate implementation from the contrib directory
of the official zlib distribution.
Supported PNG features :
All currently specified PNG image types are supported : grey, truecolour, indexed,
grey with alpha channel and truecolour with alpha channel.
All bit depths are supported : 1, 2, 4, 8, 16 bits.
Alpha channels and the simpler transparency are supported.
All currently specified compression methods are supported, as there is only one : zlib compression.
All currently specified filter methods and filter types are supported.
Interlaced and non interlaced PNG images are supported.
Unsupported PNG features :
Ancillary chunks like colour space information, gamma value, ICC profiles,
background colour, text comments and so on are ignored
because these are not really necessary or supported by icculus.org/quake3.
CRC hashes are ignored, but it would be easy to support them.
On the other hand the files are checked by Quake 3 itself, so we do not really need these CRCs.
Testing :
The PNG parser was tested with the testsuite from the PNG project.
It loaded all valid PNGs and ignored the corrupted ones without crashing.
The PNG support in icculus.org/quake3 was tested with a modified demo pak0
where all TGA and JPG textures where converted to PNG.
On the following systems the programm compiled and run flawlessly :
Athlon XP 2500+ : Windows 2000, binary compiled with MinGW
Athlon XP 2500+ : SuSE Linux 10.0, binary compiled with GCC 4.0
Pentium 4 3000 MHz : SuSE Linux 10.1, binary compiled with GCC 4.1, with and without SMP support
Pentium 4 3000 MHz : Windows XP SP2, same binary as above
Mac mini G4 1250 MHz : MacOS X 10.4, compiled with official GCC 4.0
All other systems and compilers are untested by me.
64 bit systems are untested too but should work, I took the necessary precautions.
Big and little endian systems are recognized and handled correctly.
Compiling :
To use the PNG support of icculus.org/quake3 you need to compile it in
(or find a prebuild binary with PNG support).
The PNG support is protected by the define USE_IMAGELOADER_PNG.
Set this define to 1 in the Makefile and recompile the programm.
Attention : If you use a build system other than the official Makefile
you have to add the define USE_IMAGELOADER_PNG by yourself.
The puff() function is not protected by USE_IMAGELOADER_PNG
because it could be used by other functions for zlib inflation.
Mapping :
The current GtkRadiant 1.5.0 Beta and q3map2 2.5.16 support PNG images out of the box.
But as there was no PNG support in Quake 3 up until now, GtkRadiant is configured to
ignore PNG images when mapping for Quake 3. To change this behaviour open the file
'q3.game' in the 'games' directory of the GtkRadiant base directory with an editor
and change the line :
texturetypes="tga jpg"
to
texturetypes="tga jpg png"
Restart GtkRadiant and your shiny new PNG textures are now available.
Converting old TGA or JPG textures to PNG :
Quake 3 tries to load the JPG image of the same name when it can't find the original TGA.
I have expanded this mechanism and now it tries to load the PNG too.
So you can convert all of your JPG and TGA textures to PNG images.
Attention : Textures for MD3 models don't work anymore when converted to PNG.
Changed or new files :
The following files were added :
code/qcommon/puff.c - small in-memory inflate function from zlib
code/qcommon/puff.h - header file for puff.c
The following files were changed :
code/renderer/tr_image.c - added PNG support : LoadPNG()
Makefile - added PNG support for every supported client
Copyright and License :
The PNG loader is Copyright (C) 2006 Joerg Dietrich.
It is licensed under the GNU GENERAL PUBLIC LICENSE.
The files code/qcommon/puff.c and code/qcommon/puff.h are Copyright (C) 2002-2004 Mark Adler.
These are licensed under the zlib license : http://www.gzip.org/zlib/zlib_license.html .
The zlib license is compatible with the GPL as stated by the FSF : http://www.gnu.org/licenses/license-list.html .
Nice work (though I didn't test it yet).
I guess the earliest time of inclusion would be after ioq3 1.34 has been released. Of course, I don't have the final word about this.
Comment 3Zachary J. Slater
2006-05-31 21:13:01 EDT
After 1.34, for sure.
Comment 4Zachary J. Slater
2007-01-23 15:40:08 EST
I just tested the patch against the current svn trunk.
It still applies flawlessly and compiles and runs whitout problems.
IMHO we should include it in the project as like the Ogg patch.
It is not patent encumbered like the MP3 patch or changes the
gameplay as forbidden in NOTTODO.
This patch would give Mod- and Standalone developers the
ability to include lossless compressed textures in their
projects. The users could always upgrade to a newer version
of the engine without much patching.
Setting a QA contact on all ioquake3 bugs, even resolved ones. Sorry if you get a flood of email from this, it should only happen once. Apologies for the incovenience.
--ryan.
Nice to see my patch applied :)
But!
Tim left out the "hack" that loads the PNG if it
can't find a TGA or JPG with the images name.
This is no problem as long as the PNG-image has
a shader which specifies the image name with the
.png extension.
But this doesn't work with images without shaders
because GtkRadiant and Q3Map2 strip out the
extensions in the MAP- and BSP-files.
What do we do now?
Joerg
Created attachment 916 [details] the actual PNG image loader patch