]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2001-03-01 15:11:30 by ltoetsch]
authorltoetsch <ltoetsch@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Thu, 1 Mar 2001 15:11:30 +0000 (15:11 +0000)
committerltoetsch <ltoetsch@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Thu, 1 Mar 2001 15:11:30 +0000 (15:11 +0000)
added PNG,Webinterface

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@91 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

README.Webinterface [new file with mode: 0644]
Raster.c
nph-png [new file with mode: 0755]
png.html [new file with mode: 0644]

diff --git a/README.Webinterface b/README.Webinterface
new file mode 100644 (file)
index 0000000..0f87dff
--- /dev/null
@@ -0,0 +1,29 @@
+
+Prerequisits:
+
+- libgd (I used 1.81 for testing), which needs libpng and libz.
+    Get it from http://www.boutell.com/gd/
+- apache, perl, netscape (I don't know, if other browsers can display
+    server pushed images)
+
+The PNG driver in Raster is able to generate PNG-Images.
+
+To display this png file continuously in a web page, follow these instructions:
+Copy the sample png.html to an appropriate place under your htdocs.
+Copy the sample nph-png perl script into your cgi-bin directory, and adjust
+png.html to contain this directory.
+Adjust nph-png to contain the path/filename of the outputfile (s. -o option
+in README.Raster or 'lcd4linux -h').
+Start 'lcd4linux -o /path/filename.png'.
+
+If you are on a slow connection to your webserver you might also adjust the
+$DELAY in nph-png or the tick/tack in lcd4linux.conf.
+
+Note: depending on your webservers configuration, you must rename nph-png to
+   nph-png.pl or npg-png.cgi.
+
+
+Please send correction, additions, questions & donations to
+Leopold Toetsch <lt@toetsch.at>
+
+Have fun.
index 1e6d4d6e2a11fe9c7e7d2e066e4553b4910eb55c..eeb9aeab3d296171d567a2d1fcf0432e496d1f90 100644 (file)
--- a/Raster.c
+++ b/Raster.c
@@ -1,4 +1,4 @@
-/* $Id: Raster.c,v 1.12 2001/03/01 11:08:16 reinelt Exp $
+/* $Id: Raster.c,v 1.13 2001/03/01 15:11:30 ltoetsch Exp $
  *
  * driver for raster formats
  *
@@ -20,6 +20,9 @@
  *
  *
  * $Log: Raster.c,v $
+ * Revision 1.13  2001/03/01 15:11:30  ltoetsch
+ * added PNG,Webinterface
+ *
  * Revision 1.12  2001/03/01 11:08:16  reinelt
  *
  * reworked configure to allow selection of drivers
@@ -94,7 +97,9 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-
+#ifdef WITH_PNG
+#include <gd.h>
+#endif
 
 #include "debug.h"
 #include "cfg.h"
@@ -203,12 +208,77 @@ int Raster_flush (void)
     return -1;
   }
   if (rename (tmp, path)<0) {
-    error ("Raster: close(%s) failed: %s", tmp, strerror(errno));
+    error ("Raster: rename(%s) failed: %s", tmp, strerror(errno));
+    return -1;
+  }
+  
+  return 0;
+}
+
+
+#ifdef WITH_PNG
+int Png_flush (void)
+{
+  static int seq=0;
+  int xsize, ysize, row, col;
+  char path[256], tmp[256];
+  FILE *fp;
+  gdImagePtr im;
+  int bg, hg, fg;
+  
+  xsize=2*border+(Lcd.cols-1)*cgap+Lcd.cols*Lcd.xres*pixel+(Lcd.cols*Lcd.xres-1)*pgap;
+  ysize=2*border+(Lcd.rows-1)*rgap+Lcd.rows*Lcd.yres*pixel+(Lcd.rows*Lcd.yres-1)*pgap;
+
+  im = gdImageCreate(xsize, ysize);
+  /* first color = background */
+  bg = gdImageColorAllocate(im, 
+                           0xff&background>>16,
+                           0xff&background>>8,
+                            0xff&background);
+  hg = gdImageColorAllocate(im, 
+                           0xff&halfground>>16,
+                           0xff&halfground>>8,
+                            0xff&halfground);
+  
+  fg = gdImageColorAllocate(im, 
+                           0xff&foreground>>16,
+                           0xff&foreground>>8,
+                            0xff&foreground);
+  
+  
+  for (row=0; row<Lcd.rows*Lcd.yres; row++) {
+    int y=border+(row/Lcd.yres)*rgap+row*(pixel+pgap);
+    for (col=0; col<Lcd.cols*Lcd.xres; col++) {
+      int x=border+(col/Lcd.xres)*cgap+col*(pixel+pgap);
+      gdImageFilledRectangle(im, x, y, x + pixel - 1 , y + pixel - 1,
+                            LCDpixmap[row*Lcd.cols*Lcd.xres+col]? fg : hg);
+    }
+  }
+  
+  snprintf (path, sizeof(path), output, seq++);
+  snprintf (tmp, sizeof(tmp), "%s.tmp", path);
+  
+  if ((fp=fopen(tmp, "w")) == NULL) {
+    error("Png: fopen(%s) failed: %s\n", tmp, strerror(errno));
+    return -1;
+  }
+  gdImagePng(im, fp);
+  gdImageDestroy(im);
+  
+  
+  if (fclose (fp) != 0) {
+    error("Png: fclose(%s) failed: %s\n", tmp, strerror(errno));
+    return -1;
+  }
+  if (rename (tmp, path)<0) {
+    error("Png: rename(%s) failed: %s\n", tmp, strerror(errno));
     return -1;
   }
   
   return 0;
 }
+#endif
+
 
 int Raster_clear (void)
 {
@@ -297,7 +367,7 @@ LCD Raster[] = {
   { "PPM",0,0,0,0,BARS,0,Raster_init,Raster_clear,Raster_put,Raster_bar,NULL,Raster_flush },
 #endif
 #ifdef WITH_PNG
-  { "PNG",0,0,0,0,BARS,0,Raster_init,Raster_clear,Raster_put,Raster_bar,NULL,Raster_flush },
+  { "PNG",0,0,0,0,BARS,0,Raster_init,Raster_clear,Raster_put,Raster_bar,NULL,Png_flush },
 #endif
   { NULL }
 };
diff --git a/nph-png b/nph-png
new file mode 100755 (executable)
index 0000000..0240b64
--- /dev/null
+++ b/nph-png
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+
+use strict;
+use vars qw ($file $DELAY);
+########## CONFIG
+  $file = "lcd4linux"; # .png is appended
+  $DELAY = 0;          # delay in seconds
+                       # if delay is zero, file is sent when modified.
+#################
+
+use CGI qw/:push -nph/;
+$| = 1;
+my ($mtime, $nmtime, $size, $nsize);
+(undef, undef, undef, undef, undef, undef, undef, $size, undef,
+   $mtime) = stat "$file.png";
+print multipart_init(-boundary=>'----------------here we go!');
+while (1) {
+  print multipart_start(-type=>'image/png');
+  undef $/;
+  open(IN, "$file.png") or die("Can't read '$file.png'");
+  $_ = <IN>;
+  print $_;
+  close(IN);
+  print multipart_end;
+  if ($DELAY) {
+    sleep $DELAY;
+  }  
+  else {
+    W: while (1) {
+  #    sleep(1);
+      (undef, undef, undef, undef, undef, undef, undef, $nsize, undef,
+         $nmtime) = stat "$file.png";
+      if($mtime != $nmtime || $size != $nsize) {        
+        $mtime = $nmtime;
+       $size = $nsize;
+       last W;
+      }        
+    }   
+  }    
+}
+
diff --git a/png.html b/png.html
new file mode 100644 (file)
index 0000000..5cb914b
--- /dev/null
+++ b/png.html
@@ -0,0 +1,8 @@
+<html><head>
+<title>PNG Test</title>
+</head>
+<body>
+<h1>PNG test</h1>
+<img src=/cgi-bin/nph-png>
+</body>
+</html>