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