]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2000-03-24 11:36:56 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Fri, 24 Mar 2000 11:36:56 +0000 (11:36 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Fri, 24 Mar 2000 11:36:56 +0000 (11:36 +0000)
new syntax for raster configuration
changed XRES and YRES to be configurable
PPM driver works nice

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

Raster.c
XWindow.c
fontmap.c
lcd4linux.c
lcd4linux.conf.sample
parser.c
pixmap.c
pixmap.h

index a7cac00be92738bc4ff8cbb83c1637cdfd4df582..34c4cd9073a83c12196eb7265091abb869f444f8 100644 (file)
--- a/Raster.c
+++ b/Raster.c
@@ -1,4 +1,4 @@
-/* $Id: Raster.c,v 1.1 2000/03/23 07:24:48 reinelt Exp $
+/* $Id: Raster.c,v 1.2 2000/03/24 11:36:56 reinelt Exp $
  *
  * driver for raster formats
  *
  *
  *
  * $Log: Raster.c,v $
+ * Revision 1.2  2000/03/24 11:36:56  reinelt
+ *
+ * new syntax for raster configuration
+ * changed XRES and YRES to be configurable
+ * PPM driver works nice
+ *
  * Revision 1.1  2000/03/23 07:24:48  reinelt
  *
  * PPM driver up and running (but slow!)
@@ -36,6 +42,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 
 #include "cfg.h"
 #include "display.h"
 
 static DISPLAY Display;
 
-static int pixelsize=-1;
-static int pixelgap=0;
-static int rowgap=0;
-static int colgap=0;
+static int pixel=-1;
+static int pgap=0;
+static int rgap=0;
+static int cgap=0;
 static int border=0;
 
 static int foreground=0;
 static int halfground=0;
 static int background=0;
 
-#define R(color) (0xff&((color)>>16))
-#define G(color) (0xff&((color)>>8))
-#define B(color) (0xff&((color)))
-
 int Raster_flush (void)
 {
-  int xsize, ysize;
-  int x, y, pos;
+  int xsize, ysize, row, col;
+  unsigned char *buffer;
+  unsigned char R[3], G[3], B[3];
   
-  xsize=2*border+Display.cols*Display.xres*(pixelsize+pixelgap);
-  ysize=2*border+Display.rows*Display.yres*(pixelsize+pixelgap);
+  xsize=2*border+(Display.cols-1)*cgap+Display.cols*Display.xres*(pixel+pgap);
+  ysize=2*border+(Display.rows-1)*rgap+Display.rows*Display.yres*(pixel+pgap);
   
-  printf ("P3\n");
-  printf ("%d %d\n", xsize, ysize);
-  printf ("255\n");
+  if ((buffer=malloc(xsize*ysize*sizeof(*buffer)))==NULL)
+    return -1;
 
-  pos=0;
+  memset (buffer, 0, xsize*ysize*sizeof(*buffer));
   
-  for (y=0; y<ysize; y++) {
-    for (x=0; x<xsize; x++) {
-      if (x<border || x>=xsize-border || 
-         y<border || y>=ysize-border ||
-         (y-border)%(pixelsize+pixelgap)>=pixelsize ||
-         (x-border)%(pixelsize+pixelgap)>=pixelsize) {
-       pos+=printf ("%d %d %d ", R(background), G(background), B(background));
-      } else {
-       if (Pixmap[((y-border)/(pixelsize+pixelgap))*Display.cols*Display.xres+(x-border)/(pixelsize+pixelgap)])
-         pos+=printf ("%d %d %d ", R(foreground), G(foreground), B(foreground));
-       else
-         pos+=printf ("%d %d %d ", R(halfground), G(halfground), B(halfground));
-      }
-      if (pos>80) {
-       pos=0;
-       printf ("\n");
-      }
+  for (row=0; row<Display.rows*Display.yres; row++) {
+    int y=border+(row/Display.yres)*rgap+row*(pixel+pgap);
+    for (col=0; col<Display.cols*Display.xres; col++) {
+      int x=border+(col/Display.xres)*cgap+col*(pixel+pgap);
+      int a, b;
+      for (a=0; a<pixel; a++)
+       for (b=0; b<pixel; b++)
+         buffer[y*xsize+x+a*xsize+b]=Pixmap[row*Display.cols*Display.xres+col]+1;
     }
   }
+  
+  printf ("P6\n%d %d\n255\n", xsize, ysize);
+  
+  R[0]=0xff&background>>16;
+  G[0]=0xff&background>>8;
+  B[0]=0xff&background;
+
+  R[1]=0xff&halfground>>16;
+  G[1]=0xff&halfground>>8;
+  B[1]=0xff&halfground;
+
+  R[2]=0xff&foreground>>16;
+  G[2]=0xff&foreground>>8;
+  B[2]=0xff&foreground;
+
+  for (row=0; row<ysize; row++) {
+    for (col=0; col<xsize; col++) {
+      int i=buffer[row*xsize+col];
+      printf("%c%c%c", R[i], G[i], B[i]);
+    }
+  }
+
   return 0;
 }
 
@@ -105,39 +121,45 @@ int Raster_clear (void)
 
 int Raster_init (DISPLAY *Self)
 {
-  int rows=-1;
-  int cols=-1;
+  char *s;
+  int rows=-1, cols=-1;
+  int xres=1, yres=-1;
+  
+  if (sscanf(s=cfg_get("size")?:"20x4", "%dx%d", &cols, &rows)!=2 || rows<1 || cols<1) {
+    fprintf (stderr, "Raster: bad size '%s'\n", s);
+    return -1;
+  }
+
+  if (sscanf(s=cfg_get("font")?:"5x8", "%dx%d", &xres, &yres)!=2 || xres<5 || yres<7) {
+    fprintf (stderr, "Raster: bad font '%s'\n", s);
+    return -1;
+  }
 
-  rows=atoi(cfg_get("rows")?:"4");
-  cols=atoi(cfg_get("columns")?:"20");
+  if (sscanf(s=cfg_get("pixel")?:"4+1", "%d+%d", &pixel, &pgap)!=2 || pixel<1 || pgap<0) {
+    fprintf (stderr, "Raster: bad pixel '%s'\n", s);
+    return -1;
+  }
+
+  if (sscanf(s=cfg_get("gap")?:"3x3", "%dx%d", &rgap, &cgap)!=2 || rgap<0 || cgap<0) {
+    fprintf (stderr, "Raster: bad gap '%s'\n", s);
+    return -1;
+  }
 
-  pixelsize=atoi(cfg_get("pixelsize")?:"1");
-  pixelgap=atoi(cfg_get("pixelgap")?:"0");
-  rowgap=atoi(cfg_get("rowgap")?:"0");
-  colgap=atoi(cfg_get("colgap")?:"0");
   border=atoi(cfg_get("border")?:"0");
 
   foreground=strtol(cfg_get("foreground")?:"000000", NULL, 16);
   halfground=strtol(cfg_get("halfground")?:"ffffff", NULL, 16);
   background=strtol(cfg_get("background")?:"ffffff", NULL, 16);
 
-  if (rows<1 || cols<1) {
-    fprintf (stderr, "Raster: incorrect number of rows or columns\n");
-    return -1;
-  }
-  
-  if (pixelsize<1) {
-    fprintf (stderr, "Raster: incorrect pixel size\n");
-    return -1;
-  }
-
-  if (pix_init (rows, cols)!=0) {
-    fprintf (stderr, "Raster: pix_init(%d, %d) failed\n", rows, cols);
+  if (pix_init (rows, cols, xres, yres)!=0) {
+    fprintf (stderr, "Raster: pix_init(%d, %d, %d, %d) failed\n", rows, cols, xres, yres);
     return -1;
   }
 
   Self->rows=rows;
   Self->cols=cols;
+  Self->xres=xres;
+  Self->yres=yres;
   Display=*Self;
 
   pix_clear();
@@ -156,6 +178,6 @@ int Raster_bar (int type, int row, int col, int max, int len1, int len2)
 
 
 DISPLAY Raster[] = {
-  { "PPM", 0, 0, XRES, YRES, BARS, Raster_init, Raster_clear, Raster_put, Raster_bar, Raster_flush },
+  { "PPM", 0, 0, 0, 0, BARS, Raster_init, Raster_clear, Raster_put, Raster_bar, Raster_flush },
   { "" }
 };
index e332f0bec7d35546891dd2af06681ba4ac637d45..d3bbc220b5276e05057b2236312aeef1fc6738e7 100644 (file)
--- a/XWindow.c
+++ b/XWindow.c
@@ -1,4 +1,4 @@
-/* $Id: XWindow.c,v 1.2 2000/03/23 07:24:48 reinelt Exp $
+/* $Id: XWindow.c,v 1.3 2000/03/24 11:36:56 reinelt Exp $
  *
  * driver for X11
  *
  *
  *
  * $Log: XWindow.c,v $
+ * Revision 1.3  2000/03/24 11:36:56  reinelt
+ *
+ * new syntax for raster configuration
+ * changed XRES and YRES to be configurable
+ * PPM driver works nice
+ *
  * Revision 1.2  2000/03/23 07:24:48  reinelt
  *
  * PPM driver up and running (but slow!)
@@ -42,6 +48,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
 
 #include "cfg.h"
 #include "display.h"
 
 #define BARS ( BAR_L | BAR_R | BAR_U | BAR_D | BAR_H2 | BAR_V2 )
 
+static int pixel=-1;
+static int pgap=0;
+static int rgap=0;
+static int cgap=0;
+static int border=0;
+
+static int foreground=0;
+static int halfground=0;
+static int background=0;
+
 static DISPLAY Display;
 
 int X_flush (void)
 {
-  int r, c;
+  int xsize, ysize, row, col;
+  unsigned char *buffer;
+  unsigned char R[3], G[3], B[3];
+  
+  xsize=2*border+(Display.cols-1)*cgap+Display.cols*Display.xres*(pixel+pgap);
+  ysize=2*border+(Display.rows-1)*rgap+Display.rows*Display.yres*(pixel+pgap);
+  
+  if ((buffer=malloc(xsize*ysize*sizeof(*buffer)))==NULL)
+    return -1;
 
-  for (r=0; r<Display.rows*Display.yres; r++) {
-    for (c=0; c<Display.cols*Display.xres; c++) {
-      printf ("%c", Pixmap[r*Display.cols*Display.xres+c] ? '#':'.');
+  memset (buffer, 0, xsize*ysize*sizeof(*buffer));
+  
+  for (row=0; row<Display.rows*Display.yres; row++) {
+    int y=border+(row/Display.yres)*rgap+row*(pixel+pgap);
+    for (col=0; col<Display.cols*Display.xres; col++) {
+      int x=border+(col/Display.xres)*cgap+col*(pixel+pgap);
+      int a, b;
+      for (a=0; a<pixel; a++)
+       for (b=0; b<pixel; b++)
+         buffer[y*xsize+x+a*xsize+b]=Pixmap[row*Display.cols*Display.xres+col]+1;
     }
-    printf ("\n");
   }
-  printf ("\n");
+  
+  R[0]=0xff&background>>16;
+  G[0]=0xff&background>>8;
+  B[0]=0xff&background;
+
+  R[1]=0xff&halfground>>16;
+  G[1]=0xff&halfground>>8;
+  B[1]=0xff&halfground;
+
+  R[2]=0xff&foreground>>16;
+  G[2]=0xff&foreground>>8;
+  B[2]=0xff&foreground;
+
+  for (row=0; row<ysize; row++) {
+    for (col=0; col<xsize; col++) {
+      int i=buffer[row*xsize+col];
+      printf("%d.%d.%d ", R[i], G[i], B[i]);
+    }
+  }
+
   return 0;
 }
 
@@ -78,24 +128,45 @@ int X_clear (void)
 
 int X_init (DISPLAY *Self)
 {
-  int rows=-1;
-  int cols=-1;
+  char *s;
+  int rows=-1, cols=-1;
+  int xres=1, yres=-1;
+  
+  if (sscanf(s=cfg_get("size")?:"20x4", "%dx%d", &cols, &rows)!=2 || rows<1 || cols<1) {
+    fprintf (stderr, "Raster: bad size '%s'\n", s);
+    return -1;
+  }
+
+  if (sscanf(s=cfg_get("font")?:"5x8", "%dx%d", &xres, &yres)!=2 || xres<5 || yres<7) {
+    fprintf (stderr, "Raster: bad font '%s'\n", s);
+    return -1;
+  }
 
-  rows=atoi(cfg_get("rows")?:"4");
-  cols=atoi(cfg_get("columns")?:"20");
+  if (sscanf(s=cfg_get("pixel")?:"4+1", "%d+%d", &pixel, &pgap)!=2 || pixel<1 || pgap<0) {
+    fprintf (stderr, "Raster: bad pixel '%s'\n", s);
+    return -1;
+  }
 
-  if (rows<1 || cols<1) {
-    fprintf (stderr, "X11: incorrect number of rows or columns\n");
+  if (sscanf(s=cfg_get("gap")?:"3x3", "%dx%d", &rgap, &cgap)!=2 || rgap<0 || cgap<0) {
+    fprintf (stderr, "Raster: bad gap '%s'\n", s);
     return -1;
   }
 
-  if (pix_init (rows, cols)!=0) {
-    fprintf (stderr, "X11: pix_init(%d, %d) failed\n", rows, cols);
+  border=atoi(cfg_get("border")?:"0");
+
+  foreground=strtol(cfg_get("foreground")?:"000000", NULL, 16);
+  halfground=strtol(cfg_get("halfground")?:"ffffff", NULL, 16);
+  background=strtol(cfg_get("background")?:"ffffff", NULL, 16);
+
+  if (pix_init (rows, cols, xres, yres)!=0) {
+    fprintf (stderr, "Raster: pix_init(%d, %d, %d, %d) failed\n", rows, cols, xres, yres);
     return -1;
   }
 
   Self->rows=rows;
   Self->cols=cols;
+  Self->xres=xres;
+  Self->yres=yres;
   Display=*Self;
 
   pix_clear();
@@ -114,6 +185,6 @@ int X_bar (int type, int row, int col, int max, int len1, int len2)
 
 
 DISPLAY XWindow[] = {
-  { "X11", 0, 0, XRES, YRES, BARS, X_init, X_clear, X_put, X_bar, X_flush },
+  { "X11", 0, 0, 0, 0, BARS, X_init, X_clear, X_put, X_bar, X_flush },
   { "" }
 };
index e8494ae6aebeb6d115a8300836ee3c649d40b377..3dc81e55b47221eb5d0e8f205ab8d85b4dc2d577 100644 (file)
--- a/fontmap.c
+++ b/fontmap.c
@@ -1,4 +1,4 @@
-/* $Id: fontmap.c,v 1.1 2000/03/22 15:36:21 reinelt Exp $
+/* $Id: fontmap.c,v 1.2 2000/03/24 11:36:56 reinelt Exp $
  *
  * 5x8 font
  *
  *
  *
  * $Log: fontmap.c,v $
+ * Revision 1.2  2000/03/24 11:36:56  reinelt
+ *
+ * new syntax for raster configuration
+ * changed XRES and YRES to be configurable
+ * PPM driver works nice
+ *
  * Revision 1.1  2000/03/22 15:36:21  reinelt
  *
  * added '-l' switch (list drivers)
@@ -649,12 +655,12 @@ unsigned char Fontmap[256][8]={
           b_O___O,
           b_O___O,
           b______ },
-  [0x69] { b______,
-          b___O__,
+  [0x69] { b___O__,
           b______,
           b__OO__,
           b___O__,
           b___O__,
+          b___O__,
           b__OOO_,
           b______ },
   [0x6a] { b____O_,
index 668e3b143ad5b425022d208668eb625068154009..c471843438b8867d25c743eaa84cfce7e1717b06 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: lcd4linux.c,v 1.10 2000/03/23 07:24:48 reinelt Exp $
+/* $Id: lcd4linux.c,v 1.11 2000/03/24 11:36:56 reinelt Exp $
  *
  * LCD4Linux
  *
  *
  *
  * $Log: lcd4linux.c,v $
+ * Revision 1.11  2000/03/24 11:36:56  reinelt
+ *
+ * new syntax for raster configuration
+ * changed XRES and YRES to be configurable
+ * PPM driver works nice
+ *
  * Revision 1.10  2000/03/23 07:24:48  reinelt
  *
  * PPM driver up and running (but slow!)
@@ -143,6 +149,7 @@ void main (int argc, char *argv[])
   lcd_put (2, 1, " (c) 2000 M.Reinelt");
   lcd_flush();
 
+  // FIXME: just debugging
   exit (0);
 
   sleep (3);
index cb68fba3129ae307e91b7cd76e036d24692ec1e7..3a2be423d20c55f3715e01ee4230607eed05ef3e 100644 (file)
@@ -4,21 +4,17 @@
 #Contrast 160
 
 #Display X11
-#rows 2
-#columns 20
 DISPLAY PPM
-rows 4
-columns 20
-pixelsize 5
-pixelgap 1
-rowgap 1
-colgap 1
+size 20x4
+font 5x8
+pixel 5+1
+gap 5x5
 border 20
 foreground 102000
 halfground 70c000
 background 80d000
 
+
 #Row1 "*** %o %v ***"
 #Row2 "%p CPU  %r MB RAM"
 #Row3 "Busy %cu%% $r10cs+cb"
index 4d9346dc9099c7f77f2cd7bf6435a9f96bb5df85..f9ff7e1b25cd9d833db6a3107b92788314e963e0 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1,4 +1,4 @@
-/* $Id: parser.c,v 1.4 2000/03/19 08:41:28 reinelt Exp $
+/* $Id: parser.c,v 1.5 2000/03/24 11:36:56 reinelt Exp $
  *
  * row definition parser
  *
  *
  *
  * $Log: parser.c,v $
+ * Revision 1.5  2000/03/24 11:36:56  reinelt
+ *
+ * new syntax for raster configuration
+ * changed XRES and YRES to be configurable
+ * PPM driver works nice
+ *
  * Revision 1.4  2000/03/19 08:41:28  reinelt
  *
  * documentation available! README, README.MatrixOrbital, README.Drivers
@@ -225,7 +231,7 @@ char *parse (char *string, int supported_bars, int usage[])
       break;
       
     default:
-      *p++=*s++;
+      if ((*p++=*s)!='\0') s++;
     }
     
   } while (*s);
index 48343cbe610becf6e12d2da83038d49545d0b601..24a65be530a17c4ef78010deea38b5d728078b70 100644 (file)
--- a/pixmap.c
+++ b/pixmap.c
@@ -1,4 +1,4 @@
-/* $Id: pixmap.c,v 1.2 2000/03/23 07:24:48 reinelt Exp $
+/* $Id: pixmap.c,v 1.3 2000/03/24 11:36:56 reinelt Exp $
  *
  * generic pixmap driver
  *
  *
  *
  * $Log: pixmap.c,v $
+ * Revision 1.3  2000/03/24 11:36:56  reinelt
+ *
+ * new syntax for raster configuration
+ * changed XRES and YRES to be configurable
+ * PPM driver works nice
+ *
  * Revision 1.2  2000/03/23 07:24:48  reinelt
  *
  * PPM driver up and running (but slow!)
@@ -38,8 +44,8 @@
  * int pix_clear(void);
  *   clears the pixmap
  *
- * int pix_init (int r, int c);
- *   allocates & clear pixmap wit r rows and c columns
+ * int pix_init (int rows, int cols, int XRES, int YRES);
+ *   allocates & clears pixmap
  *
  * int pix_put (int row, int col, char *text);
  *   draws text into the pixmap
 #include "pixmap.h"
 #include "fontmap.h"
 
-static int rows=0;
-static int cols=0;
+static int ROWS=0;
+static int COLS=0;
+static int XRES=0;
+static int YRES=0;
+
 unsigned char *Pixmap=NULL;
 
 int pix_clear(void)
 {
   int i;
 
-  for (i=0; i<rows*cols; i++) {
+  for (i=0; i<ROWS*COLS; i++) {
     Pixmap[i]=0;
   }
 
   return 0;
 }
 
-int pix_init (int r, int c)
+int pix_init (int rows, int cols, int xres, int yres)
 {
-  if (r<1 || c<1) 
+  if (rows<1 || cols<1 || xres<1 || yres<1) 
     return -1;
   
   if (Pixmap) 
     free (Pixmap);
 
-  rows=r*YRES;
-  cols=c*XRES;
+  XRES=xres;
+  YRES=yres;
+  ROWS=rows*yres;
+  COLS=cols*xres;
 
-  if ((Pixmap=malloc (rows*cols*sizeof(unsigned char)))==NULL)
+  if ((Pixmap=malloc (ROWS*COLS*sizeof(unsigned char)))==NULL)
     return -1;
     
   return pix_clear();
@@ -95,13 +106,13 @@ int pix_put (int row, int col, char *text)
   row*=YRES;
   col*=XRES;
   
-  while (*text && col<cols) {
+  while (*text && col<COLS) {
     c=*text;
     for (y=0; y<YRES; y++) {
       mask=1<<XRES;
       for (x=0; x<XRES; x++) {
        mask>>=1;
-       Pixmap[(row+y)*cols+col+x]=Fontmap[c][y]&mask?1:0;
+       Pixmap[(row+y)*COLS+col+x]=Fontmap[c][y]&mask?1:0;
       }
     }
     col+=XRES;
@@ -118,11 +129,11 @@ int pix_bar (int type, int row, int col, int max, int len1, int len2)
   col*=XRES;
 
   if (type & BAR_H) {
-    if (max>cols-col)
-      max=cols-col;
+    if (max>COLS-col)
+      max=COLS-col;
   } else {
-    if (max>rows-row)
-      max=rows-row;
+    if (max>ROWS-row)
+      max=ROWS-row;
   }
   
   if (len1<1) len1=1;
@@ -143,7 +154,7 @@ int pix_bar (int type, int row, int col, int max, int len1, int len2)
     for (y=0; y<YRES; y++) {
       len=y<YRES/2?len1:len2;
       for (x=0; x<max; x++) {
-       Pixmap[(row+y)*cols+col+x]=x<len?!rev:rev;
+       Pixmap[(row+y)*COLS+col+x]=x<len?!rev:rev;
       }
     }
     break;
@@ -157,7 +168,7 @@ int pix_bar (int type, int row, int col, int max, int len1, int len2)
     for (y=0; y<max; y++) {
       for (x=0; x<XRES; x++) {
        len=x<XRES/2?len1:len2;
-       Pixmap[(row+y)*cols+col+x]=y<len?!rev:rev;
+       Pixmap[(row+y)*COLS+col+x]=y<len?!rev:rev;
       }
     }
     break;
index d5c818d0d8d52bebd629d7a46699edc799ce7f6e..5dcc812441b79ccc4dc26b11f2e23daa6a31827b 100644 (file)
--- a/pixmap.h
+++ b/pixmap.h
@@ -1,4 +1,4 @@
-/* $Id: pixmap.h,v 1.1 2000/03/22 15:36:21 reinelt Exp $
+/* $Id: pixmap.h,v 1.2 2000/03/24 11:36:56 reinelt Exp $
  *
  * generic pixmap driver
  *
  *
  *
  * $Log: pixmap.h,v $
+ * Revision 1.2  2000/03/24 11:36:56  reinelt
+ *
+ * new syntax for raster configuration
+ * changed XRES and YRES to be configurable
+ * PPM driver works nice
+ *
  * Revision 1.1  2000/03/22 15:36:21  reinelt
  *
  * added '-l' switch (list drivers)
 #ifndef _PIXMAP_H_
 #define _PIXMAP_H_
 
-#define XRES 6
-#define YRES 8
-
 extern unsigned char *Pixmap;
 
 int pix_clear(void);
-int pix_init (int r, int c);
+int pix_init (int rows, int cols, int xres, int yres);
 int pix_put (int row, int col, char *text);
 int pix_bar (int type, int row, int col, int max, int len1, int len2);