source: trunk/MagicSoft/Cosy/gui/MGImage.cc@ 2325

Last change on this file since 2325 was 2278, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 3.4 KB
Line 
1//
2// This File contains the definition of the MGImage-class
3//
4// Author: Thomas Bretz
5// Version: V1.0 (1-8-2000)
6//
7// x11/src/GX11Gui.cxx
8//
9#include "MGImage.h"
10
11#include <iostream.h>
12#include <pthread.h>
13
14#include <X11/Xlib.h>
15
16#include <TTimer.h>
17#include <TSystem.h>
18#include <TVirtualX.h>
19#include <TGX11.h>
20
21ClassImp(MGImage);
22/*
23class MyX11 : public TGX11
24{
25public:
26 Display *GetDisplay() { return fDisplay; }
27 Drawable GetRootWin() { return fRootWin; }
28 Drawable GetVisRootWin() { return fVisRootWin; }
29 Int_t GetDepth() { return fDepth; }
30};
31*/
32
33MGImage::MGImage(const TGWindow* p, UInt_t w, UInt_t h, UInt_t options, ULong_t back)
34 : TGFrame(p, w, h, options, back), fWidth(w), fHeight(h)
35{
36 // p = pointer to MainFrame (not owner)
37 // w = width of frame
38 // h = width of frame
39
40 //
41 // Creat drawing semaphore
42 //
43 fMuxPixmap = new pthread_mutex_t;
44 pthread_mutex_init((pthread_mutex_t*)fMuxPixmap, NULL);
45
46 Resize(w, h);
47
48 //
49 // create empty pixmap
50 //
51 fPixmap = gVirtualX->CreatePixmap(fId, fWidth, fHeight);
52 fDefGC = gVirtualX->CreateGC(fId, 0);
53 fImage = (XImage*)gVirtualX->CreateImage(fWidth, fHeight);
54}
55
56MGImage::~MGImage()
57{
58 pthread_mutex_lock((pthread_mutex_t*)fMuxPixmap);
59
60 cout << "Deleting MGImage..." << endl;
61
62 gVirtualX->DeletePixmap(fPixmap);
63 gVirtualX->DeleteGC(fDefGC);
64 gVirtualX->DeleteImage((Drawable_t)fImage);
65
66 pthread_mutex_destroy((pthread_mutex_t*)fMuxPixmap);
67
68 cout << "MGImage destroyed." << endl;
69}
70
71void MGImage::DoRedraw()
72{
73 pthread_mutex_lock((pthread_mutex_t*)fMuxPixmap);
74
75 if (TestBit(kNeedRedraw))
76 {
77 gVirtualX->PutImage(fId, fDefGC, (Drawable_t)fImage, 0, 0, 0, 0, fWidth, fHeight);
78 ResetBit(kNeedRedraw);
79 }
80
81 pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
82}
83
84void MGImage::DrawImg(const byte *buffer)
85{
86 if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
87 return;
88
89 char *d = fImage->data;
90 char *e = (char*)(buffer+fWidth*fHeight);
91 char *s = (char*)buffer;
92
93 // FIXME: This loop depends on the screen color depth
94 while (s<e)
95 {
96 *d++ = *s;
97 *d++ = *s;
98 *d++ = *s++;
99 d++;
100 }
101
102 SetBit(kNeedRedraw);
103
104 pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
105}
106
107void MGImage::DrawColImg(const byte *gbuf, const byte *cbuf)
108{
109 if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
110 return;
111
112 char *d = fImage->data;
113 char *e = (char*)(gbuf+fWidth*fHeight);
114 char *s1 = (char*)gbuf;
115 char *s2 = (char*)cbuf;
116
117 // FROM libAfterImage:
118 // -------------------
119 //#define ALPHA_TRANSPARENT 0x00
120 //#define ALPHA_SEMI_TRANSPARENT 0x7F
121 //#define ALPHA_SOLID 0xFF
122 // * Lowermost 8 bits - Blue channel
123 // * bits 8 to 15 - Green channel
124 // * bits 16 to 23 - Red channel
125 // * bits 24 to 31 - Alpha channel
126 //#define ARGB32_White 0xFFFFFFFF
127 //#define ARGB32_Black 0xFF000000
128
129 // FIXME: This loop depends on the screen color depth
130 while (s1<e)
131 {
132 if (*s2)
133 {
134 *d++ = ((*s2>>4)&0x3)*85;
135 *d++ = ((*s2>>2)&0x3)*85;
136 *d++ = ((*s2++ )&0x3)*85;
137 d++;
138 s1++;
139 }
140 else
141 {
142 *d++ = *s1;
143 *d++ = *s1;
144 *d++ = *s1++;
145 d++;
146 s2++;
147 }
148 }
149
150 SetBit(kNeedRedraw);
151
152 pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
153}
Note: See TracBrowser for help on using the repository browser.