BilinearScalerInternal_2x.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2005 The Pentagram Team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (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 #include "pent_include.h"
00020 #include "BilinearScalerInternal.h"
00021 #include "Manips.h"
00022 
00023 
00024 namespace Pentagram {
00025 
00026 template<class uintX, class Manip, class uintS> 
00027 bool BilinearScalerInternal_2x(Texture *tex, sint32 sx, sint32 sy, sint32 sw, sint32 sh, 
00028                                         uint8* pixel, sint32 dw, sint32 dh, sint32 pitch, bool clamp_src)
00029 {
00030         // Source buffer pointers
00031         uintS *texel = reinterpret_cast<uintS*>(tex->buffer) + (sy * tex->width + sx);
00032         int tpitch = tex->width;
00033         uintS *tline_end = texel + (sw-1);
00034         uintS *tex_end = texel + (sh-4)*tex->width;
00035         int tex_diff = (tex->width*4) - sw;
00036 
00037         uint8 a[4], b[4], c[4], d[4], e[4], f[4], g[4], h[4], i[4], j[4];
00038         int p_diff    = (pitch*8)-(dw*sizeof(uintX));
00039 
00040         bool clip_x = true;
00041         if (sw+sx < tex->width && clamp_src == false)
00042         {
00043                 clip_x = false;
00044                 tline_end = texel + (sw+1);
00045                 tex_diff--;
00046         }
00047 
00048         bool clip_y = true;
00049         if (sh+sy < tex->height && clamp_src == false)
00050         {
00051                 clip_y = false;
00052                 tex_end = texel + (sh)*tex->width;
00053         }
00054 
00055         // Src Loop Y
00056         do {
00057                 Read5(a,b,c,d,e);
00058                 texel++;
00059 
00060                 // Src Loop X
00061                 do {
00062                         Read5(f,g,h,i,j);
00063                         texel++;
00064 
00065                         ScalePixel2x(a, b, f, g);
00066                         ScalePixel2x(b, c, g, h);
00067                         ScalePixel2x(c, d, h, i);
00068                         ScalePixel2x(d, e, i, j);
00069 
00070                         pixel-=pitch*8;
00071                         pixel+=sizeof(uintX)*2;
00072 
00073                         Read5(a,b,c,d,e);
00074                         texel++;
00075 
00076                         ScalePixel2x(f, g, a, b);
00077                         ScalePixel2x(g, h, b, c);
00078                         ScalePixel2x(h, i, c, d);
00079                         ScalePixel2x(i, j, d, e);
00080 
00081                         pixel-=pitch*8;
00082                         pixel+=sizeof(uintX)*2;
00083 
00084                 } while (texel != tline_end);
00085 
00086                 // Final X (clipping)
00087                 if (clip_x) {
00088                         Read5(f,g,h,i,j);
00089                         texel++;
00090 
00091                         ScalePixel2x(a, b, f, g);
00092                         ScalePixel2x(b, c, g, h);
00093                         ScalePixel2x(c, d, h, i);
00094                         ScalePixel2x(d, e, i, j);
00095 
00096                         pixel-=pitch*8;
00097                         pixel+=sizeof(uintX)*2;
00098 
00099                         ScalePixel2x(f, g, f, g);
00100                         ScalePixel2x(g, h, g, h);
00101                         ScalePixel2x(h, i, h, i);
00102                         ScalePixel2x(i, j, i, j);
00103 
00104                         pixel-=pitch*8;
00105                         pixel+=sizeof(uintX)*2;
00106                 };
00107 
00108                 pixel  += p_diff;
00109 
00110                 texel += tex_diff;
00111                 tline_end += tpitch*4;
00112         } while (texel != tex_end);
00113 
00114         //
00115         // Final Rows - Clipping
00116         //
00117 
00118         // Src Loop Y
00119         if (clip_y) {
00120                 Read5_Clipped(a,b,c,d,e);
00121                 texel++;
00122 
00123                 // Src Loop X
00124                 do {
00125                         Read5_Clipped(f,g,h,i,j);
00126                         texel++;
00127                         ScalePixel2x(a, b, f, g);
00128                         ScalePixel2x(b, c, g, h);
00129                         ScalePixel2x(c, d, h, i);
00130                         ScalePixel2x(d, e, i, j);
00131                         pixel-=pitch*8;
00132                         pixel+=sizeof(uintX)*2;
00133 
00134                         Read5_Clipped(a,b,c,d,e);
00135                         texel++;
00136                         ScalePixel2x(f, g, a, b);
00137                         ScalePixel2x(g, h, b, c);
00138                         ScalePixel2x(h, i, c, d);
00139                         ScalePixel2x(i, j, d, e);
00140                         pixel-=pitch*8;
00141                         pixel+=sizeof(uintX)*2;
00142                 } while (texel != tline_end);
00143 
00144                 // Final X (clipping)
00145                 if (clip_x) {
00146                         Read5_Clipped(f,g,h,i,j);
00147                         texel++;
00148 
00149                         ScalePixel2x(a, b, f, g);
00150                         ScalePixel2x(b, c, g, h);
00151                         ScalePixel2x(c, d, h, i);
00152                         ScalePixel2x(d, e, i, j);
00153 
00154                         pixel-=pitch*8;
00155                         pixel+=sizeof(uintX)*2;
00156 
00157                         ScalePixel2x(f, g, f, g);
00158                         ScalePixel2x(g, h, g, h);
00159                         ScalePixel2x(h, i, h, i);
00160                         ScalePixel2x(i, j, i, j);
00161 
00162                         pixel-=pitch*8;
00163                         pixel+=sizeof(uintX)*2;
00164                 };
00165 
00166                 pixel  += p_diff;
00167 
00168                 texel += tex_diff;
00169                 tline_end += tpitch*4;
00170         }
00171 
00172         return true;
00173 }
00174 
00175 InstantiateBilinearScalerFunc(BilinearScalerInternal_2x);
00176 
00177 };
00178 
00179 

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