void test_optparser () { MySystem sys; optparser (sys, "i=14"); OIIO_CHECK_EQUAL (sys.i, 14); optparser (sys, "i=-28"); OIIO_CHECK_EQUAL (sys.i, -28); optparser (sys, "f=6.28"); OIIO_CHECK_EQUAL (sys.f, 6.28f); optparser (sys, "f=-56.0"); OIIO_CHECK_EQUAL (sys.f, -56.0f); optparser (sys, "f=-1."); OIIO_CHECK_EQUAL (sys.f, -1.0f); optparser (sys, "s=foo"); OIIO_CHECK_EQUAL (sys.s, "foo"); optparser (sys, "s=\"foo, bar\""); OIIO_CHECK_EQUAL (sys.s, "foo, bar"); optparser (sys, "f=256.29,s=\"phone call\",i=100"); OIIO_CHECK_EQUAL (sys.i, 100); OIIO_CHECK_EQUAL (sys.f, 256.29f); OIIO_CHECK_EQUAL (sys.s, "phone call"); }
int main(int argc, char* argv[]) { //fprintf(stderr,"size of indel element %d \n",sizeof(struct VCF_ALLELE)); //fprintf(stdout,"%d %d %d\n",sizeof(uint8_t),BAM_PAIRED_READ1,BAM_PAIRED_READ2); return 1; int vflag=0; time_t now; time(&now); unsigned int iseed = (unsigned int)time(NULL); srand48(iseed); struct OPTIONS* options = (struct OPTIONS*)malloc(sizeof(struct OPTIONS)); options->POOLSIZE = 2; options->targettid =-1; options->targetstart=0; options->targetend=0; int flag = optparser(argc,argv,options); if (flag ==0) return 1; REFLIST reflist; if (read_fastaheader(options->fastafile,&reflist) == -1) return -1; strcpy(reflist.fastafile,options->fastafile); FILE* fp = fopen(options->fastafile,"r"); if (read_bedfile(options->bedfile,&reflist) != -1) targeted = 1; else targeted = 0; if (strcmp(options->vcffile,"None") ==0) options->vfile = stdout; else options->vfile = fopen(options->vcffile,"w"); // open indel file with candidate indels if (strcmp(options->indelfile,"None") !=0) options->fp_indelfile = fopen(options->indelfile,"w"); else options->fp_indelfile = NULL; // print VCF to stdout as well if no VCFfile is specified if (options->vfile != NULL && strcmp(options->vcffile,"None") !=0) { vflag =1; print_crispheader(options); } if (options->bamfiles >=2) fprintf(stderr,"processing %d bamfiles: %s ..... %s \n\n",options->bamfiles,options->bamfilelist[0],options->bamfilelist[options->bamfiles-1]); multisampleVC(options,&reflist,fp); if (vflag ==1) fclose(options->vfile); fclose(fp); // close pointer to fasta reference file return 1; }
csPtr<iDataBuffer> csJNGImageIO::Save (iImage *Image, iImageIO::FileFormatDescription *, const char* extraoptions) { // we need to get a RGB/RGBA version of the image. switch (Image->GetFormat() & CS_IMGFMT_MASK) { case CS_IMGFMT_PALETTED8: //imgRGBA = Image->Clone (); //imgRGBA->SetFormat (CS_IMGFMT_TRUECOLOR | (Image->GetFormat() & CS_IMGFMT_ALPHA)); // act like JPEG plugin; reject paletted image so no // unwanted/unnoticed conversions take place. return 0; break; case CS_IMGFMT_TRUECOLOR: imgRGBA = csRef<iImage>(Image); break; default: // unknown format return 0; } // compression options int quality = 80; bool progressive = false; bool alpha_jpeg = false; int alpha_png_compress = 6; int alpha_jpeg_quality = -1; /* parse output options. options are a comma-separated list and can be either 'option' or 'option=value'. supported options: compress=# image color compression, 0..100 higher values give smaller files but uglier results. progressive progressive encoding. jng_lossy_alpha use lossy JPEG compression for alpha channel (instead of default lossles PNG) jng_alpha_compress alpha channel compression, 0..100 Impact of higher value depends on alpha channel type. JPEG - smaller files, uglier results. PNG - smaller files, longer time to encode. Note: defaults to value for image color compression if lossy alpha is selected. examples: compress=50 progressive,compress=30 */ csImageLoaderOptionsParser optparser (extraoptions); optparser.GetBool ("progressive", progressive); if (optparser.GetInt ("compress", quality)) { quality = 100 - quality; if (quality < 0) quality = 0; if (quality > 100) quality = 100; if (alpha_jpeg_quality == -1) alpha_jpeg_quality = quality; } if (optparser.GetBool ("jng_lossy_alpha", alpha_jpeg)) { if (alpha_jpeg_quality == -1) alpha_jpeg_quality = quality; } if (optparser.GetInt ("jng_alpha_compress", alpha_png_compress)) { alpha_jpeg_quality = 100 - alpha_png_compress; if (alpha_jpeg_quality < 0) alpha_jpeg_quality = 0; if (alpha_jpeg_quality > 100) alpha_jpeg_quality = 100; alpha_png_compress /= 10; if (alpha_png_compress < 0) alpha_png_compress = 0; if (alpha_png_compress > 9) alpha_png_compress = 9; } mng_handle handle = mng_initialize ( mng_ptr(this), cb_alloc, cb_free, MNG_NULL); if (!handle) { Report (object_reg, CS_REPORTER_SEVERITY_WARNING, "failed to initialize libmng"); return 0; } if ((mng_setcb_openstream (handle, cb_openstream) != MNG_NOERROR) || (mng_setcb_closestream (handle, cb_closestream) != MNG_NOERROR) || (mng_setcb_writedata (handle, cb_writedata) != MNG_NOERROR)) { ReportLibmngError (object_reg, handle, "failed to set libmng callbacks"); mng_cleanup (&handle); return 0; } outfile = new csMemFile (); if (mng_create (handle) != MNG_NOERROR) { ReportLibmngError (object_reg, handle, "failed to create new jng"); mng_cleanup (&handle); delete outfile; imgRGBA = 0; return 0; } bool has_alpha = (imgRGBA->GetFormat() & CS_IMGFMT_ALPHA) != 0; if (mng_putchunk_jhdr (handle, imgRGBA->GetWidth(), imgRGBA->GetHeight(), has_alpha ? MNG_COLORTYPE_JPEGCOLORA : MNG_COLORTYPE_JPEGCOLOR, MNG_BITDEPTH_JPEG8, MNG_COMPRESSION_BASELINEJPEG, progressive ? MNG_INTERLACE_PROGRESSIVE : MNG_INTERLACE_SEQUENTIAL, has_alpha?8:0, has_alpha?(alpha_jpeg?8:0):0, 0, 0) != MNG_NOERROR) { ReportLibmngError (object_reg, handle, "failed to put JHDR chunk"); mng_cleanup (&handle); delete outfile; imgRGBA = 0; return 0; } // @@@ chunk data generation. // lots of stuff needs to be done manually. // should be changed as libmng evolves. // write out alpha channel if (has_alpha) { // extract the alpha channel from the image int pixels = imgRGBA->GetWidth() * imgRGBA->GetHeight(); uint8 *alpha = new uint8 [pixels]; uint8 *alphaptr = alpha; csRGBpixel *imgdata = (csRGBpixel*)imgRGBA->GetImageData(); while (pixels>0) { *alphaptr++ = (imgdata++)->alpha; pixels--; } if (alpha_jpeg) { // compress the alpha data as JPEG and write it out. uint8* volatile row = 0; struct jpg_datastore ds; struct jpeg_compress_struct cinfo; struct my_error_mgr jerr; cinfo.err = jpeg_std_error (&jerr.pub); jerr.pub.error_exit = my_error_exit; if (setjmp (jerr.setjmp_buffer)) { Report (object_reg, CS_REPORTER_SEVERITY_WARNING, "failed to JPEG compress alpha data"); mng_cleanup (&handle); delete outfile; delete [] row; delete[] alpha; jpeg_destroy_compress (&cinfo); imgRGBA = 0; return 0; } jpeg_create_compress (&cinfo); jpeg_buffer_dest (&cinfo, &ds); cinfo.image_width = imgRGBA->GetWidth (); cinfo.image_height = imgRGBA->GetHeight (); cinfo.input_components = 1; cinfo.in_color_space = JCS_GRAYSCALE; row = new uint8[cinfo.image_width]; jpeg_set_defaults (&cinfo); jpeg_set_quality (&cinfo, alpha_jpeg_quality, true); jpeg_start_compress (&cinfo, true); JSAMPROW row_pointer[1]; uint8 *image = alpha; row_pointer[0] = (JSAMPLE*)&row[0]; while (cinfo.next_scanline < cinfo.image_height) { for (size_t i=0; i < cinfo.image_width; i++) row[i] = image[cinfo.next_scanline * cinfo.image_width + i]; jpeg_write_scanlines (&cinfo, row_pointer, 1); } jpeg_finish_compress (&cinfo); jpeg_destroy_compress (&cinfo); delete [] row; // funny, mng_putchunk_jdaa is missing from libmng //if (mng_putchunk_jdaa (handle, ds.len, ds.data) != MNG_NOERROR) if (mng_putchunk_unknown (handle, MNG_UINT_JDAA, (mng_uint32)ds.len, ds.data) != MNG_NOERROR) { ReportLibmngError (object_reg, handle, "failed to put JDAA chunk"); mng_cleanup (&handle); delete outfile; delete[] alpha; imgRGBA = 0; return 0; } } else { // generate the IDAT chunk data // we use the "Up" filter. uint8* chunkdata = new uint8[(imgRGBA->GetWidth() + 1) * imgRGBA->GetHeight()]; uint8* lastline = new uint8[imgRGBA->GetWidth()]; uint8* chunkptr = chunkdata; alphaptr = alpha; memset (lastline, 0, imgRGBA->GetWidth()); int lines = imgRGBA->GetHeight(); while (lines > 0) { *chunkptr++ = 2; int pix = 0; while (pix<imgRGBA->GetWidth()) { *chunkptr++ = *alphaptr - lastline[pix]; lastline[pix] = *alphaptr++; pix++; } lines--; } delete[] lastline; // now compress the data z_stream zs; zs.zalloc = (alloc_func) 0; zs.zfree = (free_func) 0; zs.next_in = (Byte *) chunkdata; zs.avail_in = (imgRGBA->GetWidth() + 1) * imgRGBA->GetHeight(); if (deflateInit (&zs, alpha_png_compress) != Z_OK) { Report (object_reg, CS_REPORTER_SEVERITY_WARNING, "deflateInit() failed"); mng_cleanup (&handle); delete outfile; delete[] chunkdata; delete[] alpha; imgRGBA = 0; return 0; } char buff[0x8000]; while (1) { zs.next_out = (Byte *)buff; zs.avail_out = sizeof (buff); int rc = deflate (&zs, Z_FINISH); /* Do actual compression */ size_t size = sizeof (buff) - zs.avail_out; // create a chuk w/compressed data. if (mng_putchunk_idat (handle, (mng_uint32)size, &buff) != MNG_NOERROR) { ReportLibmngError (object_reg, handle, "failed to put IDAT chunk"); deflateEnd (&zs); mng_cleanup (&handle); delete outfile; delete[] chunkdata; delete[] alpha; imgRGBA = 0; return 0; } if (rc == Z_STREAM_END) break; /* finished */ } deflateEnd (&zs); delete[] chunkdata; } delete[] alpha; } // compress the color data as JPEG and write it out. csRGBcolor* volatile row = 0; struct jpg_datastore ds; struct jpeg_compress_struct cinfo; struct my_error_mgr jerr; cinfo.err = jpeg_std_error (&jerr.pub); jerr.pub.error_exit = my_error_exit; if (setjmp (jerr.setjmp_buffer)) { Report (object_reg, CS_REPORTER_SEVERITY_WARNING, "failed to JPEG compress color data"); mng_cleanup (&handle); delete outfile; delete [] row; jpeg_destroy_compress (&cinfo); imgRGBA = 0; return 0; } jpeg_create_compress (&cinfo); jpeg_buffer_dest (&cinfo, &ds); cinfo.image_width = imgRGBA->GetWidth (); cinfo.image_height = imgRGBA->GetHeight (); cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; row = new csRGBcolor[cinfo.image_width]; jpeg_set_defaults (&cinfo); jpeg_set_quality (&cinfo, quality, true); if (progressive) jpeg_simple_progression (&cinfo); jpeg_start_compress (&cinfo, true); JSAMPROW row_pointer[1]; JSAMPLE *image = (JSAMPLE*)csPackRGB::PackRGBpixelToRGB ((csRGBpixel*)Image->GetImageData (), Image->GetWidth () * Image->GetHeight ()); row_pointer[0] = (JSAMPLE*)&row[0]; while (cinfo.next_scanline < cinfo.image_height) { row_pointer[0] = (JSAMPLE*)&image[cinfo.next_scanline * cinfo.image_width * 3]; jpeg_write_scanlines (&cinfo, row_pointer, 1); } jpeg_finish_compress (&cinfo); jpeg_destroy_compress (&cinfo); delete [] row; if (mng_putchunk_jdat (handle, (mng_uint32)ds.len, ds.data) != MNG_NOERROR) { ReportLibmngError (object_reg, handle, "failed to put JDAT chunk"); mng_cleanup (&handle); delete outfile; imgRGBA = 0; return 0; } imgRGBA = 0; if (mng_putchunk_iend (handle) != MNG_NOERROR) { ReportLibmngError (object_reg, handle, "failed to put IEND chunk"); mng_cleanup (&handle); delete outfile; return 0; } if (mng_write (handle) != MNG_NOERROR) { ReportLibmngError (object_reg, handle, "failed to write out JNG data"); mng_cleanup (&handle); delete outfile; return 0; } mng_cleanup (&handle); csRef<iDataBuffer> db (outfile->GetAllData ()); delete outfile; return csPtr<iDataBuffer> (db); }
csPtr<iDataBuffer> csJPGImageIO::Save(iImage *Image, iImageIO::FileFormatDescription*, const char* extraoptions) { int format = Image->GetFormat (); switch (format & CS_IMGFMT_MASK) { case CS_IMGFMT_TRUECOLOR: break; default: // unknown format return 0; } /* endswitch */ // compression options int quality = 80; bool progressive = false; /* parse output options. options are a comma-separated list and can be either 'option' or 'option=value'. supported options: compress=# image compression, 0..100 higher values give smaller files but uglier results. progressive progressive encoding. examples: compress=50 progressive,compress=30 */ csImageLoaderOptionsParser optparser (extraoptions); optparser.GetBool ("progressive", progressive); if (optparser.GetInt ("compress", quality)) { quality = 100 - quality; if (quality < 0) quality = 0; if (quality > 100) quality = 100; } JSAMPLE* volatile row = 0; struct jpg_datastore ds; struct jpeg_compress_struct cinfo; struct my_error_mgr jerr; cinfo.err = jpeg_std_error (&jerr.pub); jerr.pub.error_exit = my_error_exit; if (setjmp (jerr.setjmp_buffer)) { delete [] row; char errmsg [256]; cinfo.err->format_message ((jpeg_common_struct *)&cinfo, errmsg); Report (object_reg, CS_REPORTER_SEVERITY_WARNING, "%s\n", errmsg); jpeg_destroy_compress (&cinfo); return 0; } jpeg_create_compress (&cinfo); jpeg_buffer_dest (&cinfo, &ds); cinfo.image_width = Image->GetWidth (); cinfo.image_height = Image->GetHeight (); cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; jpeg_set_defaults (&cinfo); jpeg_set_quality (&cinfo, quality, true); if (progressive) jpeg_simple_progression (&cinfo); jpeg_start_compress (&cinfo, true); JSAMPROW row_pointer[1]; JSAMPLE *image = (JSAMPLE*)csPackRGB::PackRGBpixelToRGB ((csRGBpixel*)Image->GetImageData (), Image->GetWidth () * Image->GetHeight ()); row_pointer[0] = (JSAMPLE*)&row[0]; while (cinfo.next_scanline < cinfo.image_height) { row_pointer[0] = (JSAMPLE*)&image[cinfo.next_scanline * cinfo.image_width * 3]; jpeg_write_scanlines (&cinfo, row_pointer, 1); } jpeg_finish_compress (&cinfo); jpeg_destroy_compress (&cinfo); delete[] image; delete [] row; /* make the iDataBuffer to return */ csDataBuffer *db = new csDataBuffer (ds.len); memcpy (db->GetData (), ds.data, ds.len); return csPtr<iDataBuffer> (db); }