aboutsummaryrefslogtreecommitdiff
path: root/Plugins/hist.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Plugins/hist.cpp')
-rw-r--r--Plugins/hist.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/Plugins/hist.cpp b/Plugins/hist.cpp
new file mode 100644
index 0000000..f525db1
--- /dev/null
+++ b/Plugins/hist.cpp
@@ -0,0 +1,54 @@
+//
+// build an array where x=color intensity and y=number of colors with that intensity.
+// use with fs.hist.pd.
+//
+// array is passed in a file, a better solution would be to use vframe...
+//
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <iostream.h>
+#include <fstream.h>
+#include <string.h>
+#include "plugin.h"
+#include "pixels.h"
+
+void perform_effect(_frame f, _args a)
+{
+ if(!a.s) return;
+
+ // parameters: <color> <filename for output> <pd receivename to bang>
+ // get gol
+ byte col = atoi(a.s);
+
+ // get filename
+ char *t;
+ if(!(t = strstr(a.s, " "))) return;
+ char *filename = t+1;
+
+ // get receivename
+ if(!(t = strstr(t+1, " "))) return;
+ char *retname = t+1;
+ t[0]=0; // tell filename and receivename apart
+
+ pixels p(f);
+ signed short hist[256]; // 16bits, for read16 on pd
+
+// count colors from zero up
+ memset(hist, 0, sizeof(hist));
+// or count from -2^15 (bottom of graph)?
+// short i, v=1<<15;
+// for(i=0; i<256; hist[i++]=v) ;
+
+ while(!p.eof())
+ {
+ ++hist[col==0 ? p.red() : col==1 ? p.green() : col==2 ? p.blue() : 0];
+ p.next();
+ }
+
+ ofstream of(filename, ios::out|ios::binary);
+ of.write((char *)&hist, sizeof(hist));
+ of.close();
+
+ sprintf(a.ret, "%s=1", retname); // bang to indicate we're done
+}