home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / updates / update14.zoo / gemlib / vdibez.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-15  |  8.2 KB  |  317 lines

  1. /*
  2.  *  vdibez.c
  3.  *
  4.  *  Bindings for Bezier curves. 
  5.  *
  6.  *    ++jrb   bammi@cadence.com
  7.  *    and Michal Jaegermann, ntomczak@vm.ucs.ulberta.ca
  8.  *
  9.  *  Some function have alias names in order to maintain a common
  10.  *  set of symbols with compilers which need symbols unique in the
  11.  *  first seven characters.  Besides this resolution is required
  12.  *  by "The Standard" :-)
  13.  */
  14. #include "common.h"
  15. #ifndef _COMPILER_H
  16. # include <compiler.h>
  17. #endif
  18. #include <types.h>
  19.  
  20. #define ALTERNATE    0
  21.  
  22. __EXTERN void vdi __PROTO((void));
  23.  
  24. #ifdef __DEF_ALL__
  25.  
  26. #define L_v_set_ap
  27. #ifdef ALTERNATE
  28. #define L_v_bez_co
  29. #else
  30. #define L_v_bez_on
  31. #define L_v_bez_of
  32. #endif /* ALTERNATE */
  33. #define L_v_bez
  34. #define L_v_bez_fi
  35. #define L_v_bez_qu
  36.  
  37. #endif /* __DEF_ALL__ */
  38.  
  39.  
  40. #ifdef L_v_set_ap
  41.  
  42. /*
  43.  * Inform GDOS about  location and size of a buffer which  GDOS
  44.  * can use for creation of Bezier curves.
  45.  *    buf_p  is a pointer to an address of a buffer
  46.  *    size   its a buffer size in 2-byte words (!!)
  47.  *           or 16-bytes paragraphs - depends in which document
  48.  *           you believe.
  49.  * If buf_p is NULL, then space for a buffer will be allocated
  50.  * by GDOS - using Malloc (who knows where to look for this space?)
  51.  *
  52.  * "Hand coding" required - function opcode does not fit into 0-255 range
  53.  */
  54. void
  55. v_set_app_buff (void *buf_p, int size)
  56. {
  57.     short *wptr = _intin;
  58.     
  59.     *wptr++ = (short) buf_p;           /* low word of an address */
  60.     *wptr++ = (short)((long)buf_p >> 16);  /* high word of an address */
  61.     *wptr =   (short) size;               /* size of buffer in something */
  62.  
  63.      wptr = (short *)_contrl;
  64.     *wptr++ = -1;    /* 0  - opcode */
  65.     *wptr++ = 0;    /* 1 */
  66.      wptr++;        /* 2 */
  67.     *wptr++ = 3;    /* 3  - # of entries in _intin */
  68.      wptr++;        /* 4 */
  69.     *wptr++ = 6;    /* 5 - id */
  70.     *wptr   = 0;    /* 6 - dummy handle - really needed? */
  71.     vdi();        /* call vdi */
  72. }
  73. #endif /* L_v_set_ap */
  74.  
  75. #ifdef ALTERNATE
  76. #ifdef L_v_bez_co
  77.  
  78. /*
  79.  * If onoff is 1 then enable Bezier capabilities and
  80.  * find a number of segments per Bezier curve.
  81.  * Returns logarithm in a base of 2 from that number
  82.  *
  83.  * If onoff is 0 then disable Bezier capabilities and
  84.  * release memory allocated in v_set_app_buff call.
  85.  * Returns NOTHING!
  86.  */
  87.  
  88. int 
  89. v_bez_con(int handle, int onoff)
  90. {
  91.     __vdi__(VDI_CONTRL_ENCODE(11, (unsigned short)(onoff), 0, 13), handle);
  92.     return(_intout[0]);
  93. }
  94. #endif /* L_v_bez_co */
  95. #else
  96.  
  97. #ifdef L_v_bez_on
  98.  
  99. /*
  100.  * v_bez_on (alias v_bezon)
  101.  * Enable Bezier capabilities.
  102.  * Find a number of segments per Bezier curve.
  103.  * Returns logarithm in a base of 2 from that number
  104.  */
  105.  
  106. __asm__(".stabs \"_v_bezon\",5,0,0,_v_bez_on"); /* dept of clean tricks */
  107. int
  108. v_bez_on (int handle)
  109. {
  110.     __vdi__(VDI_CONTRL_ENCODE(11, 1, 0, 13), handle);
  111.     return *_intout;
  112. }
  113. #endif /* L_v_bez_on */
  114.  
  115. #ifdef L_v_bez_of
  116.  
  117. /*
  118.  * v_bez_off (alias v_bezoff)
  119.  * Disable Bezier capabilities.
  120.  * Free space allocated by GDOS for Bezier curves.
  121.  */
  122. __asm__(".stabs \"_v_bezoff\",5,0,0,_v_bez_off"); /* dept of clean tricks */
  123. void
  124. v_bez_off (int handle)
  125. {
  126.     __vdi__(VDI_CONTRL_ENCODE(11, 0, 0, 13), handle);
  127. }
  128. #endif /* L_v_bez_of */
  129. #endif /* ALTERNATE */
  130.  
  131.  
  132. #ifdef L_v_bez
  133. /*
  134.  * Draw an unfilled Bezier curve
  135.  *    xyarr   - an array of 'count' pairs of control vertices
  136.  *    bezarr  - an array of flags specifying which control points
  137.  *        are jump points
  138.  *              bit 0  off - start of a polyline if not continuation
  139.  *              bit 0  on  - start of a Bezier segment
  140.  *              bit 1  on  - jump point (move to the next one without draw)
  141.  *
  142.  * Returns - a number of points in a Bezier curve
  143.  */
  144.  
  145. int
  146. v_bez(     int     handle,   /* Device handle we're drawing to */
  147.            int   count,       /* Number of points total... */
  148.        int  *xyarr,       /* The points in x1,y1,x2,y2 format */
  149.        char    *bezarr,   /* Flag array, so that we can set start, jump pts */
  150.        int    *extent,   /* "bounding box coordinates */
  151.        int    *totpts,   /* number of resulting polygon points */
  152.        int    *totmoves) /* number of resulting moves  */
  153. {
  154.     short *end;
  155.     char *pbd = bezarr;
  156.     char *opbd = (char *)_intin;
  157. #ifndef __MSHORT__
  158.     short *optr;
  159.     int *iptr = xyarr;
  160. #endif
  161.  
  162.     int cntrl0 = 6;
  163.  
  164.     /* copy entries from bezarr to _intin packing and swaping bytes ???! */
  165.     /* this requirement for byte swapping  is not documented - if you    */
  166.     /* discount some old code example, but things seem to work this way  */
  167.     end  = (short *) (pbd + count);
  168.     while (pbd < (char *)end) {
  169.     *(opbd + 1) = *pbd++;
  170.     if (pbd >= (char *)end)
  171.         break;
  172.     *opbd = *pbd++;
  173.     opbd += 2;
  174.     }
  175. #ifdef __MSHORT__
  176.     _vdiparams[2] = (void *) xyarr;
  177.     _vdiparams[4] = (void *) extent;
  178. #else
  179.     /* copy xyarr into an array of shorts */
  180.  
  181.     optr = _ptsin;
  182.     end  = optr + count + count;
  183.     while (optr < end)
  184.         *optr++ = *xyarr++;
  185. #endif
  186.     __vdi__(VDI_CONTRL_ENCODE(cntrl0, count, ((count + 1) >> 1), 13), handle);
  187. #ifdef __MSHORT__
  188.     /* restore standard parameter block */ 
  189.     _vdiparams[2] = (void *) _ptsin;
  190.     _vdiparams[4] = (void *) _ptsout;
  191. #else
  192.     optr = _ptsout;
  193.     iptr = extent;
  194.     *iptr++ = *optr++;
  195.     *iptr++ = *optr++;
  196.     *iptr++ = *optr++;
  197.     *iptr   = *optr;
  198. #endif
  199.     *totmoves = _intout[1];
  200.     return(*totpts = _intout[0]);     /* number of points in Bezier */
  201. }
  202.  
  203. #endif /* L_v_bez */
  204.  
  205.  
  206. #ifdef L_v_bez_fi
  207.  
  208. /*
  209.  * v_bez_fill (alias _v_bezfill)
  210.  * Draw a filled Bezier curve
  211.  *    xyarr   - an array of 'count' pairs of control vertices
  212.  *    bezarr  - an array of flags specifying which control points
  213.  *        are jump points
  214.  *              bit 0  off - start of a polyline if not continuation
  215.  *              bit 0  on  - start of a Bezier segment
  216.  *              bit 1  on  - jump point (move to the next one without draw)
  217.  * Returns - a number of points in a filled Bezier curve
  218.  */
  219.  
  220. __asm__(".stabs \"_v_bezfill\",5,0,0,_v_bez_fill"); /* dept of clean tricks */
  221. int
  222. v_bez_fill(int handle,       /* Device handle we're drawing to */
  223.            int   count,       /* Number of points total... */
  224.        int  *xyarr,       /* The points in x1,y1,x2,y2 format */
  225.        char    *bezarr,   /* Flag array, so that we can set start, jump pts */
  226.        int    *extent,   /* "bounding box coordinates */
  227.        int    *totpts,   /* number of resulting polygon points */
  228.        int    *totmoves) /* number of resulting moves  */
  229. {
  230.     short *end;
  231.     char *pbd = bezarr;
  232.     char *opbd = (char *)_intin;
  233. #ifndef __MSHORT__
  234.     short *optr;
  235.     int *iptr = xyarr;
  236. #endif
  237.  
  238.     int cntrl0 = 9;
  239.  
  240.     /* copy entries from bezarr to _intin packing and swaping bytes ???! */
  241.     /* this requirement for byte swapping  is not documented - if you    */
  242.     /* discount some old code example, but things seem to work this way  */
  243.     end  = (short *) (pbd + count);
  244.     while (pbd < (char *)end) {
  245.     *(opbd + 1) = *pbd++;
  246.     if (pbd >= (char *)end)
  247.         break;
  248.     *opbd = *pbd++;
  249.     opbd += 2;
  250.     }
  251. #ifdef __MSHORT__
  252.     _vdiparams[2] = (void *) xyarr;
  253.     _vdiparams[4] = (void *) extent;
  254. #else
  255.     /* copy xyarr into an array of shorts */
  256.  
  257.     optr = _ptsin;
  258.     end  = optr + count + count;
  259.     while (optr < end)
  260.         *optr++ = *xyarr++;
  261. #endif
  262.     __vdi__(VDI_CONTRL_ENCODE(cntrl0, count, ((count + 1) >> 1), 13), handle);
  263. #ifdef __MSHORT__
  264.     /* restore standard parameter block */ 
  265.     _vdiparams[2] = (void *) _ptsin;
  266.     _vdiparams[4] = (void *) _ptsout;
  267. #else
  268.     optr = _ptsout;
  269.     iptr = extent;
  270.     *iptr++ = *optr++;
  271.     *iptr++ = *optr++;
  272.     *iptr++ = *optr++;
  273.     *iptr   = *optr;
  274. #endif
  275.     *totmoves = _intout[1];
  276.     return(*totpts = _intout[0]);     /* number of points in Bezier */
  277. }
  278. #endif /* L_v_bez_fi */
  279.  
  280. #ifdef L_v_bez_qu
  281.  
  282. /*
  283.  * v_bez_qual (alias v_bezqual)
  284.  * Set the quality / speed tradeoff when drawing Beizier curve
  285.  * quality is given in percents
  286.  * 
  287.  * Returns an actual quality set.
  288.  *
  289.  * This function requires "hand coding" since subcode 99 does
  290.  * not fit into 5 bits required by VDI_CONTRL_ENCODE
  291.  */
  292. __asm__(".stabs \"_v_bezqual\",5,0,0,_v_bez_qual"); /* dept of clean tricks */
  293. int
  294. v_bez_qual (int handle, int percent, int *actual)
  295. {
  296.     short *wptr = _intin;
  297.  
  298.     *wptr++ = 32;
  299.     *wptr++ = 1;
  300.     *wptr  = percent;
  301.  
  302.      wptr = (short *)_contrl;
  303.     *wptr++ = 5;    /* 0  - opcode */
  304.     *wptr++ = 0;    /* 1 */
  305.      wptr++;        /* 2 */
  306.     *wptr++ = 3;    /* 3  - # of entries in _intin */
  307.      wptr++;        /* 4 */
  308.     *wptr++ = 99;    /* 5 - id */
  309.     *wptr   = handle;    /* 6 - handle */
  310.     vdi();        /* call vdi */
  311.  
  312.     return (*actual = *_intout);
  313. }
  314. #endif /* L_v_bez_qu */
  315.  
  316. /* -eof- */
  317.