Ignore:
Timestamp:
11/17/03 13:50:48 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Cosy/gui/MGImage.cc

    r2514 r2518  
    99#include "MGImage.h"
    1010
    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
    1913#include <TGX11.h>
     14#include <TMutex.h>
    2015
    2116ClassImp(MGImage);
     17
     18using namespace std;
    2219/*
    2320class MyX11 : public TGX11
     
    4138    // Creat drawing semaphore
    4239    //
    43     fMuxPixmap = new pthread_mutex_t;
    44     pthread_mutex_init((pthread_mutex_t*)fMuxPixmap, NULL);
     40    fMuxPixmap = new TMutex;
    4541
    4642    Resize(w, h);
     
    5854MGImage::~MGImage()
    5955{
    60     pthread_mutex_lock((pthread_mutex_t*)fMuxPixmap);
     56    fMuxPixmap->Lock();
    6157
    6258    cout << "Deleting MGImage..." << endl;
     
    6662    gVirtualX->DeleteImage((Drawable_t)fImage);
    6763
    68     pthread_mutex_destroy((pthread_mutex_t*)fMuxPixmap);
     64    delete fMuxPixmap;
    6965
    7066    cout << "MGImage destroyed." << endl;
     
    7369void MGImage::DoRedraw()
    7470{
    75     pthread_mutex_lock((pthread_mutex_t*)fMuxPixmap);
     71    fMuxPixmap->Lock();
    7672
    7773    if (TestBit(kNeedRedraw))
     
    8177    }
    8278
    83     pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
     79    fMuxPixmap->UnLock();
    8480}
    8581
     
    9187    while (s<e)
    9288    {
     89        //      11111100    11111000      11111100
    9390        *d++ = (*s&0xfc) | (*s&0xf8)<<5 | (*s&0xfc)<<11;
    9491        s++;
     
    107104        *d++ = *s++;
    108105        d++;
     106    }
     107}
     108
     109void 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
     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        }
    109154    }
    110155}
     
    134179}
    135180
    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 
    161181void MGImage::DrawColImg(const byte *gbuf, const byte *cbuf)
    162182{
    163     if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
     183    if (fMuxPixmap->TryLock()==13)
    164184        return;
    165185
     
    179199    switch (gVirtualX->GetDepth())
    180200    {
     201    case 16:
     202        DrawColImg16((unsigned short*)fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight));
     203        break;
    181204    case 24:
    182         DrawColImg32(fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight));
     205        DrawColImg24(fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight));
    183206        break;
    184207    default:
     
    188211    SetBit(kNeedRedraw);
    189212
    190     pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
    191 }
     213    fMuxPixmap->UnLock();
     214}
Note: See TracChangeset for help on using the changeset viewer.