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