diff options
Diffstat (limited to 'generator/ppmrough.c')
-rw-r--r-- | generator/ppmrough.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/generator/ppmrough.c b/generator/ppmrough.c index c43b1fa5..d9f1bb65 100644 --- a/generator/ppmrough.c +++ b/generator/ppmrough.c @@ -96,6 +96,7 @@ parseCommandLine(int argc, const char ** argv, cmdlineP->fg = NULL; if (!varSpec) cmdlineP->var = 10; + if (cmdlineP->topSpec && cmdlineP->top > cmdlineP->height) pm_error("-top value too large. Max is %u", cmdlineP->height); if (cmdlineP->bottomSpec && cmdlineP->bottom > cmdlineP->height) @@ -113,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, @@ -173,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); @@ -201,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); @@ -229,13 +239,13 @@ procTop(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; - 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); @@ -257,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; @@ -357,7 +367,8 @@ makeRaggedTopBorder(pixel ** const pixels, for (row = 0; row < topR2; ++row) pixels[row][topC2] = bgcolor; - procTop(pixels, topC1, topC2, topR1, topR2, rows, var, bgcolor, randStP); + procTop(pixels, topC1, topC2, topR1, topR2, rows, + var, bgcolor, randStP); } } |