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 ) ;
105 init ( I, x, y, title ) ;
135 this->x_color = NULL;
140 this->title =
new char[strlen ( title ) + 1] ;
141 strcpy ( this->title, title ) ;
144 ximage_data_init =
false;
172 title =
new char[1] ;
173 strcpy (
title,
"" ) ;
176 ximage_data_init =
false;
199 if (x_color == NULL) {
208 if ( this->title != NULL )
211 delete [] this->
title ;
217 this->title =
new char[strlen ( title ) + 1] ;
218 strcpy ( this->title, title ) ;
229 hints.flags = USPosition;
238 display = XOpenDisplay ( NULL );
239 if ( display == NULL )
241 vpERROR_TRACE (
"Can't connect display on server %s.\n", XDisplayName ( NULL ) );
243 "Can't connect display on server." ) ) ;
246 screen = DefaultScreen ( display );
247 lut = DefaultColormap ( display, screen );
248 screen_depth = (
unsigned int)DefaultDepth ( display, screen );
251 XCreateSimpleWindow ( display, RootWindow ( display, screen ),
253 BlackPixel ( display, screen ),
254 WhitePixel ( display, screen ) ) ) == 0 )
258 "Can't create window." ) ) ;
264 if ( screen_depth == 8 )
266 lut = XCreateColormap ( display, window,
267 DefaultVisual ( display, screen ), AllocAll ) ;
268 xcolor.flags = DoRed | DoGreen | DoBlue ;
270 for (
unsigned int i = 0 ; i < 256 ; i++ )
273 xcolor.red = 256 * i;
274 xcolor.green = 256 * i;
275 xcolor.blue = 256 * i;
276 XStoreColor ( display, lut, &xcolor );
279 XSetWindowColormap ( display, window, lut ) ;
280 XInstallColormap ( display, lut ) ;
283 else if ( screen_depth == 16 )
285 for (
unsigned int i = 0; i < 256; i ++ )
288 xcolor.red = xcolor.green = xcolor.blue = 256 * i;
289 if ( XAllocColor ( display, lut, &xcolor ) == 0 )
291 vpERROR_TRACE (
"Can't allocate 256 colors. Only %d allocated.", i );
293 "Can't allocate 256 colors." ) ) ;
295 colortable[i] = xcolor.pixel;
298 XSetWindowColormap ( display, window, lut ) ;
299 XInstallColormap ( display, lut ) ;
306 switch ( screen_depth )
314 xcolor.red = 256 * 192;
315 xcolor.green = 256 * 192;
316 xcolor.blue = 256 * 192;
317 XStoreColor ( display, lut, &xcolor );
322 xcolor.red = 256 * 128;
323 xcolor.green = 256 * 128;
324 xcolor.blue = 256 * 128;
325 XStoreColor ( display, lut, &xcolor );
330 xcolor.red = 256 * 64;
331 xcolor.green = 256 * 64;
332 xcolor.blue = 256 * 64;
333 XStoreColor ( display, lut, &xcolor );
338 xcolor.red = 256 * 255;
339 xcolor.green = 256 * 140;
340 xcolor.blue = 256 * 140;
341 XStoreColor ( display, lut, &xcolor );
346 xcolor.red = 256 * 255;
349 XStoreColor ( display, lut, &xcolor );
354 xcolor.red = 256 * 128;
357 XStoreColor ( display, lut, &xcolor );
362 xcolor.red = 256 * 140;
363 xcolor.green = 256 * 255;
364 xcolor.blue = 256 * 140;
365 XStoreColor ( display, lut, &xcolor );
371 xcolor.green = 256 * 255;
373 XStoreColor ( display, lut, &xcolor );
379 xcolor.green = 256 * 128;
381 XStoreColor ( display, lut, &xcolor );
386 xcolor.red = 256 * 140;
387 xcolor.green = 256 * 140;
388 xcolor.blue = 256 * 255;
389 XStoreColor ( display, lut, &xcolor );
396 xcolor.blue = 256 * 255;
397 XStoreColor ( display, lut, &xcolor );
404 xcolor.blue = 256 * 128;
405 XStoreColor ( display, lut, &xcolor );
410 xcolor.red = 256 * 255;
411 xcolor.green = 256 * 255;
413 XStoreColor ( display, lut, &xcolor );
418 xcolor.red = 256 * 255;
419 xcolor.green = 256 * 165;
421 XStoreColor ( display, lut, &xcolor );
427 xcolor.green = 256 * 255;
428 xcolor.blue = 256 * 255;
429 XStoreColor ( display, lut, &xcolor );
434 xcolor.red = 256 * 128;
436 xcolor.blue = 256 * 128;
437 XStoreColor ( display, lut, &xcolor );
444 xcolor.flags = DoRed | DoGreen | DoBlue ;
451 XAllocColor ( display, lut, &xcolor );
456 xcolor.red = 256* 255;
457 xcolor.green = 256* 255;
458 xcolor.blue = 256* 255;
459 XAllocColor ( display, lut, &xcolor );
464 xcolor.red = 256 * 192;
465 xcolor.green = 256 * 192;
466 xcolor.blue = 256 * 192;
467 XAllocColor ( display, lut, &xcolor );
472 xcolor.red = 256 * 128;
473 xcolor.green = 256 * 128;
474 xcolor.blue = 256 * 128;
475 XAllocColor ( display, lut, &xcolor );
480 xcolor.red = 256 * 64;
481 xcolor.green = 256 * 64;
482 xcolor.blue = 256 * 64;
483 XAllocColor ( display, lut, &xcolor );
488 xcolor.red = 256 * 255;
489 xcolor.green = 256 * 140;
490 xcolor.blue = 256 * 140;
491 XAllocColor ( display, lut, &xcolor );
496 xcolor.red = 256* 255;
499 XAllocColor ( display, lut, &xcolor );
504 xcolor.red = 256* 128;
507 XAllocColor ( display, lut, &xcolor );
512 xcolor.red = 256 * 140;
513 xcolor.green = 256 * 255;
514 xcolor.blue = 256 * 140;
515 XAllocColor ( display, lut, &xcolor );
521 xcolor.green = 256*255;
523 XAllocColor ( display, lut, &xcolor );
529 xcolor.green = 256* 128;
531 XAllocColor ( display, lut, &xcolor );
536 xcolor.red = 256 * 140;
537 xcolor.green = 256 * 140;
538 xcolor.blue = 256 * 255;
539 XAllocColor ( display, lut, &xcolor );
546 xcolor.blue = 256* 255;
547 XAllocColor ( display, lut, &xcolor );
554 xcolor.blue = 256* 128;
555 XAllocColor ( display, lut, &xcolor );
560 xcolor.red = 256 * 255;
561 xcolor.green = 256 * 255;
563 XAllocColor ( display, lut, &xcolor );
568 xcolor.red = 256 * 255;
569 xcolor.green = 256 * 165;
571 XAllocColor ( display, lut, &xcolor );
577 xcolor.green = 256 * 255;
578 xcolor.blue = 256 * 255;
579 XAllocColor ( display, lut, &xcolor );
584 xcolor.red = 256 * 128;
586 xcolor.blue = 256 * 128;
587 XAllocColor ( display, lut, &xcolor );
593 XSetStandardProperties ( display, window, title, title, None, 0, 0, &hints );
594 XMapWindow ( display, window ) ;
596 XSelectInput ( display, window,
598 ButtonPressMask | ButtonReleaseMask |
599 KeyPressMask | KeyReleaseMask |
600 StructureNotifyMask |
604 values.plane_mask = AllPlanes;
605 values.fill_style = FillSolid;
606 values.foreground = WhitePixel ( display, screen );
607 values.background = BlackPixel ( display, screen );
608 context = XCreateGC ( display, window,
609 GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
612 if ( context == NULL )
616 "Can't create graphics context" ) ) ;
621 pixmap = XCreatePixmap ( display, window,
width,
height, screen_depth );
624 XNextEvent ( display, &event );
625 while ( event.xany.type != Expose );
628 Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
629 screen_depth, ZPixmap, 0, NULL,
632 Ximage->data = (
char * ) malloc ( I.
getWidth() * I.
getHeight() * (
unsigned int)Ximage->bits_per_pixel / 8 );
633 ximage_data_init =
true;
638 XSync ( display, 1 );
660 if (x_color == NULL) {
666 if ( this->title != NULL )
668 delete [] this->
title ;
674 this->title =
new char[strlen ( title ) + 1] ;
675 strcpy ( this->title, title ) ;
686 hints.flags = USPosition;
696 if ( ( display = XOpenDisplay ( NULL ) ) == NULL )
698 vpERROR_TRACE (
"Can't connect display on server %s.\n", XDisplayName ( NULL ) );
700 "Can't connect display on server." ) ) ;
703 screen = DefaultScreen ( display );
704 lut = DefaultColormap ( display, screen );
705 screen_depth = (
unsigned int)DefaultDepth ( display, screen );
709 if ( ( window = XCreateSimpleWindow ( display, RootWindow ( display, screen ),
712 BlackPixel ( display, screen ),
713 WhitePixel ( display, screen ) ) ) == 0 )
717 "Can't create window." ) ) ;
723 if ( screen_depth == 8 )
725 lut = XCreateColormap ( display, window,
726 DefaultVisual ( display, screen ), AllocAll ) ;
727 xcolor.flags = DoRed | DoGreen | DoBlue ;
729 for (
unsigned int i = 0 ; i < 256 ; i++ )
732 xcolor.red = 256 * i;
733 xcolor.green = 256 * i;
734 xcolor.blue = 256 * i;
735 XStoreColor ( display, lut, &xcolor );
738 XSetWindowColormap ( display, window, lut ) ;
739 XInstallColormap ( display, lut ) ;
742 else if ( screen_depth == 16 )
744 for (
unsigned int i = 0; i < 256; i ++ )
747 xcolor.red = xcolor.green = xcolor.blue = 256 * i;
748 if ( XAllocColor ( display, lut, &xcolor ) == 0 )
750 vpERROR_TRACE (
"Can't allocate 256 colors. Only %d allocated.", i );
752 "Can't allocate 256 colors." ) ) ;
754 colortable[i] = xcolor.pixel;
757 XSetWindowColormap ( display, window, lut ) ;
758 XInstallColormap ( display, lut ) ;
766 switch ( screen_depth )
775 xcolor.red = 256 * 192;
776 xcolor.green = 256 * 192;
777 xcolor.blue = 256 * 192;
778 XStoreColor ( display, lut, &xcolor );
783 xcolor.red = 256 * 128;
784 xcolor.green = 256 * 128;
785 xcolor.blue = 256 * 128;
786 XStoreColor ( display, lut, &xcolor );
791 xcolor.red = 256 * 64;
792 xcolor.green = 256 * 64;
793 xcolor.blue = 256 * 64;
794 XStoreColor ( display, lut, &xcolor );
799 xcolor.red = 256 * 255;
800 xcolor.green = 256 * 140;
801 xcolor.blue = 256 * 140;
802 XStoreColor ( display, lut, &xcolor );
807 xcolor.red = 256 * 255;
810 XStoreColor ( display, lut, &xcolor );
815 xcolor.red = 256 * 128;
818 XStoreColor ( display, lut, &xcolor );
823 xcolor.red = 256 * 140;
824 xcolor.green = 256 * 255;
825 xcolor.blue = 256 * 140;
826 XStoreColor ( display, lut, &xcolor );
832 xcolor.green = 256 * 255;
834 XStoreColor ( display, lut, &xcolor );
840 xcolor.green = 256 * 128;
842 XStoreColor ( display, lut, &xcolor );
847 xcolor.red = 256 * 140;
848 xcolor.green = 256 * 140;
849 xcolor.blue = 256 * 255;
850 XStoreColor ( display, lut, &xcolor );
857 xcolor.blue = 256 * 255;
858 XStoreColor ( display, lut, &xcolor );
865 xcolor.blue = 256 * 128;
866 XStoreColor ( display, lut, &xcolor );
871 xcolor.red = 256 * 255;
872 xcolor.green = 256 * 255;
874 XStoreColor ( display, lut, &xcolor );
879 xcolor.red = 256 * 255;
880 xcolor.green = 256 * 165;
882 XStoreColor ( display, lut, &xcolor );
888 xcolor.green = 256 * 255;
889 xcolor.blue = 256 * 255;
890 XStoreColor ( display, lut, &xcolor );
895 xcolor.red = 256 * 128;
897 xcolor.blue = 256 * 128;
898 XStoreColor ( display, lut, &xcolor );
905 xcolor.flags = DoRed | DoGreen | DoBlue ;
912 XAllocColor ( display, lut, &xcolor );
917 xcolor.red = 256* 255;
918 xcolor.green = 256* 255;
919 xcolor.blue = 256* 255;
920 XAllocColor ( display, lut, &xcolor );
925 xcolor.red = 256 * 192;
926 xcolor.green = 256 * 192;
927 xcolor.blue = 256 * 192;
928 XAllocColor ( display, lut, &xcolor );
933 xcolor.red = 256 * 128;
934 xcolor.green = 256 * 128;
935 xcolor.blue = 256 * 128;
936 XAllocColor ( display, lut, &xcolor );
941 xcolor.red = 256 * 64;
942 xcolor.green = 256 * 64;
943 xcolor.blue = 256 * 64;
944 XAllocColor ( display, lut, &xcolor );
949 xcolor.red = 256 * 255;
950 xcolor.green = 256 * 140;
951 xcolor.blue = 256 * 140;
952 XAllocColor ( display, lut, &xcolor );
957 xcolor.red = 256* 255;
960 XAllocColor ( display, lut, &xcolor );
965 xcolor.red = 256* 128;
968 XAllocColor ( display, lut, &xcolor );
973 xcolor.red = 256 * 140;
974 xcolor.green = 256 * 255;
975 xcolor.blue = 256 * 140;
976 XAllocColor ( display, lut, &xcolor );
982 xcolor.green = 256*255;
984 XAllocColor ( display, lut, &xcolor );
990 xcolor.green = 256* 128;
992 XAllocColor ( display, lut, &xcolor );
997 xcolor.red = 256 * 140;
998 xcolor.green = 256 * 140;
999 xcolor.blue = 256 * 255;
1000 XAllocColor ( display, lut, &xcolor );
1007 xcolor.blue = 256* 255;
1008 XAllocColor ( display, lut, &xcolor );
1015 xcolor.blue = 256* 128;
1016 XAllocColor ( display, lut, &xcolor );
1021 xcolor.red = 256 * 255;
1022 xcolor.green = 256 * 255;
1024 XAllocColor ( display, lut, &xcolor );
1029 xcolor.red = 256 * 255;
1030 xcolor.green = 256 * 165;
1032 XAllocColor ( display, lut, &xcolor );
1038 xcolor.green = 256 * 255;
1039 xcolor.blue = 256 * 255;
1040 XAllocColor ( display, lut, &xcolor );
1045 xcolor.red = 256 * 128;
1047 xcolor.blue = 256 * 128;
1048 XAllocColor ( display, lut, &xcolor );
1054 XSetStandardProperties ( display, window, title, title, None, 0, 0, &hints );
1055 XMapWindow ( display, window ) ;
1057 XSelectInput ( display, window,
1059 ButtonPressMask | ButtonReleaseMask |
1060 KeyPressMask | KeyReleaseMask |
1061 StructureNotifyMask |
1065 values.plane_mask = AllPlanes;
1066 values.fill_style = FillSolid;
1067 values.foreground = WhitePixel ( display, screen );
1068 values.background = BlackPixel ( display, screen );
1069 context = XCreateGC ( display, window,
1070 GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
1073 if ( context == NULL )
1077 "Can't create graphics context" ) ) ;
1081 pixmap = XCreatePixmap ( display, window,
width,
height, screen_depth );
1084 XNextEvent ( display, &event );
1085 while ( event.xany.type != Expose );
1089 Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
1090 screen_depth, ZPixmap, 0, NULL,
1095 * (
unsigned int)Ximage->bits_per_pixel / 8 );
1096 ximage_data_init =
true;
1101 XSync ( display,
true );
1116 int x,
int y,
const char *title )
1120 this->width =
width;
1134 hints.flags = USPosition;
1141 if ( this->title != NULL )
1143 delete [] this->
title ;
1144 this->title = NULL ;
1147 if ( title != NULL )
1149 this->title =
new char[strlen ( title ) + 1] ;
1150 strcpy ( this->title, title ) ;
1155 if ( ( display = XOpenDisplay ( NULL ) ) == NULL )
1157 vpERROR_TRACE (
"Can't connect display on server %s.\n", XDisplayName ( NULL ) );
1159 "Can't connect display on server." ) ) ;
1162 screen = DefaultScreen ( display );
1163 lut = DefaultColormap ( display, screen );
1164 screen_depth = (
unsigned int)DefaultDepth ( display, screen );
1166 vpTRACE (
"Screen depth: %d\n", screen_depth );
1168 if ( ( window = XCreateSimpleWindow ( display, RootWindow ( display, screen ),
1171 BlackPixel ( display, screen ),
1172 WhitePixel ( display, screen ) ) ) == 0 )
1176 "Can't create window." ) ) ;
1183 if ( screen_depth == 8 )
1185 lut = XCreateColormap ( display, window,
1186 DefaultVisual ( display, screen ), AllocAll ) ;
1187 xcolor.flags = DoRed | DoGreen | DoBlue ;
1189 for (
unsigned int i = 0 ; i < 256 ; i++ )
1192 xcolor.red = 256 * i;
1193 xcolor.green = 256 * i;
1194 xcolor.blue = 256 * i;
1195 XStoreColor ( display, lut, &xcolor );
1198 XSetWindowColormap ( display, window, lut ) ;
1199 XInstallColormap ( display, lut ) ;
1202 else if ( screen_depth == 16 )
1204 for (
unsigned int i = 0; i < 256; i ++ )
1207 xcolor.red = xcolor.green = xcolor.blue = 256 * i;
1208 if ( XAllocColor ( display, lut, &xcolor ) == 0 )
1210 vpERROR_TRACE (
"Can't allocate 256 colors. Only %d allocated.", i );
1212 "Can't allocate 256 colors." ) ) ;
1214 colortable[i] = xcolor.pixel;
1217 XSetWindowColormap ( display, window, lut ) ;
1218 XInstallColormap ( display, lut ) ;
1227 switch ( screen_depth )
1237 xcolor.pixel = 254 ;
1238 xcolor.red = 256 * pcolor.
R;
1239 xcolor.green = 256 * pcolor.
G;
1240 xcolor.blue = 256 * pcolor.
B;
1241 XStoreColor ( display, lut, &xcolor );
1245 xcolor.pixel = 253 ;
1246 xcolor.red = 256 * pcolor.
R;
1247 xcolor.green = 256 * pcolor.
G;
1248 xcolor.blue = 256 * pcolor.
B;
1249 XStoreColor ( display, lut, &xcolor );
1253 xcolor.pixel = 252 ;
1254 xcolor.red = 256 * pcolor.
R;
1255 xcolor.green = 256 * pcolor.
G;
1256 xcolor.blue = 256 * pcolor.
B;
1257 XStoreColor ( display, lut, &xcolor );
1261 xcolor.pixel = 251 ;
1262 xcolor.red = 256 * pcolor.
R;
1263 xcolor.green = 256 * pcolor.
G;
1264 xcolor.blue = 256 * pcolor.
B;
1265 XStoreColor ( display, lut, &xcolor );
1269 xcolor.pixel = 250 ;
1270 xcolor.red = 256 * pcolor.
R;
1271 xcolor.green = 256 * pcolor.
G;
1272 xcolor.blue = 256 * pcolor.
B;
1273 XStoreColor ( display, lut, &xcolor );
1277 xcolor.pixel = 249 ;
1278 xcolor.red = 256 * pcolor.
R;
1279 xcolor.green = 256 * pcolor.
G;
1280 xcolor.blue = 256 * pcolor.
B;
1281 XStoreColor ( display, lut, &xcolor );
1285 xcolor.pixel = 248 ;
1286 xcolor.red = 256 * pcolor.
R;
1287 xcolor.green = 256 * pcolor.
G;
1288 xcolor.blue = 256 * pcolor.
B;
1289 XStoreColor ( display, lut, &xcolor );
1294 xcolor.red = 256 * pcolor.
R;
1295 xcolor.green = 256 * pcolor.
G;
1296 xcolor.blue = 256 * pcolor.
B;
1297 XStoreColor ( display, lut, &xcolor );
1301 xcolor.pixel = 246 ;
1302 xcolor.red = 256 * pcolor.
R;
1303 xcolor.green = 256 * pcolor.
G;
1304 xcolor.blue = 256 * pcolor.
B;
1305 XStoreColor ( display, lut, &xcolor );
1309 xcolor.pixel = 245 ;
1310 xcolor.red = 256 * pcolor.
R;
1311 xcolor.green = 256 * pcolor.
G;
1312 xcolor.blue = 256 * pcolor.
B;
1313 XStoreColor ( display, lut, &xcolor );
1318 xcolor.red = 256 * pcolor.
R;
1319 xcolor.green = 256 * pcolor.
G;
1320 xcolor.blue = 256 * pcolor.
B;
1321 XStoreColor ( display, lut, &xcolor );
1325 xcolor.pixel = 243 ;
1326 xcolor.red = 256 * pcolor.
R;
1327 xcolor.green = 256 * pcolor.
G;
1328 xcolor.blue = 256 * pcolor.
B;
1329 XStoreColor ( display, lut, &xcolor );
1334 xcolor.red = 256 * pcolor.
R;
1335 xcolor.green = 256 * pcolor.
G;
1336 xcolor.blue = 256 * pcolor.
B;
1337 XStoreColor ( display, lut, &xcolor );
1342 xcolor.red = 256 * pcolor.
R;
1343 xcolor.green = 256 * pcolor.
G;
1344 xcolor.blue = 256 * pcolor.
B;
1345 XStoreColor ( display, lut, &xcolor );
1350 xcolor.red = 256 * pcolor.
R;
1351 xcolor.green = 256 * pcolor.
G;
1352 xcolor.blue = 256 * pcolor.
B;
1353 XStoreColor ( display, lut, &xcolor );
1358 xcolor.red = 256 * pcolor.
R;
1359 xcolor.green = 256 * pcolor.
G;
1360 xcolor.blue = 256 * pcolor.
B;
1361 XStoreColor ( display, lut, &xcolor );
1368 xcolor.flags = DoRed | DoGreen | DoBlue ;
1373 xcolor.red = 256 * pcolor.
R;
1374 xcolor.green = 256 * pcolor.
G;
1375 xcolor.blue = 256 * pcolor.
B;
1376 XAllocColor ( display, lut, &xcolor );
1382 xcolor.red = 256 * pcolor.
R;
1383 xcolor.green = 256 * pcolor.
G;
1384 xcolor.blue = 256 * pcolor.
B;
1385 XAllocColor ( display, lut, &xcolor );
1391 xcolor.red = 256 * pcolor.
R;
1392 xcolor.green = 256 * pcolor.
G;
1393 xcolor.blue = 256 * pcolor.
B;
1394 XAllocColor ( display, lut, &xcolor );
1400 xcolor.red = 256 * pcolor.
R;
1401 xcolor.green = 256 * pcolor.
G;
1402 xcolor.blue = 256 * pcolor.
B;
1403 XAllocColor ( display, lut, &xcolor );
1409 xcolor.red = 256 * pcolor.
R;
1410 xcolor.green = 256 * pcolor.
G;
1411 xcolor.blue = 256 * pcolor.
B;
1412 XAllocColor ( display, lut, &xcolor );
1418 xcolor.red = 256 * pcolor.
R;
1419 xcolor.green = 256 * pcolor.
G;
1420 xcolor.blue = 256 * pcolor.
B;
1421 XAllocColor ( display, lut, &xcolor );
1427 xcolor.red = 256 * pcolor.
R;
1428 xcolor.green = 256 * pcolor.
G;
1429 xcolor.blue = 256 * pcolor.
B;
1430 XAllocColor ( display, lut, &xcolor );
1436 xcolor.red = 256 * pcolor.
R;
1437 xcolor.green = 256 * pcolor.
G;
1438 xcolor.blue = 256 * pcolor.
B;
1439 XAllocColor ( display, lut, &xcolor );
1445 xcolor.red = 256 * pcolor.
R;
1446 xcolor.green = 256 * pcolor.
G;
1447 xcolor.blue = 256 * pcolor.
B;
1448 XAllocColor ( display, lut, &xcolor );
1454 xcolor.red = 256 * pcolor.
R;
1455 xcolor.green = 256 * pcolor.
G;
1456 xcolor.blue = 256 * pcolor.
B;
1457 XAllocColor ( display, lut, &xcolor );
1463 xcolor.red = 256 * pcolor.
R;
1464 xcolor.green = 256 * pcolor.
G;
1465 xcolor.blue = 256 * pcolor.
B;
1466 XAllocColor ( display, lut, &xcolor );
1472 xcolor.red = 256 * pcolor.
R;
1473 xcolor.green = 256 * pcolor.
G;
1474 xcolor.blue = 256 * pcolor.
B;
1475 XAllocColor ( display, lut, &xcolor );
1481 xcolor.red = 256 * pcolor.
R;
1482 xcolor.green = 256 * pcolor.
G;
1483 xcolor.blue = 256 * pcolor.
B;
1484 XAllocColor ( display, lut, &xcolor );
1490 xcolor.red = 256 * pcolor.
R;
1491 xcolor.green = 256 * pcolor.
G;
1492 xcolor.blue = 256 * pcolor.
B;
1493 XAllocColor ( display, lut, &xcolor );
1499 xcolor.red = 256 * pcolor.
R;
1500 xcolor.green = 256 * pcolor.
G;
1501 xcolor.blue = 256 * pcolor.
B;
1502 XAllocColor ( display, lut, &xcolor );
1508 xcolor.red = 256 * pcolor.
R;
1509 xcolor.green = 256 * pcolor.
G;
1510 xcolor.blue = 256 * pcolor.
B;
1511 XAllocColor ( display, lut, &xcolor );
1517 xcolor.red = 256 * pcolor.
R;
1518 xcolor.green = 256 * pcolor.
G;
1519 xcolor.blue = 256 * pcolor.
B;
1520 XAllocColor ( display, lut, &xcolor );
1526 xcolor.red = 256 * pcolor.
R;
1527 xcolor.green = 256 * pcolor.
G;
1528 xcolor.blue = 256 * pcolor.
B;
1529 XAllocColor ( display, lut, &xcolor );
1536 XSetStandardProperties ( display, window, title, title, None, 0, 0, &hints );
1537 XMapWindow ( display, window ) ;
1539 XSelectInput ( display, window,
1541 ButtonPressMask | ButtonReleaseMask |
1542 KeyPressMask | KeyReleaseMask |
1543 StructureNotifyMask |
1547 values.plane_mask = AllPlanes;
1548 values.fill_style = FillSolid;
1549 values.foreground = WhitePixel ( display, screen );
1550 values.background = BlackPixel ( display, screen );
1551 context = XCreateGC ( display, window,
1552 GCPlaneMask | GCFillStyle | GCForeground | GCBackground,
1555 if ( context == NULL )
1559 "Can't create graphics context" ) ) ;
1563 pixmap = XCreatePixmap ( display, window, width, height, screen_depth );
1566 XNextEvent ( display, &event );
1567 while ( event.xany.type != Expose );
1570 Ximage = XCreateImage ( display, DefaultVisual ( display, screen ),
1571 screen_depth, ZPixmap, 0, NULL,
1572 width, height, XBitmapPad ( display ), 0 );
1574 Ximage->data = (
char * ) malloc ( width * height
1575 * (
unsigned int)Ximage->bits_per_pixel / 8 );
1576 ximage_data_init =
true;
1580 XSync ( display,
true );
1608 stringfont = XLoadFont (display, font) ;
1609 XSetFont (display, context, stringfont);
1622 "X not initialized" ) ) ;
1635 XStoreName ( display, window, title );
1641 "X not initialized" ) ) ;
1656 XMoveWindow(display, window, winx, winy);
1662 "X not initialized" ) ) ;
1682 switch ( screen_depth )
1686 unsigned char *src_8 = NULL;
1687 unsigned char *dst_8 = NULL;
1688 src_8 = (
unsigned char * ) I.
bitmap;
1689 dst_8 = (
unsigned char * ) Ximage->data;
1695 unsigned char nivGris;
1700 nivGris = src_8[i] ;
1701 if ( nivGris > nivGrisMax )
1710 XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0,
width,
height );
1711 XSetWindowBackgroundPixmap ( display, window, pixmap );
1718 unsigned short *dst_16 = NULL;
1719 dst_16 = (
unsigned short* ) Ximage->data;
1721 for (
unsigned int i = 0; i <
height ; i++ )
1723 for (
unsigned int j=0 ; j <
width; j++ )
1725 * ( dst_16+ ( i*width+j ) ) = (
unsigned short ) colortable[I[i][j]] ;
1730 XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0,
width, height );
1731 XSetWindowBackgroundPixmap ( display, window, pixmap );
1740 unsigned char *dst_32 = NULL;
1742 dst_32 = (
unsigned char* ) Ximage->data;
1743 unsigned char *bitmap = I.
bitmap ;
1744 unsigned char *n = I.
bitmap + size;
1746 while ( bitmap < n )
1748 unsigned char val = * ( bitmap++ );
1749 * ( dst_32 ++ ) = val;
1750 * ( dst_32 ++ ) = val;
1751 * ( dst_32 ++ ) = val;
1752 * ( dst_32 ++ ) = val;
1756 XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0,
width, height );
1757 XSetWindowBackgroundPixmap ( display, window, pixmap );
1768 "X not initialized" ) ) ;
1788 switch ( screen_depth )
1797 unsigned char *dst_32 = NULL;
1798 dst_32 = (
unsigned char* ) Ximage->data;
1803 for (
unsigned int i = 0; i < sizeI ; i++ )
1805 *(dst_32++) = bitmap->A;
1806 *(dst_32++) = bitmap->R;
1807 *(dst_32++) = bitmap->G;
1808 *(dst_32++) = bitmap->B;
1812 for (
unsigned int i = 0; i < sizeI; i++ )
1814 *(dst_32++) = bitmap->B;
1815 *(dst_32++) = bitmap->G;
1816 *(dst_32++) = bitmap->R;
1817 *(dst_32++) = bitmap->A;
1822 XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0,
width,
height );
1823 XSetWindowBackgroundPixmap ( display, window, pixmap );
1830 vpERROR_TRACE (
"Unsupported depth (%d bpp) for color display",
1833 "Unsupported depth for color display" ) ) ;
1840 "X not initialized" ) ) ;
1857 unsigned char *dst_32 = NULL;
1862 dst_32 = (
unsigned char* ) Ximage->data;
1864 for (
unsigned int i = 0; i <
width *
height; i++ )
1866 * ( dst_32 ++ ) = *I;
1867 * ( dst_32 ++ ) = *I;
1868 * ( dst_32 ++ ) = *I;
1869 * ( dst_32 ++ ) = *I;
1874 XPutImage ( display, pixmap, context, Ximage, 0, 0, 0, 0,
width, height );
1875 XSetWindowBackgroundPixmap ( display, window, pixmap );
1883 "X not initialized" ) ) ;
1909 switch ( screen_depth )
1913 unsigned char *src_8 = NULL;
1914 unsigned char *dst_8 = NULL;
1915 src_8 = (
unsigned char * ) I.
bitmap;
1916 dst_8 = (
unsigned char * ) Ximage->data;
1921 unsigned char nivGris;
1925 unsigned int iwidth = I.
getWidth();
1927 src_8 = src_8 + (int)(iP.
get_i()*iwidth+ iP.
get_j());
1928 dst_8 = dst_8 + (int)(iP.
get_i()*this->height+ iP.
get_j());
1936 nivGris = *(src_8+j);
1937 if ( nivGris > nivGrisMax )
1940 *(dst_8+j) = nivGris;
1943 src_8 = src_8 + iwidth;
1944 dst_8 = dst_8 + this->
height;
1951 XSetWindowBackgroundPixmap ( display, window, pixmap );
1958 unsigned short *dst_16 = NULL;
1959 dst_16 = (
unsigned short* ) Ximage->data;
1960 unsigned char *src_8 = NULL;
1961 src_8 = (
unsigned char * ) I.
bitmap;
1963 unsigned int iwidth = I.
getWidth();
1965 src_8 = src_8 + (int)(iP.
get_i()*iwidth+ iP.
get_j());
1966 dst_16 = dst_16 + (int)(iP.
get_i()*this->height+ iP.
get_j());
1974 *(dst_16+j) = (
unsigned short ) colortable[*(src_8+j)];
1977 src_8 = src_8 + iwidth;
1978 dst_16 = dst_16 + this->
height;
1984 XSetWindowBackgroundPixmap ( display, window, pixmap );
1993 unsigned char *dst_32 = NULL;
1995 dst_32 = (
unsigned char* ) Ximage->data;
1996 unsigned char *src_8 = I.
bitmap ;
1999 unsigned int iwidth = I.
getWidth();
2001 src_8 = src_8 + (int)(iP.
get_i()*iwidth+ iP.
get_j());
2002 dst_32 = dst_32 + (int)(iP.
get_i()*4*this->width+ iP.
get_j()*4);
2010 unsigned char val = *(src_8+j);
2011 *(dst_32+4*j) = val;
2012 *(dst_32+4*j+1) = val;
2013 *(dst_32+4*j+2) = val;
2014 *(dst_32+4*j+3) = val;
2017 src_8 = src_8 + iwidth;
2018 dst_32 = dst_32 + 4*this->
width;
2024 XSetWindowBackgroundPixmap ( display, window, pixmap );
2035 "X not initialized" ) ) ;
2063 switch ( screen_depth )
2072 unsigned char *dst_32 = NULL;
2073 dst_32 = (
unsigned char* ) Ximage->data;
2077 unsigned int iwidth = I.
getWidth();
2079 src_32 = src_32 + (int)(iP.
get_i()*iwidth+ iP.
get_j());
2080 dst_32 = dst_32 + (int)(iP.
get_i()*4*this->width+ iP.
get_j()*4);
2089 *(dst_32+4*j) = (src_32+j)->A;
2090 *(dst_32+4*j+1) = (src_32+j)->R;
2091 *(dst_32+4*j+2) = (src_32+j)->G;
2092 *(dst_32+4*j+3) = (src_32+j)->B;
2094 *(dst_32+4*j) = (src_32+j)->B;
2095 *(dst_32+4*j+1) = (src_32+j)->G;
2096 *(dst_32+4*j+2) = (src_32+j)->R;
2097 *(dst_32+4*j+3) = (src_32+j)->A;
2101 src_32 = src_32 + iwidth;
2102 dst_32 = dst_32 + 4*this->
width;
2108 XSetWindowBackgroundPixmap ( display, window, pixmap );
2115 vpERROR_TRACE (
"Unsupported depth (%d bpp) for color display",
2118 "Unsupported depth for color display" ) ) ;
2125 "X not initialized" ) ) ;
2140 if ( ximage_data_init ==
true )
2141 free ( Ximage->data );
2143 Ximage->data = NULL;
2144 XDestroyImage ( Ximage );
2146 XFreePixmap ( display, pixmap );
2148 XFreeGC ( display, context );
2149 XDestroyWindow ( display, window );
2150 XCloseDisplay ( display );
2153 if (
title != NULL )
2159 if (x_color != NULL) {
2167 if (
title != NULL )
2185 XClearWindow ( display, window );
2193 "X not initialized" ) ) ;
2217 "X not initialized" ) ) ;
2232 XSetWindowBackground ( display, window, x_color[color.
id] );
2235 xcolor.red = 256 * color.
R;
2236 xcolor.green = 256 * color.
G;
2237 xcolor.blue = 256 * color.
B;
2238 XAllocColor ( display, lut, &xcolor );
2239 XSetForeground ( display, context, xcolor.pixel );
2242 XClearWindow ( display, window );
2244 XFreePixmap ( display, pixmap );
2246 pixmap = XCreatePixmap ( display, window,
width,
height, screen_depth );
2252 "X not initialized" ) ) ;
2266 unsigned int w,
unsigned int h,
2267 unsigned int thickness)
2278 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon() )&&(std::fabs(b) <= std::numeric_limits<double>::epsilon()) )
2314 "X not initialized" ) ) ;
2336 XSetForeground ( display, context, x_color[color.
id] );
2339 xcolor.red = 256 * color.
R;
2340 xcolor.green = 256 * color.
G;
2341 xcolor.blue = 256 * color.
B;
2342 XAllocColor ( display, lut, &xcolor );
2343 XSetForeground ( display, context, xcolor.pixel );
2345 XDrawString ( display, pixmap, context,
2347 text, (int)strlen ( text ) );
2353 "X not initialized" ) ) ;
2367 unsigned int radius,
2370 unsigned int thickness )
2374 if ( thickness == 1 ) thickness = 0;
2376 XSetForeground ( display, context, x_color[color.
id] );
2379 xcolor.red = 256 * color.
R;
2380 xcolor.green = 256 * color.
G;
2381 xcolor.blue = 256 * color.
B;
2382 XAllocColor ( display, lut, &xcolor );
2383 XSetForeground ( display, context, xcolor.pixel );
2386 XSetLineAttributes ( display, context, thickness,
2387 LineSolid, CapButt, JoinBevel );
2389 if ( fill ==
false )
2391 XDrawArc ( display, pixmap, context,
2394 radius*2, radius*2, 0, 23040 );
2398 XFillArc ( display, pixmap, context,
2401 radius*2, radius*2, 0, 23040 );
2408 "X not initialized" ) ) ;
2422 unsigned int thickness)
2428 double i = ip.
get_i();
2429 double j = ip.
get_j();
2432 ip1.
set_i( i-size/2 );
2434 ip2.
set_i( i+size/2 );
2439 ip1.
set_j( j-size/2 );
2441 ip2.
set_j( j+size/2 );
2456 "X not initialized" ) ) ;
2469 unsigned int thickness )
2474 if ( thickness == 1 ) thickness = 0;
2477 XSetForeground ( display, context, x_color[color.
id] );
2480 xcolor.red = 256 * color.
R;
2481 xcolor.green = 256 * color.
G;
2482 xcolor.blue = 256 * color.
B;
2483 XAllocColor ( display, lut, &xcolor );
2484 XSetForeground ( display, context, xcolor.pixel );
2487 XSetLineAttributes ( display, context, thickness,
2488 LineOnOffDash, CapButt, JoinBevel );
2490 XDrawLine ( display, pixmap, context,
2500 "X not initialized" ) ) ;
2513 unsigned int thickness )
2517 if ( thickness == 1 ) thickness = 0;
2520 XSetForeground ( display, context, x_color[color.
id] );
2523 xcolor.red = 256 * color.
R;
2524 xcolor.green = 256 * color.
G;
2525 xcolor.blue = 256 * color.
B;
2526 XAllocColor ( display, lut, &xcolor );
2527 XSetForeground ( display, context, xcolor.pixel );
2530 XSetLineAttributes ( display, context, thickness,
2531 LineSolid, CapButt, JoinBevel );
2533 XDrawLine ( display, pixmap, context,
2543 "X not initialized" ) ) ;
2558 XSetForeground ( display, context, x_color[color.
id] );
2561 xcolor.red = 256 * color.
R;
2562 xcolor.green = 256 * color.
G;
2563 xcolor.blue = 256 * color.
B;
2564 XAllocColor ( display, lut, &xcolor );
2565 XSetForeground ( display, context, xcolor.pixel );
2568 XDrawPoint ( display, pixmap, context,
2576 "X not initialized" ) ) ;
2595 unsigned int width,
unsigned int height,
2596 const vpColor &color,
bool fill,
2597 unsigned int thickness )
2601 if ( thickness == 1 ) thickness = 0;
2603 XSetForeground ( display, context, x_color[color.
id] );
2606 xcolor.red = 256 * color.
R;
2607 xcolor.green = 256 * color.
G;
2608 xcolor.blue = 256 * color.
B;
2609 XAllocColor ( display, lut, &xcolor );
2610 XSetForeground ( display, context, xcolor.pixel );
2612 XSetLineAttributes ( display, context, thickness,
2613 LineSolid, CapButt, JoinBevel );
2614 if ( fill ==
false )
2616 XDrawRectangle ( display, pixmap, context,
2619 width-1, height-1 );
2623 XFillRectangle ( display, pixmap, context,
2633 "X not initialized" ) ) ;
2652 const vpColor &color,
bool fill,
2653 unsigned int thickness )
2657 if ( thickness == 1 ) thickness = 0;
2659 XSetForeground ( display, context, x_color[color.
id] );
2662 xcolor.red = 256 * color.
R;
2663 xcolor.green = 256 * color.
G;
2664 xcolor.blue = 256 * color.
B;
2665 XAllocColor ( display, lut, &xcolor );
2666 XSetForeground ( display, context, xcolor.pixel );
2669 XSetLineAttributes ( display, context, thickness,
2670 LineSolid, CapButt, JoinBevel );
2674 if ( fill ==
false )
2677 XDrawRectangle ( display, pixmap, context,
2680 width > 0 ? width-1 : 1, height > 0 ? height : 1 );
2684 XFillRectangle ( display, pixmap, context,
2694 "X not initialized" ) ) ;
2712 const vpColor &color,
bool fill,
2713 unsigned int thickness )
2717 if ( thickness == 1 ) thickness = 0;
2719 XSetForeground ( display, context, x_color[color.
id] );
2722 xcolor.red = 256 * color.
R;
2723 xcolor.green = 256 * color.
G;
2724 xcolor.blue = 256 * color.
B;
2725 XAllocColor ( display, lut, &xcolor );
2726 XSetForeground ( display, context, xcolor.pixel );
2729 XSetLineAttributes ( display, context, thickness,
2730 LineSolid, CapButt, JoinBevel );
2732 if ( fill ==
false )
2734 XDrawRectangle ( display, pixmap, context,
2742 XFillRectangle ( display, pixmap, context,
2754 "X not initialized" ) ) ;
2781 Window rootwin, childwin ;
2782 int root_x, root_y, win_x, win_y ;
2783 unsigned int modifier ;
2787 XCheckMaskEvent(display , ButtonPressMask, &event);
2788 XCheckMaskEvent(display , ButtonReleaseMask, &event);
2789 XMaskEvent ( display, ButtonPressMask ,&event );
2793 ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2798 if ( XQueryPointer ( display,
2800 &rootwin, &childwin,
2809 "X not initialized" ) ) ;
2837 Window rootwin, childwin ;
2838 int root_x, root_y, win_x, win_y ;
2839 unsigned int modifier ;
2842 XCheckMaskEvent(display , ButtonPressMask, &event);
2843 XCheckMaskEvent(display , ButtonReleaseMask, &event);
2844 XMaskEvent ( display, ButtonPressMask ,&event );
2848 ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2853 if ( XQueryPointer ( display,
2855 &rootwin, &childwin,
2859 ip.
set_u( (
double)event.xbutton.x );
2860 ip.
set_v( (
double)event.xbutton.y );
2867 "X not initialized" ) ) ;
2900 Window rootwin, childwin ;
2901 int root_x, root_y, win_x, win_y ;
2902 unsigned int modifier ;
2906 XCheckMaskEvent(display , ButtonPressMask, &event);
2907 XCheckMaskEvent(display , ButtonReleaseMask, &event);
2908 XMaskEvent ( display, ButtonPressMask ,&event );
2912 ret = XCheckMaskEvent(display , ButtonPressMask, &event);
2917 if ( XQueryPointer ( display,
2919 &rootwin, &childwin,
2923 ip.
set_u( (
double)event.xbutton.x );
2924 ip.
set_v( (
double)event.xbutton.y );
2925 switch ( event.xbutton.button ) {
2936 "X not initialized" ) ) ;
2972 Window rootwin, childwin ;
2973 int root_x, root_y, win_x, win_y ;
2974 unsigned int modifier ;
2978 XCheckMaskEvent(display , ButtonPressMask, &event);
2979 XCheckMaskEvent(display , ButtonReleaseMask, &event);
2980 XMaskEvent ( display, ButtonReleaseMask ,&event );
2984 ret = XCheckMaskEvent(display , ButtonReleaseMask, &event);
2989 if ( XQueryPointer ( display,
2991 &rootwin, &childwin,
2995 ip.
set_u( (
double)event.xbutton.x );
2996 ip.
set_v( (
double)event.xbutton.y );
2997 switch ( event.xbutton.button ) {
3008 "X not initialized" ) ) ;
3030 XCopyArea (display,window, pixmap, context,
3034 AllPlanes, ZPixmap ) ;
3046 unsigned char *src_32 = NULL;
3047 src_32 = (
unsigned char* ) xi->data;
3054 I.
bitmap[i].
R = src_32[i*4 + 1] ;
3055 I.
bitmap[i].
G = src_32[i*4 + 2] ;
3056 I.
bitmap[i].
B = src_32[i*4 + 3] ;
3062 I.
bitmap[i].
G = src_32[i*4 + 1] ;
3063 I.
bitmap[i].
R = src_32[i*4 + 2] ;
3064 I.
bitmap[i].
A = src_32[i*4 + 3] ;
3069 XDestroyImage ( xi ) ;
3076 "X not initialized" ) ) ;
3089 if ( ( _display = XOpenDisplay ( NULL ) ) == NULL )
3092 XDisplayName ( NULL ) );
3094 "Can't connect display on server." ) ) ;
3096 screen = DefaultScreen ( _display );
3097 depth = (
unsigned int)DefaultDepth ( _display, screen );
3099 XCloseDisplay ( _display );
3113 if ( ( _display = XOpenDisplay ( NULL ) ) == NULL )
3116 XDisplayName ( NULL ) );
3118 "Can't connect display on server." ) ) ;
3120 screen = DefaultScreen ( _display );
3121 width = (
unsigned int)DisplayWidth ( _display, screen );
3122 height = (
unsigned int)DisplayHeight ( _display, screen );
3124 XCloseDisplay ( _display );
3155 XMaskEvent ( display, KeyPressMask ,&event );
3159 ret = XCheckMaskEvent(display , KeyPressMask, &event);
3165 "X not initialized" ) ) ;
3199 XComposeStatus compose_status;
3205 XMaskEvent ( display, KeyPressMask ,&event );
3206 XLookupString ((XKeyEvent *)&event, &buffer, 1,
3207 &keysym, &compose_status);
3209 sprintf(
string,
"%c", buffer);
3213 ret = XCheckMaskEvent(display , KeyPressMask, &event);
3215 XLookupString ((XKeyEvent *)&event, &buffer, 1,
3216 &keysym, &compose_status);
3217 sprintf(
string,
"%c", buffer);
3224 "X not initialized" ) ) ;
3247 Window rootwin, childwin ;
3248 int root_x, root_y, win_x, win_y ;
3249 unsigned int modifier ;
3251 ret = XCheckMaskEvent(display , PointerMotionMask, &event);
3255 if ( XQueryPointer ( display,
3257 &rootwin, &childwin,
3261 ip.
set_u( (
double)event.xbutton.x );
3262 ip.
set_v( (
double)event.xbutton.y );
3269 "X not initialized" ) ) ;
3291 Window rootwin, childwin ;
3292 int root_x, root_y, win_x, win_y ;
3293 unsigned int modifier ;
3299 if ( XQueryPointer ( display,
3301 &rootwin, &childwin,
3305 ip.
set_u( (
double)win_x );
3306 ip.
set_v( (
double)win_y );
3313 "X not initialized" ) ) ;