source: Sophya/branches/EA_Juin98/SophyaPI/PI/picmapmac.cc@ 1036

Last change on this file since 1036 was 69, checked in by aubourg, 28 years ago

Pour mac

File size: 2.3 KB
Line 
1#include "picmapmac.h"
2#include <UDebugging.h>
3
4static int NTotAllocCol;
5
6
7PIColorMapMac::PIColorMapMac()
8: PIColorMapGen(), mPalette(NULL), mCTab(NULL)
9{
10}
11
12PIColorMapMac::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
40PIColorMapMac::~PIColorMapMac()
41{
42 DisposePalette(mPalette);
43 DisposeHandle((Handle)mCTab);
44}
45
46/* --Methode-- */
47PIColor PIColorMapMac::GetColor(int n)
48{
49PIColor picr;
50picr.red = picr.green = picr.blue = 0;
51
52if ((n<0) || (n >= NCol()))
53 return(picr);
54
55RGBColor qdCol;
56GetEntryColor(mPalette,n+2,&qdCol);
57
58picr.red = qdCol.red;
59picr.green = qdCol.green;
60picr.blue = qdCol.blue;
61
62return(picr);
63}
64
65
66bool 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
82long 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
92void PIColorMapMac::FreeColors()
93{
94 Assert_(mPalette);
95 DisposePalette(mPalette);
96 DisposeCTable(mCTab);
97}
98
99int PIColorMapMac::NbAllocColors()
100{
101return(NTotAllocCol);
102}
103
104
105void 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}
Note: See TracBrowser for help on using the repository browser.