summaryrefslogtreecommitdiff
path: root/Year_2/IandM/bitplane
diff options
context:
space:
mode:
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