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(nullptr), window(), Ximage(nullptr), lut(), context(), screen(0), event(), pixmap(), x_color(nullptr),
79 screen_depth(8), xcolor(), values(), ximage_data_init(false), RMask(0), GMask(0), BMask(0), RShift(0), GShift(0),
88 XSetWindowBackground(
display, window, x_color[color.
id]);
91 xcolor.red = 256 * color.
R;
92 xcolor.green = 256 * color.
G;
93 xcolor.blue = 256 * color.
B;
94 XAllocColor(
display, lut, &xcolor);
95 XSetForeground(
display, context, xcolor.pixel);
102 pixmap = XCreatePixmap(
display, window, width, height, screen_depth);
107 if (ximage_data_init ==
true)
110 Ximage->data =
nullptr;
111 XDestroyImage(Ximage);
116 XDestroyWindow(
display, window);
119 if (x_color !=
nullptr) {
128 XSetForeground(
display, context, x_color[color.
id]);
131 xcolor.red = 256 * color.
R;
132 xcolor.green = 256 * color.
G;
133 xcolor.blue = 256 * color.
B;
134 XAllocColor(
display, lut, &xcolor);
135 XSetForeground(
display, context, xcolor.pixel);
137 XDrawString(
display, pixmap, context, (
int)(ip.
get_u() / scale), (
int)(ip.
get_v() / scale), text.c_str(),
142 unsigned int thickness,
unsigned int scale)
145 XSetForeground(
display, context, x_color[color.
id]);
148 xcolor.red = 256 * color.
R;
149 xcolor.green = 256 * color.
G;
150 xcolor.blue = 256 * color.
B;
151 XAllocColor(
display, lut, &xcolor);
152 XSetForeground(
display, context, xcolor.pixel);
155 XSetLineAttributes(
display, context, thickness, LineSolid, CapButt, JoinBevel);
159 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)
214 unsigned char *dst_8 = (
unsigned char *)Ximage->data;
216 for (
unsigned int i = 0; i < height; i++) {
217 for (
unsigned int j = 0; j < width; j++) {
218 unsigned char nivGris = I[i * scale][j * scale];
219 if (nivGris > nivGrisMax)
222 dst_8[k++] = nivGris;
228 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
229 XSetWindowBackgroundPixmap(
display, window, pixmap);
233 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
235 for (
unsigned int i = 0; i < height; i++) {
236 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
237 unsigned short *dst_16 = (
unsigned short *)dst_8;
238 for (
unsigned int j = 0; j < width; j++) {
239 *(dst_16 + j) = (
unsigned short)colortable[I[i][j]];
244 for (
unsigned int i = 0; i < height; i++) {
245 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
246 unsigned short *dst_16 = (
unsigned short *)dst_8;
247 for (
unsigned int j = 0; j < width; j++) {
248 *(dst_16 + j) = (
unsigned short)colortable[I[i * scale][j * scale]];
254 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
255 XSetWindowBackgroundPixmap(
display, window, pixmap);
261 unsigned char *dst_32 = (
unsigned char *)Ximage->data;
263 unsigned int size_ = width * height;
264 unsigned char *bitmap = I.
bitmap;
265 unsigned char *n = I.
bitmap + size_;
268 if (XImageByteOrder(
display) == 1) {
271 unsigned char val = *(bitmap++);
281 unsigned char val = *(bitmap++);
290 if (XImageByteOrder(
display) == 1) {
292 for (
unsigned int i = 0; i < height; i++) {
293 for (
unsigned int j = 0; j < width; j++) {
294 unsigned char val = I[i * scale][j * scale];
304 for (
unsigned int i = 0; i < height; i++) {
305 for (
unsigned int j = 0; j < width; j++) {
306 unsigned char val = I[i * scale][j * scale];
317 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
318 XSetWindowBackgroundPixmap(
display, window, pixmap);
326 switch (screen_depth) {
329 unsigned int r, g, b;
330 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
333 for (
unsigned int i = 0; i < height; i++) {
334 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
335 unsigned short *dst_16 = (
unsigned short *)dst_8;
336 for (
unsigned int j = 0; j < width; j++) {
341 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
347 for (
unsigned int i = 0; i < height; i++) {
348 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
349 unsigned short *dst_16 = (
unsigned short *)dst_8;
350 for (
unsigned int j = 0; j < width; j++) {
351 vpRGBa val = I[i * scale][j * scale];
356 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
362 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
363 XSetWindowBackgroundPixmap(
display, window, pixmap);
372 unsigned char *dst_32 =
nullptr;
373 dst_32 = (
unsigned char *)Ximage->data;
376 unsigned int sizeI = width * height;
377 if (XImageByteOrder(
display) == 1) {
379 for (
unsigned int i = 0; i < sizeI; i++) {
380 *(dst_32++) = bitmap->
A;
381 *(dst_32++) = bitmap->
R;
382 *(dst_32++) = bitmap->
G;
383 *(dst_32++) = bitmap->
B;
389 for (
unsigned int i = 0; i < sizeI; i++) {
390 *(dst_32++) = bitmap->
B;
391 *(dst_32++) = bitmap->
G;
392 *(dst_32++) = bitmap->
R;
393 *(dst_32++) = bitmap->
A;
399 if (XImageByteOrder(
display) == 1) {
401 for (
unsigned int i = 0; i < height; i++) {
402 for (
unsigned int j = 0; j < width; j++) {
403 vpRGBa val = I[i * scale][j * scale];
413 for (
unsigned int i = 0; i < height; i++) {
414 for (
unsigned int j = 0; j < width; j++) {
415 vpRGBa val = I[i * scale][j * scale];
426 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
427 XSetWindowBackgroundPixmap(
display, window, pixmap);
432 "Unsupported depth (%d bpp) for color display", screen_depth));
436 void displayImage(
const unsigned char *bitmap,
unsigned int width,
unsigned int height)
438 unsigned char *dst_32 = (
unsigned char *)Ximage->data;
439 for (
unsigned int i = 0; i < width * height; i++) {
440 *(dst_32++) = *bitmap;
441 *(dst_32++) = *bitmap;
442 *(dst_32++) = *bitmap;
443 *(dst_32++) = *bitmap;
448 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
449 XSetWindowBackgroundPixmap(
display, window, pixmap);
453 unsigned int scale,
unsigned int width,
unsigned int height)
455 switch (screen_depth) {
461 unsigned char *src_8 = (
unsigned char *)I.
bitmap;
462 unsigned char *dst_8 = (
unsigned char *)Ximage->data;
465 src_8 = src_8 + (int)(iP.
get_i() * iwidth + iP.
get_j());
466 dst_8 = dst_8 + (int)(iP.
get_i() * width + iP.
get_j());
472 unsigned char nivGris = *(src_8 + j);
473 if (nivGris > nivGrisMax)
476 *(dst_8 + j) = nivGris;
479 src_8 = src_8 + iwidth;
480 dst_8 = dst_8 + width;
490 int i_min = std::max<int>((
int)ceil(iP.
get_i() / scale), 0);
491 int j_min = std::max<int>((
int)ceil(iP.
get_j() / scale), 0);
492 int i_max = std::min<int>((
int)ceil((iP.
get_i() + h) / scale), (
int)height);
493 int j_max = std::min<int>((
int)ceil((iP.
get_j() + w) / scale), (
int)width);
495 unsigned int i_min_ = (
unsigned int)i_min;
496 unsigned int i_max_ = (
unsigned int)i_max;
497 unsigned int j_min_ = (
unsigned int)j_min;
498 unsigned int j_max_ = (
unsigned int)j_max;
500 for (
unsigned int i = i_min_; i < i_max_; i++) {
501 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * width;
502 for (
unsigned int j = j_min_; j < j_max_; j++) {
503 unsigned char nivGris = I[i * scale][j * scale];
504 if (nivGris > nivGrisMax)
510 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
514 XSetWindowBackgroundPixmap(
display, window, pixmap);
518 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
520 for (
unsigned int i = (
unsigned int)iP.
get_i(); i < (
unsigned int)(iP.
get_i() + h); i++) {
521 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
522 unsigned short *dst_16 = (
unsigned short *)dst_8;
523 for (
unsigned int j = (
unsigned int)iP.
get_j(); j < (
unsigned int)(iP.
get_j() + w); j++) {
524 *(dst_16 + j) = (
unsigned short)colortable[I[i][j]];
532 int i_min = std::max<int>((
int)ceil(iP.
get_i() / scale), 0);
533 int j_min = std::max<int>((
int)ceil(iP.
get_j() / scale), 0);
534 int i_max = std::min<int>((
int)ceil((iP.
get_i() + h) / scale), (
int)height);
535 int j_max = std::min<int>((
int)ceil((iP.
get_j() + w) / scale), (
int)width);
537 unsigned int i_min_ = (
unsigned int)i_min;
538 unsigned int i_max_ = (
unsigned int)i_max;
539 unsigned int j_min_ = (
unsigned int)j_min;
540 unsigned int j_max_ = (
unsigned int)j_max;
542 for (
unsigned int i = i_min_; i < i_max_; i++) {
543 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
544 unsigned short *dst_16 = (
unsigned short *)dst_8;
545 for (
unsigned int j = j_min_; j < j_max_; j++) {
546 *(dst_16 + j) = (
unsigned short)colortable[I[i * scale][j * scale]];
550 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
553 XSetWindowBackgroundPixmap(
display, window, pixmap);
562 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(iP.
get_i() * 4 * width + iP.
get_j() * 4);
564 if (XImageByteOrder(
display) == 1) {
570 unsigned char val = *(src_8 + j);
572 *(dst_32 + 4 * j + 1) = val;
573 *(dst_32 + 4 * j + 2) = val;
574 *(dst_32 + 4 * j + 3) = val;
577 src_8 = src_8 + iwidth;
578 dst_32 = dst_32 + 4 * width;
588 unsigned char val = *(src_8 + j);
589 *(dst_32 + 4 * j) = val;
590 *(dst_32 + 4 * j + 1) = val;
591 *(dst_32 + 4 * j + 2) = val;
595 src_8 = src_8 + iwidth;
596 dst_32 = dst_32 + 4 * width;
605 int i_min = std::max<int>((
int)ceil(iP.
get_i() / scale), 0);
606 int j_min = std::max<int>((
int)ceil(iP.
get_j() / scale), 0);
607 int i_max = std::min<int>((
int)ceil((iP.
get_i() + h) / scale), (
int)height);
608 int j_max = std::min<int>((
int)ceil((iP.
get_j() + w) / scale), (
int)width);
610 unsigned int i_min_ = (
unsigned int)i_min;
611 unsigned int i_max_ = (
unsigned int)i_max;
612 unsigned int j_min_ = (
unsigned int)j_min;
613 unsigned int j_max_ = (
unsigned int)j_max;
615 if (XImageByteOrder(
display) == 1) {
617 for (
unsigned int i = i_min_; i < i_max_; i++) {
618 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
619 for (
unsigned int j = j_min_; j < j_max_; j++) {
620 unsigned char val = I[i * scale][j * scale];
630 for (
unsigned int i = i_min_; i < i_max_; i++) {
631 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
632 for (
unsigned int j = j_min_; j < j_max_; j++) {
633 unsigned char val = I[i * scale][j * scale];
642 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
645 XSetWindowBackgroundPixmap(
display, window, pixmap);
652 unsigned int scale,
unsigned int width,
unsigned int height)
654 switch (screen_depth) {
657 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
658 for (
unsigned int i = (
unsigned int)iP.
get_i(); i < (
unsigned int)(iP.
get_i() + h); i++) {
659 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
660 unsigned short *dst_16 = (
unsigned short *)dst_8;
661 for (
unsigned int j = (
unsigned int)iP.
get_j(); j < (
unsigned int)(iP.
get_j() + w); j++) {
663 unsigned int r = val.
R;
664 unsigned int g = val.
G;
665 unsigned int b = val.
B;
667 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
674 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
675 int i_min = std::max<int>((
int)ceil(iP.
get_i() / scale), 0);
676 int j_min = std::max<int>((
int)ceil(iP.
get_j() / scale), 0);
677 int i_max = std::min<int>((
int)ceil((iP.
get_i() + h) / scale), (
int)height);
678 int j_max = std::min<int>((
int)ceil((iP.
get_j() + w) / scale), (
int)width);
680 unsigned int i_min_ = (
unsigned int)i_min;
681 unsigned int i_max_ = (
unsigned int)i_max;
682 unsigned int j_min_ = (
unsigned int)j_min;
683 unsigned int j_max_ = (
unsigned int)j_max;
685 for (
unsigned int i = i_min_; i < i_max_; i++) {
686 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
687 unsigned short *dst_16 = (
unsigned short *)dst_8;
688 for (
unsigned int j = j_min_; j < j_max_; j++) {
689 vpRGBa val = I[i * scale][j * scale];
690 unsigned int r = val.
R;
691 unsigned int g = val.
G;
692 unsigned int b = val.
B;
694 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
697 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
700 XSetWindowBackgroundPixmap(
display, window, pixmap);
711 unsigned char *dst_32 = (
unsigned char *)Ximage->data;
716 src_32 = src_32 + (int)(iP.
get_i() * iwidth + iP.
get_j());
717 dst_32 = dst_32 + (int)(iP.
get_i() * 4 * width + iP.
get_j() * 4);
721 if (XImageByteOrder(
display) == 1) {
726 *(dst_32 + 4 * j) = (src_32 + j)->A;
727 *(dst_32 + 4 * j + 1) = (src_32 + j)->R;
728 *(dst_32 + 4 * j + 2) = (src_32 + j)->G;
729 *(dst_32 + 4 * j + 3) = (src_32 + j)->B;
733 src_32 = src_32 + iwidth;
734 dst_32 = dst_32 + 4 * width;
744 *(dst_32 + 4 * j) = (src_32 + j)->B;
745 *(dst_32 + 4 * j + 1) = (src_32 + j)->G;
746 *(dst_32 + 4 * j + 2) = (src_32 + j)->R;
747 *(dst_32 + 4 * j + 3) = (src_32 + j)->A;
751 src_32 = src_32 + iwidth;
752 dst_32 = dst_32 + 4 * width;
761 int i_min = std::max<int>((
int)ceil(iP.
get_i() / scale), 0);
762 int j_min = std::max<int>((
int)ceil(iP.
get_j() / scale), 0);
763 int i_max = std::min<int>((
int)ceil((iP.
get_i() + h) / scale), (
int)height);
764 int j_max = std::min<int>((
int)ceil((iP.
get_j() + w) / scale), (
int)width);
766 unsigned int i_min_ = (
unsigned int)i_min;
767 unsigned int i_max_ = (
unsigned int)i_max;
768 unsigned int j_min_ = (
unsigned int)j_min;
769 unsigned int j_max_ = (
unsigned int)j_max;
771 if (XImageByteOrder(
display) == 1) {
773 for (
unsigned int i = i_min_; i < i_max_; i++) {
774 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
775 for (
unsigned int j = j_min_; j < j_max_; j++) {
776 vpRGBa val = I[i * scale][j * scale];
786 for (
unsigned int i = i_min_; i < i_max_; i++) {
787 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
788 for (
unsigned int j = j_min_; j < j_max_; j++) {
789 vpRGBa val = I[i * scale][j * scale];
797 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
800 XSetWindowBackgroundPixmap(
display, window, pixmap);
805 "Unsupported depth (%d bpp) for color display", screen_depth));
813 XSetForeground(
display, context, x_color[color.
id]);
816 xcolor.red = 256 * color.
R;
817 xcolor.green = 256 * color.
G;
818 xcolor.blue = 256 * color.
B;
819 XAllocColor(
display, lut, &xcolor);
820 XSetForeground(
display, context, xcolor.pixel);
823 XSetLineAttributes(
display, context, thickness, LineSolid, CapButt, JoinBevel);
832 XSetForeground(
display, context, x_color[color.
id]);
835 xcolor.red = 256 * color.
R;
836 xcolor.green = 256 * color.
G;
837 xcolor.blue = 256 * color.
B;
838 XAllocColor(
display, lut, &xcolor);
839 XSetForeground(
display, context, xcolor.pixel);
842 if (thickness == 1) {
847 thickness, thickness);
852 unsigned int thickness,
unsigned int scale)
855 XSetForeground(
display, context, x_color[color.
id]);
858 xcolor.red = 256 * color.
R;
859 xcolor.green = 256 * color.
G;
860 xcolor.blue = 256 * color.
B;
861 XAllocColor(
display, lut, &xcolor);
862 XSetForeground(
display, context, xcolor.pixel);
864 XSetLineAttributes(
display, context, thickness, LineSolid, CapButt, JoinBevel);
883 XClearArea(
display, window, (
int)(iP.
get_u() / scale), (
int)(iP.
get_v() / scale), w / scale, h / scale, 0);
890 Window rootwin, childwin;
891 int root_x, root_y, win_x, win_y;
892 unsigned int modifier;
896 XCheckMaskEvent(
display, ButtonPressMask, &event);
897 XCheckMaskEvent(
display, ButtonReleaseMask, &event);
898 XMaskEvent(
display, ButtonPressMask, &event);
902 ret = XCheckMaskEvent(
display, ButtonPressMask, &event);
907 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
908 ip.
set_u((
double)event.xbutton.x * scale);
909 ip.
set_v((
double)event.xbutton.y * scale);
910 switch (event.xbutton.button) {
930 Window rootwin, childwin;
931 int root_x, root_y, win_x, win_y;
932 unsigned int modifier;
936 XCheckMaskEvent(
display, ButtonPressMask, &event);
937 XCheckMaskEvent(
display, ButtonReleaseMask, &event);
938 XMaskEvent(
display, ButtonReleaseMask, &event);
942 ret = XCheckMaskEvent(
display, ButtonReleaseMask, &event);
947 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
948 ip.
set_u((
double)event.xbutton.x * scale);
949 ip.
set_v((
double)event.xbutton.y * scale);
950 switch (event.xbutton.button) {
971 XCopyArea(
display, window, pixmap, context, 0, 0, width, height, 0, 0);
973 xi = XGetImage(
display, pixmap, 0, 0, width, height, AllPlanes, ZPixmap);
977 unsigned char *src_32 =
nullptr;
978 src_32 = (
unsigned char *)xi->data;
980 if (screen_depth == 16) {
981 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
982 size_t i_ = i * width;
983 for (
unsigned int j = 0; j < height; j++) {
985 unsigned long pixel = XGetPixel(xi, (
int)j, (
int)i);
986 I.
bitmap[ij_].R = (((pixel & RMask) << RShift) >> 8);
987 I.
bitmap[ij_].G = (((pixel & GMask) << GShift) >> 8);
988 I.
bitmap[ij_].B = (((pixel & BMask) << BShift) >> 8);
998 if (XImageByteOrder(
display) == 1) {
1000 for (
unsigned int i = 0; i < width * height; i++) {
1005 I.
bitmap[i].R = src_32[i * 4 + 1];
1006 I.
bitmap[i].G = src_32[i * 4 + 2];
1007 I.
bitmap[i].B = src_32[i * 4 + 3];
1012 for (
unsigned int i = 0; i < width * height; i++) {
1013 I.
bitmap[i].B = src_32[i * 4];
1014 I.
bitmap[i].G = src_32[i * 4 + 1];
1015 I.
bitmap[i].R = src_32[i * 4 + 2];
1032 XMaskEvent(
display, KeyPressMask, &event);
1036 ret = XCheckMaskEvent(
display, KeyPressMask, &event);
1047 XComposeStatus compose_status;
1052 XMaskEvent(
display, KeyPressMask, &event);
1053 XLookupString((XKeyEvent *)&event, &buffer, 1, &keysym, &compose_status);
1058 ret = XCheckMaskEvent(
display, KeyPressMask, &event);
1060 XLookupString((XKeyEvent *)&event, &buffer, 1, &keysym, &compose_status);
1071 int getMsb(
unsigned int u32val)
1075 for (i = 31; i >= 0; --i) {
1076 if (u32val & 0x80000000L)
1087 Window rootwin, childwin;
1088 int root_x, root_y, win_x, win_y;
1089 unsigned int modifier;
1091 ret = XCheckMaskEvent(
display, PointerMotionMask, &event);
1095 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
1096 ip.
set_u((
double)event.xbutton.x * scale);
1097 ip.
set_v((
double)event.xbutton.y * scale);
1107 Window rootwin, childwin;
1108 int root_x, root_y, win_x, win_y;
1109 unsigned int modifier;
1115 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
1116 ip.
set_u((
double)win_x * scale);
1117 ip.
set_v((
double)win_y * scale);
1130 if ((display_ = XOpenDisplay(
nullptr)) ==
nullptr) {
1132 XDisplayName(
nullptr)));
1134 screen_ = DefaultScreen(display_);
1135 depth = (
unsigned int)DefaultDepth(display_, screen_);
1137 XCloseDisplay(display_);
1147 if ((display_ = XOpenDisplay(
nullptr)) ==
nullptr) {
1149 XDisplayName(
nullptr)));
1151 screen_ = DefaultScreen(display_);
1152 w = (
unsigned int)DisplayWidth(display_, screen_);
1153 h = (
unsigned int)DisplayHeight(display_, screen_);
1155 XCloseDisplay(display_);
1158 void init(
unsigned int win_width,
unsigned int win_height,
int win_x,
int win_y,
const std::string &win_title)
1160 if (x_color ==
nullptr) {
1168 if ((win_x < 0) || (win_y < 0)) {
1172 hints.flags = USPosition;
1177 if ((
display = XOpenDisplay(
nullptr)) ==
nullptr) {
1178 vpERROR_TRACE(
"Can't connect display on server %s.\n", XDisplayName(
nullptr));
1182 screen = DefaultScreen(
display);
1183 lut = DefaultColormap(
display, screen);
1184 screen_depth = (
unsigned int)DefaultDepth(
display, screen);
1186 vpTRACE(
"Screen depth: %d\n", screen_depth);
1188 if ((window = XCreateSimpleWindow(
display, RootWindow(
display, screen), win_x, win_y, win_width, win_height, 1,
1189 BlackPixel(
display, screen), WhitePixel(
display, screen))) == 0) {
1197 if (screen_depth == 8) {
1198 lut = XCreateColormap(
display, window, DefaultVisual(
display, screen), AllocAll);
1199 xcolor.flags = DoRed | DoGreen | DoBlue;
1201 for (
unsigned int i = 0; i < 256; i++) {
1203 xcolor.red = 256 * i;
1204 xcolor.green = 256 * i;
1205 xcolor.blue = 256 * i;
1206 XStoreColor(
display, lut, &xcolor);
1209 XSetWindowColormap(
display, window, lut);
1210 XInstallColormap(
display, lut);
1213 else if (screen_depth == 16) {
1214 for (
unsigned int i = 0; i < 256; i++) {
1216 xcolor.red = xcolor.green = xcolor.blue = 256 * i;
1217 if (XAllocColor(
display, lut, &xcolor) == 0) {
1218 vpERROR_TRACE(
"Can't allocate 256 colors. Only %d allocated.", i);
1221 colortable[i] = xcolor.pixel;
1224 XSetWindowColormap(
display, window, lut);
1225 XInstallColormap(
display, lut);
1227 Visual *visual = DefaultVisual(
display, screen);
1228 RMask = visual->red_mask;
1229 GMask = visual->green_mask;
1230 BMask = visual->blue_mask;
1232 RShift = 15 - getMsb(RMask);
1233 GShift = 15 - getMsb(GMask);
1234 BShift = 15 - getMsb(BMask);
1242 switch (screen_depth) {
1252 xcolor.
red = 256 * 192;
1253 xcolor.
green = 256 * 192;
1254 xcolor.
blue = 256 * 192;
1255 XStoreColor(
display, lut, &xcolor);
1260 xcolor.red = 256 * 128;
1261 xcolor.green = 256 * 128;
1262 xcolor.blue = 256 * 128;
1263 XStoreColor(
display, lut, &xcolor);
1268 xcolor.red = 256 * 64;
1269 xcolor.green = 256 * 64;
1270 xcolor.blue = 256 * 64;
1271 XStoreColor(
display, lut, &xcolor);
1276 xcolor.red = 256 * 255;
1277 xcolor.green = 256 * 140;
1278 xcolor.blue = 256 * 140;
1279 XStoreColor(
display, lut, &xcolor);
1284 xcolor.red = 256 * 255;
1287 XStoreColor(
display, lut, &xcolor);
1292 xcolor.red = 256 * 128;
1295 XStoreColor(
display, lut, &xcolor);
1300 xcolor.red = 256 * 140;
1301 xcolor.green = 256 * 255;
1302 xcolor.blue = 256 * 140;
1303 XStoreColor(
display, lut, &xcolor);
1309 xcolor.green = 256 * 255;
1311 XStoreColor(
display, lut, &xcolor);
1317 xcolor.green = 256 * 128;
1319 XStoreColor(
display, lut, &xcolor);
1324 xcolor.red = 256 * 140;
1325 xcolor.green = 256 * 140;
1326 xcolor.blue = 256 * 255;
1327 XStoreColor(
display, lut, &xcolor);
1334 xcolor.blue = 256 * 255;
1335 XStoreColor(
display, lut, &xcolor);
1342 xcolor.blue = 256 * 128;
1343 XStoreColor(
display, lut, &xcolor);
1348 xcolor.red = 256 * 255;
1349 xcolor.green = 256 * 255;
1351 XStoreColor(
display, lut, &xcolor);
1356 xcolor.red = 256 * 255;
1357 xcolor.green = 256 * 165;
1359 XStoreColor(
display, lut, &xcolor);
1365 xcolor.green = 256 * 255;
1366 xcolor.blue = 256 * 255;
1367 XStoreColor(
display, lut, &xcolor);
1372 xcolor.red = 256 * 128;
1374 xcolor.blue = 256 * 128;
1375 XStoreColor(
display, lut, &xcolor);
1382 xcolor.flags = DoRed | DoGreen | DoBlue;
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 xcolor.
red = 256 * pcolor.
R;
1523 xcolor.green = 256 * pcolor.
G;
1524 xcolor.blue = 256 * pcolor.
B;
1525 XAllocColor(
display, lut, &xcolor);
1531 xcolor.
red = 256 * pcolor.
R;
1532 xcolor.green = 256 * pcolor.
G;
1533 xcolor.blue = 256 * pcolor.
B;
1534 XAllocColor(
display, lut, &xcolor);
1540 xcolor.
red = 256 * pcolor.
R;
1541 xcolor.green = 256 * pcolor.
G;
1542 xcolor.blue = 256 * pcolor.
B;
1543 XAllocColor(
display, lut, &xcolor);
1549 XSetStandardProperties(
display, window, win_title.c_str(), win_title.c_str(), None, 0, 0, &hints);
1553 ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
1554 StructureNotifyMask | PointerMotionMask);
1557 values.plane_mask = AllPlanes;
1558 values.fill_style = FillSolid;
1559 values.foreground = WhitePixel(
display, screen);
1560 values.background = BlackPixel(
display, screen);
1561 context = XCreateGC(
display, window, GCPlaneMask | GCFillStyle | GCForeground | GCBackground, &values);
1563 if (context ==
nullptr) {
1569 pixmap = XCreatePixmap(
display, window, win_width, win_height, screen_depth);
1577 Ximage = XCreateImage(
display, DefaultVisual(
display, screen), screen_depth, ZPixmap, 0,
nullptr, win_width,
1578 win_height, XBitmapPad(
display), 0);
1580 Ximage->data = (
char *)malloc(win_height * (
unsigned int)Ximage->bytes_per_line);
1581 ximage_data_init =
true;
1586 XStoreName(
display, window, win_title.c_str());
1589 void setFont(
const std::string &fontname)
1593 stringfont = XLoadFont(
display, fontname.c_str());
1594 XSetFont(
display, context, stringfont);
1601 void setTitle(
const std::string &title) { XStoreName(
display, window, title.c_str()); }
1614 unsigned long *x_color;
1615 unsigned int screen_depth;
1616 unsigned short colortable[256];
1619 bool ximage_data_init;
1620 unsigned int RMask, GMask, BMask;
1621 int RShift, GShift, BShift;
1676 init(I, x, y, title);
1729 init(I, x, y, title);
1809 if (!win_title.empty())
1838 if (!win_title.empty())
1856 const std::string &win_title)
1892 if (!fontname.empty()) {
1893 m_impl->setFont(fontname);
1910 m_impl->setTitle(title);
1929 m_impl->setWindowPosition(win_x, win_y);
2060 m_impl->closeDisplay();
2074 m_impl->flushDisplay();
2091 m_impl->flushDisplayROI(iP, w, h,
m_scale);
2120 unsigned int h,
unsigned int thickness)
2128 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon()) &&
2129 (std::fabs(b) <= std::numeric_limits<double>::epsilon())) {
2175 m_impl->displayText(ip, text, color,
m_scale);
2192 unsigned int thickness)
2197 m_impl->displayCircle(center, radius, color, fill, thickness,
m_scale);
2212 unsigned int thickness)
2215 double i = ip.
get_i();
2216 double j = ip.
get_j();
2219 ip1.
set_i(i - cross_size / 2);
2221 ip2.
set_i(i + cross_size / 2);
2226 ip1.
set_j(j - cross_size / 2);
2228 ip2.
set_j(j + cross_size / 2);
2243 unsigned int thickness)
2249 m_impl->displayDotLine(ip1, ip2, color, thickness,
m_scale);
2263 unsigned int thickness)
2268 m_impl->displayLine(ip1, ip2, color, thickness,
m_scale);
2284 m_impl->displayPoint(ip, color, thickness,
m_scale);
2305 bool fill,
unsigned int thickness)
2311 m_impl->displayRectangle(topLeft, w, h, color, fill, thickness,
m_scale);
2331 bool fill,
unsigned int thickness)
2340 m_impl->displayRectangle(topLeft, w, h, color, fill, thickness,
m_scale);
2367 m_impl->displayRectangle(topLeft, w, h, color, fill, thickness,
m_scale);
2396 ret = m_impl->getClick(ip, button, blocking,
m_scale);
2425 ret = m_impl->getClick(ip, button, blocking,
m_scale);
2457 ret = m_impl->getClick(ip, button, blocking,
m_scale);
2493 ret = m_impl->getClickUp(ip, button, blocking,
m_scale);
2534 unsigned int width, height;
2544 unsigned int width, height;
2574 ret = m_impl->getKeyboardEvent(blocking);
2609 ret = m_impl->getKeyboardEvent(key, blocking);
2633 ret = m_impl->getPointerMotionEvent(ip,
m_scale);
2655 ret = m_impl->getPointerPosition(ip,
m_scale);
2663 #elif !defined(VISP_BUILD_SHARED_LIBS)
2665 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) vp_override
unsigned int getScreenDepth()
bool getClick(bool blocking=true) vp_override
void setTitle(const std::string &title) vp_override
void setWindowPosition(int win_x, int win_y) vp_override
bool getClickUp(vpImagePoint &ip, vpMouseButton::vpMouseButtonType &button, bool blocking=true) vp_override
void displayCircle(const vpImagePoint ¢er, unsigned int radius, const vpColor &color, bool fill=false, unsigned int thickness=1) vp_override
void displayText(const vpImagePoint &ip, const std::string &text, const vpColor &color=vpColor::green) vp_override
bool getPointerPosition(vpImagePoint &ip) vp_override
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) vp_override
void displayLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1) vp_override
void displayImageROI(const vpImage< unsigned char > &I, const vpImagePoint &iP, unsigned int width, unsigned int height) vp_override
void clearDisplay(const vpColor &color=vpColor::white) vp_override
void flushDisplayROI(const vpImagePoint &iP, unsigned int width, unsigned int height) vp_override
void getImage(vpImage< vpRGBa > &I) vp_override
Get the window pixmap and put it in vpRGBa image.
void getScreenSize(unsigned int &width, unsigned int &height) vp_override
bool getKeyboardEvent(bool blocking=true) vp_override
bool getPointerMotionEvent(vpImagePoint &ip) vp_override
void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1) vp_override
void setFont(const std::string &font) vp_override
void displayCross(const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1) vp_override
void displayDotLine(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1) vp_override
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="") vp_override
unsigned int getScreenWidth() vp_override
void displayPoint(const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1) vp_override
void closeDisplay() vp_override
unsigned int getScreenHeight() vp_override
void flushDisplay() vp_override
virtual ~vpDisplayX() vp_override
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