44 #include <visp3/core/vpConfig.h>
54 #include <visp3/core/vpDisplay.h>
55 #include <visp3/gui/vpDisplayX.h>
58 #include <visp3/core/vpDebug.h>
59 #include <visp3/core/vpDisplayException.h>
62 #include <visp3/core/vpMath.h>
64 #ifndef DOXYGEN_SHOULD_SKIP_THIS
67 #include <X11/Xutil.h>
74 class vpDisplayX::Impl
78 :
display(NULL), window(), Ximage(NULL), lut(), context(), screen(0), event(), pixmap(), x_color(NULL),
79 screen_depth(8), xcolor(), values(), ximage_data_init(false), RMask(0), GMask(0), BMask(0), RShift(0), GShift(0),
89 XSetWindowBackground(
display, window, x_color[color.
id]);
92 xcolor.red = 256 * color.
R;
93 xcolor.green = 256 * color.
G;
94 xcolor.blue = 256 * color.
B;
95 XAllocColor(
display, lut, &xcolor);
96 XSetForeground(
display, context, xcolor.pixel);
103 pixmap = XCreatePixmap(
display, window, width, height, screen_depth);
108 if (ximage_data_init ==
true)
112 XDestroyImage(Ximage);
117 XDestroyWindow(
display, window);
120 if (x_color != NULL) {
129 XSetForeground(
display, context, x_color[color.
id]);
132 xcolor.red = 256 * color.
R;
133 xcolor.green = 256 * color.
G;
134 xcolor.blue = 256 * color.
B;
135 XAllocColor(
display, lut, &xcolor);
136 XSetForeground(
display, context, xcolor.pixel);
138 XDrawString(
display, pixmap, context, (
int)(ip.
get_u() / scale), (
int)(ip.
get_v() / scale), text,
143 unsigned int thickness,
unsigned int scale)
146 XSetForeground(
display, context, x_color[color.
id]);
149 xcolor.red = 256 * color.
R;
150 xcolor.green = 256 * color.
G;
151 xcolor.blue = 256 * color.
B;
152 XAllocColor(
display, lut, &xcolor);
153 XSetForeground(
display, context, xcolor.pixel);
156 XSetLineAttributes(
display, context, thickness, LineSolid, CapButt, JoinBevel);
160 vpMath::round((center.
get_v() - radius) / scale), radius * 2 / scale, radius * 2 / scale, 0,
164 vpMath::round((center.
get_v() - radius) / scale), radius * 2 / scale, radius * 2 / scale, 0,
173 XSetForeground(
display, context, x_color[color.
id]);
176 xcolor.red = 256 * color.
R;
177 xcolor.green = 256 * color.
G;
178 xcolor.blue = 256 * color.
B;
179 XAllocColor(
display, lut, &xcolor);
180 XSetForeground(
display, context, xcolor.pixel);
183 XSetLineAttributes(
display, context, thickness, LineOnOffDash, CapButt, JoinBevel);
191 switch (screen_depth) {
197 unsigned char *src_8 = (
unsigned char *)I.
bitmap;
198 unsigned char *dst_8 = (
unsigned char *)Ximage->data;
200 unsigned int size = width * height;
203 unsigned char nivGris = src_8[i];
204 if (nivGris > nivGrisMax)
213 unsigned char *dst_8 = (
unsigned char *)Ximage->data;
215 for (
unsigned int i = 0; i < height; i++) {
216 for (
unsigned int j = 0; j < width; j++) {
217 unsigned char nivGris = I[i * scale][j * scale];
218 if (nivGris > nivGrisMax)
221 dst_8[k++] = nivGris;
227 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
228 XSetWindowBackgroundPixmap(
display, window, pixmap);
232 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
234 for (
unsigned int i = 0; i < height; i++) {
235 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
236 unsigned short *dst_16 = (
unsigned short *)dst_8;
237 for (
unsigned int j = 0; j < width; j++) {
238 *(dst_16 + j) = (
unsigned short)colortable[I[i][j]];
242 for (
unsigned int i = 0; i < height; i++) {
243 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
244 unsigned short *dst_16 = (
unsigned short *)dst_8;
245 for (
unsigned int j = 0; j < width; j++) {
246 *(dst_16 + j) = (
unsigned short)colortable[I[i * scale][j * scale]];
252 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
253 XSetWindowBackgroundPixmap(
display, window, pixmap);
259 unsigned char *dst_32 = (
unsigned char *)Ximage->data;
261 unsigned int size_ = width * height;
262 unsigned char *bitmap = I.
bitmap;
263 unsigned char *n = I.
bitmap + size_;
266 if (XImageByteOrder(
display) == 1) {
269 unsigned char val = *(bitmap++);
278 unsigned char val = *(bitmap++);
286 if (XImageByteOrder(
display) == 1) {
288 for (
unsigned int i = 0; i < height; i++) {
289 for (
unsigned int j = 0; j < width; j++) {
290 unsigned char val = I[i * scale][j * scale];
299 for (
unsigned int i = 0; i < height; i++) {
300 for (
unsigned int j = 0; j < width; j++) {
301 unsigned char val = I[i * scale][j * scale];
312 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
313 XSetWindowBackgroundPixmap(
display, window, pixmap);
321 switch (screen_depth) {
324 unsigned int r, g, b;
325 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
328 for (
unsigned int i = 0; i < height; i++) {
329 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
330 unsigned short *dst_16 = (
unsigned short *)dst_8;
331 for (
unsigned int j = 0; j < width; j++) {
336 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
341 for (
unsigned int i = 0; i < height; i++) {
342 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
343 unsigned short *dst_16 = (
unsigned short *)dst_8;
344 for (
unsigned int j = 0; j < width; j++) {
345 vpRGBa val = I[i * scale][j * scale];
350 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
356 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
357 XSetWindowBackgroundPixmap(
display, window, pixmap);
366 unsigned char *dst_32 = NULL;
367 dst_32 = (
unsigned char *)Ximage->data;
370 unsigned int sizeI = width * height;
371 if (XImageByteOrder(
display) == 1) {
373 for (
unsigned int i = 0; i < sizeI; i++) {
374 *(dst_32++) = bitmap->
A;
375 *(dst_32++) = bitmap->
R;
376 *(dst_32++) = bitmap->
G;
377 *(dst_32++) = bitmap->
B;
382 for (
unsigned int i = 0; i < sizeI; i++) {
383 *(dst_32++) = bitmap->
B;
384 *(dst_32++) = bitmap->
G;
385 *(dst_32++) = bitmap->
R;
386 *(dst_32++) = bitmap->
A;
391 if (XImageByteOrder(
display) == 1) {
393 for (
unsigned int i = 0; i < height; i++) {
394 for (
unsigned int j = 0; j < width; j++) {
395 vpRGBa val = I[i * scale][j * scale];
404 for (
unsigned int i = 0; i < height; i++) {
405 for (
unsigned int j = 0; j < width; j++) {
406 vpRGBa val = I[i * scale][j * scale];
417 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
418 XSetWindowBackgroundPixmap(
display, window, pixmap);
423 "Unsupported depth (%d bpp) for color display", screen_depth));
427 void displayImage(
const unsigned char *bitmap,
unsigned int width,
unsigned int height)
429 unsigned char *dst_32 = (
unsigned char *)Ximage->data;
430 for (
unsigned int i = 0; i < width * height; i++) {
431 *(dst_32++) = *bitmap;
432 *(dst_32++) = *bitmap;
433 *(dst_32++) = *bitmap;
434 *(dst_32++) = *bitmap;
439 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
440 XSetWindowBackgroundPixmap(
display, window, pixmap);
444 unsigned int scale,
unsigned int width,
unsigned int height)
446 switch (screen_depth) {
452 unsigned char *src_8 = (
unsigned char *)I.
bitmap;
453 unsigned char *dst_8 = (
unsigned char *)Ximage->data;
456 src_8 = src_8 + (int)(iP.
get_i() * iwidth + iP.
get_j());
457 dst_8 = dst_8 + (int)(iP.
get_i() * width + iP.
get_j());
463 unsigned char nivGris = *(src_8 + j);
464 if (nivGris > nivGrisMax)
467 *(dst_8 + j) = nivGris;
470 src_8 = src_8 + iwidth;
471 dst_8 = dst_8 + width;
480 int i_min = (std::max)((
int)ceil(iP.
get_i() / scale), 0);
481 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
482 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
483 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
485 unsigned int i_min_ = (
unsigned int)i_min;
486 unsigned int i_max_ = (
unsigned int)i_max;
487 unsigned int j_min_ = (
unsigned int)j_min;
488 unsigned int j_max_ = (
unsigned int)j_max;
490 for (
unsigned int i = i_min_; i < i_max_; i++) {
491 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * width;
492 for (
unsigned int j = j_min_; j < j_max_; j++) {
493 unsigned char nivGris = I[i * scale][j * scale];
494 if (nivGris > nivGrisMax)
500 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
504 XSetWindowBackgroundPixmap(
display, window, pixmap);
508 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
510 for (
unsigned int i = (
unsigned int)iP.
get_i(); i < (
unsigned int)(iP.
get_i() + h); i++) {
511 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
512 unsigned short *dst_16 = (
unsigned short *)dst_8;
513 for (
unsigned int j = (
unsigned int)iP.
get_j(); j < (
unsigned int)(iP.
get_j() + w); j++) {
514 *(dst_16 + j) = (
unsigned short)colortable[I[i][j]];
521 int i_min = (std::max)((
int)ceil(iP.
get_i() / scale), 0);
522 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
523 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
524 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
526 unsigned int i_min_ = (
unsigned int)i_min;
527 unsigned int i_max_ = (
unsigned int)i_max;
528 unsigned int j_min_ = (
unsigned int)j_min;
529 unsigned int j_max_ = (
unsigned int)j_max;
531 for (
unsigned int i = i_min_; i < i_max_; i++) {
532 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
533 unsigned short *dst_16 = (
unsigned short *)dst_8;
534 for (
unsigned int j = j_min_; j < j_max_; j++) {
535 *(dst_16 + j) = (
unsigned short)colortable[I[i * scale][j * scale]];
539 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
542 XSetWindowBackgroundPixmap(
display, window, pixmap);
551 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(iP.
get_i() * 4 * width + iP.
get_j() * 4);
553 if (XImageByteOrder(
display) == 1) {
559 unsigned char val = *(src_8 + j);
561 *(dst_32 + 4 * j + 1) = val;
562 *(dst_32 + 4 * j + 2) = val;
563 *(dst_32 + 4 * j + 3) = val;
566 src_8 = src_8 + iwidth;
567 dst_32 = dst_32 + 4 * width;
576 unsigned char val = *(src_8 + j);
577 *(dst_32 + 4 * j) = val;
578 *(dst_32 + 4 * j + 1) = val;
579 *(dst_32 + 4 * j + 2) = val;
583 src_8 = src_8 + iwidth;
584 dst_32 = dst_32 + 4 * width;
592 int i_min = (std::max)((
int)ceil(iP.
get_i() / scale), 0);
593 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
594 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
595 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
597 unsigned int i_min_ = (
unsigned int)i_min;
598 unsigned int i_max_ = (
unsigned int)i_max;
599 unsigned int j_min_ = (
unsigned int)j_min;
600 unsigned int j_max_ = (
unsigned int)j_max;
602 if (XImageByteOrder(
display) == 1) {
604 for (
unsigned int i = i_min_; i < i_max_; i++) {
605 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
606 for (
unsigned int j = j_min_; j < j_max_; j++) {
607 unsigned char val = I[i * scale][j * scale];
616 for (
unsigned int i = i_min_; i < i_max_; i++) {
617 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
618 for (
unsigned int j = j_min_; j < j_max_; j++) {
619 unsigned char val = I[i * scale][j * scale];
628 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
631 XSetWindowBackgroundPixmap(
display, window, pixmap);
638 unsigned int scale,
unsigned int width,
unsigned int height)
640 switch (screen_depth) {
643 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
644 for (
unsigned int i = (
unsigned int)iP.
get_i(); i < (
unsigned int)(iP.
get_i() + h); i++) {
645 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
646 unsigned short *dst_16 = (
unsigned short *)dst_8;
647 for (
unsigned int j = (
unsigned int)iP.
get_j(); j < (
unsigned int)(iP.
get_j() + w); j++) {
649 unsigned int r = val.
R;
650 unsigned int g = val.
G;
651 unsigned int b = val.
B;
653 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
659 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
660 int i_min = (std::max)((int)ceil(iP.
get_i() / scale), 0);
661 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
662 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
663 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
665 unsigned int i_min_ = (
unsigned int)i_min;
666 unsigned int i_max_ = (
unsigned int)i_max;
667 unsigned int j_min_ = (
unsigned int)j_min;
668 unsigned int j_max_ = (
unsigned int)j_max;
670 for (
unsigned int i = i_min_; i < i_max_; i++) {
671 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
672 unsigned short *dst_16 = (
unsigned short *)dst_8;
673 for (
unsigned int j = j_min_; j < j_max_; j++) {
674 vpRGBa val = I[i * scale][j * scale];
675 unsigned int r = val.
R;
676 unsigned int g = val.
G;
677 unsigned int b = val.
B;
679 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
682 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
685 XSetWindowBackgroundPixmap(
display, window, pixmap);
696 unsigned char *dst_32 = (
unsigned char *)Ximage->data;
701 src_32 = src_32 + (int)(iP.
get_i() * iwidth + iP.
get_j());
702 dst_32 = dst_32 + (int)(iP.
get_i() * 4 * width + iP.
get_j() * 4);
706 if (XImageByteOrder(
display) == 1) {
711 *(dst_32 + 4 * j) = (src_32 + j)->A;
712 *(dst_32 + 4 * j + 1) = (src_32 + j)->R;
713 *(dst_32 + 4 * j + 2) = (src_32 + j)->G;
714 *(dst_32 + 4 * j + 3) = (src_32 + j)->B;
718 src_32 = src_32 + iwidth;
719 dst_32 = dst_32 + 4 * width;
728 *(dst_32 + 4 * j) = (src_32 + j)->B;
729 *(dst_32 + 4 * j + 1) = (src_32 + j)->G;
730 *(dst_32 + 4 * j + 2) = (src_32 + j)->R;
731 *(dst_32 + 4 * j + 3) = (src_32 + j)->A;
735 src_32 = src_32 + iwidth;
736 dst_32 = dst_32 + 4 * width;
744 int i_min = (std::max)((
int)ceil(iP.
get_i() / scale), 0);
745 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
746 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
747 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
749 unsigned int i_min_ = (
unsigned int)i_min;
750 unsigned int i_max_ = (
unsigned int)i_max;
751 unsigned int j_min_ = (
unsigned int)j_min;
752 unsigned int j_max_ = (
unsigned int)j_max;
754 if (XImageByteOrder(
display) == 1) {
756 for (
unsigned int i = i_min_; i < i_max_; i++) {
757 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
758 for (
unsigned int j = j_min_; j < j_max_; j++) {
759 vpRGBa val = I[i * scale][j * scale];
768 for (
unsigned int i = i_min_; i < i_max_; i++) {
769 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
770 for (
unsigned int j = j_min_; j < j_max_; j++) {
771 vpRGBa val = I[i * scale][j * scale];
779 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
782 XSetWindowBackgroundPixmap(
display, window, pixmap);
787 "Unsupported depth (%d bpp) for color display", screen_depth));
795 XSetForeground(
display, context, x_color[color.
id]);
798 xcolor.red = 256 * color.
R;
799 xcolor.green = 256 * color.
G;
800 xcolor.blue = 256 * color.
B;
801 XAllocColor(
display, lut, &xcolor);
802 XSetForeground(
display, context, xcolor.pixel);
805 XSetLineAttributes(
display, context, thickness, LineSolid, CapButt, JoinBevel);
814 XSetForeground(
display, context, x_color[color.
id]);
817 xcolor.red = 256 * color.
R;
818 xcolor.green = 256 * color.
G;
819 xcolor.blue = 256 * color.
B;
820 XAllocColor(
display, lut, &xcolor);
821 XSetForeground(
display, context, xcolor.pixel);
824 if (thickness == 1) {
828 thickness, thickness);
833 unsigned int thickness,
unsigned int scale)
836 XSetForeground(
display, context, x_color[color.
id]);
839 xcolor.red = 256 * color.
R;
840 xcolor.green = 256 * color.
G;
841 xcolor.blue = 256 * color.
B;
842 XAllocColor(
display, lut, &xcolor);
843 XSetForeground(
display, context, xcolor.pixel);
845 XSetLineAttributes(
display, context, thickness, LineSolid, CapButt, JoinBevel);
863 XClearArea(
display, window, (
int)(iP.
get_u() / scale), (
int)(iP.
get_v() / scale), w / scale, h / scale, 0);
870 Window rootwin, childwin;
871 int root_x, root_y, win_x, win_y;
872 unsigned int modifier;
876 XCheckMaskEvent(
display, ButtonPressMask, &event);
877 XCheckMaskEvent(
display, ButtonReleaseMask, &event);
878 XMaskEvent(
display, ButtonPressMask, &event);
881 ret = XCheckMaskEvent(
display, ButtonPressMask, &event);
886 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
887 ip.
set_u((
double)event.xbutton.x * scale);
888 ip.
set_v((
double)event.xbutton.y * scale);
889 switch (event.xbutton.button) {
909 Window rootwin, childwin;
910 int root_x, root_y, win_x, win_y;
911 unsigned int modifier;
915 XCheckMaskEvent(
display, ButtonPressMask, &event);
916 XCheckMaskEvent(
display, ButtonReleaseMask, &event);
917 XMaskEvent(
display, ButtonReleaseMask, &event);
920 ret = XCheckMaskEvent(
display, ButtonReleaseMask, &event);
925 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
926 ip.
set_u((
double)event.xbutton.x * scale);
927 ip.
set_v((
double)event.xbutton.y * scale);
928 switch (event.xbutton.button) {
949 XCopyArea(
display, window, pixmap, context, 0, 0, width, height, 0, 0);
951 xi = XGetImage(
display, pixmap, 0, 0, width, height, AllPlanes, ZPixmap);
955 unsigned char *src_32 = NULL;
956 src_32 = (
unsigned char *)xi->data;
958 if (screen_depth == 16) {
959 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
960 size_t i_ = i * width;
961 for (
unsigned int j = 0; j < height; j++) {
963 unsigned long pixel = XGetPixel(xi, (
int)j, (
int)i);
964 I.
bitmap[ij_].R = (((pixel & RMask) << RShift) >> 8);
965 I.
bitmap[ij_].G = (((pixel & GMask) << GShift) >> 8);
966 I.
bitmap[ij_].B = (((pixel & BMask) << BShift) >> 8);
975 if (XImageByteOrder(
display) == 1) {
977 for (
unsigned int i = 0; i < width * height; i++) {
982 I.
bitmap[i].R = src_32[i * 4 + 1];
983 I.
bitmap[i].G = src_32[i * 4 + 2];
984 I.
bitmap[i].B = src_32[i * 4 + 3];
988 for (
unsigned int i = 0; i < width * height; i++) {
989 I.
bitmap[i].B = src_32[i * 4];
990 I.
bitmap[i].G = src_32[i * 4 + 1];
991 I.
bitmap[i].R = src_32[i * 4 + 2];
1008 XMaskEvent(
display, KeyPressMask, &event);
1011 ret = XCheckMaskEvent(
display, KeyPressMask, &event);
1022 XComposeStatus compose_status;
1027 XMaskEvent(
display, KeyPressMask, &event);
1028 XLookupString((XKeyEvent *)&event, &buffer, 1, &keysym, &compose_status);
1032 ret = XCheckMaskEvent(
display, KeyPressMask, &event);
1034 XLookupString((XKeyEvent *)&event, &buffer, 1, &keysym, &compose_status);
1045 int getMsb(
unsigned int u32val)
1049 for (i = 31; i >= 0; --i) {
1050 if (u32val & 0x80000000L)
1061 Window rootwin, childwin;
1062 int root_x, root_y, win_x, win_y;
1063 unsigned int modifier;
1065 ret = XCheckMaskEvent(
display, PointerMotionMask, &event);
1069 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
1070 ip.
set_u((
double)event.xbutton.x * scale);
1071 ip.
set_v((
double)event.xbutton.y * scale);
1081 Window rootwin, childwin;
1082 int root_x, root_y, win_x, win_y;
1083 unsigned int modifier;
1089 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
1090 ip.
set_u((
double)win_x * scale);
1091 ip.
set_v((
double)win_y * scale);
1104 if ((display_ = XOpenDisplay(NULL)) == NULL) {
1106 XDisplayName(NULL)));
1108 screen_ = DefaultScreen(display_);
1109 depth = (
unsigned int)DefaultDepth(display_, screen_);
1111 XCloseDisplay(display_);
1121 if ((display_ = XOpenDisplay(NULL)) == NULL) {
1123 XDisplayName(NULL)));
1125 screen_ = DefaultScreen(display_);
1126 w = (
unsigned int)DisplayWidth(display_, screen_);
1127 h = (
unsigned int)DisplayHeight(display_, screen_);
1129 XCloseDisplay(display_);
1132 void init(
unsigned int win_width,
unsigned int win_height,
int win_x,
int win_y,
const std::string &win_title)
1134 if (x_color == NULL) {
1142 if ((win_x < 0) || (win_y < 0)) {
1145 hints.flags = USPosition;
1150 if ((
display = XOpenDisplay(NULL)) == NULL) {
1151 vpERROR_TRACE(
"Can't connect display on server %s.\n", XDisplayName(NULL));
1155 screen = DefaultScreen(
display);
1156 lut = DefaultColormap(
display, screen);
1157 screen_depth = (
unsigned int)DefaultDepth(
display, screen);
1159 vpTRACE(
"Screen depth: %d\n", screen_depth);
1161 if ((window = XCreateSimpleWindow(
display, RootWindow(
display, screen), win_x, win_y, win_width, win_height, 1,
1162 BlackPixel(
display, screen), WhitePixel(
display, screen))) == 0) {
1170 if (screen_depth == 8) {
1171 lut = XCreateColormap(
display, window, DefaultVisual(
display, screen), AllocAll);
1172 xcolor.flags = DoRed | DoGreen | DoBlue;
1174 for (
unsigned int i = 0; i < 256; i++) {
1176 xcolor.red = 256 * i;
1177 xcolor.green = 256 * i;
1178 xcolor.blue = 256 * i;
1179 XStoreColor(
display, lut, &xcolor);
1182 XSetWindowColormap(
display, window, lut);
1183 XInstallColormap(
display, lut);
1186 else if (screen_depth == 16) {
1187 for (
unsigned int i = 0; i < 256; i++) {
1189 xcolor.red = xcolor.green = xcolor.blue = 256 * i;
1190 if (XAllocColor(
display, lut, &xcolor) == 0) {
1191 vpERROR_TRACE(
"Can't allocate 256 colors. Only %d allocated.", i);
1194 colortable[i] = xcolor.pixel;
1197 XSetWindowColormap(
display, window, lut);
1198 XInstallColormap(
display, lut);
1200 Visual *visual = DefaultVisual(
display, screen);
1201 RMask = visual->red_mask;
1202 GMask = visual->green_mask;
1203 BMask = visual->blue_mask;
1205 RShift = 15 - getMsb(RMask);
1206 GShift = 15 - getMsb(GMask);
1207 BShift = 15 - getMsb(BMask);
1215 switch (screen_depth) {
1225 xcolor.
red = 256 * 192;
1226 xcolor.
green = 256 * 192;
1227 xcolor.
blue = 256 * 192;
1228 XStoreColor(
display, lut, &xcolor);
1233 xcolor.red = 256 * 128;
1234 xcolor.green = 256 * 128;
1235 xcolor.blue = 256 * 128;
1236 XStoreColor(
display, lut, &xcolor);
1241 xcolor.red = 256 * 64;
1242 xcolor.green = 256 * 64;
1243 xcolor.blue = 256 * 64;
1244 XStoreColor(
display, lut, &xcolor);
1249 xcolor.red = 256 * 255;
1250 xcolor.green = 256 * 140;
1251 xcolor.blue = 256 * 140;
1252 XStoreColor(
display, lut, &xcolor);
1257 xcolor.red = 256 * 255;
1260 XStoreColor(
display, lut, &xcolor);
1265 xcolor.red = 256 * 128;
1268 XStoreColor(
display, lut, &xcolor);
1273 xcolor.red = 256 * 140;
1274 xcolor.green = 256 * 255;
1275 xcolor.blue = 256 * 140;
1276 XStoreColor(
display, lut, &xcolor);
1282 xcolor.green = 256 * 255;
1284 XStoreColor(
display, lut, &xcolor);
1290 xcolor.green = 256 * 128;
1292 XStoreColor(
display, lut, &xcolor);
1297 xcolor.red = 256 * 140;
1298 xcolor.green = 256 * 140;
1299 xcolor.blue = 256 * 255;
1300 XStoreColor(
display, lut, &xcolor);
1307 xcolor.blue = 256 * 255;
1308 XStoreColor(
display, lut, &xcolor);
1315 xcolor.blue = 256 * 128;
1316 XStoreColor(
display, lut, &xcolor);
1321 xcolor.red = 256 * 255;
1322 xcolor.green = 256 * 255;
1324 XStoreColor(
display, lut, &xcolor);
1329 xcolor.red = 256 * 255;
1330 xcolor.green = 256 * 165;
1332 XStoreColor(
display, lut, &xcolor);
1338 xcolor.green = 256 * 255;
1339 xcolor.blue = 256 * 255;
1340 XStoreColor(
display, lut, &xcolor);
1345 xcolor.red = 256 * 128;
1347 xcolor.blue = 256 * 128;
1348 XStoreColor(
display, lut, &xcolor);
1355 xcolor.flags = DoRed | DoGreen | DoBlue;
1360 xcolor.
red = 256 * pcolor.
R;
1361 xcolor.green = 256 * pcolor.
G;
1362 xcolor.blue = 256 * pcolor.
B;
1363 XAllocColor(
display, lut, &xcolor);
1369 xcolor.
red = 256 * pcolor.
R;
1370 xcolor.green = 256 * pcolor.
G;
1371 xcolor.blue = 256 * pcolor.
B;
1372 XAllocColor(
display, lut, &xcolor);
1378 xcolor.
red = 256 * pcolor.
R;
1379 xcolor.green = 256 * pcolor.
G;
1380 xcolor.blue = 256 * pcolor.
B;
1381 XAllocColor(
display, lut, &xcolor);
1387 xcolor.
red = 256 * pcolor.
R;
1388 xcolor.green = 256 * pcolor.
G;
1389 xcolor.blue = 256 * pcolor.
B;
1390 XAllocColor(
display, lut, &xcolor);
1396 xcolor.
red = 256 * pcolor.
R;
1397 xcolor.green = 256 * pcolor.
G;
1398 xcolor.blue = 256 * pcolor.
B;
1399 XAllocColor(
display, lut, &xcolor);
1405 xcolor.
red = 256 * pcolor.
R;
1406 xcolor.green = 256 * pcolor.
G;
1407 xcolor.blue = 256 * pcolor.
B;
1408 XAllocColor(
display, lut, &xcolor);
1414 xcolor.
red = 256 * pcolor.
R;
1415 xcolor.green = 256 * pcolor.
G;
1416 xcolor.blue = 256 * pcolor.
B;
1417 XAllocColor(
display, lut, &xcolor);
1423 xcolor.
red = 256 * pcolor.
R;
1424 xcolor.green = 256 * pcolor.
G;
1425 xcolor.blue = 256 * pcolor.
B;
1426 XAllocColor(
display, lut, &xcolor);
1432 xcolor.
red = 256 * pcolor.
R;
1433 xcolor.green = 256 * pcolor.
G;
1434 xcolor.blue = 256 * pcolor.
B;
1435 XAllocColor(
display, lut, &xcolor);
1441 xcolor.
red = 256 * pcolor.
R;
1442 xcolor.green = 256 * pcolor.
G;
1443 xcolor.blue = 256 * pcolor.
B;
1444 XAllocColor(
display, lut, &xcolor);
1450 xcolor.
red = 256 * pcolor.
R;
1451 xcolor.green = 256 * pcolor.
G;
1452 xcolor.blue = 256 * pcolor.
B;
1453 XAllocColor(
display, lut, &xcolor);
1459 xcolor.
red = 256 * pcolor.
R;
1460 xcolor.green = 256 * pcolor.
G;
1461 xcolor.blue = 256 * pcolor.
B;
1462 XAllocColor(
display, lut, &xcolor);
1468 xcolor.
red = 256 * pcolor.
R;
1469 xcolor.green = 256 * pcolor.
G;
1470 xcolor.blue = 256 * pcolor.
B;
1471 XAllocColor(
display, lut, &xcolor);
1477 xcolor.
red = 256 * pcolor.
R;
1478 xcolor.green = 256 * pcolor.
G;
1479 xcolor.blue = 256 * pcolor.
B;
1480 XAllocColor(
display, lut, &xcolor);
1486 xcolor.
red = 256 * pcolor.
R;
1487 xcolor.green = 256 * pcolor.
G;
1488 xcolor.blue = 256 * pcolor.
B;
1489 XAllocColor(
display, lut, &xcolor);
1495 xcolor.
red = 256 * pcolor.
R;
1496 xcolor.green = 256 * pcolor.
G;
1497 xcolor.blue = 256 * pcolor.
B;
1498 XAllocColor(
display, lut, &xcolor);
1504 xcolor.
red = 256 * pcolor.
R;
1505 xcolor.green = 256 * pcolor.
G;
1506 xcolor.blue = 256 * pcolor.
B;
1507 XAllocColor(
display, lut, &xcolor);
1513 xcolor.
red = 256 * pcolor.
R;
1514 xcolor.green = 256 * pcolor.
G;
1515 xcolor.blue = 256 * pcolor.
B;
1516 XAllocColor(
display, lut, &xcolor);
1522 XSetStandardProperties(
display, window, win_title.c_str(), win_title.c_str(), None, 0, 0, &hints);
1526 ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
1527 StructureNotifyMask | PointerMotionMask);
1530 values.plane_mask = AllPlanes;
1531 values.fill_style = FillSolid;
1532 values.foreground = WhitePixel(
display, screen);
1533 values.background = BlackPixel(
display, screen);
1534 context = XCreateGC(
display, window, GCPlaneMask | GCFillStyle | GCForeground | GCBackground, &values);
1536 if (context == NULL) {
1542 pixmap = XCreatePixmap(
display, window, win_width, win_height, screen_depth);
1550 Ximage = XCreateImage(
display, DefaultVisual(
display, screen), screen_depth, ZPixmap, 0, NULL, win_width,
1551 win_height, XBitmapPad(
display), 0);
1553 Ximage->data = (
char *)malloc(win_height * (
unsigned int)Ximage->bytes_per_line);
1554 ximage_data_init =
true;
1559 XStoreName(
display, window, win_title.c_str());
1562 void setFont(
const std::string &fontname)
1566 stringfont = XLoadFont(
display, fontname.c_str());
1567 XSetFont(
display, context, stringfont);
1573 void setTitle(
const std::string &title) { XStoreName(
display, window, title.c_str()); }
1586 unsigned long *x_color;
1587 unsigned int screen_depth;
1588 unsigned short colortable[256];
1591 bool ximage_data_init;
1592 unsigned int RMask, GMask, BMask;
1593 int RShift, GShift, BShift;
1648 init(I, x, y, title);
1701 init(I, x, y, title);
1781 if (!win_title.empty())
1810 if (!win_title.empty())
1828 const std::string &win_title)
1864 if (!fontname.empty()) {
1865 m_impl->setFont(fontname);
1881 m_impl->setTitle(title);
1899 m_impl->setWindowPosition(win_x, win_y);
2024 m_impl->closeDisplay();
2038 m_impl->flushDisplay();
2054 m_impl->flushDisplayROI(iP, w, h,
m_scale);
2081 unsigned int h,
unsigned int thickness)
2089 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon()) &&
2090 (std::fabs(b) <= std::numeric_limits<double>::epsilon())) {
2134 m_impl->displayCharString(ip, text, color,
m_scale);
2150 unsigned int thickness)
2155 m_impl->displayCircle(center, radius, color, fill, thickness,
m_scale);
2169 unsigned int thickness)
2172 double i = ip.
get_i();
2173 double j = ip.
get_j();
2176 ip1.
set_i(i - cross_size / 2);
2178 ip2.
set_i(i + cross_size / 2);
2183 ip1.
set_j(j - cross_size / 2);
2185 ip2.
set_j(j + cross_size / 2);
2199 unsigned int thickness)
2205 m_impl->displayDotLine(ip1, ip2, color, thickness,
m_scale);
2218 unsigned int thickness)
2223 m_impl->displayLine(ip1, ip2, color, thickness,
m_scale);
2238 m_impl->displayPoint(ip, color, thickness,
m_scale);
2258 bool fill,
unsigned int thickness)
2264 m_impl->displayRectangle(topLeft, w, h, color, fill, thickness,
m_scale);
2283 bool fill,
unsigned int thickness)
2292 m_impl->displayRectangle(topLeft, w, h, color, fill, thickness,
m_scale);
2318 m_impl->displayRectangle(topLeft, w, h, color, fill, thickness,
m_scale);
2346 ret = m_impl->getClick(ip, button, blocking,
m_scale);
2374 ret = m_impl->getClick(ip, button, blocking,
m_scale);
2405 ret = m_impl->getClick(ip, button, blocking,
m_scale);
2440 ret = m_impl->getClickUp(ip, button, blocking,
m_scale);
2479 unsigned int width, height;
2489 unsigned int width, height;
2519 ret = m_impl->getKeyboardEvent(blocking);
2553 ret = m_impl->getKeyboardEvent(key, blocking);
2576 ret = m_impl->getPointerMotionEvent(ip,
m_scale);
2597 ret = m_impl->getPointerPosition(ip,
m_scale);
2604 #elif !defined(VISP_BUILD_SHARED_LIBS)
2607 void dummy_vpDisplayX(){};
Class to define RGB colors available for display functionalities.
static const vpColor white
static const vpColor darkGray
static const vpColor black
static const vpColor cyan
static const vpColor orange
static const vpColor darkRed
static const vpColor blue
static const vpColor lightGray
static const vpColor lightBlue
static const vpColor darkGreen
static const vpColor darkBlue
static const vpColor purple
static const vpColor lightGreen
static const vpColor yellow
static const vpColor lightRed
static const vpColor green
static const vpColor gray
Error that can be emitted by the vpDisplay class and its derivatives.
@ connexionError
Connection error.
@ colorAllocError
Color allocation error.
@ cannotOpenWindowError
Unable to open display window.
@ notInitializedError
Display not initialized.
@ XWindowsError
XWindow error.
@ depthNotSupportedError
Color depth not supported.
void displayImage(const vpImage< unsigned char > &I)
void setTitle(const std::string &title)
unsigned int getScreenDepth()
void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height)
void displayCharString(const vpImagePoint &ip, const char *text, const vpColor &color=vpColor::green)
void clearDisplay(const vpColor &color=vpColor::white)
void getScreenSize(unsigned int &width, unsigned int &height)
bool getPointerPosition(vpImagePoint &ip)
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="")
void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
void setWindowPosition(int win_x, int win_y)
void getImage(vpImage< vpRGBa > &I)
get the window pixmap and put it in vpRGBa image
void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
bool getClick(bool blocking=true)
void setFont(const std::string &font)
void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1)
unsigned int getScreenHeight()
void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
void displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, unsigned int width, unsigned int height)
bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true)
bool getKeyboardEvent(bool blocking=true)
unsigned int getScreenWidth()
bool getPointerMotionEvent(vpImagePoint &ip)
void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1)
void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
Class that defines generic functionalities for display.
static void display(const vpImage< unsigned char > &I)
int m_windowXPosition
display position
int m_windowYPosition
display position
bool m_displayHasBeenInitialized
display has been initialized
void setScale(vpScaleType scaleType, unsigned int width, unsigned int height)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
static double distance(const vpImagePoint &iP1, const vpImagePoint &iP2)
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Type * bitmap
points toward the bitmap
unsigned int getHeight() const
static double sqr(double x)
static int round(double x)
unsigned char B
Blue component.
unsigned char R
Red component.
unsigned char G
Green component.
unsigned char A
Additionnal component.
Defines a rectangle in the plane.
vpImagePoint getTopLeft() const