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

provider_jpeg_generic.h

Go to the documentation of this file.
00001 /*
00002         ------------------------------------------------------------------------
00003         JPEG-SurfaceProvider Class
00004         written by Ingo Ruhnke
00005 
00006         in order to work with
00007         ClanLib, the platform independent game SDK.
00008 
00009         This file is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00010         version 2. See COPYING for details.
00011 
00012         For a total list of contributers see CREDITS.
00013 
00014         ------------------------------------------------------------------------
00015 */
00016 
00017 #ifndef header_provider_jpeg_generic
00018 #define header_provider_jpeg_generic
00019 
00020 #ifdef WIN32
00021 #define XMD_H
00022 #endif
00023 
00024 #include <stdio.h>
00025 extern "C"
00026 {
00027         #include <jpeglib.h>
00028 }
00029 
00030 #include "API/core.h" // todo: include the correct stuff.
00031 #include "API/Display/Display/pixelformat.h"
00032 #include "API/Core/System/clanstring.h"
00033 
00034 class CL_Surface;
00035 class CL_InputSourceProvider;
00036 class CL_Palette;
00037 
00038 class CL_JPEGProvider_Generic
00039 //: Surface provider that can load JPEG (.jpg) files.
00040 {
00041 public:
00042         CL_JPEGProvider_Generic(
00043                 CL_String name, 
00044                 CL_InputSourceProvider *provider = NULL,
00045                 bool transparent=true,
00046                 bool ignore_alphachannel=false);
00047         //: Constructs a surface provider that can read PNG files.
00055 
00056         ~CL_JPEGProvider_Generic();
00057 
00058         unsigned int get_pitch() const { return pitch; }
00059         //: Returns the pitch of the image (bytes per line).
00060 
00061         unsigned int get_width() const { return width; }
00062         //: Returns the width of the image.
00063 
00064         unsigned int get_height() const { return height; }
00065         //: Returns the height of the image.
00066         
00067         unsigned int get_num_frames() const { return 1; }
00068         //: Returns the number of subsprites in the image.
00069 
00070         EPixelFormat get_pixel_format() const { return RGB888; }
00071         //: Returns the pixelformat used by the image.
00072 
00073         CL_Palette *get_palette() const { return NULL; }
00074         //: Returns the palette used by the image. NULL if system palette.
00075 
00076         unsigned int get_src_colorkey() const { return 0; }
00077         //: Returns the transparency color used.
00078 
00079         bool uses_src_colorkey() const { return false; }
00080         //: Returns whether a source colorkey is used.
00081 
00082         bool is_indexed() const { return false; }
00083         //: Returns whether the target uses an indexed color mode or not.
00084         
00085         unsigned int get_red_mask() const;
00086         //: Returns the red color mask used by the target.
00087 
00088         unsigned int get_green_mask() const;
00089         //: Returns the green color mask by the target.
00090 
00091         unsigned int get_blue_mask() const;
00092         //: Returns the blue color mask by the target.
00093 
00094         unsigned int get_alpha_mask() const;
00095         //: Returns the alpha mask by the target.
00096 
00097         void *get_data() const;
00098         //: Returns the image data. Provider must be locked before pointer is valid.
00099 
00100         void perform_lock();
00101         //: Locks the surface provider.
00102 
00103         void perform_unlock();
00104         //: Unlocks the surface provider.
00105 
00106 private:
00107         CL_String filename;
00108         int locked;
00109         
00110         unsigned char *image;
00111 
00112         int pitch;
00113         int width, height;
00114 
00115         int bpp;
00116 
00117         bool transparent, ignore_alphachannel, use_alphapixels;
00118 
00119         unsigned char trans_redcol, trans_greencol, trans_bluecol;
00120 
00121         int pos;
00122 
00123         typedef struct
00124         {
00125                 struct jpeg_source_mgr   pub;           /* public fields */
00126                 CL_JPEGProvider_Generic* jpeg_provider; /* source stream */
00127                 JOCTET *                 buffer;        /* start of buffer */
00128                 boolean                  start_of_file; /* have we gotten any data yet? */
00129         } InputSource_source_mgr;
00130         
00131         typedef InputSource_source_mgr* InputSource_src_ptr;
00132 
00133         // Functions for managing the input handling
00134         static void jpeg_InputSource_src (j_decompress_ptr cinfo, CL_JPEGProvider_Generic* prov); 
00135         static void    init_source (j_decompress_ptr cinfo);
00136         static boolean fill_input_buffer (j_decompress_ptr cinfo);
00137         static void    skip_input_data (j_decompress_ptr cinfo, long num_bytes);
00138         static void    term_source (j_decompress_ptr cinfo);
00139 
00140         CL_InputSourceProvider* input_provider;
00141         CL_InputSource* input_source;
00142 };
00143 
00144 #endif

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