Index: trunk/MagicSoft/Cosy/Changelog
===================================================================
--- trunk/MagicSoft/Cosy/Changelog	(revision 8859)
+++ trunk/MagicSoft/Cosy/Changelog	(revision 8860)
@@ -1,3 +1,22 @@
                                                                   -*-*- END -*-*-
+
+ 2008/02/09 Thomas Bretz (La Palma)
+
+   * Makefile:
+     - removed readcam
+
+   * cosy.cc:
+     - fixed a problem with the --channel option
+
+   * videodev/Camera.[h,cc]:
+     - changed argument of Process frame to unsigned
+     - always interpolate the rgb value -- this gives clearly
+       less noisy pictures
+     - fixed the switchibng of the channel
+
+   * videodev/PngReader.cc:
+     - fixed order of includes
+
+
 
  2008/02/08 Thomas Bretz (La Palma)
Index: trunk/MagicSoft/Cosy/Makefile
===================================================================
--- trunk/MagicSoft/Cosy/Makefile	(revision 8859)
+++ trunk/MagicSoft/Cosy/Makefile	(revision 8860)
@@ -19,5 +19,5 @@
 
 #
-PROGRAMS = cosy readcam telesto
+PROGRAMS = cosy telesto
 SOLIB    = libcosy.so
 CINT     = M
Index: trunk/MagicSoft/Cosy/cosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/cosy.cc	(revision 8859)
+++ trunk/MagicSoft/Cosy/cosy.cc	(revision 8860)
@@ -80,5 +80,5 @@
     }
 
-    const Int_t  channel       = arg.GetIntAndRemove("--channel", 0);
+    const Int_t  channel       = arg.GetIntAndRemove("--channel=", 0);
     const Bool_t kDebugMem     = arg.HasOnlyAndRemove("--debug-mem");
     const Bool_t kDebugThreads = arg.HasOnlyAndRemove("--debug-threads");
Index: trunk/MagicSoft/Cosy/videodev/Camera.cc
===================================================================
--- trunk/MagicSoft/Cosy/videodev/Camera.cc	(revision 8859)
+++ trunk/MagicSoft/Cosy/videodev/Camera.cc	(revision 8860)
@@ -34,5 +34,5 @@
 using namespace std;
 
-Camera::Camera(PixClient &client, Int_t nch) : MThread("Camera"), fClient(client), fVideo(0)
+Camera::Camera(PixClient &client, Int_t nch) : MThread("Camera"), fClient(client), fVideo(0), fNumFrame(0)
 {
     fVideo = new MVideo;
@@ -51,5 +51,5 @@
 }
 
-void Camera::ProcessFrame(char *img)
+void Camera::ProcessFrame(unsigned char *img)
 {
     gettimeofday(&fTime, NULL);
@@ -57,5 +57,5 @@
     const Int_t W = fVideo->GetWidth();
     const Int_t H = fVideo->GetHeight();
-
+/*
     const Bool_t crop = W!=768 || H!=576;
 
@@ -64,5 +64,5 @@
     {
         // FIXME: Grey scale assumed!
-        const char *end = img + 768*576*depth;
+        const unsigned char *end = img + 768*576*depth;
         char *beg = fImg;
         while (img < end)
@@ -73,4 +73,5 @@
     }
     else
+ */
     {
         const Int_t w = TMath::Min(W, 768);
@@ -80,5 +81,8 @@
         for (int y=0; y<h; y++)
             for (int x=0; x<w; x++)
-                fImg[x+y*768] = ((UInt_t)(UChar_t)img[(x+y*W)*3]+(UInt_t)(UChar_t)img[(x+y*fVideo->GetWidth())*3+1]+(UInt_t)(UChar_t)img[(x+y*fVideo->GetWidth())*3+2])/3;
+            {
+                const Int_t p = (x+y*W)*depth;
+                fImg[x+y*768] = ((UInt_t)img[p]+(UInt_t)img[p+1]+(UInt_t)img[p+2])/3;
+            }
     }
 
@@ -97,30 +101,48 @@
     }
 
-    //Print();
+    gLog << dbg << "Start Camera::Thread at frame " << fNumFrame%fVideo->GetNumBuffers() << endl;
 
-    for (int f=1; f<fVideo->GetNumBuffers(); f++)
+    for (int f=0; f<fVideo->GetNumBuffers(); f++)
         if (!fVideo->CaptureStart(f))
             return kFALSE;
 
     Int_t timeouts = 0;
-
     while (1)
     {
-        // If cacellation is requested cancel here
-        TThread::CancelPoint();
-
-        // Start to capture into the buffer which has just been processed
-        if (!fVideo->CaptureStart(fNumFrame))
+        // Switch channel if necessary
+        switch (fVideo->SetChannel(fChannel))
+        {
+        case kFALSE:        // Error swucthing channel
+            return kFALSE;
+        case kSKIP:         // No channel switching necessary
             break;
-
-        // If cacellation is requested cancel here
-        TThread::CancelPoint();
+        case kTRUE:         // Channel switched (skip filled buffers)
+            for (int f=0; f<fVideo->GetNumBuffers(); f++)
+                if (!fVideo->CaptureWait(fNumFrame+f))
+                    return kFALSE;
+            fNumFrame=0;
+            for (int f=0; f<fVideo->GetNumBuffers(); f++)
+                if (!fVideo->CaptureStart(f))
+                    return kFALSE;
+            break;
+        }
 
         // Check and wait until capture into the next buffer is finshed
-        char *img = 0;
-        switch (fVideo->CaptureWait(++fNumFrame, &img))
+        unsigned char *img = 0;
+        switch (fVideo->CaptureWait(fNumFrame++, &img))
         {
         case kTRUE: // Process frame
+            // If cacellation is requested cancel here
+            TThread::CancelPoint();
+
             ProcessFrame(img);
+
+            // If cacellation is requested cancel here
+            TThread::CancelPoint();
+
+            // Start to capture into the buffer which has just been processed
+            if (!fVideo->CaptureStart(fNumFrame-1))
+                break;
+
             timeouts = 0;
             continue;
@@ -158,7 +180,8 @@
 void Camera::SetChannel(int chan)
 {
-    CancelThread();
-    fVideo->SetChannel(chan);
-    RunThread();
+    fChannel = chan;
+//    CancelThread();
+//    fVideo->SetChannel(chan);
+//    RunThread();
 }
 
Index: trunk/MagicSoft/Cosy/videodev/Camera.h
===================================================================
--- trunk/MagicSoft/Cosy/videodev/Camera.h	(revision 8859)
+++ trunk/MagicSoft/Cosy/videodev/Camera.h	(revision 8860)
@@ -33,6 +33,8 @@
     UInt_t fNumSkipped;
 
+    UInt_t fChannel;
+
     Int_t Thread();
-    void  ProcessFrame(char *img);
+    void  ProcessFrame(unsigned char *img);
 
 public:
Index: trunk/MagicSoft/Cosy/videodev/PngReader.cc
===================================================================
--- trunk/MagicSoft/Cosy/videodev/PngReader.cc	(revision 8859)
+++ trunk/MagicSoft/Cosy/videodev/PngReader.cc	(revision 8860)
@@ -1,24 +1,9 @@
+#include "png.h"
+
 #include "PngReader.h"
-#include "PixClient.h"
 
 #include <iostream>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <signal.h>
-#include <endian.h>
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
 
-#include "png.h"
-
-#include "videodev.h"
-
-#include <sys/time.h>
-#include <sys/resource.h>
+#include "PixClient.h"
 
 ClassImp(PngReader);
