about summary refs log tree commit diff
path: root/editor/pnmpad.c
diff options
context:
space:
mode:
Diffstat (limited to 'editor/pnmpad.c')
-rw-r--r--editor/pnmpad.c60
1 files changed, 42 insertions, 18 deletions
diff --git a/editor/pnmpad.c b/editor/pnmpad.c
index 7cc53b69..9fa9f9e6 100644
--- a/editor/pnmpad.c
+++ b/editor/pnmpad.c
@@ -38,6 +38,7 @@ struct cmdlineInfo {
     unsigned int mwidth;
     unsigned int mheight;
     unsigned int white;     /* >0: pad white; 0: pad black */
+    unsigned int reportonly;
     unsigned int verbose;
 };
 
@@ -86,14 +87,16 @@ parseCommandLine(int argc, const char ** argv,
             &yalignSpec,           0);
     OPTENT3(0,   "valign",    OPT_FLOAT,   &cmdlineP->yalign,
             &yalignSpec,           0);
-    OPTENT3(0,   "black",     OPT_FLAG,    NULL,
-            &blackOpt,           0);
     OPTENT3(0,   "mwidth",    OPT_UINT,    &cmdlineP->mwidth,
             &mwidthSpec,         0);
     OPTENT3(0,   "mheight",   OPT_UINT,    &cmdlineP->mheight,
             &mheightSpec,        0);
+    OPTENT3(0,   "black",     OPT_FLAG,    NULL,
+            &blackOpt,           0);
     OPTENT3(0,   "white",     OPT_FLAG,    NULL,
             &cmdlineP->white,    0);
+    OPTENT3(0,   "reportonly", OPT_FLAG,   NULL,
+            &cmdlineP->reportonly,   0);
     OPTENT3(0,   "verbose",   OPT_FLAG,    NULL,
             &cmdlineP->verbose,  0);
 
@@ -126,16 +129,16 @@ parseCommandLine(int argc, const char ** argv,
        pm_error("You can specify -height only once");
 
     if (xalignSpec && (cmdlineP->leftSpec || cmdlineP->rightSpec))
-        pm_error("You cannot specify both -xalign and -left or -right");
+        pm_error("You cannot specify both -halign and -left or -right");
 
     if (yalignSpec && (cmdlineP->topSpec || cmdlineP->bottomSpec))
-        pm_error("You cannot specify both -yalign and -top or -bottom");
+        pm_error("You cannot specify both -valign and -top or -bottom");
 
-    if (xalignSpec && !cmdlineP->xsizeSpec)
-        pm_error("-xalign is meaningless without -width");
+    if (xalignSpec && (!cmdlineP->xsizeSpec && !mwidthSpec) )
+        pm_error("-halign is meaningless without -width or -mwidth");
 
-    if (yalignSpec && !cmdlineP->ysizeSpec)
-        pm_error("-yalign is meaningless without -height");
+    if (yalignSpec && (!cmdlineP->ysizeSpec && !mheightSpec) )
+        pm_error("-valign is meaningless without -height or -mheight");
 
     if (xalignSpec) {
         if (cmdlineP->xalign < 0)
@@ -265,7 +268,7 @@ validateHorizontalSize(struct cmdlineInfo const cmdline,
         pm_error("The right padding value you specified is too large.");
 
     if ((double) cols +
-        (double) lpad + 
+        (double) lpad +
         (double) rpad +
         (double) mwidthMaxPad > MAX_WIDTHHEIGHT)
         pm_error("Given padding parameters make output width too large "
@@ -375,9 +378,9 @@ computePadSizesOneDim(unsigned int   const unpaddedSize,
         unsigned int const totalPadBeforeMult =
             begPadBeforeMult + endPadBeforeMult;
         double const begFrac =
-            totalPadBeforeMult > 0 ? 
+            totalPadBeforeMult > 0 ?
             (double)begPadBeforeMult / totalPadBeforeMult :
-            0.0;
+            align;
         unsigned int const addlMsizeBegPad = ROUNDU(morePadNeeded * begFrac);
             /* # of pixels we have to add to the beginning to satisfy
                user's desire for the final size to be a multiple of something
@@ -489,6 +492,23 @@ computePadSizes(struct cmdlineInfo const cmdline,
 
 
 static void
+reportPadSizes(int          const inCols,
+               int          const inRows,
+               unsigned int const lpad,
+               unsigned int const rpad,
+               unsigned int const tpad,
+               unsigned int const bpad) {
+
+    unsigned int const outCols = inCols + lpad + rpad;
+    unsigned int const outRows = inRows + tpad + bpad;
+
+    printf("%u %u %u %u %u %u\n", lpad, rpad, tpad, bpad, outCols, outRows);
+
+}
+
+
+
+static void
 padPbm(FILE *       const ifP,
        unsigned int const cols,
        unsigned int const rows,
@@ -527,7 +547,7 @@ padPbm(FILE *       const ifP,
     /* Write top margin */
     for (row = 0; row < tpad; ++row)
         pbm_writepbmrow_packed(stdout, bgrow, newcols, 0);
-    
+
     /* Read rows, shift and write with left and right margins added */
     for (row = 0; row < rows; ++row) {
         pbm_readpbmrow_bitoffset(ifP, newrow, cols, format, lpad);
@@ -636,12 +656,16 @@ main(int argc, const char ** argv) {
 
     newcols = cols + lpad + rpad;
 
-    if (PNM_FORMAT_TYPE(format) == PBM_TYPE)
-        padPbm(ifP, cols, rows, format, newcols, lpad, rpad, tpad, bpad,
-               !!cmdline.white);
-    else
-        padGeneral(ifP, cols, rows, maxval, format, 
-                   newcols, lpad, rpad, tpad, bpad, !!cmdline.white);
+    if (cmdline.reportonly)
+        reportPadSizes(cols, rows, lpad, rpad, tpad, bpad);
+    else {
+        if (PNM_FORMAT_TYPE(format) == PBM_TYPE)
+            padPbm(ifP, cols, rows, format, newcols, lpad, rpad, tpad, bpad,
+                   !!cmdline.white);
+        else
+            padGeneral(ifP, cols, rows, maxval, format,
+                       newcols, lpad, rpad, tpad, bpad, !!cmdline.white);
+    }
 
     pm_close(ifP);