PageRenderTime 77ms CodeModel.GetById 18ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  27. #include "llviewerlayer.h"
  28. #include "llerror.h"
  29. #include "llmath.h"
  30. LLViewerLayer::LLViewerLayer(const S32 width, const F32 scale)
  31. {
  32. mWidth = width;
  33. mScale = scale;
  34. mScaleInv = 1.f/scale;
  35. mDatap = new F32[width*width];
  36. for (S32 i = 0; i < width*width; i++)
  37. {
  38. *(mDatap + i) = 0.f;
  39. }
  40. }
  41. LLViewerLayer::~LLViewerLayer()
  42. {
  43. delete[] mDatap;
  44. mDatap = NULL;
  45. }
  46. F32 LLViewerLayer::getValue(const S32 x, const S32 y) const
  47. {
  48. // llassert(x >= 0);
  49. // llassert(x < mWidth);
  50. // llassert(y >= 0);
  51. // llassert(y < mWidth);
  52. return *(mDatap + x + y*mWidth);
  53. }
  54. F32 LLViewerLayer::getValueScaled(const F32 x, const F32 y) const
  55. {
  56. S32 x1, x2, y1, y2;
  57. F32 x_frac, y_frac;
  58. x_frac = x*mScaleInv;
  59. x1 = llfloor(x_frac);
  60. x2 = x1 + 1;
  61. x_frac -= x1;
  62. y_frac = y*mScaleInv;
  63. y1 = llfloor(y_frac);
  64. y2 = y1 + 1;
  65. y_frac -= y1;
  66. x1 = llmin((S32)mWidth-1, x1);
  67. x1 = llmax(0, x1);
  68. x2 = llmin((S32)mWidth-1, x2);
  69. x2 = llmax(0, x2);
  70. y1 = llmin((S32)mWidth-1, y1);
  71. y1 = llmax(0, y1);
  72. y2 = llmin((S32)mWidth-1, y2);
  73. y2 = llmax(0, y2);
  74. // Take weighted average of all four points (bilinear interpolation)
  75. S32 row1 = y1 * mWidth;
  76. S32 row2 = y2 * mWidth;
  77. // Access in squential order in memory, and don't use immediately.
  78. F32 row1_left = mDatap[ row1 + x1 ];
  79. F32 row1_right = mDatap[ row1 + x2 ];
  80. F32 row2_left = mDatap[ row2 + x1 ];
  81. F32 row2_right = mDatap[ row2 + x2 ];
  82. F32 row1_interp = row1_left - x_frac * (row1_left - row1_right);
  83. F32 row2_interp = row2_left - x_frac * (row2_left - row2_right);
  84. return row1_interp - y_frac * (row1_interp - row2_interp);
  85. }