Scaler.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2004  Ryan Nunn and The Pentagram Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef SCALER_H_INCLUDED
00020 #define SCALER_H_INCLUDED
00021 
00022 #include "Texture.h"
00023 #include "RenderSurface.h"
00024 #include "ScalerManager.h"
00025 
00026 namespace Pentagram {
00027 
00029 class Scaler
00030 {
00031 protected:
00032         // Basic scaler function template
00033         typedef bool (*ScalerFunc) ( Texture *tex, sint32 sx, sint32 sy, sint32 sw, sint32 sh, 
00034                                         uint8* pixel, sint32 dw, sint32 dh, sint32 pitch, bool clamp_src);
00035 
00036         //
00037         // Basic scaler functions (filled in by the scalers constructor)
00038         //
00039         ScalerFunc      Scale16Nat;
00040         ScalerFunc      Scale16Sta;
00041 
00042         ScalerFunc      Scale32Nat;
00043         ScalerFunc      Scale32Sta;
00044         ScalerFunc      Scale32_A888;
00045         ScalerFunc      Scale32_888A;
00046 
00047         Scaler() { ScalerManager::get_instance()->AddScaler(this); }
00048 public:
00049         //
00050         // Scaler Capabilites
00051         //
00052 
00053         virtual const uint32    ScaleBits() const = 0;                  //< bits for supported integer scaling
00054         virtual const bool              ScaleArbitrary() const = 0;             //< supports arbitrary scaling of any degree 
00055 
00056         virtual const char *    ScalerName() const = 0;                 //< Name Of the Scaler (1 word)
00057         virtual const char *    ScalerDesc() const = 0;                 //< Desciption of the Scaler
00058         virtual const char *    ScalerCopyright() const = 0;    //< Scaler Copyright info
00059 
00060         //
00061         // Maybe one day... for now we just grab everything from RenderSurface
00062         // virtual bool SetDisplayFormat(const RenderSurface::Format &format);
00063 
00064         // Call this to scale a section of the screen
00065         inline bool Scale(      Texture *texture, sint32 sx, sint32 sy, sint32 sw, sint32 sh, 
00066                                                 uint8* pixel, sint32 dw, sint32 dh, sint32 pitch, bool clamp_src) const
00067         {
00068                 // Check to see if we are doing valid integer scalings
00069                 if (!ScaleArbitrary())
00070                 {
00071                         uint32 scale_bits = ScaleBits();
00072                         int x_factor = dw/sw;
00073                         int y_factor = dh/sh;
00074 
00075                         // Not integer
00076                         if ((x_factor*sw)!=dw || (y_factor*sh)!=dh) return false;
00077 
00078                         // Don't support this
00079                         if (!(scale_bits & (1<<x_factor))) return false;
00080 
00081                         // Don't support this
00082                         if (!(scale_bits & (1<<y_factor))) return false;
00083                 }
00084 
00085                 if (RenderSurface::format.s_bytes_per_pixel == 4) 
00086                 {
00087                         if (texture->format == TEX_FMT_NATIVE || (texture->format == TEX_FMT_STANDARD && 
00088                                 RenderSurface::format.a_mask == TEX32_A_MASK && RenderSurface::format.r_mask == TEX32_R_MASK && 
00089                                 RenderSurface::format.g_mask == TEX32_G_MASK && RenderSurface::format.b_mask == TEX32_B_MASK))
00090                         {
00091                                 if (RenderSurface::format.a_mask == 0xFF000000)
00092                                 {
00093                                         if (!Scale32_A888) return 0;
00094                                         return Scale32_A888(texture,sx,sy,sw,sh,pixel,dw,dh,pitch,clamp_src);
00095                                 }
00096                                 else if (RenderSurface::format.a_mask == 0x000000FF)
00097                                 {
00098                                         if (!Scale32_888A) return 0;
00099                                         return Scale32_888A(texture,sx,sy,sw,sh,pixel,dw,dh,pitch,clamp_src);
00100                                 }
00101                                 else 
00102                                 {
00103                                         if (!Scale32Nat) return 0;
00104                                         return Scale32Nat(texture,sx,sy,sw,sh,pixel,dw,dh,pitch,clamp_src);
00105                                 }
00106                         }
00107                         else if (texture->format == TEX_FMT_STANDARD)
00108                         {
00109                                 if (!Scale32Sta) return 0;
00110                                 return Scale32Sta(texture,sx,sy,sw,sh,pixel,dw,dh,pitch,clamp_src);
00111                         }
00112                 }
00113                 if (RenderSurface::format.s_bytes_per_pixel == 2) 
00114                 {
00115                         if (texture->format == TEX_FMT_NATIVE)
00116                         {
00117                                 if (!Scale16Nat) return 0;
00118                                 return Scale16Nat(texture,sx,sy,sw,sh,pixel,dw,dh,pitch,clamp_src);
00119                         }
00120                         else if (texture->format == TEX_FMT_STANDARD)
00121                         {
00122                                 if (!Scale16Sta) return 0;
00123                                 return Scale16Sta(texture,sx,sy,sw,sh,pixel,dw,dh,pitch,clamp_src);
00124                         }
00125                 }
00126 
00127                 return false;
00128         }
00129 
00130         virtual ~Scaler() { }
00131 };
00132 
00133 }
00134 
00135 #endif

Generated on Fri Jul 27 22:27:33 2007 for pentagram by  doxygen 1.4.7