summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/video4linux/test_video4linux.cc
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert/src/video4linux/test_video4linux.cc')
-rw-r--r--2005/i/robert/src/video4linux/test_video4linux.cc84
1 files changed, 84 insertions, 0 deletions
diff --git a/2005/i/robert/src/video4linux/test_video4linux.cc b/2005/i/robert/src/video4linux/test_video4linux.cc
new file mode 100644
index 0000000..9abdf4a
--- /dev/null
+++ b/2005/i/robert/src/video4linux/test_video4linux.cc
@@ -0,0 +1,84 @@
+// test_video4linux.cc
+// robert - programme du robot 2005. {{{
+//
+// Copyright (C) 2005 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2005.
+// Web: http://assos.efrei.fr/robot/
+// Email: robot AT efrei DOT fr
+//
+// 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-1307, USA.
+//
+// }}}
+#include "video4linux.hh"
+#include "utils/errno_exception.hh"
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <iostream>
+#include <sstream>
+#include <iomanip>
+#include <stdexcept>
+#include <string>
+
+int
+main (int argc, char **argv)
+{
+ try
+ {
+ if (argc != 3)
+ throw std::runtime_error ("Syntaxe : fichier "
+ "{rgb|bgr|yuv|yuv422}");
+ std::string format (argv[2]);
+ Image::PixelFormat pf;
+ if (format == "rgb")
+ pf = Image::rgb;
+ else if (format == "bgr")
+ pf = Image::bgr;
+ else if (format == "yuv")
+ pf = Image::yuv;
+ else if (format == "yuv422")
+ pf = Image::yuv422;
+ else
+ throw std::invalid_argument ("Syntaxe : fichier {rgb|yuv422}");
+ Video4Linux vid ("/dev/video", pf);
+ vid.calibrate ();
+ int w, h;
+ vid.getParam (w, h, pf);
+ std::cout << w << ' ' << h << std::endl;
+ int s;
+ s = Image::getBufSize (w, h, pf);
+ uint8_t *buf = new uint8_t[s];
+ for (int i = 0; i < 10; ++i)
+ {
+ vid.read (buf, s);
+ std::ostringstream os;
+ os << argv[1] << std::setw (3) << std::setfill ('0') << i << '.'
+ << argv[2];
+ int fd = open (os.str ().c_str (), O_WRONLY | O_CREAT, 0666);
+ if (fd == -1)
+ throw errno_exception (argv[1], errno);
+ write (fd, buf, s);
+ close (fd);
+ }
+ delete[] buf;
+ return 0;
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << e.what () << std::endl;
+ return 1;
+ }
+}