Browse Source

Decoding multiple pages with -p, --pages arg

master
surkeh 3 years ago
parent
commit
3824023e17
5 changed files with 80 additions and 40 deletions
  1. 2
    1
      include/paperbak.h
  2. 15
    13
      src/Decoder.cpp
  3. 5
    5
      src/Fileproc.cpp
  4. 1
    1
      src/Printer.cpp
  5. 57
    20
      src/main.cpp

+ 2
- 1
include/paperbak.h View File

@@ -348,7 +348,8 @@ inline void Reporterror(const char *input)

inline void Message(const char *input, int progress)
{
printf("%s @ %d\%\n", input, progress);
//printf("%s @ %d\%\n", input, progress);
printf("%s\n", input);
}



+ 15
- 13
src/Decoder.cpp View File

@@ -563,7 +563,7 @@ static void Preparefordecoding(t_procdata *pdata) {
pdata->buf1=(uchar *)malloc(dx*dy);
pdata->buf2=(uchar *)malloc(dx*dy);
pdata->bufx=(int *)malloc(dx*sizeof(int));
pdata->bufy=(int *)malloc(sizeof(int));
pdata->bufy=(int *)malloc(dy*sizeof(int));
pdata->blocklist=(t_block *)
malloc(pdata->nposx*pdata->nposy*sizeof(t_block));
// Check that we have enough memory.
@@ -819,17 +819,18 @@ static void Decodenextblock(t_procdata *pdata) {
int answer,ngroup,percent;
char s[TEXTLEN];
t_data result;

// Display percent of executed data and, if known, data name in progress bar.
if (pdata->superblock.name[0]=='\0')
sprintf(s,"Processing image");
else {
sprintf(s,"%.64s (page %i)",
pdata->superblock.name,pdata->superblock.page);
}
percent=(pdata->posy*pdata->nposx+pdata->posx)*100/
(pdata->nposx*pdata->nposy);
if (percent % 10 == 0)
Message(s,percent);
//if (pdata->superblock.name[0]=='\0')
// sprintf(s,"Processing image");
//else {
// sprintf(s,"%.64s (page %i)",
// pdata->superblock.name,pdata->superblock.page);
//}
//percent=(pdata->posy*pdata->nposx+pdata->posx)*100/
// (pdata->nposx*pdata->nposy);
// Message(s,percent);
// Decode block.
answer=Decodeblock(pdata,pdata->posx,pdata->posy,&result);
// If we are unable to locate block, probably we are outside the raster.
@@ -923,20 +924,21 @@ void Nextdataprocessingstep(t_procdata *pdata) {
pdata->step++;
break;
case 2: // Determine grid size
Message("Searching for raster...",0);
Message("Searching for raster...", 0);
Getgridposition(pdata);
break;
case 3: // Determine min and max intensity
Getgridintensity(pdata);
break;
case 4: // Determine step and angle in X
Message("Searching for grid lines...",0);
Message("Searching for grid lines...", 0);
Getxangle(pdata);
break;
case 5: // Determine step and angle in Y
Getyangle(pdata);
break;
case 6: // Prepare for data decoding
Message("Decoding", 0);
Preparefordecoding(pdata);
break;
case 7: // Decode next block of data

+ 5
- 5
src/Fileproc.cpp View File

@@ -203,10 +203,10 @@ int Finishpage(int slot,int ngood,int nbad,uint32_t nrestored) {
pf->badblocks+=nbad;
pf->restoredbytes+=nrestored;

printf("\nngood: %d\n", pb_procdata.ngood);
printf("ngood: %d\n", pb_procdata.ngood);
printf("nbad: %d\n", pb_procdata.nbad);
printf("nsuper: %d\n", pb_procdata.nsuper);
printf("nrestored: %d\n\n", pb_procdata.nrestored);
printf("nrestored: %d\n", pb_procdata.nrestored);

// Restore bad blocks if corresponding recovery blocks are available (max. 1
// per group).
@@ -250,11 +250,11 @@ int Finishpage(int slot,int ngood,int nbad,uint32_t nrestored) {
for (j=firstblock; j<firstblock+pf->pagesize/NDATA && j<pf->nblock; j++) {
if (pf->datavalid[j]!=1) break; };
if (j<firstblock+pf->pagesize/NDATA && j<pf->nblock)
Message("Unrecoverable errors on page, please scan it again",0);
Message("Unrecoverable errors on page, please scan it again\n",0);
else if (nbad>0)
Message("Page processed, all bad blocks successfully restored",0);
Message("Page processed\n, all bad blocks successfully restored",0);
else
Message("Page processed",0);
Message("Page processed\n",0);
// Calculate list of (partially) incomplete pages.
nrempages=0;
if (pf->pagesize>0) {

+ 1
- 1
src/Printer.cpp View File

@@ -332,7 +332,7 @@ static void Readandcompress(t_printdata *print) {
return;
}; }
else {
Message("Reading file", (print->readsize+size)*100/print->origsize);
//Message("Reading file", (print->readsize+size)*100/print->origsize);
memcpy(print->buf+print->readsize,print->readbuf,size);
print->readsize+=size; };
// If all data is read, finish step.

+ 57
- 20
src/main.cpp View File

@@ -83,11 +83,15 @@ int pb_marginright; // Right printer page margin
int pb_margintop; // Top printer page margin
int pb_marginbottom; // Bottom printer page margin

// New globals
int pb_npages;


// Function prototypes
int arguments (int ac, char **av);
void dhelp (const char *exe);
void dversion();
int arguments (int ac, char **av);
void nextBitmap (char *path);



@@ -100,6 +104,7 @@ int main(int argc, char ** argv) {
::pb_infile[0] = '\0';
::pb_outfile[0] = '\0';
::pb_outbmp[0] = '\0';
::pb_npages = 0;
::pb_dpi = 200;
::pb_dotpercent = 70;
::pb_redundancy = 5;
@@ -124,10 +129,21 @@ int main(int argc, char ** argv) {
}
}
else {
printf ("Decoding %s into %s\n", ::pb_infile, ::pb_outfile);
Decodebitmap (::pb_infile);
while (::pb_procdata.step != 0) {
Nextdataprocessingstep (&::pb_procdata);
char drv[MAXDRIVE],dir[MAXDIR],nam[MAXFILE],ext[MAXEXT],path[MAXPATH+32];
fnsplit (::pb_infile, drv, dir, nam, ext);
int i;
if (::pb_npages > 0) {
for (int i = 0; i < ::pb_npages; i++) {
sprintf(path,"%s%s%s_%04i%s",drv,dir,nam,i+1,ext);
Decodebitmap (path);
while (::pb_procdata.step != 0) {
nextBitmap (path);
}
}
}
else {
sprintf(path,"%s%s%s%s",drv,dir,nam,ext);
nextBitmap (path);
}
}

@@ -136,17 +152,27 @@ int main(int argc, char ** argv) {



inline void nextBitmap (char *path) {
printf ("Decoding %s into %s\n", path, ::pb_outfile);
Decodebitmap (path);
while (::pb_procdata.step != 0) {
Nextdataprocessingstep (&::pb_procdata);
}
}



inline void dhelp (const char *exe) {
printf("%s\n\n"
"Usage:\n"
"\t%s --encode -i [infile] -o [out].bmp [OPTION...]\n"
"\t%s --decode -i [in].bmp -o [outfile]\n"
"\t%s --decode -f [inputfolder] -o [outfile]\n\n"
"\t%s --decode -i [in].bmp -o [outfile] -p [nPages]\n"
"\t--encode Create a bitmap from the input file\n"
"\t--decode Decode an encoded bitmap/folder of bitmaps\n"
"\t-i, --input File to encode to or decode from\n"
"\t-o, --output Newly encoded bitmap or decoded file\n"
"\t-f, --inputfolder Directory of bitmaps to decode into a single file\n"
"\t-p, --pages Number of pages (e.g. bitmaps labeled 0001 through 0029)\n"
"\t-d, --dpi Dots per inch of the output bitmap (40 to 600)\n"
"\t-s, --dotsize Size of the dots in bitmap as percentage of maximum dot\n"
"\t size in pixels, (50 to 100)\n"
@@ -155,7 +181,7 @@ inline void dhelp (const char *exe) {
"\t-n, --no-header Disable printing of file name, last modify date and time,\n"
"\t file size, and page number\n"
"\t-b, --border Print a black border around the page\n"
"\t-v, --version Display version and information relevant to that version\n"
"\t-v, --version Display version and information about that version\n"
"\t-h, --help Display all arguments and program description\n\n",
"\nEncodes or decodes high-density printable file backups.",
exe,
@@ -192,7 +218,7 @@ int arguments (int ac, char **av) {
// options that assign values in switch
{"input", required_argument, NULL, 'i'},
{"output", required_argument, NULL, 'o'},
{"inputfolder", required_argument, NULL, 'f'},
{"pages", required_argument, NULL, 'p'},
{"dpi", required_argument, NULL, 'd'},
{"dotsize", required_argument, NULL, 's'},
{"redundancy", required_argument, NULL, 'r'},
@@ -205,7 +231,7 @@ int arguments (int ac, char **av) {
int c;
while(is_ok) {
int options_index = 0;
c = getopt_long (ac, av, "i:o:f:d:s:r:nbvh", long_options, &options_index);
c = getopt_long (ac, av, "i:o:p:f:d:s:r:nbvh", long_options, &options_index);
if (c == -1) {
break;
}
@@ -229,34 +255,41 @@ int arguments (int ac, char **av) {
strcpy (::pb_outbmp, optarg);
}
break;
case 'f':
case 'p':
if (optarg == NULL) {
fprintf(stderr, "error: inputfolder arg is null \n");
fprintf(stderr, "error: pages arg is null \n");
is_ok = false;
} else {
strcpy (::pb_infile, optarg);
::pb_npages = atoi(optarg);
}
break;
case 'd':
::pb_dpi = atoi(optarg);
if (optarg != NULL)
::pb_dpi = atoi(optarg);
break;
case 's':
::pb_dotpercent = atoi(optarg);
if (optarg != NULL)
::pb_dotpercent = atoi(optarg);
break;
case 'r':
::pb_redundancy = atoi(optarg);
if (optarg != NULL)
::pb_redundancy = atoi(optarg);
break;
case 'n':
::pb_printheader = !(atoi(optarg));
if (optarg != NULL)
::pb_printheader = !(atoi(optarg));
break;
case 'b':
::pb_printborder = atoi(optarg);
if (optarg != NULL)
::pb_printborder = atoi(optarg);
break;
case 'v':
displayversion = true;
if (optarg != NULL)
displayversion = true;
break;
case 'h':
displayhelp = true;
if (optarg != NULL)
displayhelp = true;
break;
default:
exit (EXIT_FAILURE);
@@ -278,6 +311,10 @@ int arguments (int ac, char **av) {
fprintf (stderr, "error: no output file given\n");
is_ok = false;
}
if (::pb_npages < 0 || ::pb_npages > 9999) {
fprintf (stderr, "error: invalid number of pages given\n");
is_ok = false;
}
if (::pb_dotpercent < 50 || ::pb_dotpercent > 100) {
fprintf (stderr, "error: invalid dotsize given\n");
is_ok = false;

Loading…
Cancel
Save