00001 /* 00002 $Id: provider_pcx.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 PCX surface provider. 00016 */ 00017 00019 00020 #ifndef header_pcxprovider 00021 #define header_pcxprovider 00022 00023 #include "generic_surfaceprovider.h" 00024 #include "../Display/pixelformat.h" 00025 00026 class CL_PCXProvider : public CL_SurfaceProvider_Generic 00027 //: Surface provider that can load PCX files. 00028 //: 00029 //: The PCX decoder has been modified to load most PCX files 00030 //: (instead of just the ones created by Deluxe Paint IIe). 00031 //: It now support 1,2,4,8, or 24 bit files... and has been tested 00032 //: in all but a few situations. 00033 //: 00034 //: Technically, the implementation cheats in that it doesnt 00035 //: store images with less than 8 bits per pixel in their 00036 //: native format. It simply converts them to PAL8 00037 //: pixelformat instead of creating other pixelformats. 00038 //: 00039 //: Also note that the PCX decoder creates more bytes per 00040 //: line than the image is supposed to contain. We rely on the clipping 00041 //: capabilities of ClanLib to take care of that. Also note that some 00042 //: default palettes were defined in the read_header() method. These 00043 //: definitions might be better placed in palette.h. Since the scope of 00044 //: the PCX_Provider rewrite was limited to the provider itself, no files 00045 //: outside of pcx_provider.h and pcx_provider.cpp were modified. 00046 //: 00047 //: The PCX decoding code was moved to read_data() and read_header() 00048 //: to make it easier to follow the code (called from perform_unlock()). 00049 //: 00050 //: There is a chance the transparency is broken now... It is untested. 00051 { 00052 public: 00053 static CL_Surface *create( 00054 std::string handle, 00055 CL_InputSourceProvider *provider, 00056 bool transparent=false, 00057 unsigned char trans_col=0); 00058 //: Loads the pcx file 'handle' from the inputsource provider 'provider. 00059 //: Creates a CL_Surface using the pcx image and returns it. 00060 //: If you just want to load a file, use 'handle' for filename, and set provider to NULL 00061 00062 CL_PCXProvider( 00063 std::string name, 00064 CL_InputSourceProvider *provider, 00065 bool transparent=false, 00066 unsigned char trans_col=0); 00067 //: Constructs a surface provider that can read pcx files. 00072 00073 virtual ~CL_PCXProvider(); 00074 00075 virtual unsigned int get_pitch() const { return pitch; } 00076 //: Returns the pitch of the image (bytes per line). 00077 00078 virtual int get_translate_x() const { return bounding_left; } 00079 //: Returns how many pixels to translate the image (X axis). 00080 00081 virtual int get_translate_y() const { return bounding_top; } 00082 //: Returns how many pixels to translate the image (Y axis). 00083 00084 virtual unsigned int get_width() const { return bounding_right-bounding_left; } 00085 //: Returns the width of the image. 00086 00087 virtual unsigned int get_height() const { return bounding_bottom-bounding_top; } 00088 //: Returns the height of the image. 00089 00090 virtual unsigned int get_num_frames() const { return 1; } 00091 //: Returns the number of subsprites in the image. 00092 /* 00093 virtual EPixelFormat get_pixel_format() const; 00094 //: Returns the pixelformat used by the image. 00095 */ 00096 virtual unsigned int get_red_mask() const; 00097 virtual unsigned int get_green_mask() const; 00098 virtual unsigned int get_blue_mask() const; 00099 virtual unsigned int get_alpha_mask() const; 00100 virtual unsigned int get_depth() const; 00101 00102 virtual CL_Palette *get_palette() const { return palette; } 00103 //: Returns the palette used by the image. NULL if system palette. 00104 00105 virtual bool is_indexed() const { return true; } 00106 00107 virtual bool uses_src_colorkey() const { return trans_col != -1; } 00108 00109 virtual unsigned int get_src_colorkey() const { return trans_col; } 00110 //: Returns the transparency color used, -1 if none. 00111 00112 virtual void *get_data() const { return image+bounding_left+bounding_top*pitch; } 00113 //: Returns the image data. Provider must be locked before pointer is valid. 00114 00115 virtual void perform_lock(); 00116 //: Locks the surface provider. 00117 00118 virtual void perform_unlock(); 00119 //: Unlocks the surface provider. 00120 00121 virtual void read_header(CL_InputSource *_datafile); 00122 //: Loads header data into class variables. Called by read_data(). 00123 00124 virtual void read_data(); 00125 //: Decodes image data 00126 00127 00128 private: 00129 //PCX specific variables 00130 int num_planes; //number of color planes in file data 00131 int dest_num_planes; //number of color planes in final image format 00132 int size_data; //size of data in file 00133 unsigned char pcx_version, bits_per_pixel_per_plane; 00134 int decode_pitch; //bytes to decode per scanline (different than pitch) 00135 int bytes_to_allocate; //bytes to allocate for decoding process. 00136 //This is not necessarily the same as the image size. 00137 00138 //Surface Provider variables 00139 CL_InputSourceProvider *provider; 00140 int pitch; //bytes per scanline in decoded image 00141 int height; 00142 int bounding_left, bounding_top, bounding_right, bounding_bottom; 00143 bool transparent; 00144 int trans_col; 00145 std::string name; 00146 EPixelFormat pixelformat; 00147 00148 CL_Palette *palette; 00149 unsigned char *image; 00150 }; 00151 00152 #endif
1.2.6 written by Dimitri van Heesch,
© 1997-2001