00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034 #include "llviewerlayer.h"
00035 #include "llerror.h"
00036 #include "llmath.h"
00037
00038 LLViewerLayer::LLViewerLayer(const S32 width, const F32 scale)
00039 {
00040 mWidth = width;
00041 mScale = scale;
00042 mScaleInv = 1.f/scale;
00043 mDatap = new F32[width*width];
00044
00045 for (S32 i = 0; i < width*width; i++)
00046 {
00047 *(mDatap + i) = 0.f;
00048 }
00049 }
00050
00051 LLViewerLayer::~LLViewerLayer()
00052 {
00053 delete[] mDatap;
00054 mDatap = NULL;
00055 }
00056
00057 F32 LLViewerLayer::getValue(const S32 x, const S32 y) const
00058 {
00059
00060
00061
00062
00063
00064 return *(mDatap + x + y*mWidth);
00065 }
00066
00067 F32 LLViewerLayer::getValueScaled(const F32 x, const F32 y) const
00068 {
00069 S32 x1, x2, y1, y2;
00070 F32 x_frac, y_frac;
00071
00072 x_frac = x*mScaleInv;
00073 x1 = llfloor(x_frac);
00074 x2 = x1 + 1;
00075 x_frac -= x1;
00076
00077 y_frac = y*mScaleInv;
00078 y1 = llfloor(y_frac);
00079 y2 = y1 + 1;
00080 y_frac -= y1;
00081
00082 x1 = llmin((S32)mWidth-1, x1);
00083 x1 = llmax(0, x1);
00084 x2 = llmin((S32)mWidth-1, x2);
00085 x2 = llmax(0, x2);
00086 y1 = llmin((S32)mWidth-1, y1);
00087 y1 = llmax(0, y1);
00088 y2 = llmin((S32)mWidth-1, y2);
00089 y2 = llmax(0, y2);
00090
00091
00092 S32 row1 = y1 * mWidth;
00093 S32 row2 = y2 * mWidth;
00094
00095
00096 F32 row1_left = mDatap[ row1 + x1 ];
00097 F32 row1_right = mDatap[ row1 + x2 ];
00098 F32 row2_left = mDatap[ row2 + x1 ];
00099 F32 row2_right = mDatap[ row2 + x2 ];
00100
00101 F32 row1_interp = row1_left - x_frac * (row1_left - row1_right);
00102 F32 row2_interp = row2_left - x_frac * (row2_left - row2_right);
00103
00104 return row1_interp - y_frac * (row1_interp - row2_interp);
00105 }