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