Subversion Repositories wimsdev

Rev

Rev 11132 | Rev 16344 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11132 Rev 12473
Line 20... Line 20...
20
 
20
 
21
/* bug in gdImageFillToBorder */
21
/* bug in gdImageFillToBorder */
22
 
22
 
23
void patchgdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color)
23
void patchgdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color)
24
{
24
{
25
   if(x>=im->sx || x<0 || y>=im->sy || y<0) return;
25
  if(x>=im->sx || x<0 || y>=im->sy || y<0) return;
26
   gdImageFillToBorder(im,x,y,border,color);
26
  gdImageFillToBorder(im,x,y,border,color);
27
}
27
}
28
 
28
 
29
void patchgdImageFill (gdImagePtr im, int x, int y, int color)
29
void patchgdImageFill (gdImagePtr im, int x, int y, int color)
30
{
30
{
31
   if(x>=im->sx || x<0 || y>=im->sy || y<0) return;
31
  if(x>=im->sx || x<0 || y>=im->sy || y<0) return;
32
   gdImageFill(im,x,y,color);
32
  gdImageFill(im,x,y,color);
33
}
33
}
34
 
34
 
35
 
35
 
36
#define DASHPIXELS 8
36
#define DASHPIXELS 8
37
 
37
 
Line 52... Line 52...
52
 
52
 
53
 
53
 
54
/* File opening: with security */
54
/* File opening: with security */
55
FILE *open4read(char *n)
55
FILE *open4read(char *n)
56
{
56
{
57
    char *p, *p1, *p2, namebuf[2048];
57
  char *p, *p1, *p2, namebuf[2048];
58
    int t;
58
  int t;
59
    FILE *f;
59
  FILE *f;
60
    n=find_word_start(n);
60
  n=find_word_start(n);
61
    if(*n==0) return NULL;
61
  if(*n==0) return NULL;
62
    p=getenv("flydraw_filebase");
62
  p=getenv("flydraw_filebase");
63
    p1=n+strlen(n)-4;if(p1<n || strcasecmp(p1,".gif")!=0) t=1; else t=0;
63
  p1=n+strlen(n)-4;if(p1<n || strcasecmp(p1,".gif")!=0) t=1; else t=0;
64
    if(p!=NULL && *p!=0) {
64
  if(p!=NULL && *p!=0) {
65
      char pbuf[MAX_LINELEN+1];
65
    char pbuf[MAX_LINELEN+1];
66
      snprintf(pbuf,sizeof(pbuf),"%s",p);
66
    snprintf(pbuf,sizeof(pbuf),"%s",p);
67
      p=find_word_start(pbuf); if(strstr(p,"..")!=NULL) return NULL;
67
    p=find_word_start(pbuf); if(strstr(p,"..")!=NULL) return NULL;
68
      if(*n=='/' || strstr(n,"..")!=NULL) return NULL;
68
    if(*n=='/' || strstr(n,"..")!=NULL) return NULL;
69
/* prohibit unusual file/dir names */
69
    /* prohibit unusual file/dir names */
70
      for(p1=p;*p1;p1++)
70
    for(p1=p;*p1;p1++)
71
        if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL)
71
      if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL)
72
          return NULL;
72
        return NULL;
73
      for(p1=n;*p1;p1++)
73
    for(p1=n;*p1;p1++)
74
        if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL)
74
      if(!isalnum(*p1) && !isspace(*p1) && strchr("~_-/.",*p1)==NULL)
75
          return NULL;
75
        return NULL;
76
      f=NULL;
76
    f=NULL;
77
      for(p1=p; *p1; p1=find_word_start(p2)) {
77
    for(p1=p; *p1; p1=find_word_start(p2)) {
78
          p2=find_word_end(p1);
78
      p2=find_word_end(p1);
79
          if(*p2) *p2++=0;
79
      if(*p2) *p2++=0;
80
          snprintf(namebuf,sizeof(namebuf),"%s/%s",p1,n);
80
      snprintf(namebuf,sizeof(namebuf),"%s/%s",p1,n);
81
          f=fopen(namebuf,"r"); if(f!=NULL) goto imgtype;
81
      f=fopen(namebuf,"r"); if(f!=NULL) goto imgtype;
82
      }
82
    }
83
      p1=getenv("w_wims_session");
83
    p1=getenv("w_wims_session");
84
      if(p1!=NULL && strncmp(n,"insert",6)==0) {
84
    if(p1!=NULL && strncmp(n,"insert",6)==0) {
85
          snprintf(namebuf,sizeof(namebuf),"../s2/%s/%s",p1,n);
85
      snprintf(namebuf,sizeof(namebuf),"../s2/%s/%s",p1,n);
86
          f=fopen(namebuf,"r");
-
 
87
      }
-
 
88
    }
-
 
89
    else {
-
 
90
      snprintf(namebuf,sizeof(namebuf),"%s",n);
-
 
91
      f=fopen(namebuf,"r");
86
      f=fopen(namebuf,"r");
92
    }
87
    }
-
 
88
  }
-
 
89
  else {
-
 
90
    snprintf(namebuf,sizeof(namebuf),"%s",n);
-
 
91
    f=fopen(namebuf,"r");
-
 
92
  }
93
    imgtype:
93
  imgtype:
94
    if(t && f!=NULL) {
94
  if(t && f!=NULL) {
95
      char tbuf[1024],sbuf[4096];
95
    char tbuf[1024],sbuf[4096];
96
      fclose(f); f=NULL;
96
    fclose(f); f=NULL;
97
      p1=getenv("TMPDIR"); if(p1==NULL || *p1==0) p1=".";
97
    p1=getenv("TMPDIR"); if(p1==NULL || *p1==0) p1=".";
98
      snprintf(tbuf,sizeof(tbuf),"%s/drawfile_.gif",p1);
98
    snprintf(tbuf,sizeof(tbuf),"%s/drawfile_.gif",p1);
99
      snprintf(sbuf,sizeof(sbuf),"convert %s %s",namebuf,tbuf);
99
    snprintf(sbuf,sizeof(sbuf),"convert %s %s",namebuf,tbuf);
100
      if (system(sbuf)) fly_error("system_failed");
100
    if (system(sbuf)) fly_error("system_failed");
101
        f=fopen(tbuf,"r");
101
      f=fopen(tbuf,"r");
102
    }
102
  }
103
    return f;
103
  return f;
104
}
104
}
105
 
105
 
106
/* Does nothing; just a comment. */
106
/* Does nothing; just a comment. */
107
void obj_comment(objparm *pm)
107
void obj_comment(objparm *pm)
108
{
108
{
109
    return;
109
  return;
110
}
110
}
111
 
111
 
112
/* define image size */
112
/* define image size */
113
void obj_size(objparm *pm)
113
void obj_size(objparm *pm)
114
{
114
{
115
    sizex=rint(pm->pd[0]); sizey=rint(pm->pd[1]);
115
  sizex=rint(pm->pd[0]); sizey=rint(pm->pd[1]);
116
    if(sizex<0 || sizey<0 || sizex>MAX_SIZE || sizey>MAX_SIZE) {
116
  if(sizex<0 || sizey<0 || sizex>MAX_SIZE || sizey>MAX_SIZE) {
117
      fly_error("bad_size"); return;
117
    fly_error("bad_size"); return;
118
    }
118
  }
119
    if(image!=NULL) {
119
  if(image!=NULL) {
120
      fly_error("size_already_defined"); return;
120
    fly_error("size_already_defined"); return;
121
    }
121
  }
122
    image=gdImageCreate(sizex,sizey);
122
  image=gdImageCreate(sizex,sizey);
123
    if(image==NULL) fly_error("image_creation_failure");
123
  if(image==NULL) fly_error("image_creation_failure");
124
    else {
124
  else {
125
      color_white=gdImageColorAllocate(image,255,255,255);
125
    color_white=gdImageColorAllocate(image,255,255,255);
126
      color_black=gdImageColorAllocate(image,0,0,0);
126
    color_black=gdImageColorAllocate(image,0,0,0);
127
      color_bounder=gdImageColorAllocate(image,1,2,3);
127
    color_bounder=gdImageColorAllocate(image,1,2,3);
128
      color_frame=gdImageColorAllocate(image,254,254,254);
128
    color_frame=gdImageColorAllocate(image,254,254,254);
129
    }
129
  }
130
}
130
}
131
 
131
 
132
/* new image */
132
/* new image */
133
void obj_new(objparm *pm)
133
void obj_new(objparm *pm)
134
{
134
{
135
    if(image) {
135
  if(image) {
136
      gdImageDestroy(image);image=NULL;
136
    gdImageDestroy(image);image=NULL;
137
    }
137
  }
138
    if(pm->pcnt>=2) { obj_size(pm); gdImageRectangle(image,0,0,sizex-1,sizey-1,color_frame);}
138
  if(pm->pcnt>=2) { obj_size(pm); gdImageRectangle(image,0,0,sizex-1,sizey-1,color_frame);}
139
    else sizex=sizey=0;
139
  else sizex=sizey=0;
140
    saved=0;
140
  saved=0;
141
}
141
}
142
 
142
 
143
/* new image */
143
/* new image */
144
void obj_existing(objparm *pm)
144
void obj_existing(objparm *pm)
145
{
145
{
146
    FILE *inf;
146
  FILE *inf;
147
    char *pp;
147
  char *pp;
148
 
148
 
149
    if(image) {
149
  if(image) {
150
      gdImageDestroy(image);image=NULL;
150
    gdImageDestroy(image);image=NULL;
151
    }
151
  }
152
    pp=find_word_start(pm->str);*find_word_end(pp)=0;
152
  pp=find_word_start(pm->str);*find_word_end(pp)=0;
153
    inf=open4read(pp);
153
  inf=open4read(pp);
154
    if(inf==NULL) {
154
  if(inf==NULL) {
155
      fly_error("file_not_exist"); return;
155
    fly_error("file_not_exist"); return;
156
    }
156
  }
157
    image=gdImageCreateFromGif(inf); fclose(inf);
157
  image=gdImageCreateFromGif(inf); fclose(inf);
158
    if(image==NULL) {
158
  if(image==NULL) {
159
      fly_error("bad_gif"); return;
159
    fly_error("bad_gif"); return;
160
    }
160
  }
161
    sizex=image->sx; sizey=image->sy;
161
  sizex=image->sx; sizey=image->sy;
162
    saved=0;
162
  saved=0;
163
}
163
}
164
 
164
 
165
/* solid line */
165
/* solid line */
166
void obj_line(objparm *pm)
166
void obj_line(objparm *pm)
167
{
167
{
168
    scale(pm->pd,pm->p,2);
168
  scale(pm->pd,pm->p,2);
169
    gdImageLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],pm->color[0]);
169
  gdImageLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],pm->color[0]);
170
    if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]);
170
  if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]);
171
}
171
}
172
 
172
 
173
void _obj_arrow(objparm *pm, int twoside)
173
void _obj_arrow(objparm *pm, int twoside)
174
{
174
{
175
    int l,xx,yy;
175
  int l,xx,yy;
176
    gdPoint ii[3];
176
  gdPoint ii[3];
177
    double dx,dy,length,dd[6];
177
  double dx,dy,length,dd[6];
178
    scale(pm->pd,pm->p,2);
178
  scale(pm->pd,pm->p,2);
179
    xx=ii[0].x=pm->p[2];yy=ii[0].y=pm->p[3];
179
  xx=ii[0].x=pm->p[2];yy=ii[0].y=pm->p[3];
180
    l=pm->pd[4];if(l<0) l=0; if(l>200) l=200;
180
  l=pm->pd[4];if(l<0) l=0; if(l>200) l=200;
181
    scale2(pm->pd[0]-pm->pd[2],pm->pd[1]-pm->pd[3],&dx,&dy);
181
  scale2(pm->pd[0]-pm->pd[2],pm->pd[1]-pm->pd[3],&dx,&dy);
182
    length=sqrt(dx*dx+dy*dy);
182
  length=sqrt(dx*dx+dy*dy);
183
    if(length<3 || l<5) goto stem;
183
  if(length<3 || l<5) goto stem;
184
    dd[0]=l*dx/length; dd[1]=l*dy/length;
184
  dd[0]=l*dx/length; dd[1]=l*dy/length;
185
    #define fat 0.27
185
  #define fat 0.27
186
    dd[2]=dd[0]+dd[1]*fat; dd[3]=dd[1]-dd[0]*fat;
186
  dd[2]=dd[0]+dd[1]*fat; dd[3]=dd[1]-dd[0]*fat;
187
    dd[4]=dd[0]-dd[1]*fat; dd[5]=dd[1]+dd[0]*fat;
187
  dd[4]=dd[0]-dd[1]*fat; dd[5]=dd[1]+dd[0]*fat;
-
 
188
  ii[1].x=rint(dd[2])+ii[0].x; ii[1].y=rint(dd[3])+ii[0].y;
-
 
189
  ii[2].x=rint(dd[4])+ii[0].x; ii[2].y=rint(dd[5])+ii[0].y;
-
 
190
  gdImageFilledPolygon(image, ii,3,pm->color[0]);
-
 
191
  xx=rint(dd[0])+ii[0].x;yy=rint(dd[1])+ii[0].y;
-
 
192
  if(twoside) {
-
 
193
    ii[0].x=pm->p[0]; ii[0].y=pm->p[1];
188
    ii[1].x=rint(dd[2])+ii[0].x; ii[1].y=rint(dd[3])+ii[0].y;
194
    ii[1].x=-rint(dd[2])+ii[0].x; ii[1].y=-rint(dd[3])+ii[0].y;
189
    ii[2].x=rint(dd[4])+ii[0].x; ii[2].y=rint(dd[5])+ii[0].y;
195
    ii[2].x=-rint(dd[4])+ii[0].x; ii[2].y=-rint(dd[5])+ii[0].y;
190
    gdImageFilledPolygon(image, ii,3,pm->color[0]);
196
    gdImageFilledPolygon(image, ii,3,pm->color[0]);
191
    xx=rint(dd[0])+ii[0].x;yy=rint(dd[1])+ii[0].y;
-
 
192
    if(twoside) {
-
 
193
      ii[0].x=pm->p[0]; ii[0].y=pm->p[1];
-
 
194
      ii[1].x=-rint(dd[2])+ii[0].x; ii[1].y=-rint(dd[3])+ii[0].y;
-
 
195
      ii[2].x=-rint(dd[4])+ii[0].x; ii[2].y=-rint(dd[5])+ii[0].y;
-
 
196
      gdImageFilledPolygon(image, ii,3,pm->color[0]);
-
 
197
    }
197
  }
198
    stem: if(pm->fill)
198
  stem: if(pm->fill)
199
      myDashedLine(image,pm->p[0],pm->p[1],xx,yy,pm->color[0]);
199
    myDashedLine(image,pm->p[0],pm->p[1],xx,yy,pm->color[0]);
200
    else
200
  else
201
      gdImageLine(image,pm->p[0],pm->p[1],xx,yy,pm->color[0]);
201
    gdImageLine(image,pm->p[0],pm->p[1],xx,yy,pm->color[0]);
202
    if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]);
202
  if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]);
203
}
203
}
204
 
204
 
205
/* Arrow */
205
/* Arrow */
206
void obj_arrow(objparm *pm)
206
void obj_arrow(objparm *pm)
207
{
207
{
208
    _obj_arrow(pm,0);
208
  _obj_arrow(pm,0);
209
}
209
}
210
 
210
 
211
/* 2-sided arrow */
211
/* 2-sided arrow */
212
void obj_arrow2(objparm *pm)
212
void obj_arrow2(objparm *pm)
213
{
213
{
214
    _obj_arrow(pm,1);
214
   _obj_arrow(pm,1);
215
}
215
}
216
 
216
 
217
/* horizontal line */
217
/* horizontal line */
218
void obj_hline(objparm *pm)
218
void obj_hline(objparm *pm)
219
{
219
{
220
    scale(pm->pd,pm->p,1);
220
  scale(pm->pd,pm->p,1);
221
    if(pm->fill)
221
  if(pm->fill)
222
      myDashedLine(image,0,pm->p[1],sizex,pm->p[1],pm->color[0]);
222
    myDashedLine(image,0,pm->p[1],sizex,pm->p[1],pm->color[0]);
223
    else
223
  else
224
      gdImageLine(image,0,pm->p[1],sizex,pm->p[1],pm->color[0]);
224
    gdImageLine(image,0,pm->p[1],sizex,pm->p[1],pm->color[0]);
225
}
225
}
226
 
226
 
227
/* vertical line */
227
/* vertical line */
228
void obj_vline(objparm *pm)
228
void obj_vline(objparm *pm)
229
{
229
{
230
    scale(pm->pd,pm->p,1);
230
  scale(pm->pd,pm->p,1);
231
    if(pm->fill)
231
  if(pm->fill)
232
      myDashedLine(image,pm->p[0],0,pm->p[0],sizey,pm->color[0]);
232
    myDashedLine(image,pm->p[0],0,pm->p[0],sizey,pm->color[0]);
233
    else
233
  else
234
      gdImageLine(image,pm->p[0],0,pm->p[0],sizey,pm->color[0]);
234
    gdImageLine(image,pm->p[0],0,pm->p[0],sizey,pm->color[0]);
235
}
235
}
236
 
236
 
237
/* dashed line */
237
/* dashed line */
238
void obj_dline(objparm *pm)
238
void obj_dline(objparm *pm)
239
{
239
{
240
    scale(pm->pd,pm->p,2);
240
  scale(pm->pd,pm->p,2);
241
    myDashedLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3], pm->color[0]);
241
  myDashedLine(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3], pm->color[0]);
242
}
242
}
243
 
243
 
244
/* parallel lines.
244
/* parallel lines.
245
 * x1,y1,x2,y2,xv,yv,n,color */
245
 * x1,y1,x2,y2,xv,yv,n,color */
246
void obj_parallel(objparm *pm)
246
void obj_parallel(objparm *pm)
247
{
247
{
248
    int i, n, xi,yi;
248
  int i, n, xi,yi;
249
    double xv,yv;
249
  double xv,yv;
250
    n=pm->pd[6]; if(n<0) return; if(n>256) n=256;
250
  n=pm->pd[6]; if(n<0) return; if(n>256) n=256;
251
    scale(pm->pd,pm->p,3);
251
  scale(pm->pd,pm->p,3);
252
    scale2(pm->pd[4],pm->pd[5],&xv,&yv);
252
  scale2(pm->pd[4],pm->pd[5],&xv,&yv);
253
    for(i=0;i<n;i++) {
253
  for(i=0;i<n;i++) {
254
      xi=rint(i*xv); yi=rint(i*yv);
254
    xi=rint(i*xv); yi=rint(i*yv);
255
      gdImageLine(image,pm->p[0]+xi,pm->p[1]+yi,pm->p[2]+xi,pm->p[3]+yi,
255
    gdImageLine(image,pm->p[0]+xi,pm->p[1]+yi,pm->p[2]+xi,pm->p[3]+yi,
256
                pm->color[0]);
256
              pm->color[0]);
257
      if(vimg_enable) vimg_line(scale_buf[0]+i*(scale_buf[4]-transx),
257
    if(vimg_enable) vimg_line(scale_buf[0]+i*(scale_buf[4]-transx),
258
                          scale_buf[1]+i*(scale_buf[5]-transy),
258
        scale_buf[1]+i*(scale_buf[5]-transy),
259
                          scale_buf[2]+i*(scale_buf[4]-transx),
259
        scale_buf[2]+i*(scale_buf[4]-transx),
260
                          scale_buf[3]+i*(scale_buf[5]-transy));
260
        scale_buf[3]+i*(scale_buf[5]-transy));
261
    }
261
  }
262
}
262
}
263
 
263
 
264
/* rectangle */
264
/* rectangle */
265
void obj_rect(objparm *pm)
265
void obj_rect(objparm *pm)
266
{
266
{
267
    int x1,y1,x2,y2;
267
  int x1,y1,x2,y2;
268
    scale(pm->pd,pm->p,2);
268
  scale(pm->pd,pm->p,2);
269
    x1=min(pm->p[0],pm->p[2]); x2=max(pm->p[0],pm->p[2]);
269
  x1=min(pm->p[0],pm->p[2]); x2=max(pm->p[0],pm->p[2]);
270
    y1=min(pm->p[1],pm->p[3]); y2=max(pm->p[1],pm->p[3]);
270
  y1=min(pm->p[1],pm->p[3]); y2=max(pm->p[1],pm->p[3]);
271
    if(pm->fill)
271
  if(pm->fill)
272
      gdImageFilledRectangle(image,x1,y1,x2,y2,pm->color[0]);
272
    gdImageFilledRectangle(image,x1,y1,x2,y2,pm->color[0]);
273
    else
273
  else
274
      gdImageRectangle(image,x1,y1,x2,y2,pm->color[0]);
274
    gdImageRectangle(image,x1,y1,x2,y2,pm->color[0]);
275
    if(vimg_enable) vimg_rect(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]);
275
  if(vimg_enable) vimg_rect(scale_buf[0],scale_buf[1],scale_buf[2],scale_buf[3]);
276
}
276
}
277
 
277
 
278
/* square */
278
/* square */
279
void obj_square(objparm *pm)
279
void obj_square(objparm *pm)
280
{
280
{
281
    int w,h;
281
  int w,h;
282
    scale(pm->pd,pm->p,1);
282
  scale(pm->pd,pm->p,1);
283
    w=rint(pm->pd[2]); h=rint(pm->pd[2]);
283
  w=rint(pm->pd[2]); h=rint(pm->pd[2]);
284
    if(pm->fill)
284
  if(pm->fill)
285
      gdImageFilledRectangle(image,pm->p[0],pm->p[1],
285
    gdImageFilledRectangle(image,pm->p[0],pm->p[1],
286
                 pm->p[0]+w,pm->p[1]+h,pm->color[0]);
286
               pm->p[0]+w,pm->p[1]+h,pm->color[0]);
287
    else
287
  else
288
      gdImageRectangle(image,pm->p[0],pm->p[1],
288
    gdImageRectangle(image,pm->p[0],pm->p[1],
289
                 pm->p[0]+w,pm->p[1]+h,pm->color[0]);
289
               pm->p[0]+w,pm->p[1]+h,pm->color[0]);
290
    if(vimg_enable) vimg_rect(scale_buf[0],scale_buf[1],
290
  if(vimg_enable) vimg_rect(scale_buf[0],scale_buf[1],
291
                        scale_buf[0]+pm->pd[2],scale_buf[1]+pm->pd[2]);
291
                      scale_buf[0]+pm->pd[2],scale_buf[1]+pm->pd[2]);
292
}
292
}
293
 
293
 
294
/* triangle */
294
/* triangle */
295
void obj_triangle(objparm *pm)
295
void obj_triangle(objparm *pm)
296
{
296
{
297
    scale(pm->pd,pm->p,3);
297
  scale(pm->pd,pm->p,3);
298
    if(pm->fill)
298
  if(pm->fill)
299
      gdImageFilledPolygon(image,(gdPointPtr) pm->p,3,pm->color[0]);
299
    gdImageFilledPolygon(image,(gdPointPtr) pm->p,3,pm->color[0]);
300
    else
300
  else
301
      gdImagePolygon(image,(gdPointPtr) pm->p,3,pm->color[0]);
301
    gdImagePolygon(image,(gdPointPtr) pm->p,3,pm->color[0]);
302
    if(vimg_enable) vimg_polyline(scale_buf,3,1);
302
  if(vimg_enable) vimg_polyline(scale_buf,3,1);
303
}
303
}
304
 
304
 
305
/* polygon */
305
/* polygon */
306
void obj_poly(objparm *pm)
306
void obj_poly(objparm *pm)
307
{
307
{
308
    int cnt;
308
  int cnt;
309
    cnt=(pm->pcnt)/2;
309
  cnt=(pm->pcnt)/2;
310
    scale(pm->pd,pm->p,cnt);
310
  scale(pm->pd,pm->p,cnt);
311
    if(pm->fill)
311
  if(pm->fill)
312
      gdImageFilledPolygon(image,(gdPointPtr) pm->p,cnt,pm->color[0]);
312
    gdImageFilledPolygon(image,(gdPointPtr) pm->p,cnt,pm->color[0]);
313
    else
313
  else
314
      gdImagePolygon(image,(gdPointPtr) pm->p,cnt,pm->color[0]);
314
    gdImagePolygon(image,(gdPointPtr) pm->p,cnt,pm->color[0]);
315
    if(vimg_enable) vimg_polyline(scale_buf,cnt,1);
315
  if(vimg_enable) vimg_polyline(scale_buf,cnt,1);
316
}
316
}
317
 
317
 
318
/* rays */
318
/* rays */
319
void obj_rays(objparm *pm)
319
void obj_rays(objparm *pm)
320
{
320
{
321
    int i, n;
321
  int i, n;
322
    n=(pm->pcnt)/2;
322
  n=(pm->pcnt)/2;
323
    scale(pm->pd,pm->p,n);
323
  scale(pm->pd,pm->p,n);
324
    for(i=2;i<2*n;i+=2) {
324
  for(i=2;i<2*n;i+=2) {
325
      gdImageLine(image,pm->p[0],pm->p[1],pm->p[i],pm->p[i+1],pm->color[0]);
325
    gdImageLine(image,pm->p[0],pm->p[1],pm->p[i],pm->p[i+1],pm->color[0]);
326
      if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],
326
    if(vimg_enable) vimg_line(scale_buf[0],scale_buf[1],
327
                          scale_buf[i],scale_buf[i+1]);
327
                        scale_buf[i],scale_buf[i+1]);
328
    }
328
  }
329
}
329
}
330
/* crosshair */
330
/* crosshair */
331
void obj_crosshair(objparm *pm)
331
void obj_crosshair(objparm *pm)
332
{
332
{
333
    scale(pm->pd,pm->p,2);
333
  scale(pm->pd,pm->p,2);
334
    gdImageLine(image,pm->p[0]+width2,pm->p[1]+width2,pm->p[0]-width2,pm->p[1]-width2,pm->color[0]);
334
  gdImageLine(image,pm->p[0]+width2,pm->p[1]+width2,pm->p[0]-width2,pm->p[1]-width2,pm->color[0]);
335
    gdImageLine(image,pm->p[0]-width2,pm->p[1]+width2,pm->p[0]+width2,pm->p[1]-width2,pm->color[0]);
335
  gdImageLine(image,pm->p[0]-width2,pm->p[1]+width2,pm->p[0]+width2,pm->p[1]-width2,pm->color[0]);
336
}
336
}
337
/* crosshairs */
337
/* crosshairs */
338
 
338
 
339
void obj_crosshairs(objparm *pm)
339
void obj_crosshairs(objparm *pm)
340
{
340
{
341
    int i, n;
341
  int i, n;
342
    n=(pm->pcnt)/2;
342
  n=(pm->pcnt)/2;
343
    scale(pm->pd,pm->p,n);
343
  scale(pm->pd,pm->p,n);
344
    for(i=0;i<2*n;i+=2) {
344
  for(i=0;i<2*n;i+=2) {
345
      gdImageLine(image,pm->p[i]+width2,pm->p[i+1]+width2,pm->p[i]-width2,pm->p[i+1]-width2,pm->color[0]);
345
    gdImageLine(image,pm->p[i]+width2,pm->p[i+1]+width2,pm->p[i]-width2,pm->p[i+1]-width2,pm->color[0]);
346
      gdImageLine(image,pm->p[i]-width2,pm->p[i+1]+width2,pm->p[i]+width2,pm->p[i+1]-width2,pm->color[0]);
346
    gdImageLine(image,pm->p[i]-width2,pm->p[i+1]+width2,pm->p[i]+width2,pm->p[i+1]-width2,pm->color[0]);
347
   }
347
  }
348
}
348
}
349
 
349
 
350
 
350
 
351
/* segments */
351
/* segments */
352
void obj_lines(objparm *pm)
352
void obj_lines(objparm *pm)
353
{
353
{
354
    int i, n;
354
  int i, n;
355
    n=(pm->pcnt)/2;
355
  n=(pm->pcnt)/2;
356
    scale(pm->pd,pm->p,n);
356
  scale(pm->pd,pm->p,n);
357
    for(i=2;i<2*n;i+=2)
357
  for(i=2;i<2*n;i+=2)
358
      gdImageLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]);
358
    gdImageLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]);
359
    if(vimg_enable) vimg_polyline(scale_buf,n,0);
359
  if(vimg_enable) vimg_polyline(scale_buf,n,0);
360
}
360
}
361
 
361
 
362
/* segments */
362
/* segments */
363
void obj_dlines(objparm *pm)
363
void obj_dlines(objparm *pm)
364
{
364
{
365
    int i, n;
365
  int i, n;
366
    n=(pm->pcnt)/2;
366
  n=(pm->pcnt)/2;
367
    scale(pm->pd,pm->p,n);
367
  scale(pm->pd,pm->p,n);
368
    for(i=2;i<2*n;i+=2)
368
  for(i=2;i<2*n;i+=2)
369
      myDashedLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]);
369
    myDashedLine(image,pm->p[i-2],pm->p[i-1],pm->p[i],pm->p[i+1],pm->color[0]);
370
    if(vimg_enable) vimg_polyline(scale_buf,n,0);
370
  if(vimg_enable) vimg_polyline(scale_buf,n,0);
371
}
371
}
372
 
372
 
373
/* points */
373
/* points */
374
void obj_points(objparm *pm)
374
void obj_points(objparm *pm)
375
{
375
{
376
    int i, n;
376
  int i, n;
377
    n=(pm->pcnt)/2;
377
  n=(pm->pcnt)/2;
378
    scale(pm->pd,pm->p,n);
378
  scale(pm->pd,pm->p,n);
379
    for(i=0;i<2*n;i+=2)
379
  for(i=0;i<2*n;i+=2)
380
      gdImageSetPixel(image,pm->p[i],pm->p[i+1],pm->color[0]);
380
    gdImageSetPixel(image,pm->p[i],pm->p[i+1],pm->color[0]);
381
}
381
}
382
 
382
 
383
/* lattice.
383
/* lattice.
384
 * x0,y0,xv1,yv1,xv2,yv2,n1,n2,color */
384
 * x0,y0,xv1,yv1,xv2,yv2,n1,n2,color */
385
void obj_lattice(objparm *pm)
385
void obj_lattice(objparm *pm)
386
{
386
{
387
    int n1,n2,i1,i2,xi1,yi1,xi2,yi2;
387
  int n1,n2,i1,i2,xi1,yi1,xi2,yi2;
388
    double xv1,xv2,yv1,yv2;
388
  double xv1,xv2,yv1,yv2;
389
    n1=pm->pd[6];n2=pm->pd[7]; if(n1<0 || n2<0) return;
389
  n1=pm->pd[6];n2=pm->pd[7]; if(n1<0 || n2<0) return;
390
    if(n1>256) n1=256;
390
  if(n1>256) n1=256;
391
    if(n2>256) n2=256;
391
  if(n2>256) n2=256;
392
    scale(pm->pd,pm->p,1);
392
  scale(pm->pd,pm->p,1);
393
    scale2(pm->pd[2],pm->pd[3],&xv1,&yv1);
393
  scale2(pm->pd[2],pm->pd[3],&xv1,&yv1);
394
    scale2(pm->pd[4],pm->pd[5],&xv2,&yv2);
394
  scale2(pm->pd[4],pm->pd[5],&xv2,&yv2);
395
    for(i1=0;i1<n1;i1++) {
395
  for(i1=0;i1<n1;i1++) {
396
      xi1=rint(i1*xv1)+pm->p[0]; yi1=rint(i1*yv1)+pm->p[1];
396
    xi1=rint(i1*xv1)+pm->p[0]; yi1=rint(i1*yv1)+pm->p[1];
397
      for(i2=0;i2<n2;i2++) {
397
    for(i2=0;i2<n2;i2++) {
398
          xi2=i2*xv2+xi1;yi2=i2*yv2+yi1;
398
      xi2=i2*xv2+xi1;yi2=i2*yv2+yi1;
399
          gdImageSetPixel(image,xi2,yi2,pm->color[0]);
399
      gdImageSetPixel(image,xi2,yi2,pm->color[0]);
400
      }
-
 
401
    }
400
    }
-
 
401
  }
402
}
402
}
403
 
403
 
404
/* arc */
404
/* arc */
405
void obj_arc(objparm *pm)
405
void obj_arc(objparm *pm)
406
{
406
{
407
    scale(pm->pd,pm->p,1);
407
  scale(pm->pd,pm->p,1);
408
    pm->p[2]=rint(pm->pd[2]*xscale); pm->p[3]=rint(pm->pd[3]*yscale);
408
  pm->p[2]=rint(pm->pd[2]*xscale); pm->p[3]=rint(pm->pd[3]*yscale);
409
    gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],
409
  gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],
410
             pm->pd[4],pm->pd[5],pm->color[0]);
410
           pm->pd[4],pm->pd[5],pm->color[0]);
411
    if(vimg_enable) vimg_arc(scale_buf[0],scale_buf[1],
411
  if(vimg_enable) vimg_arc(scale_buf[0],scale_buf[1],
412
                       0.5*pm->pd[2],0.5*pm->pd[3],pm->pd[4],pm->pd[5]);
412
                     0.5*pm->pd[2],0.5*pm->pd[3],pm->pd[4],pm->pd[5]);
413
}
413
}
414
 
414
 
415
/* Ellipse: centre 0,1, width 2, hight 3, color 4,5,6 */
415
/* Ellipse: centre 0,1, width 2, hight 3, color 4,5,6 */
416
void obj_ellipse(objparm *pm)
416
void obj_ellipse(objparm *pm)
417
{
417
{
418
    scale(pm->pd,pm->p,1);
418
  scale(pm->pd,pm->p,1);
419
    pm->p[2]=rint(pm->pd[2]*xscale); pm->p[3]=rint(pm->pd[3]*yscale);
419
  pm->p[2]=rint(pm->pd[2]*xscale); pm->p[3]=rint(pm->pd[3]*yscale);
420
    if(pm->fill) {
420
  if(pm->fill) {
421
      gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,
421
    gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,
422
               color_bounder);
422
             color_bounder);
423
      patchgdImageFillToBorder(image,pm->p[0],pm->p[1],
423
    patchgdImageFillToBorder(image,pm->p[0],pm->p[1],
424
                      color_bounder,pm->color[0]);
424
                    color_bounder,pm->color[0]);
425
    }
425
  }
426
    gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,pm->color[0]);
426
  gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,pm->color[0]);
427
    if(vimg_enable) vimg_ellipse(scale_buf[0],scale_buf[1],0.5*pm->pd[2],0.5*pm->pd[3]);
427
    if(vimg_enable) vimg_ellipse(scale_buf[0],scale_buf[1],0.5*pm->pd[2],0.5*pm->pd[3]);
428
}
428
}
429
 
429
 
430
/* Circle */
430
/* Circle */
431
void obj_circle(objparm *pm)
431
void obj_circle(objparm *pm)
432
{
432
{
433
    scale(pm->pd,pm->p,1);
433
  scale(pm->pd,pm->p,1);
434
    pm->p[2]=rint(pm->pd[2]); pm->p[3]=rint(pm->pd[2]);
434
  pm->p[2]=rint(pm->pd[2]); pm->p[3]=rint(pm->pd[2]);
435
    if(pm->fill) {
435
  if(pm->fill) {
436
      gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,
436
    gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,
437
               color_bounder);
437
             color_bounder);
438
      patchgdImageFillToBorder(image,pm->p[0],pm->p[1],
438
    patchgdImageFillToBorder(image,pm->p[0],pm->p[1],
439
                      color_bounder,pm->color[0]);
439
                    color_bounder,pm->color[0]);
440
    }
440
  }
441
    gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,pm->color[0]);
441
  gdImageArc(image,pm->p[0],pm->p[1],pm->p[2],pm->p[3],0,360,pm->color[0]);
442
}
442
}
443
 
443
 
444
/* flood fill */
444
/* flood fill */
445
void obj_fill(objparm *pm)
445
void obj_fill(objparm *pm)
446
{
446
{
447
    scale(pm->pd,pm->p,1);
447
  scale(pm->pd,pm->p,1);
448
    patchgdImageFill(image,pm->p[0],pm->p[1],pm->color[0]);
448
  patchgdImageFill(image,pm->p[0],pm->p[1],pm->color[0]);
449
}
449
}
450
 
450
 
451
/* flood fill to border*/
451
/* flood fill to border*/
452
void obj_fillb(objparm *pm)
452
void obj_fillb(objparm *pm)
453
{
453
{
454
    scale(pm->pd,pm->p,1);
454
  scale(pm->pd,pm->p,1);
455
    patchgdImageFillToBorder(image,pm->p[0],pm->p[1],pm->color[0],pm->color[1]);
455
  patchgdImageFillToBorder(image,pm->p[0],pm->p[1],pm->color[0],pm->color[1]);
456
}
456
}
457
 
457
 
458
gdImagePtr himg;
458
gdImagePtr himg;
459
 
459
 
460
int makehatchimage(int x, int y, int px, int py, int col)
460
int makehatchimage(int x, int y, int px, int py, int col)
461
{
461
{
462
    int c1,c2,r,g,b;
462
  int c1,c2,r,g,b;
463
    gdImagePtr saveimg;
463
  gdImagePtr saveimg;
464
    himg=gdImageCreate(x,y);
464
  himg=gdImageCreate(x,y);
465
    c1=gdImageGetPixel(image,px,py);
465
  c1=gdImageGetPixel(image,px,py);
466
    r=gdImageRed(image,c1); g=gdImageGreen(image,c1); b=gdImageBlue(image,c1);
466
  r=gdImageRed(image,c1); g=gdImageGreen(image,c1); b=gdImageBlue(image,c1);
467
    if(r>=255) r--; else r++; if(g>=255) g--; else g++; if(b>=255) b--; else b++;
467
  if(r>=255) r--; else r++; if(g>=255) g--; else g++; if(b>=255) b--; else b++;
468
    c1=gdImageColorAllocate(himg,r,g,b);
468
  c1=gdImageColorAllocate(himg,r,g,b);
469
    r=gdImageRed(image,col); g=gdImageGreen(image,col); b=gdImageBlue(image,col);
469
  r=gdImageRed(image,col); g=gdImageGreen(image,col); b=gdImageBlue(image,col);
470
    c2=gdImageColorAllocate(himg,r,g,b);
470
  c2=gdImageColorAllocate(himg,r,g,b);
471
    if(width>1) {
471
  if(width>1) {
472
      savew=-1; saveimg=image;
472
    savew=-1; saveimg=image;
473
      image=himg; c2=widthcolor(width,c2); image=saveimg;
473
    image=himg; c2=widthcolor(width,c2); image=saveimg;
474
      c2=gdBrushed; savew=-1;
474
    c2=gdBrushed; savew=-1;
475
    }
475
  }
476
    return c2;
476
  return c2;
477
}
477
}
478
 
478
 
479
/* flood fill with hatching */
479
/* flood fill with hatching */
480
void obj_hatchfill(objparm *pm)
480
void obj_hatchfill(objparm *pm)
481
{
481
{
482
    int nx,ny,ax,ay, dir, c;
482
  int nx,ny,ax,ay, dir, c;
483
    scale(pm->pd,pm->p,1);
483
  scale(pm->pd,pm->p,1);
484
    nx=pm->pd[2]; ny=pm->pd[3]; ax=abs(nx); ay=abs(ny);
484
  nx=pm->pd[2]; ny=pm->pd[3]; ax=abs(nx); ay=abs(ny);
485
    if(nx==0 && ny==0) {fly_error("bad displacement vector"); return;}
485
  if(nx==0 && ny==0) {fly_error("bad displacement vector"); return;}
486
    if((nx>0 && ny>0) || (nx<0 && ny<0)) dir=1; else dir=-1;
486
  if((nx>0 && ny>0) || (nx<0 && ny<0)) dir=1; else dir=-1;
487
    if(ax==0) {ax=100; dir=2;}
487
  if(ax==0) {ax=100; dir=2;}
488
    if(ay==0) {ay=100; dir=3;}
488
  if(ay==0) {ay=100; dir=3;}
489
    c=makehatchimage(ax,ay,pm->p[0],pm->p[1],pm->color[0]);
489
  c=makehatchimage(ax,ay,pm->p[0],pm->p[1],pm->color[0]);
490
    switch(dir) {
490
  switch(dir) {
491
      case -1: {
491
    case -1: {
492
          gdImageLine(himg,0,ay-1,ax-1,0,c);
492
      gdImageLine(himg,0,ay-1,ax-1,0,c);
493
          if(width>1) {
493
      if(width>1) {
494
            gdImageLine(himg,-ax,ay-1,-1,0,c);
494
        gdImageLine(himg,-ax,ay-1,-1,0,c);
495
            gdImageLine(himg,ax,ay-1,2*ax-1,0,c);
495
        gdImageLine(himg,ax,ay-1,2*ax-1,0,c);
496
            gdImageLine(himg,0,-1,ax-1,-ay,c);
496
        gdImageLine(himg,0,-1,ax-1,-ay,c);
497
            gdImageLine(himg,0,2*ay-1,ax-1,ay,c);
497
        gdImageLine(himg,0,2*ay-1,ax-1,ay,c);
498
          }
-
 
499
          break;
-
 
500
      }
-
 
501
      case 1: {
-
 
502
          gdImageLine(himg,0,0,ax-1,ay-1,c);
-
 
503
          if(width>1) {
-
 
504
            gdImageLine(himg,-ax,0,-1,ay-1,c);
-
 
505
            gdImageLine(himg,ax,0,2*ax-1,ay-1,c);
-
 
506
            gdImageLine(himg,0,-ay,ax-1,-1,c);
-
 
507
            gdImageLine(himg,0,ay,ax-1,2*ay-1,c);
-
 
508
          }
-
 
509
          break;
-
 
510
      }
498
      }
511
      case 2: gdImageLine(himg,0,ay/2,ax-1,ay/2,c); break;
-
 
512
      case 3: gdImageLine(himg,ax/2,0,ax/2,ay-1,c); break;
499
      break;
513
    }
500
    }
-
 
501
    case 1: {
-
 
502
      gdImageLine(himg,0,0,ax-1,ay-1,c);
-
 
503
      if(width>1) {
-
 
504
        gdImageLine(himg,-ax,0,-1,ay-1,c);
-
 
505
        gdImageLine(himg,ax,0,2*ax-1,ay-1,c);
-
 
506
        gdImageLine(himg,0,-ay,ax-1,-1,c);
-
 
507
        gdImageLine(himg,0,ay,ax-1,2*ay-1,c);
-
 
508
      }
-
 
509
      break;
-
 
510
    }
-
 
511
    case 2: gdImageLine(himg,0,ay/2,ax-1,ay/2,c); break;
-
 
512
      case 3: gdImageLine(himg,ax/2,0,ax/2,ay-1,c); break;
-
 
513
  }
514
    gdImageSetTile(image,himg);
514
  gdImageSetTile(image,himg);
515
    patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled);
515
  patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled);
516
    gdImageDestroy(himg);
516
  gdImageDestroy(himg);
517
    if(tiled) gdImageSetTile(image,tileimg);
517
  if(tiled) gdImageSetTile(image,tileimg);
518
}
518
}
519
 
519
 
520
/* flood fill with grid */
520
/* flood fill with grid */
521
void obj_gridfill(objparm *pm)
521
void obj_gridfill(objparm *pm)
522
{
522
{
523
    int nx,ny, c;
523
  int nx,ny, c;
524
    scale(pm->pd,pm->p,1);
524
  scale(pm->pd,pm->p,1);
525
    nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny);
525
  nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny);
526
    if(nx==0 && ny==0) {fly_error("bad grid size"); return;}
526
  if(nx==0 && ny==0) {fly_error("bad grid size"); return;}
527
    c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]);
527
  c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]);
528
    gdImageLine(himg,0,ny/2,nx-1,ny/2,c); gdImageLine(himg,nx/2,0,nx/2,ny-1,c);
528
  gdImageLine(himg,0,ny/2,nx-1,ny/2,c); gdImageLine(himg,nx/2,0,nx/2,ny-1,c);
529
    gdImageSetTile(image,himg);
529
  gdImageSetTile(image,himg);
530
    patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled);
530
  patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled);
531
    gdImageDestroy(himg);
531
  gdImageDestroy(himg);
532
    if(tiled) gdImageSetTile(image,tileimg);
532
  if(tiled) gdImageSetTile(image,tileimg);
533
}
533
}
534
 
534
 
535
/* flood fill with double hatching */
535
/* flood fill with double hatching */
536
void obj_diafill(objparm *pm)
536
void obj_diafill(objparm *pm)
537
{
537
{
538
    int nx,ny, c;
538
  int nx,ny, c;
539
    scale(pm->pd,pm->p,1);
539
  scale(pm->pd,pm->p,1);
540
    nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny);
540
  nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny);
541
    if(nx==0 && ny==0) {fly_error("bad grid size"); return;}
541
  if(nx==0 && ny==0) {fly_error("bad grid size"); return;}
542
    c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]);
542
  c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]);
543
    gdImageLine(himg,0,0,nx-1,ny-1,c); gdImageLine(himg,0,ny-1,nx-1,0,c);
543
  gdImageLine(himg,0,0,nx-1,ny-1,c); gdImageLine(himg,0,ny-1,nx-1,0,c);
544
    gdImageSetTile(image,himg);
544
  gdImageSetTile(image,himg);
545
    patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled);
545
  patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled);
546
    gdImageDestroy(himg);
546
  gdImageDestroy(himg);
547
    if(tiled) gdImageSetTile(image,tileimg);
547
  if(tiled) gdImageSetTile(image,tileimg);
548
}
548
}
549
 
549
 
550
/* flood fill with double hatching */
550
/* flood fill with double hatching */
551
void obj_dotfill(objparm *pm)
551
void obj_dotfill(objparm *pm)
552
{
552
{
553
    int nx,ny, c;
553
  int nx,ny, c;
554
    scale(pm->pd,pm->p,1);
554
  scale(pm->pd,pm->p,1);
555
    nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny);
555
  nx=pm->pd[2]; ny=pm->pd[3]; nx=abs(nx); ny=abs(ny);
556
    if(nx==0 && ny==0) {fly_error("bad grid size"); return;}
556
  if(nx==0 && ny==0) {fly_error("bad grid size"); return;}
557
    c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]);
557
  c=makehatchimage(nx,ny,pm->p[0],pm->p[1],pm->color[0]);
558
    gdImageSetPixel(himg,nx/2,ny/2,c);
558
  gdImageSetPixel(himg,nx/2,ny/2,c);
559
    gdImageSetTile(image,himg);
559
  gdImageSetTile(image,himg);
560
    patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled);
560
  patchgdImageFill(image,pm->p[0],pm->p[1],gdTiled);
561
    gdImageDestroy(himg);
561
  gdImageDestroy(himg);
562
    if(tiled) gdImageSetTile(image,tileimg);
562
  if(tiled) gdImageSetTile(image,tileimg);
563
}
563
}
564
 
564
 
565
struct {
565
struct {
566
    char *name;
566
  char *name;
567
    gdFontPtr *fpt;
567
  gdFontPtr *fpt;
568
} fonttab[]={
568
} fonttab[]={
569
      {"tiny",      &gdFontTiny},
569
  {"tiny",      &gdFontTiny},
570
      {"small",      &gdFontSmall},
570
  {"small",      &gdFontSmall},
571
      {"medium",&gdFontMediumBold},
571
  {"medium",&gdFontMediumBold},
572
      {"large",      &gdFontLarge},
572
  {"large",      &gdFontLarge},
573
      {"giant",      &gdFontGiant},
573
  {"giant",      &gdFontGiant},
574
      {"huge",      &gdFontGiant}
574
  {"huge",      &gdFontGiant}
575
};
575
};
576
 
576
 
577
#define fonttab_no (sizeof(fonttab)/sizeof(fonttab[0]))
577
#define fonttab_no (sizeof(fonttab)/sizeof(fonttab[0]))
578
 
578
 
579
/* string */
579
/* string */
580
void obj_string(objparm *pm)
580
void obj_string(objparm *pm)
581
{
581
{
582
    char *pp, *pe, *p2;
582
  char *pp, *pe, *p2;
583
    int i;
583
  int i;
584
    pp=pm->str; pe=strchr(pp,','); if(pe==NULL) {
584
  pp=pm->str; pe=strchr(pp,','); if(pe==NULL) {
585
      fly_error("too_few_parms"); return;
585
    fly_error("too_few_parms"); return;
586
    }
586
  }
587
    *pe++=0; pp=find_word_start(pp); *find_word_end(pp)=0;
587
  *pe++=0; pp=find_word_start(pp); *find_word_end(pp)=0;
588
    pe=find_word_start(pe); strip_trailing_spaces(pe);
588
  pe=find_word_start(pe); strip_trailing_spaces(pe);
589
    if(*pp) {
589
  if(*pp) {
590
      for(i=0;i<fonttab_no && strcmp(pp,fonttab[i].name)!=0; i++);
590
    for(i=0;i<fonttab_no && strcmp(pp,fonttab[i].name)!=0; i++);
591
      if(i>=fonttab_no) i=1;
591
    if(i>=fonttab_no) i=1;
592
    }
592
  }
593
    else i=1;
593
  else i=1;
594
    scale(pm->pd,pm->p,1);
594
  scale(pm->pd,pm->p,1);
595
    if(*pe=='"') {
595
  if(*pe=='"') {
596
      p2=strchr(pe+1,'"');
596
    p2=strchr(pe+1,'"');
597
      if(p2 && *(p2+1)==0) {*p2=0; pe++;}
597
    if(p2 && *(p2+1)==0) {*p2=0; pe++;}
598
    }
598
  }
599
    if(pm->fill)
599
  if(pm->fill)
600
      gdImageStringUp(image,*(fonttab[i].fpt),pm->p[0],pm->p[1], (unsigned char*) pe,
600
    gdImageStringUp(image,*(fonttab[i].fpt),pm->p[0],pm->p[1], (unsigned char*) pe,
601
                pm->color[0]);
601
        pm->color[0]);
602
    else
602
  else
603
      gdImageString(image,*(fonttab[i].fpt),pm->p[0],pm->p[1], (unsigned char*) pe,
603
    gdImageString(image,*(fonttab[i].fpt),pm->p[0],pm->p[1], (unsigned char*) pe,
604
                pm->color[0]);
604
        pm->color[0]);
605
}
605
}
606
 
606
 
607
/* point */
607
/* point */
608
void obj_point(objparm *pm)
608
void obj_point(objparm *pm)
609
{
609
{
610
    scale(pm->pd,pm->p,1);
610
  scale(pm->pd,pm->p,1);
611
    gdImageSetPixel(image,pm->p[0],pm->p[1],pm->color[0]);
611
  gdImageSetPixel(image,pm->p[0],pm->p[1],pm->color[0]);
612
}
612
}
613
 
613
 
614
/* copy an image file */
614
/* copy an image file */
615
void obj_copy(objparm *pm)
615
void obj_copy(objparm *pm)
616
{
616
{
617
    char *pp;
617
  char *pp;
618
    FILE *inf;
618
  FILE *inf;
619
    gdImagePtr insimg;
619
  gdImagePtr insimg;
620
 
620
 
621
    pp=find_word_start(pm->str);*find_word_end(pp)=0;
621
  pp=find_word_start(pm->str);*find_word_end(pp)=0;
622
    inf=open4read(pp);
622
  inf=open4read(pp);
623
    if(inf==NULL) {
623
  if(inf==NULL) {
624
      fly_error("file_not_exist"); return;
624
    fly_error("file_not_exist"); return;
625
    }
625
  }
626
    insimg=gdImageCreateFromGif(inf); fclose(inf);
626
  insimg=gdImageCreateFromGif(inf); fclose(inf);
627
    if(insimg==NULL) {
627
  if(insimg==NULL) {
628
      fly_error("bad_gif"); return;
628
    fly_error("bad_gif"); return;
629
    }
629
  }
630
    scale(pm->pd,pm->p,1);
630
  scale(pm->pd,pm->p,1);
631
    if(pm->pd[2]<0 && pm->pd[3]<0 && pm->pd[4]<0 && pm->pd[5]<0)
631
  if(pm->pd[2]<0 && pm->pd[3]<0 && pm->pd[4]<0 && pm->pd[5]<0)
632
      gdImageCopy(image,insimg,pm->p[0],pm->p[1],0,0,
632
    gdImageCopy(image,insimg,pm->p[0],pm->p[1],0,0,
633
              insimg->sx,insimg->sy);
633
            insimg->sx,insimg->sy);
634
    else
634
  else
635
      gdImageCopy(image,insimg,pm->p[0],pm->p[1],pm->pd[2],pm->pd[3],
635
    gdImageCopy(image,insimg,pm->p[0],pm->p[1],pm->pd[2],pm->pd[3],
636
              pm->pd[4]-pm->pd[2],pm->pd[5]-pm->pd[3]);
636
            pm->pd[4]-pm->pd[2],pm->pd[5]-pm->pd[3]);
637
    gdImageDestroy(insimg);
637
  gdImageDestroy(insimg);
638
}
638
}
639
 
639
 
640
/* copy an image file, with resizing */
640
/* copy an image file, with resizing */
641
void obj_copyresize(objparm *pm)
641
void obj_copyresize(objparm *pm)
642
{
642
{
643
    char *pp;
643
  char *pp;
644
    FILE *inf;
644
  FILE *inf;
645
    gdImagePtr insimg;
645
  gdImagePtr insimg;
646
 
646
 
647
    pp=find_word_start(pm->str);*find_word_end(pp)=0;
647
  pp=find_word_start(pm->str);*find_word_end(pp)=0;
648
    inf=open4read(pp);
648
  inf=open4read(pp);
649
    if(inf==NULL) {
649
  if(inf==NULL) {
650
      fly_error("file_not_found"); return;
650
    fly_error("file_not_found"); return;
651
    }
651
  }
652
    insimg=gdImageCreateFromGif(inf); fclose(inf);
652
  insimg=gdImageCreateFromGif(inf); fclose(inf);
653
    if(insimg==NULL) {
653
  if(insimg==NULL) {
654
      fly_error("bad_gif"); return;
654
    fly_error("bad_gif"); return;
655
    }
655
  }
656
    scale(pm->pd+4,pm->p+4,2);
656
  scale(pm->pd+4,pm->p+4,2);
657
    if(pm->pd[0]<0 && pm->pd[1]<0 && pm->pd[2]<0 && pm->pd[3]<0)
657
  if(pm->pd[0]<0 && pm->pd[1]<0 && pm->pd[2]<0 && pm->pd[3]<0)
658
      gdImageCopyResized(image,insimg,pm->p[4],pm->p[5],0,0,
658
    gdImageCopyResized(image,insimg,pm->p[4],pm->p[5],0,0,
659
                   pm->p[6]-pm->p[4]+1,pm->p[7]-pm->p[5]+1,
659
                 pm->p[6]-pm->p[4]+1,pm->p[7]-pm->p[5]+1,
660
                   insimg->sx,insimg->sy);
660
                 insimg->sx,insimg->sy);
661
    else
661
  else
662
      gdImageCopyResized(image,insimg,pm->p[4],pm->p[5],pm->pd[0],pm->pd[1],
662
    gdImageCopyResized(image,insimg,pm->p[4],pm->p[5],pm->pd[0],pm->pd[1],
663
                   pm->p[6]-pm->p[4]+1,pm->p[7]-pm->p[5]+1,
663
                 pm->p[6]-pm->p[4]+1,pm->p[7]-pm->p[5]+1,
664
                   pm->pd[2]-pm->pd[0]+1,pm->pd[3]-pm->pd[1]+1);
664
                 pm->pd[2]-pm->pd[0]+1,pm->pd[3]-pm->pd[1]+1);
665
    gdImageDestroy(insimg);
665
  gdImageDestroy(insimg);
666
}
666
}
667
 
667
 
668
/* set brush or tile */
668
/* set brush or tile */
669
void obj_setbrush(objparm *pm)
669
void obj_setbrush(objparm *pm)
670
{
670
{
671
    char *pp;
671
  char *pp;
672
    FILE *inf;
672
  FILE *inf;
673
    gdImagePtr insimg;
673
  gdImagePtr insimg;
674
 
674
 
675
    pp=find_word_start(pm->str); *find_word_end(pp)=0;
675
  pp=find_word_start(pm->str); *find_word_end(pp)=0;
676
    inf=open4read(pp); if(inf==NULL) {
676
  inf=open4read(pp); if(inf==NULL) {
677
      fly_error("file_not_found"); return;
677
    fly_error("file_not_found"); return;
678
    }
678
  }
679
    insimg=gdImageCreateFromGif(inf); fclose(inf);
679
  insimg=gdImageCreateFromGif(inf); fclose(inf);
680
    if(insimg==NULL) {
680
  if(insimg==NULL) {
681
      fly_error("bad_gif"); return;
681
    fly_error("bad_gif"); return;
682
    }
682
  }
683
    if(pm->fill) {
683
  if(pm->fill) {
684
      gdImageSetTile(image,insimg); tiled=1; tileimg=insimg;
684
    gdImageSetTile(image,insimg); tiled=1; tileimg=insimg;
685
    }
685
  }
686
    else {
686
  else {
687
      gdImageSetBrush(image,insimg);brushed=1; brushimg=insimg;
687
    gdImageSetBrush(image,insimg);brushed=1; brushimg=insimg;
688
    }
688
  }
689
}
689
}
690
 
690
 
691
/* kill brush */
691
/* kill brush */
692
void obj_killbrush(objparm *pm)
692
void obj_killbrush(objparm *pm)
693
{
693
{
694
    if(brushimg) gdImageDestroy(brushimg);
694
  if(brushimg) gdImageDestroy(brushimg);
695
    brushed=0; brushimg=NULL;
695
  brushed=0; brushimg=NULL;
696
}
696
}
697
 
697
 
698
/* kill tile */
698
/* kill tile */
699
void obj_killtile(objparm *pm)
699
void obj_killtile(objparm *pm)
700
{
700
{
701
    if(tileimg) gdImageDestroy(tileimg);
701
  if(tileimg) gdImageDestroy(tileimg);
702
    tiled=0; tileimg=NULL;
702
  tiled=0; tileimg=NULL;
703
}
703
}
704
 
704
 
705
/* set style */
705
/* set style */
706
void obj_setstyle(objparm *pm)
706
void obj_setstyle(objparm *pm)
707
{
707
{
708
    int i,t;
708
  int i,t;
709
    t=pm->pcnt/3; if(t<=0) {
709
  t=pm->pcnt/3; if(t<=0) {
710
      fly_error("too_few_parms"); return;
710
    fly_error("too_few_parms"); return;
711
    }
711
  }
712
    for(i=0;i<t;i++) {
712
  for(i=0;i<t;i++) {
713
      if(pm->pd[3*i]<0 || pm->pd[3*i+1]<0 || pm->pd[3*i+2]<0)
713
    if(pm->pd[3*i]<0 || pm->pd[3*i+1]<0 || pm->pd[3*i+2]<0)
714
        pm->p[i]=gdTransparent;
714
      pm->p[i]=gdTransparent;
715
      else
715
    else
716
        pm->p[i]=getcolor(pm->pd[3*i],pm->pd[3*i+1],pm->pd[3*i+2]);
716
      pm->p[i]=getcolor(pm->pd[3*i],pm->pd[3*i+1],pm->pd[3*i+2]);
717
    }
717
  }
718
    gdImageSetStyle(image,pm->p,t); styled=1;
718
  gdImageSetStyle(image,pm->p,t); styled=1;
719
}
719
}
720
 
720
 
721
/* kill style */
721
/* kill style */
722
void obj_killstyle(objparm *pm)
722
void obj_killstyle(objparm *pm)
723
{
723
{
724
    styled=0;
724
  styled=0;
725
}
725
}
726
 
726
 
727
/* set transparent */
727
/* set transparent */
728
void obj_transp(objparm *pm)
728
void obj_transp(objparm *pm)
729
{
729
{
730
    gdImageColorTransparent(image,pm->color[0]);
730
  gdImageColorTransparent(image,pm->color[0]);
731
}
731
}
732
 
732
 
733
/* set interlace */
733
/* set interlace */
734
void obj_interlace(objparm *pm)
734
void obj_interlace(objparm *pm)
735
{
735
{
736
    gdImageInterlace(image,1);
736
  gdImageInterlace(image,1);
737
}
737
}
738
 
738
 
739
/* set linewidth */
739
/* set linewidth */
740
void obj_linewidth(objparm *pm)
740
void obj_linewidth(objparm *pm)
741
{
741
{
742
    if(pm->pd[0]<1 || pm->pd[0]>255) fly_error("bad_parms");
742
  if(pm->pd[0]<1 || pm->pd[0]>255) fly_error("bad_parms");
743
    else width=pm->pd[0];
743
  else width=pm->pd[0];
744
}
744
}
745
 
745
 
746
/* set crosshairsize */
746
/* set crosshairsize */
747
void obj_crosshairsize(objparm *pm)
747
void obj_crosshairsize(objparm *pm)
748
{
748
{
749
    if(pm->pd[0]<1 || pm->pd[0]>255) fly_error("bad_parms");
749
  if(pm->pd[0]<1 || pm->pd[0]>255) fly_error("bad_parms");
750
    else width2=pm->pd[0];
750
  else width2=pm->pd[0];
751
}
751
}
752
 
752
 
753
/* set x range */
753
/* set x range */
754
void obj_xrange(objparm *pm)
754
void obj_xrange(objparm *pm)
755
{
755
{
756
    double dd;
756
  double dd;
757
    dd=pm->pd[1]-pm->pd[0];
757
  dd=pm->pd[1]-pm->pd[0];
758
    xstart=pm->pd[0]; xscale=sizex/dd;
758
  xstart=pm->pd[0]; xscale=sizex/dd;
759
}
759
}
760
 
760
 
761
/* set y range */
761
/* set y range */
762
void obj_yrange(objparm *pm)
762
void obj_yrange(objparm *pm)
763
{
763
{
764
    double dd;
764
  double dd;
765
    dd=pm->pd[1]-pm->pd[0];
765
  dd=pm->pd[1]-pm->pd[0];
766
    ystart=pm->pd[1]; yscale=-sizey/dd;
766
  ystart=pm->pd[1]; yscale=-sizey/dd;
767
}
767
}
768
 
768
 
769
/* set x et y range */
769
/* set x et y range */
770
void obj_range(objparm *pm)
770
void obj_range(objparm *pm)
771
{
771
{
772
    double d1,d2;
772
  double d1,d2;
773
    d1=pm->pd[1]-pm->pd[0]; d2=pm->pd[3]-pm->pd[2];
773
  d1=pm->pd[1]-pm->pd[0]; d2=pm->pd[3]-pm->pd[2];
774
    xstart=pm->pd[0]; xscale=(sizex-1)/d1;
774
  xstart=pm->pd[0]; xscale=(sizex-1)/d1;
775
    ystart=pm->pd[3]; yscale=-(sizey-1)/d2;
775
  ystart=pm->pd[3]; yscale=-(sizey-1)/d2;
776
}
776
}
777
 
777
 
778
/* set t range */
778
/* set t range */
779
void obj_trange(objparm *pm)
779
void obj_trange(objparm *pm)
780
{
780
{
781
    /*double dd;
781
  /*double dd;
782
    dd=pm->pd[1]-pm->pd[0];*/
782
  dd=pm->pd[1]-pm->pd[0];*/
783
    tstart=pm->pd[0]; tend=pm->pd[1];
783
  tstart=pm->pd[0]; tend=pm->pd[1];
784
    tranged=1;
784
  tranged=1;
785
}
785
}
786
 
786
 
787
/* set tstep (plotting step) */
787
/* set tstep (plotting step) */
788
void obj_tstep(objparm *pm)
788
void obj_tstep(objparm *pm)
789
{
789
{
790
    int dd;
790
  int dd;
791
    dd=pm->pd[0];
791
  dd=pm->pd[0];
792
    if(dd<3) {
792
  if(dd<3) {
793
      fly_error("bad_step"); return;
793
    fly_error("bad_step"); return;
794
    }
794
  }
795
    if(dd>2000) dd=2000;
795
  if(dd>2000) dd=2000;
796
    tstep=dd;
796
  tstep=dd;
797
}
797
}
798
 
798
 
799
/* set plotjump (plot jump break threashold) */
799
/* set plotjump (plot jump break threashold) */
800
void obj_plotjump(objparm *pm)
800
void obj_plotjump(objparm *pm)
801
{
801
{
802
    int dd;
802
  int dd;
803
    dd=pm->pd[0];
803
  dd=pm->pd[0];
804
    if(dd<3) dd=3;
804
  if(dd<3) dd=3;
805
    if(dd>MAX_SIZE) dd=MAX_SIZE;
805
  if(dd>MAX_SIZE) dd=MAX_SIZE;
806
    plotjump=dd;
806
  plotjump=dd;
807
}
807
}
808
 
808
 
809
/* plot a curve, either parametric or explicit */
809
/* plot a curve, either parametric or explicit */
810
void _obj_plot(objparm *pm,int dash)
810
void _obj_plot(objparm *pm,int dash)
811
{
811
{
812
    int i,j,n,dist,xx,yy,varpos;
812
  int i,j,n,dist,xx,yy,varpos;
813
    char p1[MAX_LINELEN+1], p2[MAX_LINELEN+1];
813
  char p1[MAX_LINELEN+1], p2[MAX_LINELEN+1];
814
    char *varn, *pp;
814
  char *varn, *pp;
815
    double dc[2],t,v;
815
  double dc[2],t,v;
816
    int ic[2],oc[2];
816
  int ic[2],oc[2];
817
 
817
 
818
    n=itemnum(pm->str);
818
  n=itemnum(pm->str);
819
    if(n<1) {
819
  if(n<1) {
820
      fly_error("bad_parms"); return;
820
    fly_error("bad_parms"); return;
821
    }
821
  }
822
    fnd_item(pm->str,1,p1); fnd_item(pm->str,2,p2);
822
  fnd_item(pm->str,1,p1); fnd_item(pm->str,2,p2);
823
    if(n==1 && !tranged) v=sizex/xscale/tstep;
823
  if(n==1 && !tranged) v=sizex/xscale/tstep;
824
    else v=(tend-tstart)/tstep;
824
  else v=(tend-tstart)/tstep;
825
    if(n==1) varn="x"; else varn="t";
825
  if(n==1) varn="x"; else varn="t";
826
    for(pp=varchr(p1,varn); pp; pp=varchr(pp,varn)) {
826
  for(pp=varchr(p1,varn); pp; pp=varchr(pp,varn)) {
827
      string_modify(p1,pp,pp+strlen(varn),EV_T);
827
    string_modify(p1,pp,pp+strlen(varn),EV_T);
828
      pp+=strlen(EV_T);
828
    pp+=strlen(EV_T);
829
    }
829
  }
830
    for(pp=varchr(p2,varn); pp; pp=varchr(pp,varn)) {
830
  for(pp=varchr(p2,varn); pp; pp=varchr(pp,varn)) {
831
      string_modify(p2,pp,pp+strlen(varn),EV_T);
831
    string_modify(p2,pp,pp+strlen(varn),EV_T);
832
      pp+=strlen(EV_T);
832
      pp+=strlen(EV_T);
833
    }
833
  }
834
    varpos=eval_getpos(EV_T);
834
  varpos=eval_getpos(EV_T);
835
    if(varpos<0) return; /* unknown error */
835
  if(varpos<0) return; /* unknown error */
836
    evalue_compile(p1); evalue_compile(p2);
836
  evalue_compile(p1); evalue_compile(p2);
837
    if(vimg_enable) vimg_plotstart();
837
  if(vimg_enable) vimg_plotstart();
838
    for(i=j=0;i<=tstep;i++) {
838
  for(i=j=0;i<=tstep;i++) {
839
      if(n==1) {
839
    if(n==1) {
840
          if(tranged) t=tstart+i*v; else t=xstart+i*v;
840
      if(tranged) t=tstart+i*v; else t=xstart+i*v;
841
          eval_setval(varpos,t); dc[0]=t; dc[1]=strevalue(p1);
841
      eval_setval(varpos,t); dc[0]=t; dc[1]=strevalue(p1);
842
      }
842
    }
843
      else {
843
    else {
844
          t=tstart+i*v; eval_setval(varpos,t);
844
      t=tstart+i*v; eval_setval(varpos,t);
845
          dc[0]=strevalue(p1); dc[1]=strevalue(p2);
845
      dc[0]=strevalue(p1); dc[1]=strevalue(p2);
846
      }
846
    }
847
      if(!isfinite(dc[0]) || !isfinite(dc[1])) ic[0]=ic[1]=-BOUND;
847
    if(!isfinite(dc[0]) || !isfinite(dc[1])) ic[0]=ic[1]=-BOUND;
848
      else scale(dc,ic,1);
848
    else scale(dc,ic,1);
849
      if(vimg_enable) vimg_plot1 (scale_buf[0],scale_buf[1]);
849
    if(vimg_enable) vimg_plot1 (scale_buf[0],scale_buf[1]);
850
      if(j==0) {
850
    if(j==0) {
851
          gdImageSetPixel(image,ic[0],ic[1],pm->color[0]); j++;
851
      gdImageSetPixel(image,ic[0],ic[1],pm->color[0]); j++;
852
      }
852
    }
853
      else {
853
    else {
854
          xx=ic[0]-oc[0]; yy=ic[1]-oc[1];
854
      xx=ic[0]-oc[0]; yy=ic[1]-oc[1];
855
          dist=sqrt(xx*xx+yy*yy);
855
      dist=sqrt(xx*xx+yy*yy);
856
          if(dist>0) {
856
      if(dist>0) {
857
            if(dist>plotjump || dist==1)
857
        if(dist>plotjump || dist==1)
858
              gdImageSetPixel(image,ic[0],ic[1],pm->color[0]);
858
          gdImageSetPixel(image,ic[0],ic[1],pm->color[0]);
859
            else
859
        else
860
             if ( dash==1) {
860
          if ( dash==1)
861
              gdImageDashedLine(image,oc[0],oc[1],ic[0],ic[1],pm->color[0]);
861
            gdImageDashedLine(image,oc[0],oc[1],ic[0],ic[1],pm->color[0]);
862
              } else
862
          else
863
              {gdImageLine(image,oc[0],oc[1],ic[0],ic[1],pm->color[0]); }
863
            gdImageLine(image,oc[0],oc[1],ic[0],ic[1],pm->color[0]);
864
 
-
 
865
          }
864
      }
866
      }
865
    }
867
      memmove(oc,ic,sizeof(oc));
866
    memmove(oc,ic,sizeof(oc));
868
    }
867
  }
869
    if(vimg_enable) vimg_plotend();
868
  if(vimg_enable) vimg_plotend();
870
}
869
}
871
 
870
 
872
void obj_plot(objparm *pm) { _obj_plot( pm,0) ;}
871
void obj_plot(objparm *pm) { _obj_plot( pm,0) ;}
873
void obj_dplot(objparm *pm) { _obj_plot( pm,1) ; }
872
void obj_dplot(objparm *pm) { _obj_plot( pm,1) ; }
874
 
873
 
875
/* set levelcurve granularity */
874
/* set levelcurve granularity */
876
void obj_levelstep(objparm *pm)
875
void obj_levelstep(objparm *pm)
877
{
876
{
878
    int dd;
877
  int dd;
879
    dd=pm->pd[0];
878
  dd=pm->pd[0];
880
    if(dd<1) return;
879
  if(dd<1) return;
881
    if(dd>16) dd=16;
880
  if(dd>16) dd=16;
882
    lstep=dd;
881
  lstep=dd;
883
}
882
}
884
 
883
 
885
/* level curve */
884
/* level curve */
886
void obj_levelcurve(objparm *pm)
885
void obj_levelcurve(objparm *pm)
887
{
886
{
888
    char fn[MAX_LINELEN+1],tc[MAX_LINELEN+1];
887
  char fn[MAX_LINELEN+1],tc[MAX_LINELEN+1];
889
    int n,i;
888
  int n,i;
890
    double d;
889
  double d;
891
    leveldata *ld;
890
  leveldata *ld;
892
 
891
 
893
    ld=xmalloc(sizeof(leveldata)+16);
892
  ld=xmalloc(sizeof(leveldata)+16);
894
    ld->xname="x"; ld->yname="y";
893
  ld->xname="x"; ld->yname="y";
895
    ld->xsize=sizex; ld->ysize=sizey; ld->datacnt=0;
894
  ld->xsize=sizex; ld->ysize=sizey; ld->datacnt=0;
896
    ld->xrange[0]=xstart; ld->xrange[1]=sizex/xscale+xstart;
895
  ld->xrange[0]=xstart; ld->xrange[1]=sizex/xscale+xstart;
897
    ld->yrange[0]=sizey/yscale+ystart; ld->yrange[1]=ystart;
896
  ld->yrange[0]=sizey/yscale+ystart; ld->yrange[1]=ystart;
898
    ld->grain=lstep;
897
  ld->grain=lstep;
899
    fnd_item(pm->str,1,fn); ld->fn=fn;
898
  fnd_item(pm->str,1,fn); ld->fn=fn;
900
    n=itemnum(pm->str);
899
  n=itemnum(pm->str);
901
    if(n<=1) {ld->levelcnt=1; ld->levels[0]=0;}
900
  if(n<=1) {ld->levelcnt=1; ld->levels[0]=0;}
902
    else {
901
  else {
903
      if(n>LEVEL_LIM+1) n=LEVEL_LIM+1;
902
    if(n>LEVEL_LIM+1) n=LEVEL_LIM+1;
904
      for(i=0;i<n-1;i++) {
903
    for(i=0;i<n-1;i++) {
905
          fnd_item(pm->str,i+2,tc);
904
      fnd_item(pm->str,i+2,tc);
906
          d=strevalue(tc);
905
      d=strevalue(tc);
907
          if(isfinite(d)) ld->levels[i]=d; else ld->levels[i]=0;
906
      if(isfinite(d)) ld->levels[i]=d; else ld->levels[i]=0;
908
      }
-
 
909
      ld->levelcnt=n-1;
-
 
910
    }
-
 
911
    levelcurve(ld);
-
 
912
    for(i=0;i<ld->datacnt;i++) {
-
 
913
      gdImageSetPixel(image,ld->xdata[i],ld->ydata[i],pm->color[0]);
-
 
914
    }
907
    }
-
 
908
    ld->levelcnt=n-1;
-
 
909
  }
-
 
910
  levelcurve(ld);
-
 
911
  for(i=0;i<ld->datacnt;i++) {
-
 
912
    gdImageSetPixel(image,ld->xdata[i],ld->ydata[i],pm->color[0]);
-
 
913
  }
915
    free(ld);
914
  free(ld);
916
}
915
}
917
 
916
 
918
/* set animation step */
917
/* set animation step */
919
void obj_animstep(objparm *pm)
918
void obj_animstep(objparm *pm)
920
{
919
{
921
    animstep=pm->pd[0];
920
  animstep=pm->pd[0];
922
    setvar("animstep",pm->pd[0]);
921
  setvar("animstep",pm->pd[0]);
923
}
922
}
924
 
923
 
925
/* Starts a line counting */
924
/* Starts a line counting */
926
void obj_linecount(objparm *pm)
925
void obj_linecount(objparm *pm)
927
{
926
{
928
    linecnt=pm->pd[0];
927
  linecnt=pm->pd[0];
929
}
928
}
930
 
929
 
931
/* marks end of execution */
930
/* marks end of execution */
932
void obj_end(objparm *pm)
931
void obj_end(objparm *pm)
933
{
932
{
934
    fly_error("successful_end_of_execution");
933
  fly_error("successful_end_of_execution");
935
}
934
}
936
 
935
 
937
/* output */
936
/* output */
938
void obj_output(objparm *pm)
937
void obj_output(objparm *pm)
939
{
938
{
940
    char *p, namebuf[1024];
939
  char *p, namebuf[1024];
941
    p=find_word_start(pm->str); *find_word_end(p)=0;
940
  p=find_word_start(pm->str); *find_word_end(p)=0;
942
    snprintf(namebuf,sizeof(namebuf),"%s",imagefilename);
941
  snprintf(namebuf,sizeof(namebuf),"%s",imagefilename);
943
    snprintf(imagefilename,sizeof(imagefilename),"%s",p);
942
  snprintf(imagefilename,sizeof(imagefilename),"%s",p);
944
    output();
943
  output();
945
    snprintf(imagefilename,sizeof(imagefilename),"%s",namebuf);
944
  snprintf(imagefilename,sizeof(imagefilename),"%s",namebuf);
946
}
945
}
947
 
946
 
948
/* vimgfile */
947
/* vimgfile */
949
void obj_vimgfile(objparm *pm)
948
void obj_vimgfile(objparm *pm)
950
{
949
{
951
    char *p;
950
  char *p;
952
    p=find_word_start(pm->str); *find_word_end(p)=0;
951
  p=find_word_start(pm->str); *find_word_end(p)=0;
953
    snprintf(vimgfilename,sizeof(vimgfilename),"%s",p);
952
  snprintf(vimgfilename,sizeof(vimgfilename),"%s",p);
954
    if(vimg_ready) vimg_close();
953
  if(vimg_ready) vimg_close();
955
}
954
}
956
 
955
 
957
/* vimg enable/disable */
956
/* vimg enable/disable */
958
void obj_vimg(objparm *pm)
957
void obj_vimg(objparm *pm)
959
{
958
{
960
    vimg_enable=pm->pd[0];
959
  vimg_enable=pm->pd[0];
961
    if(vimg_enable>0 && vimg_ready==0) {
960
  if(vimg_enable>0 && vimg_ready==0) vimg_init();
962
      vimg_init();
-
 
963
    }
-
 
964
}
961
}
965
 
962
 
966
/* Set affine transformation */
963
/* Set affine transformation */
967
void obj_affine(objparm *pm)
964
void obj_affine(objparm *pm)
968
{
965
{
969
    int i;
966
  int i;
970
    for(i=0;i<4;i++) matrix[i]=pm->pd[i];
967
  for(i=0;i<4;i++) matrix[i]=pm->pd[i];
971
    transx=pm->pd[4]; transy=pm->pd[5];
968
  transx=pm->pd[4]; transy=pm->pd[5];
972
    transform=1;
969
  transform=1;
973
}
970
}
974
 
971
 
975
/* Set affine transformation */
972
/* Set affine transformation */
976
void obj_rotation(objparm *pm)
973
void obj_rotation(objparm *pm)
977
{
974
{
978
    double r;
975
  double r;
979
    r=M_PI*pm->pd[0]/180;
976
  r=M_PI*pm->pd[0]/180;
980
    matrix[0]=matrix[3]=cos(r);
977
  matrix[0]=matrix[3]=cos(r);
981
    matrix[1]=-sin(r); matrix[2]=sin(r);
978
  matrix[1]=-sin(r); matrix[2]=sin(r);
982
    transform=1;
979
  transform=1;
983
}
980
}
984
 
981
 
985
/* Set linear transformation */
982
/* Set linear transformation */
986
void obj_linear(objparm *pm)
983
void obj_linear(objparm *pm)
987
{
984
{
988
    int i;
985
  int i;
989
    for(i=0;i<4;i++) matrix[i]=pm->pd[i];
986
  for(i=0;i<4;i++) matrix[i]=pm->pd[i];
990
    transform=1;
987
  transform=1;
991
}
988
}
992
 
989
 
993
/* Set translation transformation */
990
/* Set translation transformation */
994
void obj_translation(objparm *pm)
991
void obj_translation(objparm *pm)
995
{
992
{
996
    transx=pm->pd[0]; transy=pm->pd[1];
993
  transx=pm->pd[0]; transy=pm->pd[1];
997
}
994
}
998
 
995
 
999
/* kill affine transformation */
996
/* kill affine transformation */
1000
void obj_killaffine(objparm *pm)
997
void obj_killaffine(objparm *pm)
1001
{
998
{
1002
    matrix[0]=matrix[3]=1;
999
  matrix[0]=matrix[3]=1;
1003
    matrix[1]=matrix[2]=transx=transy=0;
1000
  matrix[1]=matrix[2]=transx=transy=0;
1004
    transform=0;
1001
  transform=0;
1005
}
1002
}
1006
 
1003
 
1007
/* kill affine transformation */
1004
/* kill affine transformation */
1008
void obj_killlinear(objparm *pm)
1005
void obj_killlinear(objparm *pm)
1009
{
1006
{
1010
    matrix[0]=matrix[3]=1;
1007
  matrix[0]=matrix[3]=1;
1011
    matrix[1]=matrix[2]=0;
1008
  matrix[1]=matrix[2]=0;
1012
    transform=0;
1009
  transform=0;
1013
}
1010
}
1014
 
1011
 
1015
/* kill affine transformation */
1012
/* kill affine transformation */
1016
void obj_killtranslation(objparm *pm)
1013
void obj_killtranslation(objparm *pm)
1017
{
1014
{
1018
    transx=transy=0;
1015
  transx=transy=0;
1019
}
1016
}
1020
 
1017
 
1021
/***** Les modifs de Jean-Christophe Leger Fev 2006 *****/
1018
/***** Les modifs de Jean-Christophe Leger Fev 2006 *****/
1022
 
1019
 
1023
/* arguments: un numero de matrice entre 1 et JC_NB_MATRICES, une liste de 4 nombres reels pour la matrice */
1020
/* arguments: un numero de matrice entre 1 et JC_NB_MATRICES, une liste de 4 nombres reels pour la matrice */
1024
void obj_setmatrix(objparm *pm)
1021
void obj_setmatrix(objparm *pm)
1025
{
1022
{
1026
  int nummatrix = (int) (pm->pd[0]);
1023
  int nummatrix = (int) (pm->pd[0]);
1027
  if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
1024
  if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
1028
    fly_error("bad_matrix_number");
1025
    fly_error("bad_matrix_number");
1029
    return;
1026
    return;
1030
  }
1027
  }
1031
  matrices_pavage[nummatrix][0] = pm->pd[1];
1028
  matrices_pavage[nummatrix][0] = pm->pd[1];
1032
  matrices_pavage[nummatrix][1] = pm->pd[2];
1029
  matrices_pavage[nummatrix][1] = pm->pd[2];
1033
  matrices_pavage[nummatrix][2] = pm->pd[3];
1030
  matrices_pavage[nummatrix][2] = pm->pd[3];
1034
  matrices_pavage[nummatrix][3] = pm->pd[4];
1031
  matrices_pavage[nummatrix][3] = pm->pd[4];
1035
}
1032
}
1036
 
1033
 
1037
/* arguments: un numero de matrice entre 1 et JC_NB_MATRICES */
1034
/* arguments: un numero de matrice entre 1 et JC_NB_MATRICES */
1038
void obj_resetmatrix(objparm *pm)
1035
void obj_resetmatrix(objparm *pm)
1039
{
1036
{
1040
  int nummatrix = (int) (pm->pd[0]);
1037
  int nummatrix = (int) (pm->pd[0]);
1041
  if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
1038
  if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
1042
    fly_error("bad_matrix_number");
1039
    fly_error("bad_matrix_number");
1043
    return;
1040
    return;
1044
  }
1041
  }
1045
  matrices_pavage[nummatrix][0] = 1;
1042
  matrices_pavage[nummatrix][0] = 1;
1046
  matrices_pavage[nummatrix][1] = 0;
1043
  matrices_pavage[nummatrix][1] = 0;
1047
  matrices_pavage[nummatrix][2] = 0;
1044
  matrices_pavage[nummatrix][2] = 0;
1048
  matrices_pavage[nummatrix][3] = 1;
1045
  matrices_pavage[nummatrix][3] = 1;
1049
 
1046
 
1050
}
1047
}
1051
/* arguments: un numero de vecteur entre 1 et JC_NB_MATRICES, une liste de 2 nombres reels pour le vecteur */
1048
/* arguments: un numero de vecteur entre 1 et JC_NB_MATRICES, une liste de 2 nombres reels pour le vecteur */
1052
void obj_setvector(objparm *pm)
1049
void obj_setvector(objparm *pm)
1053
{
1050
{
1054
  int nummatrix = (int) (pm->pd[0]);
1051
  int nummatrix = (int) (pm->pd[0]);
1055
  if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
1052
  if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
Line 1060... Line 1057...
1060
  vecteurs_pavage[nummatrix][1] = pm->pd[2];
1057
  vecteurs_pavage[nummatrix][1] = pm->pd[2];
1061
}
1058
}
1062
 
1059
 
1063
/* arguments: un numero de matrice entre 1 et JC_NB_MATRICES */
1060
/* arguments: un numero de matrice entre 1 et JC_NB_MATRICES */
1064
void obj_resetvector(objparm *pm)
1061
void obj_resetvector(objparm *pm)
1065
{
1062
{
1066
  int nummatrix = (int) (pm->pd[0]);
1063
  int nummatrix = (int) (pm->pd[0]);
1067
  if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
1064
  if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
1068
    fly_error("bad_vector_number");
1065
    fly_error("bad_vector_number");
1069
    return;
1066
    return;
1070
  }
1067
  }
1071
  vecteurs_pavage[nummatrix][0] = 0;
1068
  vecteurs_pavage[nummatrix][0] = 0;
1072
  vecteurs_pavage[nummatrix][1] = 0;
1069
  vecteurs_pavage[nummatrix][1] = 0;
1073
}
1070
}
1074
 
1071
 
1075
/* arguments: un numero de vecteur entre 1 et JC_NB_MATRICES, une liste de 6 nombres reels pour la matrice et le vecteur */
1072
/* arguments: un numero de vecteur entre 1 et JC_NB_MATRICES, une liste de 6 nombres reels pour la matrice et le vecteur */
1076
void obj_settransform(objparm *pm)
1073
void obj_settransform(objparm *pm)
1077
{
1074
{
1078
  int nummatrix = (int) (pm->pd[0]);
1075
  int nummatrix = (int) (pm->pd[0]);
1079
  if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
1076
  if((nummatrix < 1) ||(nummatrix>JC_NB_MATRICES)) {
1080
    fly_error("bad_vector_number");
1077
    fly_error("bad_vector_number");
1081
    return;
1078
    return;
1082
  }
1079
  }
1083
  matrices_pavage[nummatrix][0] = pm->pd[1];
1080
  matrices_pavage[nummatrix][0] = pm->pd[1];
1084
  matrices_pavage[nummatrix][1] = pm->pd[2];
1081
  matrices_pavage[nummatrix][1] = pm->pd[2];
Line 1101... Line 1098...
1101
  vecteurs_pavage[nummatrix][1] = 0;
1098
  vecteurs_pavage[nummatrix][1] = 0;
1102
  matrices_pavage[nummatrix][0] = 1;
1099
  matrices_pavage[nummatrix][0] = 1;
1103
  matrices_pavage[nummatrix][1] = 0;
1100
  matrices_pavage[nummatrix][1] = 0;
1104
  matrices_pavage[nummatrix][2] = 0;
1101
  matrices_pavage[nummatrix][2] = 0;
1105
  matrices_pavage[nummatrix][3] = 1;
1102
  matrices_pavage[nummatrix][3] = 1;
1106
}
1103
}
1107
 
1104
 
1108
/* arguments: une liste de 6 nombres reels pour les coordonnees de l'origine et des vecteurs de base */
1105
/* arguments: une liste de 6 nombres reels pour les coordonnees de l'origine et des vecteurs de base */
1109
void obj_setparallelogram(objparm *pm)
1106
void obj_setparallelogram(objparm *pm)
1110
{
1107
{
1111
  int i;
1108
  int i;
1112
  for(i=0;i<6;i++)  parallogram_fonda[i]=pm->pd[i];
1109
  for(i=0;i<6;i++)  parallogram_fonda[i]=pm->pd[i];
Line 1119... Line 1116...
1119
  parallogram_fonda[1]=0;
1116
  parallogram_fonda[1]=0;
1120
  parallogram_fonda[2]=100;
1117
  parallogram_fonda[2]=100;
1121
  parallogram_fonda[3]=0;
1118
  parallogram_fonda[3]=0;
1122
  parallogram_fonda[4]=0;
1119
  parallogram_fonda[4]=0;
1123
  parallogram_fonda[5]=100;
1120
  parallogram_fonda[5]=100;
1124
}
1121
}
1125
 
1122
 
1126
/* argument : la liste des numeros des matrices a faire agir, le nom du fichier de l'image a inclure */
1123
/* argument : la liste des numeros des matrices a faire agir, le nom du fichier de l'image a inclure */
1127
void obj_multicopy(objparm *pm)
1124
void obj_multicopy(objparm *pm)
1128
{
1125
{
1129
    char *pp,*pe,*cptr;
1126
  char *pp,*pe,*cptr;
1130
    FILE *inf;
1127
  FILE *inf;
1131
    gdImagePtr insimg;
1128
  gdImagePtr insimg;
1132
    int i,j;
1129
  int i,j;
1133
    int imax,jmax;
1130
  int imax,jmax;
1134
    int c; /* la couleur reperee */
1131
  int c; /* la couleur reperee */
1135
    int mat;
1132
  int mat;
1136
    int nummatrices[JC_NB_MATRICES];
1133
  int nummatrices[JC_NB_MATRICES];
1137
    double pt[2]; /* les coordonnees math. du point repere dans le parallelogramme */
1134
  double pt[2]; /* les coordonnees math. du point repere dans le parallelogramme */
1138
    double ptr[2]; /* les coordonnees math. du point transforme */
1135
  double ptr[2]; /* les coordonnees math. du point transforme */
1139
    int pti[2]; /* les coordonnees img du point a placer sur le canevas */
1136
  int pti[2]; /* les coordonnees img du point a placer sur le canevas */
1140
    int t;
1137
  int t;
1141
    /* gestion palette de couleur de l'image a inserer */
1138
  /* gestion palette de couleur de l'image a inserer */
1142
    int colorMap[gdMaxColors];
1139
  int colorMap[gdMaxColors];
1143
    int comptmat=0; /* combien de matrices en tout ? */
1140
  int comptmat=0; /* combien de matrices en tout ? */
1144
 
1141
 
1145
    for (i=0; (i<gdMaxColors); i++) {
1142
  for (i=0; (i<gdMaxColors); i++) {
1146
      colorMap[i] = (-1);
1143
    colorMap[i] = (-1);
1147
    }
1144
  }
1148
 
1145
 
1149
    /* Gestion des parametres la liste est censee finir avec le nom du fichier */
1146
  /* Gestion des parametres la liste est censee finir avec le nom du fichier */
1150
    t=pm->pcnt-1; /* il faut enlever le nom de fichier ! c'est le nombre de parametres en plus */
1147
  t=pm->pcnt-1; /* il faut enlever le nom de fichier ! c'est le nombre de parametres en plus */
1151
    pp=find_word_start(pm->str);
1148
  pp=find_word_start(pm->str);
1152
    /* visiblement find_word_start n'arrive pas a trouver le dernier mot dans un contexte ou le nombre de parameters est variable
1149
  /* visiblement find_word_start n'arrive pas a trouver le dernier mot dans un contexte ou le nombre de parameters est variable
1153
     * on cherche donc l'emplacement de la derniere virgule:
1150
     * on cherche donc l'emplacement de la derniere virgule:
1154
     * il y en a une car t>0, on retrouve ensuite le debut de mot
1151
     * il y en a une car t>0, on retrouve ensuite le debut de mot
1155
     */
1152
     */
1156
    for(pe=pp;*pe!=0;pe++);/* trouve la fin de la chaine */
1153
  for(pe=pp;*pe!=0;pe++);/* trouve la fin de la chaine */
1157
    if(t>0){
1154
  if(t>0){
1158
      for(cptr = pe; cptr > pp && *cptr != ','; cptr--);
1155
    for(cptr = pe; cptr > pp && *cptr != ','; cptr--);
1159
      pp=find_word_start(cptr+1);
1156
    pp=find_word_start(cptr+1);
1160
    }
1157
  }
1161
    pe=find_word_end(pp);*pe=0; /* strip junk final */
1158
  pe=find_word_end(pp);*pe=0; /* strip junk final */
1162
    //      printf("pp contient %s\n",pp);
1159
  //      printf("pp contient %s\n",pp);
1163
 
1160
 
1164
 
1161
 
1165
    inf=open4read(pp);
1162
  inf=open4read(pp);
1166
    if(inf==NULL) {
1163
  if(inf==NULL) {
1167
      fly_error("file_not_exist"); return;
1164
    fly_error("file_not_exist"); return;
1168
    }
1165
  }
1169
    insimg=gdImageCreateFromGif(inf); fclose(inf);
1166
  insimg=gdImageCreateFromGif(inf); fclose(inf);
1170
    if(insimg==NULL) {
1167
  if(insimg==NULL) {
1171
      fly_error("bad_gif"); return;
1168
    fly_error("bad_gif"); return;
1172
    }
1169
  }
1173
 
1170
 
1174
/* On recupere les numeros des matrices/vecteurs a faire agir,
1171
  /* On recupere les numeros des matrices/vecteurs a faire agir,
1175
 * s'il n'y en a pas, on les fait toutes agir
1172
    * s'il n'y en a pas, on les fait toutes agir
1176
 */
1173
  */
1177
    for(i=0;i<t && i< JC_NB_MATRICES;i++) {
1174
  for(i=0;i<t && i< JC_NB_MATRICES;i++) {
1178
      if(pm->pd[i]>=1 && pm->pd[i]<=JC_NB_MATRICES){
1175
    if(pm->pd[i]>=1 && pm->pd[i]<=JC_NB_MATRICES){
1179
        nummatrices[comptmat] = pm->pd[i];
1176
      nummatrices[comptmat] = pm->pd[i];
1180
        comptmat++;
1177
      comptmat++;
1181
      }
-
 
1182
    }
-
 
1183
    if(t<=0){
-
 
1184
      for(i=0;i<JC_NB_MATRICES;i++) {
-
 
1185
        nummatrices[i] = i+1;
-
 
1186
      }
-
 
1187
      comptmat=JC_NB_MATRICES;
-
 
1188
    }
1178
    }
-
 
1179
  }
-
 
1180
  if(t<=0){
-
 
1181
    for(i=0;i<JC_NB_MATRICES;i++) {
-
 
1182
      nummatrices[i] = i+1;
-
 
1183
    }
-
 
1184
    comptmat=JC_NB_MATRICES;
-
 
1185
  }
-
 
1186
 
1189
 
1187
 
-
 
1188
  imax = gdImageSX(insimg);
-
 
1189
  jmax = gdImageSY(insimg);
1190
 
1190
 
1191
    imax = gdImageSX(insimg);
-
 
1192
    jmax = gdImageSY(insimg);
-
 
1193
 
-
 
1194
    for(i=0;i<imax;i++){
1191
  for(i=0;i<imax;i++){
1195
      for(j=0;j<jmax;j++){
1192
    for(j=0;j<jmax;j++){
1196
        int nc;
1193
      int nc;
1197
        c=gdImageGetPixel(insimg,i,j);
1194
      c=gdImageGetPixel(insimg,i,j);
1198
/* Le code suivant est une copie du code dans gdImageCopy  Added 7/24/95: support transparent copies */
1195
      /* Le code suivant est une copie du code dans gdImageCopy  Added 7/24/95: support transparent copies */
1199
        if (gdImageGetTransparent(insimg) != c) {
1196
      if (gdImageGetTransparent(insimg) != c) {
1200
/* Have we established a mapping for this color? */
1197
        /* Have we established a mapping for this color? */
1201
          if (colorMap[c] == (-1)) {
1198
        if (colorMap[c] == (-1)) {
1202
/* If it's the same image, mapping is trivial, dans notre cas ca n'arrive jamais... */
1199
          /* If it's the same image, mapping is trivial, dans notre cas ca n'arrive jamais... */
1203
            if (image == insimg) {
1200
          if (image == insimg) {
1204
              nc = c;
1201
            nc = c;
1205
            } else {
1202
          } else {
1206
/* First look for an exact match */
1203
            /* First look for an exact match */
1207
              nc = gdImageColorExact(image,
1204
            nc = gdImageColorExact(image,
1208
                     insimg->red[c], insimg->green[c],
1205
                   insimg->red[c], insimg->green[c],
-
 
1206
                           insimg->blue[c]);
-
 
1207
          }
-
 
1208
          if (nc == (-1)) {
-
 
1209
          /* No, so try to allocate it */
-
 
1210
            nc = gdImageColorAllocate(image,
-
 
1211
                             insimg->red[c], insimg->green[c],
1209
                             insimg->blue[c]);
1212
                             insimg->blue[c]);
1210
           }
1213
             /* If we're out of colors, go for the closest color */
1211
           if (nc == (-1)) {
1214
            if (nc == (-1)) {
1212
/* No, so try to allocate it */
-
 
1213
             nc = gdImageColorAllocate(image,
1215
              nc = gdImageColorClosest(image,
1214
                              insimg->red[c], insimg->green[c],
1216
                              insimg->red[c], insimg->green[c],
1215
                              insimg->blue[c]);
1217
                              insimg->blue[c]);
1216
/* If we're out of colors, go for the closest color */
-
 
1217
             if (nc == (-1)) {
-
 
1218
               nc = gdImageColorClosest(image,
-
 
1219
                               insimg->red[c], insimg->green[c],
-
 
1220
                               insimg->blue[c]);
-
 
1221
             }
1218
            }
1222
           }
1219
          }
1223
           colorMap[c] = nc;
1220
          colorMap[c] = nc;
1224
         }
1221
        }
1225
 
1222
 
1226
         pt[0]= i*(parallogram_fonda[2])/(imax-1)+(jmax-j)*(parallogram_fonda[4])/(jmax-1)+parallogram_fonda[0];
1223
        pt[0]= i*(parallogram_fonda[2])/(imax-1)+(jmax-j)*(parallogram_fonda[4])/(jmax-1)+parallogram_fonda[0];
1227
         pt[1]= i*(parallogram_fonda[3])/(imax-1)+(jmax-j)*(parallogram_fonda[5])/(jmax-1)+parallogram_fonda[1];
1224
        pt[1]= i*(parallogram_fonda[3])/(imax-1)+(jmax-j)*(parallogram_fonda[5])/(jmax-1)+parallogram_fonda[1];
1228
         for(mat=0;mat<comptmat;mat++){
1225
        for(mat=0;mat<comptmat;mat++){
1229
          double *matricecourante = matrices_pavage[nummatrices[mat]];
1226
          double *matricecourante = matrices_pavage[nummatrices[mat]];
1230
          double *vecteurcourant = vecteurs_pavage[nummatrices[mat]];
1227
          double *vecteurcourant = vecteurs_pavage[nummatrices[mat]];
1231
          ptr[0] = matricecourante[0]*pt[0]+matricecourante[1]*pt[1]+vecteurcourant[0];
1228
          ptr[0] = matricecourante[0]*pt[0]+matricecourante[1]*pt[1]+vecteurcourant[0];
1232
          ptr[1] = matricecourante[2]*pt[0]+matricecourante[3]*pt[1]+vecteurcourant[1];
1229
          ptr[1] = matricecourante[2]*pt[0]+matricecourante[3]*pt[1]+vecteurcourant[1];
1233
          scale(ptr,pti,1);
1230
          scale(ptr,pti,1);
1234
          gdImageSetPixel(image,pti[0],pti[1],colorMap[c]);
1231
          gdImageSetPixel(image,pti[0],pti[1],colorMap[c]);
1235
         }
1232
        }
1236
       }
-
 
1237
      }
1233
      }
1238
    }
1234
    }
-
 
1235
  }
1239
    gdImageDestroy(insimg);
1236
  gdImageDestroy(insimg);
1240
}
1237
}
1241
 
1238
 
1242
/**** Fin modifs JC Fev 06 ******/
1239
/**** Fin modifs JC Fev 06 ******/
1243
 
1240
 
1244
/* get color from value */
1241
/* get color from value */
1245
int calc_color(char *p, struct objtab *o)
1242
int calc_color(char *p, struct objtab *o)
1246
{
1243
{
1247
    int k, cc[3];
1244
  int k, cc[3];
1248
    char buf[MAX_LINELEN+1];
1245
  char buf[MAX_LINELEN+1];
1249
    for(k=0;k<3;k++) {
1246
  for(k=0;k<3;k++) {
1250
      fnd_item(p,k+1,buf);
1247
    fnd_item(p,k+1,buf);
1251
      cc[k]=strevalue(buf);
1248
    cc[k]=strevalue(buf);
1252
    }
1249
  }
1253
    collapse_item(p,3);
1250
  collapse_item(p,3);
1254
    if(cc[0]==-1 && cc[1]==-1 && cc[2]==-255) {
1251
  if(cc[0]==-1 && cc[1]==-1 && cc[2]==-255) {
1255
 
1252
 
1256
      if(brushed && o->subst&1) return gdBrushed;
1253
    if(brushed && o->subst&1) return gdBrushed;
1257
      else return color_black;
1254
    else return color_black;
1258
    }
1255
  }
1259
    if(cc[0]==-1 && cc[1]==-255 && cc[2]==-1) {
1256
  if(cc[0]==-1 && cc[1]==-255 && cc[2]==-1) {
1260
      if(styled && o->subst&2)  return gdStyled;
1257
    if(styled && o->subst&2)  return gdStyled;
1261
      else return color_black;
1258
    else return color_black;
1262
    }
1259
  }
1263
    if(cc[0]==-255 && cc[1]==-1 && cc[2]==-1) {
1260
  if(cc[0]==-255 && cc[1]==-1 && cc[2]==-1) {
1264
      if(tiled && o->fill_tag==1)  return gdTiled;
1261
    if(tiled && o->fill_tag==1)  return gdTiled;
1265
      else return color_black;
1262
    else return color_black;
1266
    }
1263
  }
1267
    return getcolor(cc[0],cc[1],cc[2]);
1264
  return getcolor(cc[0],cc[1],cc[2]);
1268
}
1265
}
1269
 
1266
 
1270
/* Routine to parse parameters */
1267
/* Routine to parse parameters */
1271
int parse_parms(char *p,objparm *pm,struct objtab *o)
1268
int parse_parms(char *p,objparm *pm,struct objtab *o)
1272
{
1269
{
1273
    char buf[MAX_LINELEN+1];
1270
  char buf[MAX_LINELEN+1];
1274
    char *p1, *p2;
1271
  char *p1, *p2;
1275
    int j,t,c,c1,c2;
1272
  int j,t,c,c1,c2;
1276
 
1273
 
1277
    c=o->color_pos;c1=c2=0;
1274
  c=o->color_pos;c1=c2=0;
1278
    pm->color[0]=pm->color[1]=0;
1275
  pm->color[0]=pm->color[1]=0;
1279
    if(c>0) c1=c;
1276
  if(c>0) c1=c;
1280
    if(c<0) c2=-c;
1277
  if(c<0) c2=-c;
1281
    c=c1+c2;
1278
  c=c1+c2;
1282
    t=itemnum(p);if(t<o->required_parms+3*c) return -1;
1279
  t=itemnum(p);if(t<o->required_parms+3*c) return -1;
1283
    if(c1>0 && t>o->required_parms+3*c) t=o->required_parms+3*c;
1280
  if(c1>0 && t>o->required_parms+3*c) t=o->required_parms+3*c;
1284
    pm->pcnt=t-3*c;
1281
  pm->pcnt=t-3*c;
1285
    if(pm->pcnt>MAX_PARMS) pm->pcnt=MAX_PARMS;
1282
  if(pm->pcnt>MAX_PARMS) pm->pcnt=MAX_PARMS;
1286
    if(c2>0) {
1283
  if(c2>0) {
1287
      for(j=0;j<2 && j<c2; j++) pm->color[j]=calc_color(p,o);
1284
    for(j=0;j<2 && j<c2; j++) pm->color[j]=calc_color(p,o);
1288
    }
1285
  }
1289
    snprintf(buf,sizeof(buf),"%s",p);
1286
  snprintf(buf,sizeof(buf),"%s",p);
1290
    for(j=0, p1=buf; j<pm->pcnt; j++, p1=p2) {
1287
  for(j=0, p1=buf; j<pm->pcnt; j++, p1=p2) {
1291
      p2=find_item_end(p1); if(*p2) *p2++=0;
1288
    p2=find_item_end(p1); if(*p2) *p2++=0;
1292
      p1=find_word_start(p1);
1289
    p1=find_word_start(p1);
1293
      if(*p1) pm->pd[j]=strevalue(p1); else pm->pd[j]=0;
1290
    if(*p1) pm->pd[j]=strevalue(p1); else pm->pd[j]=0;
1294
      if(!isfinite(pm->pd[j])) {
1291
    if(!isfinite(pm->pd[j])) {
1295
          if(j<o->required_parms) return -1;
1292
        if(j<o->required_parms) return -1;
1296
          else {pm->pd[j]=0;break;}
1293
        else {pm->pd[j]=0;break;}
1297
      }
-
 
1298
    }
1294
    }
-
 
1295
  }
1299
    collapse_item(p,o->required_parms);
1296
  collapse_item(p,o->required_parms);
1300
    if(c1>0) {
1297
  if(c1>0) {
1301
      for(j=0;j<c1 && j<2; j++) pm->color[j]=calc_color(p,o);
1298
    for(j=0;j<c1 && j<2; j++) pm->color[j]=calc_color(p,o);
1302
    }
1299
  }
1303
    if(width>1 && o->subst&1 && pm->color[0]!=gdBrushed
1300
  if(width>1 && o->subst&1 && pm->color[0]!=gdBrushed
1304
       && pm->color[0]!=gdStyled && pm->color[0]!=gdTiled) {
1301
      && pm->color[0]!=gdStyled && pm->color[0]!=gdTiled) {
1305
      pm->color[1]=pm->color[0];
1302
    pm->color[1]=pm->color[0];
1306
      pm->color[0]=widthcolor(width,pm->color[0]);
1303
    pm->color[0]=widthcolor(width,pm->color[0]);
1307
    }
1304
  }
1308
    pm->fill=o->fill_tag;
1305
  pm->fill=o->fill_tag;
1309
    ovlstrcpy(pm->str,p); return 0;
1306
  ovlstrcpy(pm->str,p); return 0;
1310
}
1307
}
1311
 
1308
 
1312
/* Create the struct objparm pm corresponding to the objparm p
1309
/* Create the struct objparm pm corresponding to the objparm p
1313
 * Execute a command. Returns 0 if OK.
1310
 * Execute a command. Returns 0 if OK.
1314
 */
1311
 */
1315
int obj_main(char *p)
1312
int obj_main(char *p)
1316
{
1313
{
1317
    int i;
1314
  int i;
1318
    char *pp,*name,*pt;
1315
  char *pp,*name,*pt;
1319
    char tbuf2[MAX_LINELEN+1];
1316
  char tbuf2[MAX_LINELEN+1];
1320
    struct objparm pm;
1317
  struct objparm pm;
1321
 
1318
 
1322
    p=find_word_start(p);
1319
  p=find_word_start(p);
1323
    if(*p==exec_prefix_char || *p==0) return 0; /* comment */
1320
  if(*p==exec_prefix_char || *p==0) return 0; /* comment */
1324
    name=p;
1321
  name=p;
1325
    pp=find_name_end(p);
1322
  pp=find_name_end(p);
1326
    pt=find_word_start(pp); if(*pt=='=') *pt=' ';
1323
  pt=find_word_start(pp); if(*pt=='=') *pt=' ';
1327
    if(*pt==':' && *(pt+1)=='=') *pt=*(pt+1)=' ';
1324
  if(*pt==':' && *(pt+1)=='=') *pt=*(pt+1)=' ';
1328
    pp=find_word_end(p);
1325
  pp=find_word_end(p);
1329
    if(*pp!=0) {
1326
  if(*pp!=0) {
1330
      *(pp++)=0; pp=find_word_start(pp);
1327
    *(pp++)=0; pp=find_word_start(pp);
1331
    }
1328
  }
1332
    if(strlen(p)==1 || (strlen(p)==2 && isdigit(*(p+1)))) {
1329
  if(strlen(p)==1 || (strlen(p)==2 && isdigit(*(p+1)))) {
1333
      setvar(p,strevalue(pp)); return 0;
1330
    setvar(p,strevalue(pp)); return 0;
1334
    }
1331
  }
1335
/* search the number of the object */
1332
  /* search the number of the object */
1336
    i=search_list(objtab,obj_no,sizeof(objtab[0]),name);
1333
  i=search_list(objtab,obj_no,sizeof(objtab[0]),name);
1337
    if(i<0) {
1334
  if(i<0) {
1338
      fly_error("bad_cmd"); return 1;
1335
    fly_error("bad_cmd"); return 1;
1339
    }
1336
  }
1340
    if(image==NULL && (objtab[i].color_pos || objtab[i].required_parms>2)) {
1337
  if(image==NULL && (objtab[i].color_pos || objtab[i].required_parms>2)) {
1341
      fly_error("image_not_defined"); return 1;
1338
    fly_error("image_not_defined"); return 1;
1342
    }
1339
  }
1343
    ovlstrcpy(tbuf2,pp);
1340
  ovlstrcpy(tbuf2,pp);
1344
    if(objtab[i].color_pos || objtab[i].routine==obj_setstyle) {
1341
  if(objtab[i].color_pos || objtab[i].routine==obj_setstyle) {
1345
      substit(tbuf2);
1342
    substit(tbuf2);
1346
    }
1343
  }
1347
    if(parse_parms(tbuf2,&pm,objtab+i)!=0) fly_error("bad_parms");
1344
  if(parse_parms(tbuf2,&pm,objtab+i)!=0) fly_error("bad_parms");
1348
    else objtab[i].routine(&pm);
1345
  else objtab[i].routine(&pm);
1349
    return 0;
1346
  return 0;
1350
}
1347
}
1351
 
-