int getc_ppi_wsq(int *oppi, unsigned char *idata, const int ilen) { int ret; int ppi; char *value; NISTCOM *nistcom; /* Get ppi from NISTCOM, if one exists ... */ if((ret = getc_nistcom_wsq(&nistcom, idata, ilen))) return(ret); if(nistcom != (NISTCOM *)NULL){ if((ret = extractfet_ret(&value, NCM_PPI, nistcom))){ freefet(nistcom); return(ret); } if(value != (char *)NULL){ ppi = atoi(value); free(value); } /* Otherwise, PPI not in NISTCOM, so ppi = -1. */ else ppi = -1; freefet(nistcom); } /* Otherwise, NISTCOM does NOT exist, so ppi = -1. */ else ppi = -1; *oppi = ppi; return(0); }
int main( int argc, char **argv) { int ret; int rawflag; /* raw input data or Ihead image */ char *outext; /* ouput file extension */ char *ifile, ofile[MAXPATHLEN]; /* file names */ int ilen; int width, height; /* image parameters */ int depth, ppi; unsigned char *idata, *odata; /* image pointers */ int lossyflag; /* data loss flag */ NISTCOM *nistcom; /* NIST Comment */ char *ppi_str; procargs(argc, argv, &outext, &ifile, &rawflag); ret = read_raw_from_filesize(ifile, &idata, &ilen); if(ret) exit(ret); ret = wsq_decode_mem(&odata, &width, &height, &depth, &ppi, &lossyflag, idata, ilen); if(ret){ free(idata); exit(ret); } if(debug > 1) fprintf(stderr, "Image pixmap constructed\n"); fileroot(ifile); sprintf(ofile, "%s.%s", ifile, NCM_EXT); /* Get NISTCOM from compressed data file */ ret = getc_nistcom_wsq(&nistcom, idata, ilen); if(ret){ free(idata); exit(ret); } free(idata); /* WSQ decoder always returns ppi=-1, so believe PPI in NISTCOM, */ /* if it already exists. */ ppi_str = (char *)NULL; if(nistcom != (NISTCOM *)NULL){ ret = extractfet_ret(&ppi_str, NCM_PPI, nistcom); if(ret){ free(odata); freefet(nistcom); exit(ret); } } if(ppi_str != (char *)NULL){ ppi = atoi(ppi_str); free(ppi_str); } /* Combine NISTCOM with image features */ ret = combine_wsq_nistcom(&nistcom, width, height, depth, ppi, lossyflag, 0.0 /* will be deleted next */); if(ret){ free(odata); if(nistcom != (NISTCOM *)NULL) freefet(nistcom); exit(ret); } ret = del_wsq_nistcom(nistcom); if(ret){ free(odata); freefet(nistcom); exit(ret); } /* Write NISTCOM */ ret = writefetfile_ret(ofile, nistcom); if(ret){ free(odata); freefet(nistcom); exit(ret); } freefet(nistcom); /* Write decoded image file. */ sprintf(ofile, "%s.%s", ifile, outext); ret = write_raw_or_ihead(!rawflag, ofile, odata, width, height, depth, ppi); if(ret){ free(odata); exit(ret); } free(odata); if(debug > 1) fprintf(stdout, "Image pixmap written to %s\n", ofile); exit(0); }
int read_ppi_wsq(int *oppi, FILE *infp) { int ret; long savepos; int ppi; char *value; NISTCOM *nistcom; /* Save current position in filestream ... */ if((savepos = ftell(infp)) < 0){ fprintf(stderr, "ERROR : read_ppi_wsq : "); fprintf(stderr, "ftell : couldn't determine current position\n"); return(-2); } /* Set file pointer to beginning of filestream ... */ if(fseek(infp, 0L, SEEK_SET) < 0){ fprintf(stderr, "ERROR : read_ppi_wsq : "); fprintf(stderr, "fseek : couldn't set pointer to start of file\n"); return(-3); } /* Get ppi from NISTCOM, if one exists ... */ if((ret = read_nistcom_wsq(&nistcom, infp))){ /* Reset file pointer to original position in filestream ... */ if(fseek(infp, savepos, SEEK_SET) < 0){ fprintf(stderr, "ERROR : read_ppi_wsq : "); fprintf(stderr, "fseek : couldn't reset file pointer\n"); return(-4); } return(ret); } if(nistcom != (NISTCOM *)NULL){ if((ret = extractfet_ret(&value, NCM_PPI, nistcom))){ freefet(nistcom); /* Reset file pointer to original position in filestream ... */ if(fseek(infp, savepos, SEEK_SET) < 0){ fprintf(stderr, "ERROR : read_ppi_wsq : "); fprintf(stderr, "fseek : couldn't reset file pointer\n"); return(-5); } return(ret); } if(value != (char *)NULL){ ppi = atoi(value); free(value); } /* Otherwise, PPI not in NISTCOM, so ppi = -1. */ else ppi = -1; freefet(nistcom); } /* Otherwise, NISTCOM does NOT exist, so ppi = -1. */ else ppi = -1; /* Reset file pointer to original position in filestream ... */ if(fseek(infp, savepos, SEEK_SET) < 0){ fprintf(stderr, "ERROR : read_ppi_wsq : "); fprintf(stderr, "fseek : couldn't reset file pointer\n"); return(-6); } *oppi = ppi; return(0); }