00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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
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
00051
00052
00053 virtual const uint32 ScaleBits() const = 0;
00054 virtual const bool ScaleArbitrary() const = 0;
00055
00056 virtual const char * ScalerName() const = 0;
00057 virtual const char * ScalerDesc() const = 0;
00058 virtual const char * ScalerCopyright() const = 0;
00059
00060
00061
00062
00063
00064
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
00069 if (!ScaleArbitrary())
00070 {
00071 uint32 scale_bits = ScaleBits();
00072 int x_factor = dw/sw;
00073 int y_factor = dh/sh;
00074
00075
00076 if ((x_factor*sw)!=dw || (y_factor*sh)!=dh) return false;
00077
00078
00079 if (!(scale_bits & (1<<x_factor))) return false;
00080
00081
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