2xSaIScalers.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2002  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 Library 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 "2xSaIScalers.h"
00021 #include "Manips.h"
00022 #include "Texture.h"
00023 #include <cmath>
00024 
00025 namespace Pentagram {
00026 
00027 
00028 
00029 template<class uintX, class Manip, class uintS=uintX> class _2xSaIScalerInternal {
00030 
00031 public:
00032 
00033 
00042 static inline uintX Interpolate_2xSaI (uintS colorA, uintS colorB)
00043 {
00044         uint8 r0, r1, g0, g1, b0, b1, a0, a1;
00045         Manip::split(colorA, r0, g0, b0, a0);
00046         Manip::split(colorB, r1, g1, b1, a1);
00047         int r = (r0 + r1)>>1;
00048         int g = (g0 + g1)>>1;
00049         int b = (b0 + b1)>>1;
00050         int a = (a0 + a1)>>1;
00051         return Manip::merge(r, g, b, a);
00052 }
00053 
00054 static inline uintX OInterpolate_2xSaI (uintS colorA, uintS colorB, uintS colorC)
00055 {
00056         uint8 r0, r1, g0, g1, b0, b1, a0, a1;
00057         uint8 r2, g2, b2, a2;
00058         Manip::split(colorA, r0, g0, b0, a0);
00059         Manip::split(colorB, r1, g1, b1, a1);
00060         Manip::split(colorC, r2, g2, b2, a2);
00061         unsigned int r = ((r0<<2) + (r0<<1) + r1 + r2)>>3;
00062         unsigned int g = ((g0<<2) + (g0<<1) + g1 + g2)>>3;
00063         unsigned int b = ((b0<<2) + (b0<<1) + b1 + b2)>>3;
00064         unsigned int a = ((a0<<2) + (a0<<1) + a1 + a2)>>3;
00065         return Manip::merge(r, g, b, a);
00066 }
00067 
00068 static inline uintX QInterpolate_2xSaI (uintS colorA, uintS colorB, uintS colorC, uintS colorD)
00069 {
00070         uint8 r0, r1, g0, g1, b0, b1, a0, a1;
00071         uint8 r2, r3, g2, g3, b2, b3, a2, a3;
00072         Manip::split(colorA, r0, g0, b0, a0);
00073         Manip::split(colorB, r1, g1, b1, a1);
00074         Manip::split(colorC, r2, g2, b2, a2);
00075         Manip::split(colorD, r3, g3, b3, a3);
00076         unsigned int r = (r0 + r1 + r2 + r3)>>2;
00077         unsigned int g = (g0 + g1 + g2 + g3)>>2;
00078         unsigned int b = (b0 + b1 + b2 + b3)>>2;
00079         unsigned int a = (a0 + a1 + a2 + a3)>>2;
00080         return Manip::merge(r, g, b, a);
00081 }
00082 
00083 static inline int GetResult1(uintS A, uintS B, uintS C, uintS D)
00084 {
00085         int x = 0;
00086         int y = 0;
00087         int r = 0;
00088         if (A == C) x+=1; else if (B == C) y+=1;
00089         if (A == D) x+=1; else if (B == D) y+=1;
00090         if (x <= 1) r+=1; 
00091         if (y <= 1) r-=1;
00092         return r;
00093 }
00094 
00095 static inline int GetResult2(uintS A, uintS B, uintS C, uintS D) 
00096 {
00097         int x = 0; 
00098         int y = 0;
00099         int r = 0;
00100         if (A == C) x+=1; else if (B == C) y+=1;
00101         if (A == D) x+=1; else if (B == D) y+=1;
00102         if (x <= 1) r-=1; 
00103         if (y <= 1) r+=1;
00104         return r;
00105 }
00106 
00107 //
00108 // 2xSaI Scaler
00109 //
00110 static void Scale_2xSaI
00111 (
00112         uintS *source,                  // ->source pixels.
00113         int srcx, int srcy,                     // Start of rectangle within src.
00114         int srcw, int srch,                     // Dims. of rectangle.
00115         const int sline_pixels,         // Pixels (words)/line for source.
00116         const int sheight,                      // Source height.
00117         uintX *dest,                    // ->dest pixels.
00118         const int dline_pixels          // Pixels (words)/line for dest.
00119 )
00120 {
00121         uintS *srcPtr = source + (srcx + srcy*sline_pixels);
00122         uintX *dstPtr = dest;
00123 
00124         if (srcx + srcw >= sline_pixels)
00125         {
00126                 srcw = sline_pixels - srcx;
00127         }
00128                                         // Init offset to prev. line, next 2.
00129     int prev1_yoff = srcy ? sline_pixels : 0;
00130     int next1_yoff = sline_pixels, next2_yoff = 2*sline_pixels;
00131                                         // Figure threshholds for counters.
00132     int ybeforelast = sheight - 2 - srcy;
00133     int xbeforelast = sline_pixels - 2 - srcx;
00134     for (int y = 0; y < srch; y++, prev1_yoff = sline_pixels)
00135         {
00136                 if (y >= ybeforelast)   // Last/next-to-last row?
00137                         if (y == ybeforelast)
00138                                 next2_yoff = sline_pixels;
00139                         else            // Very last line?
00140                                 next2_yoff = next1_yoff = 0;
00141 
00142                 uintS *bP = srcPtr;
00143                 uintX *dP = dstPtr;
00144                 int prev1_xoff = srcx ? 1 : 0;
00145                 int next1_xoff = 1, next2_xoff = 2;
00146 
00147                 for (int x = 0; x < srcw; x++)
00148                 {
00149                         uintS colorA, colorB;
00150                         uintS colorC, colorD,
00151                                    colorE, colorF, colorG, colorH,
00152                                    colorI, colorJ, colorK, colorL,
00153                                    colorM, colorN, colorO, colorP;
00154                         uintX product, product1, product2, orig;
00155 
00156                                 // Last/next-to-last row?
00157                         if (x >= xbeforelast)
00158                                 if (x == xbeforelast)
00159                                         next2_xoff = 1;
00160                                 else
00161                                         next2_xoff = next1_xoff = 0;
00162 
00163                         //---------------------------------------
00164                         // Map of the pixels:                    I|E F|J
00165                         //                                       G|A B|K
00166                         //                                       H|C D|L
00167                         //                                       M|N O|P
00168                         colorI = *(bP- prev1_yoff - prev1_xoff);
00169                         colorE = *(bP- prev1_yoff);
00170                         colorF = *(bP- prev1_yoff + next1_xoff);
00171                         colorJ = *(bP- prev1_yoff + next2_xoff);
00172 
00173                         colorG = *(bP - prev1_xoff);
00174                         colorA = *(bP);
00175                         colorB = *(bP + next1_xoff);
00176                         colorK = *(bP + next2_xoff);
00177 
00178                         colorH = *(bP + next1_yoff - prev1_xoff);
00179                         colorC = *(bP + next1_yoff);
00180                         colorD = *(bP + next1_yoff + next1_xoff);
00181                         colorL = *(bP + next1_yoff + next2_xoff);
00182 
00183                         colorM = *(bP + next2_yoff - prev1_xoff);
00184                         colorN = *(bP + next2_yoff);
00185                         colorO = *(bP + next2_yoff + next1_xoff);
00186                         colorP = *(bP + next2_yoff + next2_xoff);
00187 
00188                         if ((colorA == colorD) && (colorB != colorC))
00189                         {
00190                            if ( ((colorA == colorE) && (colorB == colorL)) ||
00191                                         ((colorA == colorC) && (colorA == colorF) && (colorB != colorE) && (colorB == colorJ)) )
00192                            {
00193                                   //product = colorA;
00194                                         product = Manip::copy(colorA);
00195                            }
00196                            else
00197                            {
00198                                   //product = INTERPOLATE(colorA, colorB);
00199                                   product = Interpolate_2xSaI(colorA, colorB);
00200                            }
00201 
00202                            if (((colorA == colorG) && (colorC == colorO)) ||
00203                                    ((colorA == colorB) && (colorA == colorH) && (colorG != colorC) && (colorC == colorM)) )
00204                            {
00205                                   //product1 = colorA;
00206                                         product1 = Manip::copy(colorA);
00207                            }
00208                            else
00209                            {
00210                                   //product1 = INTERPOLATE(colorA, colorC);
00211                                   product1 = Interpolate_2xSaI(colorA, colorC);
00212                            }
00213                            //product2 = colorA;
00214                            product2 = Manip::copy(colorA);
00215                         }
00216                         else
00217                         if ((colorB == colorC) && (colorA != colorD))
00218                         {
00219                            if (((colorB == colorF) && (colorA == colorH)) ||
00220                                    ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI)) )
00221                            {
00222                                   //product = colorB;
00223                                   product = Manip::copy(colorB);
00224                            }
00225                            else
00226                            {
00227                                   //product = INTERPOLATE(colorA, colorB);
00228                                   product = Interpolate_2xSaI(colorA, colorB);
00229                            }
00230 
00231                            if (((colorC == colorH) && (colorA == colorF)) ||
00232                                    ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI)) )
00233                            {
00234                                   //product1 = colorC;
00235                                   product1 = Manip::copy(colorC);
00236                            }
00237                            else
00238                            {
00239                                   //product1 = INTERPOLATE(colorA, colorC);
00240                                   product1 = Interpolate_2xSaI(colorA, colorC);
00241                            }
00242                            //product2 = colorB;
00243                            product2 = Manip::copy(colorB);
00244                         }
00245                         else
00246                         if ((colorA == colorD) && (colorB == colorC))
00247                         {
00248                            if (colorA == colorB)
00249                            {
00250                                   //product = colorA;
00251                                   product = Manip::copy(colorA);
00252                                   //product1 = colorA;
00253                                   product1 = Manip::copy(colorA);
00254                                   //product2 = colorA;
00255                                   product2 = Manip::copy(colorA);
00256                            }
00257                            else
00258                            {
00259                                   register int r = 0;
00260                                   //product1 = INTERPOLATE(colorA, colorC);
00261                                   product1 = Interpolate_2xSaI(colorA, colorC);
00262                                   //product = INTERPOLATE(colorA, colorB);
00263                                   product = Interpolate_2xSaI(colorA, colorB);
00264 
00265                                   r += GetResult1 (colorA, colorB, colorG, colorE);
00266                                   r += GetResult2 (colorB, colorA, colorK, colorF);
00267                                   r += GetResult2 (colorB, colorA, colorH, colorN);
00268                                   r += GetResult1 (colorA, colorB, colorL, colorO);
00269 
00270                                   if (r > 0)
00271                                           //product2 = colorA;
00272                                           product2 = Manip::copy(colorA);
00273                                   else
00274                                   if (r < 0)
00275                                           //product2 = colorB;
00276                                           product2 = Manip::copy(colorB);
00277                                   else
00278                                   {
00279                                           //product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD);
00280                                           product2 = QInterpolate_2xSaI(colorA, colorB, colorC, colorD);
00281                                   }
00282                            }
00283                         }
00284                         else
00285                         {
00286                            //product2 = Q_INTERPOLATE(colorA, colorB, colorC, colorD);
00287                            product2 = QInterpolate_2xSaI(colorA, colorB, colorC, colorD);
00288 
00289                            if ((colorA == colorC) && (colorA == colorF) && (colorB != colorE) && (colorB == colorJ))
00290                            {
00291                                   //product = colorA;
00292                                   product = Manip::copy(colorA);
00293                            }
00294                            else
00295                            if ((colorB == colorE) && (colorB == colorD) && (colorA != colorF) && (colorA == colorI))
00296                            {
00297                                   //product = colorB;
00298                                   product = Manip::copy(colorB);
00299                            }
00300                            else
00301                            {
00302                                   //product = INTERPOLATE(colorA, colorB);
00303                                   product = Interpolate_2xSaI(colorA, colorB);
00304                            }
00305 
00306                            if ((colorA == colorB) && (colorA == colorH) && (colorG != colorC) && (colorC == colorM))
00307                            {
00308                                   //product1 = colorA;
00309                                   product1 = Manip::copy(colorA);
00310                            }
00311                            else
00312                            if ((colorC == colorG) && (colorC == colorD) && (colorA != colorH) && (colorA == colorI))
00313                            {
00314                                   //product1 = colorC;
00315                                   product1 = Manip::copy(colorC);
00316                            }
00317                            else
00318                            {
00319                                   //product1 = INTERPOLATE(colorA, colorC);
00320                                   product1 = Interpolate_2xSaI(colorA, colorC);
00321                            }
00322                         }
00323 
00324 
00325                         //product = colorA | (product << 16);
00326                         //product1 = product1 | (product2 << 16);
00327                         orig = Manip::copy(colorA);
00328                         *dP = orig;
00329                         *(dP+1) = product;
00330                         *(dP+dline_pixels) = product1;
00331                         *(dP+dline_pixels+1) = product2;
00332 
00333                         bP += 1;
00334                         dP += 2;
00335                         prev1_xoff = 1;
00336                 }//end of for ( finish= width etc..)
00337 
00338                 srcPtr += sline_pixels;
00339                 dstPtr += 2*dline_pixels;
00340                 prev1_yoff = 1;
00341         };
00342 }
00343 
00344 //
00345 // Super2xSaI Scaler
00346 //
00347 static void Scale_Super2xSaI
00348 (
00349         uintS *source,                  // ->source pixels.
00350         int srcx, int srcy,                     // Start of rectangle within src.
00351         int srcw, int srch,                     // Dims. of rectangle.
00352         const int sline_pixels,         // Pixels (words)/line for source.
00353         const int sheight,                      // Source height.
00354         uintX *dest,                    // ->dest pixels.
00355         const int dline_pixels          // Pixels (words)/line for dest.
00356 )
00357 {
00358 
00359         uintS *srcPtr = source + (srcx + srcy*sline_pixels);
00360         uintX *dstPtr = dest;
00361 
00362         if (srcx + srcw >= sline_pixels)
00363         {
00364                 srcw = sline_pixels - srcx;
00365         }
00366 
00367     int ybeforelast1 = sheight - 1 - srcy;
00368     int ybeforelast2 = sheight - 2 - srcy;
00369     int xbeforelast1 = sline_pixels - 1 - srcx;
00370     int xbeforelast2 = sline_pixels - 2 - srcx;
00371                 
00372     for (int y = 0; y < srch; y++)
00373         {
00374                 uintS *bP = srcPtr;
00375                 uintX *dP = dstPtr;
00376 
00377                 for (int x = 0; x < srcw; x++)
00378                 {
00379            uintS color4, color5, color6;
00380            uintS color1, color2, color3;
00381            uintS colorA0, colorA1, colorA2, colorA3,
00382                                                 colorB0, colorB1, colorB2, colorB3,
00383                                                 colorS1, colorS2;
00384            uintX product1a, product1b,
00385                                          product2a, product2b;
00386 
00387                         //---------------------------------------  B0 B1 B2 B3
00388                         //                                         4  5  6  S2
00389                         //                                         1  2  3  S1
00390                         //                                         A0 A1 A2 A3
00391                         //--------------------------------------
00392                         int add1, add2;
00393                         int sub1;
00394                         int nextl1, nextl2;
00395                         int prevl1;
00396 
00397                         if ((x+srcx) == 0)
00398                                 sub1 = 0;
00399                         else
00400                                 sub1 = 1;
00401 
00402                         if (x >= xbeforelast2)
00403                                 add2 = 0;
00404                         else add2 = 1;
00405 
00406                         if (x >= xbeforelast1)
00407                                 add1 = 0;
00408                         else add1 = 1;
00409 
00410                         if ((y+srcy) == 0)
00411                                 prevl1 = 0;
00412                         else
00413                                 prevl1 = sline_pixels;
00414 
00415                         if (y >= ybeforelast2)
00416                                 nextl2 = 0;
00417                         else nextl2 = sline_pixels;
00418 
00419                         if (y >= ybeforelast1)
00420                                 nextl1 = 0;
00421                         else nextl1 = sline_pixels;
00422 
00423 
00424             colorB0 = *(bP- prevl1 - sub1);
00425             colorB1 = *(bP- prevl1);
00426             colorB2 = *(bP- prevl1 + add1);
00427             colorB3 = *(bP- prevl1 + add1 + add2);
00428 
00429             color4 = *(bP - sub1);
00430             color5 = *(bP);
00431             color6 = *(bP + add1);
00432             colorS2 = *(bP + add1 + add2);
00433 
00434             color1 = *(bP + nextl1 - sub1);
00435             color2 = *(bP + nextl1);
00436             color3 = *(bP + nextl1 + add1);
00437             colorS1 = *(bP + nextl1 + add1 + add2);
00438 
00439             colorA0 = *(bP + nextl1 + nextl2 - sub1);
00440             colorA1 = *(bP + nextl1 + nextl2);
00441             colorA2 = *(bP + nextl1 + nextl2 + add1);
00442             colorA3 = *(bP + nextl1 + nextl2 + add1 + add2);
00443 
00444                         if (color2 == color6 && color5 != color3)
00445                         {
00446                            //product2b = product1b = color2;
00447                                 product2b = product1b = Manip::copy(color2);
00448                         }
00449                         else
00450                         if (color5 == color3 && color2 != color6)
00451                         {
00452                            //product2b = product1b = color5;
00453                                 product2b = product1b = Manip::copy(color5);
00454                         }
00455                         else
00456                         if (color5 == color3 && color2 == color6)
00457                         {
00458                                 register int r = 0;
00459 
00460                 //r += GetResult (color6, color5, color1, colorA1);
00461                 //r += GetResult (color6, color5, color4, colorB1);
00462                 //r += GetResult (color6, color5, colorA2, colorS1);
00463                 //r += GetResult (color6, color5, colorB2, colorS2);
00464                                 r += GetResult1 (color5, color6, color4, colorB1);
00465                                 r += GetResult2 (color6, color5, colorA2, colorS1);
00466                                 r += GetResult2 (color6, color5, color1, colorA1);
00467                                 r += GetResult1 (color5, color6, colorB2, colorS2);
00468 
00469                                 if (r > 0)
00470                                 {
00471                                         //product2b = product1b = color6;
00472                                         product2b = product1b = Manip::copy(color6);
00473                                 }
00474                                 else
00475                                 if (r < 0)
00476                                 {
00477                                         //product2b = product1b = color5;
00478                                         product2b = product1b = Manip::copy(color5);
00479                                 }
00480                                 else
00481                                 {
00482                                         //product2b = product1b = INTERPOLATE (color5, color6);
00483                                         product1b = product2b = Interpolate_2xSaI(color5, color6);
00484                                 }
00485 
00486                         }
00487                         else
00488                         {
00489 
00490                            if (color6 == color3 && color3 == colorA1 && color2 != colorA2 && color3 != colorA0)
00491                                         //product2b = Q_INTERPOLATE (color3, color3, color3, color2);
00492                                         product2b = QInterpolate_2xSaI(color3, color3, color3, color2);
00493                            else
00494                            if (color5 == color2 && color2 == colorA2 && colorA1 != color3 && color2 != colorA3)
00495                                         //product2b = Q_INTERPOLATE (color2, color2, color2, color3);
00496                                         product2b = QInterpolate_2xSaI(color3, color2, color2, color2);
00497                            else
00498                                         //product2b = INTERPOLATE (color2, color3);
00499                                         product2b = Interpolate_2xSaI(color2, color3);
00500 
00501 
00502                            if (color6 == color3 && color6 == colorB1 && color5 != colorB2 && color6 != colorB0)
00503                                         //product1b = Q_INTERPOLATE (color6, color6, color6, color5);
00504                                         product1b = QInterpolate_2xSaI(color5, color6, color6, color6);
00505                            else
00506                            if (color5 == color2 && color5 == colorB2 && colorB1 != color6 && color5 != colorB3)
00507                                         //product1b = Q_INTERPOLATE (color6, color5, color5, color5);
00508                                         product1b = QInterpolate_2xSaI(color6, color5, color5, color5);
00509                            else
00510                                         //product1b = INTERPOLATE (color5, color6);
00511                                         product1b = Interpolate_2xSaI(color5, color6);
00512 
00513                         }
00514 
00515                         if (color5 == color3 && color2 != color6 && color4 == color5 && color5 != colorA2)
00516                                 //product2a = INTERPOLATE (color2, color5);
00517                                 product2a = Interpolate_2xSaI(color5, color2);
00518                         else
00519                         if (color5 == color1 && color6 == color5 && color4 != color2 && color5 != colorA0)
00520                                 //product2a = INTERPOLATE(color2, color5);
00521                                 product2a = Interpolate_2xSaI(color5, color2);
00522                         else
00523                                 //product2a = color2;
00524                                 product2a = Manip::copy(color2);
00525 
00526 
00527                         if (color2 == color6 && color5 != color3 && color1 == color2 && color2 != colorB2)
00528                                 //product1a = INTERPOLATE (color2, color5);
00529                                 product1a = Interpolate_2xSaI(color5, color2);
00530                         else
00531                         if (color4 == color2 && color3 == color2 && color1 != color5 && color2 != colorB0)
00532                                 //product1a = INTERPOLATE(color2, color5);
00533                                 product1a = Interpolate_2xSaI(color5, color2);
00534                         else
00535                                 //product1a = color5;
00536                                 product1a = Manip::copy(color5);
00537 
00538 
00539                         *dP = product1a;
00540                         *(dP+1) = product1b;
00541                         *(dP+dline_pixels) = product2a;
00542                         *(dP+dline_pixels+1) = product2b;
00543 
00544                         bP += 1;
00545                         dP += 2;
00546 
00547                 }
00548                 srcPtr += sline_pixels;
00549                 dstPtr += 2*dline_pixels;
00550         }; 
00551 }
00552 
00553 //
00554 // SuperEagle Scaler
00555 //
00556 static void Scale_SuperEagle
00557 (
00558         uintS *source,                  // ->source pixels.
00559         int srcx, int srcy,                     // Start of rectangle within src.
00560         int srcw, int srch,                     // Dims. of rectangle.
00561         const int sline_pixels,         // Pixels (words)/line for source.
00562         const int sheight,                      // Source height.
00563         uintX *dest,                    // ->dest pixels.
00564         const int dline_pixels          // Pixels (words)/line for dest.
00565 )
00566 {
00567 
00568         uintS *srcPtr = source + (srcx + srcy*sline_pixels);
00569         uintX *dstPtr = dest;
00570 
00571         if (srcx + srcw >= sline_pixels)
00572         {
00573                 srcw = sline_pixels - srcx;
00574         }
00575 
00576     int ybeforelast1 = sheight - 1 - srcy;
00577     int ybeforelast2 = sheight - 2 - srcy;
00578     int xbeforelast1 = sline_pixels - 1 - srcx;
00579     int xbeforelast2 = sline_pixels - 2 - srcx;
00580                 
00581     for (int y = 0; y < srch; y++)
00582         {
00583                 uintS *bP = srcPtr;
00584                 uintX *dP = dstPtr;
00585 
00586                 for (int x = 0; x < srcw; x++)
00587                 {
00588            uintS color4, color5, color6;
00589            uintS color1, color2, color3;
00590            uintS colorA0, colorA1, colorA2, colorA3,
00591                                                 colorB0, colorB1, colorB2, colorB3,
00592                                                 colorS1, colorS2;
00593            uintX product1a, product1b,
00594                                          product2a, product2b;
00595 
00596                         //---------------------------------------  B0 B1 B2 B3
00597                         //                                         4  5  6  S2
00598                         //                                         1  2  3  S1
00599                         //                                         A0 A1 A2 A3
00600                         //--------------------------------------
00601                         int add1, add2;
00602                         int sub1;
00603                         int nextl1, nextl2;
00604                         int prevl1;
00605 
00606                         if ((x+srcx) == 0)
00607                                 sub1 = 0;
00608                         else
00609                                 sub1 = 1;
00610 
00611                         if (x >= xbeforelast2)
00612                                 add2 = 0;
00613                         else add2 = 1;
00614 
00615                         if (x >= xbeforelast1)
00616                                 add1 = 0;
00617                         else add1 = 1;
00618 
00619                         if ((y+srcy) == 0)
00620                                 prevl1 = 0;
00621                         else
00622                                 prevl1 = sline_pixels;
00623 
00624                         if (y >= ybeforelast2)
00625                                 nextl2 = 0;
00626                         else nextl2 = sline_pixels;
00627 
00628                         if (y >= ybeforelast1)
00629                                 nextl1 = 0;
00630                         else nextl1 = sline_pixels;
00631 
00632 
00633             colorB0 = *(bP- prevl1 - sub1);
00634             colorB1 = *(bP- prevl1);
00635             colorB2 = *(bP- prevl1 + add1);
00636             colorB3 = *(bP- prevl1 + add1 + add2);
00637 
00638             color4 = *(bP - sub1);
00639             color5 = *(bP);
00640             color6 = *(bP + add1);
00641             colorS2 = *(bP + add1 + add2);
00642 
00643             color1 = *(bP + nextl1 - sub1);
00644             color2 = *(bP + nextl1);
00645             color3 = *(bP + nextl1 + add1);
00646             colorS1 = *(bP + nextl1 + add1 + add2);
00647 
00648             colorA0 = *(bP + nextl1 + nextl2 - sub1);
00649             colorA1 = *(bP + nextl1 + nextl2);
00650             colorA2 = *(bP + nextl1 + nextl2 + add1);
00651             colorA3 = *(bP + nextl1 + nextl2 + add1 + add2);
00652 
00653 
00654                         if (color2 == color6 && color5 != color3)
00655                         {
00656                            //product1b = product2a = color2;
00657                            product1b = product2a = Manip::copy(color2);
00658 
00659 
00660                            if ((color1 == color2) || (color6 == colorB2))
00661                            {
00662                                    //product1a = INTERPOLATE (color2, color5);
00663                                    //product1a = INTERPOLATE (color2, product1a);
00664                                    product1a = QInterpolate_2xSaI(color2, color2, color2, color5);
00665 
00666                            }
00667                            else
00668                            {
00669                                    //product1a = INTERPOLATE (color5, color6);
00670                                    product1a = Interpolate_2xSaI(color6, color5);
00671                            }
00672 
00673                            if ((color6 == colorS2) || (color2 == colorA1))
00674                {
00675                    //product2b = INTERPOLATE (color2, color3);
00676                    //product2b = INTERPOLATE (color2, product2b);
00677                                    product2b = QInterpolate_2xSaI(color2, color2, color2, color3);
00678 
00679                }
00680                else
00681                {
00682                    //product2b = INTERPOLATE (color2, color3);
00683                                    product2b = Interpolate_2xSaI(color2, color3);
00684                }
00685             }
00686             else
00687             if (color5 == color3 && color2 != color6)
00688             {
00689                //product2b = product1a = color5;
00690                            product2b = product1a = Manip::copy(color5);
00691 
00692  
00693                if ((colorB1 == color5) ||  (color3 == colorS1))
00694                {
00695                    //product1b = INTERPOLATE (color5, color6);
00696                                    //product1b = INTERPOLATE (color5, product1b);
00697                                    product1b = QInterpolate_2xSaI(color5, color5, color5, color6);
00698                }
00699                else
00700                {
00701                   //product1b = INTERPOLATE (color5, color6);
00702                                   product1b = Interpolate_2xSaI(color5, color6);
00703                }
00704 
00705                            if ((color3 == colorA2) || (color4 == color5))
00706                {
00707                    //product2a = INTERPOLATE (color5, color2);
00708                    //product2a = INTERPOLATE (color5, product2a);
00709                                    product2a = QInterpolate_2xSaI(color2, color5, color5, color5);
00710                }
00711                else
00712                {
00713                   //product2a = INTERPOLATE (color2, color3);
00714                                   product2a = Interpolate_2xSaI(color3, color2);
00715                }
00716 
00717             }
00718             else
00719             if (color5 == color3 && color2 == color6)
00720             {
00721                register int r = 0;
00722 
00723                //r += GetResult (color6, color5, color1, colorA1);
00724                //r += GetResult (color6, color5, color4, colorB1);
00725                //r += GetResult (color6, color5, colorA2, colorS1);
00726                //r += GetResult (color6, color5, colorB2, colorS2);
00727                            r += GetResult1 (color5, color6, color4, colorB1);
00728                            r += GetResult2 (color6, color5, colorA2, colorS1);
00729                            r += GetResult2 (color6, color5, color1, colorA1);
00730                            r += GetResult1 (color5, color6, colorB2, colorS2);
00731 
00732                if (r > 0)
00733                {
00734                   //product1b = product2a = color2;
00735                                    product1b = product2a = Manip::copy(color2);
00736                   //product1a = product2b = INTERPOLATE (color5, color6);
00737                                   product1a = product2b = Interpolate_2xSaI(color5, color6);
00738                }
00739                else
00740                if (r < 0)
00741                {
00742                   //product2b = product1a = color5;
00743                                    product2b = product1a = Manip::copy(color5);
00744                   //product1b = product2a = INTERPOLATE (color5, color6);
00745                                   product1b = product2a = Interpolate_2xSaI(color5, color6);
00746                }
00747                else
00748                {
00749                   //product2b = product1a = color5;
00750                                    product2b = product1a = Manip::copy(color5);
00751                   //product1b = product2a = color2;
00752                                    product1b = product2a = Manip::copy(color2);
00753                }
00754             }
00755             else
00756             {
00757                   //product2b = product1a = INTERPOLATE (color2, color6);
00758                   //product2b = Q_INTERPOLATE (color3, color3, color3, product2b);
00759                   //product1a = Q_INTERPOLATE (color5, color5, color5, product1a);
00760                                   product2b = OInterpolate_2xSaI(color3, color2, color6);
00761                                   product1a = OInterpolate_2xSaI(color5, color6, color2);
00762 
00763                   //product2a = product1b = INTERPOLATE (color5, color3);
00764                   //product2a = Q_INTERPOLATE (color2, color2, color2, product2a);
00765                   //product1b = Q_INTERPOLATE (color6, color6, color6, product1b);
00766                                   product2a = OInterpolate_2xSaI(color2, color5, color3);
00767                                   product1b = OInterpolate_2xSaI(color6, color5, color3);
00768                         }
00769 
00770                         *dP = product1a;
00771                         *(dP+1) = product1b;
00772                         *(dP+dline_pixels) = product2a;
00773                         *(dP+dline_pixels+1) = product2b;
00774 
00775                         bP += 1;
00776                         dP += 2;
00777 
00778                 }
00779                 srcPtr += sline_pixels;
00780                 dstPtr += 2*dline_pixels;
00781         }
00782         
00783 }
00784 
00785 static bool Scale2xSaI(Texture *tex, sint32 sx, sint32 sy, sint32 sw, sint32 sh, 
00786                                         uint8* pixel, sint32 dw, sint32 dh, sint32 pitch, bool clamp_src)
00787 {
00788         if (sw*2!=dw || sh*2!=dh) return false;
00789 
00790         if (clamp_src)
00791         {
00792                 Scale_2xSaI(reinterpret_cast<uintS*>(tex->buffer) + sx + sy*tex->width,
00793                                         0, 0, sw, sh, tex->width, sh,
00794                                         reinterpret_cast<uintX*>(pixel), pitch/sizeof(uintX));
00795         }
00796         else
00797         {
00798                 Scale_2xSaI(reinterpret_cast<uintS*>(tex->buffer),
00799                                         sx, sy, sw, sh, tex->width, tex->height,
00800                                         reinterpret_cast<uintX*>(pixel), pitch/sizeof(uintX));
00801         }
00802         return true;
00803 }
00804 
00805 static bool ScaleSuper2xSaI(Texture *tex, sint32 sx, sint32 sy, sint32 sw, sint32 sh, 
00806                                         uint8* pixel, sint32 dw, sint32 dh, sint32 pitch, bool clamp_src)
00807 {
00808         if (sw*2!=dw || sh*2!=dh) return false;
00809 
00810         if (clamp_src)
00811         {
00812                 Scale_Super2xSaI(reinterpret_cast<uintS*>(tex->buffer) + sx + sy*tex->width,
00813                                         0, 0, sw, sh, tex->width, sh,
00814                                         reinterpret_cast<uintX*>(pixel), pitch/sizeof(uintX));
00815         }
00816         else
00817         {
00818                 Scale_Super2xSaI(reinterpret_cast<uintS*>(tex->buffer),
00819                                         sx, sy, sw, sh, tex->width, tex->height,
00820                                         reinterpret_cast<uintX*>(pixel), pitch/sizeof(uintX));
00821         }
00822         return true;
00823 }
00824 
00825 static bool ScaleSuperEagle(Texture *tex, sint32 sx, sint32 sy, sint32 sw, sint32 sh, 
00826                                         uint8* pixel, sint32 dw, sint32 dh, sint32 pitch, bool clamp_src)
00827 {
00828         if (sw*2!=dw || sh*2!=dh) return false;
00829 
00830         if (clamp_src)
00831         {
00832                 Scale_SuperEagle(reinterpret_cast<uintS*>(tex->buffer) + sx + sy*tex->width,
00833                                         0, 0, sw, sh, tex->width, sh,
00834                                         reinterpret_cast<uintX*>(pixel), pitch/sizeof(uintX));
00835         }
00836         else
00837         {
00838                 Scale_SuperEagle(reinterpret_cast<uintS*>(tex->buffer),
00839                                         sx, sy, sw, sh, tex->width, tex->height,
00840                                         reinterpret_cast<uintX*>(pixel), pitch/sizeof(uintX));
00841         }
00842         return true;
00843 }
00844 
00845 };      // Class
00846 
00847 //
00848 // 2xSaI
00849 //
00850 _2xSaIScaler::_2xSaIScaler() : Scaler()
00851 {
00852         Scale16Nat = _2xSaIScalerInternal<uint16, Manip_Nat2Nat_16, uint16>::Scale2xSaI;
00853         Scale16Sta = _2xSaIScalerInternal<uint16, Manip_Sta2Nat_16, uint32>::Scale2xSaI;
00854 
00855         Scale32Nat = _2xSaIScalerInternal<uint32, Manip_Nat2Nat_32, uint32>::Scale2xSaI;
00856         Scale32Sta = _2xSaIScalerInternal<uint32, Manip_Sta2Nat_32, uint32>::Scale2xSaI;
00857         Scale32_A888 = _2xSaIScalerInternal<uint32, Manip_32_A888, uint32>::Scale2xSaI;
00858         Scale32_888A = _2xSaIScalerInternal<uint32, Manip_32_888A, uint32>::Scale2xSaI;
00859 }
00860 
00861 const uint32 _2xSaIScaler::ScaleBits() const { return 1<<2; }
00862 const bool _2xSaIScaler::ScaleArbitrary() const { return false; }
00863 
00864 const char *_2xSaIScaler::ScalerName() const { return "2xSaI"; }
00865 const char *_2xSaIScaler::ScalerDesc() const { return "2xSaI Scaling Filter"; }
00866 const char *_2xSaIScaler::ScalerCopyright() const { return "Copyright (c) 1999-2001 Derek Liauw Kie Fa"; }
00867 
00868 const _2xSaIScaler _2xSaI_scaler;
00869 
00870 //
00871 // Super2xSaI
00872 //
00873 Super2xSaIScaler::Super2xSaIScaler() : Scaler()
00874 {
00875         Scale16Nat = _2xSaIScalerInternal<uint16, Manip_Nat2Nat_16, uint16>::ScaleSuper2xSaI;
00876         Scale16Sta = _2xSaIScalerInternal<uint16, Manip_Sta2Nat_16, uint32>::ScaleSuper2xSaI;
00877 
00878         Scale32Nat = _2xSaIScalerInternal<uint32, Manip_Nat2Nat_32, uint32>::ScaleSuper2xSaI;
00879         Scale32Sta = _2xSaIScalerInternal<uint32, Manip_Sta2Nat_32, uint32>::ScaleSuper2xSaI;
00880         Scale32_A888 = _2xSaIScalerInternal<uint32, Manip_32_A888, uint32>::ScaleSuper2xSaI;
00881         Scale32_888A = _2xSaIScalerInternal<uint32, Manip_32_888A, uint32>::ScaleSuper2xSaI;
00882 }
00883 
00884 const uint32 Super2xSaIScaler::ScaleBits() const { return 1<<2; }
00885 const bool Super2xSaIScaler::ScaleArbitrary() const { return false; }
00886 
00887 const char *Super2xSaIScaler::ScalerName() const { return "Super2xSaI"; }
00888 const char *Super2xSaIScaler::ScalerDesc() const { return "Super2xSaI Scaling Filter"; }
00889 const char *Super2xSaIScaler::ScalerCopyright() const { return "Copyright (c) 1999-2001 Derek Liauw Kie Fa"; }
00890 
00891 const Super2xSaIScaler Super2xSaI_scaler;
00892 
00893 //
00894 // SuperEagle
00895 //
00896 SuperEagleScaler::SuperEagleScaler() : Scaler()
00897 {
00898         Scale16Nat = _2xSaIScalerInternal<uint16, Manip_Nat2Nat_16, uint16>::ScaleSuperEagle;
00899         Scale16Sta = _2xSaIScalerInternal<uint16, Manip_Sta2Nat_16, uint32>::ScaleSuperEagle;
00900 
00901         Scale32Nat = _2xSaIScalerInternal<uint32, Manip_Nat2Nat_32, uint32>::ScaleSuperEagle;
00902         Scale32Sta = _2xSaIScalerInternal<uint32, Manip_Sta2Nat_32, uint32>::ScaleSuperEagle;
00903         Scale32_A888 = _2xSaIScalerInternal<uint32, Manip_32_A888, uint32>::ScaleSuperEagle;
00904         Scale32_888A = _2xSaIScalerInternal<uint32, Manip_32_888A, uint32>::ScaleSuperEagle;
00905 }
00906 
00907 const uint32 SuperEagleScaler::ScaleBits() const { return 1<<2; }
00908 const bool SuperEagleScaler::ScaleArbitrary() const { return false; }
00909 
00910 const char *SuperEagleScaler::ScalerName() const { return "SuperEagle"; }
00911 const char *SuperEagleScaler::ScalerDesc() const { return "SuperEagle Scaling Filter"; }
00912 const char *SuperEagleScaler::ScalerCopyright() const { return "Copyright (c) 1999-2001 Derek Liauw Kie Fa"; }
00913 
00914 const SuperEagleScaler SuperEagle_scaler;
00915 
00916 
00917 #ifdef COMPILE_GAMMA_CORRECT_SCALERS
00918 
00919 //
00920 // Gamma Corrected 2xSaI 
00921 //
00922 
00923 GC_2xSaIScaler::GC_2xSaIScaler() : Scaler()
00924 {
00925         Scale16Nat = _2xSaIScalerInternal<uint16, Manip_Nat2Nat_16_GC, uint16>::Scale2xSaI;
00926         Scale16Sta = _2xSaIScalerInternal<uint16, Manip_Sta2Nat_16_GC, uint32>::Scale2xSaI;
00927 
00928         Scale32Nat = _2xSaIScalerInternal<uint32, Manip_Nat2Nat_32_GC, uint32>::Scale2xSaI;
00929         Scale32Sta = _2xSaIScalerInternal<uint32, Manip_Sta2Nat_32_GC, uint32>::Scale2xSaI;
00930         Scale32_A888 = _2xSaIScalerInternal<uint32, Manip_32_A888_GC, uint32>::Scale2xSaI;
00931         Scale32_888A = _2xSaIScalerInternal<uint32, Manip_32_888A_GC, uint32>::Scale2xSaI;
00932 
00933 }
00934 
00935 const uint32 GC_2xSaIScaler::ScaleBits() const { return 1<<2; }
00936 const bool GC_2xSaIScaler::ScaleArbitrary() const { return false; }
00937 
00938 const char *GC_2xSaIScaler::ScalerName() const { return "GC-2xSaI"; }
00939 const char *GC_2xSaIScaler::ScalerDesc() const { return "Gamma 2.2 Correct 2xSaI Scaling Filter"; }
00940 const char *GC_2xSaIScaler::ScalerCopyright() const { return "Copyright (c) 1999-2001 Derek Liauw Kie Fa"; }
00941 
00942 const GC_2xSaIScaler GC_2xSaI_scaler;
00943 
00944 
00945 //
00946 // Gamma Corrected Super2xSaI 
00947 //
00948 
00949 GC_Super2xSaIScaler::GC_Super2xSaIScaler() : Scaler()
00950 {
00951         Scale16Nat = _2xSaIScalerInternal<uint16, Manip_Nat2Nat_16_GC, uint16>::ScaleSuper2xSaI;
00952         Scale16Sta = _2xSaIScalerInternal<uint16, Manip_Sta2Nat_16_GC, uint32>::ScaleSuper2xSaI;
00953 
00954         Scale32Nat = _2xSaIScalerInternal<uint32, Manip_Nat2Nat_32_GC, uint32>::ScaleSuper2xSaI;
00955         Scale32Sta = _2xSaIScalerInternal<uint32, Manip_Sta2Nat_32_GC, uint32>::ScaleSuper2xSaI;
00956         Scale32_A888 = _2xSaIScalerInternal<uint32, Manip_32_A888_GC, uint32>::ScaleSuper2xSaI;
00957         Scale32_888A = _2xSaIScalerInternal<uint32, Manip_32_888A_GC, uint32>::ScaleSuper2xSaI;
00958 
00959 }
00960 
00961 const uint32 GC_Super2xSaIScaler::ScaleBits() const { return 1<<2; }
00962 const bool GC_Super2xSaIScaler::ScaleArbitrary() const { return false; }
00963 
00964 const char *GC_Super2xSaIScaler::ScalerName() const { return "GC-Super2xSaI"; }
00965 const char *GC_Super2xSaIScaler::ScalerDesc() const { return "Gamma 2.2 Correct Super2xSaI Scaling Filter"; }
00966 const char *GC_Super2xSaIScaler::ScalerCopyright() const { return "Copyright (c) 1999-2001 Derek Liauw Kie Fa"; }
00967 
00968 const GC_Super2xSaIScaler GC_Super2xSaI_scaler;
00969 
00970 
00971 //
00972 // Gamma Corrected SuperEagle
00973 //
00974 GC_SuperEagleScaler::GC_SuperEagleScaler() : Scaler()
00975 {
00976         Scale16Nat = _2xSaIScalerInternal<uint16, Manip_Nat2Nat_16_GC, uint16>::ScaleSuperEagle;
00977         Scale16Sta = _2xSaIScalerInternal<uint16, Manip_Sta2Nat_16_GC, uint32>::ScaleSuperEagle;
00978 
00979         Scale32Nat = _2xSaIScalerInternal<uint32, Manip_Nat2Nat_32_GC, uint32>::ScaleSuperEagle;
00980         Scale32Sta = _2xSaIScalerInternal<uint32, Manip_Sta2Nat_32_GC, uint32>::ScaleSuperEagle;
00981         Scale32_A888 = _2xSaIScalerInternal<uint32, Manip_32_A888_GC, uint32>::ScaleSuperEagle;
00982         Scale32_888A = _2xSaIScalerInternal<uint32, Manip_32_888A_GC, uint32>::ScaleSuperEagle;
00983 }
00984 
00985 const uint32 GC_SuperEagleScaler::ScaleBits() const { return 1<<2; }
00986 const bool GC_SuperEagleScaler::ScaleArbitrary() const { return false; }
00987 
00988 const char *GC_SuperEagleScaler::ScalerName() const { return "GC-SuperEagle"; }
00989 const char *GC_SuperEagleScaler::ScalerDesc() const { return "Gamma 2.2 Correct SuperEagle Scaling Filter"; }
00990 const char *GC_SuperEagleScaler::ScalerCopyright() const { return "Copyright (c) 1999-2001 Derek Liauw Kie Fa"; }
00991 
00992 const GC_SuperEagleScaler GC_SuperEagle_scaler;
00993 
00994 #endif
00995 
00996 };      // Namespace
00997 

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