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

Last change on this file since 3848 was 2613, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.8 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>
12
13#include <TGX11.h>
14#include <TMutex.h>
15
16ClassImp(MGImage);
17
18using namespace std;
19/*
20class MyX11 : public TGX11
21{
22public:
23 Display *GetDisplay() { return fDisplay; }
24 Drawable GetRootWin() { return fRootWin; }
25 Drawable GetVisRootWin() { return fVisRootWin; }
26 Int_t GetDepth() { return fDepth; }
27};
28*/
29
30MGImage::MGImage(const TGWindow* p, UInt_t w, UInt_t h, UInt_t options, ULong_t back)
31 : TGFrame(p, w, h, options, back), fWidth(w), fHeight(h)
32{
33 // p = pointer to MainFrame (not owner)
34 // w = width of frame
35 // h = width of frame
36
37 //
38 // Creat drawing semaphore
39 //
40 fMuxPixmap = new TMutex;
41
42 Resize(w, h);
43
44 //
45 // create empty pixmap
46 //
47 fPixmap = gVirtualX->CreatePixmap(fId, fWidth, fHeight);
48 fDefGC = gVirtualX->CreateGC(fId, 0);
49 fImage = (XImage*)gVirtualX->CreateImage(fWidth, fHeight);
50
51 cout << "Detected Color Depth: " << gVirtualX->GetDepth() << endl;
52}
53
54MGImage::~MGImage()
55{
56 fMuxPixmap->Lock();
57
58 cout << "Deleting MGImage..." << endl;
59
60 gVirtualX->DeletePixmap(fPixmap);
61 gVirtualX->DeleteGC(fDefGC);
62 gVirtualX->DeleteImage((Drawable_t)fImage);
63
64 delete fMuxPixmap;
65
66 cout << "MGImage destroyed." << endl;
67}
68
69void MGImage::DoRedraw()
70{
71 fMuxPixmap->Lock();
72
73 if (TestBit(kNeedRedraw))
74 {
75 gVirtualX->PutImage(fId, fDefGC, (Drawable_t)fImage, 0, 0, 0, 0, fWidth, fHeight);
76 ResetBit(kNeedRedraw);
77 }
78
79 fMuxPixmap->UnLock();
80}
81
82void MGImage::DrawImg16(unsigned short *d, char *s, char *e)
83{
84 // d=destination, s=source, e=end
85 // rrrrrggg gggbbbbb
86 //
87 while (s<e)
88 {
89 // 11111100 11111000 11111000
90 *d++ = (*s&0xfc) | (*s&0xf8)<<5 | (*s&0xf8)<<11;
91 s++;
92 }
93}
94
95void MGImage::DrawImg24(char *d, char *s, char *e)
96{
97 // d=destination, s=source, e=end
98 // rrrrrrrr gggggggg bbbbbbbb aaaaaaaa
99 //
100 while (s<e)
101 {
102 *d++ = *s;
103 *d++ = *s;
104 *d++ = *s++;
105 d++;
106 }
107}
108
109void MGImage::DrawImg(const byte *buffer)
110{
111 if (fMuxPixmap->TryLock())
112 return;
113
114 switch (gVirtualX->GetDepth())
115 {
116 case 8:
117 memcpy(fImage->data, buffer, fWidth*fHeight);
118 break;
119 case 16:
120 DrawImg16((unsigned short*)fImage->data, (char*)buffer, (char*)(buffer+fWidth*fHeight));
121 break;
122 case 24:
123 DrawImg24(fImage->data, (char*)buffer, (char*)(buffer+fWidth*fHeight));
124 break;
125 default:
126 cout << "Sorry, " << gVirtualX->GetDepth() << "bit color depth not yet implemented." << endl;
127 }
128
129 SetBit(kNeedRedraw);
130
131 fMuxPixmap->UnLock();
132}
133
134void MGImage::DrawColImg16(unsigned short *d, char *s1, char *s2, char *e)
135{
136 // d=destination, s1=source1, s2=source2, e=end
137 // d: rrrrrggg gggbbbbb
138 // s2: 00rrggbb
139 //
140 while (s1<e)
141 {
142 if (*s2)
143 {
144 // 00000011 00001100 00110000
145 *d++ = (*s2&0x3) | (*s2&0xb)<<3 | (*s2&0x30)<<7;
146 s1++;
147 }
148 else
149 {
150 // 11111100 11111000 11111100
151 *d++ = (*s1&0xfc) | (*s1&0xf8)<<5 | (*s1&0xfc)<<11;
152 s2++;
153 }
154 }
155}
156
157void MGImage::DrawColImg24(char *d, char *s1, char *s2, char *e)
158{
159 // d=destination, s1=source1, s2=source2, e=end
160 while (s1<e)
161 {
162 if (*s2)
163 {
164 *d++ = ((*s2>>4)&0x3)*85;
165 *d++ = ((*s2>>2)&0x3)*85;
166 *d++ = ((*s2++ )&0x3)*85;
167 d++;
168 s1++;
169 }
170 else
171 {
172 *d++ = *s1;
173 *d++ = *s1;
174 *d++ = *s1++;
175 d++;
176 s2++;
177 }
178 }
179}
180
181void MGImage::DrawColImg(const byte *gbuf, const byte *cbuf)
182{
183 if (fMuxPixmap->TryLock())
184 return;
185
186 // FROM libAfterImage:
187 // -------------------
188 //#define ALPHA_TRANSPARENT 0x00
189 //#define ALPHA_SEMI_TRANSPARENT 0x7F
190 //#define ALPHA_SOLID 0xFF
191 // * Lowermost 8 bits - Blue channel
192 // * bits 8 to 15 - Green channel
193 // * bits 16 to 23 - Red channel
194 // * bits 24 to 31 - Alpha channel
195 //#define ARGB32_White 0xFFFFFFFF
196 //#define ARGB32_Black 0xFF000000
197
198 // FIXME: This loop depends on the screen color depth
199 switch (gVirtualX->GetDepth())
200 {
201 case 16:
202 DrawColImg16((unsigned short*)fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight));
203 break;
204 case 24:
205 DrawColImg24(fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight));
206 break;
207 default:
208 cout << "Sorry, " << gVirtualX->GetDepth() << "bit color depth not yet implemented." << endl;
209 }
210
211 SetBit(kNeedRedraw);
212
213 fMuxPixmap->UnLock();
214}
Note: See TracBrowser for help on using the repository browser.