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 |
|
---|
21 | ClassImp(MGImage);
|
---|
22 | /*
|
---|
23 | class MyX11 : public TGX11
|
---|
24 | {
|
---|
25 | public:
|
---|
26 | Display *GetDisplay() { return fDisplay; }
|
---|
27 | Drawable GetRootWin() { return fRootWin; }
|
---|
28 | Drawable GetVisRootWin() { return fVisRootWin; }
|
---|
29 | Int_t GetDepth() { return fDepth; }
|
---|
30 | };
|
---|
31 | */
|
---|
32 |
|
---|
33 | MGImage::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 | cout << "Detected Color Depth: " << gVirtualX->GetDepth() << endl;
|
---|
56 | }
|
---|
57 |
|
---|
58 | MGImage::~MGImage()
|
---|
59 | {
|
---|
60 | pthread_mutex_lock((pthread_mutex_t*)fMuxPixmap);
|
---|
61 |
|
---|
62 | cout << "Deleting MGImage..." << endl;
|
---|
63 |
|
---|
64 | gVirtualX->DeletePixmap(fPixmap);
|
---|
65 | gVirtualX->DeleteGC(fDefGC);
|
---|
66 | gVirtualX->DeleteImage((Drawable_t)fImage);
|
---|
67 |
|
---|
68 | pthread_mutex_destroy((pthread_mutex_t*)fMuxPixmap);
|
---|
69 |
|
---|
70 | cout << "MGImage destroyed." << endl;
|
---|
71 | }
|
---|
72 |
|
---|
73 | void MGImage::DoRedraw()
|
---|
74 | {
|
---|
75 | pthread_mutex_lock((pthread_mutex_t*)fMuxPixmap);
|
---|
76 |
|
---|
77 | if (TestBit(kNeedRedraw))
|
---|
78 | {
|
---|
79 | gVirtualX->PutImage(fId, fDefGC, (Drawable_t)fImage, 0, 0, 0, 0, fWidth, fHeight);
|
---|
80 | ResetBit(kNeedRedraw);
|
---|
81 | }
|
---|
82 |
|
---|
83 | pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
|
---|
84 | }
|
---|
85 |
|
---|
86 | void MGImage::DrawImg16(unsigned short *d, char *s, char *e)
|
---|
87 | {
|
---|
88 | // d=destination, s=source, e=end
|
---|
89 | // rrrrrggg gggbbbbb
|
---|
90 | //
|
---|
91 | while (s<e)
|
---|
92 | {
|
---|
93 | *d++ = (*s&0xfc) | (*s&0xf8)<<5 | (*s&0xfc)<<11;
|
---|
94 | s++;
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | void MGImage::DrawImg32(char *d, char *s, char *e)
|
---|
99 | {
|
---|
100 | // d=destination, s=source, e=end
|
---|
101 | // rrrrrrrr gggggggg bbbbbbbb aaaaaaaa
|
---|
102 | //
|
---|
103 | while (s<e)
|
---|
104 | {
|
---|
105 | *d++ = *s;
|
---|
106 | *d++ = *s;
|
---|
107 | *d++ = *s++;
|
---|
108 | d++;
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | void MGImage::DrawColImg32(char *d, char *s1, char *s2, char *e)
|
---|
113 | {
|
---|
114 | // d=destination, s1=source1, s2=source2, e=end
|
---|
115 | while (s1<e)
|
---|
116 | {
|
---|
117 | if (*s2)
|
---|
118 | {
|
---|
119 | *d++ = ((*s2>>4)&0x3)*85;
|
---|
120 | *d++ = ((*s2>>2)&0x3)*85;
|
---|
121 | *d++ = ((*s2++ )&0x3)*85;
|
---|
122 | d++;
|
---|
123 | s1++;
|
---|
124 | }
|
---|
125 | else
|
---|
126 | {
|
---|
127 | *d++ = *s1;
|
---|
128 | *d++ = *s1;
|
---|
129 | *d++ = *s1++;
|
---|
130 | d++;
|
---|
131 | s2++;
|
---|
132 | }
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | void MGImage::DrawImg(const byte *buffer)
|
---|
137 | {
|
---|
138 | if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
|
---|
139 | return;
|
---|
140 |
|
---|
141 | switch (gVirtualX->GetDepth())
|
---|
142 | {
|
---|
143 | case 8:
|
---|
144 | memcpy(fImage->data, buffer, fWidth*fHeight);
|
---|
145 | break;
|
---|
146 | case 16:
|
---|
147 | DrawImg16((unsigned short*)fImage->data, (char*)buffer, (char*)(buffer+fWidth*fHeight));
|
---|
148 | break;
|
---|
149 | case 32:
|
---|
150 | DrawImg32(fImage->data, (char*)buffer, (char*)(buffer+fWidth*fHeight));
|
---|
151 | break;
|
---|
152 | default:
|
---|
153 | cout << "Sorry, " << gVirtualX->GetDepth() << "bit color depth not yet implemented." << endl;
|
---|
154 | }
|
---|
155 |
|
---|
156 | SetBit(kNeedRedraw);
|
---|
157 |
|
---|
158 | pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
|
---|
159 | }
|
---|
160 |
|
---|
161 | void MGImage::DrawColImg(const byte *gbuf, const byte *cbuf)
|
---|
162 | {
|
---|
163 | if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
|
---|
164 | return;
|
---|
165 |
|
---|
166 | // FROM libAfterImage:
|
---|
167 | // -------------------
|
---|
168 | //#define ALPHA_TRANSPARENT 0x00
|
---|
169 | //#define ALPHA_SEMI_TRANSPARENT 0x7F
|
---|
170 | //#define ALPHA_SOLID 0xFF
|
---|
171 | // * Lowermost 8 bits - Blue channel
|
---|
172 | // * bits 8 to 15 - Green channel
|
---|
173 | // * bits 16 to 23 - Red channel
|
---|
174 | // * bits 24 to 31 - Alpha channel
|
---|
175 | //#define ARGB32_White 0xFFFFFFFF
|
---|
176 | //#define ARGB32_Black 0xFF000000
|
---|
177 |
|
---|
178 | // FIXME: This loop depends on the screen color depth
|
---|
179 | switch (gVirtualX->GetDepth())
|
---|
180 | {
|
---|
181 | case 32:
|
---|
182 | DrawColImg32(fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight));
|
---|
183 | break;
|
---|
184 | default:
|
---|
185 | cout << "Sorry, " << gVirtualX->GetDepth() << "bit color depth not yet implemented." << endl;
|
---|
186 | }
|
---|
187 |
|
---|
188 | SetBit(kNeedRedraw);
|
---|
189 |
|
---|
190 | pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
|
---|
191 | }
|
---|