/[opencvs]/eyes/tilify.c
ViewVC logotype

Contents of /eyes/tilify.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations)
Thu Sep 24 02:50:12 2015 UTC (2 years, 6 months ago) by hib
Branch: MAIN
CVS Tags: HEAD
Changes since 1.11: +6 -5 lines
File MIME type: text/plain
Adjustments
1
2
3
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <math.h>
8
9 #include "util.h"
10
11 /* This will tile an image based on finding the best contrast between the 4 areas
12 based on a range up to 30 percent from one area to another.
13 */
14
15
16 //define SCALE
17 /* special - to scale up the picture to something really really big */
18
19 #define min(a,b) ((a)<(b)?(a):(b))
20 #define max(a,b) ((a)>(b)?(a):(b))
21
22 struct speed {
23 /* the following are for speed */
24 int xmin;
25 int ymin;
26 int xmax;
27 int ymax;
28 double one_over_vertys[4];
29 double vertx[4];
30 double verty[4];
31 };
32
33
34 struct square {
35 int x1;
36 int y1;
37 int x2;
38 int y2;
39 int x3;
40 int y3;
41 int x4;
42 int y4;
43 struct square *upper_left_sub;
44 struct square *upper_right_sub;
45 struct square *lower_left_sub;
46 struct square *lower_right_sub;
47 struct square *above;
48 struct square *below;
49 struct square *left;
50 struct square *right;
51 struct square *parent;
52 int r;
53 int g;
54 int b;
55 struct speed speed;
56 };
57
58
59 struct square squares[1048576];
60 int square_count = 0;
61
62
63 /* stoled from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
64 But modified it to better handle the slope=0
65 */
66 inline int pnpoly(int nvert, double *vertx, double *verty, double testx, double testy)
67 {
68 int i, j, c = 0;
69 for (i = 0, j = nvert-1; i < nvert; j = i++) {
70 if ( ((verty[i]>testy) != (verty[j]>testy)) &&
71 (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
72 c = !c;
73 }
74 return c;
75 }
76
77 inline int some_inside2(int x,int y,struct speed speed) {
78 double testx,testy;
79 int i, j, c = 0;
80 testx=x;
81 testy=y;
82 for (i = 0, j = 3; i < 4; j = i++) {
83 if ( ((speed.verty[i]>testy) != (speed.verty[j]>testy)) &&
84 (testx < (speed.vertx[j]-speed.vertx[i]) * (testy-speed.verty[i])
85 * (speed.one_over_vertys[i]) + speed.vertx[i]) )
86 c = !c;
87 }
88 return c;
89 }
90
91 inline int some_inside1(int x,int y,struct speed speed) {
92 double testx,testy;
93 int i, j, c = 0;
94 if ((x<speed.xmin)||(x>=speed.xmax)||(y<speed.ymin)||(y>speed.ymax)) return 0;
95 testx=x;
96 testy=y;
97 for (i = 0, j = 3; i < 4; j = i++) {
98 if ( ((speed.verty[i]>testy) != (speed.verty[j]>testy)) &&
99 (testx < (speed.vertx[j]-speed.vertx[i]) * (testy-speed.verty[i])
100 * (speed.one_over_vertys[i]) + speed.vertx[i]) )
101 c = !c;
102 }
103 return c;
104
105 }
106
107
108
109 void compute_speed(struct speed *sp,int x1,int y1,int x2,int y2,int x3,int y3, int x4, int y4)
110 {
111 sp->xmax = max(max(x1,x2),max(x3,x4));
112 sp->xmin = min(min(x1,x2),min(x3,x4));
113 sp->ymax = max(max(y1,y2),max(y3,y4));
114 sp->ymin = min(min(y1,y2),min(y3,y4));
115
116 sp->vertx[0] = x1;
117 sp->vertx[1] = x2;
118 sp->vertx[2] = x4; /* yes, this is flipped because we are doing line segments here */
119 sp->vertx[3] = x3;
120
121 sp->verty[0] = y1;
122 sp->verty[1] = y2;
123 sp->verty[2] = y4; /* yes, this is flipped because we are doing line segments here */
124 sp->verty[3] = y3;
125
126 double ydelta;
127 ydelta = sp->verty[3]-sp->verty[0];
128 if (ydelta!= 0.0) ydelta = 1.0 / ydelta;
129 sp->one_over_vertys[0] = ydelta;
130
131 ydelta = sp->verty[0]-sp->verty[1];
132 if (ydelta!= 0.0) ydelta = 1.0 / ydelta;
133 sp->one_over_vertys[1] = ydelta;
134 ydelta = sp->verty[1]-sp->verty[2];
135 if (ydelta!= 0.0) ydelta = 1.0 / ydelta;
136 sp->one_over_vertys[2] = ydelta;
137 ydelta = sp->verty[2]-sp->verty[3];
138 if (ydelta!= 0.0) ydelta = 1.0 / ydelta;
139 sp->one_over_vertys[3] = ydelta;
140
141 }
142
143
144 inline int some_inside(int x,int y,int x1,int y1,int x2,int y2,int x3,int y3, int x4, int y4)
145 {
146 /* This assumes that x1,y1 is included 100 % but x4,y4 is not included
147 This also assumes that positive y goes down and positive x goes right */
148 struct speed speed;
149 compute_speed(&speed,x1,y1,x2,y2,x3,y3,x4,y4);
150 return some_inside1(x,y,speed);
151 }
152
153
154 /* This legacy inside has the magic that makes the picture look great
155 without it it looks like crap */
156 int some_insidel(int x,int y,int x1,int y1,int x2,int y2,int x3,int y3, int x4, int y4) {
157 /* This assumes that x1,y1 is included 100 % but x4,y4 is not included
158 This also assumes that positive y goes down and positive x goes right */
159 double x1d,y1d,x2d,y2d,x3d,y3d,x4d,y4d,xd,yd;
160 /* above below slope intercept stuff - but there are weird cases at the edges
161 for now we will ignore the edge cases. It is either inside or not
162 I guess we could make a percentage inside by multiplying and doing an antialiasing and
163 getting a percentage
164 */
165
166 xd = x;yd = y;
167 x1d = x1;y1d = y1;
168 x2d = x2; y2d = y2;
169 x3d = x3; y3d = y3;
170 x4d = x4; y4d = y4;
171 if ((xd < x1d)&&(xd < x3d)) { return 0;} /* x is to the left */
172 if ((xd >= x2d)&&(xd >= x4d)) { return 0;} /* x is to the right */
173 if ((yd < y1d)&&(yd < y2d)) { return 0;} /* y is above */
174 if ((yd >= y3d)&&(yd >= y4d)) { return 0;} /* y is below */
175 double slope;
176 double y_intercept;
177 double inv_slope;
178 double x_intercept;
179 double our_y;
180 double our_x;
181
182 /* see if above the 12 line */
183 if (x1==x2) {
184 if ((yd < y1d)||(yd < y2d)) { return 0;}
185 }
186 else {
187 slope = ((double)(y2d - y1d))/((double)(x2d-x1d));
188 y_intercept = y1 - x1*slope;
189 our_y = slope * xd + y_intercept;
190 if (y <our_y) {return 0;} /* y is above our line for the given x */
191 }
192
193
194 /* see if below or on the 34 line */
195 if (x3==x4) {
196 if ((yd >= y3d)||(yd >= y4d)) { return 0;}
197 }
198 else {
199 slope = (y4d - y3d)/(x4d-x3d);
200 y_intercept = y3 - x3*slope;
201 our_y = slope * xd + y_intercept;
202 if (y >= our_y) {return 0;} /* y is below or on our line for the given x */
203 }
204
205 /* see if to the right of the 13 line */
206 if (y1==y3) {
207 if ((xd < x1d)||(xd < x3d)) { return 0;}
208 }
209 inv_slope = (x3d-x1d)/(y3d-y1d);
210 x_intercept = x3 - y3*inv_slope;
211 our_x = inv_slope * yd + x_intercept;
212 if (x < our_x) {return 0;};
213
214
215 /* see if to the left of the 24 line */
216 if (y2==y4) {
217 if ((xd >= x2d)||(xd >= x4d)) { return 0;}
218 }
219 inv_slope = (x4d-x2d)/(y4d-y2d);
220 x_intercept = x4 - y4*inv_slope;
221 our_x = inv_slope * yd + x_intercept;
222 if (x >= our_x) {return 0;};
223
224 return 1;
225 }
226
227
228
229 int compute_average(unsigned char *raster,int xsize,int ysize,
230 int x1,int y1, int x2, int y2, int x3, int y3, int x4, int y4,double *pr, double *pg, double *pb)
231 {
232 double count;
233 double r,g,b;
234 count = 0.;
235 r=0.;
236 g=0.;
237 b=0.;
238
239 int ix,iy;
240 int minx,miny,maxx,maxy;
241 minx=min(min(x1,x2),min(x3,x4));
242 miny=min(min(y1,y2),min(y3,y4));
243 maxx=max(max(x1,x2),max(x3,x4));
244 maxy=max(max(y1,y2),max(y3,y4));
245 for (iy=miny;iy<maxy;iy++) {
246 for (ix=minx;ix<maxx;ix++) {
247 if (some_insidel(ix,iy,x1,y1,x2,y2,x3,y3,x4,y4)) {
248 int loc= (iy*xsize+ix);
249 loc = loc+loc+loc;
250 r += raster[loc++];
251 g += raster[loc++];
252 b += raster[loc++];
253 count += 1.;
254 }
255 }
256 }
257 if (count==0) {
258 r=128.;
259 g=128.;
260 b=128.;
261 }
262 else {
263 r = r / count;
264 g = g / count;
265 b = b / count;
266 }
267 *pr = r;
268 *pg = g;
269 *pb = b;
270 return count;
271 }
272
273
274
275
276 int compute_average1(unsigned char *raster,int xsize,int ysize,
277 int x1,int y1, int x2, int y2, int x3, int y3, int x4, int y4,double *pr, double *pg, double *pb)
278 {
279 double count;
280 double r,g,b;
281 count = 0.;
282 r=0.;
283 g=0.;
284 b=0.;
285
286 int ix,iy;
287 struct speed speed;
288 compute_speed(&speed,x1,y1,x2,y2,x3,y3,x4,y4);
289 int loc;
290 for (iy=speed.ymin;iy<speed.ymax;iy++) {
291 loc=(speed.ymin*xsize+speed.xmin)*3;
292 for (ix=speed.xmin;ix<speed.xmax;ix++) {
293 if (some_inside2(ix,iy,speed)) {
294 r += raster[loc++];
295 g += raster[loc++];
296 b += raster[loc++];
297 count++;
298 }
299 else {
300 loc += 3;
301 }
302 }
303 }
304 if (count==0) {
305 r=128.;
306 g=128.;
307 b=128.;
308 }
309 else {
310 r = r / count;
311 g = g / count;
312 b = b / count;
313 }
314 *pr = r;
315 *pg = g;
316 *pb = b;
317 return count;
318 }
319
320
321
322
323
324
325
326
327 int find_best_intersection_main(unsigned char *raster,int xsize,int ysize,int percentage,
328 int x1,int y1, int x2, int y2,int x3, int y3, int x4, int y4,
329 int cx, int cy, int *pbestx, int *pbesty)
330 {
331 int ix,iy;
332 int rx1,rx2,rx3,rx4,ry1,ry2,ry3,ry4; /* range to look for the new center point */
333 /* figure out the range to look at */
334 rx1 = cx + ((x1-cx) * percentage) / 100;
335 ry1 = cy + ((y1-cy)*percentage) / 100;
336 rx2 = cx + ((x2-cx) * percentage) / 100;
337 ry2 = cy + ((y2-cy)*percentage) / 100;
338 rx3 = cx + ((x3-cx) * percentage) / 100;
339 ry3 = cy + ((y3-cy)*percentage) / 100;
340 rx4 = cx + ((x4-cx) * percentage) / 100;
341 ry4 = cy + ((y4-cy)*percentage) / 100;
342
343 int x12 = (x1+x2)>>1;
344 int x13 = (x1+x3)>>1;
345 int x24 = (x2+x4)>>1;
346 int x34 = (x3+x4)>>1;
347 int y12 = (y1+y2)>>1;
348 int y13 = (y1+y3)>>1;
349 int y24 = (y2+y4)>>1;
350 int y34 = (y3+y4)>>1;
351
352 /* convert the quad range into a square range bigger than the quad */
353 struct speed speed;
354 compute_speed(&speed,rx1,ry1,rx2,ry2,rx3,ry3,rx4,ry4);
355 int minx,miny,maxx,maxy;
356 minx=speed.xmin;
357 maxx=speed.xmax;
358 miny=speed.ymin;
359 maxy=speed.ymax;
360
361 int tries;
362
363 double best_variance=-1.;
364 int best_x = -1;
365 int best_y = -1;
366 /* loop through all possible points and find the one combination with the highest variance between the blobs - thats where
367 we want to make a sub-point */
368 {
369 for (tries = 0;tries<500;tries++) {
370 if (maxy==miny) iy=maxy;
371 else iy = ((random()>>2)%(maxy-miny))+miny;
372 if (maxx==minx) ix=maxx;
373 else ix = ((random()>>2)%(maxx-minx))+minx;
374
375
376 /*for (iy=miny;iy<maxy;iy++) {
377 fprintf(stderr," \r");
378 fprintf(stderr,"%lf %d,%d %d\r",best_variance,best_x,best_y,iy);
379 for (ix=minx;ix<maxx;ix++) {
380 */
381 if (some_inside2(ix,iy,speed)) {
382 double r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4;
383 double meanr,meang,meanb;
384 double varr,varg,varb;
385 double combined_var;
386 compute_average(raster,xsize,ysize,x1,y1,x12,y12,x13,y13,ix,iy,&r1,&g1,&b1); /* upper left */
387 compute_average(raster,xsize,ysize,x12,y12,x2,y2,ix,iy,x24,y24,&r2,&g2,&b2); /* upper right */
388 compute_average(raster,xsize,ysize,x13,y13,ix,iy,x3,y3,x34,y34,&r3,&g3,&b3); /* lower left */
389 compute_average(raster,xsize,ysize,ix,iy,x24,y24,x34,y34,x4,y4,&r4,&g4,&b4); /* lower right */
390 meanr=(r1+r2+r3+r4)/4.0;
391 varr = fabs(r1-meanr) + fabs(r2-meanr) + fabs(r3-meanr) + fabs(r4-meanr);
392 meang = (g1+g2+g3+g4)/4.0;
393 varg = fabs(g1-meang) + fabs(g2-meang) + fabs(g3-meang) + fabs(g4-meang);
394 meanb = (b1+b2+b3+b4)/4.0;
395 varb = fabs(b1-meanb) + fabs(b2-meanb) + fabs(b3-meanb) + fabs(b4-meanb);
396 combined_var = varr*varr + varg*varg + varb*varb; /* could square root, but there is no point */
397 if (combined_var > best_variance) {
398 best_variance = combined_var;
399 best_x = ix;
400 best_y = iy;
401 }
402 } /* if we fit */
403 } /* for each possible x */
404 } /* for each possible y */
405
406
407 if (best_x == -1) { /* cannot split further */
408 *pbestx = cx;
409 *pbesty = cy;
410 return 0;
411 }
412 *pbestx = best_x;
413 *pbesty = best_y;
414 return 1;
415 }
416
417
418
419
420
421
422
423
424
425 #ifdef NOTUSEDfgdsgdsg
426
427
428
429 int find_best_intersection_points(unsigned char *raster,int xsize,int ysize,int percentage,
430 struct square *s)
431 {
432 int minx,miny,maxx,maxy;
433 /* figure out the range to look at */
434 double r;
435 double slope;
436 double y_intercept;
437 double inv_slope;
438 double x_intercept;
439 double our_y;
440 double our_x;
441 struct square *s1,*s2,*s3,*s4;
442 s1 = s->upper_left_sub;
443 s2 = s->upper_right_sub;
444 s3 = s->lower_left_sub;
445 s4 = s->lower_right_sub;
446
447 int x1, y1,x2,y2,x3,y3,x4,y4;
448 int cx,cy;
449 x1=s->x1;y1=s->y1;
450 x2=s->x2;y2=s->y2;
451 x3=s->x3;y3=s->y3;
452 x4=s->x4;y4=s->y4;
453 cx = s1->x4;
454 cy = s1->y4;
455
456
457 int r2;
458
459 int x12 = (x1+x2)>>1;
460 int x13 = (x1+x3)>>1;
461 int x24 = (x2+x4)>>1;
462 int x34 = (x3+x4)>>1;
463 int y12 = (y1+y2)>>1;
464 int y13 = (y1+y3)>>1;
465 int y24 = (y2+y4)>>1;
466 int y34 = (y3+y4)>>1;
467
468
469 double factor;
470
471 int flag=1;
472 if ((x1==50717)&&(x2==50981)&&(x2==50541)&&(x4==50776)) {
473 flag=1;
474 fprintf(stderr,"got it\n");
475 }
476
477
478
479 /* handle 1-2 edge */
480 double best_variance=-1.;
481 int best_x = -1;
482 int best_y = -1;
483
484
485
486 if (x2==x1) { // no slope
487 int rf,rt;
488 int miny,maxy;
489 miny = min(y1,y2);
490 maxy = max(y1,y2);
491 rf = (maxy+miny)>>1 - ((maxy-miny)>>1 * percentage / 100) ;
492 rt = (maxy+miny)>>1 + ((maxy-miny)>>1 * percentage / 100) ;
493
494 int i;
495 for (i=rf;i<rt;i++) {
496 int ix,iy;
497 ix = x1;
498 iy = i;
499 double r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4;
500 double meanr,meang,meanb;
501 double varr,varg,varb;
502 double combined_var;
503 compute_average(raster,xsize,ysize,x1,y1,ix,iy,x13,y13,cx,cy,&r1,&g1,&b1); /* upper left */
504 compute_average(raster,xsize,ysize,ix,iy,x2,y2,cx,cy,x24,y24,&r2,&g2,&b2); /* upper right */
505
506 if (s1->above) {
507 struct square *k;
508 k=s1->above;
509 compute_average(raster,xsize,ysize,k->x1,k->y1,k->x2,k->y2,k->x3,k->y3,ix,iy,&r3,&g3,&b3); /* upper neighbor */
510 } else {
511 r3=r1;g3=g1;b3=b1;
512 }
513
514 if (s2->above) {
515 struct square *k;
516 k=s2->above;
517 compute_average(raster,xsize,ysize,k->x1,k->y1,k->x2,k->y2,ix,iy,k->x4,k->y4,&r4,&g4,&b4); /* upper neighbor */
518 } else {
519 r4=r2;g4=g2;b4=b2;
520 }
521
522
523 meanr=(r1+r2+r3+r4)/4.0;
524 varr = fabs(r1-meanr) + fabs(r2-meanr) + fabs(r3-meanr) + fabs(r4-meanr);
525 meang = (g1+g2+g3+g4)/4.0;
526 varg = fabs(g1-meang) + fabs(g2-meang) + fabs(g3-meang) + fabs(g4-meang);
527 meanb = (b1+b2+b3+b4)/4.0;
528 varb = fabs(b1-meanb) + fabs(b2-meanb) + fabs(b3-meanb) + fabs(b4-meanb);
529 combined_var = varr*varr + varg*varg + varb*varb; /* could square root, but there is no point */
530 if (combined_var > best_variance) {
531 best_variance = combined_var;
532 best_x = ix;
533 best_y = iy;
534 }
535 } /* for each possible position */
536 } /* if we have no slope */
537 else {
538 int rf,rt;
539 r = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
540 r = sqrt(r);
541 r2 = r*1.5; /*fudge */
542 slope = ((double)(y2-y1))/((double)(x2-x1));
543 y_intercept = (double)(y1) - ((double)(x1))*slope;
544 factor = ((double)(x2-x1))/r2;
545 rf = r2>>1 - ((r2>>1) * percentage) / 100;
546 rt = r2>>1 + ((r2>>1) * percentage) / 100;
547
548 int i;
549 for (i=rf;i<rt;i++) {
550 int pos;
551 double x,y;
552 int ix,iy;
553 x = x1 + factor * ((double)(i));
554 y = x * slope + y_intercept;
555 ix=x;
556 iy=y;
557 double r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4;
558 double meanr,meang,meanb;
559 double varr,varg,varb;
560 double combined_var;
561 compute_average(raster,xsize,ysize,x1,y1,ix,iy,x13,y13,cx,cy,&r1,&g1,&b1); /* upper left */
562 compute_average(raster,xsize,ysize,ix,iy,x2,y2,cx,cy,x24,y24,&r2,&g2,&b2); /* upper right */
563
564 if (s1->above) {
565 struct square *k;
566 k=s1->above;
567 compute_average(raster,xsize,ysize,k->x1,k->y1,k->x2,k->y2,k->x3,k->y3,ix,iy,&r3,&g3,&b3); /* upper neighbor */
568 } else {
569 r3=r1;g3=g1;b3=b1;
570 }
571
572 if (s2->above) {
573 struct square *k;
574 k=s2->above;
575 compute_average(raster,xsize,ysize,k->x1,k->y1,k->x2,k->y2,ix,iy,k->x4,k->y4,&r4,&g4,&b4); /* upper neighbor */
576 } else {
577 r4=r2;g4=g2;b4=b2;
578 }
579
580
581 meanr=(r1+r2+r3+r4)/4.0;
582 varr = fabs(r1-meanr) + fabs(r2-meanr) + fabs(r3-meanr) + fabs(r4-meanr);
583 meang = (g1+g2+g3+g4)/4.0;
584 varg = fabs(g1-meang) + fabs(g2-meang) + fabs(g3-meang) + fabs(g4-meang);
585 meanb = (b1+b2+b3+b4)/4.0;
586 varb = fabs(b1-meanb) + fabs(b2-meanb) + fabs(b3-meanb) + fabs(b4-meanb);
587
588 combined_var = varr*varr + varg*varg + varb*varb; /* could square root, but there is no point */
589 if (combined_var > best_variance) {
590 best_variance = combined_var;
591 best_x = ix;
592 best_y = iy;
593 }
594 } /* for each possible position */
595 }
596 if (best_x == -1) { /* cannot split further */
597 best_x = x12;
598 best_y = y12;
599 }
600 else {
601 x12 = best_x;
602 y12 = best_y;
603 }
604
605 s1->x2 = best_x;
606 s1->y2 = best_y;
607 s2->x1 = best_x;
608 s2->y1 = best_y;
609 if (s1->above) {
610 s1->above->x4 = best_x;
611 s1->above->y4 = best_y;
612 }
613 if (s2->above) {
614 s2->above->x3 = best_x;
615 s2->above->y3 = best_y;
616 }
617
618
619
620 /* now find the point on the 3/4 line */
621 /* handle 3-4 edge */
622 best_variance=-1.;
623 best_x = -1;
624 best_y = -1;
625
626 if (x3==x4) { // no slope
627 int rf,rt;
628 int miny,maxy;
629 miny = min(y3,y4);
630 maxy = max(y3,y4);
631 rf = (maxy+miny)>>1 - ((maxy-miny)>>1 * percentage / 100) ;
632 rt = (maxy+miny)>>1 + ((maxy-miny)>>1 * percentage / 100) ;
633
634 int i;
635 for (i=rf;i<rt;i++) {
636 int ix,iy;
637 ix = x1;
638 iy = i;
639 double r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4;
640 double meanr,meang,meanb;
641 double varr,varg,varb;
642 double combined_var;
643 compute_average(raster,xsize,ysize,x13,y13,cx,cy,x3,y3,ix,iy,&r1,&g1,&b1); /* lower left */
644 compute_average(raster,xsize,ysize,cx,cy,x24,y24,ix,iy,x4,y4,&r2,&g2,&b2); /* lower right */
645
646 if (s3->below) {
647 struct square *k;
648 k=s3->below;
649 compute_average(raster,xsize,ysize,k->x1,k->y1,ix,iy,k->x3,k->y3,k->x4,k->y4,&r3,&g3,&b3); /* upper neighbor */
650 } else {
651 r3=r1;g3=g1;b3=b1;
652 }
653
654 if (s4->below) {
655 struct square *k;
656 k=s4->below;
657 compute_average(raster,xsize,ysize,ix,iy,k->x2,k->y2,k->x3,k->y3,k->x4,k->y4,&r4,&g4,&b4); /* upper neighbor */
658 } else {
659 r4=r2;g4=g2;b4=b2;
660 }
661
662
663 meanr=(r1+r2+r3+r4)/4.0;
664 varr = fabs(r1-meanr) + fabs(r2-meanr) + fabs(r3-meanr) + fabs(r4-meanr);
665 meang = (g1+g2+g3+g4)/4.0;
666 varg = fabs(g1-meang) + fabs(g2-meang) + fabs(g3-meang) + fabs(g4-meang);
667 meanb = (b1+b2+b3+b4)/4.0;
668 varb = fabs(b1-meanb) + fabs(b2-meanb) + fabs(b3-meanb) + fabs(b4-meanb);
669 combined_var = varr*varr + varg*varg + varb*varb; /* could square root, but there is no point */
670 if (combined_var > best_variance) {
671 best_variance = combined_var;
672 best_x = ix;
673 best_y = iy;
674 }
675 } /* for each possible position */
676 } /* if we have no slope */
677 else {
678 int rf,rt;
679 r = (x4-x3)*(x4-x3) + (y4-y3)*(y4-y3);
680 r = sqrt(r);
681 r2 = r*1.5; /*fudge */
682 slope = ((double)(y4-y3))/((double)(x4-x3));
683 y_intercept = ((double)y3) - ((double)(x3))*slope;
684 factor = ((double)(x4-x3))/r2;
685 rf = r2>>1 - ((r2>>1) * percentage) / 100;
686 rt = r2>>1 + ((r2>>1) * percentage) / 100;
687
688 int i;
689 for (i=rf;i<rt;i++) {
690 int pos;
691 double x,y;
692 int ix,iy;
693 x = x3 + factor * ((double)(i));
694 y = x * slope + y_intercept;
695 ix=x;
696 iy=y;
697 double r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4;
698 double meanr,meang,meanb;
699 double varr,varg,varb;
700 double combined_var;
701 compute_average(raster,xsize,ysize,x13,y13,cx,cy,x3,y3,ix,iy,&r1,&g1,&b1); /* lower left */
702 compute_average(raster,xsize,ysize,cx,cy,x24,y24,ix,iy,x4,y4,&r2,&g2,&b2); /* lower right */
703
704 if (s3->below) {
705 struct square *k;
706 k=s3->below;
707 compute_average(raster,xsize,ysize,k->x1,k->y1,ix,iy,k->x3,k->y3,k->x4,k->y4,&r3,&g3,&b3); /* upper neighbor */
708 } else {
709 r3=r1;g3=g1;b3=b1;
710 }
711
712 if (s4->below) {
713 struct square *k;
714 k=s4->below;
715 compute_average(raster,xsize,ysize,ix,iy,k->x2,k->y2,k->x3,k->y3,k->x4,k->y4,&r4,&g4,&b4); /* upper neighbor */
716 } else {
717 r4=r2;g4=g2;b4=b2;
718 }
719
720
721 meanr=(r1+r2+r3+r4)/4.0;
722 varr = fabs(r1-meanr) + fabs(r2-meanr) + fabs(r3-meanr) + fabs(r4-meanr);
723 meang = (g1+g2+g3+g4)/4.0;
724 varg = fabs(g1-meang) + fabs(g2-meang) + fabs(g3-meang) + fabs(g4-meang);
725 meanb = (b1+b2+b3+b4)/4.0;
726 varb = fabs(b1-meanb) + fabs(b2-meanb) + fabs(b3-meanb) + fabs(b4-meanb);
727 combined_var = varr*varr + varg*varg + varb*varb; /* could square root, but there is no point */
728
729 if (combined_var > best_variance) {
730 best_variance = combined_var;
731 best_x = ix;
732 best_y = iy;
733 }
734 } /* for each possible position */
735 }
736 if (best_x == -1) { /* cannot split further */
737 best_x = x34;
738 best_y = y34;
739 }
740 else {
741 x34 = best_x;
742 y34 = best_y;
743 }
744
745 s3->x4 = best_x;
746 s3->y4 = best_y;
747 s4->x3 = best_x;
748 s4->y3 = best_y;
749 if (s3->below) {
750 s3->below->x2 = best_x;
751 s3->below->y2 = best_y;
752 }
753 if (s4->below) {
754 s4->below->x1 = best_x;
755 s4->below->y1 = best_y;
756 }
757
758
759
760
761
762
763
764
765 /* handle 1-3 edge */
766 best_variance=-1.;
767 best_x = -1;
768 best_y = -1;
769
770 if (x3==x1) { // no slope
771 int rf,rt;
772 int miny,maxy;
773 miny = min(y1,y3);
774 maxy = max(y1,y3);
775 rf = (maxy+miny)>>1 - ((maxy-miny)>>1 * percentage / 100) ;
776 rt = (maxy+miny)>>1 + ((maxy-miny)>>1 * percentage / 100) ;
777
778 int i;
779 for (i=rf;i<rt;i++) {
780 int ix,iy;
781 ix = x1;
782 iy = i;
783 double r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4;
784 double meanr,meang,meanb;
785 double varr,varg,varb;
786 double combined_var;
787 compute_average(raster,xsize,ysize,x1,y1,x12,y12,ix,iy,cx,cy,&r1,&g1,&b1); /* upper left */
788 compute_average(raster,xsize,ysize,ix,iy,cx,cy,x3,y3,x34,y34,&r2,&g2,&b2); /* lower left */
789 if (s1->left) {
790 struct square *k;
791 k=s1->left;
792 compute_average(raster,xsize,ysize,k->x1,k->y1,k->x2,k->y2,k->x3,k->y3,ix,iy,&r3,&g3,&b3); /* left */
793 } else {
794 r3=r1;g3=g1;b3=b1;
795 }
796
797 if (s3->left) {
798 struct square *k;
799 k=s3->left;
800 compute_average(raster,xsize,ysize,k->x1,k->y1,ix,iy,k->x3,k->y3,k->x4,k->y4,&r4,&g4,&b4); /* upper neighbor */
801 } else {
802 r4=r2;g4=g2;b4=b2;
803 }
804
805
806 meanr=(r1+r2+r3+r4)/4.0;
807 varr = fabs(r1-meanr) + fabs(r2-meanr) + fabs(r3-meanr) + fabs(r4-meanr);
808 meang = (g1+g2+g3+g4)/4.0;
809 varg = fabs(g1-meang) + fabs(g2-meang) + fabs(g3-meang) + fabs(g4-meang);
810 meanb = (b1+b2+b3+b4)/4.0;
811 varb = fabs(b1-meanb) + fabs(b2-meanb) + fabs(b3-meanb) + fabs(b4-meanb);
812 combined_var = varr*varr + varg*varg + varb*varb; /* could square root, but there is no point */
813 if (combined_var > best_variance) {
814 best_variance = combined_var;
815 best_x = ix;
816 best_y = iy;
817 }
818 } /* for each possible position */
819 } /* if we have no slope */
820 else {
821 int rf,rt;
822 r = (x3-x1)*(x3-x1) + (y3-y1)*(y3-y1);
823 r = sqrt(r);
824 r2 = r*1.5; /*fudge */
825 slope = ((double)(y3-y1))/((double)(x3-x1));
826 y_intercept = (double)(y1) - ((double)(x1))*slope;
827 factor = ((double)(x3-x1))/r2;
828 rf = r2>>1 - ((r2>>1) * percentage) / 100;
829 rt = r2>>1 + ((r2>>1) * percentage) / 100;
830
831 int i;
832 for (i=rf;i<rt;i++) {
833 int pos;
834 double x,y;
835 int ix,iy;
836 x = x1 + factor * ((double)(i));
837 y = x * slope + y_intercept;
838 ix=x;
839 iy=y;
840 double r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4;
841 double meanr,meang,meanb;
842 double varr,varg,varb;
843 double combined_var;
844 compute_average(raster,xsize,ysize,x1,y1,x12,y12,ix,iy,cx,cy,&r1,&g1,&b1); /* upper left */
845 compute_average(raster,xsize,ysize,ix,iy,cx,cy,x3,y3,x34,y34,&r2,&g2,&b2); /* lower left */
846 if (s1->left) {
847 struct square *k;
848 k=s1->left;
849 compute_average(raster,xsize,ysize,k->x1,k->y1,k->x2,k->y2,k->x3,k->y3,ix,iy,&r3,&g3,&b3); /* left */
850 } else {
851 r3=r1;g3=g1;b3=b1;
852 }
853
854 if (s3->left) {
855 struct square *k;
856 k=s3->left;
857 compute_average(raster,xsize,ysize,k->x1,k->y1,ix,iy,k->x3,k->y3,k->x4,k->y4,&r4,&g4,&b4); /* upper neighbor */
858 } else {
859 r4=r2;g4=g2;b4=b2;
860 }
861
862
863 meanr=(r1+r2+r3+r4)/4.0;
864 varr = fabs(r1-meanr) + fabs(r2-meanr) + fabs(r3-meanr) + fabs(r4-meanr);
865 meang = (g1+g2+g3+g4)/4.0;
866 varg = fabs(g1-meang) + fabs(g2-meang) + fabs(g3-meang) + fabs(g4-meang);
867 meanb = (b1+b2+b3+b4)/4.0;
868 varb = fabs(b1-meanb) + fabs(b2-meanb) + fabs(b3-meanb) + fabs(b4-meanb);
869 combined_var = varr*varr + varg*varg + varb*varb; /* could square root, but there is no point */
870 if (combined_var > best_variance) {
871 best_variance = combined_var;
872 best_x = ix;
873 best_y = iy;
874 }
875 } /* for each possible position */
876 }
877 if (best_x == -1) { /* cannot split further */
878 best_x = x13;
879 best_y = y13;
880 }
881 else {
882 x13 = best_x;
883 y13 = best_y;
884 }
885
886 s1->x3 = best_x;
887 s1->y3 = best_y;
888 s3->x1 = best_x;
889 s3->y1 = best_y;
890 if (s1->left) {
891 s1->left->x4 = best_x;
892 s1->left->y4 = best_y;
893 }
894 if (s3->left) {
895 s3->left->x2 = best_x;
896 s3->left->y2 = best_y;
897 }
898
899
900
901
902
903
904
905 /* handle 2-4 edge */
906 best_variance=-1.;
907 best_x = -1;
908 best_y = -1;
909
910 if (x4==x2) { // no slope
911 int rf,rt;
912 int miny,maxy;
913 miny = min(y2,y4);
914 maxy = max(y2,y4);
915 rf = (maxy+miny)>>1 - ((maxy-miny)>>1 * percentage / 100) ;
916 rt = (maxy+miny)>>1 + ((maxy-miny)>>1 * percentage / 100) ;
917
918 int i;
919 for (i=rf;i<rt;i++) {
920 int ix,iy;
921 ix = x2;
922 iy = i;
923 double r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4;
924 double meanr,meang,meanb;
925 double varr,varg,varb;
926 double combined_var;
927 compute_average(raster,xsize,ysize,x12,y12,x2,y2,cx,cy,ix,iy,&r1,&g1,&b1); /* upper right */
928 compute_average(raster,xsize,ysize,cx,cy,ix,iy,x34,y34,x4,y4,&r2,&g2,&b2); /* lower right */
929 if (s2->right) {
930 struct square *k;
931 k=s2->right;
932 compute_average(raster,xsize,ysize,k->x1,k->y1,k->x2,k->y2,ix,iy,k->x4,k->y4,&r3,&g3,&b3); /* left */
933 } else {
934 r3=r1;g3=g1;b3=b1;
935 }
936
937 if (s4->right) {
938 struct square *k;
939 k=s4->right;
940 compute_average(raster,xsize,ysize,ix,iy,k->x2,k->y2,k->x3,k->y3,k->x4,k->y4,&r4,&g4,&b4); /* upper neighbor */
941 } else {
942 r4=r2;g4=g2;b4=b2;
943 }
944
945
946 meanr=(r1+r2+r3+r4)/4.0;
947 varr = fabs(r1-meanr) + fabs(r2-meanr) + fabs(r3-meanr) + fabs(r4-meanr);
948 meang = (g1+g2+g3+g4)/4.0;
949 varg = fabs(g1-meang) + fabs(g2-meang) + fabs(g3-meang) + fabs(g4-meang);
950 meanb = (b1+b2+b3+b4)/4.0;
951 varb = fabs(b1-meanb) + fabs(b2-meanb) + fabs(b3-meanb) + fabs(b4-meanb);
952 combined_var = varr*varr + varg*varg + varb*varb; /* could square root, but there is no point */
953
954
955 if (combined_var > best_variance) {
956 best_variance = combined_var;
957 best_x = ix;
958 best_y = iy;
959 }
960 } /* for each possible position */
961 } /* if we have no slope */
962 else {
963 int rf,rt;
964 r = (x4-x2)*(x4-x2) + (y4-y2)*(y4-y2);
965 r = sqrt(r);
966 r2 = r*1.5; /*fudge */
967 slope = ((double)(y4-y2))/((double)(x4-x2));
968 y_intercept = (double)(y2) - ((double)(x2))*slope;
969 factor = ((double)(x4-x2))/r2;
970 rf = r2>>1 - ((r2>>1) * percentage) / 100;
971 rt = r2>>1 + ((r2>>1) * percentage) / 100;
972
973
974 if (flag) {
975 fprintf(stderr,"from [%d to %d)\n",rf,rt);
976 }
977 int i;
978 for (i=rf;i<rt;i++) {
979 int pos;
980 double x,y;
981 int ix,iy;
982 x = x2 + factor * ((double)(i));
983 y = x * slope + y_intercept;
984 ix=x;
985 iy=y;
986 if (flag) {
987 fprintf(stderr,"i %d x %d y %d\n",i,ix,iy);
988 }
989
990 double r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4;
991 double meanr,meang,meanb;
992 double varr,varg,varb;
993 double combined_var;
994 compute_average(raster,xsize,ysize,x12,y12,x2,y2,cx,cy,ix,iy,&r1,&g1,&b1); /* upper right */
995 compute_average(raster,xsize,ysize,cx,cy,ix,iy,x34,y34,x4,y4,&r2,&g2,&b2); /* lower right */
996
997
998 if (s2->right) {
999 struct square *k;
1000 k=s2->right;
1001 compute_average(raster,xsize,ysize,k->x1,k->y1,k->x2,k->y2,ix,iy,k->x4,k->y4,&r3,&g3,&b3); /* left */
1002 } else {
1003 r3=r1;g3=g1;b3=b1;
1004 }
1005
1006 if (s4->right) {
1007 struct square *k;
1008 k=s4->right;
1009 compute_average(raster,xsize,ysize,ix,iy,k->x2,k->y2,k->x3,k->y3,k->x4,k->y4,&r4,&g4,&b4); /* upper neighbor */
1010 } else {
1011 r4=r2;g4=g2;b4=b2;
1012 }
1013
1014
1015 meanr=(r1+r2+r3+r4)/4.0;
1016 varr = fabs(r1-meanr) + fabs(r2-meanr) + fabs(r3-meanr) + fabs(r4-meanr);
1017 meang = (g1+g2+g3+g4)/4.0;
1018 varg = fabs(g1-meang) + fabs(g2-meang) + fabs(g3-meang) + fabs(g4-meang);
1019 meanb = (b1+b2+b3+b4)/4.0;
1020 varb = fabs(b1-meanb) + fabs(b2-meanb) + fabs(b3-meanb) + fabs(b4-meanb);
1021 combined_var = varr*varr + varg*varg + varb*varb; /* could square root, but there is no point */
1022
1023 if (combined_var > best_variance) {
1024 best_variance = combined_var;
1025 best_x = ix;
1026 best_y = iy;
1027 }
1028 } /* for each possible position */
1029 }
1030 if (best_x == -1) { /* cannot split further */
1031 best_x = x24;
1032 best_y = y24;
1033 }
1034 else {
1035 if (flag) {
1036 fprintf(stderr,"changing 24 from %d,%d to %d,%d\n",x24,y24,best_x,best_y);
1037 }
1038 x24 = best_x;
1039 y24 = best_y;
1040 }
1041
1042 s2->x4 = best_x;
1043 s2->y4 = best_y;
1044 s4->x2 = best_x;
1045 s4->y2 = best_y;
1046 if (s2->right) {
1047 s2->right->x3 = best_x;
1048 s2->right->y3 = best_y;
1049 }
1050 if (s4->right) {
1051 s4->right->x1 = best_x;
1052 s4->right->y1 = best_y;
1053 }
1054
1055
1056
1057 return 1;
1058 }
1059
1060 #endif
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072 int find_sub_squares(unsigned char *raster,
1073 int xsize,int ysize,
1074 int percentage,
1075 int level,
1076 int top_level,
1077 struct square *s) {
1078
1079 if (level<0) level=0; /* hack */
1080 if (!level) {
1081
1082 int x1,y1,x2,y2,x3,y3,x4,y4;
1083 int cx,cy; /* the center of the 4 points */
1084 int rx1,rx2,rx3,rx4,ry1,ry2,ry3,ry4; /* range to look for the new center point */
1085 int minx,miny,maxx,maxy; /* change the quad to a square for checking */
1086 int ix,iy; /* loop control variables */
1087
1088 x1=s->x1;
1089 y1=s->y1;
1090 x2=s->x2;
1091 y2=s->y2;
1092 x3=s->x3;
1093 y3=s->y3;
1094 x4=s->x4;
1095 y4=s->y4;
1096
1097 {
1098 double r,g,b;
1099 int c=compute_average(raster,xsize,ysize,x1,y1,x2,y2,x3,y3,x4,y4,&r,&g,&b);
1100 if (c) {
1101 s->r = (int)r;
1102 s->g = (int)g;
1103 s->b = (int)b;
1104 }
1105 else {
1106 s->r = s->parent->r;
1107 s->g = s->parent->g;
1108 s->b = s->parent->b;
1109 }
1110 }
1111
1112
1113 /*
1114 printf("-stroke green -strokewidth 1 -draw \"line %d,%d,%d,%d\" \\\n",x1,y1,x2,y2);
1115 printf("-stroke red -strokewidth 1 -draw \"line %d,%d,%d,%d\" \\\n",x1,y1,x3,y3);
1116 printf("-stroke blue -strokewidth 1 -draw \"line %d,%d,%d,%d\" \\\n",x3,y3,x4,y4);
1117 printf("-stroke white -strokewidth 1 -draw \"line %d,%d,%d,%d\" \\\n",x2,y2,x4,y4);
1118 */
1119 return (squares-s);
1120 }
1121 /* OK we have 4 points in a quad. And we need to find 5 more points. We will start with the center,
1122 the center takes the longest to find. And in this case, we are going to do it linear.
1123 Could do random and get an estimate. Oh well */
1124 int x1,y1,x2,y2,x3,y3,x4,y4;
1125 int cx,cy; /* the center of the 4 points */
1126 int rx1,rx2,rx3,rx4,ry1,ry2,ry3,ry4; /* range to look for the new center point */
1127 int minx,miny,maxx,maxy; /* change the quad to a square for checking */
1128 int ix,iy; /* loop control variables */
1129
1130 x1=s->x1;
1131 y1=s->y1;
1132 x2=s->x2;
1133 y2=s->y2;
1134 x3=s->x3;
1135 y3=s->y3;
1136 x4=s->x4;
1137 y4=s->y4;
1138
1139 {
1140 double r,g,b;
1141 int c=compute_average(raster,xsize,ysize,x1,y1,x2,y2,x3,y3,x4,y4,&r,&g,&b);
1142 if (c) {
1143 s->r = (int)r;
1144 s->g = (int)g;
1145 s->b = (int)b;
1146 }
1147 else {
1148 s->r = s->parent->r;
1149 s->g = s->parent->g;
1150 s->b = s->parent->b;
1151 }
1152 }
1153
1154
1155 /* 1 2
1156 3 4
1157 */
1158 /* need to find all points that are in a percentage% average */
1159 cx = (x1+x2+x3+x4)>>2;
1160 cy = (y1+y2+y3+y4)>>2;
1161
1162 /* figure out the range to look at */
1163 rx1 = cx + ((x1-cx) * percentage) / 100;
1164 ry1 = cy + ((y1-cy)*percentage) / 100;
1165 rx2 = cx + ((x2-cx) * percentage) / 100;
1166 ry2 = cy + ((y2-cy)*percentage) / 100;
1167 rx3 = cx + ((x3-cx) * percentage) / 100;
1168 ry3 = cy + ((y3-cy)*percentage) / 100;
1169 rx4 = cx + ((x4-cx) * percentage) / 100;
1170 ry4 = cy + ((y4-cy)*percentage) / 100;
1171
1172 /* convert the quad range into a square range bigger than the quad */
1173 minx=min(min(rx1,rx2),min(rx3,rx4));
1174 miny=min(min(ry1,ry2),min(ry3,ry4));
1175
1176 maxx=max(max(rx1,rx2),max(rx3,rx4));
1177 maxy=max(max(ry1,ry2),max(ry3,ry4));
1178
1179 int x12 = (x1+x2)>>1;
1180 int x13 = (x1+x3)>>1;
1181 int x24 = (x2+x4)>>1;
1182 int x34 = (x3+x4)>>1;
1183 int y12 = (y1+y2)>>1;
1184 int y13 = (y1+y3)>>1;
1185 int y24 = (y2+y4)>>1;
1186 int y34 = (y3+y4)>>1;
1187
1188
1189
1190 find_best_intersection_main(raster,xsize,ysize,percentage,
1191 x1,y1,x2,y2,x3,y3,x4,y4,
1192 cx,cy,&cx,&cy);
1193
1194
1195
1196
1197 /* make 4 quads */
1198 struct square *s1,*s2,*s3,*s4;
1199 s1 = squares+square_count++;
1200 s2 = squares+square_count++;
1201 s3 = squares+square_count++;
1202 s4 = squares+square_count++;
1203
1204
1205 s1->parent = s;
1206 s2->parent = s;
1207 s3->parent = s;
1208 s4->parent = s;
1209
1210 s1->upper_left_sub = NULL;
1211 s1->lower_left_sub = NULL;
1212 s1->upper_right_sub = NULL;
1213 s1->lower_right_sub = NULL;
1214
1215 if ((s->above)&&(s->above->lower_left_sub)) {
1216 s1->above = s->above->lower_left_sub;
1217 s1->above->below = s1;
1218 }
1219 else
1220 s1->above = NULL;
1221 s1->below = s3;
1222 if ((s->left) && (s->left->upper_right_sub)) {
1223 s1->left = s->left->upper_right_sub;
1224 s1->left->right = s1;
1225 }
1226 else
1227 s1->left = NULL;
1228 s1->right = s2; /* figure this out later */
1229
1230
1231
1232
1233 s2->upper_left_sub = NULL;
1234 s2->lower_left_sub = NULL;
1235 s2->upper_right_sub = NULL;
1236 s2->lower_right_sub = NULL;
1237
1238 if ((s->above)&&(s->above->lower_right_sub)) {
1239 s2->above = s->above->lower_right_sub;
1240 s2->above->below = s2;
1241 }
1242 else
1243 s2->above = NULL;
1244 s2->below = s4;
1245 s2->left = s1;
1246 if ((s->right) && (s->right->upper_left_sub)) {
1247 s2->right = s->right->upper_left_sub;
1248 s2->right->left = s2;
1249 }
1250 else
1251 s2->right = NULL; /* figure this out later */
1252
1253
1254 s3->upper_left_sub = NULL;
1255 s3->lower_left_sub = NULL;
1256 s3->upper_right_sub = NULL;
1257 s3->lower_right_sub = NULL;
1258
1259 s3->above = s1;
1260 if ((s->below)&&(s->below->upper_left_sub)) {
1261 s3->below = s->below->upper_left_sub;
1262 s3->below->above = s3;
1263 }
1264 else
1265 s3->below = NULL;
1266 if ((s->left) && (s->left->lower_right_sub)) {
1267 s3->left = s->left->lower_right_sub;
1268 s3->left->right = s3;
1269 }
1270 else
1271 s3->left = NULL;
1272 s3->right = s4; /* figure this out later */
1273
1274
1275
1276 s4->upper_left_sub = NULL;
1277 s4->lower_left_sub = NULL;
1278 s4->upper_right_sub = NULL;
1279 s4->lower_right_sub = NULL;
1280 s4->above = s2;
1281 if ((s->below)&&(s->below->upper_right_sub)) {
1282 s4->below = s->below->upper_right_sub;
1283 s4->below->above = s4;
1284 }
1285 else
1286 s4->below = NULL;
1287 s4->left = s3;
1288 if ((s->right) && (s->right->lower_left_sub)) {
1289 s4->right = s->right->lower_left_sub;
1290 s4->right->left = s4;
1291 }
1292 else s4->right = NULL; /* figure this out later */
1293
1294
1295 s->upper_left_sub = s1;
1296 s->lower_left_sub = s3;
1297 s->upper_right_sub = s2;
1298 s->lower_right_sub = s4;
1299
1300 s1->x1 = x1;
1301 s1->y1 = y1;
1302 s1->x2 = x12;
1303 s1->y2 = y12;
1304 s1->x3 = x13;
1305 s1->y3 = y13;
1306 s1->x4 = cx;
1307 s1->y4 = cy;
1308
1309 s2->x1 = x12;
1310 s2->y1 = y12;
1311 s2->x2 = x2;
1312 s2->y2 = y2;
1313 s2->x3 = cx;
1314 s2->y3 = cy;
1315 s2->x4 = x24;
1316 s2->y4 = y24;
1317
1318 s3->x1 = x13;
1319 s3->y1 = y13;
1320 s3->x2 = cx;
1321 s3->y2 = cy;
1322 s3->x3 = x3;
1323 s3->y3 = y3;
1324 s3->x4 = x34;
1325 s3->y4 = y34;
1326
1327 s4->x1 = cx;
1328 s4->y1 = cy;
1329 s4->x2 = x24;
1330 s4->y2 = y24;
1331 s4->x3 = x34;
1332 s4->y3 = y34;
1333 s4->x4 = x4;
1334 s4->y4 = y4;
1335
1336
1337 /*
1338 This ha a bug between level 2 and level 3, and itl looks yucky with long streams when linemode is drawn
1339 Maybee someday we will fix the bug and then have ti look cool. But not today.
1340 find_best_intersection_points(raster,xsize,ysize,percentage,s);
1341 */
1342
1343
1344 /* OK - this level is done. Now go down a level */
1345 int ss;
1346 ss = find_sub_squares(raster,xsize,ysize,percentage,level-1,top_level,s1);
1347 find_sub_squares(raster,xsize,ysize,percentage,level-1,top_level,s2);
1348 find_sub_squares(raster,xsize,ysize,percentage,level-1,top_level,s3);
1349 find_sub_squares(raster,xsize,ysize,percentage,level-1,top_level,s4);
1350 return ss;
1351
1352 }
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368 void scale_it(struct square *s,int oldxsize,int oldysize, int newxsize, int newysize)
1369 {
1370 if (s) {
1371 scale_it(s->upper_left_sub,oldxsize,oldysize,newxsize,newysize);
1372 scale_it(s->lower_left_sub,oldxsize,oldysize,newxsize,newysize);
1373 scale_it(s->upper_right_sub,oldxsize,oldysize,newxsize,newysize);
1374 scale_it(s->lower_right_sub,oldxsize,oldysize,newxsize,newysize);
1375
1376 s->x1=s->x1 * newxsize / oldxsize;
1377 s->x2=s->x2 * newxsize / oldxsize;
1378 s->x3=s->x3 * newxsize / oldxsize;
1379 s->x4=s->x4 * newxsize / oldxsize;
1380 s->y1 = s->y1 * newysize / oldysize;
1381 s->y2 = s->y2 * newysize / oldysize;
1382 s->y3 = s->y3 * newysize / oldysize;
1383 s->y4 = s->y4 * newysize / oldysize;
1384 }
1385 }
1386
1387
1388 /* This makes the scale more accurate - because
1389 the integer math can make some points off of their centers.
1390 */
1391 void clean_scale(struct square *s)
1392 {
1393 if (s->upper_left_sub) {
1394 int x1=s->x1;
1395 int x2=s->x2;
1396 int x3=s->x3;
1397 int x4=s->x4;
1398 int y1=s->y1;
1399 int y2=s->y2;
1400 int y3=s->y3;
1401 int y4=s->y4;
1402 int x12 = (x1+x2)>>1;
1403 int x13 = (x1+x3)>>1;
1404 int x24 = (x2+x4)>>1;
1405 int x34 = (x3+x4)>>1;
1406 int y12 = (y1+y2)>>1;
1407 int y13 = (y1+y3)>>1;
1408 int y24 = (y2+y4)>>1;
1409 int y34 = (y3+y4)>>1;
1410
1411 /* redo all points except the center point, and fix the lower ones as well */
1412 s->upper_left_sub->x1 = x1;
1413 s->upper_left_sub->y1 = y1;
1414 s->upper_left_sub->x2 = x12;
1415 s->upper_left_sub->y2 = y12;
1416 s->upper_left_sub->x3 = x13;
1417 s->upper_left_sub->y3 = y13;
1418 clean_scale(s->upper_left_sub);
1419
1420 s->upper_right_sub->x1 = x12;
1421 s->upper_right_sub->y1 = y12;
1422 s->upper_right_sub->x2 = x2;
1423 s->upper_right_sub->y2 = y2;
1424 s->upper_right_sub->x4 = x24;
1425 s->upper_right_sub->y4 = y24;
1426 clean_scale(s->upper_right_sub);
1427
1428 s->lower_left_sub->x1 = x13;
1429 s->lower_left_sub->y1 = y13;
1430 s->lower_left_sub->x3 = x3;
1431 s->lower_left_sub->y3 = y3;
1432 s->lower_left_sub->x4 = x34;
1433 s->lower_left_sub->y4 = y34;
1434 clean_scale(s->lower_left_sub);
1435
1436 s->lower_right_sub->x2 = x24;
1437 s->lower_right_sub->y2 = y24;
1438 s->lower_right_sub->x3 = x34;
1439 s->lower_right_sub->y3 = y34;
1440 s->lower_right_sub->x4 = x4;
1441 s->lower_right_sub->y4 = y4;
1442 clean_scale(s->lower_right_sub);
1443 }
1444 }
1445
1446
1447
1448
1449
1450 /* This makes the scale more accurate - because
1451 the integer math can make some points off of their centers.
1452 */
1453 void set_speed(struct square *s)
1454 {
1455 compute_speed(&(s->speed),s->x1,s->y1,s->x2,s->y2,s->x3,s->y3,s->x4,s->y4);
1456 if (s->upper_left_sub) {
1457 set_speed(s->upper_left_sub);
1458 set_speed(s->upper_right_sub);
1459 set_speed(s->lower_left_sub);
1460 set_speed(s->lower_right_sub);
1461 }
1462 }
1463
1464
1465
1466
1467
1468 int draw_squares(struct square *s) {
1469 if (!s) return;
1470 int x1,y1,x2,y2,x3,y3,x4,y4;
1471 x1=s->x1;
1472 y1=s->y1;
1473 x2=s->x2;
1474 y2=s->y2;
1475 x3=s->x3;
1476 y3=s->y3;
1477 x4=s->x4;
1478 y4=s->y4;
1479
1480 if (s->upper_left_sub) {
1481 int ss;
1482
1483 printf("-stroke white -strokewidth 1 -draw \"line %d,%d,%d,%d\" \\\n",x1,y1,x2,y2);
1484 printf("-stroke pink -strokewidth 1 -draw \"line %d,%d,%d,%d\" \\\n",x1,y1,x3,y3);
1485 printf("-stroke orange -strokewidth 1 -draw \"line %d,%d,%d,%d\" \\\n",x3,y3,x4,y4);
1486 printf("-stroke yellow -strokewidth 1 -draw \"line %d,%d,%d,%d\" \\\n",x2,y2,x4,y4);
1487 ss=draw_squares(s->upper_left_sub);
1488 draw_squares(s->upper_right_sub);
1489 draw_squares(s->lower_left_sub);
1490 draw_squares(s->lower_right_sub);
1491 return ss;
1492 }
1493 else {
1494
1495 printf("-stroke green -strokewidth 1 -draw \"line %d,%d,%d,%d\" \\\n",x1,y1,x2,y2);
1496 printf("-stroke red -strokewidth 1 -draw \"line %d,%d,%d,%d\" \\\n",x1,y1,x3,y3);
1497 printf("-stroke blue -strokewidth 1 -draw \"line %d,%d,%d,%d\" \\\n",x3,y3,x4,y4);
1498 printf("-stroke white -strokewidth 1 -draw \"line %d,%d,%d,%d\" \\\n",x2,y2,x4,y4);
1499 return (squares-s);
1500 }
1501
1502 }
1503
1504
1505
1506
1507 /* usage tilify xsize ysize seed basefile */
1508 int main (int argc,char *argv[]) {
1509 char *basefile; /* base.txt by convention */
1510 int xsize;
1511 int ysize;
1512 int degree;
1513 int levels;
1514 if (argc==6) {
1515 xsize=atoi(argv[1]);
1516 ysize=atoi(argv[2]);
1517 degree=atoi(argv[3]);
1518 levels=atoi(argv[4]);
1519 basefile=argv[5];
1520 }
1521 else {
1522 fprintf(stderr,"usage tilify xsize ysize degree levels basefile\n"
1523 "Where file has x|y|r|g|b text format\n"
1524 "oh and degree is hard coded to be percentage and levels is hard coded to 5 at the moment\n");
1525 exit(-1);
1526 }
1527 if (levels<1) levels=1;
1528 if (degree<1) degree=30;
1529 FILE *base;
1530 base = fopen(basefile,"r");
1531 char basebuf[10001];
1532 char otherbuf[10001];
1533 char alphabuf[10001];
1534 char hologrambuf[10001];
1535 unsigned char *a = (unsigned char *)malloc(sizeof(unsigned char)*3*xsize*ysize);
1536
1537
1538 fprintf(stderr,"reading\n");
1539 fprintf(stderr,"some inside %d",
1540 some_inside(5568,1,5568,0,5692,0,5456,58,5647,58)
1541 );
1542
1543
1544 #ifdef SCALE
1545 printf("# ImageMagick pixel enumeration: %d,%d,255,rgb\n", 9600,4020);
1546 #else
1547 printf("# ImageMagick pixel enumeration: %d,%d,255,rgb\n",xsize,ysize);
1548 #endif
1549 while (fgets(basebuf,10000,base)) {
1550 char *q;
1551 int xb,yb,rb,gb,bb;
1552 int xo,yo,ro,go,bo;
1553 int xa,ya,ra,ga,ba;
1554 int hb;
1555 xb = fieldi(basebuf,0);
1556 yb = fieldi(basebuf,1);
1557 rb = fieldi(basebuf,2);
1558 gb = fieldi(basebuf,3);
1559 bb = fieldi(basebuf,4);
1560 int loc= (yb*xsize+xb);
1561 loc = loc+loc+loc;
1562 a[loc++] = rb;
1563 a[loc++] = gb;
1564 a[loc++] = bb;
1565 }
1566
1567
1568 /* for each level, we know 4 points, and need to find 5 points more. */
1569 square_count++;
1570 struct square *top_square = squares;
1571 top_square->x1 = 0;
1572 top_square->y1 = 0;
1573 top_square->x2 = xsize;
1574 top_square->y2 = 0;
1575 top_square->x3 = 0;
1576 top_square->y3 = ysize;
1577 top_square->x4 = xsize;
1578 top_square->y4 = ysize;
1579 top_square->upper_left_sub = NULL;
1580 top_square->lower_left_sub = NULL;
1581 top_square->upper_right_sub = NULL;
1582 top_square->lower_right_sub = NULL;
1583 top_square->above = NULL;
1584 top_square->below = NULL;
1585 top_square->left = NULL;
1586 top_square->right = NULL;
1587
1588 fprintf(stderr,"find sub squares\n");
1589 int start_square;
1590 //printf("convert source.png -size 550x780 \\\n");
1591 start_square = find_sub_squares(a,xsize,ysize,degree,levels,levels,top_square);
1592
1593 fprintf(stderr,"scaling\n");
1594
1595 #ifdef SCALE
1596 //scale_it(top_square,xsize,ysize,6600,8800); /* for cyclone */
1597 //scale_it(top_square,xsize,ysize,63360,84480); /* for kristie*/
1598 //scale_it(top_square,xsize,ysize,30000,30000); /* for Cassidi */
1599 scale_it(top_square,xsize,ysize,9600,4020); /* for Cassidi */
1600 /* OK things are scaled, but because of the inaccuracy of ints, the mid points are
1601 kinda screwed up. So we will clean them up
1602 This is only useful if the midpoints don't float, and currently they don't
1603 */
1604 clean_scale(top_square);
1605 /* scale */
1606 xsize = 9600;
1607 ysize = 4020;
1608 #endif
1609 set_speed(top_square);
1610
1611
1612 int x,y;
1613 for (y=0;y<ysize;y++) {
1614 for (x=0;x<xsize;x++) {
1615 struct square *s;
1616 s = top_square;
1617 int l=0;
1618 while(s) {
1619 struct square *ss;
1620 l++;
1621 ss=s->upper_left_sub;
1622 if (!ss) {
1623 break;
1624 }
1625 if (some_inside1(x,y,ss->speed)) {
1626 s=ss;
1627 continue;
1628 }
1629 ss = s->upper_right_sub;
1630 if (some_inside1(x,y,ss->speed)) {
1631 s=ss;
1632 continue;
1633 }
1634 ss = s->lower_left_sub;
1635 if (some_inside1(x,y,ss->speed)) {
1636 s=ss;
1637 continue;
1638 }
1639 ss = s->lower_right_sub;
1640 if (some_inside1(x,y,ss->speed)) {
1641 s=ss;
1642 continue;
1643 }
1644
1645
1646
1647 int illie;
1648 illie=0;
1649
1650 illie++;
1651 /* make it bigger */
1652 ss=s->upper_left_sub;
1653 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1654 s=ss;
1655 continue;
1656 }
1657 ss = s->upper_right_sub;
1658 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1659 s=ss;
1660 continue;
1661 }
1662 ss = s->lower_left_sub;
1663 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1664 s=ss;
1665 continue;
1666 }
1667 ss = s->lower_right_sub;
1668 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1669 s=ss;
1670 continue;
1671 }
1672
1673
1674 illie++;
1675 /* make it bigger */
1676 ss=s->upper_left_sub;
1677 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1678 s=ss;
1679 continue;
1680 }
1681 ss = s->upper_right_sub;
1682 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1683 s=ss;
1684 continue;
1685 }
1686 ss = s->lower_left_sub;
1687 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1688 s=ss;
1689 continue;
1690 }
1691 ss = s->lower_right_sub;
1692 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1693 s=ss;
1694 continue;
1695 }
1696
1697
1698 illie++;
1699 /* make it bigger */
1700 ss=s->upper_left_sub;
1701 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1702 s=ss;
1703 continue;
1704 }
1705 ss = s->upper_right_sub;
1706 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1707 s=ss;
1708 continue;
1709 }
1710 ss = s->lower_left_sub;
1711 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1712 s=ss;
1713 continue;
1714 }
1715 ss = s->lower_right_sub;
1716 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1717 s=ss;
1718 continue;
1719 }
1720
1721
1722 illie++;
1723 /* make it bigger */
1724 ss=s->upper_left_sub;
1725 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1726 s=ss;
1727 continue;
1728 }
1729 ss = s->upper_right_sub;
1730 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1731 s=ss;
1732 continue;
1733 }
1734 ss = s->lower_left_sub;
1735 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1736 s=ss;
1737 continue;
1738 }
1739 ss = s->lower_right_sub;
1740 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1741 s=ss;
1742 continue;
1743 }
1744
1745
1746 illie++;
1747 /* make it bigger */
1748 ss=s->upper_left_sub;
1749 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1750 s=ss;
1751 continue;
1752 }
1753 ss = s->upper_right_sub;
1754 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1755 s=ss;
1756 continue;
1757 }
1758 ss = s->lower_left_sub;
1759 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1760 s=ss;
1761 continue;
1762 }
1763 ss = s->lower_right_sub;
1764 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1765 s=ss;
1766 continue;
1767 }
1768
1769
1770 illie++;
1771 /* make it bigger */
1772 ss=s->upper_left_sub;
1773 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1774 s=ss;
1775 continue;
1776 }
1777 ss = s->upper_right_sub;
1778 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1779 s=ss;
1780 continue;
1781 }
1782 ss = s->lower_left_sub;
1783 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1784 s=ss;
1785 continue;
1786 }
1787 ss = s->lower_right_sub;
1788 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1789 s=ss;
1790 continue;
1791 }
1792
1793
1794 illie++;
1795 /* make it bigger */
1796 ss=s->upper_left_sub;
1797 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1798 s=ss;
1799 continue;
1800 }
1801 ss = s->upper_right_sub;
1802 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1803 s=ss;
1804 continue;
1805 }
1806 ss = s->lower_left_sub;
1807 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1808 s=ss;
1809 continue;
1810 }
1811 ss = s->lower_right_sub;
1812 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1813 s=ss;
1814 continue;
1815 }
1816
1817
1818 illie++;
1819 /* make it bigger */
1820 ss=s->upper_left_sub;
1821 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1822 s=ss;
1823 continue;
1824 }
1825 ss = s->upper_right_sub;
1826 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1827 s=ss;
1828 continue;
1829 }
1830 ss = s->lower_left_sub;
1831 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1832 s=ss;
1833 continue;
1834 }
1835 ss = s->lower_right_sub;
1836 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1837 s=ss;
1838 continue;
1839 }
1840
1841
1842 illie++;
1843 /* make it bigger */
1844 ss=s->upper_left_sub;
1845 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1846 s=ss;
1847 continue;
1848 }
1849 ss = s->upper_right_sub;
1850 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1851 s=ss;
1852 continue;
1853 }
1854 ss = s->lower_left_sub;
1855 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1856 s=ss;
1857 continue;
1858 }
1859 ss = s->lower_right_sub;
1860 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1861 s=ss;
1862 continue;
1863 }
1864
1865
1866 illie++;
1867 /* make it bigger */
1868 ss=s->upper_left_sub;
1869 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1870 s=ss;
1871 continue;
1872 }
1873 ss = s->upper_right_sub;
1874 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1875 s=ss;
1876 continue;
1877 }
1878 ss = s->lower_left_sub;
1879 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1880 s=ss;
1881 continue;
1882 }
1883 ss = s->lower_right_sub;
1884 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1885 s=ss;
1886 continue;
1887 }
1888
1889
1890 illie++;
1891 /* make it bigger */
1892 ss=s->upper_left_sub;
1893 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1894 s=ss;
1895 continue;
1896 }
1897 ss = s->upper_right_sub;
1898 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1899 s=ss;
1900 continue;
1901 }
1902 ss = s->lower_left_sub;
1903 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1904 s=ss;
1905 continue;
1906 }
1907 ss = s->lower_right_sub;
1908 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1909 s=ss;
1910 continue;
1911 }
1912
1913
1914 illie++;
1915 /* make it bigger */
1916 ss=s->upper_left_sub;
1917 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1918 s=ss;
1919 continue;
1920 }
1921 ss = s->upper_right_sub;
1922 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1923 s=ss;
1924 continue;
1925 }
1926 ss = s->lower_left_sub;
1927 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1928 s=ss;
1929 continue;
1930 }
1931 ss = s->lower_right_sub;
1932 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1933 s=ss;
1934 continue;
1935 }
1936
1937
1938 illie++;
1939 /* make it bigger */
1940 ss=s->upper_left_sub;
1941 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1942 s=ss;
1943 continue;
1944 }
1945 ss = s->upper_right_sub;
1946 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1947 s=ss;
1948 continue;
1949 }
1950 ss = s->lower_left_sub;
1951 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1952 s=ss;
1953 continue;
1954 }
1955 ss = s->lower_right_sub;
1956 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1957 s=ss;
1958 continue;
1959 }
1960
1961
1962 illie++;
1963 /* make it bigger */
1964 ss=s->upper_left_sub;
1965 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1966 s=ss;
1967 continue;
1968 }
1969 ss = s->upper_right_sub;
1970 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1971 s=ss;
1972 continue;
1973 }
1974 ss = s->lower_left_sub;
1975 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1976 s=ss;
1977 continue;
1978 }
1979 ss = s->lower_right_sub;
1980 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1981 s=ss;
1982 continue;
1983 }
1984
1985
1986 illie++;
1987 /* make it bigger */
1988 ss=s->upper_left_sub;
1989 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1990 s=ss;
1991 continue;
1992 }
1993 ss = s->upper_right_sub;
1994 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
1995 s=ss;
1996 continue;
1997 }
1998 ss = s->lower_left_sub;
1999 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2000 s=ss;
2001 continue;
2002 }
2003 ss = s->lower_right_sub;
2004 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2005 s=ss;
2006 continue;
2007 }
2008
2009
2010 illie++;
2011 /* make it bigger */
2012 ss=s->upper_left_sub;
2013 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2014 s=ss;
2015 continue;
2016 }
2017 ss = s->upper_right_sub;
2018 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2019 s=ss;
2020 continue;
2021 }
2022 ss = s->lower_left_sub;
2023 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2024 s=ss;
2025 continue;
2026 }
2027 ss = s->lower_right_sub;
2028 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2029 s=ss;
2030 continue;
2031 }
2032
2033
2034 illie++;
2035 /* make it bigger */
2036 ss=s->upper_left_sub;
2037 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2038 s=ss;
2039 continue;
2040 }
2041 ss = s->upper_right_sub;
2042 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2043 s=ss;
2044 continue;
2045 }
2046 ss = s->lower_left_sub;
2047 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2048 s=ss;
2049 continue;
2050 }
2051 ss = s->lower_right_sub;
2052 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2053 s=ss;
2054 continue;
2055 }
2056
2057
2058 illie++;
2059 /* make it bigger */
2060 ss=s->upper_left_sub;
2061 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2062 s=ss;
2063 continue;
2064 }
2065 ss = s->upper_right_sub;
2066 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2067 s=ss;
2068 continue;
2069 }
2070 ss = s->lower_left_sub;
2071 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2072 s=ss;
2073 continue;
2074 }
2075 ss = s->lower_right_sub;
2076 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2077 s=ss;
2078 continue;
2079 }
2080
2081
2082 illie++;
2083 /* make it bigger */
2084 ss=s->upper_left_sub;
2085 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2086 s=ss;
2087 continue;
2088 }
2089 ss = s->upper_right_sub;
2090 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2091 s=ss;
2092 continue;
2093 }
2094 ss = s->lower_left_sub;
2095 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2096 s=ss;
2097 continue;
2098 }
2099 ss = s->lower_right_sub;
2100 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2101 s=ss;
2102 continue;
2103 }
2104
2105
2106 illie++;
2107 /* make it bigger */
2108 ss=s->upper_left_sub;
2109 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2110 s=ss;
2111 continue;
2112 }
2113 ss = s->upper_right_sub;
2114 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2115 s=ss;
2116 continue;
2117 }
2118 ss = s->lower_left_sub;
2119 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2120 s=ss;
2121 continue;
2122 }
2123 ss = s->lower_right_sub;
2124 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2125 s=ss;
2126 continue;
2127 }
2128
2129
2130 illie++;
2131 /* make it bigger */
2132 ss=s->upper_left_sub;
2133 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2134 s=ss;
2135 continue;
2136 }
2137 ss = s->upper_right_sub;
2138 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2139 s=ss;
2140 continue;
2141 }
2142 ss = s->lower_left_sub;
2143 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2144 s=ss;
2145 continue;
2146 }
2147 ss = s->lower_right_sub;
2148 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2149 s=ss;
2150 continue;
2151 }
2152
2153
2154 illie++;
2155 /* make it bigger */
2156 ss=s->upper_left_sub;
2157 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2158 s=ss;
2159 continue;
2160 }
2161 ss = s->upper_right_sub;
2162 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2163 s=ss;
2164 continue;
2165 }
2166 ss = s->lower_left_sub;
2167 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2168 s=ss;
2169 continue;
2170 }
2171 ss = s->lower_right_sub;
2172 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2173 s=ss;
2174 continue;
2175 }
2176
2177
2178 illie++;
2179 /* make it bigger */
2180 ss=s->upper_left_sub;
2181 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2182 s=ss;
2183 continue;
2184 }
2185 ss = s->upper_right_sub;
2186 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2187 s=ss;
2188 continue;
2189 }
2190 ss = s->lower_left_sub;
2191 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2192 s=ss;
2193 continue;
2194 }
2195 ss = s->lower_right_sub;
2196 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2197 s=ss;
2198 continue;
2199 }
2200
2201
2202 illie++;
2203 /* make it bigger */
2204 ss=s->upper_left_sub;
2205 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2206 s=ss;
2207 continue;
2208 }
2209 ss = s->upper_right_sub;
2210 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2211 s=ss;
2212 continue;
2213 }
2214 ss = s->lower_left_sub;
2215 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2216 s=ss;
2217 continue;
2218 }
2219 ss = s->lower_right_sub;
2220 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2221 s=ss;
2222 continue;
2223 }
2224
2225
2226 illie++;
2227 /* make it bigger */
2228 ss=s->upper_left_sub;
2229 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2230 s=ss;
2231 continue;
2232 }
2233 ss = s->upper_right_sub;
2234 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2235 s=ss;
2236 continue;
2237 }
2238 ss = s->lower_left_sub;
2239 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2240 s=ss;
2241 continue;
2242 }
2243 ss = s->lower_right_sub;
2244 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2245 s=ss;
2246 continue;
2247 }
2248
2249
2250 illie++;
2251 /* make it bigger */
2252 ss=s->upper_left_sub;
2253 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2254 s=ss;
2255 continue;
2256 }
2257 ss = s->upper_right_sub;
2258 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2259 s=ss;
2260 continue;
2261 }
2262 ss = s->lower_left_sub;
2263 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2264 s=ss;
2265 continue;
2266 }
2267 ss = s->lower_right_sub;
2268 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2269 s=ss;
2270 continue;
2271 }
2272
2273
2274 illie++;
2275 /* make it bigger */
2276 ss=s->upper_left_sub;
2277 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2278 s=ss;
2279 continue;
2280 }
2281 ss = s->upper_right_sub;
2282 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2283 s=ss;
2284 continue;
2285 }
2286 ss = s->lower_left_sub;
2287 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2288 s=ss;
2289 continue;
2290 }
2291 ss = s->lower_right_sub;
2292 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2293 s=ss;
2294 continue;
2295 }
2296
2297
2298 illie++;
2299 /* make it bigger */
2300 ss=s->upper_left_sub;
2301 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2302 s=ss;
2303 continue;
2304 }
2305 ss = s->upper_right_sub;
2306 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2307 s=ss;
2308 continue;
2309 }
2310 ss = s->lower_left_sub;
2311 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2312 s=ss;
2313 continue;
2314 }
2315 ss = s->lower_right_sub;
2316 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2317 s=ss;
2318 continue;
2319 }
2320
2321
2322 illie++;
2323 /* make it bigger */
2324 ss=s->upper_left_sub;
2325 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2326 s=ss;
2327 continue;
2328 }
2329 ss = s->upper_right_sub;
2330 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2331 s=ss;
2332 continue;
2333 }
2334 ss = s->lower_left_sub;
2335 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2336 s=ss;
2337 continue;
2338 }
2339 ss = s->lower_right_sub;
2340 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2341 s=ss;
2342 continue;
2343 }
2344
2345
2346 illie++;
2347 /* make it bigger */
2348 ss=s->upper_left_sub;
2349 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2350 s=ss;
2351 continue;
2352 }
2353 ss = s->upper_right_sub;
2354 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2355 s=ss;
2356 continue;
2357 }
2358 ss = s->lower_left_sub;
2359 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2360 s=ss;
2361 continue;
2362 }
2363 ss = s->lower_right_sub;
2364 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2365 s=ss;
2366 continue;
2367 }
2368
2369
2370 illie++;
2371 /* make it bigger */
2372 ss=s->upper_left_sub;
2373 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2374 s=ss;
2375 continue;
2376 }
2377 ss = s->upper_right_sub;
2378 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2379 s=ss;
2380 continue;
2381 }
2382 ss = s->lower_left_sub;
2383 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2384 s=ss;
2385 continue;
2386 }
2387 ss = s->lower_right_sub;
2388 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2389 s=ss;
2390 continue;
2391 }
2392
2393
2394 illie++;
2395 /* make it bigger */
2396 ss=s->upper_left_sub;
2397 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2398 s=ss;
2399 continue;
2400 }
2401 ss = s->upper_right_sub;
2402 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2403 s=ss;
2404 continue;
2405 }
2406 ss = s->lower_left_sub;
2407 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2408 s=ss;
2409 continue;
2410 }
2411 ss = s->lower_right_sub;
2412 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2413 s=ss;
2414 continue;
2415 }
2416
2417
2418 illie++;
2419 /* make it bigger */
2420 ss=s->upper_left_sub;
2421 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2422 s=ss;
2423 continue;
2424 }
2425 ss = s->upper_right_sub;
2426 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2427 s=ss;
2428 continue;
2429 }
2430 ss = s->lower_left_sub;
2431 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2432 s=ss;
2433 continue;
2434 }
2435 ss = s->lower_right_sub;
2436 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2437 s=ss;
2438 continue;
2439 }
2440
2441
2442 illie++;
2443 /* make it bigger */
2444 ss=s->upper_left_sub;
2445 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2446 s=ss;
2447 continue;
2448 }
2449 ss = s->upper_right_sub;
2450 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2451 s=ss;
2452 continue;
2453 }
2454 ss = s->lower_left_sub;
2455 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2456 s=ss;
2457 continue;
2458 }
2459 ss = s->lower_right_sub;
2460 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2461 s=ss;
2462 continue;
2463 }
2464
2465
2466 illie++;
2467 /* make it bigger */
2468 ss=s->upper_left_sub;
2469 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2470 s=ss;
2471 continue;
2472 }
2473 ss = s->upper_right_sub;
2474 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2475 s=ss;
2476 continue;
2477 }
2478 ss = s->lower_left_sub;
2479 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2480 s=ss;
2481 continue;
2482 }
2483 ss = s->lower_right_sub;
2484 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2485 s=ss;
2486 continue;
2487 }
2488
2489
2490 illie++;
2491 /* make it bigger */
2492 ss=s->upper_left_sub;
2493 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2494 s=ss;
2495 continue;
2496 }
2497 ss = s->upper_right_sub;
2498 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2499 s=ss;
2500 continue;
2501 }
2502 ss = s->lower_left_sub;
2503 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2504 s=ss;
2505 continue;
2506 }
2507 ss = s->lower_right_sub;
2508 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2509 s=ss;
2510 continue;
2511 }
2512
2513
2514 illie++;
2515 /* make it bigger */
2516 ss=s->upper_left_sub;
2517 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2518 s=ss;
2519 continue;
2520 }
2521 ss = s->upper_right_sub;
2522 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2523 s=ss;
2524 continue;
2525 }
2526 ss = s->lower_left_sub;
2527 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2528 s=ss;
2529 continue;
2530 }
2531 ss = s->lower_right_sub;
2532 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2533 s=ss;
2534 continue;
2535 }
2536
2537
2538 illie++;
2539 /* make it bigger */
2540 ss=s->upper_left_sub;
2541 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2542 s=ss;
2543 continue;
2544 }
2545 ss = s->upper_right_sub;
2546 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2547 s=ss;
2548 continue;
2549 }
2550 ss = s->lower_left_sub;
2551 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2552 s=ss;
2553 continue;
2554 }
2555 ss = s->lower_right_sub;
2556 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2557 s=ss;
2558 continue;
2559 }
2560
2561
2562 illie++;
2563 /* make it bigger */
2564 ss=s->upper_left_sub;
2565 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2566 s=ss;
2567 continue;
2568 }
2569 ss = s->upper_right_sub;
2570 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2571 s=ss;
2572 continue;
2573 }
2574 ss = s->lower_left_sub;
2575 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2576 s=ss;
2577 continue;
2578 }
2579 ss = s->lower_right_sub;
2580 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2581 s=ss;
2582 continue;
2583 }
2584
2585
2586 illie++;
2587 /* make it bigger */
2588 ss=s->upper_left_sub;
2589 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2590 s=ss;
2591 continue;
2592 }
2593 ss = s->upper_right_sub;
2594 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2595 s=ss;
2596 continue;
2597 }
2598 ss = s->lower_left_sub;
2599 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2600 s=ss;
2601 continue;
2602 }
2603 ss = s->lower_right_sub;
2604 if (some_inside(x,y,ss->x1-illie,ss->y1-illie,ss->x2+illie,ss->y2-illie,ss->x3-illie,ss->y3+illie,ss->x4+illie,ss->y4+illie)) {
2605 s=ss;
2606 continue;
2607 }
2608
2609
2610
2611 fprintf(stderr,"failed %d levels down x %d y %d \n",l,x,y);
2612 ss=s->upper_left_sub;
2613 fprintf(stderr,"UL %d,%d %d,%d\n %d,%d %d,%d\n",ss->x1,ss->y1,ss->x2,ss->y2,
2614 ss->x3,ss->y3,ss->x4,ss->y4);
2615 ss = s->upper_right_sub;
2616 fprintf(stderr,"UR %d,%d %d,%d\n %d,%d %d,%d\n",ss->x1,ss->y1,ss->x2,ss->y2,
2617 ss->x3,ss->y3,ss->x4,ss->y4);
2618 ss = s->lower_left_sub;
2619 fprintf(stderr,"LL %d,%d %d,%d\n %d,%d %d,%d\n",ss->x1,ss->y1,ss->x2,ss->y2,
2620 ss->x3,ss->y3,ss->x4,ss->y4);
2621 ss = s->lower_right_sub;
2622 fprintf(stderr,"LR %d,%d %d,%d\n %d,%d %d,%d\n",ss->x1,ss->y1,ss->x2,ss->y2,
2623 ss->x3,ss->y3,ss->x4,ss->y4);
2624 ss=s;
2625 fprintf(stderr,"SS %d,%d %d,%d\n %d,%d %d,%d\n\n",ss->x1,ss->y1,ss->x2,ss->y2,
2626 ss->x3,ss->y3,ss->x4,ss->y4);
2627
2628 ss = s->upper_left_sub;
2629 fprintf(stderr,"iUL %d,%d %d,%d\n %d,%d %d,%d\n",ss->x1-illie,ss->y1-illie
2630 ,ss->x2+illie,ss->y2-illie,
2631 ss->x3-illie,ss->y3+illie,
2632 ss->x4+illie,ss->y4+illie);
2633 ss = s->upper_right_sub;
2634 fprintf(stderr,"iUR %d,%d %d,%d\n %d,%d %d,%d\n",ss->x1-illie,ss->y1-illie
2635 ,ss->x2+illie,ss->y2-illie,
2636 ss->x3-illie,ss->y3+illie,
2637 ss->x4+illie,ss->y4+illie);
2638 ss = s->lower_left_sub;
2639 fprintf(stderr,"iLL %d,%d %d,%d\n %d,%d %d,%d\n",ss->x1-illie,ss->y1-illie
2640 ,ss->x2+illie,ss->y2-illie,
2641 ss->x3-illie,ss->y3+illie,
2642 ss->x4+illie,ss->y4+illie);
2643 ss = s->lower_right_sub;
2644 fprintf(stderr,"iLR %d,%d %d,%d\n %d,%d %d,%d\n\n",ss->x1-illie,ss->y1-illie
2645 ,ss->x2+illie,ss->y2-illie,
2646 ss->x3-illie,ss->y3+illie,
2647 ss->x4+illie,ss->y4+illie);
2648 ss=s;
2649
2650 break;
2651 }
2652 int rf,gf,bf;
2653 rf = s->r;
2654 gf = s->g;
2655 bf = s->b;
2656 int total;
2657 total = rf*65536+gf*256+bf;
2658 printf("%d,%d: (%d,%d,%d) #%06x rgb(%d,%d,%d)\n",
2659 x,y,rf,gf,bf,total,rf,gf,bf);
2660 } /* for x */
2661 } /* for y */
2662
2663
2664 exit(0);
2665 }
2666
2667
2668
2669
2670

  ViewVC Help
Powered by ViewVC 1.1.5