Changeset 2518 for trunk/MagicSoft/Cosy/gui/MGImage.cc
- Timestamp:
- 11/17/03 13:50:48 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/gui/MGImage.cc
r2514 r2518 9 9 #include "MGImage.h" 10 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> 11 #include <iostream> 12 19 13 #include <TGX11.h> 14 #include <TMutex.h> 20 15 21 16 ClassImp(MGImage); 17 18 using namespace std; 22 19 /* 23 20 class MyX11 : public TGX11 … … 41 38 // Creat drawing semaphore 42 39 // 43 fMuxPixmap = new pthread_mutex_t; 44 pthread_mutex_init((pthread_mutex_t*)fMuxPixmap, NULL); 40 fMuxPixmap = new TMutex; 45 41 46 42 Resize(w, h); … … 58 54 MGImage::~MGImage() 59 55 { 60 pthread_mutex_lock((pthread_mutex_t*)fMuxPixmap);56 fMuxPixmap->Lock(); 61 57 62 58 cout << "Deleting MGImage..." << endl; … … 66 62 gVirtualX->DeleteImage((Drawable_t)fImage); 67 63 68 pthread_mutex_destroy((pthread_mutex_t*)fMuxPixmap);64 delete fMuxPixmap; 69 65 70 66 cout << "MGImage destroyed." << endl; … … 73 69 void MGImage::DoRedraw() 74 70 { 75 pthread_mutex_lock((pthread_mutex_t*)fMuxPixmap);71 fMuxPixmap->Lock(); 76 72 77 73 if (TestBit(kNeedRedraw)) … … 81 77 } 82 78 83 pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);79 fMuxPixmap->UnLock(); 84 80 } 85 81 … … 91 87 while (s<e) 92 88 { 89 // 11111100 11111000 11111100 93 90 *d++ = (*s&0xfc) | (*s&0xf8)<<5 | (*s&0xfc)<<11; 94 91 s++; … … 107 104 *d++ = *s++; 108 105 d++; 106 } 107 } 108 109 void MGImage::DrawImg(const byte *buffer) 110 { 111 if (fMuxPixmap->TryLock()==13) 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 134 void 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 } 109 154 } 110 155 } … … 134 179 } 135 180 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 24:150 DrawImg24(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 181 void MGImage::DrawColImg(const byte *gbuf, const byte *cbuf) 162 182 { 163 if ( pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))183 if (fMuxPixmap->TryLock()==13) 164 184 return; 165 185 … … 179 199 switch (gVirtualX->GetDepth()) 180 200 { 201 case 16: 202 DrawColImg16((unsigned short*)fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight)); 203 break; 181 204 case 24: 182 DrawColImg 32(fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight));205 DrawColImg24(fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight)); 183 206 break; 184 207 default: … … 188 211 SetBit(kNeedRedraw); 189 212 190 pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);191 } 213 fMuxPixmap->UnLock(); 214 }
Note:
See TracChangeset
for help on using the changeset viewer.