inv cam shits
authorSyed S. Albiz <ssalbiz@uwaterloo.ca>
Wed, 27 Jun 2012 05:02:44 +0000 (01:02 -0400)
committerSyed S. Albiz <ssalbiz@uwaterloo.ca>
Wed, 27 Jun 2012 05:02:44 +0000 (01:02 -0400)
bg.png [new file with mode: 0644]
blit_fb [new file with mode: 0755]
camwho
invcam [new file with mode: 0755]
invcamd [new file with mode: 0755]
last [new file with mode: 0755]
montage [new file with mode: 0755]
out.png [new file with mode: 0644]
shit.c [new file with mode: 0644]

diff --git a/bg.png b/bg.png
new file mode 100644 (file)
index 0000000..1ce1f3f
Binary files /dev/null and b/bg.png differ
diff --git a/blit_fb b/blit_fb
new file mode 100755 (executable)
index 0000000..afaaad1
Binary files /dev/null and b/blit_fb differ
diff --git a/camwho b/camwho
index 8c1d219..e8ffdcb 100755 (executable)
--- a/camwho
+++ b/camwho
@@ -1,14 +1,21 @@
 #!/bin/bash
 
-OUTPUT_FILE=/scratch/camwho_output
+OLD_PERVS=
+PERVS=
+PORT=7000
 
 while [ 1 -eq 1 ];
 do
-  grep -E '(webcam HTTP|Webcams HTTP)' /var/log/apache2/access.log | \
+  PERVS=`grep -E '(webcam HTTP|Webcams HTTP)' /var/log/apache2/access.log | \
     grep ' 200 ' | \
     sed 's/\].*$/]/' | \
     sed 's/ \[.*$//' | \
     sed 's/^.*- //' | \
-    tail > $OUTPUT_FILE
+    tail`
+  if [ "$OLD_PERVS" != "$PERVS" ];
+  then
+    OLD_PERVS=$PERVS
+    echo $PERVS | nc nullsleep $PORT
+  fi
   sleep 1
 done
diff --git a/invcam b/invcam
new file mode 100755 (executable)
index 0000000..563298c
--- /dev/null
+++ b/invcam
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+PORT=7000
+#MONTAGE=/opt/invcam/montage
+MONTAGE=/opt/invcam/last
+
+nc -kl $PORT | $MONTAGE
diff --git a/invcamd b/invcamd
new file mode 100755 (executable)
index 0000000..16fad20
--- /dev/null
+++ b/invcamd
@@ -0,0 +1,20 @@
+#!/bin/bash
+
+PIDFILE=/var/run/invcam.pid
+DAEMON="/bin/bash /opt/invcam/invcam"
+
+case "$1" in
+       start)
+               start-stop-daemon -S -mp $PIDFILE -x $DAEMON -b
+               ;;
+       stop)
+               start-stop-daemon -K -p $PIDFILE -x $DAEMON
+               ;;
+       restart)
+               "$0" stop
+               "$0" start
+               ;;
+       *)
+               echo "Usage: $0 (start|stop|restart)"
+               ;;
+esac
diff --git a/last b/last
new file mode 100755 (executable)
index 0000000..8d9d090
--- /dev/null
+++ b/last
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+picpath="/users/ssalbiz/dev/invcam/"
+
+while read -e user
+do
+  user=`echo $user | sed 's/.* //'`
+  echo $user
+  if [ -f  "${picpath}/${user}.png" ]; then
+    ./blit_fb "${picpath}/${user}.png"
+  else
+    ./blit_fb "${picpath}/black.png"
+  fi
+done
diff --git a/montage b/montage
new file mode 100755 (executable)
index 0000000..7c51d08
--- /dev/null
+++ b/montage
@@ -0,0 +1,34 @@
+#!/bin/bash
+# Usage: ./shit.sh (takes input via stdin in the form of space separated usernames)
+
+userlist=
+filelist=""
+picpath="/users/ssalbiz/dev/invcam"
+line=""
+rc=0
+
+#while read -e userlist
+read -e userlist
+#do
+  for user in $userlist
+  do
+    echo $user
+    f="${picpath}/${user}.png"
+    if [ -f  "${picpath}/${user}.png" ]; then
+      f="${picpath}/${user}.png"
+    else
+      f="${picpath}/placeholder.png"
+    fi
+    filelist="$filelist ${f}"
+  done
+  echo $filelist
+
+  if [ ${#filelist} -gt 0 ]; then
+    echo montage -border 0 -geometry "1024x720+5+5" -background black $filelist "bg.png"
+    montage -border 0 -geometry "1024x720+5+5" -background black -label '%t' $filelist "${picpath}/bg.png"
+    ./blit_fb "${picpath}/bg.png"
+  else
+#    echo feh --bg-scale "${picpath}/black.png"
+    ./blit_fb "${picpath}/black.png"
+  fi
+#done
diff --git a/out.png b/out.png
new file mode 100644 (file)
index 0000000..6380f47
Binary files /dev/null and b/out.png differ
diff --git a/shit.c b/shit.c
new file mode 100644 (file)
index 0000000..3281463
--- /dev/null
+++ b/shit.c
@@ -0,0 +1,108 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <fcntl.h>
+#include <linux/fb.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <assert.h>
+#include <png.h>
+
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
+#define MAX(x, y) ((x) > (y) ? (x) : (y))
+
+int main(int argc, char** argv)
+{
+    int fbfd = 0;
+    struct fb_var_screeninfo vinfo;
+    struct fb_fix_screeninfo finfo;
+    long int screensize = 0;
+    char *fbp = 0;
+    long int location = 0;
+    if (argc < 2) {
+      perror("Error: need a png to shit");
+      return 1;
+    }
+    FILE * fp = fopen(argv[1], "rb");
+    if (!fp) {
+      perror("Error: need a valid png to shit");
+      perror(argv[1]);
+      return 1;
+    }
+    png_structp png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, NULL,
+        NULL, NULL);;
+    if (!png_ptr) {
+      perror("THAT SHIT CRAY");
+      exit(1);
+    }
+    png_infop info_ptr = png_create_info_struct(png_ptr);
+    if (!info_ptr) {
+      perror("THAT SHIT CRAY");
+      exit(1);
+    }
+    png_init_io(png_ptr, fp);
+    png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
+    png_bytepp row_pointers = png_get_rows(png_ptr, info_ptr);
+
+    // Open the file for reading and writing
+    fbfd = open("/dev/fb0", O_RDWR);
+    if (fbfd == -1) {
+        perror("Error: cannot open framebuffer device");
+        exit(1);
+    }
+    printf("The framebuffer device was opened successfully.\n");
+
+    // Get fixed screen information
+    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {
+        perror("Error reading fixed information");
+        exit(2);
+    }
+
+    // Get variable screen information
+    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
+        perror("Error reading variable information");
+        exit(3);
+    }
+
+    printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);
+
+    // Figure out the size of the screen in bytes
+    screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
+
+    // Map the device to memory
+    fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
+    if ((int)fbp == -1) {
+        perror("Error: failed to map framebuffer device to memory");
+        exit(4);
+    }
+    printf("The framebuffer device was mapped to memory successfully.\n");
+    uint8_t channels = png_get_channels(png_ptr, info_ptr);
+
+    printf("png # of channels: %d\n", channels);
+
+    // dump this shit to a framebuffer nigga
+    assert(vinfo.bits_per_pixel == 32);
+    for (int y = 0; y < MIN(info_ptr->height, vinfo.yres); ++y) {
+      for (int x = 0; x < MIN(info_ptr->width, channels*vinfo.xres); ++x) {
+        assert(x*y*3 < channels*screensize);
+        location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
+                    (y+vinfo.yoffset) * finfo.line_length;
+
+        if (channels == 3 || channels == 4) {
+          *(fbp + location) = row_pointers[y][channels*x+2]; // BLUE
+          *(fbp + location + 1) = row_pointers[y][(channels*x)+1]; // GREEN
+          *(fbp + location + 2) = row_pointers[y][(channels*x)+0]; // RED
+        } else if (channels == 1) {
+          *(fbp + location) = row_pointers[y][x]; // BLUE
+          *(fbp + location + 1) = row_pointers[y][x]; // GREEN
+          *(fbp + location + 2) = row_pointers[y][x]; // RED
+        }
+        *(fbp + location + 3) = 0;      // No transparency
+      }
+    }
+    munmap(fbp, screensize);
+    close(fbfd);
+    fclose(fp);
+    return 0;
+}