Browse Source

Decodes in linux, segfaults due to cxxopts

master
suhrke 3 years ago
parent
commit
e48684c07d
4 changed files with 49 additions and 41 deletions
  1. 5
    4
      src/Decoder.cpp
  2. 16
    7
      src/Fileproc.cpp
  3. 28
    26
      src/main.cpp
  4. 0
    4
      src/paperbak.h

+ 5
- 4
src/Decoder.cpp View File

@@ -217,13 +217,13 @@ static int Recognizebits(t_data *result,uchar grid[NDOT][NDOT],
case 7: c=grid1[NDOT-1-j][i]; break;
};
if (c<limit) {
((ulong *)result)[j]|=1<<i;
((uint32_t *)result)[j]|=1<<i;
};
};
};
// XOR with grid that corrects mean brightness.
for (j=0; j<NDOT; j++) {
((ulong *)result)[j]^=(j & 1?0xAAAAAAAA:0x55555555); };
((uint32_t *)result)[j]^=(j & 1?0xAAAAAAAA:0x55555555); };
// Apply ECC to restore invalid data.
if (pdata->mode & M_BEST)
memcpy(&uncorrected,result,sizeof(t_data));
@@ -822,9 +822,10 @@ static void Decodenextblock(t_procdata *pdata) {
// Display percent of executed data and, if known, data name in progress bar.
if (pdata->superblock.name[0]=='\0')
sprintf(s,"Processing image");
else
else {
sprintf(s,"%.64s (page %i)",
pdata->superblock.name,pdata->superblock.page);
pdata->superblock.name,pdata->superblock.page);
}
percent=(pdata->posy*pdata->nposx+pdata->posx)*100/
(pdata->nposx*pdata->nposy);
Message(s,percent);

+ 16
- 7
src/Fileproc.cpp View File

@@ -106,7 +106,8 @@ int Startnextpage(t_superblock *superblock) {
if (pf->datavalid!=NULL) free(pf->datavalid);
if (pf->data!=NULL) free(pf->data);
Reporterror("Low memory");
return -1; };
return -1;
};
// Initialize remaining fields.
memcpy(pf->name,superblock->name,64);
pf->modified=superblock->modified;
@@ -201,6 +202,12 @@ int Finishpage(int slot,int ngood,int nbad,uint32_t nrestored) {
pf->goodblocks+=ngood;
pf->badblocks+=nbad;
pf->restoredbytes+=nrestored;

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

// Restore bad blocks if corresponding recovery blocks are available (max. 1
// per group).
if (pf->ngroup>0) {
@@ -266,8 +273,10 @@ int Finishpage(int slot,int ngood,int nbad,uint32_t nrestored) {
pf->rempages[nrempages]=0;
//Updatefileinfo(slot,pf);
if (pf->ndata==pf->nblock) {
if (::pb_autosave==0)
Message("File restored. Press \"Save\" to save it to disk",0);
if (::pb_autosave==0) {
Message("File restored.",0);
Saverestoredfile(slot,0);
}
else {
Message("File complete",0);
Saverestoredfile(slot,0);
@@ -357,10 +366,10 @@ int Saverestoredfile(int slot,int force) {
data=bufout; };
// Ask user for file name.
// FIXME selectoutfile must be initialized prior/by arg
if (pf->name!=NULL) {
if (bufout!=NULL) free (bufout);
return -1;
};
//if (pf->name!=NULL) {
// if (bufout!=NULL) free (bufout);
// return -1;
//};
// Open file and save data.
//hfile=CreateFile(::pb_outfile,GENERIC_WRITE,0,NULL,
// CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

+ 28
- 26
src/main.cpp View File

@@ -163,42 +163,27 @@ cxxopts::Options arguments(int ac, char **av) {
return o;
}



int main(int argc, char ** argv) {
bool isEncode;
try {
cxxopts::Options options = arguments(argc, argv);
// set arguments to extern (global) variables
pb_dpi = options["dpi"].as<int>();
pb_dotpercent = options["dotsize"].as<int>();
pb_redundancy = options["redundancy"].as<int>();
pb_printheader = ( ! options["no-header"].as<int>() );
pb_printborder = options["border"].as<int>();
::pb_dpi = options["dpi"].as<int>();
::pb_dotpercent = options["dotsize"].as<int>();
::pb_redundancy = options["redundancy"].as<int>();
::pb_printheader = ( ! options["no-header"].as<int>() );
::pb_printborder = options["border"].as<int>();
// decode = !encode
bool isEncode = options["mode"].as<string>().compare("encode") == 0;
isEncode = options["mode"].as<string>().compare("encode") == 0;

// externs (also have matching values in printdata and/or procdata)
std::string infile = options["input"].as<string>();
std::string outfile = options["output"].as<string>();
strcpy (::pb_infile, infile.c_str());

if (isEncode) {
strcpy (::pb_outbmp, outfile.c_str());
Printfile(::pb_infile, ::pb_outbmp);
// begin the process to write the bitmap
while (::pb_printdata.step != 0) {
//cout << "Step: " << ::pb_printdata.step << endl;
Nextdataprintingstep (&::pb_printdata);
}
}
else {
strcpy (::pb_outfile, outfile.c_str());
Decodebitmap (::pb_infile);
while (::pb_procdata.step != 0) {
//cout << "Step: " << ::pb_procdata.step << endl;
Nextdataprocessingstep (&::pb_procdata);
}
}

return 0;
strcpy (::pb_outbmp, outfile.c_str());
strcpy (::pb_outfile, outfile.c_str());
}
catch (const cxxopts::OptionException& e) {
cerr << "error parsing options: " << e.what() << endl;
@@ -209,5 +194,22 @@ int main(int argc, char ** argv) {
exit(1);
}

if (isEncode) {
Printfile(::pb_infile, ::pb_outbmp);
// begin the process to write the bitmap
while (::pb_printdata.step != 0) {
//cout << "Step: " << ::pb_printdata.step << endl;
Nextdataprintingstep (&::pb_printdata);
}
}
else {
Decodebitmap (::pb_infile);
while (::pb_procdata.step != 0) {
//cout << "Step: " << ::pb_procdata.step << endl;
Nextdataprocessingstep (&::pb_procdata);
}
}

return 0;
}


+ 0
- 4
src/paperbak.h View File

@@ -419,7 +419,6 @@ inline int fnsplit(const char *path,
// parse char by char
char token[MAXPATH];
int iToken = 0;
//int extCount = 0;
if (dir != NULL)
dir[0] = '\0';

@@ -444,7 +443,6 @@ inline int fnsplit(const char *path,
strcpy (name, token);
token[0] = '.';
iToken = 1;
//++extCount;
continue;
}
// token is name or extension
@@ -472,8 +470,6 @@ inline int fnsplit(const char *path,
else {
//if not delimiter, build string
token[iToken++] = path[i];
//if (flags & EXTENSION)
// ++extCount;
}
}
}

Loading…
Cancel
Save