about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2024-02-20 18:36:00 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2024-02-20 18:36:00 +0000
commit46cc33320db790cf550d7e325d41e309fd714a08 (patch)
tree18e78a385bf8e4f3f2f2228584c582e710f9b7f5
parent178e96ba4d48955966fcad2518975e021397dd07 (diff)
downloadnetpbm-mirror-46cc33320db790cf550d7e325d41e309fd714a08.tar.gz
netpbm-mirror-46cc33320db790cf550d7e325d41e309fd714a08.tar.xz
netpbm-mirror-46cc33320db790cf550d7e325d41e309fd714a08.zip
Add -reportonly
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4845 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--doc/HISTORY2
-rw-r--r--editor/pamcut.c69
2 files changed, 60 insertions, 11 deletions
diff --git a/doc/HISTORY b/doc/HISTORY
index 4915d888..f0b813d4 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -6,6 +6,8 @@ CHANGE HISTORY
 
 not yet  BJH  Release 11.06.00
 
+              pamcut: add -reportonly.
+
               ppmtowinicon: fix array overrun with 4 and 8 bits per pixel.
               Broken in Netpbm 11.05 (December 2023).
 
diff --git a/editor/pamcut.c b/editor/pamcut.c
index 7870fd70..29a04e77 100644
--- a/editor/pamcut.c
+++ b/editor/pamcut.c
@@ -74,6 +74,7 @@ struct CmdlineInfo {
     unsigned int heightSpec;
     unsigned int height;
     unsigned int pad;
+    unsigned int reportonly;
     unsigned int verbose;
 };
 
@@ -185,6 +186,8 @@ parseCommandLine(int argc, const char ** const argv,
     OPTENT3(0,   "height",     OPT_UINT,   &cmdlineP->height,
             &cmdlineP->heightSpec,      0);
     OPTENT3(0,   "pad",        OPT_FLAG,   NULL, &cmdlineP->pad,           0);
+    OPTENT3(0,   "reportonly", OPT_FLAG,   NULL,
+            &cmdlineP->reportonly, 0);
     OPTENT3(0,   "verbose",    OPT_FLAG,   NULL, &cmdlineP->verbose,       0);
 
     opt.opt_table = option_def;
@@ -466,6 +469,41 @@ rejectOutOfBounds(unsigned int const cols,
 
 
 static void
+reportCuts(int const leftCol,
+           int const rghtCol,
+           int const topRow,
+           int const botRow) {
+
+    /* N.B. negative column/row number means pad */
+
+    unsigned int const newWidth  = rghtCol - leftCol + 1;
+    unsigned int const newHeight = botRow  - topRow  + 1;
+
+    assert (rghtCol >= leftCol);
+    assert (botRow  >= topRow );
+
+    printf("%d %d %d %d %u %u\n",
+           leftCol, rghtCol, topRow, botRow, newWidth, newHeight);
+}
+
+
+
+static void
+drainRaster(const struct pam * const inpamP) {
+/*----------------------------------------------------------------------------
+   Read through the input image described by *inpamP, which is positioned
+   to the raster, so the input stream is properly positioned for whatever
+   is next.
+-----------------------------------------------------------------------------*/
+    unsigned int row;
+
+    for (row = 0; row < inpamP->height; ++row)
+        pnm_readpamrow(inpamP, NULL);
+}
+
+
+
+static void
 writeBlackRows(const struct pam * const outpamP,
                int                const rows) {
 /*----------------------------------------------------------------------------
@@ -797,17 +835,24 @@ cutOneImage(FILE *             const ifP,
                    toprow, leftcol, bottomrow, rightcol);
     }
 
-    outpam = inpam;    /* Initial value -- most fields should be same */
-    outpam.file   = ofP;
-    outpam.width  = rightcol - leftcol + 1;
-    outpam.height = bottomrow - toprow + 1;
-
-    pnm_writepaminit(&outpam);
-
-    if (PNM_FORMAT_TYPE(outpam.format) == PBM_TYPE)
-        extractRowsPBM(&inpam, &outpam, leftcol, rightcol, toprow, bottomrow);
-    else
-        extractRowsGen(&inpam, &outpam, leftcol, rightcol, toprow, bottomrow);
+    if (cmdline.reportonly) {
+        reportCuts(leftcol, rightcol, toprow, bottomrow);
+        drainRaster(&inpam);
+    } else {
+        outpam = inpam;    /* Initial value -- most fields should be same */
+        outpam.file   = ofP;
+        outpam.width  = rightcol - leftcol + 1;
+        outpam.height = bottomrow - toprow + 1;
+
+        pnm_writepaminit(&outpam);
+
+        if (PNM_FORMAT_TYPE(outpam.format) == PBM_TYPE)
+            extractRowsPBM(&inpam, &outpam,
+                           leftcol, rightcol, toprow, bottomrow);
+        else
+            extractRowsGen(&inpam, &outpam,
+                           leftcol, rightcol, toprow, bottomrow);
+    }
 }
 
 
@@ -838,3 +883,5 @@ main(int argc, const char *argv[]) {
 
     return 0;
 }
+
+