(libload "video/libdc/libdc")

(setq webcam (new dc1394))
(setq camera (new dc1394_cameracapture))
(==> webcam setup_capture  0
		  @FORMAT_VGA_NONCOMPRESSED 
		  @MODE_640x480_MONO
		  @SPEED_400
		  @FRAMERATE_7_5
		  :camera:p)
(==> webcam set_trigger_mode  @TRIGGER_MODE_0)
(==> webcam start_iso_transmission)
(==> webcam single_capture :camera:p)
(==> webcam stop_iso_transmission)

(de writeppm ( filename data w h)
  ((-str-) filename)
  ((-gptr-) data)
  ((-int-) w h)
  #{ {
  FILE *imagefile = fopen((char *)$filename->data, "w");
 fprintf(imagefile,"P5\n%u %u 255\n", $w, $h );
  fwrite((const char *)$data, 1,$w*$h, imagefile);
  fclose(imagefile); } #}
  ())

(dhc-make () writeppm)

(writeppm  "test.ppm" (==> camera get_buffer)  640 480)
