Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

provider_targa.h

Go to the documentation of this file.
00001 /*
00002         $Id: provider_targa.h,v 1.1 2001/03/06 15:09:12 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 
00014         File purpose:
00015                 Targa (.tga) surface provider.
00016 */
00017 
00019 
00020 #ifndef header_targaprovider
00021 #define header_targaprovider
00022 
00023 #include "generic_surfaceprovider.h"
00024 #include "../../Core/IOData/inputsource.h"
00025 #include "../../Core/IOData/inputsource_provider.h"
00026 
00027 class CL_TargaProvider : public CL_SurfaceProvider_Generic
00028 //: Surface provider that can load targa (.tga) files.
00029 {
00030         std::string filename;
00031         bool locked;
00032         unsigned char *file;
00033         int filesize;
00034 
00035         unsigned char *image;
00036 
00037         unsigned short map_length;
00038         unsigned char *color_map;
00039 
00040         unsigned char datatype;
00041 
00042         int pitch, height, no_sprs, trans_col;
00043         int bounding_left, bounding_top, bounding_right, bounding_bottom;
00044         int map_direction_x, map_direction_y;
00045 
00046         unsigned char bpp;
00047 
00048         bool transparent, ignore_alphachannel, use_alphapixels;
00049         unsigned char trans_redcol, trans_greencol, trans_bluecol;
00050 
00051         int pos;
00052 
00053         // returns true if non-transparent pixel read
00054         inline bool read_rgb_16(
00055                 unsigned char *a, 
00056                 unsigned char *b, 
00057                 unsigned char *g, 
00058                 unsigned char *r);
00059         inline bool read_rgb_24(
00060                 unsigned char *a, 
00061                 unsigned char *b, 
00062                 unsigned char *g, 
00063                 unsigned char *r);
00064         inline bool read_rgb_32(
00065                 unsigned char *a, 
00066                 unsigned char *b, 
00067                 unsigned char *g, 
00068                 unsigned char *r);
00069         inline bool read_rgb(
00070                 unsigned char *a, 
00071                 unsigned char *b, 
00072                 unsigned char *g, 
00073                 unsigned char *r);
00074 
00075         void read_from_colormap(unsigned char *a,
00076                                                         unsigned char *b,
00077                                                         unsigned char *g,
00078                                                         unsigned char *r);
00079                                                         
00080 
00081         void read_data();
00082         void read_header(bool read_colormap);
00083 
00084         void read_colormapped();
00085         void read_uncompressed_rgb();
00086         void read_runlength_encoded_colormapped_rgb();
00087         void read_runlength_encoded_rgb();
00088 
00089         CL_InputSourceProvider *provider;
00090         CL_InputSource *input_source;
00091 public:
00092         static CL_Surface *create(
00093                 std::string handle,
00094                 CL_InputSourceProvider *provider, 
00095                 bool transparent=false,
00096                 bool ignore_alphachannel=false,
00097                 unsigned char trans_red=0, 
00098                 unsigned char trans_green=0, 
00099                 unsigned char trans_blue=0);
00100 
00101         //: Loads the targa file 'handle' from the inputsource provider 'provider. 
00102         //: Creates a CL_Surface using the targa image and returns it.
00103         //: If you just want to load a file, use 'handle' for filename, and set provider to NULL
00104         CL_TargaProvider(
00105                 std::string name,
00106                 CL_InputSourceProvider *provider,
00107                 bool transparent=false,
00108                 bool ignore_alphachannel=false,
00109                 unsigned char trans_red=0, 
00110                 unsigned char trans_green=0, 
00111                  unsigned char trans_blue=0);
00112 
00113         //: Constructs a surface provider that can read targa files.
00121 
00122         virtual ~CL_TargaProvider();
00123 
00124         virtual unsigned int get_pitch() const { return pitch*4; }
00125         //: Returns the pitch of the image (bytes per line).
00126 
00127         virtual int get_translate_x() const { return bounding_left; }
00128         //: Returns how many pixels to translate the image (X axis).
00129 
00130         virtual int get_translate_y() const { return bounding_top; }
00131         //: Returns how many pixels to translate the image (Y axis).
00132 
00133         virtual unsigned int get_width() const { return bounding_right-bounding_left+1; }
00134         //: Returns the width of the image.
00135 
00136         virtual unsigned int get_height() const { return bounding_bottom-bounding_top+1; }
00137         //: Returns the height of the image.
00138         
00139         virtual unsigned int get_num_frames() const { return no_sprs; }
00140         //: Returns the number of subsprites in the image.
00141 
00142         virtual unsigned int get_depth() const { return 32; }
00143         //: Returns the pixelformat used by the image.
00144         
00145         virtual unsigned int get_red_mask() const   { return 0xff000000; }
00146         virtual unsigned int get_green_mask() const { return 0x00ff0000; }
00147         virtual unsigned int get_blue_mask() const  { return 0x0000ff00; }
00148         virtual unsigned int get_alpha_mask() const { if ((!transparent) && (ignore_alphachannel)) return 0x0; else return 0x000000ff; }
00149         
00150         virtual bool is_indexed() const { return false; }
00151 
00152         virtual CL_Palette *get_palette() const { return NULL; }
00153         //: Returns the palette used by the image. NULL if system palette.
00154 
00155         virtual bool uses_src_colorkey() const { return trans_col != -1; }
00156 
00157         virtual unsigned int get_src_colorkey() const { return trans_col; }
00158         //: Returns the transparency color used, -1 if none.
00159 
00160         virtual void *get_data() const;
00161         //: Returns the image data. Provider must be locked before pointer is valid.
00162 
00163         virtual void perform_lock();
00164         //: Locks the surface provider.
00165 
00166         virtual void perform_unlock();
00167         //: Unlocks the surface provider.
00168 
00169 };
00170 
00171 #endif

Generated at Wed Apr 4 19:54:02 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001