about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-08-22 18:15:12 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-08-22 18:15:12 +0000
commit5aca09385006e28e68dcaa6ddae2b7e8664f8e49 (patch)
tree146bf109569a06f2e589ccfdc9ba03a9e82c895a
parentb79e93eef34c7852ed8a1980b4d7ff0da221008d (diff)
downloadnetpbm-mirror-5aca09385006e28e68dcaa6ddae2b7e8664f8e49.tar.gz
netpbm-mirror-5aca09385006e28e68dcaa6ddae2b7e8664f8e49.tar.xz
netpbm-mirror-5aca09385006e28e68dcaa6ddae2b7e8664f8e49.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4609 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--generator/ppmrough.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/generator/ppmrough.c b/generator/ppmrough.c
index 682ac56c..d9f1bb65 100644
--- a/generator/ppmrough.c
+++ b/generator/ppmrough.c
@@ -114,6 +114,15 @@ parseCommandLine(int argc, const char ** argv,
 
 
 
+static int
+mean(int const a,
+     int const b) {
+
+    return (a + b) / 2;
+}
+
+
+
 static void
 reportParameters(struct CmdlineInfo const cmdline,
                  pixel              const bgcolor,
@@ -174,13 +183,13 @@ procLeft(pixel **           const pixels,
          struct pm_randSt * const randStP) {
 
     if (r1 + 1 != r2) {
-        int const rm = (r1 + r2) >> 1;
-        int const cm = ((c1 + c2) >> 1) +
+        int const rm = mean(r1, r2);
+        int const cm = mean(c1, c2) +
             (int)floor(((float)pm_drand(randStP) - 0.5) * var + 0.5);
 
         unsigned int c;
 
-        for (c = 0; c < MIN(width, MAX(0, cm)); c++)
+        for (c = 0; c < MIN(width, MAX(0, cm)); ++c)
             pixels[rm][c] = bgcolor;
 
         procLeft(pixels, r1, rm, c1, cm, width, var, bgcolor, randStP);
@@ -202,13 +211,13 @@ procRight(pixel **           const pixels,
           struct pm_randSt * const randStP) {
 
     if (r1 + 1 != r2) {
-        int const rm = (r1 + r2) >> 1;
-        int const cm = ((c1 + c2) >> 1) +
+        int const rm = mean(r1, r2);
+        int const cm = mean(c1, c2) +
             (int)floor(((float)pm_drand(randStP) - 0.5) * var + 0.5);
 
         unsigned int c;
 
-        for (c = MAX(0, cm); c < width; c++)
+        for (c = MAX(0, cm); c < width; ++c)
             pixels[rm][c] = bgcolor;
 
         procRight(pixels, r1, rm, c1, cm, width, var, bgcolor, randStP);
@@ -224,19 +233,19 @@ procTop(pixel **           const pixels,
         int                const c2,
         int                const r1,
         int                const r2,
-        unsigned int       const height,        
+        unsigned int       const height,
         unsigned int       const var,
         pixel              const bgcolor,
         struct pm_randSt * const randStP) {
 
     if (c1 + 1 != c2) {
-        int const cm = (c1 + c2) >> 1;
-        int const rm = ((r1 + r2) >> 1) +
+        int const cm = mean(c1, c2);
+        int const rm = mean(r1, r2) +
             (int)floor(((float)pm_drand(randStP) - 0.5) * var + 0.5);
 
         unsigned int r;
 
-        for (r = 0; r < MIN(height, MAX(0, rm)); r++)
+        for (r = 0; r < MIN(height, MAX(0, rm)); ++r)
             pixels[r][cm] = bgcolor;
 
         procTop(pixels, c1, cm, r1, rm, height, var, bgcolor, randStP);
@@ -258,8 +267,8 @@ procBottom(pixel **           const pixels,
            struct pm_randSt * const randStP) {
 
     if (c1 + 1 != c2) {
-        int const cm = (c1 + c2) >> 1;
-        int const rm = ((r1 + r2) >> 1) +
+        int const cm = mean(c1, c2);
+        int const rm = mean(r1, r2) +
             (int)floor(((float)pm_drand(randStP) - 0.5) * var + 0.5);
 
         unsigned int r;