~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tv/tv_draw.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <tina/sys.h>
  2 #include <tina/sysfuncs.h>
  3 #include <tina/math.h>
  4 #include <tina/mathfuncs.h>
  5 #include <tina/tv.h>
  6 #include <tina/tvfuncs.h>
  7 
  8 /* EXTERNS */
  9 extern void *tw_tool();
 10 extern void tv_screen_point();
 11 extern void tv_screen_line();
 12 extern void tv_screen_point();
 13 extern void tv_screen_raster();
 14 extern void tv_screen_rect();
 15 extern void tv_screen_circle();
 16 extern void tv_screen_erase();
 17 extern void tv_screen_fillrect();
 18 extern void tv_screen_flush();
 19 extern void tv_screen_image();
 20 extern void tv_screen_line();
 21 extern void tv_screen_point();
 22 extern void tv_screen_polyline();
 23 extern void tv_screen_raster();
 24 extern void tv_screen_text();
 25 
 26 Ipos tv_proj2();
 27 Ipos tv_proj3();
 28 Vec2 tv_backproj2();
 29 
 30 void tv_flush(Tv * tv)
 31 {
 32     if (tv == NULL)
 33         return;
 34     tv_screen_flush(tv->tv_screen);
 35 }
 36 
 37 void tv_erase(Tv * tv)
 38 {
 39     if (tv == NULL)
 40         return;
 41     tv_screen_erase(tv->tv_screen);
 42 }
 43 
 44 void tv_point(Tv * tv, Ipos p)
 45 {
 46     if (tv == NULL)
 47         return;
 48     tv_screen_point(tv->tv_screen, p);
 49 }
 50 
 51 void tv_pointxy(Tv * tv, int x, int y)
 52 {
 53     if (tv == NULL)
 54         return;
 55     tv_screen_point(tv->tv_screen, ipos(x, y));
 56 }
 57 
 58 void tv_point2(Tv * tv, Vec2 p)
 59 {
 60     if (tv == NULL)
 61         return;
 62     tv_screen_point(tv->tv_screen, tv_proj2(tv, p));
 63 }
 64 
 65 void tv_point3(Tv * tv, Vec3 p)
 66 {
 67     if (tv == NULL)
 68         return;
 69     tv_screen_point(tv->tv_screen, tv_proj3(tv, p));
 70 }
 71 
 72 void tv_line(Tv * tv, Ipos p1, Ipos p2)
 73 {
 74     if (tv == NULL)
 75         return;
 76     tv_screen_line(tv->tv_screen, p1, p2);
 77 }
 78 
 79 void tv_linexy(Tv * tv, int x1, int y1, int x2, int y2)
 80 {
 81     if (tv == NULL)
 82         return;
 83     tv_screen_line(tv->tv_screen, ipos(x1, y1), ipos(x2, y2));
 84 }
 85 
 86 void tv_line2(Tv * tv, Vec2 p1, Vec2 p2)
 87 {
 88     if (tv == NULL)
 89         return;
 90     tv_screen_line(tv->tv_screen, tv_proj2(tv, p1), tv_proj2(tv, p2));
 91 }
 92 
 93 void tv_line3(Tv * tv, Vec3 p1, Vec3 p2)
 94 {
 95     if (tv == NULL)
 96         return;
 97     tv_screen_line(tv->tv_screen, tv_proj3(tv, p1), tv_proj3(tv, p2));
 98 }
 99 
100 void tv_dot(Tv * tv, Ipos p)
101 {
102     int x = ipos_x(p);
103     int y = ipos_y(p);
104     if (tv == NULL)
105         return;
106     tv_screen_fillrect(tv->tv_screen, ipos(x - 1, y - 1), ipos(x + 2, y + 2));
107 }
108 
109 void tv_dotxy(Tv * tv, int x, int y)
110 {
111     tv_dot(tv, ipos(x, y));
112 }
113 
114 void tv_dot2(Tv * tv, Vec2 p)
115 {
116     if (tv == NULL)
117         return;
118     tv_dot(tv, tv_proj2(tv, p));
119 }
120 
121 void tv_dot3(Tv * tv, Vec3 p)
122 {
123     if (tv == NULL)
124         return;
125     tv_dot(tv, tv_proj3(tv, p));
126 }
127 
128 void tv_bigdot(Tv * tv, Ipos p, int n)
129 {
130     int x = ipos_x(p);
131     int y = ipos_y(p);
132     if (tv == NULL)
133         return;
134     tv_screen_fillrect(tv->tv_screen, ipos(x - n, y - n), ipos(x + n + 1, y + n + 1));
135 }
136 
137 void tv_bigdot2(Tv * tv, Vec2 p, int n)
138 {
139     if (tv == NULL)
140         return;
141     tv_bigdot(tv, tv_proj2(tv, p), n);
142 }
143 
144 void tv_bigdot3(Tv * tv, Vec3 p, int n)
145 {
146     if (tv == NULL)
147         return;
148     tv_bigdot(tv, tv_proj3(tv, p), n);
149 }
150 
151 void tv_cross(Tv * tv, Ipos p, int n)
152 {
153     int x0, x1, x2;
154     int y0, y1, y2;
155     if (tv == NULL)
156         return;
157     x1 = ipos_x(p);
158     x0 = x1 - n;
159     x2 = x1 + n;
160     y1 = ipos_y(p);
161     y0 = y1 - n;
162     y2 = y1 + n;
163     tv_line(tv, ipos(x0, y1), ipos(x2, y1));
164     tv_line(tv, ipos(x1, y0), ipos(x1, y2));
165 }
166 
167 void tv_cross2(Tv * tv, Vec2 p, int n)
168 {
169     if (tv == NULL)
170         return;
171     tv_cross(tv, tv_proj2(tv, p), n);
172 }
173 
174 void tv_cross3(Tv * tv, Vec3 p, int n)
175 {
176     if (tv == NULL)
177         return;
178     tv_cross(tv, tv_proj3(tv, p), n);
179 }
180 
181 void tv_vector(Tv * tv, Ipos p, Ipos v)
182 {
183     if (tv == NULL)
184         return;
185     tv_dot(tv, p);
186     tv_line(tv, p, ipos_sum(p, v));
187 }
188 
189 void tv_vector2(Tv * tv, Vec2 p, Vec2 v)
190 {
191     tv_dot2(tv, p);
192     tv_line2(tv, p, vec2_sum(p, v));
193 }
194 
195 void tv_vector3(Tv * tv, Vec3 p, Vec3 v)
196 {
197     tv_dot3(tv, p);
198     tv_line3(tv, p, vec3_sum(p, v));
199 }
200 
201 void tv_polyline(Tv * tv, List * points)
202 {
203     if (tv == NULL)
204         return;
205     tv_screen_polyline(tv->tv_screen, points);
206 }
207 
208 void tv_polyline2(Tv * tv, List * points)
209 {
210     List *ptr;
211     List *ipoints = NULL;
212     List *ref_addtostart();
213     if (tv == NULL)
214         return;
215     for (ptr = points; ptr != NULL; ptr = ptr->next)
216     {
217         Ipos *p = ipos_alloc();
218         *p = tv_proj2(tv, *((Vec2 *) ptr->to));
219         ipoints = ref_addtostart(ipoints, (void *) &p, (int)NULL);
220     }
221     tv_screen_polyline(tv->tv_screen, ipoints);
222     list_rm(ipoints, rfree);
223 }
224 
225 void tv_polyline3(Tv * tv, List * points)
226 {
227     List *ptr;
228     List *ipoints = NULL;
229     List *ref_addtostart();
230     if (tv == NULL)
231         return;
232     for (ptr = points; ptr != NULL; ptr = ptr->next)
233     {
234         Ipos *p = ipos_alloc();
235         *p = tv_proj3(tv, *((Vec3 *) ptr->to));
236         ipoints = ref_addtostart(ipoints, (void *) &p, (int)NULL);
237     }
238     tv_screen_polyline(tv->tv_screen, ipoints);
239     list_rm(ipoints, rfree);
240 }
241 
242 void tv_quad(Tv * tv, Ipos p1, Ipos p2, Ipos p3, Ipos p4)
243 {
244     tv_line(tv, p1, p2);
245     tv_line(tv, p2, p3);
246     tv_line(tv, p3, p4);
247     tv_line(tv, p4, p1);
248 }
249 
250 void tv_quad2(Tv * tv, Vec2 p1, Vec2 p2, Vec2 p3, Vec2 p4)
251 {
252     tv_line2(tv, p1, p2);
253     tv_line2(tv, p2, p3);
254     tv_line2(tv, p3, p4);
255     tv_line2(tv, p4, p1);
256 }
257 
258 void tv_quad3(Tv * tv, Vec3 p1, Vec3 p2, Vec3 p3, Vec3 p4)
259 {
260     tv_line3(tv, p1, p2);
261     tv_line3(tv, p2, p3);
262     tv_line3(tv, p3, p4);
263     tv_line3(tv, p4, p1);
264 }
265 
266 void tv_rect(Tv * tv, Ipos p1, Ipos p2)
267 {
268     int x1, x2, sx;
269     int y1, y2, sy;
270     if (tv == NULL)
271         return;
272     x1 = ipos_x(p1);
273     x2 = ipos_x(p2);
274     y1 = ipos_y(p1);
275     y2 = ipos_y(p2);
276     if (x1 == x2 || y1 == y2)
277     {
278         if (x1 == x2 && y1 == y2)
279             tv_point(tv, p1);
280         else
281             tv_line(tv, p1, p2);
282         return;
283     }
284     sx = (x1 < x2) ? 1 : -1;
285     sy = (y1 < y2) ? 1 : -1;
286     tv_line(tv, ipos(x1, y1), ipos(x1, y2));
287     tv_line(tv, ipos(x1, y1), ipos(x2, y1));
288     tv_line(tv, ipos(x1 + sx, y2), ipos(x2, y2));
289     tv_line(tv, ipos(x2, y1 + sy), ipos(x2, y2));
290 }
291 
292 void tv_rect2(Tv * tv, Vec2 p1, Vec2 p2)
293 {
294     if (tv == NULL)
295         return;
296     tv_rect(tv, tv_proj2(tv, p1), tv_proj2(tv, p2));
297 }
298 
299 void tv_rect3(Tv * tv, Vec3 p1, Vec3 p2)
300 {
301     if (tv == NULL)
302         return;
303     tv_rect(tv, tv_proj3(tv, p1), tv_proj3(tv, p2));
304 }
305 
306 void tv_fillrect(Tv * tv, Ipos p1, Ipos p2)
307 {
308     if (tv == NULL)
309         return;
310     tv_screen_fillrect(tv->tv_screen, p1, p2);
311 }
312 
313 void tv_fillrectxy(Tv * tv, int x1, int y1, int x2, int y2)
314 {
315     if (tv == NULL)
316         return;
317     tv_screen_fillrect(tv->tv_screen, ipos(x1, y1), ipos(x2, y2));
318 }
319 
320 void tv_fillrect2(Tv * tv, Vec2 p1, Vec2 p2)
321 {
322     if (tv == NULL)
323         return;
324     tv_screen_fillrect(tv->tv_screen, tv_proj2(tv, p1), tv_proj2(tv, p2));
325 }
326 
327 void tv_fillrect3(Tv * tv, Vec3 p1, Vec3 p2)
328 {
329     if (tv == NULL)
330         return;
331     tv_screen_fillrect(tv->tv_screen, tv_proj3(tv, p1), tv_proj3(tv, p2));
332 }
333 
334 void tv_text(Tv * tv, char *string, Ipos p)
335 {
336     if (tv == NULL)
337         return;
338     tv_screen_text(tv->tv_screen, string, p);
339 }
340 
341 void tv_textxy(Tv * tv, char *string, int x, int y)
342 {
343     if (tv == NULL)
344         return;
345     tv_screen_text(tv->tv_screen, string, ipos(x, y));
346 }
347 
348 void tv_text2(Tv * tv, char *string, Vec2 p)
349 {
350     if (tv == NULL)
351         return;
352     tv_screen_text(tv->tv_screen, string, tv_proj2(tv, p));
353 }
354 
355 void tv_text3(Tv * tv, char *string, Vec3 p)
356 {
357     if (tv == NULL)
358         return;
359     tv_screen_text(tv->tv_screen, string, tv_proj3(tv, p));
360 }
361 
362 void tv_offset_text(Tv * tv, char *string, Ipos p, int offx, int offy)
363 {
364     if (tv == NULL)
365         return;
366     p.x += offx;
367     p.y += offy;
368     tv_screen_text(tv->tv_screen, string, p);
369 }
370 
371 void tv_offset_text2(Tv * tv, char *string, Vec2 p, int offx, int offy)
372 {
373     if (tv == NULL)
374         return;
375     tv_offset_text(tv, string, tv_proj2(tv, p), offx, offy);
376 }
377 
378 void tv_offset_text3(Tv * tv, char *string, Vec3 p, int offx, int offy)
379 {
380     if (tv == NULL)
381         return;
382     tv_offset_text(tv, string, tv_proj3(tv, p), offx, offy);
383 }
384 
385 void tv_pixel2(Tv * tv, Vec2 p)
386 {
387     Ipos pos1 = {Ipos_id};
388     Ipos pos2 = {Ipos_id};
389     if (tv == NULL)
390         return;
391 
392     vec2_x(p) = (float)(tina_int(vec2_x(p)));
393     vec2_y(p) = (float)(tina_int(vec2_y(p)));
394     pos1 = tv_proj2(tv, p);
395 
396     vec2_x(p) += (float)1.0;
397     vec2_y(p) += (float)1.0;
398     pos2 = tv_proj2(tv, p);
399 
400     if (ipos_equal(pos1, pos2))
401     {
402         tv_screen_point(tv->tv_screen, pos1);
403         return;
404     }
405     if (ipos_x(pos2) == ipos_x(pos1))
406     {
407         ipos_y(pos2) -= 1;
408 
409         if (ipos_equal(pos1, pos2))
410             tv_screen_point(tv->tv_screen, pos1);
411         tv_screen_line(tv->tv_screen, pos1, pos2);
412         return;
413     }
414     if (ipos_y(pos2) == ipos_y(pos1))
415     {
416         ipos_x(pos2) -= 1;
417         if (ipos_equal(pos1, pos2))
418             tv_screen_point(tv->tv_screen, pos1);
419         tv_screen_line(tv->tv_screen, pos1, pos2);
420         return;
421     }
422     ipos_x(pos2) -= 1;
423     ipos_y(pos2) -= 1;
424 
425     if (ipos_equal(pos1, pos2))
426         tv_screen_point(tv->tv_screen, pos1);
427     else
428         tv_screen_rect(tv->tv_screen, pos1, pos2);
429 }
430 
431 void tv_fillpixel2(Tv * tv, Vec2 p)
432 {
433     Ipos pos1 = {Ipos_id};
434     Ipos pos2 = {Ipos_id};
435     if (tv == NULL)
436         return;
437 
438     vec2_x(p) = (float)(tina_int(vec2_x(p)));
439     vec2_y(p) = (float)(tina_int(vec2_y(p)));
440     pos1 = tv_proj2(tv, p);
441 
442     vec2_x(p) += (float)1.0;
443     vec2_y(p) += (float)1.0;
444     pos2 = tv_proj2(tv, p);
445 
446     if (ipos_equal(pos1, pos2))
447     {
448         tv_screen_point(tv->tv_screen, pos1);
449         return;
450     }
451     ipos_x(pos2) -= 1;
452     ipos_y(pos2) -= 1;
453 
454     tv_screen_fillrect(tv->tv_screen, pos1, pos2);
455 }
456 
457 void tv_circle(Tv * tv, Ipos centre, int radius)
458 {
459     if (tv == NULL)
460         return;
461     tv_screen_circle(tv->tv_screen, centre, radius);
462 }
463 
464 void tv_circle2(Tv * tv, Vec2 centre, double radius)
465 {
466     extern void tv_screen_circle();
467     Ipos c = {Ipos_id};
468     int r;
469     if (tv == NULL)
470         return;
471     c = tv_proj2(tv, centre);
472     r = (int) (radius * tv->scalex);    /** what about scalex != scaley ? **/
473     tv_screen_circle(tv->tv_screen, c, r);
474 }
475 
476 void tv_raster(Tv * tv, int x1, int x2, int y, char *raster)
477 {
478     /* assumes grey level conversion complete */
479     if (tv == NULL)
480         return;
481     tv_screen_raster(tv->tv_screen, x1, x2, y, raster + x1);
482 }
483 
484 /*
485 may not work with 16 bit colormaps 
486 void tv_raster2(Tv * tv, int c1, int c2, int r, char *raster)
487 
488 
489 {
490     Ipos ll = {Ipos_id};
491     Ipos ur = {Ipos_id};        
492     int lx, ly, ux, uy;
493     float sx, imx;
494     char *tv_screen_rast;
495     int i;
496     Vec2 v2 = {Vec2_id};
497     if (tv == NULL || tv->tv_screen == NULL)
498         return;
499 
500     ll = tv_proj2(tv, vec2((float) c1, (float) r));
501     ur = tv_proj2(tv, vec2((float) c2, r + 1.0));
502 
503     lx = MAX(0, ipos_x(ll));
504     ux = MIN(tv->width, ipos_x(ur));
505     ly = MAX(0, ipos_y(ll));
506     uy = MIN(tv->height, ipos_y(ur));
507 
508     if (ly == uy)
509         ++uy;
510 
511     if (ux < 0 || lx >= tv->width || uy < 0 || ly >= tv->height)
512         return;
513 
514     sx = (float)(1.0 / tv->scalex);
515     v2 = tv_backproj2(tv, ipos(lx, ly));
516     imx = vec2_x(v2);
517 
518     while (imx < c1)
519     {
520         ++lx;
521         imx += sx;
522     }
523 
524     tv_screen_rast = cvector_alloc(lx, ux);
525 
526     for (i = lx; i < ux; ++i)
527     {
528         tv_screen_rast[i] = raster[(int) imx];
529         imx += sx;
530     }
531 
532     for (i = ly; i < uy; ++i)
533         tv_screen_raster(tv->tv_screen, lx, ux, i, tv_screen_rast + lx);
534 
535     cvector_free((void *) tv_screen_rast, lx);
536 }
537 */
538 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.