;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; 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")



#? *** libutils

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

;; #? * (dummy_libutils)
;; #? * (cvloadprimitives <proctype>)
;; #? * (cvfillinternalfuncstable <table>)
;; #? * (cvalloc <size>)
;; #? * (cvfree <ptr>)
;; #? * (cvgetlibraryinfo <version> <loaded> <loadedmodules>)
;; #? * (cvgeterrstatus)
;; #? * (cvseterrstatus <status>)
;; #? * (cvgeterrmode)
;; #? * (cvseterrmode <mode>)
;; #? * (cverror <code> <func> <context> <file> <line>)
;; #? * (cverrorstr <status>)
;; #? * (cvredirecterror_aux)
;; #? * (cvredirecterror <cverrorfunc>)
;; #? * (cvsetprofile <startprofilef> <endprofilef>)
;; #? * (cvsetiplallocators <createheader> <allocatedata> <deallocate> <createroi> <cloneimage>)

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


#? (cvLoadPrimitives <proctype>)
;;.VP
;;  /*F//////////////////////////////////////////////////////////////////////////////////////
;;  //    Name: cvLoadPrimitives
;;  //    Purpose: The function loads primitives
;;  //    Context:
;;  //    Parameters:  dllName        - name of dll to be loaded(without prefix) or NULL
;;  //                                  for default dll
;;  //                 processor_type - needep processor type or NULL for automatic processor
;;  //                                  detection
;;  //    Return value: number of loaded functions
;;  //    Notes:   full dll name is consists from dllName + processor_type.dll(or
;;  //             dllName + processor_type + "d".dll for debug configuration)
;;  //F*/
;;  OPENCVAPI  int  cvLoadPrimitives( const char* proc_type CV_DEFAULT(0) );

(de cvLoadPrimitives(proctype)
    ((-gptr- "const char *") proctype)
    (let ((s 0))
      ((-int-) s)
      #{ cvLoadPrimitives($proctype); #}
      s))


;;  OPENCVAPI  int  cvFillInternalFuncsTable(void* table);
(de cvFillInternalFuncsTable(table)
    ((-gptr-) table)
    (let ((s 0))
      ((-int-) s)
      #{  $s = cvFillInternalFuncsTable($table); #}
      s))


#? (cvAlloc <size>)
;;.VP
;;  /*F//////////////////////////////////////////////////////////////////////////////////////
;;  //    Name: cvAlloc and cvFree
;;  //    Purpose: The functions allocate/deallocate plain memory buffers
;;  //F*/
;;  OPENCVAPI  void*  cvAlloc( int size );
(de cvAlloc(size)
    ((-int-) size)
    (let ((s (gptr ())))
      #{ $s = cvAlloc($size);  #}
      s))


;;  OPENCVAPI  void   cvFree( void** ptr );
(de cvFree(ptr)
    ((-gptr-) ptr)
    #{ cvFree(&$ptr); #}
    ())


#? (cvGetLibraryInfo <version> <loaded> <loadedmodules>)
;;.VP
;;  /*F//////////////////////////////////////////////////////////////////////////////////////
;;  //    Name: cvGetLibraryInfo
;;  //    Purpose: The function returns information about current version of library and
;;  //             loaded/non loaded primitives dll
;;  //    Context:
;;  //    Parameters:  version  - pointer to pointer to version of OpenCV - build date
;;  //                           (or NULL if not needed)
;;  //                 loaded   - pointer to flag of loaded primitives, nonzero value
;;  //                            after returning from function indicates that primitives
;;  //                            are loaded(NULL if not needed)
;;  //                 loaded_modules - comma-separated list of loaded optimized dlls
;;  //                           (NULL if not needed)
;;  //
;;  //    Notes:   
;;  //F*/
;;  OPENCVAPI  void  cvGetLibraryInfo( const char** version, int* loaded,
;;                                     const char** loaded_modules );

(de cvGetLibraryInfo(version loaded loadedmodules)
    ((-gptr- "const char *") version loadedmodules)
    ((-gptr- "int *") loaded)
    #{ cvGetLibraryInfo(&$version, $loaded, &$loadedmodules); #}
    ())

;;  /* **************************** Error handling ************************* */

#? (cvGetErrStatus  )
;;  /*F/////////////////////////////////////////////////////////////////////////
;;.VP
;;  // Name:       cvGetErrStatus
;;  // Purpose:    Gets last error status
;;  // Returns:
;;  // Parameters:
;;  //
;;  // Notes:
;;  */
;;  OPENCVAPI CVStatus cvGetErrStatus( void );

(de cvGetErrStatus ()
    (let ((s 0))
      ((-int-) s)
      #{ $s = cvGetErrStatus(); #}
      s))

#? (cvSetErrStatus  <status>)
;;.VP
;;  /*F/////////////////////////////////////////////////////////////////////////
;;  // Name:       cvSetErrStatus
;;  // Purpose:    Sets error status
;;  // Returns:
;;  // Parameters:
;;  //
;;  // Notes:
;;  */
;;  OPENCVAPI void cvSetErrStatus( CVStatus status );

(de cvSetErrStatus (status)
    ((-int-) status)
    #{  cvSetErrStatus($status); #}
    ())

#? (cvGetErrMode )
;;.VP
;;  /*F/////////////////////////////////////////////////////////////////////////
;;  // Name:       cvGetErrMode, cvSetErrMode
;;  // Purpose:    gets/sets error mode
;;  // Returns:
;;  // Parameters:
;;  //
;;  // Notes:
;;  */
;;  OPENCVAPI int  cvGetErrMode( void );

(de cvGetErrMode()
    (let ((s 0))
      ((-int-) s)
      #{ $s = cvGetErrMode(); #}
      s))

;;  OPENCVAPI void cvSetErrMode( int mode );

(de cvSetErrMode(mode)
    ((-int-) mode)
    #{ cvSetErrMode($mode); #}
    ())

#? (cvError  <code> <func> <context> <file> <line>)
;;.VP
;;  /*F/////////////////////////////////////////////////////////////////////////
;;  // Name:       cvError
;;  // Purpose:    performs basic error handling
;;  // Returns:    last status
;;  // Parameters:
;;  //
;;  // Notes:
;;  */
;;  OPENCVAPI CVStatus cvError( CVStatus code, const char *func,
;;                           const char *context, const char *file, int line);

(de cvError( code func context file line)
    ((-int-) code line)
    ((-gptr- "const char *") func context file)
    (let ((s 0))
      ((-int-) s)
      #{ $s = cvError($code,$func,$context,$file,$line); #}
      s))

#? (cvErrorStr <status>)
;;.VP
;;  /*F/////////////////////////////////////////////////////////////////////////
;;  // Name:       cvErrorStr
;;  // Purpose:    translates an error status code into a textual description
;;  // Returns:
;;  // Parameters:
;;  //
;;  // Notes:
;;  */
;;  OPENCVAPI const char* cvErrorStr( CVStatus status );

(de cvErrorStr (status)
    ((-int-) status)
    (let ((s (gptr ())))
      #{ $s = (void *)cvErrorStr($status); #}
      s))



(de cvRedirectError_aux ()
    (cheader "typedef int int_func();")
    ())

#? (cvRedirectError <cverrorfunc>)
;;.VP
;;  /*F/////////////////////////////////////////////////////////////////////////
;;  // Name:       cvRedirectError
;;  // Purpose:    assigns a new error-handling function
;;  // Returns:    old error-handling function
;;  // Parameters: new error-handling function
;;  //
;;  // Notes:
;;  */
;;  OPENCVAPI CVErrorCallBack cvRedirectError(CVErrorCallBack cvErrorFunc);

(de cvRedirectError (cverrorfunc)
    ((-gptr- "int_func *") cverrorfunc)
    (let ((s (gptr ())))
      #{ $s = (int_func *) cvRedirectError($cverrorfunc); #}
      s))

#? * (cvnulldevreport <status> <funcname> <context> <file> <line>)
;;.PRE
;;  /*-----------------  Predefined error-handling functions  -----------------*/
;;  /*
;;      Output to:
;;          cvNulDevReport - nothing
;;          cvStdErrReport - console(printf)
;;          cvGuiBoxReport - MessageBox(WIN32)
;;  */
;;  OPENCVAPI CVStatus cvNulDevReport( CVStatus status, const char *funcName,
;;                                  const char *context, const char *file, int line );

(de cvNullDevReport(status funcname context file line)
    ((-int-) status line)
    ((-gptr- "const char *") funcname context file)
    (let ((s 0))
      ((-int-) s)
      #{  $s = cvNullDevReport($status, $funcname, $context, $file, $line); #}
      s))
    

#? * (cvstderrreport <status> <funcname> <context> <file> <line>)
;;.PRE
;;  OPENCVAPI CVStatus cvStdErrReport( CVStatus status, const char *funcName,
;;                                  const char *context, const char *file, int line );

(de cvStdErrReport(status funcname context file line)
    ((-int-) status line)
    ((-gptr- "const char *") funcname context file)
    (let ((s 0))
      ((-int-) s)
      #{  $s = cvStdErrReport($status, $funcname, $context, $file, $line); #}
      s))
    

#? * (cvguiboxreport <status> <funcname> <context> <file> <line>)
;;.PRE
;;  OPENCVAPI CVStatus cvGuiBoxReport( CVStatus status, const char *funcName,
;;                                  const char *context, const char *file, int line);

(de cvGuiBoxReport(status funcname context file line)
    ((-int-) status line)
    ((-gptr- "const char *") funcname context file)
    (let ((s 0))
      ((-int-) s)
      #{  $s = cvGuiBoxReport($status, $funcname, $context, $file, $line); #}
      s))

#? * (cvstartprofile <call> <file> <line>)
;;.PRE
;;  OPENCVAPI void cvStartProfile( const char* call, const char* file, int line );

(de cvStartProfile(call file line)
    ((-gptr- "const char *") call file)
    ((-int-) line)
    #{ cvStartProfile($call, $file, $line); #}
    ())

#? * (cvendprofile <file> <line>)
;;.PRE
;;  OPENCVAPI void cvEndProfile( const char* file, int line );

(de cvEndProfile(file line)
    ((-gptr- "const char *") file)
    ((-int-) line)
    #{ cvEndProfile($file,$line); #}
    ())

;;  /* management functions */
;;  OPENCVAPI void cvSetProfile( void (CV_CDECL *startprofile_f)(const char*, const char*, int),
;;                            void (CV_CDECL *endprofile_f)(const char*, int) ); 

(de cvSetProfile_aux()
    (cheader "typedef void void_func1(const char *, const char *, int);")
    (cheader "typedef void void_func2(const char *, int);")
    ())

#? * (cvsetprofile_aux)
;;.PRE
(de cvSetProfile(startprofilef endprofilef)
    ((-gptr- "void_func1 *") startprofilef)
    ((-gptr- "void_func2 *") endprofilef)
    #{ cvSetProfile($startprofilef, $endprofilef); #}
    ())

;;   

#? * (cvremoveprofile)
;;.PRE
;;  OPENCVAPI void cvRemoveProfile();                  

(de cvRemoveProfile()
    #{ cvRemoveProfile(); #}
    ())



#? * (cvsetmemorymanager_aux)
(de cvSetMemoryManager_aux ()
    (cheader "typedef void * voidstar_alloc_func(int, const char *, int);")
    (cheader "typedef int int_free_func(void **, const char*, int);")
    ())

#? * (cvsetmemorymanager <allocfunc> <freefunc>)
;;.PRE
;;  OPENCVAPI void cvSetMemoryManager( void* (CV_STDCALL *allocFunc)(int, const char*, int) CV_DEFAULT(0),
;;                             int (CV_STDCALL *freeFunc)(void**, const char*, int) CV_DEFAULT(0));
(de cvSetMemoryManager( allocfunc freefunc)
    ((-gptr- "voidstar_alloc_func *") allocfunc )
    ((-gptr- "int_free_func *") freefunc)
    #{ cvSetMemoryManager($allocfunc, $freefunc); #}
    ())


#? * (cvgetcallstack <stack> <size>)
;;.PRE
;;  OPENCVAPI void cvGetCallStack(CvStackRecord** stack, int* size);

(de cvGetCallStack(stack size)
    ((-gptr- "CvStackRecord *") stack)
    ((-gptr- "int *") size)
    #{ cvGetCallStack(&$stack, $size); #}
    ())



#? (cvSetIPLAllocators <createheader> <allocatedata> <deallocate> <createroi> <cloneimage>)
;;.VP
;;  /*F//////////////////////////////////////////////////////////////////////////////////
;;  // Name:    cvSetIPLAllocators
;;  // Purpose:  Makes OpenCV to use IPL functions for image allocation/deallocation
;;  // Returns:
;;  // Parameters:
;;  //
;;  // Notes:
;;  */
;;  OPENCVAPI void
;;  cvSetIPLAllocators( Cv_iplCreateImageHeader createHeader,
;;                      Cv_iplAllocateImageData allocateData,
;;                      Cv_iplDeallocate deallocate,
;;                      Cv_iplCreateROI createROI,
;;                      Cv_iplCloneImage cloneImage );

(de cvSetIPLAllocators(createheader allocatedata deallocate createroi cloneimage)
    ((-gptr-) createheader)
    ((-gptr-) allocatedata)
    ((-gptr-) deallocate)
    ((-gptr-) createroi)
    ((-gptr-) cloneimage)
    #{ cvSetIPLAllocators($createheader, $allocatedata, $deallocate, $createroi, $cloneimage); #}
    ())

;;  #define CV_TURN_ON_IPL_COMPATIBILITY()                                  \
;;      cvSetIPLAllocators( iplCreateImageHeader, iplAllocateImageData,     \
;;                          iplDeallocate, iplCreateROI, iplCloneImage )
()

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

(dhc-make ()
  dummy_libutils
  cvloadprimitives
  cvfillinternalfuncstable
  cvalloc
  cvfree
  cvgetlibraryinfo
  cvgeterrstatus
  cvseterrstatus
  cvgeterrmode
  cvseterrmode
  cverror
  cverrorstr
  cvredirecterror_aux
  cvredirecterror
;;  cvnulldevreport
  cvstderrreport
  cvguiboxreport
  cvstartprofile
  cvendprofile
  cvsetprofile_aux
  cvsetprofile
  cvremoveprofile
  cvsetmemorymanager_aux
  cvsetmemorymanager
  cvgetcallstack
  cvsetiplallocators
)
