PageRenderTime 136ms CodeModel.GetById 119ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llviewerlayer.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 100 lines | 54 code | 15 blank | 31 comment | 1 complexity | cb2293c4092b7eb896b46c1ab7c268aa MD5 | raw file
  1/** 
  2 * @file llviewerlayer.cpp
  3 * @brief LLViewerLayer class implementation
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llviewerlayer.h"
 30#include "llerror.h"
 31#include "llmath.h"
 32
 33LLViewerLayer::LLViewerLayer(const S32 width, const F32 scale)
 34{
 35	mWidth = width;
 36	mScale = scale;
 37	mScaleInv = 1.f/scale;
 38	mDatap = new F32[width*width];
 39
 40	for (S32 i = 0; i < width*width; i++)
 41	{
 42		*(mDatap + i) = 0.f;
 43	}
 44}
 45
 46LLViewerLayer::~LLViewerLayer()
 47{
 48	delete[] mDatap;
 49	mDatap = NULL;
 50}
 51
 52F32 LLViewerLayer::getValue(const S32 x, const S32 y) const
 53{
 54//	llassert(x >= 0);
 55//	llassert(x < mWidth);
 56//	llassert(y >= 0);
 57//	llassert(y < mWidth);
 58
 59	return *(mDatap + x + y*mWidth);
 60}
 61
 62F32 LLViewerLayer::getValueScaled(const F32 x, const F32 y) const
 63{
 64	S32 x1, x2, y1, y2;
 65	F32 x_frac, y_frac;
 66
 67	x_frac = x*mScaleInv;
 68	x1 = llfloor(x_frac);
 69	x2 = x1 + 1;
 70	x_frac -= x1;
 71
 72	y_frac = y*mScaleInv;
 73	y1 = llfloor(y_frac);
 74	y2 = y1 + 1;
 75	y_frac -= y1;
 76
 77	x1 = llmin((S32)mWidth-1, x1);
 78	x1 = llmax(0, x1);
 79	x2 = llmin((S32)mWidth-1, x2);
 80	x2 = llmax(0, x2);
 81	y1 = llmin((S32)mWidth-1, y1);
 82	y1 = llmax(0, y1);
 83	y2 = llmin((S32)mWidth-1, y2);
 84	y2 = llmax(0, y2);
 85
 86	// Take weighted average of all four points (bilinear interpolation)
 87	S32 row1 = y1 * mWidth;
 88	S32 row2 = y2 * mWidth;
 89	
 90	// Access in squential order in memory, and don't use immediately.
 91	F32 row1_left  = mDatap[ row1 + x1 ];
 92	F32 row1_right = mDatap[ row1 + x2 ];
 93	F32 row2_left  = mDatap[ row2 + x1 ];
 94	F32 row2_right = mDatap[ row2 + x2 ];
 95	
 96	F32 row1_interp = row1_left - x_frac * (row1_left - row1_right);
 97	F32 row2_interp = row2_left - x_frac * (row2_left - row2_right);
 98	
 99	return row1_interp - y_frac * (row1_interp - row2_interp);
100}