about summary refs log tree commit diff
path: root/lib/libppmd.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2009-06-26 02:42:31 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2009-06-26 02:42:31 +0000
commit2bc36257c93fabb40070170b6f93efaa7389853c (patch)
tree403a0737da3b9d5ef99cd80c2f7aec4fe32996c0 /lib/libppmd.c
parentd5dc5396c5f2700810a591a8359c5415923b308a (diff)
downloadnetpbm-mirror-2bc36257c93fabb40070170b6f93efaa7389853c.tar.gz
netpbm-mirror-2bc36257c93fabb40070170b6f93efaa7389853c.tar.xz
netpbm-mirror-2bc36257c93fabb40070170b6f93efaa7389853c.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@937 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/libppmd.c')
-rw-r--r--lib/libppmd.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/lib/libppmd.c b/lib/libppmd.c
index 89504c46..3b4c9e7c 100644
--- a/lib/libppmd.c
+++ b/lib/libppmd.c
@@ -1336,7 +1336,26 @@ static long icos(int deg)
     return isin(deg + 90);
 }  
 
-#define SCHAR(x) (u = (x), (((u) & 0x80) ? ((u) | (-1 ^ 0xFF)) : (u)))
+static int
+twosCompByteValue(unsigned char const c) {
+/*----------------------------------------------------------------------------
+   E.g. if 'c' is 0x5, return 5.  If 'c' is 0xF0, return -16.
+-----------------------------------------------------------------------------*/
+    return (char)c;
+}
+
+static int
+glyphSkipBefore(const struct ppmd_glyph * const glyphP) {
+
+    return twosCompByteValue(glyphP->header.skipBefore);
+}
+
+static ppmd_point
+commandPoint(const struct ppmd_glyphCommand * const commandP) {
+
+    return makePoint(twosCompByteValue(commandP->x),
+                     twosCompByteValue(commandP->y));
+}
 
 #define Scalef 21       /* Font design size */
 #define Descend 9       /* Descender offset */
@@ -1365,10 +1384,8 @@ drawGlyph(const struct ppmd_glyph * const glyphP,
     ppmd_point const glyphCorner = *glyphCornerP;
     ppmd_point p;
     unsigned int commandNum;
-    int u;  /* Used by the SCHAR macro */
 
-    p = makePoint(glyphCorner.x - SCHAR(glyphP->header.skipBefore),
-                  glyphCorner.y);
+    p = makePoint(glyphCorner.x - glyphSkipBefore(glyphP), glyphCorner.y);
         /* initial value */
 
     for (commandNum = 0;
@@ -1383,8 +1400,7 @@ drawGlyph(const struct ppmd_glyph * const glyphP,
             break;
         case CMD_DRAWLINE:
         {
-            ppmd_point const n = vectorSum(p, makePoint(SCHAR(commandP->x),
-                                                        SCHAR(commandP->y)));
+            ppmd_point const n = vectorSum(p, commandPoint(commandP));
             int const mx1 = (p.x * height) / Scalef;
             int const my1 = ((p.y - Descend) * height) / Scalef;
             int const mx2 = (n.x * height) / Scalef;
@@ -1412,8 +1428,7 @@ drawGlyph(const struct ppmd_glyph * const glyphP,
         }
         break;
         case CMD_MOVEPEN:
-            p = vectorSum(p, makePoint(SCHAR(commandP->x),
-                                       SCHAR(commandP->y)));
+            p = vectorSum(p, commandPoint(commandP));
             break;
         }
     }