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

# LinearMinificationFilter.cpp

Go to the documentation of this file.

    00001 //------------------------------------------------------------------------------
    00002 // Lamp : Open source game middleware
    00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
    00004 //
    00005 // This library is free software; you can redistribute it and/or
    00006 // modify it under the terms of the GNU Lesser General Public
    00007 // License as published by the Free Software Foundation; either
    00008 // version 2.1 of the License, or (at your option) any later version.
    00009 //
    00010 // This library is distributed in the hope that it will be useful,
    00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013 // Lesser General Public License for more details.
    00014 //
    00015 // You should have received a copy of the GNU Lesser General Public
    00016 // License along with this library; if not, write to the Free Software
    00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00018 //------------------------------------------------------------------------------
    00019
    00020 /** @file
    00021  * 線形縮小フィルタ実装
    00022  * @author Junpee
    00023  */
    00024
    00025 #include "LampBasic.h"
    00026 #include "Core/Codec/LinearMinificationFilter/LinearMinificationFilter.h"
    00027
    00028 namespace Lamp{
    00029
    00030 //------------------------------------------------------------------------------
    00031 // フィルタ
    00032 void LinearMinificationFilter::filter(
    00033     const Color3c* source, const DimensionI& sourceSize,
    00034     Color3c* destination, const DimensionI destinationSize){
    00035     // 引数チェック
    00036     Assert(source != NULL);
    00037     Assert(sourceSize.width != 0);
    00038     Assert(sourceSize.height != 0);
    00039     Assert((sourceSize.width != 1) || (sourceSize.height != 1));
    00040     Assert(destination != NULL);
    00041     Assert(destinationSize.width != 0);
    00042     Assert(destinationSize.height != 0);
    00043     Assert(((sourceSize.width / 2) == destinationSize.width) ||
    00044         (sourceSize.width == 1));
    00045     Assert(((sourceSize.height / 2) == destinationSize.height) ||
    00046         (sourceSize.height == 1));
    00047     // フィルタ
    00048     for(int i = 0; i < destinationSize.height; i++){
    00049         int offset = i * destinationSize.width;
    00050         int sourceOffset0 = i * 2 * sourceSize.width;
    00051         int sourceOffset1 = sourceOffset0 + sourceSize.width;
    00052         if(sourceSize.height == 1){ sourceOffset1 -= sourceSize.width; }
    00053         for(int j = 0; j < destinationSize.width; j++){
    00054             int widthOffset0 = j * 2;
    00055             int widthOffset1 = widthOffset0 + 1;
    00056             if(sourceSize.width == 1){ widthOffset1 -= 1; }
    00057             int r = ((int)source[sourceOffset0 + widthOffset0].r +
    00058                 (int)source[sourceOffset0 + widthOffset1].r +
    00059                 (int)source[sourceOffset1 + widthOffset0].r +
    00060                 (int)source[sourceOffset1 + widthOffset1].r) / 4;
    00061             int g = ((int)source[sourceOffset0 + widthOffset0].g +
    00062                 (int)source[sourceOffset0 + widthOffset1].g +
    00063                 (int)source[sourceOffset1 + widthOffset0].g +
    00064                 (int)source[sourceOffset1 + widthOffset1].g) / 4;
    00065             int b = ((int)source[sourceOffset0 + widthOffset0].b +
    00066                 (int)source[sourceOffset0 + widthOffset1].b +
    00067                 (int)source[sourceOffset1 + widthOffset0].b +
    00068                 (int)source[sourceOffset1 + widthOffset1].b) / 4;
    00069             destination[offset + j].set(r, g, b);
    00070         }
    00071     }
    00072 }
    00073 //------------------------------------------------------------------------------
    00074 // フィルタ
    00075 void LinearMinificationFilter::filter(
    00076     const Color4c* source, const DimensionI& sourceSize,
    00077     Color4c* destination, const DimensionI destinationSize){
    00078     // 引数チェック
    00079     Assert(source != NULL);
    00080     Assert(sourceSize.width != 0);
    00081     Assert(sourceSize.height != 0);
    00082     Assert((sourceSize.width != 1) || (sourceSize.height != 1));
    00083     Assert(destination != NULL);
    00084     Assert(destinationSize.width != 0);
    00085     Assert(destinationSize.height != 0);
    00086     Assert(((sourceSize.width / 2) == destinationSize.width) ||
    00087         (sourceSize.width == 1));
    00088     Assert(((sourceSize.height / 2) == destinationSize.height) ||
    00089         (sourceSize.height == 1));
    00090     // フィルタ
    00091     for(int i = 0; i < destinationSize.height; i++){
    00092         int offset = i * destinationSize.width;
    00093         int sourceOffset0 = i * 2 * sourceSize.width;
    00094         int sourceOffset1 = sourceOffset0 + sourceSize.width;
    00095         if(sourceSize.height == 1){ sourceOffset1 -= sourceSize.width; }
    00096         for(int j = 0; j < destinationSize.width; j++){
    00097             int widthOffset0 = j * 2;
    00098             int widthOffset1 = widthOffset0 + 1;
    00099             if(sourceSize.width == 1){ widthOffset1 -= 1; }
    00100             int r = ((int)source[sourceOffset0 + widthOffset0].r +
    00101                 (int)source[sourceOffset0 + widthOffset1].r +
    00102                 (int)source[sourceOffset1 + widthOffset0].r +
    00103                 (int)source[sourceOffset1 + widthOffset1].r) / 4;
    00104             int g = ((int)source[sourceOffset0 + widthOffset0].g +
    00105                 (int)source[sourceOffset0 + widthOffset1].g +
    00106                 (int)source[sourceOffset1 + widthOffset0].g +
    00107                 (int)source[sourceOffset1 + widthOffset1].g) / 4;
    00108             int b = ((int)source[sourceOffset0 + widthOffset0].b +
    00109                 (int)source[sourceOffset0 + widthOffset1].b +
    00110                 (int)source[sourceOffset1 + widthOffset0].b +
    00111                 (int)source[sourceOffset1 + widthOffset1].b) / 4;
    00112             int a = ((int)source[sourceOffset0 + widthOffset0].a +
    00113                 (int)source[sourceOffset0 + widthOffset1].a +
    00114                 (int)source[sourceOffset1 + widthOffset0].a +
    00115                 (int)source[sourceOffset1 + widthOffset1].a) / 4;
    00116             destination[offset + j].set(r, g, b, a);
    00117         }
    00118     }
    00119 }
    00120 //------------------------------------------------------------------------------
    00121 } // End of namespace Lamp
    00122 //------------------------------------------------------------------------------