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

Last change on this file since 2385 was 2384, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 4.0 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 cout << "Detected Color Depth: " << gVirtualX->GetDepth() << endl;
56}
57
58MGImage::~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
73void 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
86void MGImage::DrawImg32(char *d, char *s, char *e)
87{
88 // d=destination, s=source, e=end
89 while (s<e)
90 {
91 *d++ = *s;
92 *d++ = *s;
93 *d++ = *s++;
94 d++;
95 }
96}
97
98void MGImage::DrawColImg32(char *d, char *s1, char *s2, char *e)
99{
100 // d=destination, s1=source1, s2=source2, e=end
101 while (s1<e)
102 {
103 if (*s2)
104 {
105 *d++ = ((*s2>>4)&0x3)*85;
106 *d++ = ((*s2>>2)&0x3)*85;
107 *d++ = ((*s2++ )&0x3)*85;
108 d++;
109 s1++;
110 }
111 else
112 {
113 *d++ = *s1;
114 *d++ = *s1;
115 *d++ = *s1++;
116 d++;
117 s2++;
118 }
119 }
120}
121
122void MGImage::DrawImg(const byte *buffer)
123{
124 if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
125 return;
126
127 switch (gVirtualX->GetDepth())
128 {
129 case 32:
130 DrawImg32(fImage->data, (char*)buffer, (char*)(buffer+fWidth*fHeight));
131 break;
132 default:
133 cout << "Sorry, " << gVirtualX->GetDepth() << "bit color depth not yet implemented." << endl;
134 }
135
136 SetBit(kNeedRedraw);
137
138 pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
139}
140
141void MGImage::DrawColImg(const byte *gbuf, const byte *cbuf)
142{
143 if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
144 return;
145
146 // FROM libAfterImage:
147 // -------------------
148 //#define ALPHA_TRANSPARENT 0x00
149 //#define ALPHA_SEMI_TRANSPARENT 0x7F
150 //#define ALPHA_SOLID 0xFF
151 // * Lowermost 8 bits - Blue channel
152 // * bits 8 to 15 - Green channel
153 // * bits 16 to 23 - Red channel
154 // * bits 24 to 31 - Alpha channel
155 //#define ARGB32_White 0xFFFFFFFF
156 //#define ARGB32_Black 0xFF000000
157
158 // FIXME: This loop depends on the screen color depth
159 switch (gVirtualX->GetDepth())
160 {
161 case 32:
162 DrawColImg32(fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight));
163 break;
164 default:
165 cout << "Sorry, " << gVirtualX->GetDepth() << "bit color depth not yet implemented." << endl;
166 }
167
168 SetBit(kNeedRedraw);
169
170 pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
171}
Note: See TracBrowser for help on using the repository browser.