
(libload "opencv/aux_const")
(libload "libimage/image-io")
(libload "opencv/aux_object")
(libload "opencv/aux_convert")
(libload "opencv/cv-config")

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

(de cvimage-read-rgb (filename)
  ((-str-) filename)
  (let* ((buf_idx (image-read-rgb filename))
	 (ret_img (new cvimage 
		       (idx-dim buf_idx 1) 
		       (idx-dim buf_idx 0) 
		       @IPL_DEPTH_8U 3)))
    (idx8u_ipl buf_idx  :ret_img:p)
    ret_img))

(de cvimage-show ( img )
  ((-obj- (cvimage)) img)
  (when ~window (new-window 
		 (==> img get_width) 
		 (==> img get_height)))
  (let ((buf_idx (ubyte-matrix 1 1 1)))
    (ipl8u_idx  :img:p  buf_idx)
    (if (= (idx-dim  buf_idx 2) 1)          ;; gray image?
	(rgb-draw-matrix 0 0 
			 (select buf_idx 2 0))  ;; draw gray image
      (rgb-draw-matrix 0 0 
		       buf_idx))                ;; draw rgb image
    ()))

(dhc-make () |dummy_cvimage| cvimage-read-rgb)
