[658] | 1 | #if 0
|
---|
| 2 | /* Fonctions interface XWindow pour affichage d'images */
|
---|
| 3 | /* Reza 05/95 */
|
---|
| 4 |
|
---|
| 5 | /* LAL (Orsay) / IN2P3-CNRS */
|
---|
| 6 |
|
---|
| 7 | #include <stdlib.h>
|
---|
| 8 | #include <stdio.h>
|
---|
| 9 |
|
---|
| 10 | #include <X11/Xlib.h>
|
---|
| 11 | #include <X11/Xutil.h>
|
---|
| 12 | #include <X11/Xatom.h>
|
---|
| 13 |
|
---|
| 14 | #include "xdispim.h"
|
---|
| 15 |
|
---|
| 16 | /* Variables globales pour */
|
---|
| 17 |
|
---|
| 18 | static int RzXwDispImg = 0;
|
---|
| 19 | static Display * display;
|
---|
| 20 | static int screen;
|
---|
| 21 | static GC defgc;
|
---|
| 22 | static RzXCMap rzxcmap[5];
|
---|
| 23 | static int rzxgcok = 0;
|
---|
| 24 | static Font fonts[5];
|
---|
| 25 |
|
---|
| 26 | static int NbRzXw = 0;
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | /* Fin des variables globales */
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | /* Nouvelle-Fonction */
|
---|
| 33 | int RzXInitDisplay(int prtl)
|
---|
| 34 |
|
---|
| 35 | /* Connection avec un serveur X, et allocation des couleurs */
|
---|
| 36 |
|
---|
| 37 | {
|
---|
| 38 | Visual* vis;
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | struct rzvisu_struc
|
---|
| 42 | {
|
---|
| 43 | int MMsize_x;
|
---|
| 44 | int MMsize_y;
|
---|
| 45 | int Pixsize_x;
|
---|
| 46 | int Pixsize_y;
|
---|
| 47 | float resol_x;
|
---|
| 48 | float resol_y;
|
---|
| 49 | } rzvisu;
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | display = XOpenDisplay ("");
|
---|
| 53 |
|
---|
| 54 | if (display == 0)
|
---|
| 55 | { printf("RzXInitDisplay_Error: Cannot connect to X-Server \n");
|
---|
| 56 | return(1); }
|
---|
| 57 | screen = XDefaultScreen(display);
|
---|
| 58 |
|
---|
| 59 | rzvisu.Pixsize_x = DisplayWidth (display, screen);
|
---|
| 60 | rzvisu.Pixsize_y = DisplayHeight (display, screen);
|
---|
| 61 | rzvisu.MMsize_x = DisplayWidthMM (display, screen);
|
---|
| 62 | rzvisu.MMsize_y = DisplayHeightMM (display, screen);
|
---|
| 63 |
|
---|
| 64 | rzvisu.resol_x = (float)rzvisu.Pixsize_x*10./(float)rzvisu.MMsize_x;
|
---|
| 65 | rzvisu.resol_y = (float)rzvisu.Pixsize_y*10./(float)rzvisu.MMsize_y;
|
---|
| 66 |
|
---|
| 67 | vis = DefaultVisual(display,screen);
|
---|
| 68 |
|
---|
| 69 | if (prtl > 0)
|
---|
| 70 | {
|
---|
| 71 | printf("RzXInitDisplay_Info: Screen size (X,Y) : %d * %d Pix (%d * %d mm)\n",
|
---|
| 72 | rzvisu.Pixsize_x,rzvisu.Pixsize_y,
|
---|
| 73 | rzvisu.MMsize_x,rzvisu.MMsize_y);
|
---|
| 74 | printf ("... Planes= %d Cells= %d depth= %d ", XDisplayPlanes(display, screen) ,
|
---|
| 75 | XDisplayCells(display, screen), XDefaultDepth(display, screen));
|
---|
| 76 |
|
---|
| 77 | switch (vis->class)
|
---|
| 78 | {
|
---|
| 79 | case PseudoColor :
|
---|
| 80 | printf (".... Class = %d (PseudoColor) \n",vis->class);
|
---|
| 81 | break;
|
---|
| 82 | case DirectColor :
|
---|
| 83 | printf (".... Class = %d (DirectColor) \n",vis->class);
|
---|
| 84 | break;
|
---|
| 85 | case GrayScale :
|
---|
| 86 | printf (".... Class = %d (GreyScale) \n",vis->class);
|
---|
| 87 | break;
|
---|
| 88 | case StaticColor :
|
---|
| 89 | printf (".... Class = %d (StaticColor) \n",vis->class);
|
---|
| 90 | break;
|
---|
| 91 | case StaticGray :
|
---|
| 92 | printf (".... Class = %d (StaticGray) \n",vis->class);
|
---|
| 93 | break;
|
---|
| 94 | case TrueColor :
|
---|
| 95 | printf (".... Class = %d (TrueColor) \n",vis->class);
|
---|
| 96 | break;
|
---|
| 97 | default :
|
---|
| 98 | printf (".... Class = %d (Unknown !) \n",vis->class);
|
---|
| 99 | break;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | /* Allocating default CMap */
|
---|
| 105 | RzXAllocCMap(rzxcmap, CMAP_GREY32, prtl);
|
---|
| 106 | RzXAllocCMap(rzxcmap+1, CMAP_COL16, prtl);
|
---|
| 107 | RzXAllocCMap(rzxcmap+2, CMAP_GREYINV32, prtl);
|
---|
| 108 | RzXAllocCMap(rzxcmap+3, CMAP_COLRJ32, prtl);
|
---|
| 109 | rzxcmap[4].typ = -1; rzxcmap[4].nCol = 0;
|
---|
| 110 |
|
---|
| 111 | if (prtl > 1)
|
---|
| 112 | printf("...Loading fonts Adobe-Courier Normal/Bold/Ital : \n");
|
---|
| 113 | fonts[0] = XLoadFont(display,
|
---|
| 114 | "-adobe-courier-medium-r-normal--*-140-*-iso8859-1");
|
---|
| 115 | fonts[1] = XLoadFont(display,
|
---|
| 116 | "-adobe-courier-bold-r-normal--*-140-*-iso8859-1");
|
---|
| 117 | fonts[2] = XLoadFont(display,
|
---|
| 118 | "-adobe-courier-medium-o-normal--*-140-*-iso8859-1");
|
---|
| 119 |
|
---|
| 120 | RzXwDispImg = 1; /* Variable de controle d'initialisation */
|
---|
| 121 |
|
---|
| 122 | return(0);
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | /* Nouvelle-Fonction */
|
---|
| 126 | int RzXCheckInitDisp()
|
---|
| 127 | {
|
---|
| 128 | return (RzXwDispImg);
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 |
|
---|
| 132 | /* Nouvelle-Fonction */
|
---|
| 133 | int RzXGetPixDSize()
|
---|
| 134 | /* Retourne la taille correspondant a depth en Byte ( 8->1) */
|
---|
| 135 | {
|
---|
| 136 | int depth;
|
---|
| 137 | depth = DefaultDepth(display,screen);
|
---|
| 138 | if (depth <= 8) return(1);
|
---|
| 139 | else if (depth <= 16) return(2);
|
---|
| 140 | else return(4);
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | /* Nouvelle-Fonction */
|
---|
| 144 | int RzXDispPixMap(Window xw, unsigned char *pix, int sizx, int sizy, RzXCMap *cmap)
|
---|
| 145 | {
|
---|
| 146 | int depth;
|
---|
| 147 | XImage * ximg;
|
---|
| 148 | int i,j;
|
---|
| 149 | unsigned char *pp;
|
---|
| 150 |
|
---|
| 151 | depth = DefaultDepth(display,screen);
|
---|
| 152 | ximg = XCreateImage (display,DefaultVisual(display,screen),
|
---|
| 153 | depth,ZPixmap,0,pix,sizx,sizy,8,0);
|
---|
| 154 | pp = pix;
|
---|
| 155 | for(j=0; j<sizy; j++)
|
---|
| 156 | for(i=0; i<sizx; i++)
|
---|
| 157 | { XPutPixel(ximg, i, j, cmap->colpix[*pp]); pp++; }
|
---|
| 158 | XRaiseWindow(display, xw);
|
---|
| 159 | XPutImage(display,xw,defgc,ximg,0,0,0,0,sizx, sizy);
|
---|
| 160 | XSync(display,1);
|
---|
| 161 | XFree(ximg);
|
---|
| 162 |
|
---|
| 163 | return(0);
|
---|
| 164 |
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 |
|
---|
| 168 | /* Nouvelle-Fonction */
|
---|
| 169 | RzXCMap * RzXGetCMap(int cmapid)
|
---|
| 170 | {
|
---|
| 171 | int i;
|
---|
| 172 | for(i=0; i<5; i++)
|
---|
| 173 | if (rzxcmap[i].typ == cmapid) return(rzxcmap+i);
|
---|
| 174 | if (rzxcmap[4].typ >= 0) RzXFreeCMap(rzxcmap+4);
|
---|
| 175 | RzXAllocCMap(rzxcmap+4, cmapid, 0);
|
---|
| 176 | return(rzxcmap+4);
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | /* Definition d' une table de couleurs R G B */
|
---|
| 181 |
|
---|
| 182 | static float R_RGB1[16] =
|
---|
| 183 | {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};
|
---|
| 184 | static float G_RGB1[16] =
|
---|
| 185 | {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};
|
---|
| 186 | static float B_RGB1[16] =
|
---|
| 187 | {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};
|
---|
| 188 |
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | /* Nouvelle-Fonction */
|
---|
| 192 | int RzXAllocCMap(RzXCMap *rcmap, int cmapid, int prtl)
|
---|
| 193 | /* Allocation des tables de couleurs */
|
---|
| 194 |
|
---|
| 195 | {
|
---|
| 196 | Colormap cmap;
|
---|
| 197 | XColor mycol;
|
---|
| 198 | int nok,i;
|
---|
| 199 |
|
---|
| 200 | cmap = XDefaultColormap (display, screen);
|
---|
| 201 |
|
---|
| 202 | nok = 0;
|
---|
| 203 |
|
---|
| 204 | rcmap->typ = -1;
|
---|
| 205 |
|
---|
| 206 | switch (cmapid)
|
---|
| 207 | {
|
---|
| 208 | case CMAP_GREY32 :
|
---|
| 209 | rcmap->nCol = 32; nok = 0;
|
---|
| 210 | for(i=0; i<rcmap->nCol; i++)
|
---|
| 211 | {
|
---|
| 212 | mycol.red = mycol.green = mycol.blue = 3535+(i*62000/32);
|
---|
| 213 | if (XAllocColor(display, cmap, &mycol) )
|
---|
| 214 | { rcmap->colpix[i] = mycol.pixel; nok++; }
|
---|
| 215 | else rcmap->colpix[i] = BlackPixel(display, screen);
|
---|
| 216 | }
|
---|
| 217 | rcmap->typ = CMAP_GREY32;
|
---|
| 218 | break;
|
---|
| 219 |
|
---|
| 220 | case CMAP_GREYINV32 :
|
---|
| 221 | rcmap->nCol = 32; nok = 0;
|
---|
| 222 | for(i=0; i<rcmap->nCol; i++)
|
---|
| 223 | {
|
---|
| 224 | mycol.red = mycol.green = mycol.blue = 65535-(i*62000/32);
|
---|
| 225 | if (XAllocColor(display, cmap, &mycol) )
|
---|
| 226 | { rcmap->colpix[i] = mycol.pixel; nok++; }
|
---|
| 227 | else rcmap->colpix[i] = BlackPixel(display, screen);
|
---|
| 228 | }
|
---|
| 229 | rcmap->typ = CMAP_GREYINV32;
|
---|
| 230 | break;
|
---|
| 231 |
|
---|
| 232 | case CMAP_COL16 :
|
---|
| 233 | rcmap->nCol = 16; nok = 0;
|
---|
| 234 | for(i=0; i<rcmap->nCol; i++)
|
---|
| 235 | {
|
---|
| 236 | mycol.red = (int)(R_RGB1[i]*65535.);
|
---|
| 237 | mycol.green = (int)(G_RGB1[i]*65535.);
|
---|
| 238 | mycol.blue =(int)(B_RGB1[i]*65535.) ;
|
---|
| 239 | if (XAllocColor(display, cmap, &mycol) )
|
---|
| 240 | { rcmap->colpix[i] = mycol.pixel; nok++; }
|
---|
| 241 | else rcmap->colpix[i] = BlackPixel(display, screen);
|
---|
| 242 | }
|
---|
| 243 | rcmap->typ = CMAP_COL16;
|
---|
| 244 | break;
|
---|
| 245 |
|
---|
| 246 | case CMAP_COLRJ32 :
|
---|
| 247 | rcmap->nCol = 32; nok = 0;
|
---|
| 248 | for(i=0; i<rcmap->nCol; i++)
|
---|
| 249 | {
|
---|
| 250 | if (i < 12)
|
---|
| 251 | { mycol.green = mycol.blue = 0;
|
---|
| 252 | mycol.red = 21535+(i*4000); }
|
---|
| 253 | else if (i < 24)
|
---|
| 254 | { mycol.blue = 0; mycol.red = 65535;
|
---|
| 255 | mycol.green = 21535+(i-12)*4000; }
|
---|
| 256 | else
|
---|
| 257 | { mycol.green = mycol.red = 65535;
|
---|
| 258 | mycol.blue = 17535+(i-23)*6000; }
|
---|
| 259 |
|
---|
| 260 | if (XAllocColor(display, cmap, &mycol) )
|
---|
| 261 | { rcmap->colpix[i] = mycol.pixel; nok++; }
|
---|
| 262 | else rcmap->colpix[i] = BlackPixel(display, screen);
|
---|
| 263 | }
|
---|
| 264 | rcmap->typ = CMAP_COLRJ32;
|
---|
| 265 | break;
|
---|
| 266 |
|
---|
| 267 | case CMAP_COLBR32 :
|
---|
| 268 | rcmap->nCol = 32; nok = 0;
|
---|
| 269 | for(i=0; i<rcmap->nCol; i++)
|
---|
| 270 | {
|
---|
| 271 | if (i < 5)
|
---|
| 272 | { mycol.green = mycol.red = 0;
|
---|
| 273 | mycol.blue = 5535+i*15000; }
|
---|
| 274 | else if (i < 10)
|
---|
| 275 | { mycol.blue = 65535;
|
---|
| 276 | mycol.green = 5535+(i-5)*9000;
|
---|
| 277 | mycol.red = 0; }
|
---|
| 278 | else if (i < 15)
|
---|
| 279 | { mycol.blue = 60000-(i-10)*15000;
|
---|
| 280 | mycol.green = 41535+(i-10)*6000;
|
---|
| 281 | mycol.red = 0; }
|
---|
| 282 | else if (i < 21)
|
---|
| 283 | { mycol.blue = 0;
|
---|
| 284 | mycol.green = 65535;
|
---|
| 285 | mycol.red = 5535+(i-15)*12000; }
|
---|
| 286 | else if (i < 27)
|
---|
| 287 | { mycol.blue = 0;
|
---|
| 288 | mycol.green = 60000-(i-21)*12000;
|
---|
| 289 | mycol.red = 65535-(i-21)*2000; }
|
---|
| 290 | else
|
---|
| 291 | { mycol.blue = 0;
|
---|
| 292 | mycol.green = 0;
|
---|
| 293 | mycol.red = 57535+(i-27)*2000; }
|
---|
| 294 |
|
---|
| 295 | if (XAllocColor(display, cmap, &mycol) )
|
---|
| 296 | { rcmap->colpix[i] = mycol.pixel; nok++; }
|
---|
| 297 | else rcmap->colpix[i] = BlackPixel(display, screen);
|
---|
| 298 | }
|
---|
| 299 | rcmap->typ = CMAP_COLBR32;
|
---|
| 300 | break;
|
---|
| 301 |
|
---|
| 302 | case CMAP_COLRV32 :
|
---|
| 303 | rcmap->nCol = 32; nok = 0;
|
---|
| 304 | for(i=0; i<rcmap->nCol; i++)
|
---|
| 305 | {
|
---|
| 306 | if (i < 8)
|
---|
| 307 | { mycol.green = 15000+(i*5000); mycol.blue = 0;
|
---|
| 308 | mycol.red = 15000+(i*5000); }
|
---|
| 309 | else if (i < 21)
|
---|
| 310 | { mycol.green = 50000-(i-7)*5000;
|
---|
| 311 | if (mycol.green < 0) mycol.green = 0;
|
---|
| 312 | mycol.blue = 0;
|
---|
| 313 | mycol.red = 53535+(i-8)*1000; }
|
---|
| 314 | else
|
---|
| 315 | { mycol.green = 0; mycol.red = 65535;
|
---|
| 316 | mycol.blue = 15535+(i-21)*5000; }
|
---|
| 317 |
|
---|
| 318 | if (XAllocColor(display, cmap, &mycol) )
|
---|
| 319 | { rcmap->colpix[i] = mycol.pixel; nok++; }
|
---|
| 320 | else rcmap->colpix[i] = BlackPixel(display, screen);
|
---|
| 321 | }
|
---|
| 322 | rcmap->typ = CMAP_COLRV32;
|
---|
| 323 | break;
|
---|
| 324 |
|
---|
| 325 | default :
|
---|
| 326 | printf("RzXAllocCMap_Info: Erreur specification CMapType (%d) \n", cmapid);
|
---|
| 327 | break;
|
---|
| 328 | }
|
---|
| 329 |
|
---|
| 330 | for(i=rcmap->nCol; i<256; i++) rcmap->colpix[i] = 0;
|
---|
| 331 |
|
---|
| 332 | if (prtl)
|
---|
| 333 | printf("RzXAllocCMap_Info: %d colors allocated for CMap Type %d \n", nok, cmapid);
|
---|
| 334 |
|
---|
| 335 | return(0);
|
---|
| 336 |
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | /* Nouvelle-Fonction */
|
---|
| 340 | int RzXFreeCMap(RzXCMap *rcmap)
|
---|
| 341 | {
|
---|
| 342 | Colormap cmap;
|
---|
| 343 | int i;
|
---|
| 344 |
|
---|
| 345 | cmap = XDefaultColormap (display, screen);
|
---|
| 346 | XFreeColors(display, cmap, rcmap->colpix, rcmap->nCol, 0);
|
---|
| 347 | for(i=0; i<rcmap->nCol; i++) rcmap->colpix[i] = 0;
|
---|
| 348 | rcmap->nCol = 0;
|
---|
| 349 | return(0);
|
---|
| 350 | }
|
---|
| 351 |
|
---|
| 352 |
|
---|
| 353 | /* Nouvelle-Fonction */
|
---|
| 354 | Window RzXNewWin(int sx, int sy, char *title, int posx, int posy)
|
---|
| 355 |
|
---|
| 356 | /* Creation de fenetre X simple pour mettre une image */
|
---|
| 357 | {
|
---|
| 358 | XSizeHints hint;
|
---|
| 359 | Window win;
|
---|
| 360 |
|
---|
| 361 | hint.x = posx; hint.y = posy;
|
---|
| 362 | hint.width = sx; hint.height = sy;
|
---|
| 363 | hint.flags = PPosition | PSize;
|
---|
| 364 |
|
---|
| 365 |
|
---|
| 366 | win = XCreateSimpleWindow (display, DefaultRootWindow (display),
|
---|
| 367 | hint.x, hint.y, hint.width, hint.height, 3,
|
---|
| 368 | WhitePixel(display, screen), BlackPixel(display, screen) );
|
---|
| 369 |
|
---|
| 370 | XSetStandardProperties (display, win, title, title, None, NULL, 0, &hint);
|
---|
| 371 |
|
---|
| 372 | if (!rzxgcok)
|
---|
| 373 | {
|
---|
| 374 | defgc = XCreateGC (display, win, 0, 0);
|
---|
| 375 | rzxgcok = 1;
|
---|
| 376 | }
|
---|
| 377 | XMapRaised(display,win);
|
---|
| 378 | XSync(display,1);
|
---|
| 379 |
|
---|
| 380 | return(win);
|
---|
| 381 | }
|
---|
| 382 | #endif
|
---|
| 383 |
|
---|