45 #include <visp3/core/vpConfig.h>
55 #include <visp3/core/vpDisplay.h>
56 #include <visp3/gui/vpDisplayX.h>
59 #include <visp3/core/vpDebug.h>
60 #include <visp3/core/vpDisplayException.h>
63 #include <visp3/core/vpMath.h>
65 #ifndef DOXYGEN_SHOULD_SKIP_THIS
68 #include <X11/Xutil.h>
75 class vpDisplayX::Impl
79 :
display(NULL), window(), Ximage(NULL), lut(), context(), screen(0), event(), pixmap(), x_color(NULL),
80 screen_depth(8), xcolor(), values(), ximage_data_init(false), RMask(0), GMask(0), BMask(0), RShift(0), GShift(0),
90 XSetWindowBackground(
display, window, x_color[color.
id]);
93 xcolor.red = 256 * color.
R;
94 xcolor.green = 256 * color.
G;
95 xcolor.blue = 256 * color.
B;
96 XAllocColor(
display, lut, &xcolor);
97 XSetForeground(
display, context, xcolor.pixel);
104 pixmap = XCreatePixmap(
display, window, width, height, screen_depth);
109 if (ximage_data_init ==
true)
113 XDestroyImage(Ximage);
118 XDestroyWindow(
display, window);
121 if (x_color != NULL) {
130 XSetForeground(
display, context, x_color[color.
id]);
133 xcolor.red = 256 * color.
R;
134 xcolor.green = 256 * color.
G;
135 xcolor.blue = 256 * color.
B;
136 XAllocColor(
display, lut, &xcolor);
137 XSetForeground(
display, context, xcolor.pixel);
139 XDrawString(
display, pixmap, context, (
int)(ip.
get_u() / scale), (
int)(ip.
get_v() / scale), text,
144 unsigned int thickness,
unsigned int scale)
147 XSetForeground(
display, context, x_color[color.
id]);
150 xcolor.red = 256 * color.
R;
151 xcolor.green = 256 * color.
G;
152 xcolor.blue = 256 * color.
B;
153 XAllocColor(
display, lut, &xcolor);
154 XSetForeground(
display, context, xcolor.pixel);
157 XSetLineAttributes(
display, context, thickness, LineSolid, CapButt, JoinBevel);
161 vpMath::round((center.
get_v() - radius) / scale), radius * 2 / scale, radius * 2 / scale, 0,
165 vpMath::round((center.
get_v() - radius) / scale), radius * 2 / scale, radius * 2 / scale, 0,
174 XSetForeground(
display, context, x_color[color.
id]);
177 xcolor.red = 256 * color.
R;
178 xcolor.green = 256 * color.
G;
179 xcolor.blue = 256 * color.
B;
180 XAllocColor(
display, lut, &xcolor);
181 XSetForeground(
display, context, xcolor.pixel);
184 XSetLineAttributes(
display, context, thickness, LineOnOffDash, CapButt, JoinBevel);
192 switch (screen_depth) {
198 unsigned char *src_8 = (
unsigned char *)I.
bitmap;
199 unsigned char *dst_8 = (
unsigned char *)Ximage->data;
201 unsigned int size = width * height;
204 unsigned char nivGris = src_8[i];
205 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]];
243 for (
unsigned int i = 0; i < height; i++) {
244 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
245 unsigned short *dst_16 = (
unsigned short *)dst_8;
246 for (
unsigned int j = 0; j < width; j++) {
247 *(dst_16 + j) = (
unsigned short)colortable[I[i * scale][j * scale]];
253 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
254 XSetWindowBackgroundPixmap(
display, window, pixmap);
260 unsigned char *dst_32 = (
unsigned char *)Ximage->data;
262 unsigned int size_ = width * height;
263 unsigned char *bitmap = I.
bitmap;
264 unsigned char *n = I.
bitmap + size_;
267 if (XImageByteOrder(
display) == 1) {
270 unsigned char val = *(bitmap++);
279 unsigned char val = *(bitmap++);
287 if (XImageByteOrder(
display) == 1) {
289 for (
unsigned int i = 0; i < height; i++) {
290 for (
unsigned int j = 0; j < width; j++) {
291 unsigned char val = I[i * scale][j * scale];
300 for (
unsigned int i = 0; i < height; i++) {
301 for (
unsigned int j = 0; j < width; j++) {
302 unsigned char val = I[i * scale][j * scale];
313 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
314 XSetWindowBackgroundPixmap(
display, window, pixmap);
322 switch (screen_depth) {
325 unsigned int r, g, b;
326 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
329 for (
unsigned int i = 0; i < height; i++) {
330 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
331 unsigned short *dst_16 = (
unsigned short *)dst_8;
332 for (
unsigned int j = 0; j < width; j++) {
337 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
342 for (
unsigned int i = 0; i < height; i++) {
343 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
344 unsigned short *dst_16 = (
unsigned short *)dst_8;
345 for (
unsigned int j = 0; j < width; j++) {
346 vpRGBa val = I[i * scale][j * scale];
351 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
357 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
358 XSetWindowBackgroundPixmap(
display, window, pixmap);
367 unsigned char *dst_32 = NULL;
368 dst_32 = (
unsigned char *)Ximage->data;
371 unsigned int sizeI = width * height;
372 if (XImageByteOrder(
display) == 1) {
374 for (
unsigned int i = 0; i < sizeI; i++) {
375 *(dst_32++) = bitmap->
A;
376 *(dst_32++) = bitmap->
R;
377 *(dst_32++) = bitmap->
G;
378 *(dst_32++) = bitmap->
B;
383 for (
unsigned int i = 0; i < sizeI; i++) {
384 *(dst_32++) = bitmap->
B;
385 *(dst_32++) = bitmap->
G;
386 *(dst_32++) = bitmap->
R;
387 *(dst_32++) = bitmap->
A;
392 if (XImageByteOrder(
display) == 1) {
394 for (
unsigned int i = 0; i < height; i++) {
395 for (
unsigned int j = 0; j < width; j++) {
396 vpRGBa val = I[i * scale][j * scale];
405 for (
unsigned int i = 0; i < height; i++) {
406 for (
unsigned int j = 0; j < width; j++) {
407 vpRGBa val = I[i * scale][j * scale];
418 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
419 XSetWindowBackgroundPixmap(
display, window, pixmap);
424 "Unsupported depth (%d bpp) for color display", screen_depth));
428 void displayImage(
const unsigned char *bitmap,
unsigned int width,
unsigned int height)
430 unsigned char *dst_32 = (
unsigned char *)Ximage->data;
431 for (
unsigned int i = 0; i < width * height; i++) {
432 *(dst_32++) = *bitmap;
433 *(dst_32++) = *bitmap;
434 *(dst_32++) = *bitmap;
435 *(dst_32++) = *bitmap;
440 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
441 XSetWindowBackgroundPixmap(
display, window, pixmap);
445 unsigned int scale,
unsigned int width,
unsigned int height)
447 switch (screen_depth) {
453 unsigned char *src_8 = (
unsigned char *)I.
bitmap;
454 unsigned char *dst_8 = (
unsigned char *)Ximage->data;
457 src_8 = src_8 + (int)(iP.
get_i() * iwidth + iP.
get_j());
458 dst_8 = dst_8 + (int)(iP.
get_i() * width + iP.
get_j());
464 unsigned char nivGris = *(src_8 + j);
465 if (nivGris > nivGrisMax)
468 *(dst_8 + j) = nivGris;
471 src_8 = src_8 + iwidth;
472 dst_8 = dst_8 + width;
481 int i_min = (std::max)((
int)ceil(iP.
get_i() / scale), 0);
482 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
483 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
484 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
486 unsigned int i_min_ = (
unsigned int)i_min;
487 unsigned int i_max_ = (
unsigned int)i_max;
488 unsigned int j_min_ = (
unsigned int)j_min;
489 unsigned int j_max_ = (
unsigned int)j_max;
491 for (
unsigned int i = i_min_; i < i_max_; i++) {
492 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * width;
493 for (
unsigned int j = j_min_; j < j_max_; j++) {
494 unsigned char nivGris = I[i * scale][j * scale];
495 if (nivGris > nivGrisMax)
501 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
505 XSetWindowBackgroundPixmap(
display, window, pixmap);
509 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
511 for (
unsigned int i = (
unsigned int)iP.
get_i(); i < (
unsigned int)(iP.
get_i() + h); i++) {
512 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
513 unsigned short *dst_16 = (
unsigned short *)dst_8;
514 for (
unsigned int j = (
unsigned int)iP.
get_j(); j < (
unsigned int)(iP.
get_j() + w); j++) {
515 *(dst_16 + j) = (
unsigned short)colortable[I[i][j]];
522 int i_min = (std::max)((
int)ceil(iP.
get_i() / scale), 0);
523 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
524 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
525 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
527 unsigned int i_min_ = (
unsigned int)i_min;
528 unsigned int i_max_ = (
unsigned int)i_max;
529 unsigned int j_min_ = (
unsigned int)j_min;
530 unsigned int j_max_ = (
unsigned int)j_max;
532 for (
unsigned int i = i_min_; i < i_max_; i++) {
533 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
534 unsigned short *dst_16 = (
unsigned short *)dst_8;
535 for (
unsigned int j = j_min_; j < j_max_; j++) {
536 *(dst_16 + j) = (
unsigned short)colortable[I[i * scale][j * scale]];
540 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
543 XSetWindowBackgroundPixmap(
display, window, pixmap);
552 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(iP.
get_i() * 4 * width + iP.
get_j() * 4);
554 if (XImageByteOrder(
display) == 1) {
560 unsigned char val = *(src_8 + j);
562 *(dst_32 + 4 * j + 1) = val;
563 *(dst_32 + 4 * j + 2) = val;
564 *(dst_32 + 4 * j + 3) = val;
567 src_8 = src_8 + iwidth;
568 dst_32 = dst_32 + 4 * width;
577 unsigned char val = *(src_8 + j);
578 *(dst_32 + 4 * j) = val;
579 *(dst_32 + 4 * j + 1) = val;
580 *(dst_32 + 4 * j + 2) = val;
584 src_8 = src_8 + iwidth;
585 dst_32 = dst_32 + 4 * width;
593 int i_min = (std::max)((
int)ceil(iP.
get_i() / scale), 0);
594 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
595 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
596 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
598 unsigned int i_min_ = (
unsigned int)i_min;
599 unsigned int i_max_ = (
unsigned int)i_max;
600 unsigned int j_min_ = (
unsigned int)j_min;
601 unsigned int j_max_ = (
unsigned int)j_max;
603 if (XImageByteOrder(
display) == 1) {
605 for (
unsigned int i = i_min_; i < i_max_; i++) {
606 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
607 for (
unsigned int j = j_min_; j < j_max_; j++) {
608 unsigned char val = I[i * scale][j * scale];
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];
629 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
632 XSetWindowBackgroundPixmap(
display, window, pixmap);
639 unsigned int scale,
unsigned int width,
unsigned int height)
641 switch (screen_depth) {
644 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
645 for (
unsigned int i = (
unsigned int)iP.
get_i(); i < (
unsigned int)(iP.
get_i() + h); i++) {
646 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
647 unsigned short *dst_16 = (
unsigned short *)dst_8;
648 for (
unsigned int j = (
unsigned int)iP.
get_j(); j < (
unsigned int)(iP.
get_j() + w); j++) {
650 unsigned int r = val.
R;
651 unsigned int g = val.
G;
652 unsigned int b = val.
B;
654 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
660 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
661 int i_min = (std::max)((int)ceil(iP.
get_i() / scale), 0);
662 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
663 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
664 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
666 unsigned int i_min_ = (
unsigned int)i_min;
667 unsigned int i_max_ = (
unsigned int)i_max;
668 unsigned int j_min_ = (
unsigned int)j_min;
669 unsigned int j_max_ = (
unsigned int)j_max;
671 for (
unsigned int i = i_min_; i < i_max_; i++) {
672 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
673 unsigned short *dst_16 = (
unsigned short *)dst_8;
674 for (
unsigned int j = j_min_; j < j_max_; j++) {
675 vpRGBa val = I[i * scale][j * scale];
676 unsigned int r = val.
R;
677 unsigned int g = val.
G;
678 unsigned int b = val.
B;
680 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
683 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
686 XSetWindowBackgroundPixmap(
display, window, pixmap);
697 unsigned char *dst_32 = (
unsigned char *)Ximage->data;
702 src_32 = src_32 + (int)(iP.
get_i() * iwidth + iP.
get_j());
703 dst_32 = dst_32 + (int)(iP.
get_i() * 4 * width + iP.
get_j() * 4);
707 if (XImageByteOrder(
display) == 1) {
712 *(dst_32 + 4 * j) = (src_32 + j)->A;
713 *(dst_32 + 4 * j + 1) = (src_32 + j)->R;
714 *(dst_32 + 4 * j + 2) = (src_32 + j)->G;
715 *(dst_32 + 4 * j + 3) = (src_32 + j)->B;
719 src_32 = src_32 + iwidth;
720 dst_32 = dst_32 + 4 * width;
729 *(dst_32 + 4 * j) = (src_32 + j)->B;
730 *(dst_32 + 4 * j + 1) = (src_32 + j)->G;
731 *(dst_32 + 4 * j + 2) = (src_32 + j)->R;
732 *(dst_32 + 4 * j + 3) = (src_32 + j)->A;
736 src_32 = src_32 + iwidth;
737 dst_32 = dst_32 + 4 * width;
745 int i_min = (std::max)((
int)ceil(iP.
get_i() / scale), 0);
746 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
747 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
748 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
750 unsigned int i_min_ = (
unsigned int)i_min;
751 unsigned int i_max_ = (
unsigned int)i_max;
752 unsigned int j_min_ = (
unsigned int)j_min;
753 unsigned int j_max_ = (
unsigned int)j_max;
755 if (XImageByteOrder(
display) == 1) {
757 for (
unsigned int i = i_min_; i < i_max_; i++) {
758 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
759 for (
unsigned int j = j_min_; j < j_max_; j++) {
760 vpRGBa val = I[i * scale][j * scale];
769 for (
unsigned int i = i_min_; i < i_max_; i++) {
770 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
771 for (
unsigned int j = j_min_; j < j_max_; j++) {
772 vpRGBa val = I[i * scale][j * scale];
780 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
783 XSetWindowBackgroundPixmap(
display, window, pixmap);
788 "Unsupported depth (%d bpp) for color display", screen_depth));
796 XSetForeground(
display, context, x_color[color.
id]);
799 xcolor.red = 256 * color.
R;
800 xcolor.green = 256 * color.
G;
801 xcolor.blue = 256 * color.
B;
802 XAllocColor(
display, lut, &xcolor);
803 XSetForeground(
display, context, xcolor.pixel);
806 XSetLineAttributes(
display, context, thickness, LineSolid, CapButt, JoinBevel);
815 XSetForeground(
display, context, x_color[color.
id]);
818 xcolor.red = 256 * color.
R;
819 xcolor.green = 256 * color.
G;
820 xcolor.blue = 256 * color.
B;
821 XAllocColor(
display, lut, &xcolor);
822 XSetForeground(
display, context, xcolor.pixel);
825 if (thickness == 1) {
829 thickness, thickness);
834 unsigned int thickness,
unsigned int scale)
837 XSetForeground(
display, context, x_color[color.
id]);
840 xcolor.red = 256 * color.
R;
841 xcolor.green = 256 * color.
G;
842 xcolor.blue = 256 * color.
B;
843 XAllocColor(
display, lut, &xcolor);
844 XSetForeground(
display, context, xcolor.pixel);
846 XSetLineAttributes(
display, context, thickness, LineSolid, CapButt, JoinBevel);
864 XClearArea(
display, window, (
int)(iP.
get_u() / scale), (
int)(iP.
get_v() / scale), w / scale, h / scale, 0);
871 Window rootwin, childwin;
872 int root_x, root_y, win_x, win_y;
873 unsigned int modifier;
877 XCheckMaskEvent(
display, ButtonPressMask, &event);
878 XCheckMaskEvent(
display, ButtonReleaseMask, &event);
879 XMaskEvent(
display, ButtonPressMask, &event);
882 ret = XCheckMaskEvent(
display, ButtonPressMask, &event);
887 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
888 ip.
set_u((
double)event.xbutton.x * scale);
889 ip.
set_v((
double)event.xbutton.y * scale);
890 switch (event.xbutton.button) {
910 Window rootwin, childwin;
911 int root_x, root_y, win_x, win_y;
912 unsigned int modifier;
916 XCheckMaskEvent(
display, ButtonPressMask, &event);
917 XCheckMaskEvent(
display, ButtonReleaseMask, &event);
918 XMaskEvent(
display, ButtonReleaseMask, &event);
921 ret = XCheckMaskEvent(
display, ButtonReleaseMask, &event);
926 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
927 ip.
set_u((
double)event.xbutton.x * scale);
928 ip.
set_v((
double)event.xbutton.y * scale);
929 switch (event.xbutton.button) {
950 XCopyArea(
display, window, pixmap, context, 0, 0, width, height, 0, 0);
952 xi = XGetImage(
display, pixmap, 0, 0, width, height, AllPlanes, ZPixmap);
956 unsigned char *src_32 = NULL;
957 src_32 = (
unsigned char *)xi->data;
959 if (screen_depth == 16) {
960 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
961 size_t i_ = i * width;
962 for (
unsigned int j = 0; j < height; j++) {
964 unsigned long pixel = XGetPixel(xi, (
int)j, (
int)i);
965 I.
bitmap[ij_].R = (((pixel & RMask) << RShift) >> 8);
966 I.
bitmap[ij_].G = (((pixel & GMask) << GShift) >> 8);
967 I.
bitmap[ij_].B = (((pixel & BMask) << BShift) >> 8);
976 if (XImageByteOrder(
display) == 1) {
978 for (
unsigned int i = 0; i < width * height; i++) {
983 I.
bitmap[i].R = src_32[i * 4 + 1];
984 I.
bitmap[i].G = src_32[i * 4 + 2];
985 I.
bitmap[i].B = src_32[i * 4 + 3];
989 for (
unsigned int i = 0; i < width * height; i++) {
990 I.
bitmap[i].B = src_32[i * 4];
991 I.
bitmap[i].G = src_32[i * 4 + 1];
992 I.
bitmap[i].R = src_32[i * 4 + 2];
1009 XMaskEvent(
display, KeyPressMask, &event);
1012 ret = XCheckMaskEvent(
display, KeyPressMask, &event);
1023 XComposeStatus compose_status;
1028 XMaskEvent(
display, KeyPressMask, &event);
1029 XLookupString((XKeyEvent *)&event, &buffer, 1, &keysym, &compose_status);
1033 ret = XCheckMaskEvent(
display, KeyPressMask, &event);
1035 XLookupString((XKeyEvent *)&event, &buffer, 1, &keysym, &compose_status);
1046 int getMsb(
unsigned int u32val)
1050 for (i = 31; i >= 0; --i) {
1051 if (u32val & 0x80000000L)
1062 Window rootwin, childwin;
1063 int root_x, root_y, win_x, win_y;
1064 unsigned int modifier;
1066 ret = XCheckMaskEvent(
display, PointerMotionMask, &event);
1070 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
1071 ip.
set_u((
double)event.xbutton.x * scale);
1072 ip.
set_v((
double)event.xbutton.y * scale);
1082 Window rootwin, childwin;
1083 int root_x, root_y, win_x, win_y;
1084 unsigned int modifier;
1090 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
1091 ip.
set_u((
double)win_x * scale);
1092 ip.
set_v((
double)win_y * scale);
1105 if ((display_ = XOpenDisplay(NULL)) == NULL) {
1107 XDisplayName(NULL)));
1109 screen_ = DefaultScreen(display_);
1110 depth = (
unsigned int)DefaultDepth(display_, screen_);
1112 XCloseDisplay(display_);
1122 if ((display_ = XOpenDisplay(NULL)) == NULL) {
1124 XDisplayName(NULL)));
1126 screen_ = DefaultScreen(display_);
1127 w = (
unsigned int)DisplayWidth(display_, screen_);
1128 h = (
unsigned int)DisplayHeight(display_, screen_);
1130 XCloseDisplay(display_);
1133 void init(
unsigned int win_width,
unsigned int win_height,
int win_x,
int win_y,
const std::string &win_title)
1135 if (x_color == NULL) {
1143 if ((win_x < 0) || (win_y < 0)) {
1146 hints.flags = USPosition;
1151 if ((
display = XOpenDisplay(NULL)) == NULL) {
1152 vpERROR_TRACE(
"Can't connect display on server %s.\n", XDisplayName(NULL));
1156 screen = DefaultScreen(
display);
1157 lut = DefaultColormap(
display, screen);
1158 screen_depth = (
unsigned int)DefaultDepth(
display, screen);
1160 vpTRACE(
"Screen depth: %d\n", screen_depth);
1162 if ((window = XCreateSimpleWindow(
display, RootWindow(
display, screen), win_x, win_y, win_width, win_height, 1,
1163 BlackPixel(
display, screen), WhitePixel(
display, screen))) == 0) {
1171 if (screen_depth == 8) {
1172 lut = XCreateColormap(
display, window, DefaultVisual(
display, screen), AllocAll);
1173 xcolor.flags = DoRed | DoGreen | DoBlue;
1175 for (
unsigned int i = 0; i < 256; i++) {
1177 xcolor.red = 256 * i;
1178 xcolor.green = 256 * i;
1179 xcolor.blue = 256 * i;
1180 XStoreColor(
display, lut, &xcolor);
1183 XSetWindowColormap(
display, window, lut);
1184 XInstallColormap(
display, lut);
1187 else if (screen_depth == 16) {
1188 for (
unsigned int i = 0; i < 256; i++) {
1190 xcolor.red = xcolor.green = xcolor.blue = 256 * i;
1191 if (XAllocColor(
display, lut, &xcolor) == 0) {
1192 vpERROR_TRACE(
"Can't allocate 256 colors. Only %d allocated.", i);
1195 colortable[i] = xcolor.pixel;
1198 XSetWindowColormap(
display, window, lut);
1199 XInstallColormap(
display, lut);
1201 Visual *visual = DefaultVisual(
display, screen);
1202 RMask = visual->red_mask;
1203 GMask = visual->green_mask;
1204 BMask = visual->blue_mask;
1206 RShift = 15 - getMsb(RMask);
1207 GShift = 15 - getMsb(GMask);
1208 BShift = 15 - getMsb(BMask);
1216 switch (screen_depth) {
1226 xcolor.
red = 256 * 192;
1227 xcolor.
green = 256 * 192;
1228 xcolor.
blue = 256 * 192;
1229 XStoreColor(
display, lut, &xcolor);
1234 xcolor.red = 256 * 128;
1235 xcolor.green = 256 * 128;
1236 xcolor.blue = 256 * 128;
1237 XStoreColor(
display, lut, &xcolor);
1242 xcolor.red = 256 * 64;
1243 xcolor.green = 256 * 64;
1244 xcolor.blue = 256 * 64;
1245 XStoreColor(
display, lut, &xcolor);
1250 xcolor.red = 256 * 255;
1251 xcolor.green = 256 * 140;
1252 xcolor.blue = 256 * 140;
1253 XStoreColor(
display, lut, &xcolor);
1258 xcolor.red = 256 * 255;
1261 XStoreColor(
display, lut, &xcolor);
1266 xcolor.red = 256 * 128;
1269 XStoreColor(
display, lut, &xcolor);
1274 xcolor.red = 256 * 140;
1275 xcolor.green = 256 * 255;
1276 xcolor.blue = 256 * 140;
1277 XStoreColor(
display, lut, &xcolor);
1283 xcolor.green = 256 * 255;
1285 XStoreColor(
display, lut, &xcolor);
1291 xcolor.green = 256 * 128;
1293 XStoreColor(
display, lut, &xcolor);
1298 xcolor.red = 256 * 140;
1299 xcolor.green = 256 * 140;
1300 xcolor.blue = 256 * 255;
1301 XStoreColor(
display, lut, &xcolor);
1308 xcolor.blue = 256 * 255;
1309 XStoreColor(
display, lut, &xcolor);
1316 xcolor.blue = 256 * 128;
1317 XStoreColor(
display, lut, &xcolor);
1322 xcolor.red = 256 * 255;
1323 xcolor.green = 256 * 255;
1325 XStoreColor(
display, lut, &xcolor);
1330 xcolor.red = 256 * 255;
1331 xcolor.green = 256 * 165;
1333 XStoreColor(
display, lut, &xcolor);
1339 xcolor.green = 256 * 255;
1340 xcolor.blue = 256 * 255;
1341 XStoreColor(
display, lut, &xcolor);
1346 xcolor.red = 256 * 128;
1348 xcolor.blue = 256 * 128;
1349 XStoreColor(
display, lut, &xcolor);
1356 xcolor.flags = DoRed | DoGreen | DoBlue;
1361 xcolor.
red = 256 * pcolor.
R;
1362 xcolor.green = 256 * pcolor.
G;
1363 xcolor.blue = 256 * pcolor.
B;
1364 XAllocColor(
display, lut, &xcolor);
1370 xcolor.
red = 256 * pcolor.
R;
1371 xcolor.green = 256 * pcolor.
G;
1372 xcolor.blue = 256 * pcolor.
B;
1373 XAllocColor(
display, lut, &xcolor);
1379 xcolor.
red = 256 * pcolor.
R;
1380 xcolor.green = 256 * pcolor.
G;
1381 xcolor.blue = 256 * pcolor.
B;
1382 XAllocColor(
display, lut, &xcolor);
1388 xcolor.
red = 256 * pcolor.
R;
1389 xcolor.green = 256 * pcolor.
G;
1390 xcolor.blue = 256 * pcolor.
B;
1391 XAllocColor(
display, lut, &xcolor);
1397 xcolor.
red = 256 * pcolor.
R;
1398 xcolor.green = 256 * pcolor.
G;
1399 xcolor.blue = 256 * pcolor.
B;
1400 XAllocColor(
display, lut, &xcolor);
1406 xcolor.
red = 256 * pcolor.
R;
1407 xcolor.green = 256 * pcolor.
G;
1408 xcolor.blue = 256 * pcolor.
B;
1409 XAllocColor(
display, lut, &xcolor);
1415 xcolor.
red = 256 * pcolor.
R;
1416 xcolor.green = 256 * pcolor.
G;
1417 xcolor.blue = 256 * pcolor.
B;
1418 XAllocColor(
display, lut, &xcolor);
1424 xcolor.
red = 256 * pcolor.
R;
1425 xcolor.green = 256 * pcolor.
G;
1426 xcolor.blue = 256 * pcolor.
B;
1427 XAllocColor(
display, lut, &xcolor);
1433 xcolor.
red = 256 * pcolor.
R;
1434 xcolor.green = 256 * pcolor.
G;
1435 xcolor.blue = 256 * pcolor.
B;
1436 XAllocColor(
display, lut, &xcolor);
1442 xcolor.
red = 256 * pcolor.
R;
1443 xcolor.green = 256 * pcolor.
G;
1444 xcolor.blue = 256 * pcolor.
B;
1445 XAllocColor(
display, lut, &xcolor);
1451 xcolor.
red = 256 * pcolor.
R;
1452 xcolor.green = 256 * pcolor.
G;
1453 xcolor.blue = 256 * pcolor.
B;
1454 XAllocColor(
display, lut, &xcolor);
1460 xcolor.
red = 256 * pcolor.
R;
1461 xcolor.green = 256 * pcolor.
G;
1462 xcolor.blue = 256 * pcolor.
B;
1463 XAllocColor(
display, lut, &xcolor);
1469 xcolor.
red = 256 * pcolor.
R;
1470 xcolor.green = 256 * pcolor.
G;
1471 xcolor.blue = 256 * pcolor.
B;
1472 XAllocColor(
display, lut, &xcolor);
1478 xcolor.
red = 256 * pcolor.
R;
1479 xcolor.green = 256 * pcolor.
G;
1480 xcolor.blue = 256 * pcolor.
B;
1481 XAllocColor(
display, lut, &xcolor);
1487 xcolor.
red = 256 * pcolor.
R;
1488 xcolor.green = 256 * pcolor.
G;
1489 xcolor.blue = 256 * pcolor.
B;
1490 XAllocColor(
display, lut, &xcolor);
1496 xcolor.
red = 256 * pcolor.
R;
1497 xcolor.green = 256 * pcolor.
G;
1498 xcolor.blue = 256 * pcolor.
B;
1499 XAllocColor(
display, lut, &xcolor);
1505 xcolor.
red = 256 * pcolor.
R;
1506 xcolor.green = 256 * pcolor.
G;
1507 xcolor.blue = 256 * pcolor.
B;
1508 XAllocColor(
display, lut, &xcolor);
1514 xcolor.
red = 256 * pcolor.
R;
1515 xcolor.green = 256 * pcolor.
G;
1516 xcolor.blue = 256 * pcolor.
B;
1517 XAllocColor(
display, lut, &xcolor);
1523 XSetStandardProperties(
display, window, win_title.c_str(), win_title.c_str(), None, 0, 0, &hints);
1527 ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
1528 StructureNotifyMask | PointerMotionMask);
1531 values.plane_mask = AllPlanes;
1532 values.fill_style = FillSolid;
1533 values.foreground = WhitePixel(
display, screen);
1534 values.background = BlackPixel(
display, screen);
1535 context = XCreateGC(
display, window, GCPlaneMask | GCFillStyle | GCForeground | GCBackground, &values);
1537 if (context == NULL) {
1543 pixmap = XCreatePixmap(
display, window, win_width, win_height, screen_depth);
1551 Ximage = XCreateImage(
display, DefaultVisual(
display, screen), screen_depth, ZPixmap, 0, NULL, win_width,
1552 win_height, XBitmapPad(
display), 0);
1554 Ximage->data = (
char *)malloc(win_height * (
unsigned int)Ximage->bytes_per_line);
1555 ximage_data_init =
true;
1560 XStoreName(
display, window, win_title.c_str());
1563 void setFont(
const std::string &fontname)
1567 stringfont = XLoadFont(
display, fontname.c_str());
1568 XSetFont(
display, context, stringfont);
1574 void setTitle(
const std::string &title) { XStoreName(
display, window, title.c_str()); }
1587 unsigned long *x_color;
1588 unsigned int screen_depth;
1589 unsigned short colortable[256];
1592 bool ximage_data_init;
1593 unsigned int RMask, GMask, BMask;
1594 int RShift, GShift, BShift;
1649 init(I, x, y, title);
1702 init(I, x, y, title);
1782 if (!win_title.empty())
1811 if (!win_title.empty())
1829 const std::string &win_title)
1865 if (!fontname.empty()) {
1866 m_impl->setFont(fontname);
1882 m_impl->setTitle(title);
1900 m_impl->setWindowPosition(win_x, win_y);
2025 m_impl->closeDisplay();
2039 m_impl->flushDisplay();
2055 m_impl->flushDisplayROI(iP, w, h,
m_scale);
2082 unsigned int h,
unsigned int thickness)
2090 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon()) &&
2091 (std::fabs(b) <= std::numeric_limits<double>::epsilon())) {
2135 m_impl->displayCharString(ip, text, color,
m_scale);
2151 unsigned int thickness)
2156 m_impl->displayCircle(center, radius, color, fill, thickness,
m_scale);
2170 unsigned int thickness)
2173 double i = ip.
get_i();
2174 double j = ip.
get_j();
2177 ip1.
set_i(i - cross_size / 2);
2179 ip2.
set_i(i + cross_size / 2);
2184 ip1.
set_j(j - cross_size / 2);
2186 ip2.
set_j(j + cross_size / 2);
2200 unsigned int thickness)
2206 m_impl->displayDotLine(ip1, ip2, color, thickness,
m_scale);
2219 unsigned int thickness)
2225 m_impl->displayLine(ip1, ip2, color, thickness,
m_scale);
2240 m_impl->displayPoint(ip, color, thickness,
m_scale);
2260 bool fill,
unsigned int thickness)
2266 m_impl->displayRectangle(topLeft, w, h, color, fill, thickness,
m_scale);
2285 bool fill,
unsigned int thickness)
2294 m_impl->displayRectangle(topLeft, w, h, color, fill, thickness,
m_scale);
2320 m_impl->displayRectangle(topLeft, w, h, color, fill, thickness,
m_scale);
2348 ret = m_impl->getClick(ip, button, blocking,
m_scale);
2376 ret = m_impl->getClick(ip, button, blocking,
m_scale);
2407 ret = m_impl->getClick(ip, button, blocking,
m_scale);
2442 ret = m_impl->getClickUp(ip, button, blocking,
m_scale);
2481 unsigned int width, height;
2491 unsigned int width, height;
2521 ret = m_impl->getKeyboardEvent(blocking);
2555 ret = m_impl->getKeyboardEvent(key, blocking);
2578 ret = m_impl->getPointerMotionEvent(ip,
m_scale);
2599 ret = m_impl->getPointerPosition(ip,
m_scale);
2606 #elif !defined(VISP_BUILD_SHARED_LIBS)
2609 void dummy_vpDisplayX(){};
Class to define RGB colors available for display functionnalities.
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 emited by the vpDisplay class and its derivates.
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 functionnalities 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