⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pslider.cpp

📁 this a image processing program
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	ext = "GIF"; std::fclose(file);      }    }    if (!ext) {      file = std::fopen("ps2html_auto/mosaic0001.jpg","r"); if (file) {	ext = "jpg"; std::fclose(file);      }    }    if (!ext) {      file = std::fopen("ps2html_auto/mosaic0001.JPG","r"); if (file) {	ext = "JPG"; std::fclose(file);      }    }    if (!ext) {      file = std::fopen("ps2html_auto/mosaic0001.png","r"); if (file) {	ext = "png"; std::fclose(file);      }    }    if (!ext) {      file = std::fopen("ps2html_auto/mosaic0001.PNG","r"); if (file) {	ext = "PNG"; std::fclose(file);      }    }    if (!ext) throw CImgException("I cannot recognize thumbnails format, in directory 'ps2html_auto'");    std::sprintf(thumbformat,"ps2html_auto/mosaic%%.4d.%s",ext);    std::sprintf(Link_filename,"ps2html_auto/links");    break;  case 0: // Creating presentation from a PS file#if cimg_OS==1 || cimg_OS==2    std::fprintf(stderr," - Creating PSlider presentation from file '%s' :\n",cimg::basename(file_i));    if (!cimg::strcasecmp("png",format_o)) {      std::sprintf(slideformat,"pslider_auto/slide_%%d.png");      std::sprintf(thumbformat,"pslider_auto/thumb_%%d.png");    }    else {      std::sprintf(slideformat,"pslider_auto/slide_%%d.ppm");      std::sprintf(thumbformat,"pslider_auto/thumb_%%d.ppm");    }    std::sprintf(Link_filename,"pslider_auto/links");    ext = cimg::filename_split(file_i);    stopflag = nop = 0;    std::fprintf(stderr,"   > Creating 'PSlider' directory ... "); std::fflush(stderr);#if cimg_OS==1    std::system("rm -rf pslider_auto");    std::system("mkdir pslider_auto");#else    std::system("rmdir /s /q pslider_auto");    std::system("mkdir pslider_auto");#endif    std::fprintf(stderr,"OK\n");    std::fprintf(stderr,"   > Running Postcript interpreter to generate slides ... "); std::fflush(stderr);    std::FILE *files = cimg::fopen(file_i,"r"), *filed = cimg::fopen("pslider_auto/tmp.ps","w");    while (std::fscanf(files,"%[^\n]\n",str) && cimg::strcasecmp("%%EndComments",str))      std::fprintf(filed,"%s\n",str);    if (!cimg::strcasecmp(cimg::filename_split(file_i),"ps")) {      std::fprintf(filed,"%%%%EndComments\n\    %%%%BeginProcSet: ps2html.pro\n\    userdict begin\n\    	/debug false def\n\    	/lwrites { loutput exch writestring } def\n\    	/dwrites { doutput exch writestring } def\n\    	/endline { 10 write } def\n\    	/conv { cvi 10 string cvs } def\n\    	/pnum { conv lwrites } def\n\    	/start-hook { userdict begin\n\    		(pslider_auto/links) (w) file /loutput exch def\n\    		(pslider_auto/destinations) (w) file /doutput exch def\n\    	end } bind def\n\    	/bop-hook   { dup 1 add /pagenum exch def } bind def\n\    	/end-hook   { userdict begin\n\    		loutput closefile\n\    		doutput closefile\n\    	end } bind def\n\    	/filestr {\n");      // cut the string in multiple part, since VisualStudio doesn't like bug strings      std::fprintf(filed,"\    		(0000) 4 string copy dup\n\    		4 4 -1 roll conv\n\    		dup length 3 -1 roll exch sub\n\    		exch putinterval\n\    	} def\n\    	/conc {\n\    		dup length 3 -1 roll dup length dup 4 -1 roll add string\n\    		dup 0 5 -1 roll putinterval\n\    		dup 4 -2 roll exch putinterval\n\    	} def\n\    	/pattern { 256 string cvs (@) exch conc (@) conc } def\n\    	/dummy { } def\n\    	/bbox {\n\    		cvx /proc exch def\n\    		dup dup 0 get exch 3 get /proc cvx exec /y1 exch def /x1 exch def\n\    		dup 2 get exch 1 get /proc cvx exec /y2 exch def /x2 exch def\n\    		x1 x2 gt { x1 x2 /x1 exch def /x2 exch def } if\n\    		y1 y2 gt { y1 y2 /y1 exch def /y2 exch def } if\n\    	} def\n\    	/rect { newpath x1 y1 moveto x1 y2 lineto x2 y2 lineto x2 y1 lineto closepath stroke } def\n\    	/pbbox {\n\    		debug { dup /dummy bbox rect } if\n\    		/transform bbox\n\    		y1 pnum ( ) lwrites x1 pnum ( ) lwrites\n\    		x2 x1 sub pnum ( ) lwrites y2 y1 sub pnum\n\    	} def\n\    	/link { pagenum pnum ( \") lwrites exch lwrites (\" ) lwrites pbbox loutput endline } def\n\    	/DOCINFO { cleartomark } def\n\    	/DOCVIEW { cleartomark } def\n\    	/PUT     { cleartomark } def\n\    	/OUT     { cleartomark } def\n");      // last part      std::fprintf(filed,"\    	%% Destinations\n\    	/DEST    { >> begin Dest pattern dwrites ( => ) dwrites\n\    		currentdict /Page known { Page } { pagenum } ifelse filestr (.html) conc dwrites\n\    		(,) dwrites doutput endline\n\    	end } def\n\      %% Annotations\n\      /ANN     { >> begin currentdict /Subtype known { Subtype } { /Text } ifelse\n\    		 /Link eq { Link } { Notes } ifelse end } def\n\      %% SubTypes of annotations, only links are considered.\n\      /Link    { currentdict /SrcPg\n\    		known { SrcPg filestr (.html) conc Rect link }\n\    		{ currentdict /Dest\n\    			known { Dest pattern Rect link }\n\    			{ currentdict /Action\n\    				known { Action begin\n\    					/URI where { pop URI Rect link }\n\    					{ currentdict /F known { F Rect link } { } ifelse }\n\    					ifelse\n\    				end\n\    				} if }\n\    			ifelse }\n\    		ifelse } def\n\      /Notes   { } def\n\      %% Old markers.\n\      /externalhandler { gsave initmat setmatrix exch 0 get link grestore } def\n\      /LNK             { >> begin Page filestr (.html) conc Rect link end } def\n\    	/pdfmark {\n\    		pstack\n\    		gsave\n\    			dup type /stringtype eq\n\    			{ externalhandler }\n\    			{ dup type /arraytype eq\n\    				{ initmat setmatrix setmat 0 get lookuptarget { 0 get filestr (.html) conc } if exch link }\n\    				{ dup userdict exch known\n\    					{ cvx exec }\n\    					{ (Unknown mark ) print 20 string cvs print (\\n) print cleartomark }\n\    					ifelse }\n\    				ifelse }\n\    			ifelse\n\    		grestore\n\    	} def\n\    end\n\    %%%%EndProcSet\n");    }    else std::fprintf(filed,"%%%%EndComments\n");    int c; while ((c=std::fgetc(files))!=EOF) std::fputc(c,filed);    std::fclose(files); std::fclose(filed);    double resx = ((double)height/(210.0/25.4));    double resy = ((double)width/(297/25.4));    if (!cimg::strcasecmp(ext,"pdf")) { const double tmp=resx; resx=resy; resy=tmp; }    if (!cimg::strcasecmp(format_o,"png"))      std::sprintf(str,"%s -q -dBATCH -dNOPAUSE -sPAPERSIZE=a4 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r%gx%g -sDEVICE=png16m -sOutputFile=%s pslider_auto/tmp.ps",cimg_OS!=2?"gs":"C:\\gs\\gs8.13\\bin\\gswin32c.exe",resx,resy,slideformat);    else std::sprintf(str,"%s -q -dBATCH -dNOPAUSE -sPAPERSIZE=a4 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -r%gx%g -sDEVICE=ppm -sOutputFile=%s pslider_auto/tmp.ps",cimg_OS!=2?"gs":"C:\\gs\\gs8.13\\bin\\gswin32c.exe",resx,resy,slideformat);    std::system(str); std::fprintf(stderr,"OK\n");    std::fprintf(stderr,"   > Converting images and creating thumbnails :\n");    while (!stopflag) {      std::sprintf(str,slideformat,nop+1);      file = std::fopen(str,"rb");      if (file) {	std::fprintf(stderr,"[%d]",nop+1); std::fflush(stderr);	slide = CImg<unsigned char>(str);	owidth = slide.dimx(); oheight = slide.dimy();	if (!cimg::strncmp(ext,"ps",3)) { slide.rotate(90); }	thumb = slide.get_resize(twidth,theight,1,3,3);	if (orient) { thumb.rotate(180); slide.rotate(180); }	slide.save(str);	std::sprintf(str,thumbformat,nop+1);	thumb.save(str);	std::fclose(file);	nop++;      } else stopflag=1;    }#if cimg_OS==1    std::system("rm -f pslider_auto/tmp.ps pslider_auto/destinations; echo \"\">pslider_auto/.pslider");#else    std::system("del /q /s pslider_auto\\tmp.ps pslider_auto\\destinations");    std::system("echo \"\">pslider_auto\\.pslider");#endif    std::fprintf(stderr," OK\n");    std::fprintf(stderr,"\n** The presentation has been generated, please type 'pslider' again to launch it. **\n\n");    std::exit(0);#endif    break;  }  // Check number of pages and original geometry of the presentation  std::fprintf(stderr," - Geometry of the original presentation ...."); std::fflush(stderr);  stopflag=nop=0;  while (!stopflag) {    std::sprintf(str,slideformat,nop+1); file = std::fopen(str,"rb"); if (file!=NULL) {      nop++; std::fclose(file);    }    else stopflag=1;  }  std::sprintf(str,slideformat,1);  slide = CImg<unsigned char>(str);  owidth = slide.dimx(); oheight = slide.dimy();  std::fprintf(stderr,"%d slides %dx%d\n",nop,owidth,oheight);  // Load Thumbnails (and optionally slides)  std::fprintf(stderr," - Loading Thumbnails ('%s' format)... ",cimg::filename_split(thumbformat)); std::fflush(stderr);  {    for (unsigned int i=0; i<nop; i++) {      std::fprintf(stderr,"[%d]",i+1); std::fflush(stderr);      std::sprintf(str,thumbformat,i+1);      thumb = CImg<unsigned char>(str);      thumbs.insert(thumb.get_resize(twidth,theight,1,3,3));      if (orient) thumbs[i].rotate(180);    }  }  std::fprintf(stderr," OK\n");  // Load links  std::fprintf(stderr," - Loading Links ... "); std::fflush(stderr);  std::fprintf(stderr,"%d links\n",nol=load_Links(Link_filename,Links));  // Load Mimetypes  nom = 0;  if (nol) {    std::fprintf(stderr," - Loading mimetypes ... "); std::fflush(stderr);#if cimg_OS==1    std::sprintf(mimes[nom].ext,"mpg");  std::sprintf(mimes[nom++].command,"mplayer -loop 0");    std::sprintf(mimes[nom].ext,"mpeg"); std::sprintf(mimes[nom++].command,"mplayer -loop 0");    std::sprintf(mimes[nom].ext,"avi");  std::sprintf(mimes[nom++].command,"mplayer -loop 0");    std::sprintf(mimes[nom].ext,"png");  std::sprintf(mimes[nom++].command,"display");    std::sprintf(mimes[nom].ext,"jpg");  std::sprintf(mimes[nom++].command,"display");    std::sprintf(mimes[nom].ext,"ppm");  std::sprintf(mimes[nom++].command,"display");    std::sprintf(mimes[nom].ext,"inr");  std::sprintf(mimes[nom++].command,"inrcast");    std::sprintf(mimes[nom].ext,"htm");  std::sprintf(mimes[nom++].command,"firefox");    std::sprintf(mimes[nom].ext,"html"); std::sprintf(mimes[nom++].command,"firefox");    std::sprintf(mimes[nom].ext,"pdf");  std::sprintf(mimes[nom++].command,"acroread");#else    std::sprintf(mimes[nom].ext,"mpg");  std::sprintf(mimes[nom++].command,"\"C:\\Program Files\\Windows Media Player\\mplayer2.exe\"");    std::sprintf(mimes[nom].ext,"mpeg"); std::sprintf(mimes[nom++].command,"\"C:\\Program Files\\Windows Media Player\\mplayer2.exe\"");    std::sprintf(mimes[nom].ext,"avi");  std::sprintf(mimes[nom++].command,"\"C:\\Program Files\\Windows Media Player\\mplayer2.exe\"");    std::sprintf(mimes[nom].ext,"png");  std::sprintf(mimes[nom++].command,"\"C:\\Program Files\\IrfanView\\i_view32.exe\"");    std::sprintf(mimes[nom].ext,"jpg");  std::sprintf(mimes[nom++].command,"\"C:\\Program Files\\IrfanView\\i_view32.exe\"");    std::sprintf(mimes[nom].ext,"ppm");  std::sprintf(mimes[nom++].command,"\"C:\\Program Files\\IrfanView\\i_view32.exe\"");    std::sprintf(mimes[nom].ext,"htm");  std::sprintf(mimes[nom++].command,"\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"");    std::sprintf(mimes[nom].ext,"html"); std::sprintf(mimes[nom++].command,"\"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE\"");#endif    file = std::fopen(mimefilename,"r");    if (file) {               // add user specified mimetypes      std::fprintf(stderr,"from file '%s' :",mimefilename); std::fflush(stderr);      mime mi;      while (fscanf(file,"%[^ =]%*[ =]%[ -}] ",mi.ext,mi.command)==2) {        std::fprintf(stderr," '%s'",mi.ext); std::fflush(stderr);        for (itmp=0; itmp<nom; itmp++) if (!cimg::strcasecmp(mi.ext,mimes[itmp].ext)) { strcpy(mimes[itmp].command,mi.command); itmp=nom+1; }        if (itmp==nom) { strcpy(mimes[nom].command,mi.command); strcpy(mimes[nom++].ext,mi.ext); }      }      std::fclose(file);      std::fprintf(stderr,"\n");    } else std::fprintf(stderr,"no file '%s' found, default used\n",mimefilename);  }  /*-----------------------------------  Begin User Interaction  ---------------------------------*/  old_slide = nop;  current_slide = 0;  update_flag = 1;  unsigned int time0 = (unsigned int)time(NULL);  bool links_done = false;  while (!disp || (!disp->is_closed && ckey!=cimg::keyQ)) {    if (!disp) {      disp = new CImgDisplay(CImg<unsigned char>(width,height).fill(0),"PSlider",0,2,fullscreen,true);      disp->move(0,0);    }    else { if (!dispthumb && !disp->key && !disp->button && autorun<0) disp->wait(); }    if (disp->key) { ckey=disp->key; disp->key=0; }    else ckey=0;    // Go the next slide    if (ckey==cimg::keyARROWRIGHT || ckey==cimg::keySPACE || ckey==cimg::keyN || ckey==cimg::keyPAGEDOWN || ckey==cimg::keyENTER	|| (disp->mouse_x>=(int)disp->width-8 && disp->button&1) || (autorun>=0 && (unsigned int)time(NULL)>time0+autorun)) {      current_slide=(current_slide+1)%nop;      update_flag=1;      disp->button&=~1;      time0 = (unsigned int)time(NULL);      links_done = false;      if (dautorun>=0 && autorun>=0) {	autorun = nautorun;	nautorun = dautorun;      }    }    // Go to previous slide    if (ckey==cimg::keyARROWLEFT || ckey==cimg::keyB || ckey==cimg::keyPAGEUP || ckey==cimg::keyBACKSPACE || (disp->mouse_x<=8 && disp->button&1)) {      current_slide=(current_slide+nop-1)%nop;      update_flag = 1;      disp->button&=~1;    }    // Go to first or last slide    if (ckey==cimg::keyHOME)  { current_slide=0;     update_flag=1; }    if (ckey==cimg::keyEND)   { current_slide=nop-1; update_flag=1; }    // Swap Landscape orientation    if (ckey==cimg::keyARROWDOWN) {      for (i=0; i<nop; i++) thumbs[i].rotate(180);      orient=!orient;      lorient=!lorient;      update_flag=1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -