00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00022
00023 #ifndef header_PNGprovider
00024 #define header_PNGprovider
00025
00026 #include "../Display/Display/pixelformat.h"
00027 #include "../Display/SurfaceProviders/generic_surfaceprovider.h"
00028 #include "../Core/System/clanstring.h"
00029 #include "../Core/System/cl_assert.h"
00030 #include "../Core/IOData/inputsource.h"
00031 #include "../Core/IOData/inputsource_provider.h"
00032
00033 #include <png.h>
00034
00035 class CL_PNGProvider : public CL_SurfaceProvider_Generic
00036
00037 {
00038 public:
00039 CL_InputSource* get_input_source() {return input_source; };
00040
00041
00042
00043 static CL_Surface* create(CL_String handle,
00044 CL_InputSourceProvider* provider=NULL,
00045 bool transparent=true,
00046 bool ignore_alphachannel=false);
00047
00048
00049
00050
00051 CL_PNGProvider(CL_String name,
00052 CL_InputSourceProvider *provider = NULL,
00053 bool transparent=true,
00054 bool ignore_alphachannel=false);
00055
00063
00064 virtual ~CL_PNGProvider();
00065
00066 virtual unsigned int get_pitch() const { return pitch; }
00067
00068
00069 virtual unsigned int get_width() const { return width; }
00070
00071
00072 virtual unsigned int get_height() const { return height; }
00073
00074
00075 virtual unsigned int get_num_frames() const { return 1; }
00076
00077
00078 virtual EPixelFormat get_pixel_format() const { return pixel_format; }
00079
00080
00081 virtual CL_Palette *get_palette() const { return palette; }
00082
00083
00084 virtual unsigned int get_src_colorkey() const { return trans_col; }
00085
00086
00087 virtual bool uses_src_colorkey() const { return m_uses_src_colorkey; }
00088
00089
00090 virtual bool is_indexed() const { return true; }
00091
00092
00093 virtual unsigned int get_red_mask() const;
00094
00095
00096 virtual unsigned int get_green_mask() const;
00097
00098
00099 virtual unsigned int get_blue_mask() const;
00100
00101
00102 virtual unsigned int get_alpha_mask() const;
00103
00104
00105 virtual unsigned int CL_PNGProvider::get_depth() const;
00106
00107
00108 virtual void* get_data() const;
00109
00110
00111 virtual void perform_lock();
00112
00113
00114 virtual void perform_unlock();
00115
00116
00117 static void pngread_file(png_structp png_ptr,
00118 png_bytep data,
00119 png_size_t length)
00120
00121
00122 {
00123
00124 CL_PNGProvider *instance = (CL_PNGProvider *)png_get_io_ptr(png_ptr);
00125
00126
00127
00128
00129 unsigned int read_length = instance->get_input_source ()->read(data, length);
00130 cl_assert (read_length == length);
00131 }
00132
00133 private:
00134 CL_String filename;
00135 int locked;
00136
00137 bool m_uses_src_colorkey;
00138
00139 unsigned char *image;
00140 int pitch;
00141 int no_sprs;
00142 int width;
00143 int height;
00144
00145 EPixelFormat pixel_format;
00146
00147 bool transparent;
00148 bool ignore_alphachannel;
00149
00150 CL_Palette* palette;
00151 bool indexed;
00152 int trans_col;
00153 int color_type;
00154 unsigned char trans_redcol, trans_greencol, trans_bluecol;
00155
00156 void read_data();
00157 void read_data_rgb();
00158 void read_data_rgba();
00159 void read_data_grayscale();
00160 void read_data_grayscale_alpha();
00161 void read_data_palette();
00162
00163 CL_InputSourceProvider *provider;
00164 CL_InputSource *input_source;
00165
00166
00167 png_structp png_ptr;
00168 png_infop info_ptr;
00169 png_infop end_info;
00170
00171 };
00172
00173 class CL_SetupPNG
00174 {
00175 public:
00176 static void init();
00177 static void deinit();
00178 };
00179
00180 #endif