Re: [ROOT] gVirtualX->PutImage and TCanvas

From: Thomas Bretz (Thomas_Bretz@ph.tum.de)
Date: Mon May 03 2004 - 22:35:37 MEST


Hi,

sorry, I don't know what happened. I hope this time they are complete.

Thomas.

On
Mon, 3 May 2004, Valeriy Onuchin wrote:

> Hi Thomas,
> two files in attachment are empty.
> 
> Regards. Valeriy
> 
> ----- Original Message ----- 
> From: "Thomas Bretz" <Thomas_Bretz@ph.tum.de>
> To: <roottalk@pcroot.cern.ch>
> Sent: Monday, May 03, 2004 6:45 PM
> Subject: [ROOT] gVirtualX->PutImage and TCanvas
> 
> 
> > Hi,
> > 
> > with the (very simple) attached class I try to display a gray scaled
> > bitmap in a canvas. It doesn't work. Can somebody explain me, what I'm
> > doing wrong?
> > 
> > (I'm developing this class, because I need a really fast access to the
> > screen - 25fps - which I think I won't get with the big overgead of
> > TASImage)
> > 
> > Thanks in advance,
> > Thomas.
> > 
> > 
> 
> 
> --------------------------------------------------------------------------------
> 
> 
> > void test()
> > {
> >     TCanvas *c=new TCanvas;
> > 
> >     MImage2 *i = new MImage2(100, 100);
> > 
> >     byte buf[100*100];
> > 
> >     for (int j=0; j<100*100; j++)
> >         buf[j]=j;
> > 
> >     i->DrawImg(buf);
> >     i->Draw();
> > }
> > 
> 

-----
Würden Sie Windows 95 die Kontrolle eines AKWs überlassen? 
Hiroshima '45...! Tschernobyl '86...!! Windows 95...!!! 
Unix ist benutzerfreundlich - es ist nur etwas wählerisch..." (Walter Misar) 
Was sagt ein arbeitsloser Physiker zu einem Physiker mit Arbeit?
 - "Eine Currywurst mit Pommes bitte!" 


#include "MImage2.h"

#include <iostream>

#include <TGX11.h>

ClassImp(MImage2);

using namespace std;

MImage2::MImage2(UInt_t w, UInt_t h)
    : fId(gClient->GetRoot()->GetId()), fWidth(w), fHeight(h)
{
    // p = pointer to MainFrame (not owner)
    // w = width of frame
    // h = width of frame

    fDefGC  = gVirtualX->CreateGC(fId, 0);
    fImage  = (XImage*)gVirtualX->CreateImage(fWidth, fHeight);

    cout << "Detected Color Depth: " << gVirtualX->GetDepth() << endl;
    if (gVirtualX->GetDepth()!=24)
        cout << "WARNING this class only works with 24bit color depth!" << endl;
}

MImage2::~MImage2()
{
    gVirtualX->DeleteGC(fDefGC);
    gVirtualX->DeleteImage((Drawable_t)fImage);
}

void MImage2::Paint(Option_t *o)
{
    gVirtualX->PutImage(fId, fDefGC, (Drawable_t)fImage, 0, 0, 0, 0, fWidth, fHeight);
}

void MImage2::DrawImg24(char *d, char *s, char *e)
{
    // d=destination, s=source, e=end
    // rrrrrrrr gggggggg bbbbbbbb aaaaaaaa
    //
    while (s<e)
    {
        *d++ = *s;
        *d++ = *s;
        *d++ = *s++;
        d++;
    }
}

void MImage2::DrawImg(const byte *buffer)
{
    DrawImg24(fImage->data, (char*)buffer, (char*)(buffer+fWidth*fHeight));
}

#ifndef COSY_MImage2
#define COSY_MImage2

#ifndef ROOT_TGFrame
#include <TGFrame.h>
#endif
#ifndef ROOT_TGX11
#include <TGX11.h>
#endif

typedef unsigned char byte;

class MImage2 : public TObject
{
    XImage *fImage;

    GContext_t fDefGC;

    Int_t  fId;
    UInt_t fWidth;
    UInt_t fHeight;

    void DrawImg24(char *d, char *s, char *e);

public:
    MImage2(UInt_t w, UInt_t h);
    ~MImage2();

    void Paint(Option_t *o);

    void DrawImg(const byte *buffer);

    ClassDef(MImage2, 0)
};

#endif // MGIMAGE_H



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:07 MET