[658] | 1 | // Module PI : Peida Interactive PIColorMap
|
---|
| 2 | // Gestion de table de couleurs 96
|
---|
| 3 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
| 4 |
|
---|
| 5 | #include "picmap.h"
|
---|
| 6 |
|
---|
| 7 | //++
|
---|
| 8 | // Class PIColorMap
|
---|
| 9 | // Lib PI
|
---|
| 10 | // include picmap.h
|
---|
| 11 | //
|
---|
| 12 | // Classe fournissant les services de gestion des tables de couleur.
|
---|
| 13 | // Une hiérachie un peu complexe a été mise en place pour
|
---|
| 14 | // l'implémentation des tables de couleurs pour chaque système
|
---|
| 15 | // (Mac, XWindow, ...) :
|
---|
| 16 | //| PIColorMapGen ----- PIColorMapX (=PIColorMapNative)
|
---|
| 17 | //| |-- PIColorMapMac (=PIColorMapNative)
|
---|
| 18 | // et la gestion de table de couleurs standard partagée.
|
---|
| 19 | //| PIColorMapNative (=X,Mac,...) ----- PIColorMap.
|
---|
| 20 | // La seule classe à utiliser est *PIColorMap* qui fournit
|
---|
| 21 | // l'ensemble des services de gestion de table de couleurs.
|
---|
| 22 | //--
|
---|
| 23 |
|
---|
| 24 | #define MXMAPIDS 10
|
---|
| 25 | static int MapNCols[MXMAPIDS] = {256, 256, 256, 256, 256, 256, 256, 256, 256, 256};
|
---|
| 26 | static const char* MapNoms[MXMAPIDS] = {"Grey32","InvGrey32","ColRJ32","ColBR32",
|
---|
| 27 | "ColRV32", "Grey128", "InvGrey128", "ColRJ128",
|
---|
| 28 | "ColBR128", "Col16"};
|
---|
| 29 | static CMapId MapIds[MXMAPIDS] = { CMAP_GREY32, CMAP_GREYINV32, CMAP_COLRJ32,
|
---|
| 30 | CMAP_COLBR32, CMAP_COLRV32, CMAP_GREY128,
|
---|
| 31 | CMAP_GREYINV128, CMAP_COLRJ128, CMAP_COLBR128,
|
---|
| 32 | CMAP_COL16 } ;
|
---|
| 33 |
|
---|
| 34 | static int mColTNums[8192]; // Max 8192 tables differentes pour le moment
|
---|
| 35 | static int CTNum = 0; // Numero des tables ds mColTNum - s'incremente a chaque creation
|
---|
| 36 |
|
---|
| 37 | static int NMaxTableAuto = 0;
|
---|
| 38 | static PIColorMap* mMaps[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL };
|
---|
| 39 |
|
---|
| 40 | //++
|
---|
| 41 | // Titre Constructeurs, méthodes
|
---|
| 42 | //--
|
---|
| 43 | //++
|
---|
| 44 | // PIColorMap(CMapId id)
|
---|
| 45 | // Constructeur d'une table de couleur standard, identifiée par "CMapId id"
|
---|
| 46 | //| CMAP_GREY32 : 32 niveaux de gris
|
---|
| 47 | //| CMAP_GREYINV32 : 32 niveaux gris du blanc au noir
|
---|
| 48 | //| CMAP_COLRJ32 : 32 couleurs, du Rouge au Jaune/blanc
|
---|
| 49 | //| CMAP_COLBR32 : 32 couleurs du bleu au rouge (arcenciel)
|
---|
| 50 | //| CMAP_COLRV32 : 32 couleurs du rouge au violet
|
---|
| 51 | //| CMAP_GREY128 : 128 niveaux de gris
|
---|
| 52 | //| CMAP_GREYINV128 : 128 niveaux gris inversé
|
---|
| 53 | //| CMAP_COLRJ128 : 128 couleurs, du Rouge au Jaune/blanc
|
---|
| 54 | //| CMAP_COLBR128 : 128 couleurs du bleu au rouge (arcenciel)
|
---|
| 55 | //| CMAP_COL16 : 16 Couleurs arcenciel
|
---|
| 56 | //| CMAP_OTHER : Table non standard
|
---|
| 57 | // Toutes les tables de couleurs standard possèdent 256 cellules de couleurs,
|
---|
| 58 | // contenant 16 ou 32 ou 128 couleurs distinctes.
|
---|
| 59 | //
|
---|
| 60 | // PIColorMap(string const& nom, int nCol)
|
---|
| 61 | // Constructeur d'une table de "nCol" couleurs identifié par la chaîne "nom".
|
---|
| 62 | // PIColorMap(PIColorMap&)
|
---|
| 63 | // Constructeur par copie.
|
---|
| 64 | // int Type()
|
---|
| 65 | // Retourne le type de la table, correspondant à "CMapId id"
|
---|
| 66 | // int NCol()
|
---|
| 67 | // Retourne le nombre de cellules de couleurs dans la table
|
---|
| 68 | // string const& Nom()
|
---|
| 69 | // Renvoie le nom de la table.
|
---|
| 70 | //--
|
---|
| 71 |
|
---|
| 72 | PIColorMap::PIColorMap(CMapId id)
|
---|
| 73 | : PIColorMapNative()
|
---|
| 74 | {
|
---|
| 75 | int k, kdx;
|
---|
| 76 | string mnom;
|
---|
| 77 |
|
---|
| 78 | if (NMaxTableAuto == 0) { // Il faut allouer les tables de depart
|
---|
| 79 | if ( TotNbColors() > 2048 ) NMaxTableAuto = MXMAPIDS-1;
|
---|
| 80 | else NMaxTableAuto = 3;
|
---|
| 81 | for(k=0; k<NMaxTableAuto; k++) {
|
---|
| 82 | mnom = MapNoms[k];
|
---|
| 83 | mMaps[k] = new PIColorMap(MapIds[k], MapNCols[k], mnom);
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | // Protection pour valeur de Id
|
---|
| 88 | for(kdx=0; kdx<MXMAPIDS; kdx++) if (id == MapIds[kdx]) break;
|
---|
| 89 | if (kdx == MXMAPIDS) { id = MapIds[0]; kdx = 0; }
|
---|
| 90 | for(k=0; k<NMaxTableAuto; k++)
|
---|
| 91 | if (id == mMaps[k]->Type()) {
|
---|
| 92 | CopyFrom(mMaps[k]);
|
---|
| 93 | mCTId = mMaps[k]->mCTId; mColTNums[mCTId]++;
|
---|
| 94 | break;
|
---|
| 95 | }
|
---|
| 96 | if (Type() != id) { // Table pas encore trouve dans la liste
|
---|
| 97 | k = NMaxTableAuto;
|
---|
| 98 | if (!mMaps[k] || mMaps[k]->Type() != id) {
|
---|
| 99 | if ( mMaps[k] ) {
|
---|
| 100 | mColTNums[mMaps[k]->mCTId] = 1; // Je force a liberer les couleurs
|
---|
| 101 | delete mMaps[k] ;
|
---|
| 102 | }
|
---|
| 103 | mnom = MapNoms[kdx];
|
---|
| 104 | mMaps[k] = new PIColorMap(MapIds[kdx], MapNCols[kdx], mnom);
|
---|
| 105 | }
|
---|
| 106 | CopyFrom(mMaps[k]);
|
---|
| 107 | mCTId = mMaps[k]->mCTId; mColTNums[mCTId]++;
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 | PIColorMap::PIColorMap(string const& nom, int nCol)
|
---|
| 113 | : PIColorMapNative(CMAP_OTHER, nCol, nom)
|
---|
| 114 | {
|
---|
| 115 | MakeColMap();
|
---|
| 116 | mCTId = CTNum;
|
---|
| 117 | mColTNums[mCTId] = 1;
|
---|
| 118 | CTNum++;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | PIColorMap::PIColorMap(CMapId id, int nCol, string const& nom)
|
---|
| 122 | : PIColorMapNative(id, nCol, nom)
|
---|
| 123 | {
|
---|
| 124 | MakeColMap();
|
---|
| 125 | mCTId = CTNum;
|
---|
| 126 | mColTNums[mCTId] = 1;
|
---|
| 127 | CTNum++;
|
---|
| 128 | // printf("PIColorMap/Debug-Creation: %d %d - %s ", Type(), NCol(), Nom().c_str());
|
---|
| 129 | // printf(" ..CRE.. %d %d \n", CTNum-1, mColTNums[CTNum-1]);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | PIColorMap::PIColorMap(PIColorMap& cm)
|
---|
| 133 | {
|
---|
| 134 | CopyFrom(&cm);
|
---|
| 135 | mCTId = cm.mCTId;
|
---|
| 136 | mColTNums[mCTId]++;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | PIColorMap::~PIColorMap()
|
---|
| 140 | {
|
---|
| 141 | // printf("PIColorMap/Debug-Delete: %d %d - %s ", Type(), NCol(), Nom().c_str());
|
---|
| 142 | // printf("...DEL.CTNum,mColTNums= %d %d (%d %d) ",
|
---|
| 143 | // CTNum, mColTNums[CTNum], mCTId,mColTNums[mCTId] );
|
---|
| 144 | mColTNums[mCTId]--;
|
---|
| 145 | if ( mColTNums[mCTId] == 0 ) { FreeColors(); mColTNums[mCTId] = 0; }
|
---|
| 146 | // printf("\n");
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | //++
|
---|
| 151 | // Titre Gestion des couleurs
|
---|
| 152 | // Une structure *PIColor* permet la manipulation des couleurs à
|
---|
| 153 | // travers 3 champs de type "unsigned short: 0 ... 65535" définissant
|
---|
| 154 | // les intensité des couleurs de base: Rouge, Bleue, Vert.
|
---|
| 155 | //| struct PIColor {
|
---|
| 156 | //| unsigned short red;
|
---|
| 157 | //| unsigned short green;
|
---|
| 158 | //| unsigned short blue; }
|
---|
| 159 | //
|
---|
| 160 | //--
|
---|
| 161 | //++
|
---|
| 162 | // PIColor GetColor(int n)
|
---|
| 163 | // Renvoie la couleur de la cellule "n"
|
---|
| 164 | // bool AllocColor(PIColor const& col, int index)
|
---|
| 165 | // Alloue la couleur définie par "col" dans la cellule numéro "index".
|
---|
| 166 | // Renvoie "true" si OK, "false" sinon.
|
---|
| 167 | // void FreeColors()
|
---|
| 168 | // Libère les couleurs allouées par la table
|
---|
| 169 | // long TotNbColors()
|
---|
| 170 | // Renvoie le nombre total de couleurs disponibles
|
---|
| 171 | // (Ex 256 pour un système à 8 plans image, 65536 pour 16 plans, etc ...)
|
---|
| 172 | // int NbAllocColors()
|
---|
| 173 | // Renvoie le nombre total de couleurs déjà utilisée par l'application
|
---|
| 174 | //--
|
---|
| 175 |
|
---|
| 176 | void PIColorMap::CleanColorMaps()
|
---|
| 177 | {
|
---|
| 178 | int k;
|
---|
| 179 | for(k=0; k<MXMAPIDS; k++) {
|
---|
| 180 | if (!mMaps[k]) continue;
|
---|
| 181 | mMaps[k]->FreeColors();
|
---|
| 182 | delete mMaps[k];
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | /* Definition d' une table de couleurs R G B */
|
---|
| 187 |
|
---|
| 188 | static float R_RGB1[16] =
|
---|
| 189 | {0.0,0.00,0.0,0.0,0.0,0.00,0.0,0.6,0.8,1.0,1.00,1.0,0.75,1.0,0.85,1.0};
|
---|
| 190 | static float G_RGB1[16] =
|
---|
| 191 | {0.0,0.00,0.0,0.8,1.0,1.00,1.0,0.8,0.8,1.0,0.75,0.6,0.00,0.0,0.0,0.0};
|
---|
| 192 | static float B_RGB1[16] =
|
---|
| 193 | {0.0,0.75,1.0,1.0,1.0,0.75,0.0,0.0,0.0,0.0,0.00,0.5,0.75,1.0,0.0,0.0};
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 | void PIColorMap::MakeColMap()
|
---|
| 198 | {
|
---|
| 199 | PIColor mycol;
|
---|
| 200 | int i,j,k;
|
---|
| 201 |
|
---|
| 202 | switch (mType) {
|
---|
| 203 |
|
---|
| 204 | case CMAP_GREY32 :
|
---|
| 205 | for(i=0; i<32; i++) {
|
---|
| 206 | mycol.red = mycol.green = mycol.blue = 3535+(i*62000/32);
|
---|
| 207 | for(k=0; k<8; k++) AllocColor(mycol, i*8+k);
|
---|
| 208 | }
|
---|
| 209 | break;
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 | case CMAP_GREYINV32 :
|
---|
| 213 | for(i=0; i<32; i++) {
|
---|
| 214 | mycol.red = mycol.green = mycol.blue = 3535+(i*62000/32);
|
---|
| 215 | for(k=0; k<8; k++) AllocColor(mycol, mNCol-(i*8+k)-1);
|
---|
| 216 | }
|
---|
| 217 | break;
|
---|
| 218 |
|
---|
| 219 | case CMAP_COL16 :
|
---|
| 220 | for(i=0; i<16; i++) {
|
---|
| 221 | mycol.red = (int)(R_RGB1[i]*65535.);
|
---|
| 222 | mycol.green = (int)(G_RGB1[i]*65535.);
|
---|
| 223 | mycol.blue =(int)(B_RGB1[i]*65535.) ;
|
---|
| 224 | for(k=0; k<16; k++) AllocColor(mycol, i*16+k);
|
---|
| 225 | }
|
---|
| 226 | break;
|
---|
| 227 |
|
---|
| 228 | case CMAP_COLRJ32 :
|
---|
| 229 | for( i=0; i<32; i++) {
|
---|
| 230 | if (i < 12) {
|
---|
| 231 | mycol.green = mycol.blue = 0;
|
---|
| 232 | mycol.red = 21535+(i*4000); }
|
---|
| 233 | else if (i < 24) {
|
---|
| 234 | mycol.blue = 0; mycol.red = 65535;
|
---|
| 235 | mycol.green = 21535+(i-12)*4000; }
|
---|
| 236 | else {
|
---|
| 237 | mycol.green = mycol.red = 65535;
|
---|
| 238 | mycol.blue = 17535+(i-23)*6000; }
|
---|
| 239 | for(k=0; k<8; k++) AllocColor(mycol, i*8+k);
|
---|
| 240 | }
|
---|
| 241 | break;
|
---|
| 242 |
|
---|
| 243 | case CMAP_COLBR32 :
|
---|
| 244 | for( i=0; i<32; i++) {
|
---|
| 245 | if (i < 5) {
|
---|
| 246 | mycol.green = mycol.red = 0; // Du bleu sombre au bleu clair
|
---|
| 247 | mycol.blue = 5535+i*15000; }
|
---|
| 248 | else if (i < 10) {
|
---|
| 249 | mycol.blue = 65535; // Plein bleu - On rajoute du vert -> bleu clair
|
---|
| 250 | mycol.green = 5535+(i-5)*9000;
|
---|
| 251 | mycol.red = 0; }
|
---|
| 252 | else if (i < 15) {
|
---|
| 253 | mycol.blue = 60000-(i-10)*15000; // On passe au vert
|
---|
| 254 | mycol.green = 41535+(i-10)*6000;
|
---|
| 255 | mycol.red = 0; }
|
---|
| 256 | else if (i < 21) {
|
---|
| 257 | mycol.blue = 0;
|
---|
| 258 | mycol.green = 65535; // Plein vert, on rajoute du rouge -> jaune
|
---|
| 259 | mycol.red = 5535+(i-15)*12000; }
|
---|
| 260 | else if (i < 27) {
|
---|
| 261 | mycol.blue = 0; // On diminue vert -> Orange
|
---|
| 262 | mycol.green = 60000-(i-21)*12000;
|
---|
| 263 | mycol.red = 65535-(i-21)*2000; }
|
---|
| 264 | else {
|
---|
| 265 | mycol.blue = 0; // Plein rouge
|
---|
| 266 | mycol.green = 0;
|
---|
| 267 | mycol.red = 57535+(i-27)*2000; }
|
---|
| 268 |
|
---|
| 269 | for(k=0; k<8; k++) AllocColor(mycol, i*8+k);
|
---|
| 270 | }
|
---|
| 271 | break;
|
---|
| 272 |
|
---|
| 273 | case CMAP_COLRV32 :
|
---|
| 274 | for( i=0; i<32; i++) {
|
---|
| 275 | if (i < 8) {
|
---|
| 276 | mycol.green = 15000+(i*5000); mycol.blue = 0;
|
---|
| 277 | mycol.red = 15000+(i*5000); }
|
---|
| 278 | else if (i < 21) {
|
---|
| 279 | mycol.green = 50000-(i-7)*5000;
|
---|
| 280 | if (mycol.green < 0) mycol.green = 0;
|
---|
| 281 | mycol.blue = 0;
|
---|
| 282 | mycol.red = 53535+(i-8)*1000; }
|
---|
| 283 | else {
|
---|
| 284 | mycol.green = 0; mycol.red = 65535;
|
---|
| 285 | mycol.blue = 15535+(i-21)*5000; }
|
---|
| 286 |
|
---|
| 287 | for(k=0; k<8; k++) AllocColor(mycol, i*8+k);
|
---|
| 288 | }
|
---|
| 289 | break;
|
---|
| 290 |
|
---|
| 291 | case CMAP_GREY128 :
|
---|
| 292 | for(i=0; i<128; i++) {
|
---|
| 293 | mycol.red = mycol.green = mycol.blue = 2035+(i*500);
|
---|
| 294 | for(k=0; k<2; k++) AllocColor(mycol, i*2+k);
|
---|
| 295 | }
|
---|
| 296 | break;
|
---|
| 297 |
|
---|
| 298 |
|
---|
| 299 | case CMAP_GREYINV128 :
|
---|
| 300 | for(i=0; i<128; i++) {
|
---|
| 301 | mycol.red = mycol.green = mycol.blue = 2035+(i*500);
|
---|
| 302 | for(k=0; k<2; k++) AllocColor(mycol, mNCol-(i*2+k)-1);
|
---|
| 303 | }
|
---|
| 304 | break;
|
---|
| 305 |
|
---|
| 306 | case CMAP_COLRJ128 :
|
---|
| 307 | for( i=0; i<128; i++) {
|
---|
| 308 | if (i < 48) {
|
---|
| 309 | mycol.green = mycol.blue = 0;
|
---|
| 310 | mycol.red = 5375+(i*1280); }
|
---|
| 311 | else if (i < 96) {
|
---|
| 312 | mycol.blue = 0; mycol.red = 65535;
|
---|
| 313 | mycol.green = 5375+((i-48)*1280); }
|
---|
| 314 | else {
|
---|
| 315 | mycol.green = mycol.red = 65535;
|
---|
| 316 | mycol.blue = 3535+(i-96)*2000; }
|
---|
| 317 | for(k=0; k<2; k++) AllocColor(mycol, i*2+k);
|
---|
| 318 | }
|
---|
| 319 | break;
|
---|
| 320 |
|
---|
| 321 | case CMAP_COLBR128 :
|
---|
| 322 | for( i=0; i<128; i++) {
|
---|
| 323 | if (i < 20) {
|
---|
| 324 | mycol.green = mycol.red = 0; // Du bleu sombre au bleu clair
|
---|
| 325 | mycol.blue = 2835+i*3300; }
|
---|
| 326 | else if (i < 36) {
|
---|
| 327 | mycol.blue = 65535; // Plein bleu - On rajoute du vert -> bleu clair
|
---|
| 328 | mycol.green = 3000+(i-20)*2000;
|
---|
| 329 | mycol.red = 0; }
|
---|
| 330 | else if (i < 56) {
|
---|
| 331 | mycol.blue = 64600-(i-36)*3400; // On passe au vert
|
---|
| 332 | mycol.green = 32300+(i-36)*1700;
|
---|
| 333 | mycol.red = 0; }
|
---|
| 334 | else if (i < 81) {
|
---|
| 335 | mycol.blue = 0; // Plein vert, on rajoute du rouge -> jaune
|
---|
| 336 | mycol.green = 65535;
|
---|
| 337 | mycol.red = 3135+(i-56)*2600; }
|
---|
| 338 | else if (i < 96) {
|
---|
| 339 | mycol.blue = 0;
|
---|
| 340 | mycol.green = 63535-(i-80)*2000;
|
---|
| 341 | mycol.red = 65535; }
|
---|
| 342 | else if (i < 112) {
|
---|
| 343 | mycol.blue = 0;
|
---|
| 344 | mycol.green = 30000-(i-96)*2000;
|
---|
| 345 | mycol.red = 65535-(i-96)*1000; }
|
---|
| 346 | else {
|
---|
| 347 | mycol.blue = 0;
|
---|
| 348 | mycol.green = 0 ;
|
---|
| 349 | mycol.red = 50535+(i-112)*1000; }
|
---|
| 350 |
|
---|
| 351 | for(k=0; k<2; k++) AllocColor(mycol, i*2+k);
|
---|
| 352 | }
|
---|
| 353 | break;
|
---|
| 354 |
|
---|
| 355 | default :
|
---|
| 356 | for(i=0; i<mNCol; i++) {
|
---|
| 357 | mycol.green = mycol.red = mycol.blue = 0;
|
---|
| 358 | AllocColor(mycol, i);
|
---|
| 359 | }
|
---|
| 360 | break;
|
---|
| 361 | }
|
---|
| 362 | }
|
---|