summaryrefslogtreecommitdiff
path: root/2003
diff options
context:
space:
mode:
Diffstat (limited to '2003')
-rw-r--r--2003/i/buzz/src/camera/Makefile.defs5
-rw-r--r--2003/i/buzz/src/camera/camera.cc41
-rw-r--r--2003/i/buzz/src/camera/camera.h5
-rw-r--r--2003/i/buzz/src/camera/dumpimage.cc4
-rw-r--r--2003/i/buzz/src/camera/test_camera.cc74
5 files changed, 101 insertions, 28 deletions
diff --git a/2003/i/buzz/src/camera/Makefile.defs b/2003/i/buzz/src/camera/Makefile.defs
index 6ef85b3..e9457f6 100644
--- a/2003/i/buzz/src/camera/Makefile.defs
+++ b/2003/i/buzz/src/camera/Makefile.defs
@@ -1,6 +1,7 @@
TARGETS += test_camera dumpimage
-test_camera_SOURCES = camera.cc test_camera.cc erreur.a
-dumpimage_SOURCES = camera.cc dumpimage.cc erreur.a
+LIBS += camera.a
+test_camera_SOURCES = camera.cc test_camera.cc erreur.a config.a
+dumpimage_SOURCES = camera.cc dumpimage.cc erreur.a config.a
camera_a_SOURCES = camera.cc
dumpimage: $(dumpimage_SOURCES:%.cc=%.o)
diff --git a/2003/i/buzz/src/camera/camera.cc b/2003/i/buzz/src/camera/camera.cc
index e9a7f60..27132f9 100644
--- a/2003/i/buzz/src/camera/camera.cc
+++ b/2003/i/buzz/src/camera/camera.cc
@@ -5,6 +5,7 @@
#include "camera.h"
#include "erreur/erreur.h"
#include "kernel/pbus.h"
+#include "config/config.h"
#include <fcntl.h>
#include <unistd.h>
@@ -17,6 +18,9 @@
// Constructeur.
Camera::Camera ()
{
+ // Taille par défaut.
+ m_w = 352; m_h = 288;
+ m_cut = 0;
// Ouvre le périphérique.
m_fd = open (CAM_FILE, O_RDONLY);
if (m_fd == -1)
@@ -24,13 +28,33 @@ Camera::Camera ()
" camera.\n");
// Paramètre la camera.
sccb_io param;
- ifstream rc ("rc/camera");
+ Config rc ("rc/camera");
int addr, data;
while (!rc.eof ())
{
- rc >> hex >> addr >> hex >> data;
- if (rc.good ())
+ if (rc.isId ("width"))
{
+ rc.getId ();
+ m_w = rc.getNum ();
+ cout << "camera width " << m_w << endl;
+ }
+ else if (rc.isId ("height"))
+ {
+ rc.getId ();
+ m_h = rc.getNum ();
+ cout << "camera height " << m_h << endl;
+ }
+ else if (rc.isId ("cut"))
+ {
+ rc.getId ();
+ m_cut = rc.getNum ();
+ cout << "camera cut " << m_cut << endl;
+ }
+ else if (rc.isId ("setup"))
+ {
+ rc.getId ();
+ addr = rc.getNum ();
+ data = rc.getNum ();
param.addr = addr; param.data = data;
cout << "camera sccbwrite 0x" << hex << addr << " 0x" << data <<
endl;
@@ -50,7 +74,8 @@ Camera::Camera ()
}
cout << endl << dec;
// Paramètre la taille de frame.
- m_frameSize = m_w * m_h * 3;
+ ioctl (m_fd, CAM_SETHCOUNT, &m_w);
+ m_frameSize = m_w * m_h + m_cut;
ioctl (m_fd, CAM_SETFRAMESIZE, &m_frameSize);
}
@@ -62,11 +87,15 @@ Camera::~Camera ()
}
// Lit une image.
-void
+int
Camera::read (unsigned char *image) const
{
int r;
// Lit les données sur la camera.
- r = ::read (m_fd, image, m_frameSize);
+ if (m_cut)
+ r = ::read (m_fd, image, m_cut);
+ if (!m_cut || r)
+ r = ::read (m_fd, image, m_frameSize - m_cut);
cout << "camera read " << r << endl;
+ return r;
}
diff --git a/2003/i/buzz/src/camera/camera.h b/2003/i/buzz/src/camera/camera.h
index 954980c..2d056c4 100644
--- a/2003/i/buzz/src/camera/camera.h
+++ b/2003/i/buzz/src/camera/camera.h
@@ -7,7 +7,8 @@
class Camera
{
int m_fd;
- static const int m_w = 352, m_h = 288;
+ int m_w, m_h;
+ int m_cut;
int m_frameSize;
public:
// Constructeur.
@@ -15,7 +16,7 @@ class Camera
// Destructeur.
~Camera ();
// Lit une image.
- void read (unsigned char *image) const;
+ int read (unsigned char *image) const;
// Lit la taille.
void getSize (int &w, int &h) const { w = m_w; h = m_h; }
};
diff --git a/2003/i/buzz/src/camera/dumpimage.cc b/2003/i/buzz/src/camera/dumpimage.cc
index 6692c26..e617c6a 100644
--- a/2003/i/buzz/src/camera/dumpimage.cc
+++ b/2003/i/buzz/src/camera/dumpimage.cc
@@ -13,14 +13,14 @@ main (int argc, char **argv)
Camera cam;
int w, h;
cam.getSize (w, h);
- unsigned char *image = new unsigned char[w * h];
+ unsigned char *image = new unsigned char[w * h * 3];
cout << hex;
int j = 0;
int pixel;
while (1)
{
cout << dec << "\n- " << j++ << hex << " ---------";
- cam.read (image);
+ while (cam.read (image) == 0) sleep (1);
for (int i = 0; i < 256; ++i)
{
if (!(i % 16))
diff --git a/2003/i/buzz/src/camera/test_camera.cc b/2003/i/buzz/src/camera/test_camera.cc
index 1868ad5..b81f1dc 100644
--- a/2003/i/buzz/src/camera/test_camera.cc
+++ b/2003/i/buzz/src/camera/test_camera.cc
@@ -3,26 +3,68 @@
// Copyright (C) 2003 Nicolas Schodet
//
#include "camera.h"
+#include "erreur/erreur.h"
#include <fstream>
+#include <unistd.h>
+#include <stdio.h>
int
main (int argc, char **argv)
{
- Camera cam;
- ofstream o0 (argc >= 2 ? argv[1] : "camera0.raw");
- ofstream o1 (argc >= 3 ? argv[2] : "camera1.raw");
- ofstream o2 (argc == 4 ? argv[3] : "camera2.raw");
- int w, h;
- cam.getSize (w, h);
- unsigned char *image = new unsigned char[w * h * 3];
- cam.read (image);
- o0.write (image, w * h * 3);
- o0.close ();
- cam.read (image);
- o1.write (image, w * h * 3);
- o1.close ();
- cam.read (image);
- o2.write (image, w * h * 3);
- o2.close ();
+ try
+ {
+ Camera cam;
+ int w, h;
+ cam.getSize (w, h);
+ unsigned char *image = new unsigned char[w * h];
+ unsigned char *image2 = new unsigned char[w * h * 3];
+ for (int i = 0; i < 10; ++i)
+ {
+ char s[256];
+ sprintf (s, "camera%d.gray", i);
+ ofstream o (s);
+ while (cam.read (image) == 0) sleep (1);
+ o.write (image, w * h);
+ o.close ();
+ for (int j = 0; j < w * h; j += 4)
+ {
+ image2[j * 3] = image[j + 2];
+ image2[j * 3 + 1] = image[j + 1];
+ image2[j * 3 + 2] = image[j];
+ image2[(j + 1) * 3] = image[j + 2];
+ image2[(j + 1) * 3 + 1] = image[j + 1];
+ image2[(j + 1) * 3 + 2] = image[j];
+ image2[(j + 2) * 3] = image[j + 2];
+ image2[(j + 2) * 3 + 1] = image[j + 1];
+ image2[(j + 2) * 3 + 2] = image[j];
+ image2[(j + 3) * 3] = image[j + 2];
+ image2[(j + 3) * 3 + 1] = image[j + 1];
+ image2[(j + 3) * 3 + 2] = image[j];
+ }
+ sprintf (s, "camera%d.rgb", i);
+ o.open (s);
+ o.write (image2, w * h * 3);
+ o.close ();
+ for (int j = 0; j < w * h; j += 4)
+ {
+ int t = (int) image[j + 2] >> 2 - (int) image[j + 1] >> 2;
+ t = t > 0 ? t : -t;
+ image2[j] = t;
+ image2[j + 1] = t;
+ image2[j + 2] = t;
+ image2[j + 3] = t;
+ }
+ sprintf (s, "camera%d.diff.gray", i);
+ o.open (s);
+ o.write (image2, w * h);
+ o.close ();
+ }
+ return 0;
+ }
+ catch (Erreur &e)
+ {
+ cout << e.what ();
+ return 1;
+ }
}