Manual
- Setting up Titan
- Loading an image to a surface
- Saving a surface/console to a file
- Loading an animation
- Saving an animation
- Adding a new Image/Anim handler
- File formats
Setting up Titan
Refer to docs/win32.txt, docs/linux.txt or docs/dos.txt depending on your platform.
Loading an image to a surface
Loading an image is simple. Just create an Image object, then call the copy function.
Image *loader; // Pointer to an Image object
loader = new Image("picture.jpg"); // Inititalise object and load picture.jpg
loader->copy(mysurface); // copy the image to a PTC Surface
delete loader; // Remove the Image object from memory
The Image object holds a copy of the picture in memory. This means that you can copy it to as many Surfaces as you like without loading it from a file every time. This does use up memory though, and the object should be deleted after you have finished with it.
Saving a surface/console to a file
Saving an image is almost as easy as loading one. Again, you create an Image object, and call the save function.
Image *saver; // Pointer to an Image object
saver = new Image(); // Initialise object
saver->save("picture.png",mysurface,PNG,NULL); // Save image
delete saver; // Remove the Image object from memory
The PNG means that this file will be saved as a Png file. Each file format has it's own #define in /source/contents.h to allow you to save to each format. Normally this #define will be the same as the file extension (3 letters).
The final parameter allows you to change the default settings for that file format. These settings control things like whether to compress the data or not, adding comments or the quality of the file. To use your own settings, you would pass in a Param structure like this -
PNGParams params; // Allocate a Param structure for Png files
PNGParamDefaults(&params); // Set structure to default values
params.interlaced = true; // Change some settings
saver->save("picture.png",mysurface,PNG,&params); // Save image
Loading an animation
Wait for Titan 1.2
Saving an animation
Wait for Titan 1.2
Adding a new Image/Anim handler
Not completely done yet.
Note. in these examples, I shall use a file extension of IMG and assume you are adding an image handler. Replace this with whatever extension you use.
If you use your own image format, you can easily add support for it to Titan. In the /source/image directory there are some template files. Copy these to files of the correct name (e.g. img.h/img.cc for a *.img loader). Within these files are a rough outline of what needs to be in a handler. Follow the comments and you should be able to get your code put in correctly. Then, you need to edit some of the other source files -
/source/contents.h - Add USE_IMG and IMG to the other #defines.
/source/image/idefault.cc - If you have saving support, add an IMGParamDefaults function.
/source/image/idefault.h - If you have saving support, add the IMGParamDefaults prototype and IMGParams structure.
/source/image/image.cc - Add the #ifdef/#define USE_IMG/#endif block near the top. In the Image::open function, add another #ifdef block to make load check for your file format. In the Image::save function, do the same.
makefiles - Add img.h and img.cc to the makefiles in /source/image or, for win32 users, the VC++ project in the same locations
Recompiling the Titan project/makefiles should add your file handler to Titan and allow it to be used.
This page © 1999 Dan Brown
The latest version of Titan can be found at http://now.at/Titan