/* $OpenXM: OpenXM_contrib2/asir2018/plot/smoothing.c,v 1.1 2018/09/19 05:45:08 noro Exp $ */ #include #include #include #include "ca.h" #include "parse.h" #include "ox.h" #include "ifplot.h" #include "cursor.h" #define MAG 1 #define PRINT_XOFFSET 100 #define PRINT_YOFFSET 100 #define DPI 300 static FILE *Fp = NULL; static void PSProlog(int, int, int, int); static void PSDashedLine(int, int, int, int); static void polyLine_outputPS_dashed_line(int x0,int y0,int x1,int y1); void PSFromImage(FILE *fp,XImage *image,struct canvas *can); static int Strategy_generate_PS = 0; void PSFromImage(FILE *fp,XImage *image,struct canvas *can) { int x, y, ir, ig, ib; float r, g, b; int srcc, trg,grux, gruy, ix, iy; float xwd, ywd, t; Fp = fp; srcc = 0xffffff; PSProlog(0,0,can->width,can->height); for(y=0;y< can->height;y++) for(x=0;x < can->width; x++){ trg = XGetPixel(image,x,y) & 0xffffff; if ( trg != 0xffffff ){ if ( trg != srcc ){ srcc = trg; r = ir = (srcc >>16) & 0xff; r = r/256; g = ig = (srcc >> 8) & 0xff; g = g/256; b = ib = (srcc) & 0xff; b = b/256; if(ir == 0 && ig ==0 && ib == 0) fprintf(Fp,"0 0 0 C\n"); else fprintf(Fp,"%f %f %f C\n",r,g,b); } fprintf(Fp,"%d %d R\n", x,can->height - y); } } fprintf(Fp,"0 0 0 C\n"); if ( can->noaxis == 0 ){ grux = ceil(can->xmax); xwd = can->width/(can->xmax - can->xmin); for(ix=ceil(can->xmin); ix < grux; ix++){ t = ix; x = (t - can->xmin) * xwd; PSDashedLine(x, 0, x, can->height); } gruy = ceil(can->ymax); ywd = can->height/(can->ymax - can->ymin); for(iy=can->ymin; iy < gruy; iy++){ t = iy; y = (t - can->ymin ) * ywd; PSDashedLine(0, y, can->width, y); } } fprintf(Fp,"[] 0 setdash 0 0 moveto "); fprintf(Fp,"%d 0 lineto %d %d lineto 0 %d lineto closepath stroke\n", can->width, can->width, can->height, can->height); fprintf(Fp,"showpage grestore\n"); fflush(Fp); } static void PSProlog(int xmin, int ymin,int xmax, int ymax) { int width, height; struct tm *systime; time_t t; t = time(NULL); systime = localtime(&t); width = 72*(xmax - xmin-1)/300; height = 72*(ymax - ymin-1)/300; fprintf(Fp,"%%!PS-Adobe-2.0 EPSF-2.0\n"); fprintf(Fp,"%%%%BoundingBox: -3 -2 %d %d \n", width*MAG+3, height*MAG+3); fprintf(Fp,"%%%%Creator: This is generated by ifplot\n"); fprintf(Fp,"%%%%Title: ifplot\n"); fprintf(Fp,"%%%%CreationDate: %.4d-%.2d-%.2d\n", systime->tm_year+1900,systime->tm_mon+1,systime->tm_mday); fprintf(Fp,"%%%%Pages: 0\n"); fprintf(Fp,"%%%%EndComments: \n"); fprintf(Fp,"%%%%EndProlog\n%%%%Page: one 1\n%%!\n"); fprintf(Fp,"/dpi %d def\n", DPI); fprintf(Fp,"/SCALE 72 dpi div def\n"); fprintf(Fp,"/R {moveto 1 0 rlineto 0 1 rlineto -1 0 rlineto closepath"); fprintf(Fp," fill} bind def\n"); fprintf(Fp,"/C {setrgbcolor} bind def\n"); fprintf(Fp,"gsave newpath\n"); fprintf(Fp,"0 0 moveto SCALE SCALE scale 1 setlinewidth\n"); fflush(Fp); } static void PSDashedLine(int x0,int y0,int x1,int y1) { extern FILE *Fp; fprintf(Fp,"0.1 setlinewidth [3 3] 0 setdash\n"); fprintf(Fp," %d %d moveto %d %d lineto stroke \n",x0,y0,x1,y1); }