about summary refs log tree commit diff
path: root/generator
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-02-26 21:27:52 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-02-26 21:27:52 +0000
commitdd39ccc70e096fc415eeb665e1c3d2fb578c7945 (patch)
treeebc014357434baf9a60c76e005466367b0dd80ba /generator
parent3c788c26cf354252f806885bcf8ca2fbd4b1d20b (diff)
downloadnetpbm-mirror-dd39ccc70e096fc415eeb665e1c3d2fb578c7945.tar.gz
netpbm-mirror-dd39ccc70e096fc415eeb665e1c3d2fb578c7945.tar.xz
netpbm-mirror-dd39ccc70e096fc415eeb665e1c3d2fb578c7945.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1133 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'generator')
-rw-r--r--generator/pbmpage.c207
1 files changed, 118 insertions, 89 deletions
diff --git a/generator/pbmpage.c b/generator/pbmpage.c
index 77732df6..68e20448 100644
--- a/generator/pbmpage.c
+++ b/generator/pbmpage.c
@@ -17,6 +17,7 @@
 #include <math.h>
 #include <stdio.h>
 
+#include "pm_c_util.h"
 #include "pbm.h"
 
 /* US is 8.5 in by 11 in */
@@ -31,8 +32,8 @@
 
 
 struct bitmap {
-    int Width;      /* width and height in 600ths of an inch */
-    int Height;
+    unsigned int Width;      /* width and height in 600ths of an inch */
+    unsigned int Height;
     bit ** bitmap;
 };
 
@@ -41,9 +42,9 @@ static struct bitmap bitmap;
 
 
 static void
-setpixel(int const x,
-         int const y,
-         int const c) {
+setpixel(unsigned int const x,
+         unsigned int const y,
+         unsigned int const c) {
 
     char const bitmask = 128 >> (x % 8);
 
@@ -61,122 +62,140 @@ setpixel(int const x,
 
 
 static void 
-setplus(int x,int y,int s)
+setplus(unsigned int const x,
+        unsigned int const y,
+        unsigned int const s) {
 /*----------------------------------------------------------------------------
    Draw a black plus sign centered at (x,y) with arms 's' pixels long.  
    Leave the exact center of the plus white.
 -----------------------------------------------------------------------------*/
-{
-  int i;
-
-  for(i=0; i<s; i++)
-  {
-    setpixel(x+i,y,1);
-    setpixel(x-i,y,1);
-    setpixel(x,y+i,1);
-    setpixel(x,y-i,1);
-  }
+    unsigned int i;
+
+    for (i = 0; i < s; ++i) {
+        setpixel(x+i, y,   1);
+        setpixel(x-i, y,   1);
+        setpixel(x,   y+i, 1);
+        setpixel(x,   y-i, 1);
+    }
 }
 
 
 
 static void 
-setblock(int x,int y,int s)
-{
-  int i,j;
+setblock(unsigned int const x,
+         unsigned int const y,
+         unsigned int const s) {
+
+    unsigned int i;
 
-  for(i=0; i<s; i++)
-    for(j=0; j<s; j++)
-      setpixel(x+i,y+j,1);
+    for (i = 0; i < s; ++i) {
+        unsigned int j;
+
+        for (j = 0; j < s; ++j)
+            setpixel(x+i, y+j, 1);
+    }
 }
 
 
 
 static void 
-setchar(int x,int y,char c)
-{
-  int xo,yo;
-  static char charmap[10][5]= { { 0x3e, 0x41, 0x41, 0x41, 0x3e },
-				{ 0x00, 0x42, 0x7f, 0x40, 0x00 },
-				{ 0x42, 0x61, 0x51, 0x49, 0x46 },
-				{ 0x22, 0x41, 0x49, 0x49, 0x36 },
-				{ 0x18, 0x14, 0x12, 0x7f, 0x10 },
-				{ 0x27, 0x45, 0x45, 0x45, 0x39 },
-				{ 0x3e, 0x49, 0x49, 0x49, 0x32 },
-				{ 0x01, 0x01, 0x61, 0x19, 0x07 },
-				{ 0x36, 0x49, 0x49, 0x49, 0x36 },
-				{ 0x26, 0x49, 0x49, 0x49, 0x3e } };
-
-  if(c<='9' && c>='0')
-    for(xo=0; xo<5; xo++)
-      for(yo=0; yo<8; yo++)
-	if((charmap[c-'0'][xo]>>yo)&1)
-	  setblock(x+xo*3,y+yo*3,3);
+setchar(unsigned int const x,
+        unsigned int const y,
+        char         const c) {
+
+    static char const charmap[10][5]= { { 0x3e, 0x41, 0x41, 0x41, 0x3e },
+                                        { 0x00, 0x42, 0x7f, 0x40, 0x00 },
+                                        { 0x42, 0x61, 0x51, 0x49, 0x46 },
+                                        { 0x22, 0x41, 0x49, 0x49, 0x36 },
+                                        { 0x18, 0x14, 0x12, 0x7f, 0x10 },
+                                        { 0x27, 0x45, 0x45, 0x45, 0x39 },
+                                        { 0x3e, 0x49, 0x49, 0x49, 0x32 },
+                                        { 0x01, 0x01, 0x61, 0x19, 0x07 },
+                                        { 0x36, 0x49, 0x49, 0x49, 0x36 },
+                                        { 0x26, 0x49, 0x49, 0x49, 0x3e } };
+    
+    if (c <= '9' && c >= '0') {
+        unsigned int xo;
+
+        for (xo = 0; xo < 5; ++xo) {
+            unsigned int yo;
+
+            for (yo = 0; yo < 8; ++yo) {
+                if ((charmap[c-'0'][xo] >> yo) & 0x01)
+                    setblock(x + xo*3, y + yo*3, 3);
+            }
+        }
+    }
 }
 
 
 
 static void 
-setstring(int x,int y,char* s)
-{
-  char* p;
-  int xo;
+setstring(unsigned int const x,
+          unsigned int const y,
+          const char * const s) {
+
+    const char * p;
+    unsigned int xo;
 
-  for(xo=0, p=s; *p; xo+=21, p++)
-    setchar(x+xo,y,*p);
+    for (xo = 0, p = s; *p; xo += 21, ++p)
+        setchar(x + xo, y, *p);
 }
 
 
 
 static void 
-setCG(int x,int y)
-{
-  int xo,yo,zo;
-
-  for(xo=0; xo<=50; xo++)
-  {
-    yo=sqrt(50.0*50.0-xo*xo);
-    setpixel(x+xo,y+yo,1);
-    setpixel(x+yo,y+xo,1);
-    setpixel(x-1-xo,y-1-yo,1);
-    setpixel(x-1-yo,y-1-xo,1);
-    setpixel(x+xo,y-1-yo,1);
-    setpixel(x-1-xo,y+yo,1);
-    for(zo=0; zo<yo; zo++)
-    {
-      setpixel(x+xo,y-1-zo,1);
-      setpixel(x-1-xo,y+zo,1);
+setCG(unsigned int const x,
+      unsigned int const y) {
+
+    unsigned int xo;
+
+    for (xo = 0; xo <= 50; ++xo)   {
+        unsigned int const yo = sqrt(SQR(50.0) - SQR(xo));
+
+        unsigned int zo;
+
+        setpixel(x + xo, y + yo, 1);
+        setpixel(x+yo,   y + xo, 1);
+        setpixel(x-1-xo, y-1-yo, 1);
+        setpixel(x-1-yo, y-1-xo, 1);
+        setpixel(x+xo,   y-1-yo, 1);
+        setpixel(x-1-xo, y+yo,   1);
+
+        for(zo = 0; zo < yo; ++zo) {
+            setpixel(x + xo, y-1-zo, 1);
+            setpixel(x-1-xo, y+zo,   1);
+        }
     }
-  }
 }
 
 
 
 static void
-outputPbm(FILE *        const file,
+outputPbm(FILE *        const ofP,
           struct bitmap const bitmap) {
 /*----------------------------------------------------------------------------
   Create a pbm file containing the image from the global variable bitmap[].
 -----------------------------------------------------------------------------*/
     int const forceplain = 0;
-    int row;
+
+    unsigned int row;
     
-    pbm_writepbminit(file, bitmap.Width, bitmap.Height, forceplain);
+    pbm_writepbminit(ofP, bitmap.Width, bitmap.Height, forceplain);
     
-    for (row = 0; row < bitmap.Height; row++ ) {
-      pbm_writepbmrow_packed(file, bitmap.bitmap[row],
-                             bitmap.Width, forceplain); 
+    for (row = 0; row < bitmap.Height; ++row) {
+        pbm_writepbmrow_packed(ofP, bitmap.bitmap[row],
+                               bitmap.Width, forceplain); 
     }
-
-    pm_close(file);
 }
 
 
+
 static void
 framePerimeter(unsigned int const Width, 
                unsigned int const Height) {
 
-    unsigned int x,y;
+    unsigned int x, y;
 
     /* Top edge */
     for (x = 0; x < Width; ++x)
@@ -198,58 +217,66 @@ framePerimeter(unsigned int const Width,
 
 
 int 
-main(int argc,char** argv) {
+main(int argc, const char** argv) {
 
-    int TP=1;
-    int x,y;
+    int TP;
+    unsigned int x, y;
     char buf[128];
-    int Width;      /* width and height in 600ths of an inch */
-    int Height;
+    /* width and height in 600ths of an inch */
+    unsigned int Width;
+    unsigned int Height;
 
-    pbm_init(&argc, argv);
+    pm_proginit(&argc, argv);
 
     if (argc > 1 && strcmp(argv[1], "-a4") == 0) {
-        Width = A4WIDTH;
+        Width  = A4WIDTH;
         Height = A4HEIGHT;
-        argc--;
-        argv++;
+        --argc;
+        ++argv;
     } else {
-        Width = USWIDTH;
+        Width  = USWIDTH;
         Height = USHEIGHT;
     }
 
-    bitmap.Width = Width;
+    bitmap.Width  = Width;
     bitmap.Height = Height;
     bitmap.bitmap = pbm_allocarray_packed(Width, bitmap.Height);
 
     for (y = 0; y < bitmap.Height; ++y) {
+        unsigned int x;
         for (x = 0; x < pbm_packed_bytes(bitmap.Width); ++x) 
             bitmap.bitmap[y][x] = 0x00; 
     }
 
-    if (argc>1)
+    if (argc > 1)
         TP = atoi(argv[1]);
+    else
+        TP = 1;
 
     switch (TP) {
     case 1:
         framePerimeter(Width, Height);
-        for (x = 0; x < Width; x += 100)
+        for (x = 0; x < Width; x += 100) {
+            unsigned int y;
             for(y = 0; y < Height; y += 100)
                 setplus(x, y, 4);
+        }
         for(x = 0; x < Width; x += 100) {
             sprintf(buf,"%d", x);
             setstring(x + 3, (Height/200) * 100 + 3, buf);
         }
-        for (y=0; y < Height; y += 100) {
+        for (y = 0; y < Height; y += 100) {
             sprintf(buf, "%d", y);
             setstring((Width/200) * 100 + 3, y + 3, buf);
         }
         for (x = 0; x < Width; x += 10)
             for (y = 0; y < Height; y += 100)
                 setplus(x, y, ((x%100) == 50) ? 2 : 1);
-        for (x=0; x < Width; x += 100)
+        for (x = 0; x < Width; x += 100) {
+            unsigned int y;
             for (y = 0; y < Height; y += 10)
                 setplus(x, y, ((y%100) == 50) ? 2 : 1);
+        }
         setCG(Width/2, Height/2);
         break;
     case 2:
@@ -270,5 +297,7 @@ main(int argc,char** argv) {
 
     pbm_freearray(bitmap.bitmap, Height);
 
+    pm_close(stdout);
+
     return 0;
 }