diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp
index eaac6806ab16d3927140c1a4b6736a31cbef3a49..d336eeaabcea413465564b5dfb299a3f88c8e18d 100755
--- a/indra/llimage/llimage.cpp
+++ b/indra/llimage/llimage.cpp
@@ -524,7 +524,7 @@ inline U8 LLImageRaw::fastFractionalMult( U8 a, U8 b )
 }
 
 
-void LLImageRaw::composite( const LLImageRaw* src )
+void LLImageRaw::composite( LLImageRaw* src )
 {
 	LLImageRaw* dst = this;  // Just for clarity.
 
@@ -560,7 +560,7 @@ void LLImageRaw::composite( const LLImageRaw* src )
 }
 
 // Src and dst can be any size.  Src has 4 components.  Dst has 3 components.
-void LLImageRaw::compositeScaled4onto3(const LLImageRaw* src)
+void LLImageRaw::compositeScaled4onto3(LLImageRaw* src)
 {
 	LL_INFOS() << "compositeScaled4onto3" << LL_ENDL;
 
@@ -568,12 +568,26 @@ void LLImageRaw::compositeScaled4onto3(const LLImageRaw* src)
 
 	llassert( (4 == src->getComponents()) && (3 == dst->getComponents()) );
 
-	ll_nn2d_interpolation(src->getData(), src->getWidth(), src->getHeight(), src->getComponents(), dst->getData(), dst->getWidth(), dst->getHeight(), dst->getComponents());
+	S32 temp_data_size = src->getWidth() * dst->getHeight() * src->getComponents();
+	llassert_always(temp_data_size > 0);
+	std::vector<U8> temp_buffer(temp_data_size);
+
+	// Vertical: scale but no composite
+	for( S32 col = 0; col < src->getWidth(); col++ )
+	{
+		copyLineScaled( src->getData() + (src->getComponents() * col), &temp_buffer[0] + (src->getComponents() * col), src->getHeight(), dst->getHeight(), src->getWidth(), src->getWidth() );
+	}
+
+	// Horizontal: scale and composite
+	for( S32 row = 0; row < dst->getHeight(); row++ )
+	{
+		compositeRowScaled4onto3( &temp_buffer[0] + (src->getComponents() * src->getWidth() * row), dst->getData() + (dst->getComponents() * dst->getWidth() * row), src->getWidth(), dst->getWidth() );
+	}
 }
 
 
 // Src and dst are same size.  Src has 4 components.  Dst has 3 components.
-void LLImageRaw::compositeUnscaled4onto3( const LLImageRaw* src )
+void LLImageRaw::compositeUnscaled4onto3( LLImageRaw* src )
 {
 	/*
 	//test fastFractionalMult()
@@ -596,7 +610,7 @@ void LLImageRaw::compositeUnscaled4onto3( const LLImageRaw* src )
 	llassert( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) );
 
 
-	const U8* src_data = src->getData();
+	U8* src_data = src->getData();
 	U8* dst_data = dst->getData();
 	S32 pixels = getWidth() * getHeight();
 	while( pixels-- )
@@ -737,7 +751,7 @@ void LLImageRaw::copy(LLImageRaw* src)
 }
 
 // Src and dst are same size.  Src and dst have same number of components.
-void LLImageRaw::copyUnscaled(const LLImageRaw* src)
+void LLImageRaw::copyUnscaled(LLImageRaw* src)
 {
 	LLImageRaw* dst = this;  // Just for clarity.
 
@@ -819,7 +833,7 @@ void LLImageRaw::copyUnscaled3onto4( LLImageRaw* src )
 
 
 // Src and dst can be any size.  Src and dst have same number of components.
-void LLImageRaw::copyScaled( const LLImageRaw* src )
+void LLImageRaw::copyScaled( LLImageRaw* src )
 {
 	LLImageRaw* dst = this;  // Just for clarity.
 
@@ -832,7 +846,21 @@ void LLImageRaw::copyScaled( const LLImageRaw* src )
 		return;
 	}
 
-	ll_nn2d_interpolation(src->getData(), src->getWidth(), src->getHeight(), src->getComponents(), dst->getData(), dst->getWidth(), dst->getHeight(), dst->getComponents());
+	S32 temp_data_size = src->getWidth() * dst->getHeight() * getComponents();
+	llassert_always(temp_data_size > 0);
+	std::vector<U8> temp_buffer(temp_data_size);
+
+	// Vertical
+	for( S32 col = 0; col < src->getWidth(); col++ )
+	{
+		copyLineScaled( src->getData() + (getComponents() * col), &temp_buffer[0] + (getComponents() * col), src->getHeight(), dst->getHeight(), src->getWidth(), src->getWidth() );
+	}
+
+	// Horizontal
+	for( S32 row = 0; row < dst->getHeight(); row++ )
+	{
+		copyLineScaled( &temp_buffer[0] + (getComponents() * src->getWidth() * row), dst->getData() + (getComponents() * dst->getWidth() * row), src->getWidth(), dst->getWidth(), 1, 1 );
+	}
 }
 
 
@@ -852,17 +880,25 @@ BOOL LLImageRaw::scale( S32 new_width, S32 new_height, BOOL scale_image_data )
 
 	if (scale_image_data)
 	{
-		S32 new_data_size = new_width * new_height * getComponents();
-		llassert_always(new_data_size > 0);
+		S32 temp_data_size = old_width * new_height * getComponents();
+		llassert_always(temp_data_size > 0);
+		std::vector<U8> temp_buffer(temp_data_size);
 
-		U8 *new_data = (U8*)ALLOCATE_MEM(LLImageBase::getPrivatePool(), new_data_size); 
-		if(NULL == new_data) 
+		// Vertical
+		for( S32 col = 0; col < old_width; col++ )
 		{
-			return FALSE; 
+			copyLineScaled( getData() + (getComponents() * col), &temp_buffer[0] + (getComponents() * col), old_height, new_height, old_width, old_width );
 		}
 
-		ll_nn2d_interpolation(getData(), old_width, old_height, getComponents(), new_data, new_width, new_height, getComponents());
-		setDataAndSize(new_data, new_width, new_height, getComponents());
+		deleteData();
+
+		U8* new_buffer = allocateDataSize(new_width, new_height, getComponents());
+
+		// Horizontal
+		for( S32 row = 0; row < new_height; row++ )
+		{
+			copyLineScaled( &temp_buffer[0] + (getComponents() * old_width * row), new_buffer + (getComponents() * new_width * row), old_width, new_width, 1, 1 );
+		}
 	}
 	else
 	{
diff --git a/indra/llimage/llimage.h b/indra/llimage/llimage.h
index eeb8e6de537db185ea68565784e56927d5143cfe..cd3f76f1fd0e3a0ac195874bd8611b211698fa15 100755
--- a/indra/llimage/llimage.h
+++ b/indra/llimage/llimage.h
@@ -229,7 +229,7 @@ public:
 	void copy( LLImageRaw* src );
 
 	// Src and dst are same size.  Src and dst have same number of components.
-	void copyUnscaled( const LLImageRaw* src );
+	void copyUnscaled( LLImageRaw* src );
 	
 	// Src and dst are same size.  Src has 4 components.  Dst has 3 components.
 	void copyUnscaled4onto3( LLImageRaw* src );
@@ -243,7 +243,7 @@ public:
 	void copyUnscaledAlphaMask( LLImageRaw* src, const LLColor4U& fill);
 
 	// Src and dst can be any size.  Src and dst have same number of components.
-	void copyScaled( const LLImageRaw* src );
+	void copyScaled( LLImageRaw* src );
 
 	// Src and dst can be any size.  Src has 3 components.  Dst has 4 components.
 	void copyScaled3onto4( LLImageRaw* src );
@@ -255,13 +255,13 @@ public:
 	// Composite operations
 
 	// Src and dst can be any size.  Src and dst can each have 3 or 4 components.
-	void composite( const LLImageRaw* src );
+	void composite( LLImageRaw* src );
 
 	// Src and dst can be any size.  Src has 4 components.  Dst has 3 components.
-	void compositeScaled4onto3( const LLImageRaw* src );
+	void compositeScaled4onto3( LLImageRaw* src );
 
 	// Src and dst are same size.  Src has 4 components.  Dst has 3 components.
-	void compositeUnscaled4onto3( const LLImageRaw* src );
+	void compositeUnscaled4onto3( LLImageRaw* src );
 
 protected:
 	// Create an image from a local file (generally used in tools)
diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h
index b4ac1dec73e7088fc8354b68ef7017561bc73b00..a8b27ad189d033319d3ea7d81de0ace162174b50 100755
--- a/indra/llmath/llmath.h
+++ b/indra/llmath/llmath.h
@@ -32,7 +32,6 @@
 #include <vector>
 #include <limits>
 #include "lldefs.h"
-#include "llerror.h"
 //#include "llstl.h" // *TODO: Remove when LLString is gone
 //#include "llstring.h" // *TODO: Remove when LLString is gone
 // lltut.h uses is_approx_equal_fraction(). This was moved to its own header
@@ -557,35 +556,6 @@ inline void ll_remove_outliers(std::vector<VEC_TYPE>& data, F32 k)
 	}
 }
 
-inline void	ll_nn2d_interpolation(const U8 *const src, U32 srcW, U32 srcH, U8 srcCh, U8 *const dst, U32 dstW, U32 dstH, U8 dstCh)
-{
-	llassert(srcCh>=dstCh);
-
-	S32 tmp_x = 0, tmp_y = 0, tmp_x1 = 0, tmp_x2 = 0;
-
-	const S32 x_r = ((srcW<<16)/dstW)+1;
-	const S32 y_r = ((srcH<<16)/dstH)+1;
-	const S32 srcW_ch = srcW*srcCh;
-	const S32 dstW_ch = dstW*dstCh;
-
-	for(U32 y = 0; y < dstH; ++y)
-	{
-		tmp_y = ((y*y_r)>>16)*srcW_ch;
-		tmp_x1 = y*dstW_ch;
-
-		for(U32 x = 0; x < dstW; x++)
-		{
-			tmp_x = (((x*x_r)>>16)*srcCh)+tmp_y;
-			tmp_x2 = tmp_x1+x*dstCh;
-
-			for(U8 c = 0; c < dstCh; ++c)
-			{
-				dst[tmp_x2+c] = src[tmp_x+c];
-			}
-		}
-	}
-}
-
 // Include simd math header
 #include "llsimdmath.h"