aboutsummaryrefslogtreecommitdiff
path: root/Src/Wasabi/bfc/draw/convolve.cpp
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Wasabi/bfc/draw/convolve.cpp
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/Wasabi/bfc/draw/convolve.cpp')
-rw-r--r--Src/Wasabi/bfc/draw/convolve.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/Src/Wasabi/bfc/draw/convolve.cpp b/Src/Wasabi/bfc/draw/convolve.cpp
new file mode 100644
index 00000000..2ac48930
--- /dev/null
+++ b/Src/Wasabi/bfc/draw/convolve.cpp
@@ -0,0 +1,60 @@
+#include <precomp.h>
+
+#include "convolve.h"
+
+#define RED(a) (((a)>>16)&0xff)
+#define GRN(a) (((a)>>8)&0xff)
+#define BLU(a) (((a)&0xff))
+#define ALP(a) (((a)>>24))
+
+Convolve3x3::Convolve3x3(ARGB32 *_bits, int _w, int _h) : bits(_bits), w(_w), h(_h) {
+ ZERO(vals);
+ multiplier = 0;
+}
+
+void Convolve3x3::setPos(int x, int y, float v) {
+ ASSERT(x >= -1 && x <= 1 && y >= -1 && y <= 1);
+ vals[y+1][x+1] = v;
+}
+
+void Convolve3x3::setMultiplier(int m) {
+ multiplier = m;
+}
+
+void Convolve3x3::convolve() {
+ if (bits == NULL || w <= 0 || h <= 0) return; // nothin'
+ MemMatrix<ARGB32> temp(w, h, bits); // make a copy
+ for (int y = 0; y < h; y++) {
+ for (int x = 0; x < w; x++) {
+ if (ALP(temp(x, y))<=1) continue;
+ float ra=0, rg=0, rb=0;
+ for (int a = -1; a <= 1; a++) {
+ for (int b = -1; b <= 1; b++) {
+ int px = x + a, py = y + b;
+ if (px < 0 || px >= w || py < 0 || py >= h) continue;
+ ARGB32 c = temp(px, py);
+ if (ALP(c) <= 1) continue;
+ ra += (float)RED(c) * vals[b][a] * multiplier;
+ rg += (float)GRN(c) * vals[b][a] * multiplier;
+ rb += (float)BLU(c) * vals[b][a] * multiplier;
+ }
+ }
+ unsigned int r = MINMAX((int)ra, 0, 255);
+ unsigned int g = MINMAX((int)rg, 0, 255);
+ unsigned int b = MINMAX((int)rb, 0, 255);
+ unsigned int lum = MAX(MAX(r, g), b);
+if (lum < 64) lum = 0;
+else if (lum > 192) lum = 255;
+ //bits[x+y*w] = (ALP(*temp.m(x, y))<<24)|(r<<16)|(g<<8)|(b);
+ bits[x+y*w] &= 0xffffff;
+ bits[x+y*w] |= (255-lum) << 24;
+//if (lum < 64) {
+// bits[x+y*w] &= 0xffff00ff;
+// bits[x+y*w] |= lum << 8;
+//} else {
+// bits[x+y*w] &= 0xff00ffff;
+// bits[x+y*w] |= lum << 16;
+//}
+ }
+ }
+}