From 46cc33320db790cf550d7e325d41e309fd714a08 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Tue, 20 Feb 2024 18:36:00 +0000 Subject: Add -reportonly git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4845 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- editor/pamcut.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 58 insertions(+), 11 deletions(-) (limited to 'editor') 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; @@ -465,6 +468,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; } + + -- cgit 1.4.1