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

surfaceprovider_32bpp.h

Go to the documentation of this file.
00001 /*
00002         Class:   CL_SurfaceProvider_32bpp
00003 
00004         Purpose: Convert to RGBA8888 to ensure support for colorkeying.
00005 
00006         old old old old old old old old old old old old old old old old old old 
00007         Purpose: Convert a PAL8 surface provider to 16 bpp. This is needed since
00008                  Hermes doesn't support colorkeys (atleast not when this code
00009                  was written).
00010 */
00011 
00012 #ifndef header_surfaceprovider_32bpp
00013 #define header_surfaceprovider_32bpp
00014 
00015 #include "API/Display/Display/display.h"
00016 #include "API/Display/Display/surfaceprovider.h"
00017 #include "API/Display/Display/palette.h"
00018 #include "API/Core/System/cl_assert.h"
00019 
00020 class CL_SurfaceProvider_32bpp : public CL_SurfaceProvider
00021 {
00022 public:
00023         CL_SurfaceProvider_32bpp(CL_SurfaceProvider *src)
00024         {
00025                 src->lock();
00026                 cl_assert(src->get_depth() == 8 || src->get_depth() == 32);
00027 
00028                 m_width = src->get_width();
00029                 m_height = src->get_height();
00030                 m_no_sprs = src->get_num_frames();
00031                 unsigned int pitch = src->get_pitch();
00032                 int transcol = src->uses_src_colorkey() ? (int) src->get_src_colorkey() : -1;
00033 /*              
00034                 CL_Palette *pal = src->get_palette();
00035                 if (pal == NULL) pal = CL_Display::get_palette();
00036 
00037                 int pitch = src->get_pitch();
00038                 int transcol = src->get_src_colorkey();
00039                 unsigned char *ptr = (unsigned char *) src->get_data();
00040 */
00041                 m_data = new unsigned int[pitch*m_height*m_no_sprs];
00042                 
00043                 switch (src->get_depth())
00044                 {
00045                         case 8:
00046                         {
00047                                 unsigned char *ptr = (unsigned char *) src->get_data();
00048 
00049                                 CL_Palette *pal = src->get_palette();
00050                                 if (pal == NULL) pal = CL_Display::get_palette();
00051         
00052                                 for (int y=0; y<m_height*m_no_sprs; y++)
00053                                 {
00054                                         for (int x=0; x<m_width; x++)
00055                                         {
00056                                                 int color = ptr[x+y*pitch];
00057                         
00058                                                 m_data[x+y*m_width] =
00059                                                         (pal->palette[color*3+0] << 24) +
00060                                                         (pal->palette[color*3+1] << 16) +
00061                                                         (pal->palette[color*3+2] << 8);
00062                                 
00063                                                 // Set alphamask according to transparency
00064                                                 if (transcol == -1 || color != transcol)
00065                                                 {
00066                                                         m_data[x+y*m_width] += 255;
00067                                                 }
00068                                         }
00069                                 }
00070                                 break;
00071                         }
00072                         
00073                         case 32:
00074                         {
00075                                 unsigned int *ptr = (unsigned int *) src->get_data();
00076 
00077                                 for (int y=0; y<m_height*m_no_sprs; y++)
00078                                 {
00079                                         for (int x=0; x<m_width; x++)
00080                                         {
00081                                                 // BUG: possible pitch problem - but only theoretically
00082                                                 int color = ptr[x+y*m_width];
00083                                                 m_data[x+y*m_width] = color;
00084                                 
00085                                                 // Set alphamask according to transparency
00086                                                 if (transcol == -1 || color != transcol)
00087                                                 {
00088                                                         m_data[x+y*m_width] |= 255;
00089                                                 }       
00090                                         }
00091                                 }
00092                                 break;
00093                         }
00094                         default :
00095                                 cl_assert(false);
00096                 }
00097                 src->unlock();
00098         }
00099 
00100         virtual ~CL_SurfaceProvider_32bpp()
00101         {
00102                 delete[] m_data;
00103         }
00104 
00105         virtual unsigned int get_pitch() const { return m_width*sizeof(int); }
00106         virtual unsigned int get_width() const { return m_width; }
00107         virtual unsigned int get_height() const { return m_height; }
00108         virtual unsigned int get_num_frames() const { return m_no_sprs; }
00109         virtual unsigned int get_depth() const { return 32; }
00110         virtual unsigned int get_red_mask() const { return 0xff000000; }
00111         virtual unsigned int get_green_mask() const { return 0x00ff0000; }
00112         virtual unsigned int get_blue_mask() const { return 0x0000ff00; }
00113         virtual unsigned int get_alpha_mask() const { return 0x000000ff; }
00114         virtual bool is_indexed() const { return false; }
00115 
00116         virtual CL_Palette *get_palette() const { return NULL; }
00117         virtual void lock() { return; }
00118         virtual void unlock() { return; }
00119         virtual void *get_data() const { return m_data; }
00120         virtual bool uses_src_colorkey() const { return false; }
00121         virtual unsigned int get_src_colorkey() const { return 0; }
00122         
00123 protected:
00124         unsigned int *m_data;
00125         int m_width, m_height, m_no_sprs;
00126 };
00127 
00128 #endif

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