49 #include <visp/vpConfig.h>
59 #include <visp/vpDisplay.h>
60 #include <visp/vpDisplayX.h>
63 #include <visp/vpDebug.h>
64 #include <visp/vpDisplayException.h>
67 #include <visp/vpMath.h>
85 init ( I, x, y, title ) ;
104 init ( I, x, y, title ) ;
134 this->x_color = NULL;
137 strcpy (this->title, title);
139 ximage_data_init =
false;
164 ximage_data_init =
false;
187 if (x_color == NULL) {
199 strcpy ( this->title, title ) ;
208 hints.flags = USPosition;
216 display = XOpenDisplay ( NULL );
217 if ( display == NULL )
219 vpERROR_TRACE (
"Can't connect display on server %s.\n", XDisplayName ( NULL ) );
221 "Can't connect display on server." ) ) ;
224 screen = DefaultScreen ( display );
225 lut = DefaultColormap ( display, screen );
226 screen_depth = (
unsigned int)DefaultDepth ( display, screen );
229 XCreateSimpleWindow ( display, RootWindow ( display, screen ),
231 BlackPixel ( display, screen ),
232 WhitePixel ( display, screen ) ) ) == 0 )
236 "Can't create window." ) ) ;
242 if ( screen_depth == 8 )
244 lut = XCreateColormap ( display, window,
245 DefaultVisual ( display, screen ), AllocAll ) ;
246 xcolor.flags = DoRed | DoGreen | DoBlue ;
248 for (
unsigned int i = 0 ; i < 256 ; i++ )
251 xcolor.red = 256 * i;
252 xcolor.green = 256 * i;
253 xcolor.blue = 256 * i;
254 XStoreColor ( display, lut, &xcolor );
257 XSetWindowColormap ( display, window, lut ) ;
258 XInstallColormap ( display, lut ) ;
261 else if ( screen_depth == 16 )
263 for (
unsigned int i = 0; i < 256; i ++ )
266 xcolor.red = xcolor.green = xcolor.blue = 256 * i;
267 if ( XAllocColor ( display, lut, &xcolor ) == 0 )
269 vpERROR_TRACE (
"Can't allocate 256 colors. Only %d allocated.", i );
271 "Can't allocate 256 colors." ) ) ;
273 colortable[i] = xcolor.pixel;
276 XSetWindowColormap ( display, window, lut ) ;
277 XInstallColormap ( display, lut ) ;
284 switch ( screen_depth )
292 xcolor.red = 256 * 192;
293 xcolor.green = 256 * 192;
294 xcolor.blue = 256 * 192;
295 XStoreColor ( display, lut, &xcolor );
300 xcolor.red = 256 * 128;
301 xcolor.green = 256 * 128;
302 xcolor.blue = 256 * 128;
303 XStoreColor ( display, lut, &xcolor );
308 xcolor.red = 256 * 64;
309 xcolor.green = 256 * 64;
310 xcolor.blue = 256 * 64;
311 XStoreColor ( display, lut, &xcolor );
316 xcolor.red = 256 * 255;
317 xcolor.green = 256 * 140;
318 xcolor.blue = 256 * 140;
319 XStoreColor ( display, lut, &xcolor );
324 xcolor.red = 256 * 255;
327 XStoreColor ( display, lut, &xcolor );
332 xcolor.red = 256 * 128;
335 XStoreColor ( display, lut, &xcolor );
340 xcolor.red = 256 * 140;
341 xcolor.green = 256 * 255;
342 xcolor.blue = 256 * 140;
343 XStoreColor ( display, lut, &xcolor );
349 xcolor.green = 256 * 255;
351 XStoreColor ( display, lut, &xcolor );
357 xcolor.green = 256 * 128;
359 XStoreColor ( display, lut, &xcolor );
364 xcolor.red = 256 * 140;
365 xcolor.green = 256 * 140;
366 xcolor.blue = 256 * 255;
367 XStoreColor ( display, lut, &xcolor );
374 xcolor.blue = 256 * 255;
375 XStoreColor ( display, lut, &xcolor );
382 xcolor.blue = 256 * 128;
383 XStoreColor ( display, lut, &xcolor );
388 xcolor.red = 256 * 255;
389 xcolor.green = 256 * 255;
391 XStoreColor ( display, lut, &xcolor );
396 xcolor.red = 256 * 255;
397 xcolor.green = 256 * 165;
399 XStoreColor ( display, lut, &xcolor );
405 xcolor.green = 256 * 255;
406 xcolor.blue = 256 * 255;
407 XStoreColor ( display, lut, &xcolor );
412 xcolor.red = 256 * 128;
414 xcolor.blue = 256 * 128;
415 XStoreColor ( display, lut, &xcolor );
422 xcolor.flags = DoRed | DoGreen | DoBlue ;
429 XAllocColor ( display, lut, &xcolor );
434 xcolor.red = 256* 255;
435 xcolor.green = 256* 255;
436 xcolor.blue = 256* 255;
437 XAllocColor ( display, lut, &xcolor );
442 xcolor.red = 256 * 192;
443 xcolor.green = 256 * 192;
444 xcolor.blue = 256 * 192;
445 XAllocColor ( display, lut, &xcolor );
450 xcolor.red = 256 * 128;
451 xcolor.green = 256 * 128;
452 xcolor.blue = 256 * 128;
453 XAllocColor ( display, lut, &xcolor );
458 xcolor.red = 256 * 64;
459 xcolor.green = 256 * 64;
460 xcolor.blue = 256 * 64;
461 XAllocColor ( display, lut, &xcolor );
466 xcolor.red = 256 * 255;
467 xcolor.green = 256 * 140;
468 xcolor.blue = 256 * 140;
469 XAllocColor ( display, lut, &xcolor );
474 xcolor.red = 256* 255;
477 XAllocColor ( display, lut, &xcolor );
482 xcolor.red = 256* 128;
485 XAllocColor ( display, lut, &xcolor );
490 xcolor.red = 256 * 140;
491 xcolor.green = 256 * 255;
492 xcolor.blue = 256 * 140;
493 XAllocColor ( display, lut, &xcolor );
499 xcolor.green = 256*255;
501 XAllocColor ( display, lut, &xcolor );
507 xcolor.green = 256* 128;
509 XAllocColor ( display, lut, &xcolor );
514 xcolor.red = 256 * 140;
515 xcolor.green = 256 * 140;
516 xcolor.blue = 256 * 255;
517 XAllocColor ( display, lut, &xcolor );
524 xcolor.blue = 256* 255;
525 XAllocColor ( display, lut, &xcolor );
532 xcolor.blue = 256* 128;
533 XAllocColor ( display, lut, &xcolor );
538 xcolor.red = 256 * 255;
539 xcolor.green = 256 * 255;
541 XAllocColor ( display, lut, &xcolor );
546 xcolor.red = 256 * 255;
547 xcolor.green = 256 * 165;
549 XAllocColor ( display, lut, &xcolor );
555 xcolor.green = 256 * 255;
556 xcolor.blue = 256 * 255;
557 XAllocColor ( display, lut, &xcolor );
562 xcolor.red = 256 * 128;
564 xcolor.blue = 256 * 128;
565 XAllocColor ( display, lut, &xcolor );
571 XSetStandardProperties ( display, window, this->title, this->title, None, 0, 0, &hints );
572 XMapWindow ( display, window ) ;
574 XSelectInput ( display, window,
576 ButtonPressMask | ButtonReleaseMask |
577 KeyPressMask | KeyReleaseMask |
578 StructureNotifyMask |
582 values.plane_mask = AllPlanes;
583 values.fill_style = FillSolid;
584 values.foreground = WhitePixel ( display, screen );
585 values.background = BlackPixel ( display, screen );
586 context = XCreateGC ( display, window,
587 GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
590 if ( context == NULL )
594 "Can't create graphics context" ) ) ;
599 pixmap = XCreatePixmap ( display, window,
width,
height, screen_depth );
602 XNextEvent ( display, &event );
603 while ( event.xany.type != Expose );
606 Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
607 screen_depth, ZPixmap, 0, NULL,
610 Ximage->data = (
char * ) malloc ( I.
getWidth() * I.
getHeight() * (
unsigned int)Ximage->bits_per_pixel / 8 );
611 ximage_data_init =
true;
616 XSync ( display, 1 );
640 if (x_color == NULL) {
646 strcpy ( this->title, title ) ;
655 hints.flags = USPosition;
664 if ( ( display = XOpenDisplay ( NULL ) ) == NULL )
666 vpERROR_TRACE (
"Can't connect display on server %s.\n", XDisplayName ( NULL ) );
668 "Can't connect display on server." ) ) ;
671 screen = DefaultScreen ( display );
672 lut = DefaultColormap ( display, screen );
673 screen_depth = (
unsigned int)DefaultDepth ( display, screen );
677 if ( ( window = XCreateSimpleWindow ( display, RootWindow ( display, screen ),
680 BlackPixel ( display, screen ),
681 WhitePixel ( display, screen ) ) ) == 0 )
685 "Can't create window." ) ) ;
691 if ( screen_depth == 8 )
693 lut = XCreateColormap ( display, window,
694 DefaultVisual ( display, screen ), AllocAll ) ;
695 xcolor.flags = DoRed | DoGreen | DoBlue ;
697 for (
unsigned int i = 0 ; i < 256 ; i++ )
700 xcolor.red = 256 * i;
701 xcolor.green = 256 * i;
702 xcolor.blue = 256 * i;
703 XStoreColor ( display, lut, &xcolor );
706 XSetWindowColormap ( display, window, lut ) ;
707 XInstallColormap ( display, lut ) ;
710 else if ( screen_depth == 16 )
712 for (
unsigned int i = 0; i < 256; i ++ )
715 xcolor.red = xcolor.green = xcolor.blue = 256 * i;
716 if ( XAllocColor ( display, lut, &xcolor ) == 0 )
718 vpERROR_TRACE (
"Can't allocate 256 colors. Only %d allocated.", i );
720 "Can't allocate 256 colors." ) ) ;
722 colortable[i] = xcolor.pixel;
725 XSetWindowColormap ( display, window, lut ) ;
726 XInstallColormap ( display, lut ) ;
734 switch ( screen_depth )
743 xcolor.red = 256 * 192;
744 xcolor.green = 256 * 192;
745 xcolor.blue = 256 * 192;
746 XStoreColor ( display, lut, &xcolor );
751 xcolor.red = 256 * 128;
752 xcolor.green = 256 * 128;
753 xcolor.blue = 256 * 128;
754 XStoreColor ( display, lut, &xcolor );
759 xcolor.red = 256 * 64;
760 xcolor.green = 256 * 64;
761 xcolor.blue = 256 * 64;
762 XStoreColor ( display, lut, &xcolor );
767 xcolor.red = 256 * 255;
768 xcolor.green = 256 * 140;
769 xcolor.blue = 256 * 140;
770 XStoreColor ( display, lut, &xcolor );
775 xcolor.red = 256 * 255;
778 XStoreColor ( display, lut, &xcolor );
783 xcolor.red = 256 * 128;
786 XStoreColor ( display, lut, &xcolor );
791 xcolor.red = 256 * 140;
792 xcolor.green = 256 * 255;
793 xcolor.blue = 256 * 140;
794 XStoreColor ( display, lut, &xcolor );
800 xcolor.green = 256 * 255;
802 XStoreColor ( display, lut, &xcolor );
808 xcolor.green = 256 * 128;
810 XStoreColor ( display, lut, &xcolor );
815 xcolor.red = 256 * 140;
816 xcolor.green = 256 * 140;
817 xcolor.blue = 256 * 255;
818 XStoreColor ( display, lut, &xcolor );
825 xcolor.blue = 256 * 255;
826 XStoreColor ( display, lut, &xcolor );
833 xcolor.blue = 256 * 128;
834 XStoreColor ( display, lut, &xcolor );
839 xcolor.red = 256 * 255;
840 xcolor.green = 256 * 255;
842 XStoreColor ( display, lut, &xcolor );
847 xcolor.red = 256 * 255;
848 xcolor.green = 256 * 165;
850 XStoreColor ( display, lut, &xcolor );
856 xcolor.green = 256 * 255;
857 xcolor.blue = 256 * 255;
858 XStoreColor ( display, lut, &xcolor );
863 xcolor.red = 256 * 128;
865 xcolor.blue = 256 * 128;
866 XStoreColor ( display, lut, &xcolor );
873 xcolor.flags = DoRed | DoGreen | DoBlue ;
880 XAllocColor ( display, lut, &xcolor );
885 xcolor.red = 256* 255;
886 xcolor.green = 256* 255;
887 xcolor.blue = 256* 255;
888 XAllocColor ( display, lut, &xcolor );
893 xcolor.red = 256 * 192;
894 xcolor.green = 256 * 192;
895 xcolor.blue = 256 * 192;
896 XAllocColor ( display, lut, &xcolor );
901 xcolor.red = 256 * 128;
902 xcolor.green = 256 * 128;
903 xcolor.blue = 256 * 128;
904 XAllocColor ( display, lut, &xcolor );
909 xcolor.red = 256 * 64;
910 xcolor.green = 256 * 64;
911 xcolor.blue = 256 * 64;
912 XAllocColor ( display, lut, &xcolor );
917 xcolor.red = 256 * 255;
918 xcolor.green = 256 * 140;
919 xcolor.blue = 256 * 140;
920 XAllocColor ( display, lut, &xcolor );
925 xcolor.red = 256* 255;
928 XAllocColor ( display, lut, &xcolor );
933 xcolor.red = 256* 128;
936 XAllocColor ( display, lut, &xcolor );
941 xcolor.red = 256 * 140;
942 xcolor.green = 256 * 255;
943 xcolor.blue = 256 * 140;
944 XAllocColor ( display, lut, &xcolor );
950 xcolor.green = 256*255;
952 XAllocColor ( display, lut, &xcolor );
958 xcolor.green = 256* 128;
960 XAllocColor ( display, lut, &xcolor );
965 xcolor.red = 256 * 140;
966 xcolor.green = 256 * 140;
967 xcolor.blue = 256 * 255;
968 XAllocColor ( display, lut, &xcolor );
975 xcolor.blue = 256* 255;
976 XAllocColor ( display, lut, &xcolor );
983 xcolor.blue = 256* 128;
984 XAllocColor ( display, lut, &xcolor );
989 xcolor.red = 256 * 255;
990 xcolor.green = 256 * 255;
992 XAllocColor ( display, lut, &xcolor );
997 xcolor.red = 256 * 255;
998 xcolor.green = 256 * 165;
1000 XAllocColor ( display, lut, &xcolor );
1006 xcolor.green = 256 * 255;
1007 xcolor.blue = 256 * 255;
1008 XAllocColor ( display, lut, &xcolor );
1013 xcolor.red = 256 * 128;
1015 xcolor.blue = 256 * 128;
1016 XAllocColor ( display, lut, &xcolor );
1022 XSetStandardProperties ( display, window, this->title, this->title, None, 0, 0, &hints );
1023 XMapWindow ( display, window ) ;
1025 XSelectInput ( display, window,
1027 ButtonPressMask | ButtonReleaseMask |
1028 KeyPressMask | KeyReleaseMask |
1029 StructureNotifyMask |
1033 values.plane_mask = AllPlanes;
1034 values.fill_style = FillSolid;
1035 values.foreground = WhitePixel ( display, screen );
1036 values.background = BlackPixel ( display, screen );
1037 context = XCreateGC ( display, window,
1038 GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
1041 if ( context == NULL )
1045 "Can't create graphics context" ) ) ;
1049 pixmap = XCreatePixmap ( display, window,
width,
height, screen_depth );
1052 XNextEvent ( display, &event );
1053 while ( event.xany.type != Expose );
1057 Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
1058 screen_depth, ZPixmap, 0, NULL,
1063 * (
unsigned int)Ximage->bits_per_pixel / 8 );
1064 ximage_data_init =
true;
1069 XSync ( display,
true );
1084 int x,
int y,
const char *title )
1088 this->width =
width;
1104 hints.flags = USPosition;
1109 if ( title != NULL )
1110 strcpy ( this->title, title ) ;
1112 if ( ( display = XOpenDisplay ( NULL ) ) == NULL )
1114 vpERROR_TRACE (
"Can't connect display on server %s.\n", XDisplayName ( NULL ) );
1116 "Can't connect display on server." ) ) ;
1119 screen = DefaultScreen ( display );
1120 lut = DefaultColormap ( display, screen );
1121 screen_depth = (
unsigned int)DefaultDepth ( display, screen );
1123 vpTRACE (
"Screen depth: %d\n", screen_depth );
1125 if ( ( window = XCreateSimpleWindow ( display, RootWindow ( display, screen ),
1128 BlackPixel ( display, screen ),
1129 WhitePixel ( display, screen ) ) ) == 0 )
1133 "Can't create window." ) ) ;
1140 if ( screen_depth == 8 )
1142 lut = XCreateColormap ( display, window,
1143 DefaultVisual ( display, screen ), AllocAll ) ;
1144 xcolor.flags = DoRed | DoGreen | DoBlue ;
1146 for (
unsigned int i = 0 ; i < 256 ; i++ )
1149 xcolor.red = 256 * i;
1150 xcolor.green = 256 * i;
1151 xcolor.blue = 256 * i;
1152 XStoreColor ( display, lut, &xcolor );
1155 XSetWindowColormap ( display, window, lut ) ;
1156 XInstallColormap ( display, lut ) ;
1159 else if ( screen_depth == 16 )
1161 for (
unsigned int i = 0; i < 256; i ++ )
1164 xcolor.red = xcolor.green = xcolor.blue = 256 * i;
1165 if ( XAllocColor ( display, lut, &xcolor ) == 0 )
1167 vpERROR_TRACE (
"Can't allocate 256 colors. Only %d allocated.", i );
1169 "Can't allocate 256 colors." ) ) ;
1171 colortable[i] = xcolor.pixel;
1174 XSetWindowColormap ( display, window, lut ) ;
1175 XInstallColormap ( display, lut ) ;
1184 switch ( screen_depth )
1194 xcolor.pixel = 254 ;
1195 xcolor.red = 256 * pcolor.
R;
1196 xcolor.green = 256 * pcolor.
G;
1197 xcolor.blue = 256 * pcolor.
B;
1198 XStoreColor ( display, lut, &xcolor );
1202 xcolor.pixel = 253 ;
1203 xcolor.red = 256 * pcolor.
R;
1204 xcolor.green = 256 * pcolor.
G;
1205 xcolor.blue = 256 * pcolor.
B;
1206 XStoreColor ( display, lut, &xcolor );
1210 xcolor.pixel = 252 ;
1211 xcolor.red = 256 * pcolor.
R;
1212 xcolor.green = 256 * pcolor.
G;
1213 xcolor.blue = 256 * pcolor.
B;
1214 XStoreColor ( display, lut, &xcolor );
1218 xcolor.pixel = 251 ;
1219 xcolor.red = 256 * pcolor.
R;
1220 xcolor.green = 256 * pcolor.
G;
1221 xcolor.blue = 256 * pcolor.
B;
1222 XStoreColor ( display, lut, &xcolor );
1226 xcolor.pixel = 250 ;
1227 xcolor.red = 256 * pcolor.
R;
1228 xcolor.green = 256 * pcolor.
G;
1229 xcolor.blue = 256 * pcolor.
B;
1230 XStoreColor ( display, lut, &xcolor );
1234 xcolor.pixel = 249 ;
1235 xcolor.red = 256 * pcolor.
R;
1236 xcolor.green = 256 * pcolor.
G;
1237 xcolor.blue = 256 * pcolor.
B;
1238 XStoreColor ( display, lut, &xcolor );
1242 xcolor.pixel = 248 ;
1243 xcolor.red = 256 * pcolor.
R;
1244 xcolor.green = 256 * pcolor.
G;
1245 xcolor.blue = 256 * pcolor.
B;
1246 XStoreColor ( display, lut, &xcolor );
1251 xcolor.red = 256 * pcolor.
R;
1252 xcolor.green = 256 * pcolor.
G;
1253 xcolor.blue = 256 * pcolor.
B;
1254 XStoreColor ( display, lut, &xcolor );
1258 xcolor.pixel = 246 ;
1259 xcolor.red = 256 * pcolor.
R;
1260 xcolor.green = 256 * pcolor.
G;
1261 xcolor.blue = 256 * pcolor.
B;
1262 XStoreColor ( display, lut, &xcolor );
1266 xcolor.pixel = 245 ;
1267 xcolor.red = 256 * pcolor.
R;
1268 xcolor.green = 256 * pcolor.
G;
1269 xcolor.blue = 256 * pcolor.
B;
1270 XStoreColor ( display, lut, &xcolor );
1275 xcolor.red = 256 * pcolor.
R;
1276 xcolor.green = 256 * pcolor.
G;
1277 xcolor.blue = 256 * pcolor.
B;
1278 XStoreColor ( display, lut, &xcolor );
1282 xcolor.pixel = 243 ;
1283 xcolor.red = 256 * pcolor.
R;
1284 xcolor.green = 256 * pcolor.
G;
1285 xcolor.blue = 256 * pcolor.
B;
1286 XStoreColor ( display, lut, &xcolor );
1291 xcolor.red = 256 * pcolor.
R;
1292 xcolor.green = 256 * pcolor.
G;
1293 xcolor.blue = 256 * pcolor.
B;
1294 XStoreColor ( display, lut, &xcolor );
1299 xcolor.red = 256 * pcolor.
R;
1300 xcolor.green = 256 * pcolor.
G;
1301 xcolor.blue = 256 * pcolor.
B;
1302 XStoreColor ( display, lut, &xcolor );
1307 xcolor.red = 256 * pcolor.
R;
1308 xcolor.green = 256 * pcolor.
G;
1309 xcolor.blue = 256 * pcolor.
B;
1310 XStoreColor ( display, lut, &xcolor );
1315 xcolor.red = 256 * pcolor.
R;
1316 xcolor.green = 256 * pcolor.
G;
1317 xcolor.blue = 256 * pcolor.
B;
1318 XStoreColor ( display, lut, &xcolor );
1325 xcolor.flags = DoRed | DoGreen | DoBlue ;
1330 xcolor.red = 256 * pcolor.
R;
1331 xcolor.green = 256 * pcolor.
G;
1332 xcolor.blue = 256 * pcolor.
B;
1333 XAllocColor ( display, lut, &xcolor );
1339 xcolor.red = 256 * pcolor.
R;
1340 xcolor.green = 256 * pcolor.
G;
1341 xcolor.blue = 256 * pcolor.
B;
1342 XAllocColor ( display, lut, &xcolor );
1348 xcolor.red = 256 * pcolor.
R;
1349 xcolor.green = 256 * pcolor.
G;
1350 xcolor.blue = 256 * pcolor.
B;
1351 XAllocColor ( display, lut, &xcolor );
1357 xcolor.red = 256 * pcolor.
R;
1358 xcolor.green = 256 * pcolor.
G;
1359 xcolor.blue = 256 * pcolor.
B;
1360 XAllocColor ( display, lut, &xcolor );
1366 xcolor.red = 256 * pcolor.
R;
1367 xcolor.green = 256 * pcolor.
G;
1368 xcolor.blue = 256 * pcolor.
B;
1369 XAllocColor ( display, lut, &xcolor );
1375 xcolor.red = 256 * pcolor.
R;
1376 xcolor.green = 256 * pcolor.
G;
1377 xcolor.blue = 256 * pcolor.
B;
1378 XAllocColor ( display, lut, &xcolor );
1384 xcolor.red = 256 * pcolor.
R;
1385 xcolor.green = 256 * pcolor.
G;
1386 xcolor.blue = 256 * pcolor.
B;
1387 XAllocColor ( display, lut, &xcolor );
1393 xcolor.red = 256 * pcolor.
R;
1394 xcolor.green = 256 * pcolor.
G;
1395 xcolor.blue = 256 * pcolor.
B;
1396 XAllocColor ( display, lut, &xcolor );
1402 xcolor.red = 256 * pcolor.
R;
1403 xcolor.green = 256 * pcolor.
G;
1404 xcolor.blue = 256 * pcolor.
B;
1405 XAllocColor ( display, lut, &xcolor );
1411 xcolor.red = 256 * pcolor.
R;
1412 xcolor.green = 256 * pcolor.
G;
1413 xcolor.blue = 256 * pcolor.
B;
1414 XAllocColor ( display, lut, &xcolor );
1420 xcolor.red = 256 * pcolor.
R;
1421 xcolor.green = 256 * pcolor.
G;
1422 xcolor.blue = 256 * pcolor.
B;
1423 XAllocColor ( display, lut, &xcolor );
1429 xcolor.red = 256 * pcolor.
R;
1430 xcolor.green = 256 * pcolor.
G;
1431 xcolor.blue = 256 * pcolor.
B;
1432 XAllocColor ( display, lut, &xcolor );
1438 xcolor.red = 256 * pcolor.
R;
1439 xcolor.green = 256 * pcolor.
G;
1440 xcolor.blue = 256 * pcolor.
B;
1441 XAllocColor ( display, lut, &xcolor );
1447 xcolor.red = 256 * pcolor.
R;
1448 xcolor.green = 256 * pcolor.
G;
1449 xcolor.blue = 256 * pcolor.
B;
1450 XAllocColor ( display, lut, &xcolor );
1456 xcolor.red = 256 * pcolor.
R;
1457 xcolor.green = 256 * pcolor.
G;
1458 xcolor.blue = 256 * pcolor.
B;
1459 XAllocColor ( display, lut, &xcolor );
1465 xcolor.red = 256 * pcolor.
R;
1466 xcolor.green = 256 * pcolor.
G;
1467 xcolor.blue = 256 * pcolor.
B;
1468 XAllocColor ( display, lut, &xcolor );
1474 xcolor.red = 256 * pcolor.
R;
1475 xcolor.green = 256 * pcolor.
G;
1476 xcolor.blue = 256 * pcolor.
B;
1477 XAllocColor ( display, lut, &xcolor );
1483 xcolor.red = 256 * pcolor.
R;
1484 xcolor.green = 256 * pcolor.
G;
1485 xcolor.blue = 256 * pcolor.
B;
1486 XAllocColor ( display, lut, &xcolor );
1492 XSetStandardProperties ( display, window, this->title, this->title, None, 0, 0, &hints );
1493 XMapWindow ( display, window ) ;
1495 XSelectInput ( display, window,
1497 ButtonPressMask | ButtonReleaseMask |
1498 KeyPressMask | KeyReleaseMask |
1499 StructureNotifyMask |
1503 values.plane_mask = AllPlanes;
1504 values.fill_style = FillSolid;
1505 values.foreground = WhitePixel ( display, screen );
1506 values.background = BlackPixel ( display, screen );
1507 context = XCreateGC ( display, window,
1508 GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
1511 if ( context == NULL )
1515 "Can't create graphics context" ) ) ;
1519 pixmap = XCreatePixmap ( display, window, width, height, screen_depth );
1522 XNextEvent ( display, &event );
1523 while ( event.xany.type != Expose );
1526 Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
1527 screen_depth, ZPixmap, 0, NULL,
1528 width, height, XBitmapPad ( display ), 0 );
1530 Ximage->data = (
char * ) malloc ( width * height
1531 * (
unsigned int)Ximage->bits_per_pixel / 8 );
1532 ximage_data_init =
true;
1536 XSync ( display,
true );
1564 stringfont = XLoadFont (display, font) ;
1565 XSetFont (display, context, stringfont);
1578 "X not initialized" ) ) ;
1591 XStoreName ( display, window, title );
1597 "X not initialized" ) ) ;
1612 XMoveWindow(display, window, winx, winy);
1618 "X not initialized" ) ) ;
1638 switch ( screen_depth )
1642 unsigned char *src_8 = NULL;
1643 unsigned char *dst_8 = NULL;
1644 src_8 = (
unsigned char * ) I.
bitmap;
1645 dst_8 = (
unsigned char * ) Ximage->data;
1651 unsigned char nivGris;
1656 nivGris = src_8[i] ;
1657 if ( nivGris > nivGrisMax )
1666 XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0,
width,
height );
1667 XSetWindowBackgroundPixmap ( display, window, pixmap );
1674 unsigned short *dst_16 = NULL;
1675 dst_16 = (
unsigned short* ) Ximage->data;
1677 for (
unsigned int i = 0; i <
height ; i++ )
1679 for (
unsigned int j=0 ; j <
width; j++ )
1681 * ( dst_16+ ( i*width+j ) ) = (
unsigned short ) colortable[I[i][j]] ;
1686 XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0,
width, height );
1687 XSetWindowBackgroundPixmap ( display, window, pixmap );
1696 unsigned char *dst_32 = NULL;
1698 dst_32 = (
unsigned char* ) Ximage->data;
1699 unsigned char *bitmap = I.
bitmap ;
1700 unsigned char *n = I.
bitmap + size;
1702 while ( bitmap < n )
1704 unsigned char val = * ( bitmap++ );
1705 * ( dst_32 ++ ) = val;
1706 * ( dst_32 ++ ) = val;
1707 * ( dst_32 ++ ) = val;
1708 * ( dst_32 ++ ) = val;
1712 XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0,
width, height );
1713 XSetWindowBackgroundPixmap ( display, window, pixmap );
1724 "X not initialized" ) ) ;
1744 switch ( screen_depth )
1753 unsigned char *dst_32 = NULL;
1754 dst_32 = (
unsigned char* ) Ximage->data;
1759 for (
unsigned int i = 0; i < sizeI ; i++ )
1761 *(dst_32++) = bitmap->A;
1762 *(dst_32++) = bitmap->R;
1763 *(dst_32++) = bitmap->G;
1764 *(dst_32++) = bitmap->B;
1768 for (
unsigned int i = 0; i < sizeI; i++ )
1770 *(dst_32++) = bitmap->B;
1771 *(dst_32++) = bitmap->G;
1772 *(dst_32++) = bitmap->R;
1773 *(dst_32++) = bitmap->A;
1778 XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0,
width,
height );
1779 XSetWindowBackgroundPixmap ( display, window, pixmap );
1786 vpERROR_TRACE (
"Unsupported depth (%d bpp) for color display",
1789 "Unsupported depth for color display" ) ) ;
1796 "X not initialized" ) ) ;
1813 unsigned char *dst_32 = NULL;
1818 dst_32 = (
unsigned char* ) Ximage->data;
1820 for (
unsigned int i = 0; i <
width *
height; i++ )
1822 * ( dst_32 ++ ) = *I;
1823 * ( dst_32 ++ ) = *I;
1824 * ( dst_32 ++ ) = *I;
1825 * ( dst_32 ++ ) = *I;
1830 XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0,
width, height );
1831 XSetWindowBackgroundPixmap ( display, window, pixmap );
1839 "X not initialized" ) ) ;
1865 switch ( screen_depth )
1869 unsigned char *src_8 = NULL;
1870 unsigned char *dst_8 = NULL;
1871 src_8 = (
unsigned char * ) I.
bitmap;
1872 dst_8 = (
unsigned char * ) Ximage->data;
1877 unsigned char nivGris;
1881 unsigned int iwidth = I.
getWidth();
1883 src_8 = src_8 + (int)(iP.
get_i()*iwidth+ iP.
get_j());
1884 dst_8 = dst_8 + (int)(iP.
get_i()*this->height+ iP.
get_j());
1892 nivGris = *(src_8+j);
1893 if ( nivGris > nivGrisMax )
1896 *(dst_8+j) = nivGris;
1899 src_8 = src_8 + iwidth;
1900 dst_8 = dst_8 + this->
height;
1907 XSetWindowBackgroundPixmap ( display, window, pixmap );
1914 unsigned short *dst_16 = NULL;
1915 dst_16 = (
unsigned short* ) Ximage->data;
1916 unsigned char *src_8 = NULL;
1917 src_8 = (
unsigned char * ) I.
bitmap;
1919 unsigned int iwidth = I.
getWidth();
1921 src_8 = src_8 + (int)(iP.
get_i()*iwidth+ iP.
get_j());
1922 dst_16 = dst_16 + (int)(iP.
get_i()*this->height+ iP.
get_j());
1930 *(dst_16+j) = (
unsigned short ) colortable[*(src_8+j)];
1933 src_8 = src_8 + iwidth;
1934 dst_16 = dst_16 + this->
height;
1940 XSetWindowBackgroundPixmap ( display, window, pixmap );
1949 unsigned char *dst_32 = NULL;
1951 dst_32 = (
unsigned char* ) Ximage->data;
1952 unsigned char *src_8 = I.
bitmap ;
1955 unsigned int iwidth = I.
getWidth();
1957 src_8 = src_8 + (int)(iP.
get_i()*iwidth+ iP.
get_j());
1958 dst_32 = dst_32 + (int)(iP.
get_i()*4*this->width+ iP.
get_j()*4);
1966 unsigned char val = *(src_8+j);
1967 *(dst_32+4*j) = val;
1968 *(dst_32+4*j+1) = val;
1969 *(dst_32+4*j+2) = val;
1970 *(dst_32+4*j+3) = val;
1973 src_8 = src_8 + iwidth;
1974 dst_32 = dst_32 + 4*this->
width;
1980 XSetWindowBackgroundPixmap ( display, window, pixmap );
1991 "X not initialized" ) ) ;
2019 switch ( screen_depth )
2028 unsigned char *dst_32 = NULL;
2029 dst_32 = (
unsigned char* ) Ximage->data;
2033 unsigned int iwidth = I.
getWidth();
2035 src_32 = src_32 + (int)(iP.
get_i()*iwidth+ iP.
get_j());
2036 dst_32 = dst_32 + (int)(iP.
get_i()*4*this->width+ iP.
get_j()*4);
2045 *(dst_32+4*j) = (src_32+j)->A;
2046 *(dst_32+4*j+1) = (src_32+j)->R;
2047 *(dst_32+4*j+2) = (src_32+j)->G;
2048 *(dst_32+4*j+3) = (src_32+j)->B;
2050 *(dst_32+4*j) = (src_32+j)->B;
2051 *(dst_32+4*j+1) = (src_32+j)->G;
2052 *(dst_32+4*j+2) = (src_32+j)->R;
2053 *(dst_32+4*j+3) = (src_32+j)->A;
2057 src_32 = src_32 + iwidth;
2058 dst_32 = dst_32 + 4*this->
width;
2064 XSetWindowBackgroundPixmap ( display, window, pixmap );
2071 vpERROR_TRACE (
"Unsupported depth (%d bpp) for color display",
2074 "Unsupported depth for color display" ) ) ;
2081 "X not initialized" ) ) ;
2096 if ( ximage_data_init ==
true )
2097 free ( Ximage->data );
2099 Ximage->data = NULL;
2100 XDestroyImage ( Ximage );
2102 XFreePixmap ( display, pixmap );
2104 XFreeGC ( display, context );
2105 XDestroyWindow ( display, window );
2106 XCloseDisplay ( display );
2110 if (x_color != NULL) {
2127 XClearWindow ( display, window );
2135 "X not initialized" ) ) ;
2159 "X not initialized" ) ) ;
2174 XSetWindowBackground ( display, window, x_color[color.
id] );
2177 xcolor.red = 256 * color.
R;
2178 xcolor.green = 256 * color.
G;
2179 xcolor.blue = 256 * color.
B;
2180 XAllocColor ( display, lut, &xcolor );
2181 XSetForeground ( display, context, xcolor.pixel );
2184 XClearWindow ( display, window );
2186 XFreePixmap ( display, pixmap );
2188 pixmap = XCreatePixmap ( display, window,
width,
height, screen_depth );
2194 "X not initialized" ) ) ;
2208 unsigned int w,
unsigned int h,
2209 unsigned int thickness)
2220 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon() )&&(std::fabs(b) <= std::numeric_limits<double>::epsilon()) )
2256 "X not initialized" ) ) ;
2278 XSetForeground ( display, context, x_color[color.
id] );
2281 xcolor.red = 256 * color.
R;
2282 xcolor.green = 256 * color.
G;
2283 xcolor.blue = 256 * color.
B;
2284 XAllocColor ( display, lut, &xcolor );
2285 XSetForeground ( display, context, xcolor.pixel );
2287 XDrawString ( display, pixmap, context,
2289 text, (int)strlen ( text ) );
2295 "X not initialized" ) ) ;
2309 unsigned int radius,
2312 unsigned int thickness )
2316 if ( thickness == 1 ) thickness = 0;
2318 XSetForeground ( display, context, x_color[color.
id] );
2321 xcolor.red = 256 * color.
R;
2322 xcolor.green = 256 * color.
G;
2323 xcolor.blue = 256 * color.
B;
2324 XAllocColor ( display, lut, &xcolor );
2325 XSetForeground ( display, context, xcolor.pixel );
2328 XSetLineAttributes ( display, context, thickness,
2329 LineSolid, CapButt, JoinBevel );
2331 if ( fill ==
false )
2333 XDrawArc ( display, pixmap, context,
2336 radius*2, radius*2, 0, 23040 );
2340 XFillArc ( display, pixmap, context,
2343 radius*2, radius*2, 0, 23040 );
2350 "X not initialized" ) ) ;
2364 unsigned int thickness)
2370 double i = ip.
get_i();
2371 double j = ip.
get_j();
2374 ip1.
set_i( i-size/2 );
2376 ip2.
set_i( i+size/2 );
2381 ip1.
set_j( j-size/2 );
2383 ip2.
set_j( j+size/2 );
2398 "X not initialized" ) ) ;
2411 unsigned int thickness )
2416 if ( thickness == 1 ) thickness = 0;
2419 XSetForeground ( display, context, x_color[color.
id] );
2422 xcolor.red = 256 * color.
R;
2423 xcolor.green = 256 * color.
G;
2424 xcolor.blue = 256 * color.
B;
2425 XAllocColor ( display, lut, &xcolor );
2426 XSetForeground ( display, context, xcolor.pixel );
2429 XSetLineAttributes ( display, context, thickness,
2430 LineOnOffDash, CapButt, JoinBevel );
2432 XDrawLine ( display, pixmap, context,
2442 "X not initialized" ) ) ;
2455 unsigned int thickness )
2459 if ( thickness == 1 ) thickness = 0;
2462 XSetForeground ( display, context, x_color[color.
id] );
2465 xcolor.red = 256 * color.
R;
2466 xcolor.green = 256 * color.
G;
2467 xcolor.blue = 256 * color.
B;
2468 XAllocColor ( display, lut, &xcolor );
2469 XSetForeground ( display, context, xcolor.pixel );
2472 XSetLineAttributes ( display, context, thickness,
2473 LineSolid, CapButt, JoinBevel );
2475 XDrawLine ( display, pixmap, context,
2485 "X not initialized" ) ) ;
2500 XSetForeground ( display, context, x_color[color.
id] );
2503 xcolor.red = 256 * color.
R;
2504 xcolor.green = 256 * color.
G;
2505 xcolor.blue = 256 * color.
B;
2506 XAllocColor ( display, lut, &xcolor );
2507 XSetForeground ( display, context, xcolor.pixel );
2510 XDrawPoint ( display, pixmap, context,
2518 "X not initialized" ) ) ;
2537 unsigned int width,
unsigned int height,
2538 const vpColor &color,
bool fill,
2539 unsigned int thickness )
2543 if ( thickness == 1 ) thickness = 0;
2545 XSetForeground ( display, context, x_color[color.
id] );
2548 xcolor.red = 256 * color.
R;
2549 xcolor.green = 256 * color.
G;
2550 xcolor.blue = 256 * color.
B;
2551 XAllocColor ( display, lut, &xcolor );
2552 XSetForeground ( display, context, xcolor.pixel );
2554 XSetLineAttributes ( display, context, thickness,
2555 LineSolid, CapButt, JoinBevel );
2556 if ( fill ==
false )
2558 XDrawRectangle ( display, pixmap, context,
2561 width-1, height-1 );
2565 XFillRectangle ( display, pixmap, context,
2575 "X not initialized" ) ) ;
2594 const vpColor &color,
bool fill,
2595 unsigned int thickness )
2599 if ( thickness == 1 ) thickness = 0;
2601 XSetForeground ( display, context, x_color[color.
id] );
2604 xcolor.red = 256 * color.
R;
2605 xcolor.green = 256 * color.
G;
2606 xcolor.blue = 256 * color.
B;
2607 XAllocColor ( display, lut, &xcolor );
2608 XSetForeground ( display, context, xcolor.pixel );
2611 XSetLineAttributes ( display, context, thickness,
2612 LineSolid, CapButt, JoinBevel );
2616 if ( fill ==
false )
2619 XDrawRectangle ( display, pixmap, context,
2622 width > 0 ? width-1 : 1, height > 0 ? height : 1 );
2626 XFillRectangle ( display, pixmap, context,
2636 "X not initialized" ) ) ;
2654 const vpColor &color,
bool fill,
2655 unsigned int thickness )
2659 if ( thickness == 1 ) thickness = 0;
2661 XSetForeground ( display, context, x_color[color.
id] );
2664 xcolor.red = 256 * color.
R;
2665 xcolor.green = 256 * color.
G;
2666 xcolor.blue = 256 * color.
B;
2667 XAllocColor ( display, lut, &xcolor );
2668 XSetForeground ( display, context, xcolor.pixel );
2671 XSetLineAttributes ( display, context, thickness,
2672 LineSolid, CapButt, JoinBevel );
2674 if ( fill ==
false )
2676 XDrawRectangle ( display, pixmap, context,
2684 XFillRectangle ( display, pixmap, context,
2696 "X not initialized" ) ) ;
2723 Window rootwin, childwin ;
2724 int root_x, root_y, win_x, win_y ;
2725 unsigned int modifier ;
2729 XCheckMaskEvent(display , ButtonPressMask, &event);
2730 XCheckMaskEvent(display , ButtonReleaseMask, &event);
2731 XMaskEvent ( display, ButtonPressMask ,&event );
2735 ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2740 if ( XQueryPointer ( display,
2742 &rootwin, &childwin,
2751 "X not initialized" ) ) ;
2779 Window rootwin, childwin ;
2780 int root_x, root_y, win_x, win_y ;
2781 unsigned int modifier ;
2784 XCheckMaskEvent(display , ButtonPressMask, &event);
2785 XCheckMaskEvent(display , ButtonReleaseMask, &event);
2786 XMaskEvent ( display, ButtonPressMask ,&event );
2790 ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2795 if ( XQueryPointer ( display,
2797 &rootwin, &childwin,
2801 ip.
set_u( (
double)event.xbutton.x );
2802 ip.
set_v( (
double)event.xbutton.y );
2809 "X not initialized" ) ) ;
2842 Window rootwin, childwin ;
2843 int root_x, root_y, win_x, win_y ;
2844 unsigned int modifier ;
2848 XCheckMaskEvent(display , ButtonPressMask, &event);
2849 XCheckMaskEvent(display , ButtonReleaseMask, &event);
2850 XMaskEvent ( display, ButtonPressMask ,&event );
2854 ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2859 if ( XQueryPointer ( display,
2861 &rootwin, &childwin,
2865 ip.
set_u( (
double)event.xbutton.x );
2866 ip.
set_v( (
double)event.xbutton.y );
2867 switch ( event.xbutton.button ) {
2878 "X not initialized" ) ) ;
2914 Window rootwin, childwin ;
2915 int root_x, root_y, win_x, win_y ;
2916 unsigned int modifier ;
2920 XCheckMaskEvent(display , ButtonPressMask, &event);
2921 XCheckMaskEvent(display , ButtonReleaseMask, &event);
2922 XMaskEvent ( display, ButtonReleaseMask ,&event );
2926 ret = XCheckMaskEvent(display , ButtonReleaseMask, &event);
2931 if ( XQueryPointer ( display,
2933 &rootwin, &childwin,
2937 ip.
set_u( (
double)event.xbutton.x );
2938 ip.
set_v( (
double)event.xbutton.y );
2939 switch ( event.xbutton.button ) {
2950 "X not initialized" ) ) ;
2972 XCopyArea (display,window, pixmap, context,
2976 AllPlanes, ZPixmap ) ;
2988 unsigned char *src_32 = NULL;
2989 src_32 = (
unsigned char* ) xi->data;
2996 I.
bitmap[i].
R = src_32[i*4 + 1] ;
2997 I.
bitmap[i].
G = src_32[i*4 + 2] ;
2998 I.
bitmap[i].
B = src_32[i*4 + 3] ;
3004 I.
bitmap[i].
G = src_32[i*4 + 1] ;
3005 I.
bitmap[i].
R = src_32[i*4 + 2] ;
3006 I.
bitmap[i].
A = src_32[i*4 + 3] ;
3011 XDestroyImage ( xi ) ;
3018 "X not initialized" ) ) ;
3031 if ( ( _display = XOpenDisplay ( NULL ) ) == NULL )
3034 XDisplayName ( NULL ) );
3036 "Can't connect display on server." ) ) ;
3038 screen = DefaultScreen ( _display );
3039 depth = (
unsigned int)DefaultDepth ( _display, screen );
3041 XCloseDisplay ( _display );
3055 if ( ( _display = XOpenDisplay ( NULL ) ) == NULL )
3058 XDisplayName ( NULL ) );
3060 "Can't connect display on server." ) ) ;
3062 screen = DefaultScreen ( _display );
3063 width = (
unsigned int)DisplayWidth ( _display, screen );
3064 height = (
unsigned int)DisplayHeight ( _display, screen );
3066 XCloseDisplay ( _display );
3097 XMaskEvent ( display, KeyPressMask ,&event );
3101 ret = XCheckMaskEvent(display , KeyPressMask, &event);
3107 "X not initialized" ) ) ;
3141 XComposeStatus compose_status;
3147 XMaskEvent ( display, KeyPressMask ,&event );
3148 XLookupString ((XKeyEvent *)&event, &buffer, 1,
3149 &keysym, &compose_status);
3151 sprintf(
string,
"%c", buffer);
3155 ret = XCheckMaskEvent(display , KeyPressMask, &event);
3157 XLookupString ((XKeyEvent *)&event, &buffer, 1,
3158 &keysym, &compose_status);
3159 sprintf(
string,
"%c", buffer);
3166 "X not initialized" ) ) ;
3189 Window rootwin, childwin ;
3190 int root_x, root_y, win_x, win_y ;
3191 unsigned int modifier ;
3193 ret = XCheckMaskEvent(display , PointerMotionMask, &event);
3197 if ( XQueryPointer ( display,
3199 &rootwin, &childwin,
3203 ip.
set_u( (
double)event.xbutton.x );
3204 ip.
set_v( (
double)event.xbutton.y );
3211 "X not initialized" ) ) ;
3233 Window rootwin, childwin ;
3234 int root_x, root_y, win_x, win_y ;
3235 unsigned int modifier ;
3241 if ( XQueryPointer ( display,
3243 &rootwin, &childwin,
3247 ip.
set_u( (
double)win_x );
3248 ip.
set_v( (
double)win_y );
3255 "X not initialized" ) ) ;