| 1 | #include "picmapmac.h"
 | 
|---|
| 2 | #include <UDebugging.h>
 | 
|---|
| 3 | 
 | 
|---|
| 4 | static int NTotAllocCol;
 | 
|---|
| 5 | 
 | 
|---|
| 6 | 
 | 
|---|
| 7 | PIColorMapMac::PIColorMapMac()
 | 
|---|
| 8 | : PIColorMapGen(), mPalette(NULL), mCTab(NULL)
 | 
|---|
| 9 | {
 | 
|---|
| 10 | }
 | 
|---|
| 11 | 
 | 
|---|
| 12 | PIColorMapMac::PIColorMapMac(int id, int nc, string const& nom) 
 | 
|---|
| 13 | : PIColorMapGen(id, nc, nom)
 | 
|---|
| 14 | {
 | 
|---|
| 15 |     int n = nc+2;
 | 
|---|
| 16 |         mCTab = (CTabHandle) ::NewHandle(sizeof(long) + 
 | 
|---|
| 17 |                                 sizeof(short) + sizeof(short) + 
 | 
|---|
| 18 |                                 n*sizeof(ColorSpec));
 | 
|---|
| 19 |         (**mCTab).ctFlags = 0;
 | 
|---|
| 20 |         (**mCTab).ctSeed = GetCTSeed();
 | 
|---|
| 21 |         (**mCTab).ctSize = n;
 | 
|---|
| 22 |     ColorSpec* sp = (**mCTab).ctTable;
 | 
|---|
| 23 |     sp[0].rgb.red   = 0;
 | 
|---|
| 24 |     sp[0].rgb.green = 0;
 | 
|---|
| 25 |     sp[0].rgb.blue  = 0;
 | 
|---|
| 26 |     sp[0].value     = 0;
 | 
|---|
| 27 |     sp[1].rgb.red   = 65535;
 | 
|---|
| 28 |     sp[1].rgb.green = 65535;
 | 
|---|
| 29 |     sp[1].rgb.blue  = 65535;
 | 
|---|
| 30 |     sp[1].value     = 1;
 | 
|---|
| 31 |     for (int i=2; i<n; i++) {
 | 
|---|
| 32 |       sp[i].rgb.red   = 0;
 | 
|---|
| 33 |       sp[i].rgb.green = 0;
 | 
|---|
| 34 |       sp[i].rgb.blue  = 0;
 | 
|---|
| 35 |       sp[i].value     = i;
 | 
|---|
| 36 |     }
 | 
|---|
| 37 |   mPalette = NewPalette(mNCol,mCTab,pmTolerant,0);
 | 
|---|
| 38 | }
 | 
|---|
| 39 | 
 | 
|---|
| 40 | PIColorMapMac::~PIColorMapMac()
 | 
|---|
| 41 | {
 | 
|---|
| 42 |   DisposePalette(mPalette);
 | 
|---|
| 43 |   DisposeHandle((Handle)mCTab);
 | 
|---|
| 44 | }
 | 
|---|
| 45 | 
 | 
|---|
| 46 | /* --Methode-- */
 | 
|---|
| 47 | PIColor PIColorMapMac::GetColor(int n)
 | 
|---|
| 48 | {
 | 
|---|
| 49 | PIColor picr;
 | 
|---|
| 50 | picr.red = picr.green = picr.blue = 0;
 | 
|---|
| 51 | 
 | 
|---|
| 52 | if ((n<0) || (n >= NCol()))   
 | 
|---|
| 53 |   return(picr);
 | 
|---|
| 54 | 
 | 
|---|
| 55 | RGBColor qdCol;
 | 
|---|
| 56 | GetEntryColor(mPalette,n+2,&qdCol);
 | 
|---|
| 57 | 
 | 
|---|
| 58 | picr.red   = qdCol.red;
 | 
|---|
| 59 | picr.green = qdCol.green;
 | 
|---|
| 60 | picr.blue  = qdCol.blue;
 | 
|---|
| 61 | 
 | 
|---|
| 62 | return(picr);
 | 
|---|
| 63 | }
 | 
|---|
| 64 | 
 | 
|---|
| 65 | 
 | 
|---|
| 66 | bool PIColorMapMac::AllocColor(PIColor const& col, int index)
 | 
|---|
| 67 | {
 | 
|---|
| 68 |   if (!mPalette) return false;
 | 
|---|
| 69 |   if ((index < 0) || (index > mNCol))  return(false);
 | 
|---|
| 70 |   
 | 
|---|
| 71 |   RGBColor srcRGB;
 | 
|---|
| 72 |   srcRGB.red   = col.red;
 | 
|---|
| 73 |   srcRGB.green = col.green;
 | 
|---|
| 74 |   srcRGB.blue  = col.blue;
 | 
|---|
| 75 |   
 | 
|---|
| 76 |   SetEntryColor(mPalette,index+2,&srcRGB);
 | 
|---|
| 77 |   ((**mCTab).ctTable)[index+2].rgb = srcRGB;
 | 
|---|
| 78 |   NTotAllocCol++;
 | 
|---|
| 79 |   return true;    //  $CHECK$  retourne true si OK - Reza 01/12/97
 | 
|---|
| 80 | }
 | 
|---|
| 81 | 
 | 
|---|
| 82 | long PIColorMapMac::TotNbColors()
 | 
|---|
| 83 | {
 | 
|---|
| 84 |    PixMapHandle pmh = ((CGrafPort*)qd.thePort)->portPixMap;
 | 
|---|
| 85 |    int depth = (**pmh).cmpSize * (**pmh).cmpCount;
 | 
|---|
| 86 |    long nbcol = 1;
 | 
|---|
| 87 |    for (int i=0; i<depth; i++)
 | 
|---|
| 88 |      nbcol *= 2;
 | 
|---|
| 89 |    return nbcol;
 | 
|---|
| 90 | }
 | 
|---|
| 91 | 
 | 
|---|
| 92 | void PIColorMapMac::FreeColors()
 | 
|---|
| 93 | {
 | 
|---|
| 94 |   Assert_(mPalette);
 | 
|---|
| 95 |   DisposePalette(mPalette);
 | 
|---|
| 96 |   DisposeCTable(mCTab);
 | 
|---|
| 97 | }
 | 
|---|
| 98 | 
 | 
|---|
| 99 | int PIColorMapMac::NbAllocColors()
 | 
|---|
| 100 | {
 | 
|---|
| 101 | return(NTotAllocCol);
 | 
|---|
| 102 | }
 | 
|---|
| 103 | 
 | 
|---|
| 104 | 
 | 
|---|
| 105 | void PIColorMapMac::CopyFrom(PIColorMapGen* x)
 | 
|---|
| 106 | {
 | 
|---|
| 107 |   CopyFromGen(x);
 | 
|---|
| 108 |   PIColorMapMac* y = (PIColorMapMac*) x;
 | 
|---|
| 109 |   mPalette = y->mPalette;
 | 
|---|
| 110 |   mCTab = y->mCTab;
 | 
|---|
| 111 |   HandToHand(&(Handle)mCTab);
 | 
|---|
| 112 |   HandToHand(&(Handle)mPalette);
 | 
|---|
| 113 |   Assert_(mPalette);
 | 
|---|
| 114 | }
 | 
|---|