?? pslider.cpp
字號(hào):
/*--------------------------------------------------------------- File : pslider.cpp Description : Tool for doing presentation from PS files Copyright : David Tschumperle - http://www.greyc.ensicaen.fr/~dtschump/ This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info". As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its terms.------------------------------------------------------------*/#include "../CImg.h"using namespace cimg_library;// The undef below is necessary when using a non-standard compiler.#ifdef cimg_use_visualcpp6#define std#endifunsigned int width,height,owidth,oheight;struct mime { char ext[16]; char command[256];};struct Link { unsigned int page,xmin,xmax,ymin,ymax; char url[256];};unsigned int load_Links(const char *Link_filename,Link *Links){ std::FILE *file = std::fopen(Link_filename,"r"); unsigned int nol=0,p,x0,y0,w,h; if (file) { while (std::fscanf(file,"%u \"%[^\"]\" %u %u %u %u",&p,Links[nol].url,&x0,&y0,&h,&w)==6) { Links[nol].page=p-1; Links[nol].xmin=x0; Links[nol].xmax=x0+w; Links[nol].ymin=oheight-y0-h; Links[nol++].ymax=oheight-y0; } std::fclose(file); } return nol;}void save_Links(Link *Links,const unsigned int nol,const char *Link_filename){ std::FILE *file = cimg::fopen(Link_filename,"w"); if (!file) throw CImgException("Cannot open file '%s' for writing"); for (unsigned int i=0; i<nol; i++) { Link l = Links[i]; std::fprintf(file,"%d \"%s\" %d %d %d %d\n",l.page+1,l.url,l.xmin,oheight-l.ymax,l.ymax-l.ymin,l.xmax-l.xmin); } std::fclose(file);}/*----------------------------------- Main procedure-----------------------------------*/int main(int argc,char **argv){ unsigned int ckey=0,stopflag,nop,nol,nom,current_slide,old_slide,update_flag,twidth,theight,slide_type,itmp,i; int mouse_x,mouse_y,ooverLink=-1,overLink=-1; int xmin,xmax,ymin,ymax; char slideformat[1024],thumbformat[1024],Link_filename[1024]; double gamma=1; const char *ext; mime mimes[100]; CImg<unsigned char> slide,nslide,vslide,thumb,menu,layer,menuthumb; CImgList<unsigned char> thumbs; unsigned char yellow[3]= { 255,255,0 }, white[3]= { 255,255,255 }, green[3]= { 100,255,100 }, gray[3]= { 150,150,150 }, black[3]= { 0,0,0 }; CImgDisplay *disp=NULL,*dispthumb=NULL; Link Links[1024]; std::FILE *file; char c; /*------------------------------------ PSlider Initialization Part ----------------------------------*/ // Read str line parameters // Display usage char str[1024]; std::sprintf(str,"Tool for generating and displaying presentations from PS or PS2HTML files\n\n"); std::sprintf(str+std::strlen(str)," When the window is opened, you can press the key 'H' to open the help menu.\n"); std::sprintf(str+std::strlen(str)," Additional command line parameters are :"); cimg_usage(str); // Read command line parameters const char *file_i = cimg_option("-i",(char*)NULL,"Input PS or PDF file"); const char *format_o = cimg_option("-o","png","Output image format ('png' or 'ppm')"); const char *geometry = cimg_option("-g","full","Window geometry ('wxh', or 'full')"); const char *tgeometry = cimg_option("-t","128x96","Thumbnail size (wxh)"); const char *mimefilename = cimg_option("-m","pslider.mime","Specify file of mime types"); bool orient = cimg_option("-invert",true,"Invert landscape orientation"); bool lorient = cimg_option("-linvert",false,"Invert links orientation"); bool noLink = cimg_option("-nolink",false,"Don't display link contours"); bool fullscreen = cimg_option("-full",false,"Start in Fullscreen mode"); int dautorun = cimg_option("-autorun",-1,"If >0, determine a time step (in seconds) that is used for an automatic slideshow"); int nautolink=-1, autorun=dautorun, nautorun=autorun; width = CImgDisplay::screen_dimx(); height = CImgDisplay::screen_dimy(); twidth = 128; theight = 96; std::sscanf(geometry,"%ux%u",&width,&height); std::sscanf(tgeometry,"%ux%u",&twidth,&theight); if (cimg_option("-h",false,"Display this help page")) std::exit(0); else std::fprintf(stderr,"\n*** PSlider ***\n"); std::fprintf(stderr,"\n - Input geometry : slides=%dx%d, thumbnails=%dx%d\n",width,height,twidth,theight); // Try to open an existing presentation slide_type = 0; std::fprintf(stderr," - Looking for a PS2HTML presentation in current dir ..... "); std::fflush(stderr); if ((file=std::fopen("ps2html_auto/0001.html","r"))!=NULL) { std::fclose(file); std::fprintf(stderr, "YES\n"); slide_type = 1; } else std::fprintf(stderr,"NO\n"); std::fprintf(stderr," - Looking for a PSlider presentation in current dir ..... "); std::fflush(stderr); if ((file=std::fopen("pslider_auto/.pslider","r"))!=NULL) { std::fclose(file); std::fprintf(stderr,"YES\n"); slide_type = 2; } else std::fprintf(stderr,"NO\n"); if (file_i) { if (cimg::strcasecmp(cimg::filename_split(file_i),"ps") && cimg::strcasecmp(cimg::filename_split(file_i),"pdf")) throw CImgException("You have to specify a PS or PDF file as input file. You specified '%s' as the filename",file_i); std::FILE *test_file = cimg::fopen(file_i,"r"); cimg::fclose(test_file); switch (slide_type) { case 1: cimg::warn(1,"An existing PSHTML presentation has been found.\n Do you really want to create a PSlider one ? [Y]/[N} ..."); break; case 2: cimg::warn(1,"An existing PSlider presentation has been found.\n Do you really want to overwrite it ? [Y]/[N] ..."); break; default: break; } if (slide_type) { c = getc(stdin); if (cimg::uncase(c)=='y') slide_type=0; else file_i=0; } } if (!slide_type && !file_i) throw CImgException("No existing presentations have been found, you must generate one (option '-i')"); // Init presentation (if necessary) and image paths switch (slide_type) { case 2: ext = NULL; if (!ext) { file = std::fopen("pslider_auto/slide_1.ppm","r"); if (file) { ext = "ppm"; std::fclose(file); } } if (!ext) { file = std::fopen("pslider_auto/slide_1.PPM","r"); if (file) { ext = "PPM"; std::fclose(file); } } if (!ext) { file = std::fopen("pslider_auto/slide_1.gif","r"); if (file) { ext = "gif"; std::fclose(file); } } if (!ext) { file = std::fopen("pslider_auto/slide_1.GIF","r"); if (file) { ext = "GIF"; std::fclose(file); } } if (!ext) { file = std::fopen("pslider_auto/slide_1.jpg","r"); if (file) { ext = "jpg"; std::fclose(file); } } if (!ext) { file = std::fopen("pslider_auto/slide_1.JPG","r"); if (file) { ext = "JPG"; std::fclose(file); } } if (!ext) { file = std::fopen("pslider_auto/slide_1.png","r"); if (file) { ext = "png"; std::fclose(file); } } if (!ext) { file = std::fopen("pslider_auto/slide_1.PNG","r"); if (file) { ext = "PNG"; std::fclose(file); } } if (!ext) throw CImgException("I cannot recognize slide format, in directory 'pslider_auto'"); std::sprintf(slideformat,"pslider_auto/slide_%%d.%s",ext); ext = NULL; if (!ext) { file = std::fopen("pslider_auto/thumb_1.ppm","r"); if (file) { ext = "ppm"; std::fclose(file); } } if (!ext) { file = std::fopen("pslider_auto/thumb_1.PPM","r"); if (file) { ext = "PPM"; std::fclose(file); } } if (!ext) { file = std::fopen("pslider_auto/thumb_1.gif","r"); if (file) { ext = "gif"; std::fclose(file); } } if (!ext) { file = std::fopen("pslider_auto/thumb_1.GIF","r"); if (file) { ext = "GIF"; std::fclose(file); } } if (!ext) { file = std::fopen("pslider_auto/thumb_1.jpg","r"); if (file) { ext = "jpg"; std::fclose(file); } } if (!ext) { file = std::fopen("pslider_auto/thumb_1.JPG","r"); if (file) { ext = "JPG"; std::fclose(file); } } if (!ext) { file = std::fopen("pslider_auto/thumb_1.png","r"); if (file) { ext = "png"; std::fclose(file); } } if (!ext) { file = std::fopen("pslider_auto/thumb_1.PNG","r"); if (file) { ext = "PNG"; std::fclose(file); } } if (!ext) throw CImgException("I cannot recognize thumbnails format, in directory 'pslider_auto'"); std::sprintf(thumbformat,"pslider_auto/thumb_%%d.%s",ext); std::sprintf(Link_filename,"pslider_auto/links"); break; case 1: ext = NULL; if (!ext) { file = std::fopen("ps2html_auto/0001.ppm","r"); if (file) { ext = "ppm"; std::fclose(file); } } if (!ext) { file = std::fopen("ps2html_auto/0001.PPM","r"); if (file) { ext = "PPM"; std::fclose(file); } } if (!ext) { file = std::fopen("ps2html_auto/0001.gif","r"); if (file) { ext = "gif"; std::fclose(file); } } if (!ext) { file = std::fopen("ps2html_auto/0001.GIF","r"); if (file) { ext = "GIF"; std::fclose(file); } } if (!ext) { file = std::fopen("ps2html_auto/0001.jpg","r"); if (file) { ext = "jpg"; std::fclose(file); } } if (!ext) { file = std::fopen("ps2html_auto/0001.JPG","r"); if (file) { ext = "JPG"; std::fclose(file); } } if (!ext) { file = std::fopen("ps2html_auto/0001.png","r"); if (file) { ext = "png"; std::fclose(file); } } if (!ext) { file = std::fopen("ps2html_auto/0001.PNG","r"); if (file) { ext = "PNG"; std::fclose(file); } } if (!ext) throw CImgException("I cannot recognize slide format, in directory 'ps2html_auto'"); std::sprintf(slideformat,"ps2html_auto/%%.4d.%s",ext); ext = NULL; if (!ext) { file = std::fopen("ps2html_auto/mosaic0001.ppm","r"); if (file) { ext = "ppm"; std::fclose(file); } } if (!ext) { file = std::fopen("ps2html_auto/mosaic0001.PPM","r"); if (file) { ext = "PPM"; std::fclose(file); } } if (!ext) { file = std::fopen("ps2html_auto/mosaic0001.gif","r"); if (file) { ext = "gif"; std::fclose(file); } } if (!ext) { file = std::fopen("ps2html_auto/mosaic0001.GIF","r"); if (file) {
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -