Annotation of OpenXM_contrib2/asir2000/plot/smoothing.c, Revision 1.10
1.10 ! noro 1: /* $OpenXM: OpenXM_contrib2/asir2000/plot/smoothing.c,v 1.9 2007/01/25 16:19:41 saito Exp $ */
1.9 saito 2: #include <stdio.h>
3: #include <time.h>
4: #include <math.h>
1.1 takayama 5: #include "ca.h"
6: #include "parse.h"
7: #include "ox.h"
8: #include "ifplot.h"
9: #include "cursor.h"
10:
11: #define MAG 1
12: #define PRINT_XOFFSET 100
13: #define PRINT_YOFFSET 100
1.9 saito 14: #define DPI 300
1.1 takayama 15:
16: static FILE *Fp = NULL;
1.9 saito 17: static void PSProlog(int, int, int, int);
18: static void PSDashedLine(int, int, int, int);
19: static void polyLine_outputPS_dashed_line(int x0,int y0,int x1,int y1);
1.10 ! noro 20: void PSFromImage(FILE *fp,XImage *image,struct canvas *can);
1.1 takayama 21:
1.9 saito 22: static int Strategy_generate_PS = 0;
1.1 takayama 23:
1.10 ! noro 24: void PSFromImage(FILE *fp,XImage *image,struct canvas *can) {
1.9 saito 25: int x, y, ir, ig, ib;
26: float r, g, b;
27: int srcc, trg,grux, gruy, ix, iy;
28: float xwd, ywd, t;
1.2 takayama 29:
1.9 saito 30: Fp = fp;
31: srcc = 0xffffff;
32: PSProlog(0,0,can->width,can->height);
33: for(y=0;y< can->height;y++)
34: for(x=0;x < can->width; x++){
35: trg = XGetPixel(image,x,y) & 0xffffff;
36: if ( trg != 0xffffff ){
37: if ( trg != srcc ){
38: srcc = trg;
39: r = ir = (srcc >>16) & 0xff;
40: r = r/256;
41: g = ig = (srcc >> 8) & 0xff;
42: g = g/256;
43: b = ib = (srcc) & 0xff;
44: b = b/256;
45: if(ir == 0 && ig ==0 && ib == 0)
46: fprintf(Fp,"0 0 0 C\n");
47: else
48: fprintf(Fp,"%f %f %f C\n",r,g,b);
49: }
50: fprintf(Fp,"%d %d R\n", x,can->height - y);
51: }
52: }
53: fprintf(Fp,"0 0 0 C\n");
54: if ( can->noaxis == 0 ){
55: grux = ceil(can->xmax);
56: xwd = can->width/(can->xmax - can->xmin);
57: for(ix=ceil(can->xmin); ix < grux; ix++){
58: t = ix;
59: x = (t - can->xmin) * xwd;
60: PSDashedLine(x, 0, x, can->height);
61: }
62: gruy = ceil(can->ymax);
63: ywd = can->height/(can->ymax - can->ymin);
64: for(iy=can->ymin; iy < gruy; iy++){
65: t = iy;
66: y = (t - can->ymin ) * ywd;
67: PSDashedLine(0, y, can->width, y);
68: }
69: }
70: fprintf(Fp,"[] 0 setdash 0 0 moveto ");
71: fprintf(Fp,"%d 0 lineto %d %d lineto 0 %d lineto closepath stroke\n",
72: can->width, can->width, can->height, can->height);
73: fprintf(Fp,"showpage grestore\n");
74: fflush(Fp);
75: }
1.1 takayama 76:
1.9 saito 77: static void PSProlog(int xmin, int ymin,int xmax, int ymax) {
78: int width, height;
79: struct tm *systime;
80: time_t t;
81:
82: t = time(NULL);
83: systime = localtime(&t);
84: width = 72*(xmax - xmin-1)/300;
85: height = 72*(ymax - ymin-1)/300;
86: fprintf(Fp,"%%!PS-Adobe-2.0 EPSF-2.0\n");
87: fprintf(Fp,"%%%%BoundingBox: -3 -2 %d %d \n", width*MAG+3, height*MAG+3);
1.1 takayama 88: fprintf(Fp,"%%%%Creator: This is generated by ifplot\n");
89: fprintf(Fp,"%%%%Title: ifplot\n");
1.9 saito 90: fprintf(Fp,"%%%%CreationDate: %.4d-%.2d-%.2d\n",
91: systime->tm_year+1900,systime->tm_mon+1,systime->tm_mday);
92: fprintf(Fp,"%%%%Pages: 0\n");
1.1 takayama 93: fprintf(Fp,"%%%%EndComments: \n");
1.9 saito 94: fprintf(Fp,"%%%%EndProlog\n%%%%Page: one 1\n%%!\n");
95: fprintf(Fp,"/dpi %d def\n", DPI);
96: fprintf(Fp,"/SCALE 72 dpi div def\n");
97: fprintf(Fp,"/R {moveto 1 0 rlineto 0 1 rlineto -1 0 rlineto closepath");
98: fprintf(Fp," fill} bind def\n");
99: fprintf(Fp,"/C {setrgbcolor} bind def\n");
100: fprintf(Fp,"gsave newpath\n");
101: fprintf(Fp,"0 0 moveto SCALE SCALE scale 1 setlinewidth\n");
1.1 takayama 102: fflush(Fp);
103: }
104:
1.9 saito 105: static void PSDashedLine(int x0,int y0,int x1,int y1) {
1.2 takayama 106: extern FILE *Fp;
1.9 saito 107: fprintf(Fp,"0.1 setlinewidth [3 3] 0 setdash\n");
1.2 takayama 108: fprintf(Fp," %d %d moveto %d %d lineto stroke \n",x0,y0,x1,y1);
1.1 takayama 109: }
1.6 takayama 110:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>