summaryrefslogtreecommitdiff
path: root/indra/llimage
diff options
context:
space:
mode:
authorCosmic Linden <cosmic@lindenlab.com>2023-10-13 10:39:03 -0700
committerCosmic Linden <cosmic@lindenlab.com>2023-10-13 10:39:03 -0700
commitab3b4edac7809008cfed6d1b77e5a4debb22c88e (patch)
tree312c2d96a9b803c04ea5ddac64b1a2586b45d8f4 /indra/llimage
parent7f7431891661668b898e03345c8023b4bbd0d9d9 (diff)
DRTVWR-592: Fix broken minimap loading, improve minimap view of PBR materials (still not accurate, but better...)
Diffstat (limited to 'indra/llimage')
-rw-r--r--indra/llimage/llimage.cpp53
-rw-r--r--indra/llimage/llimage.h6
2 files changed, 59 insertions, 0 deletions
diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp
index a96b6601bd..acfc254b65 100644
--- a/indra/llimage/llimage.cpp
+++ b/indra/llimage/llimage.cpp
@@ -31,6 +31,7 @@
#include "llmath.h"
#include "v4coloru.h"
+#include "v3color.h"
#include "llimagebmp.h"
#include "llimagetga.h"
@@ -1026,6 +1027,34 @@ bool LLImageRaw::optimizeAwayAlpha()
return false;
}
+bool LLImageRaw::makeAlpha()
+{
+ if (getComponents() == 3)
+ {
+ U8* data = getData();
+ U32 pixels = getWidth() * getHeight();
+
+ // alpha channel doesn't exist, make a new copy of data with alpha channel
+ U8* new_data = (U8*) ll_aligned_malloc_16(getWidth() * getHeight() * 4);
+
+ for (U32 i = 0; i < pixels; ++i)
+ {
+ U32 di = i * 4;
+ U32 si = i * 3;
+ for (U32 j = 0; j < 3; ++j)
+ {
+ new_data[di+j] = data[si+j];
+ }
+ }
+
+ setDataAndSize(new_data, getWidth(), getHeight(), 3);
+
+ return true;
+ }
+
+ return false;
+}
+
void LLImageRaw::expandToPowerOfTwo(S32 max_dim, bool scale_image)
{
// Find new sizes
@@ -1268,6 +1297,30 @@ void LLImageRaw::fill( const LLColor4U& color )
}
}
+void LLImageRaw::tint( const LLColor3& color )
+{
+ llassert( (3 == getComponents()) || (4 == getComponents()) );
+ if (isBufferInvalid())
+ {
+ LL_WARNS() << "Invalid image buffer" << LL_ENDL;
+ return;
+ }
+
+ S32 pixels = getWidth() * getHeight();
+ const S32 components = getComponents();
+ U8* data = getData();
+ for( S32 i = 0; i < pixels; i++ )
+ {
+ const float c0 = data[0] * color.mV[0];
+ const float c1 = data[1] * color.mV[1];
+ const float c2 = data[2] * color.mV[2];
+ data[0] = llclamp((U8)c0, 0, 255);
+ data[1] = llclamp((U8)c1, 0, 255);
+ data[2] = llclamp((U8)c2, 0, 255);
+ data += components;
+ }
+}
+
LLPointer<LLImageRaw> LLImageRaw::duplicate()
{
if(getNumRefs() < 2)
diff --git a/indra/llimage/llimage.h b/indra/llimage/llimage.h
index 8f9e1b3c54..77b5f0b7bc 100644
--- a/indra/llimage/llimage.h
+++ b/indra/llimage/llimage.h
@@ -71,6 +71,7 @@ const S32 HTTP_PACKET_SIZE = 1496;
class LLImageFormatted;
class LLImageRaw;
class LLColor4U;
+class LLColor3;
typedef enum e_image_codec
{
@@ -212,6 +213,8 @@ public:
// if the alpha channel is all 100% opaque, delete it
// returns true if alpha channel was deleted
bool optimizeAwayAlpha();
+ // Create an alpha channel if this image doesn't have one
+ bool makeAlpha();
static S32 biasedDimToPowerOfTwo(S32 curr_dim, S32 max_dim = MAX_IMAGE_SIZE);
static S32 expandDimToPowerOfTwo(S32 curr_dim, S32 max_dim = MAX_IMAGE_SIZE);
@@ -225,6 +228,9 @@ public:
// Fill the buffer with a constant color
void fill( const LLColor4U& color );
+ // Multiply this raw image by the given color
+ void tint( const LLColor3& color );
+
// Copy operations
//duplicate this raw image if refCount > 1.