From 55f597e2ec363b5cb22fa8f7f5694f7ef6a17772 Mon Sep 17 00:00:00 2001
From: Cosmic Linden <cosmic@lindenlab.com>
Date: Fri, 13 Oct 2023 09:56:28 -0700
Subject: DRTVWR-592: Allow using RGBA textures for terrain, as the texture
 uploader does not consolidate opaque textures

---
 indra/llimage/llimage.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'indra/llimage')

diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp
index 031471d1fe..a96b6601bd 100644
--- a/indra/llimage/llimage.cpp
+++ b/indra/llimage/llimage.cpp
@@ -1110,7 +1110,7 @@ void LLImageRaw::composite( LLImageRaw* src )
 		return;
 	}
 
-	llassert(3 == src->getComponents());
+	llassert((3 == src->getComponents()) || (4 == src->getComponents()));
 	llassert(3 == dst->getComponents());
 
 	if( 3 == dst->getComponents() )
-- 
cgit v1.2.3


From ab3b4edac7809008cfed6d1b77e5a4debb22c88e Mon Sep 17 00:00:00 2001
From: Cosmic Linden <cosmic@lindenlab.com>
Date: Fri, 13 Oct 2023 10:39:03 -0700
Subject: DRTVWR-592: Fix broken minimap loading, improve minimap view of PBR
 materials (still not accurate, but better...)

---
 indra/llimage/llimage.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++
 indra/llimage/llimage.h   |  6 ++++++
 2 files changed, 59 insertions(+)

(limited to 'indra/llimage')

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.
-- 
cgit v1.2.3


From 19163fd0fea6c92712b37e29f34b72edbbfe152d Mon Sep 17 00:00:00 2001
From: RunitaiLinden <davep@lindenlab.com>
Date: Thu, 18 Jan 2024 10:33:02 -0600
Subject: Allow for upload of 2k textures (#652)

* SL-20760 Allow 2k texture uploads

* SL-20760 Fix for textures not downloading.
---
 indra/llimage/llimage.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'indra/llimage')

diff --git a/indra/llimage/llimage.h b/indra/llimage/llimage.h
index 8f9e1b3c54..d1929b693f 100644
--- a/indra/llimage/llimage.h
+++ b/indra/llimage/llimage.h
@@ -33,7 +33,7 @@
 #include "lltrace.h"
 
 const S32 MIN_IMAGE_MIP =  2; // 4x4, only used for expand/contract power of 2
-const S32 MAX_IMAGE_MIP = 11; // 2048x2048
+const S32 MAX_IMAGE_MIP = 12; // 4096x4096
 
 // *TODO : Use MAX_IMAGE_MIP as max discard level and modify j2c management so that the number 
 // of levels is read from the header's file, not inferred from its size.
@@ -44,7 +44,7 @@ const S32 MAX_DISCARD_LEVEL = 5;
 // and declared right here. Some come from the JPEG2000 spec, some conventions specific to SL.
 const S32 MAX_DECOMPOSITION_LEVELS = 32;	// Number of decomposition levels cannot exceed 32 according to jpeg2000 spec
 const S32 MIN_DECOMPOSITION_LEVELS = 5;		// the SL viewer will *crash* trying to decode images with fewer than 5 decomposition levels (unless image is small that is)
-const S32 MAX_PRECINCT_SIZE = 2048;			// No reason to be bigger than MAX_IMAGE_SIZE 
+const S32 MAX_PRECINCT_SIZE = 4096;			// No reason to be bigger than MAX_IMAGE_SIZE 
 const S32 MIN_PRECINCT_SIZE = 4;			// Can't be smaller than MIN_BLOCK_SIZE
 const S32 MAX_BLOCK_SIZE = 64;				// Max total block size is 4096, hence 64x64 when using square blocks
 const S32 MIN_BLOCK_SIZE = 4;				// Min block dim is 4 according to jpeg2000 spec
@@ -52,11 +52,11 @@ const S32 MIN_LAYER_SIZE = 2000;			// Size of the first quality layer (after hea
 const S32 MAX_NB_LAYERS = 64;				// Max number of layers we'll entertain in SL (practical limit)
 
 const S32 MIN_IMAGE_SIZE = (1<<MIN_IMAGE_MIP); // 4, only used for expand/contract power of 2
-const S32 MAX_IMAGE_SIZE = (1<<MAX_IMAGE_MIP); // 2048
+const S32 MAX_IMAGE_SIZE = (1<<MAX_IMAGE_MIP); // 4096
 const S32 MIN_IMAGE_AREA = MIN_IMAGE_SIZE * MIN_IMAGE_SIZE;
 const S32 MAX_IMAGE_AREA = MAX_IMAGE_SIZE * MAX_IMAGE_SIZE;
 const S32 MAX_IMAGE_COMPONENTS = 8;
-const S32 MAX_IMAGE_DATA_SIZE = MAX_IMAGE_AREA * MAX_IMAGE_COMPONENTS; //2048 * 2048 * 8 = 16 MB
+const S32 MAX_IMAGE_DATA_SIZE = MAX_IMAGE_AREA * MAX_IMAGE_COMPONENTS; //4096 * 4096 * 8 = 128 MB
 
 // Note!  These CANNOT be changed without modifying simulator code
 // *TODO: change both to 1024 when SIM texture fetching is deprecated
-- 
cgit v1.2.3