Index: trunk/FACT++/drive/MGImage.cc
===================================================================
--- trunk/FACT++/drive/MGImage.cc	(revision 18627)
+++ trunk/FACT++/drive/MGImage.cc	(revision 18628)
@@ -20,11 +20,13 @@
 #include "MGImage.h"
 
+#include <iostream>
+
 #include <TGX11.h>
 #include <TMutex.h>
 
-#include "MLog.h"
-#include "MLogManip.h"
-
-ClassImp(MGImage);
+#include <TMath.h>
+
+//#include "MLog.h"
+//#include "MLogManip.h"
 
 using namespace std;
@@ -50,13 +52,13 @@
     fImage  = (XImage*)gVirtualX->CreateImage(fWidth, fHeight);
 
-    gLog << all << "Detected Color Depth: " << gVirtualX->GetDepth() << endl;
+    cout << "Detected Color Depth: " << gVirtualX->GetDepth() << endl;
 }
 
 MGImage::~MGImage()
 {
-    if (fMuxPixmap->Lock()==13)
-        cout << "MGImage::~MGImage - mutex is already locked by this thread" << endl;
-
-    gLog << inf2 << "Deleting MGImage..." << endl;
+//    if (fMuxPixmap->Lock()==13)
+//        cout << "MGImage::~MGImage - mutex is already locked by this thread" << endl;
+
+    cout << "Deleting MGImage..." << endl;
 
     gVirtualX->DeleteGC(fDefGC);
@@ -67,5 +69,5 @@
     delete fMuxPixmap;
 
-    gLog << inf2 << "MGImage destroyed." << endl;
+    cout << "MGImage destroyed." << endl;
 }
 
@@ -90,5 +92,5 @@
     if (TestBit(kSyncMode))
         if (fMuxPixmap->UnLock()==13)
-            gLog << warn << "MGImage::DoRedraw - tried to unlock mutex locked by other thread." << endl;
+            cout << "MGImage::DoRedraw - tried to unlock mutex locked by other thread." << endl;
 }
 
@@ -250,2 +252,212 @@
         cout << "MGImage::DrawColImage - tried to unlock mutex locked by other thread." << endl;
 }
+
+// --------------------------------------------------------------------------
+//
+// Convert root colors to arbitrary bitmap coordinates
+//
+UChar_t MGImage::Color(int col)
+{
+    switch (col)
+    {
+    case kBlack:  return 0;
+    case kWhite:  return 0xff;
+    case kYellow: return 0x0f;
+    case kRed:    return 2;
+    case kGreen:  return 2<<2;
+    case kBlue:   return 2<<4;
+    default:
+        return 0;
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Draw a line into the buffer (size w*h) from (x1, y1) to (x2, y2) with
+// the color col and the line style style (default: solid)
+//
+void MGImage::DrawLine(UChar_t *buf, int w, int h, Float_t x1, Float_t y1, Float_t x2, Float_t y2, UChar_t col, Int_t style)
+{
+    const Int_t    step = style==kSolid?1:3;
+    const Double_t len  = TMath::Hypot(x2-x1, y2-y1);
+    const Double_t dx   = (x2-x1)/len*step;
+    const Double_t dy   = (y2-y1)/len*step;
+
+    Double_t x = x1;
+    Double_t y = y1;
+
+    for (int i=0; i<len; i+=step)
+    {
+        x+= dx;
+        y+= dy;
+
+        const Int_t iy = TMath::Nint(y);
+        if (iy<0 || iy>=h)
+            continue;
+
+        const Int_t ix = TMath::Nint(x);
+        if (ix<0 || ix>=w)
+            continue;
+
+        buf[ix+iy*w] = col;
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Draw a box into the buffer (size w*h) from (x1, y1) to (x2, y2) with
+// the color col and the line style style (default: solid)
+//
+void MGImage::DrawBox(UChar_t *buf, int w, int h, Float_t x1, Float_t y1, Float_t x2, Float_t y2, UChar_t col, Int_t style)
+{
+    DrawLine(buf, w, h, x1, y1, x2, y1, col, style);
+    DrawLine(buf, w, h, x1, y2, x2, y1, col, style);
+    DrawLine(buf, w, h, x1, y1, x1, y2, col, style);
+    DrawLine(buf, w, h, x2, y1, x2, y2, col, style);
+}
+
+// --------------------------------------------------------------------------
+//
+// Draw a hexagon into the buffer (size w*h) around (x, y) with radius r and
+// the color col.
+//
+void MGImage::DrawHexagon(UChar_t *buf, int w, int h, Float_t px, Float_t py, Float_t d, UChar_t col, Int_t style)
+{
+    const Int_t np = 6;
+
+    const Double_t dy[np+1] = { .5   , 0.    , -.5   , -.5   , 0.    ,  .5   , .5    };
+    const Double_t dx[np+1] = { .2886,  .5772,  .2886, -.2886, -.5772, -.2886, .2886 };
+
+    //
+    //  calculate the positions of the pixel corners
+    //
+    Double_t x[np+1], y[np+1];
+    for (Int_t i=0; i<np+1; i++)
+    {
+        x[i] = px + dx[i]*d;
+        y[i] = py + dy[i]*d;
+    }
+
+    for (int i=0; i<6; i++)
+        DrawLine(buf, w, h, x[i], y[i], x[i+1], y[i+1], col, style);
+}
+
+// --------------------------------------------------------------------------
+//
+// Draw a circle into the buffer (size w*h) around (x, y) with radius r and
+// the color col.
+//
+void MGImage::DrawCircle(UChar_t *buf, int w, int h, Float_t x, Float_t y, Float_t r, UChar_t col)
+{
+    const Int_t n = TMath::Nint(sqrt(2.)*r*TMath::Pi()/2);
+    for (int i=0; i<n-1; i++)
+    {
+        const Double_t angle = TMath::TwoPi()*i/n;
+
+        const Double_t dx = r*cos(angle);
+        const Double_t dy = r*sin(angle);
+
+        const Int_t x1 = TMath::Nint(x+dx);
+        const Int_t x2 = TMath::Nint(x-dx);
+
+        const Int_t y1 = TMath::Nint(y+dy);
+        if (y1>=0 && y1<h)
+        {
+            if (x1>=0 && x1<w)
+                buf[x1+y1*w] = col;
+
+            if (x2>=0 && x2<w)
+                buf[x2+y1*w] = col;
+        }
+
+        const Int_t y2 = TMath::Nint(y-dy);
+        if (y2>=0 && y2<h)
+        {
+            if (x1>=0 && x1<w)
+                buf[x1+y2*w] = col;
+
+            if (x2>=0 && x2<w)
+                buf[x2+y2*w] = col;
+        }
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Draw a dot into the buffer (size w*h) at (x, y) with color col.
+//
+void MGImage::DrawDot(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, UChar_t col)
+{
+    const Int_t x1 = TMath::Nint(cx);
+    const Int_t y1 = TMath::Nint(cy);
+
+    if (x1>=0 && y1>=0 && x1<w && y1<h)
+        buf[x1+y1*w] = col;
+}
+
+// --------------------------------------------------------------------------
+//
+// Draw a line into the buffer. The TObject must be a TLine.
+// Currently only solid and non sloid line are supported.
+//
+/*
+void MGImage::DrawLine(TObject *o, UChar_t *buf, int w, int h, Double_t scale)
+{
+    TLine *l = dynamic_cast<TLine*>(o);
+    if (!l)
+        return;
+
+    const Double_t x1 = 0.5*w-(l->GetX1()/scale);
+    const Double_t x2 = 0.5*w-(l->GetX2()/scale);
+    const Double_t y1 = 0.5*h-(l->GetY1()/scale);
+    const Double_t y2 = 0.5*h-(l->GetY2()/scale);
+
+    const Int_t col = Color(l->GetLineColor());
+    DrawLine(buf, w, h, x1, y1, x2, y2, col, l->GetLineStyle());
+}
+*/
+void MGImage::DrawMultiply(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, Float_t size, UChar_t col)
+{
+    DrawLine(buf, w, h, cx-size, cy-size, cx+size, cy+size, col);
+    DrawLine(buf, w, h, cx+size, cy-size, cx-size, cy+size, col);
+}
+
+void MGImage::DrawCross(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, Float_t size, UChar_t col)
+{
+    DrawLine(buf, w, h, cx-size, cy, cx+size, cy, col);
+    DrawLine(buf, w, h, cx, cy-size, cx, cy+size, col);
+}
+
+// --------------------------------------------------------------------------
+//
+// Draw marker into the buffer. The TObject must be a TMarker.
+// Currently kCircle, kMultiply and KDot are supported.
+/*
+void MGImage::DrawMarker(TObject *o, UChar_t *buf, int w, int h, Double_t scale)
+{
+    TMarker *m = dynamic_cast<TMarker*>(o);
+    if (!m)
+        return;
+
+    Double_t x = 0.5*w-(m->GetX()/scale);
+    Double_t y = 0.5*h-(m->GetY()/scale);
+
+    Int_t col = Color(m->GetMarkerColor());
+
+    switch (m->GetMarkerStyle())
+    {
+    case kCircle:
+        DrawCircle(buf, w, h, x, y, m->GetMarkerSize()*2+1, col);
+        break;
+    case kDot:
+        DrawDot(buf, w, h, x, y, col);
+        break;
+    case kMultiply:
+        DrawMultiply(buf, w, h, x, y, m->GetMarkerSize()*2+1, col);
+        break;
+    case kCross:
+        DrawCross(buf, w, h, x, y, m->GetMarkerSize()*2+1, col);
+        break;
+    }
+}
+*/
Index: trunk/FACT++/drive/MGImage.h
===================================================================
--- trunk/FACT++/drive/MGImage.h	(revision 18627)
+++ trunk/FACT++/drive/MGImage.h	(revision 18628)
@@ -54,5 +54,12 @@
     void DisableSyncMode() { ResetBit(kSyncMode); }
 
-    ClassDef(MGImage, 0)
+    static UChar_t Color(int col);
+    static void    DrawCircle(UChar_t *buf, int w, int h, Float_t x, Float_t y, Float_t r, UChar_t col);
+    static void    DrawHexagon(UChar_t *buf, int w, int h, Float_t x, Float_t y, Float_t r, UChar_t col, Int_t style=1);
+    static void    DrawLine(UChar_t *buf, int w, int h, Float_t x1, Float_t y1, Float_t x2, Float_t y2, UChar_t col, Int_t style=1);
+    static void    DrawBox(UChar_t *buf, int w, int h, Float_t x1, Float_t y1, Float_t x2, Float_t y2, UChar_t col, Int_t style=1);
+    static void    DrawDot(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, UChar_t col);
+    static void    DrawMultiply(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, Float_t size, UChar_t col);
+    static void    DrawCross(UChar_t *buf, int w, int h, Float_t cx, Float_t cy, Float_t size, UChar_t col);
 };
 
