
(libload "opencv/cv-config")
(libload "opencv/aux_macro_func")
(libload "opencv/data_structures")

(eval `(de |dummy_cvsmob| () ,cv-cpheader-cmd ()))

;;*********************************************************************
(defclass cvsmob object
  ((-gptr-) p))

(defmethod cvsmob cvsmob ()
  ())

(defmethod cvsmob -destructor ()
  #{ if($p)  free($p); #}
  ())

(defmethod cvsmob getp ()
  p)

;;********************************************************************
(defclass cvsize cvsmob)

(defmethod cvsize cvsize (width height)
  ((-int-) width height)
  #{ $p = malloc(sizeof(CvSize)) ;
     ((CvSize *)$p)->width = $width; 
     ((CvSize *)$p)->height = $height; 
  #}
  ())

;;*******************************************************************
(defclass cvpoint cvsmob)

(defmethod cvpoint cvpoint (x y)
  ((-int-) x y)
  #{  $p = malloc(sizeof(CvPoint));
      ((CvPoint *)$p)->x = $x;
      ((CvPoint *)$p)->y = $y;
  #}
  ())

(defmethod cvpoint copy ( pt )
  ((-gptr- "CvPoint *") pt)
  #{  memcpy($p,$pt, sizeof(CvPoint)); #}
  ())

(defmethod cvpoint get_x ()
  (int #{ ((CvPoint *)$p)->x #} ))

(defmethod cvpoint set_x ( x)
  ((-int-) x)
  #{ ((CvPoint *)$p)->x = $x;  #} 
  ())

(defmethod cvpoint get_y ()
  (int #{ ((CvPoint *)$p)->y #} ))

(defmethod cvpoint set_y ( y)
  ((-int-) y)
  #{ ((CvPoint *)$p)->y = $y; #} 
  ())

;;******************************************************************
(defclass cvpoint2d32f cvsmob)

(defmethod cvpoint2d32f cvpoint2d32f (x y)
  ((-float-) x y)
  #{ $p = malloc(sizeof(CvPoint2D32f));
     ((CvPoint2D32f *)$p)->x = $x;
     ((CvPoint2D32f *)$p)->y = $y; 
  #}
  ())

(defmethod cvpoint2d32f copy ( pt )
  ((-gptr- "CvPoint2D32f *") pt)
  #{ memcpy($p, $pt, sizeof(CvPoint2D32f)); #}
  ())

(defmethod cvpoint2d32f get_x ()
  (float #{ ((CvPoint2D32f *)$p)->x  #} ))

(defmethod cvpoint2d32f get_y ()
  (float #{ ((CvPoint2D32f *)$p)->y #} ))

;;*******************************************************************
(defclass cvrect cvsmob)

(defmethod cvrect cvrect (x y width height)
  ((-int-) x y width height)
  #{  $p = malloc(sizeof(CvRect)); 
      ((CvRect *)$p)->x = $x;
      ((CvRect *)$p)->y = $y;
      ((CvRect *)$p)->width = $width;
      ((CvRect *)$p)->height = $height;
  #}
  ())
  
(defmethod cvrect copy ( pt)
  ((-gptr- "CvRect *") pt)
  #{ memcpy($p,$pt, sizeof(CvRect)); #}
  ())

(defmethod cvrect get_x ()
  (int #{ ((CvRect *)$p)->x #} ))

(defmethod cvrect get_y ()
  (int #{ ((CvRect *)$p)->y #} ))

(defmethod cvrect get_width ()
  (int #{ ((CvRect *)$p)->width #} ))

(defmethod cvrect get_height ()
  (int #{ ((CvRect *)$p)->height #} ))

;;*******************************************************************
(defclass cvconnectedcomp cvsmob)

(defmethod cvconnectedcomp cvconnectedcomp ( )
  #{ $p = malloc(sizeof(CvConnectedComp)); #}
  ())

(defmethod cvconnectedcomp copy (pt)
  ((-gptr- "CvConnectedComp *") pt)
  #{ memcpy($p,$pt, sizeof(CvConnectedComp)); #}
  ())

(defmethod cvconnectedcomp get_area ()
  (double #{ ((CvConnectedComp *)$p)->area #} ))

(defmethod cvconnectedcomp get_value ()
  (double #{ ((CvConnectedComp *)$p)->value #} ))

(defmethod cvconnectedcomp get_rect ()
  (gptr #{ &(((CvConnectedComp *)$p)->rect) #} ))
  
;;******************************************************************
(defclass cvtermcriteria cvsmob)

(defmethod cvtermcriteria cvtermcriteria ( s m e)
  ((-int-) s m)
  ((-float-) e)
  #{ $p = malloc(sizeof(CvTermCriteria)); 
     ((CvTermCriteria *)$p)->type = $s;
     ((CvTermCriteria *)$p)->maxIter = $m;
     ((CvTermCriteria *)$p)->epsilon = $e;
  #}
  ())

;;********************************************************************
(defclass cvbigob object 
  ((-gptr-) p))

(defmethod cvbigob cvbigob ()
  ())

(defmethod cvbigob -destructor ()
  ())

;;********************************************************************
(defclass cvimage cvbigob
  ((-gptr-) pp))

(defmethod cvimage cvimage (width height depth channels)
  ((-int-) width height depth channels)
  #{ $p = cvCreateImage( cvSize($width,$height), $depth, $channels); 
     $pp = &$p; 
  #}
  ())

(defmethod cvimage -destructor ()
  (cvReleaseImage  pp) )

(defmethod cvimage get_width ()
  (int #{ ((IplImage *)$p)->width #} ))

(defmethod cvimage get_height ()
  (int #{ ((IplImage *)$p)->height #} ))

(defmethod cvimage get_depth ()
  (int #{ ((IplImage *)$p)->depth #} ))

(defmethod cvimage get_nchannels ()
  (int #{ ((IplImage *)$p)->nChannels #} ))

(defmethod cvimage draw_onepolyline ()
  ())

;;**********************************************************************
(defclass cvsmobarray  object
  ((-gptr-) p)
  ((-gptr-) pp)
  ((-int-) elemsize)
  ((-int-) elemnum) )

(defmethod cvsmobarray cvsmobarray ( size num)
  ((-int-) size num)
  #{ $p = malloc($size * $num); 
     $elemsize = $size;
     $elemnum  = $num; 
     $pp = &$p;
  #}
  ())

(defmethod cvsmobarray -destructor ()
  #{ free($p); #}
  ())

(defmethod cvsmobarray ptr_nth ( n)
  ((-int-) n)
  (gptr #{  ((char *)$p) + ($n * $elemsize) #} ))

(dhc-make-with-c++ () ()
   |dummy_cvsmob|
   (cvsmob cvsmob -destructor)
   (cvsize cvsize)
   (cvpoint cvpoint copy get_x get_y set_x set_y)
   (cvpoint2d32f cvpoint2d32f copy get_x get_y)
   (cvrect cvrect  copy  get_x get_y get_width get_height)
   (cvconnectedcomp cvconnectedcomp copy get_area get_value get_rect)
   (cvtermcriteria cvtermcriteria)
   (cvbigob cvbigob -destructor)
   (cvimage cvimage -destructor get_width get_height get_depth get_nchannels)
   (cvsmobarray cvsmobarray -destructor ptr_nth)
)
