From 9112a47f9be023dd83bf4de72d490d21d85e6b5e Mon Sep 17 00:00:00 2001
From: Merov Linden <merov@lindenlab.com>
Date: Thu, 6 Feb 2014 10:26:25 -0800
Subject: [PATCH] ACME-1301 : Add convolve as a secondary filter command

---
 .../llimage_libtest/filters/convolve.xml      | 18 ++++++++++++++++++
 indra/llimage/llimagefilter.cpp               | 19 +++++++++++++++----
 2 files changed, 33 insertions(+), 4 deletions(-)
 create mode 100644 indra/integration_tests/llimage_libtest/filters/convolve.xml

diff --git a/indra/integration_tests/llimage_libtest/filters/convolve.xml b/indra/integration_tests/llimage_libtest/filters/convolve.xml
new file mode 100644
index 00000000000..6e65b5f88a7
--- /dev/null
+++ b/indra/integration_tests/llimage_libtest/filters/convolve.xml
@@ -0,0 +1,18 @@
+<llsd>
+    <array>
+        <array>
+            <string>convolve</string>
+            <real>1.0</real>
+            <real>0.0</real>
+            <real>4.0</real>
+            <real>1.0</real>
+            <real>4.0</real>
+            <real>1.0</real>
+            <real>0.0</real>
+            <real>1.0</real>
+            <real>4.0</real>
+            <real>1.0</real>
+            <real>4.0</real>
+        </array>
+    </array>
+</llsd>
diff --git a/indra/llimage/llimagefilter.cpp b/indra/llimage/llimagefilter.cpp
index 7734b08c188..9093e4b59c9 100755
--- a/indra/llimage/llimagefilter.cpp
+++ b/indra/llimage/llimagefilter.cpp
@@ -230,21 +230,32 @@ void LLImageFilter::executeFilter(LLPointer<LLImageRaw> raw_image)
         else if (filter_name == "sharpen")
         {
             LLMatrix3 kernel;
-            for (S32 i = 0; i < NUM_VALUES_IN_MAT3; i++)
+            for (S32 k = 0; k < NUM_VALUES_IN_MAT3; k++)
                 for (S32 j = 0; j < NUM_VALUES_IN_MAT3; j++)
-                    kernel.mMatrix[i][j] = -1.0;
+                    kernel.mMatrix[k][j] = -1.0;
             kernel.mMatrix[1][1] = 9.0;
             convolve(kernel,false,false);
         }
         else if (filter_name == "gradient")
         {
             LLMatrix3 kernel;
-            for (S32 i = 0; i < NUM_VALUES_IN_MAT3; i++)
+            for (S32 k = 0; k < NUM_VALUES_IN_MAT3; k++)
                 for (S32 j = 0; j < NUM_VALUES_IN_MAT3; j++)
-                    kernel.mMatrix[i][j] = -1.0;
+                    kernel.mMatrix[k][j] = -1.0;
             kernel.mMatrix[1][1] = 8.0;
             convolve(kernel,false,true);
         }
+        else if (filter_name == "convolve")
+        {
+            LLMatrix3 kernel;
+            S32 index = 1;
+            bool normalize = (mFilterData[i][index++].asReal() > 0.0);
+            bool abs_value = (mFilterData[i][index++].asReal() > 0.0);
+            for (S32 k = 0; k < NUM_VALUES_IN_MAT3; k++)
+                for (S32 j = 0; j < NUM_VALUES_IN_MAT3; j++)
+                    kernel.mMatrix[k][j] = mFilterData[i][index++].asReal();
+            convolve(kernel,normalize,abs_value);
+        }
         else
         {
             llwarns << "Filter unknown, cannot execute filter command : " << filter_name << llendl;
-- 
GitLab