Index: trunk/MagicSoft/Cosy/videodev/CaosFilter.h
===================================================================
--- trunk/MagicSoft/Cosy/videodev/CaosFilter.h	(revision 1803)
+++ trunk/MagicSoft/Cosy/videodev/CaosFilter.h	(revision 1803)
@@ -0,0 +1,56 @@
+#ifndef CAOSFILTER_H
+#define CAOSFILTER_H
+
+#ifndef __CINT__
+#include <TROOT.h>
+#endif
+
+typedef unsigned char byte;
+
+class Leds;
+
+class CaosFilter
+{
+    static void  DrawBox(const int x1, const int y1,
+                         const int x2, const int y2,
+                         byte *buffer, const int col);
+
+    static void  MarkPoint(const int x, const int y,
+                           byte *buffer, const int col);
+
+    static float Mean(const byte *buffer, const int offset,
+                      int *min, int *max);
+
+    static float SDev(const byte *buffer, const int offset,
+                      const double mean);
+
+    static int   GetMeanPosition(const byte *bitmap,
+                                 const int x, const int y,
+                                 const int box);
+
+    static int   GetMeanPosition(const byte *bitmap, const int x, const int y,
+                                 const int box, Float_t &mx, Float_t &my);
+
+    static bool  CalcCenter(Float_t *px, Float_t *py, Float_t &cx, Float_t &cy, Float_t &R);
+
+    static void  InterpolCenter(int &m, Float_t *x, Float_t *y, Float_t &px, Float_t &py,
+                                Float_t &pr, Float_t &sx, Float_t &sy, Float_t &sr);
+
+    static void  CalcRings(int &m, Float_t *x, Float_t *y, Float_t &px, Float_t &py,
+                           Float_t &pr, float *v, float *w);
+
+    static int   FilterLeds(float *xw, float *yw, float *xl, float *yl);
+
+
+public:
+    static void Execute(byte *img, float *xw, float *yw, float *xl, float *yl,
+                        float &prx, float &pry, float &pr, float *v, float *w);
+
+    static void Execute(byte *img, Leds &leds, Double_t conv);
+
+    static void  FilterLeds(Leds &leds);
+
+    ClassDef(CaosFilter, 0)
+};
+
+#endif
Index: trunk/MagicSoft/Cosy/videodev/PngReader.cc
===================================================================
--- trunk/MagicSoft/Cosy/videodev/PngReader.cc	(revision 1803)
+++ trunk/MagicSoft/Cosy/videodev/PngReader.cc	(revision 1803)
@@ -0,0 +1,162 @@
+#include "PngReader.h"
+#include "PixClient.h"
+
+#include <iostream.h>
+#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>
+
+ClassImp(PngReader);
+
+char *PngReader::GetImg(unsigned int frame)
+{
+    char txt1[100];
+
+    frame %= 333;
+
+    sprintf(txt1, "file%04d.png", frame);
+
+    // cout << "Reading PNG '" << txt1 << "'" << endl;
+
+    char txt2[200];
+    sprintf(txt2, "/home/caos/Dani/Cosy/smallleds/%s", txt1);
+    //sprintf(txt2, "/home/caos/cosy.lp/pix/stable_1min/%s", txt1);
+
+    //
+    // open file
+    //
+    FILE *fd = fopen(txt2, "r");
+    if (!fd)
+    {
+        cout << "Cannot open file." << endl;
+        return 0;
+    }
+    //
+    // allocate memory
+    //
+    png_structp fPng = png_create_read_struct(PNG_LIBPNG_VER_STRING,
+                                              NULL, NULL, NULL);
+
+    if (!fPng)
+    {
+        cout << "Warning: Unable to create PNG structure" << endl;
+        fclose(fd);
+        return 0;
+    }
+
+
+    png_infop fInfo = png_create_info_struct(fPng);
+
+    if (!fInfo)
+    {
+        cout << "Warning: Unable to create PNG info structure" << endl;
+        png_destroy_read_struct (&fPng, NULL, NULL);
+        fclose(fd);
+        return 0;
+    }
+
+    //
+    // set jump-back point in case of errors
+    //
+    if (setjmp(fPng->jmpbuf))
+    {
+        cout << "longjmp Warning: PNG encounterd an error!" << endl;
+        png_destroy_read_struct (&fPng, &fInfo, NULL);
+        fclose(fd);
+        return 0;
+    }
+
+    //
+    // connect file to PNG-Structure
+    //
+    png_init_io(fPng, fd);
+
+    // png_set_compression_level (fPng, Z_BEST_COMPRESSION);
+
+    png_read_png(fPng, fInfo, 0, NULL);
+
+    //
+    // Write bitmap data
+    //
+    static int first = 0;
+    for (unsigned int y=0; y<576; y++)
+        for (unsigned int x=0; x<768; x++)
+            *(fImg+(y*768)+x) = fInfo->row_pointers[y][x];
+
+    //
+    // free memory
+    //
+    png_destroy_read_struct (&fPng, &fInfo, NULL);
+
+    fclose(fd);
+
+    return fImg; 
+}
+
+PngReader::PngReader(PixClient &client) : fClient(client)
+{
+    cout << "Starting thread..." << flush;
+    pthread_create(&fThread, NULL, MapThread, this);
+    cout << "done." << endl;
+
+}
+
+PngReader::~PngReader()
+{
+    cout << "Stopping thread..." << flush;
+    pthread_cancel(fThread);
+    cout << "done." << endl;
+}
+
+void *PngReader::MapThread(void *arg)
+{
+    PngReader *cam = (PngReader*)arg;
+
+    // setpriority(PRIO_PROCESS, 0, 10);
+    pthread_detach(pthread_self());
+
+    cam->Thread();
+
+    return 0;
+}
+
+void PngReader::Thread()
+{
+    fIsRunning = 1;
+    usleep(3000000);
+    int i=0;
+
+    gettimeofday(&fTime, NULL);
+
+    while (!fStop)
+    {
+        // if (i<536)
+        // {
+        GetImg(i);
+        fClient.ProcessFrame(i++, (byte*)fImg, &fTime);
+        // usleep(10000);
+        // }
+        // else exit();
+        fTime.tv_sec += 1;
+        usleep(1000);
+    }
+
+
+    fIsRunning = 0;
+}
+
Index: trunk/MagicSoft/Cosy/videodev/PngReader.h
===================================================================
--- trunk/MagicSoft/Cosy/videodev/PngReader.h	(revision 1803)
+++ trunk/MagicSoft/Cosy/videodev/PngReader.h	(revision 1803)
@@ -0,0 +1,78 @@
+#ifndef PngReader_H
+#define PngReader_H
+
+#ifdef __CINT__
+typedef unsigned long int pthread_t;
+struct pthread_mutex_t;
+struct pthread_cond_t;
+struct timeval;
+#else
+#include <TROOT.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <sys/time.h>
+#endif
+
+class PixClient;
+
+typedef unsigned char byte;
+
+class PngReader
+{
+private:
+    //
+    // Geometry
+    //
+    static const int gfCols  = 768;
+    static const int gfRows  = 576;
+    static const int gfDepth = 3;
+
+    int fStop;
+    int fIsRunning;
+
+    //
+    // Thread interface
+    //
+    unsigned long fNum;
+
+    char fImg[gfCols*gfRows];
+    struct timeval fTime;
+
+    pthread_t fThread;
+
+    PixClient &fClient;
+
+    //
+    // Hardware dependant functions
+    //
+    char *GetImg(unsigned int frame);
+
+    //
+    // Execution thread which processes the pictures
+    //
+    void Thread();
+    static void *MapThread(void *arg);
+
+public:
+    PngReader(PixClient &client);
+    virtual ~PngReader();
+
+    //
+    // Starts, stops the execution
+    //
+    void ExitLoop()
+    {
+        fStop = 1;
+        while (IsRunning())
+            usleep(1);
+    }
+
+    //
+    // flag if the execution is running or not
+    //
+    int IsRunning() const { return fIsRunning; }
+
+    ClassDef(PngReader, 0)
+};
+
+#endif
