From 911a05806c4cce85750f3bd9bca84e18162cb739 Mon Sep 17 00:00:00 2001 From: mickeyl Date: Tue, 01 Apr 2003 23:19:16 +0000 Subject: figured out how to get binary RAW data into a QImage actual capturing is now only a footstep away :-D --- diff --git a/noncore/multimedia/camera/mainwindow.cpp b/noncore/multimedia/camera/mainwindow.cpp index 6431dfa..2cca9f9 100644 --- a/noncore/multimedia/camera/mainwindow.cpp +++ b/noncore/multimedia/camera/mainwindow.cpp @@ -14,6 +14,7 @@ **********************************************************************/ #include "mainwindow.h" +#include "zcameraio.h" #include #include @@ -26,7 +27,7 @@ CameraMainWindow::CameraMainWindow( QWidget * parent, const char * name, WFlags :QMainWindow( parent, name, f ) { QVBox* v = new QVBox( this ); - QLabel* l = new QLabel( v ); + l = new QLabel( v ); l->setFixedSize( QSize( 240, 160 ) ); QPushButton* p = new QPushButton( "Snapshot", v ); connect( p, SIGNAL( clicked() ), this, SLOT( clickedSnapShot() ) ); @@ -45,6 +46,12 @@ CameraMainWindow::~CameraMainWindow() void CameraMainWindow::clickedSnapShot() { - qDebug( "Hello!" ); + QImage i; + QPixmap p; + if ( ZCameraIO::instance()->snapshot( &i ) ) + { + p.convertFromImage( i ); + l->setPixmap( p ); + } } diff --git a/noncore/multimedia/camera/mainwindow.h b/noncore/multimedia/camera/mainwindow.h index a349652..521107b 100644 --- a/noncore/multimedia/camera/mainwindow.h +++ b/noncore/multimedia/camera/mainwindow.h @@ -18,10 +18,9 @@ #include -class Wellenreiter; -class WellenreiterConfigWindow; class QIconSet; class QToolButton; +class QLabel; class CameraMainWindow: public QMainWindow { @@ -35,6 +34,9 @@ class CameraMainWindow: public QMainWindow public slots: void clickedSnapShot(); + + private: + QLabel* l; }; #endif diff --git a/noncore/multimedia/camera/zcameraio.cpp b/noncore/multimedia/camera/zcameraio.cpp index aa6cbe3..e74136f 100644 --- a/noncore/multimedia/camera/zcameraio.cpp +++ b/noncore/multimedia/camera/zcameraio.cpp @@ -26,12 +26,15 @@ #include +ZCameraIO* ZCameraIO::_instance = 0; + ZCameraIO::ZCameraIO() { _driver = open( "/dev/sharp_zdc", O_RDWR ); if ( _driver == -1 ) oerr << "Can't open camera driver: " << strerror(errno) << oendl; + ZCameraIO::_instance = this; }; @@ -42,8 +45,10 @@ ZCameraIO::~ZCameraIO() } -bool ZCameraIO::snapshot( QImage* img ) +bool ZCameraIO::snapshot( QImage* image ) { + /* + char buf[76800]; write( _driver, "M=13", 4 ); @@ -53,4 +58,32 @@ bool ZCameraIO::snapshot( QImage* img ) int result = read( _driver, &buf, sizeof buf ); return result == sizeof buf; + + */ + + uchar buf[76800]; + uchar* bp = buf; + uchar* p; + + + int fd = open( "/tmp/cam", O_RDONLY ); + if ( read( fd, buf, sizeof buf ) != sizeof buf ) + qDebug( "WARNING: couldn't read image!" ); + + image->create( 240, 160, 16 ); + for ( int i = 0; i < 160; ++i ) + { + p = image->scanLine( i ); + for ( int j = 0; j < 240; j++ ) + { + *p = *bp; + p++; + bp++; + *p = *bp; + p++; + bp++; + } + } + + return true; } diff --git a/noncore/multimedia/camera/zcameraio.h b/noncore/multimedia/camera/zcameraio.h index 817d3b4..1690aa6 100644 --- a/noncore/multimedia/camera/zcameraio.h +++ b/noncore/multimedia/camera/zcameraio.h @@ -25,11 +25,12 @@ class ZCameraIO virtual ~ZCameraIO(); bool isOpen() const { return _driver != -1; }; - bool snapshot( QImage* ); + static ZCameraIO* instance() { return _instance; }; private: int _driver; + static ZCameraIO* _instance; }; #endif -- cgit v0.9.0.2