summaryrefslogtreecommitdiff
path: root/Year_2/IandM/bitplane
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-02-18 19:18:32 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-02-18 19:18:32 +0100
commit1942f603803a92b0c2f078975a04167a6ee2f7bf (patch)
treed9d63dcce55c3f05fa94c94f4abf5f394aca2057 /Year_2/IandM/bitplane
parentab0dfb9eb5c0e1d39bb2e87bb3692171585a6716 (diff)
i&m: add operators
Diffstat (limited to 'Year_2/IandM/bitplane')
-rw-r--r--Year_2/IandM/bitplane/bitplane.pde39
-rw-r--r--Year_2/IandM/bitplane/data/lena.pngbin0 -> 473831 bytes
2 files changed, 39 insertions, 0 deletions
diff --git a/Year_2/IandM/bitplane/bitplane.pde b/Year_2/IandM/bitplane/bitplane.pde
new file mode 100644
index 0000000..33cda9c
--- /dev/null
+++ b/Year_2/IandM/bitplane/bitplane.pde
@@ -0,0 +1,39 @@
+int nb = 0;
+
+void setup() {
+ size(512, 256);
+}
+
+void draw() {
+ PImage img = loadImage("lena.png");
+ img.resize(256, 256);
+ img.filter(GRAY);
+
+ image(img, 0, 0);
+ image(bitplane(img, nb), 256, 0);
+}
+
+void keyPressed() {
+ if(key == '+' && nb < 7) {
+ nb++;
+ } else if(key == '-' && nb > 1) {
+ nb--;
+ }
+}
+
+PImage bitplane(PImage I, int nb) {
+ PImage out = I.copy();
+ out.loadPixels();
+
+ int x, r;
+
+ for (int i = 0; i < out.pixels.length; ++i) {
+ x = int(red(out.pixels[i]));
+ r = (x >> nb) & 1;
+ out.pixels[i] = color(255*r);
+ }
+
+ out.updatePixels();
+
+ return out;
+}
diff --git a/Year_2/IandM/bitplane/data/lena.png b/Year_2/IandM/bitplane/data/lena.png
new file mode 100644
index 0000000..59ef68a
--- /dev/null
+++ b/Year_2/IandM/bitplane/data/lena.png
Binary files differ