;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; LUSH Lisp Universal Shell
;;;   Copyright (C) 2002 Leon Bottou, Yann Le Cun, AT&T Corp, NECI.
;;; Includes parts of TL3:
;;;   Copyright (C) 1987-1999 Leon Bottou and Neuristique.
;;; Includes selected parts of SN3.2:
;;;   Copyright (C) 1991-2001 AT&T Corp.
;;;
;;; Includes information derived from the GSL (Gnu Scientific Library)
;;;   header files which are copyrighted and distributed under the GPL
;;;   by their respective authors.
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(libload "opencv/cv-config")



#? *** drawing

;; dummy function that adds OpenCV C header files in C file
(eval `(de dummy_drawing () ,cv-cpheader-cmd ()))

;; #? * (dummy_drawing)
;; #? * (cvline <array> <pt1> <pt2> <color> <thickness> <connectivity>)
;; #? * (cvlineaa <array> <pt1> <pt2> <color> <scale>)
;; #? * (cvrectangle <array> <pt1> <pt2> <color> <thickness>)
;; #? * (cvcircle <array> <center> <radius> <color> <thickness>)
;; #? * (cvcircleaa <array> <center> <radius> <color> <scale>)
;; #? * (cvellipse <array> <center> <axes> <angle> <sangle> <eangle> <color> <thickness>)
;; #? * (cvellipseaa <array> <center> <axes> <angle> <sangle> <eangle> <color> <scale>)
;; #? * (cvfillconvexpoly <array> <pts> <npts> <color>)
;; #? * (cvfillpoly <array> <pts> <npts> <contours> <color>)
;; #? * (cvpolyline <array> <pts> <npts> <contours> <closed> <color> <thickness> <connectivity>)
;; #? * (cvpolylineaa <array> <pts> <npts> <contours> <closed> <color> <scale>)
;; #? * (cvinitfont <font> <font_face> <hscale> <vscale> <italic_scale> <thickness>)
;; #? * (cvputtext <array> <text> <org> <font> <color>)
;; #? * (cvgettextsize <textstring> <font> <textsize> <ymin>)

;; ********************************************************

;;  /****************************************************************************************\
;;  *       Drawing functions work with the following formats:                               *
;;  *           single channel: IPL_DEPTH_8U, IPL_DEPTH_8S                                   *
;;  *           three channels: IPL_DEPTH_8U, IPL_DEPTH_8S, coi must be == 0                 *
;;  *       All the functions include parameter color that means rgb value for three-channel *
;;  *       images(and may be constructed with CV_RGB macro) and brightness                 *
;;  *      (least-significant byte of color) for grayscale images.                          *
;;  *       If drawn figure is partially or completely outside the image, it is clipped.     *
;; \****************************************************************************************/
  
#? (cvLine  <array> <pt1> <pt2> <color> <thickness> <line-type> <shift>)
;;.VP
;;  /*F///////////////////////////////////////////////////////////////////////////////////////
;;  //
;;  //    Name:    cvLine
;;  //    Purpose:
;;  //      Draws line on the image ROI between two points
;;  //    Context:
;;  //    Parameters:
;;  //        img  - image where the line is drawn.
;;  //        pt1  - starting point
;;  //        pt2  - ending point
;;  //        color - line color(or brightness)
;;  //        thickness - line thickness. 1 means simple line.
;;  //                    if line is thick, function draws the line with round endings.
;;  //        line_type - Type of the line:
;;  //                    8 (or 0) - 8-connected line.
;;  //                    4 - 4-connected line.
;;  //                    CV_AA - antialiased line.
;;  //        shift - Number of fractional bits in the point coordinates.
;;  //    Returns:
;;  //F*/
;;  OPENCVAPI  void  cvLine( CvArr* array, CvPoint pt1, CvPoint pt2,
;;                           CvScalar color, int thickness CV_DEFAULT(1),
;;                           int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0));
(de cvLine( array pt1 pt2 color thickness line-type shift)
    ((-gptr- "CvArr *") array)
    ((-gptr- "CvPoint *") pt1 pt2)
    ((-gptr- "CvScalar *") color)
    ((-int-) thickness)
    ((-int-) line-type shift)
    #{  cvLine($array, *$pt1, *$pt2, *$color, $thickness, $line_type, $shift);  #}
    ()))


#? (cvRectangle  <array> <pt1> <pt2> <color> <thickness> <line-type> <shift>)
;;.VP
;;  /*F///////////////////////////////////////////////////////////////////////////////////////
;;  //
;;  //    Name:    cvRectangle
;;  //    Purpose:
;;  //      Draws rectangle on the image ROI
;;  //    Context:
;;  //    Parameters:
;;  //        img  - image where the rectangle is drawn.
;;  //        pt1  - one of the rectangle corners
;;  //        pt2  - opposite corner of the rectangle
;;  //        thickness - thickness of the lines that made up rectangle.
;;  //        color - line color(or brightness)
;;  //        line_type - Type of the line, see cvLine description
;;  //        shift - Number of fractional bits in the point coordinates.
;;  //    Returns:
;;  //F*/
;;  OPENCVAPI  void  cvRectangle( CvArr* array, CvPoint pt1, CvPoint pt2,
;;                                CvScalar color, int thickness CV_DEFAULT(1));

(de cvRectangle( array pt1 pt2 color thickness line-type shift)
    ((-gptr- "CvArr *") array)
    ((-gptr- "CvPoint *") pt1 pt2)
    ((-gptr- "CvScalar *") color)
    ((-int-) thickness line-type shift)
    #{  cvRectangle($array, *$pt1, *$pt2, *$color, $thickness, $line_type, $shift);  #}
    ()))


#? (cvCircle  <array> <center> <radius> <color> <thickness> <line-type> <shift>)
;;.VP
;;  /*F///////////////////////////////////////////////////////////////////////////////////////
;;  //
;;  //    Name:    cvCircle
;;  //    Purpose:
;;  //      Draws circle on the image ROI
;;  //    Context:
;;  //    Parameters:
;;  //        img  - image.
;;  //        center - circle center
;;  //        radius - circle radius(must be >= 0)
;;  //        color - circle color
;;  //        thickenss - thickness of drawn circle. <0 means filled circle.
;;  //        line_type - Type of the circle boundary, see cvLine description.
;;  //        shift - Number of fractional bits in the center coordinates and radius value
;;  //    Returns:
;;  //F*/
;;  OPENCVAPI  void  cvCircle( CvArr* array, CvPoint center, int radius,
;;                             CvScalar color, int thickness CV_DEFAULT(1));

(de cvCircle( array center radius color thickness line-type shift)
    ((-gptr- "CvArr *") array)
    ((-gptr- "CvPoint *") center)
    ((-int-) radius)
    ((-gptr- "CvScalar *") color)
    ((-int-) thickness line-type shift)
    #{  cvCircle($array, *$center, $radius, *$color, $thickness, $line_type, $shift);  #}
    ())

#? (cvEllipse  <array> <center> <axes> <angle> <sangle> <eangle> <color> <thickness> <line-type> <shift>)
;;.VP
;;  /*F///////////////////////////////////////////////////////////////////////////////////////
;;  //
;;  //    Name:    cvEllipse
;;  //    Purpose:
;;  //      Draws elliptic arc
;;  //    Context:
;;  //    Parameters:
;;  //        img  - image.
;;  //        center - ellipse center
;;  //        axes - half axes of the ellipse
;;  //        angle - ellipse angle
;;  //        startAngle - starting angle of elliptic arc
;;  //        endAngle - ending angle of elliptic arc
;;  //        thickness - arc thickness
;;  //        color - ellipse color(or brightness)
;;  //        line_type - Type of the ellipse boundary, see cvLine description.
;;  //        shift - Number of fractional bits in the center coordinates and radius value.
;;  //    Returns:
;;  //F*/
;;  OPENCVAPI  void  cvEllipse( CvArr* array, CvPoint center, CvSize axes,
;;                              double angle, double startAngle, double endAngle,
;;                              CvScalar color, int thickness CV_DEFAULT(1)
;;                              int line_type CV_DEFAULT(8), int shift CV_DEFAULT(0));

(de cvEllipse( array center axes angle sangle eangle color thickness line-type shift)
    ((-gptr- "CvArr *") array)
    ((-gptr- "CvPoint *") center)
    ((-gptr- "CvSize *") axes)
    ((-double-) angle sangle eangle)
    ((-gptr- "CvScalar *") color)
    ((-int-) thickness line-type shift)
    #{  cvEllipse($array, *$center, *$axes, $angle, $sangle, $eangle, *$color, $thickness, $line_type, $shift);  #}
    ())

#? (cvFillConvexPoly  <array> <pts> <npts> <color> <line-type> <shift>)
;;.VP
;;  /*F///////////////////////////////////////////////////////////////////////////////////////
;;  //
;;  //    Name:    cvFillConvexPoly
;;  //    Purpose:
;;  //      Fills convex polygon
;;  //    Context:
;;  //    Parameters:
;;  //        img  - image.
;;  //        pts  - array of polygon vertices
;;  //        ntps - number of vertices in the polygon
;;  //        color - polygon color(or brightness)
;;  //    Returns:
;;  //    Notes:
;;  //        fucntion automatically closes the contour -
;;  //        adds edge between first and last vertices.
;;  //        function doesn't check that input polygon is convex.
;;  //F*/
;;  CVAPI  void  cvFillConvexPoly( CvArr* array, CvPoint* pts, int npts, CvScalar color, int line_type, int shift);

(de cvFillConvexPoly (array pts npts color line-type shift)
    ((-gptr- "CvArr *") array)
    ((-gptr- "CvPoint *") pts)
    ((-int-) npts line-type shift)
    ((-gptr- "CvScalar *") color)
    #{ cvFillConvexPoly($array, $pts, $npts, *$color, $line_type, $shift); #}
    ())

#? (cvFillPoly  <array> <pts> <npts> <contours> <color> <line-type> <shift>)
;;.VP
;;  /*F///////////////////////////////////////////////////////////////////////////////////////
;;  //
;;  //    Name:    cvFillPoly
;;  //    Purpose:
;;  //      Fills arbitrary regions, bounded by several polygonal contours.
;;  //    Context:
;;  //    Parameters:
;;  //        img  - image.
;;  //        contours - number of contours
;;  //        pts  - array of pointers to polygonal contours
;;  //        ntps - array of vertices counters for the contours
;;  //        color - polygons color(or brightness)
;;  //    Returns:
;;  //    Notes:
;;  //        function automatically closes each polygonal contour.
;;  //        If some contours are overlapped, they are added modulo 2.
;;  //        That is, pixel is filled, if it belongs to odd number of polygonal contours.
;;  //F*/
;;  OPENCVAPI  void  cvFillPoly( CvArr* array, CvPoint** pts,
;;                               int* npts, int contours, CvScalar color );

(de cvFillPoly (array pts npts contours color line-type shift)
    ((-gptr- "CvArr *") array)
    ((-gptr- "CvPoint **") pts)
    ((-gptr- "int *") npts)
    ((-int-) contours line-type shift)
    ((-gptr- "CvScalar *") color)
    #{ cvFillPoly($array, $pts, $npts, $contours, *$color, $line_type, $shift); #}
    ())

#? (cvPolyLine  <array> <pts> <npts> <contours> <closed> <color> <thickness> <line-type> <shift>)
;;.VP
;;  /*F///////////////////////////////////////////////////////////////////////////////////////
;;  //
;;  //    Name:    cvPolyLine
;;  //    Purpose:
;;  //      Draws polygons outline with simple or thick lines.
;;  //    Context:
;;  //    Parameters:
;;  //        img  - image.
;;  //        contours - number of contours
;;  //        pts  - array of pointers to polygonal contours
;;  //        ntps - array of vertices counters for the contours
;;  //        closed - if non-zero, function closes each contour.
;;  //        thickness - line thickness
;;  //        color - polygons color(or brightness)
;;  //    Returns:
;;  //F*/
;;  OPENCVAPI  void  cvPolyLine( CvArr* array, CvPoint** pts, int* npts, int contours,
;;                               int closed, CvScalar color,
;;                               int thickness CV_DEFAULT(1),
;;                               int connectivity CV_DEFAULT(8));

(de cvPolyLine (array pts npts contours closed color thickness line-type shift)
    ((-gptr- "CvArr *") array)
    ((-gptr- "CvPoint **") pts)
    ((-gptr- "int *") npts)
    ((-int-) contours closed thickness line-type shift)
    ((-gptr- "CvScalar *") color)
    #{ cvPolyLine($array, $pts, $npts, $contours, $closed, *$color, $thickness, $line_type, $shift); #}
    ())


#? (cvInitFont  <font> <font_face> <hscale> <vscale> <shear> <thickness> <line-type>)
;;.VP
;;  /*F///////////////////////////////////////////////////////////////////////////////////////
;;  //
;;  //    Name:    cvInitFont
;;  //    Purpose:
;;  //      Initializes font to use it in following text rendering operations
;;  //    Context:
;;  //    Parameters:
;;  //        font - pointer to initialized font structure.
;;  //        font_face - font family. There is a single font,
;;  //                    supported now - CV_FONT_VECTOR0.
;;  //        hscale - multiplier for horizontal letter sizes.
;;  //                 If 1 then the original size is used,
;;  //                 if 2 - twice wider, if 0.5 - twice thinner etc.
;;  //        vscale - multiplier for vertical letter sizes.
;;  //                 If 1 then the original size is used,
;;  //                 if 2 - twice longer, if 0.5 - twice shorter etc.
;;  //        shear - tangent of letter slope, 0 means no slope,
;;  //                       1 - 45 degree slope
;;  //        thickness - letter thickness
;;  //        line_type
;;  //    Returns:
;;  //F*/
;;  OPENCVAPI  void  cvInitFont( CvFont* font, CvFontFace font_face,
;;                               double hscale, double vscale,
;;                               double italic_scale CV_DEFAULT(0),
;;                               int thickness CV_DEFAULT(1) );
(de cvInitFont (font font_face hscale vscale shear thickness line-type)
    ((-gptr- "CvFont *") font)
    ((-int-) font_face)
    ((-double-) hscale vscale shear)
    ((-int-) thickness line-type)
    #{   cvInitFont($font, $font_face, $hscale, $vscale, $shear, $thickness, $line_type);  #}
    ())

#? (cvPutText <img> <text> <org> <font> <color>)
;;.VP
;;  /*F///////////////////////////////////////////////////////////////////////////////////////
;;  //
;;  //    Name:    cvPutText
;;  //    Purpose:
;;  //      Draws text string on the image with given font
;;  //    Context:
;;  //    Parameters:
;;  //        img  - image.
;;  //        text - text string
;;  //        org  - left-bottom corner of output text string
;;  //        font - text font
;;  //        color - polygons color(or brightness)
;;  //    Returns:
;;  //F*/
;;  OPENCVAPI  void  cvPutText( CvArr* array, const char* text, CvPoint org,
;;                              CvFont* font, CvScalar color );

(de cvPutText (img text org font color)
    ((-gptr- "CvArr *") img)
    ((-gptr- "const char *") text)
    ((-gptr- "CvPoint *") org)
    ((-gptr- "CvFont *") font)
    ((-gptr- "CvScalar *") color)
    #{  cvPutText($img, $text, *$org, $font, *$color);  #}
    ())

#? (cvGetTextSize  <textstring> <font> <textsize> <baseline>)
;;.VP
;;  /*F///////////////////////////////////////////////////////////////////////////////////////
;;  //
;;  //    Name:    cvGetTextSize
;;  //    Purpose:
;;  //      Calculates bounding rectangle for given text string and font.
;;  //    Context:
;;  //    Parameters:
;;  //        text - text string
;;  //        font - font to draw the string with
;;  //        text_size - output parameter. width and height of bounding box
;;  //                   (not including part of the text below base line)
;;  //        baseline
;;  //    Returns:
;;  //F*/
;;  OPENCVAPI  void  cvGetTextSize( const char* text_string, CvFont* font,
;;                                  CvSize* text_size, int* ymin );

(de cvGetTextSize (textstring font textsize baseline)
    ((-gptr- "const char *") textstring)
    ((-gptr- "CvFont *") font)
    ((-gptr- "CvSize *") textsize)
    ((-gptr- "int *") baseline)
    #{ cvGetTextSize($textstring, $font, $textsize, $baseline);  #}
    ())
;; ********************************************************

(dhc-make ()
  dummy_drawing
  cvline
  cvrectangle
  cvcircle
  cvellipse
  cvfillconvexpoly
  cvfillpoly
  cvpolyline
  cvinitfont
  cvputtext
  cvgettextsize
)
