Exemple #1
0
void MainWindow::open()
{
    QString file = QFileDialog::getOpenFileName(this, tr("qwsqviewer"), QString(), tr("Wsq images (*.wsq)"));

    if (file.isEmpty())
        return;

    unsigned char *idata;
    int ilen;

    int ret;
    if ((ret = read_raw_from_filesize(file.toLocal8Bit().data(), &idata, &ilen))) {
        free(idata);
        QMessageBox::warning(this, tr("qwsqviewer"), tr("failed."));
        return;
    }

    unsigned char* odata;
    int width, height, depth, ppi, lossyflag;
    if ((ret = wsq_decode_mem(&odata, &width, &height, &depth, &ppi,
                           &lossyflag, idata, ilen))) {
        free(idata);
        QMessageBox::warning(this, tr("qwsqviewer"), tr("failed 2."));
        return;
    }

    QImage img(odata, width, height, QImage::Format_Grayscale8, &free, odata);
    _canvas->setImage(img);
    _canvas->update();
    _canvas->setPpi(ppi);

    free(idata);
}
Exemple #2
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);
}
Exemple #3
0
int main(int argc, char *argv[])
{
   int ret, n, rawflag;
   char *outext;                   /* ouput file extension */
   char *ifile, ofile[MAXPATHLEN]; /* file names */
   FILE *outfp;                    /* output file pointer */
   int  width, height, depth, ppi, ilen, olen;  /* image parameters */
   unsigned char *idata, *odata;           /* image pointers */
   int hor_sampfctr[MAX_CMPNTS], vrt_sampfctr[MAX_CMPNTS];
   int n_cmpnts;
   int fsize;


   procargs(argc, argv, &outext, &ifile,
            &width, &height, &depth, &ppi, &rawflag,
            hor_sampfctr, vrt_sampfctr, &n_cmpnts);

   if((ret = filesize(ifile)) < 0)
      exit(ret);
   fsize = ret;

   if((ret = test_image_size(fsize, width, height, hor_sampfctr,
                            vrt_sampfctr, n_cmpnts, 0)))
      exit(ret);

   if((ret = read_raw_from_filesize(ifile, &idata, &ilen)))
      exit(ret);

   if(debug > 0)
      fprintf(stdout, "File %s read\n", ifile);


   if((ret = not2intrlv_mem(&odata, &olen, idata, width, height, depth,
                           hor_sampfctr, vrt_sampfctr, n_cmpnts))){
      free(idata);
      exit(ret);
   }
   free(idata);

   if(debug > 0)
      fprintf(stdout, "Image data converted to interleaved\n");

   /* Write interleaved image file. */
   fileroot(ifile);
   sprintf(ofile, "%s.%s", ifile, outext);

   /* If H,V's are specified on command line, then YCbCr ... */
   /* so write a raw output file. */
   if(argc == 7){
      if((outfp = fopen(ofile, "wb")) == NULL) {
         fprintf(stderr, "ERROR: main : fopen : %s\n",ofile);
         free(odata);
         exit(-5);
      }

      if((n = fwrite(odata, 1, olen, outfp)) != olen){
         fprintf(stderr, "ERROR: main : fwrite : ");
         /* MDG added '%' to 's' to fix syntax error on 05/09/2005 */
         fprintf(stderr, "only %d of %d bytes written from file %s\n",
                 n, olen, ofile);
         free(odata);
         exit(-6);
      }
      fclose(outfp);
   }
   /* Otherwise, H,V's not specified on command line, so component planes */
   /* are all the same size ... so "possibly" write an IHead file. */
   else{
      if((ret = write_raw_or_ihead(!rawflag, ofile,
                                  odata, width, height, depth, ppi))){
         free(odata);
         exit(ret);
      }
   }

   if(debug > 0)
      fprintf(stdout, "Image data written to file %s\n", ofile);

   free(odata);

   exit(0);
}
Exemple #4
0
int main(int argc, char *argv[])
{
   int ret, rawflag, img_type;
   unsigned char *idata, *odata;
   int ilen, width, height, depth, ppi, lossyflag;
   IHEAD *ihead;
   FILE *fp;
   char *outext, *ifile, ofile[MAXPATHLEN];
   NISTCOM *nistcom;


   procargs(argc, argv, &outext, &ifile, &rawflag);
   /* Set ppi to unknown */
   ppi = -1;
   nistcom = (NISTCOM *)NULL;

   /* Check image type */
   ret = read_raw_from_filesize(ifile, &idata, &ilen);
   if(ret)
      exit(ret);

   ret = image_type(&img_type, idata, ilen);
   if(ret) {
      free(idata);
      exit(ret);
   }
   free(idata);

   /* Open image file for reading based on image type */
   if((fp = fopen(ifile,"rb")) == NULL) {
      fprintf(stderr, "ERROR: main : fopen : %s\n",ifile);
      exit(-1);
   }
   /* If img_type is ihead ... */
   if(img_type == IHEAD_IMG){
      /* Read ihead header and check for WSQ_SD14 compression */
      ihead = readihdr(fp);
      if(atoi(ihead->compress) != WSQ_SD14){
         fprintf(stderr, "ERROR : main : input image not WSQ_SD14 compressed\n");
         fprintf(stderr, "        compression = %d, WSQ_SD14 = %d\n",
                 atoi(ihead->compress), WSQ_SD14);
         fclose(fp);
         free(ihead);
         exit(-1);
      }

      /* Get ppi from ihead header */
      sscanf(ihead->density,"%d", &ppi);

      /* Create a nistcom for the image attributes */
      ret = sd_ihead_to_nistcom(&nistcom, ihead, 14);
      if(ret) {
         fclose(fp);
         free(ihead);
         exit(ret);
      }
      free(ihead);
   }
   /* If image not WSQ_IMG or IHEAD_IMG, ERROR!!! */
   else if(img_type != WSQ_IMG) {
      fprintf(stderr, "ERROR : main : Invalid image\n");
      fprintf(stderr, "Expected a WSQ_SD14 compressed image in\n");
      fprintf(stderr, "either raw or ihead format.\n");
      fclose(fp);
      exit(-1);
   }

   /* Decode compressed image */
   ret = wsq14_decode_file(&odata, &width, &height, &depth, &lossyflag, fp);
   if(ret){
      fclose(fp);
      if(img_type == IHEAD_IMG)
         freefet(nistcom);
      exit(ret);
   }
   fclose(fp);

   if(debug > 1)
      fprintf(stderr, "Image pixmap constructed\n");

   /* Combine image attributes into current nistcom */
   ret = combine_wsq_nistcom(&nistcom, width, height, depth, ppi, lossyflag, -1.0);
   if(ret){
     if(img_type == IHEAD_IMG)
        freefet(nistcom);
     free(odata);
     exit(ret);
   }
   ret = del_wsq_nistcom(nistcom);
   if(ret){
      free(odata);
      freefet(nistcom);
      exit(ret);
   }

   fileroot(ifile);
   sprintf(ofile, "%s.%s", ifile, NCM_EXT);
   /* Write NISTCOM */
   ret = writefetfile_ret(ofile, nistcom);
   if(ret){
     freefet(nistcom);
     free(odata);
     exit(ret);
   }
   freefet(nistcom);

   /* Write decompressed image */
   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(stderr, "Image pixmap written to %s\n", ofile);

   exit(0);
}
Exemple #5
0
int main(int argc, char *argv[])
{
   int ret, rawflag;
   char *outext;                   /* ouput file extension */
   char *ifile, ofile[MAXPATHLEN]; /* file names */
   int width, height, depth, ppi, ilen, olen;  /* image parameters */
   IHEAD *ihead;
   unsigned char *idata, *odata;           /* image pointers */
   int hor_sampfctr[MAX_CMPNTS], vrt_sampfctr[MAX_CMPNTS];
   int n_cmpnts;


   procargs(argc, argv, &outext, &ifile, &rawflag,
            &width, &height, &depth, &ppi,
            hor_sampfctr, vrt_sampfctr, &n_cmpnts);

   /* If H,V's are specified on command line, then YCbCr ... */
   /* so read a raw input file. */
   if(argc == 7){
      if((ret = read_raw_from_filesize(ifile, &idata, &ilen)))
         exit(ret);

      if((ret = test_image_size(ilen, width, height, hor_sampfctr,
                               vrt_sampfctr, n_cmpnts, 1)))
         exit(ret);
   }
   else{
      /* If raw image flagged... */
      if(rawflag) {
         if((ret = read_raw(ifile, &idata, &width, &height, &depth)))
            exit(ret);
      }
      /* Otherwise, input image is an IHead image */
      else {
         if((ret = read_ihead(ifile, &ihead, &idata, &width, &height, &depth)))
            exit(ret);
      }
   }

   if(debug > 0)
      fprintf(stdout, "File %s read\n", ifile);


   /* If IHead image file ... */
   if(!rawflag){
      /* Get PPI from IHead. */
      ppi = get_density(ihead);
      free(ihead);
   }

   if((ret = intrlv2not_mem(&odata, &olen, idata, width, height, depth,
                           hor_sampfctr, vrt_sampfctr, n_cmpnts))){
      free(idata);
      exit(ret);
   }
   free(idata);

   if(debug > 0)
      fprintf(stdout, "Image data converted to non-interleaved\n");

   fileroot(ifile);
   sprintf(ofile, "%s.%s", ifile, outext);

   if((ret = write_raw_from_memsize(ofile, odata, olen))){
      free(odata);
      exit(ret);
   }

   if(debug > 0)
      fprintf(stdout, "Image data written to file %s\n", ofile);

   free(odata);

   exit(0);
}