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
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),
91 XSetWindowBackground(
display, window, x_color[color.
id]);
94 xcolor.red = 256 * color.
R;
95 xcolor.green = 256 * color.
G;
96 xcolor.blue = 256 * color.
B;
97 XAllocColor(
display, lut, &xcolor);
98 XSetForeground(
display, context, xcolor.pixel);
105 pixmap = XCreatePixmap(
display, window, width, height, screen_depth);
110 if (ximage_data_init ==
true)
114 XDestroyImage(Ximage);
119 XDestroyWindow(
display, window);
122 if (x_color != NULL) {
131 XSetForeground(
display, context, x_color[color.
id]);
134 xcolor.red = 256 * color.
R;
135 xcolor.green = 256 * color.
G;
136 xcolor.blue = 256 * color.
B;
137 XAllocColor(
display, lut, &xcolor);
138 XSetForeground(
display, context, xcolor.pixel);
140 XDrawString(
display, pixmap, context, (
int)(ip.
get_u() / scale), (
int)(ip.
get_v() / scale), text,
145 unsigned int thickness,
unsigned int scale)
148 XSetForeground(
display, context, x_color[color.
id]);
151 xcolor.red = 256 * color.
R;
152 xcolor.green = 256 * color.
G;
153 xcolor.blue = 256 * color.
B;
154 XAllocColor(
display, lut, &xcolor);
155 XSetForeground(
display, context, xcolor.pixel);
158 XSetLineAttributes(
display, context, thickness, LineSolid, CapButt, JoinBevel);
162 vpMath::round((center.
get_v() - radius) / scale), radius * 2 / scale, radius * 2 / scale, 0,
166 vpMath::round((center.
get_v() - radius) / scale), radius * 2 / scale, radius * 2 / scale, 0,
172 unsigned int thickness,
unsigned int scale)
175 XSetForeground(
display, context, x_color[color.
id]);
178 xcolor.red = 256 * color.
R;
179 xcolor.green = 256 * color.
G;
180 xcolor.blue = 256 * color.
B;
181 XAllocColor(
display, lut, &xcolor);
182 XSetForeground(
display, context, xcolor.pixel);
185 XSetLineAttributes(
display, context, thickness, LineOnOffDash, CapButt, JoinBevel);
193 switch (screen_depth) {
199 unsigned char *src_8 = (
unsigned char *)I.
bitmap;
200 unsigned char *dst_8 = (
unsigned char *)Ximage->data;
202 unsigned int size = width * height;
205 unsigned char nivGris = src_8[i];
206 if (nivGris > nivGrisMax)
215 unsigned char *dst_8 = (
unsigned char *)Ximage->data;
217 for (
unsigned int i = 0; i < height; i++) {
218 for (
unsigned int j = 0; j < width; j++) {
219 unsigned char nivGris = I[i * scale][j * scale];
220 if (nivGris > nivGrisMax)
223 dst_8[k++] = nivGris;
229 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
230 XSetWindowBackgroundPixmap(
display, window, pixmap);
234 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
236 for (
unsigned int i = 0; i < height; i++) {
237 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
238 unsigned short *dst_16 = (
unsigned short *)dst_8;
239 for (
unsigned int j = 0; j < width; j++) {
240 *(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++);
280 unsigned char val = *(bitmap++);
288 if (XImageByteOrder(
display) == 1) {
290 for (
unsigned int i = 0; i < height; i++) {
291 for (
unsigned int j = 0; j < width; j++) {
292 unsigned char val = I[i * scale][j * scale];
301 for (
unsigned int i = 0; i < height; i++) {
302 for (
unsigned int j = 0; j < width; j++) {
303 unsigned char val = I[i * scale][j * scale];
314 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
315 XSetWindowBackgroundPixmap(
display, window, pixmap);
323 switch (screen_depth) {
326 unsigned int r, g, b;
327 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
330 for (
unsigned int i = 0; i < height; i++) {
331 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
332 unsigned short *dst_16 = (
unsigned short *)dst_8;
333 for (
unsigned int j = 0; j < width; j++) {
338 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
343 for (
unsigned int i = 0; i < height; i++) {
344 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
345 unsigned short *dst_16 = (
unsigned short *)dst_8;
346 for (
unsigned int j = 0; j < width; j++) {
347 vpRGBa val = I[i * scale][j * scale];
352 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
358 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
359 XSetWindowBackgroundPixmap(
display, window, pixmap);
368 unsigned char *dst_32 = NULL;
369 dst_32 = (
unsigned char *)Ximage->data;
372 unsigned int sizeI = width * height;
373 if (XImageByteOrder(
display) == 1) {
375 for (
unsigned int i = 0; i < sizeI; i++) {
376 *(dst_32++) = bitmap->
A;
377 *(dst_32++) = bitmap->
R;
378 *(dst_32++) = bitmap->
G;
379 *(dst_32++) = bitmap->
B;
384 for (
unsigned int i = 0; i < sizeI; i++) {
385 *(dst_32++) = bitmap->
B;
386 *(dst_32++) = bitmap->
G;
387 *(dst_32++) = bitmap->
R;
388 *(dst_32++) = bitmap->
A;
393 if (XImageByteOrder(
display) == 1) {
395 for (
unsigned int i = 0; i < height; i++) {
396 for (
unsigned int j = 0; j < width; j++) {
397 vpRGBa val = I[i * scale][j * scale];
406 for (
unsigned int i = 0; i < height; i++) {
407 for (
unsigned int j = 0; j < width; j++) {
408 vpRGBa val = I[i * scale][j * scale];
419 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
420 XSetWindowBackgroundPixmap(
display, window, pixmap);
425 "Unsupported depth (%d bpp) for color display", screen_depth));
429 void displayImage(
const unsigned char *bitmap,
unsigned int width,
unsigned int height)
431 unsigned char *dst_32 = (
unsigned char *)Ximage->data;
432 for (
unsigned int i = 0; i < width * height; i++) {
433 *(dst_32++) = *bitmap;
434 *(dst_32++) = *bitmap;
435 *(dst_32++) = *bitmap;
436 *(dst_32++) = *bitmap;
441 XPutImage(
display, pixmap, context, Ximage, 0, 0, 0, 0, width, height);
442 XSetWindowBackgroundPixmap(
display, window, pixmap);
447 unsigned int scale,
unsigned int width,
unsigned int height)
449 switch (screen_depth) {
455 unsigned char *src_8 = (
unsigned char *)I.
bitmap;
456 unsigned char *dst_8 = (
unsigned char *)Ximage->data;
459 src_8 = src_8 + (int)(iP.
get_i() * iwidth + iP.
get_j());
460 dst_8 = dst_8 + (int)(iP.
get_i() * width + iP.
get_j());
466 unsigned char nivGris = *(src_8 + j);
467 if (nivGris > nivGrisMax)
470 *(dst_8 + j) = nivGris;
473 src_8 = src_8 + iwidth;
474 dst_8 = dst_8 + width;
483 int i_min = (std::max)((
int)ceil(iP.
get_i() / scale), 0);
484 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
485 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
486 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
488 unsigned int i_min_ = (
unsigned int)i_min;
489 unsigned int i_max_ = (
unsigned int)i_max;
490 unsigned int j_min_ = (
unsigned int)j_min;
491 unsigned int j_max_ = (
unsigned int)j_max;
493 for (
unsigned int i = i_min_; i < i_max_; i++) {
494 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * width;
495 for (
unsigned int j = j_min_; j < j_max_; j++) {
496 unsigned char nivGris = I[i * scale][j * scale];
497 if (nivGris > nivGrisMax)
503 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
507 XSetWindowBackgroundPixmap(
display, window, pixmap);
511 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
513 for (
unsigned int i = (
unsigned int)iP.
get_i(); i < (
unsigned int)(iP.
get_i() + h); i++) {
514 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
515 unsigned short *dst_16 = (
unsigned short *)dst_8;
516 for (
unsigned int j = (
unsigned int)iP.
get_j(); j < (
unsigned int)(iP.
get_j() + w); j++) {
517 *(dst_16 + j) = (
unsigned short)colortable[I[i][j]];
524 int i_min = (std::max)((
int)ceil(iP.
get_i() / scale), 0);
525 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
526 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
527 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
529 unsigned int i_min_ = (
unsigned int)i_min;
530 unsigned int i_max_ = (
unsigned int)i_max;
531 unsigned int j_min_ = (
unsigned int)j_min;
532 unsigned int j_max_ = (
unsigned int)j_max;
534 for (
unsigned int i = i_min_; i < i_max_; i++) {
535 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
536 unsigned short *dst_16 = (
unsigned short *)dst_8;
537 for (
unsigned int j = j_min_; j < j_max_; j++) {
538 *(dst_16 + j) = (
unsigned short)colortable[I[i * scale][j * scale]];
542 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
545 XSetWindowBackgroundPixmap(
display, window, pixmap);
554 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(iP.
get_i() * 4 * width + iP.
get_j() * 4);
556 if (XImageByteOrder(
display) == 1) {
562 unsigned char val = *(src_8 + j);
564 *(dst_32 + 4 * j + 1) = val;
565 *(dst_32 + 4 * j + 2) = val;
566 *(dst_32 + 4 * j + 3) = val;
569 src_8 = src_8 + iwidth;
570 dst_32 = dst_32 + 4 * width;
579 unsigned char val = *(src_8 + j);
580 *(dst_32 + 4 * j) = val;
581 *(dst_32 + 4 * j + 1) = val;
582 *(dst_32 + 4 * j + 2) = val;
586 src_8 = src_8 + iwidth;
587 dst_32 = dst_32 + 4 * width;
595 int i_min = (std::max)((
int)ceil(iP.
get_i() / scale), 0);
596 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
597 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
598 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
600 unsigned int i_min_ = (
unsigned int)i_min;
601 unsigned int i_max_ = (
unsigned int)i_max;
602 unsigned int j_min_ = (
unsigned int)j_min;
603 unsigned int j_max_ = (
unsigned int)j_max;
605 if (XImageByteOrder(
display) == 1) {
607 for (
unsigned int i = i_min_; i < i_max_; i++) {
608 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
609 for (
unsigned int j = j_min_; j < j_max_; j++) {
610 unsigned char val = I[i * scale][j * scale];
619 for (
unsigned int i = i_min_; i < i_max_; i++) {
620 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
621 for (
unsigned int j = j_min_; j < j_max_; j++) {
622 unsigned char val = I[i * scale][j * scale];
631 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
634 XSetWindowBackgroundPixmap(
display, window, pixmap);
642 unsigned int scale,
unsigned int width,
unsigned int height)
644 switch (screen_depth) {
647 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
648 for (
unsigned int i = (
unsigned int)iP.
get_i(); i < (
unsigned int)(iP.
get_i() + h); i++) {
649 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
650 unsigned short *dst_16 = (
unsigned short *)dst_8;
651 for (
unsigned int j = (
unsigned int)iP.
get_j(); j < (
unsigned int)(iP.
get_j() + w); j++) {
653 unsigned int r = val.
R;
654 unsigned int g = val.
G;
655 unsigned int b = val.
B;
657 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
663 unsigned int bytes_per_line = (
unsigned int)Ximage->bytes_per_line;
664 int i_min = (std::max)((int)ceil(iP.
get_i() / scale), 0);
665 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
666 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
667 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
669 unsigned int i_min_ = (
unsigned int)i_min;
670 unsigned int i_max_ = (
unsigned int)i_max;
671 unsigned int j_min_ = (
unsigned int)j_min;
672 unsigned int j_max_ = (
unsigned int)j_max;
674 for (
unsigned int i = i_min_; i < i_max_; i++) {
675 unsigned char *dst_8 = (
unsigned char *)Ximage->data + i * bytes_per_line;
676 unsigned short *dst_16 = (
unsigned short *)dst_8;
677 for (
unsigned int j = j_min_; j < j_max_; j++) {
678 vpRGBa val = I[i * scale][j * scale];
679 unsigned int r = val.
R;
680 unsigned int g = val.
G;
681 unsigned int b = val.
B;
683 (((r << 8) >> RShift) & RMask) | (((g << 8) >> GShift) & GMask) | (((b << 8) >> BShift) & BMask);
686 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
689 XSetWindowBackgroundPixmap(
display, window, pixmap);
700 unsigned char *dst_32 = (
unsigned char *)Ximage->data;
705 src_32 = src_32 + (int)(iP.
get_i() * iwidth + iP.
get_j());
706 dst_32 = dst_32 + (int)(iP.
get_i() * 4 * width + iP.
get_j() * 4);
710 if (XImageByteOrder(
display) == 1) {
715 *(dst_32 + 4 * j) = (src_32 + j)->A;
716 *(dst_32 + 4 * j + 1) = (src_32 + j)->R;
717 *(dst_32 + 4 * j + 2) = (src_32 + j)->G;
718 *(dst_32 + 4 * j + 3) = (src_32 + j)->B;
722 src_32 = src_32 + iwidth;
723 dst_32 = dst_32 + 4 * width;
732 *(dst_32 + 4 * j) = (src_32 + j)->B;
733 *(dst_32 + 4 * j + 1) = (src_32 + j)->G;
734 *(dst_32 + 4 * j + 2) = (src_32 + j)->R;
735 *(dst_32 + 4 * j + 3) = (src_32 + j)->A;
739 src_32 = src_32 + iwidth;
740 dst_32 = dst_32 + 4 * width;
748 int i_min = (std::max)((
int)ceil(iP.
get_i() / scale), 0);
749 int j_min = (std::max)((
int)ceil(iP.
get_j() / scale), 0);
750 int i_max = (std::min)((
int)ceil((iP.
get_i() + h) / scale), (int)height);
751 int j_max = (std::min)((
int)ceil((iP.
get_j() + w) / scale), (int)width);
753 unsigned int i_min_ = (
unsigned int)i_min;
754 unsigned int i_max_ = (
unsigned int)i_max;
755 unsigned int j_min_ = (
unsigned int)j_min;
756 unsigned int j_max_ = (
unsigned int)j_max;
758 if (XImageByteOrder(
display) == 1) {
760 for (
unsigned int i = i_min_; i < i_max_; i++) {
761 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
762 for (
unsigned int j = j_min_; j < j_max_; j++) {
763 vpRGBa val = I[i * scale][j * scale];
772 for (
unsigned int i = i_min_; i < i_max_; i++) {
773 unsigned char *dst_32 = (
unsigned char *)Ximage->data + (
int)(i * 4 * width + j_min_ * 4);
774 for (
unsigned int j = j_min_; j < j_max_; j++) {
775 vpRGBa val = I[i * scale][j * scale];
783 XPutImage(
display, pixmap, context, Ximage, j_min, i_min, j_min, i_min, j_max_ - j_min_, i_max_ - i_min_);
786 XSetWindowBackgroundPixmap(
display, window, pixmap);
791 "Unsupported depth (%d bpp) for color display", screen_depth));
796 unsigned int thickness,
unsigned int scale)
799 XSetForeground(
display, context, x_color[color.
id]);
802 xcolor.red = 256 * color.
R;
803 xcolor.green = 256 * color.
G;
804 xcolor.blue = 256 * color.
B;
805 XAllocColor(
display, lut, &xcolor);
806 XSetForeground(
display, context, xcolor.pixel);
809 XSetLineAttributes(
display, context, thickness, LineSolid, CapButt, JoinBevel);
818 XSetForeground(
display, context, x_color[color.
id]);
821 xcolor.red = 256 * color.
R;
822 xcolor.green = 256 * color.
G;
823 xcolor.blue = 256 * color.
B;
824 XAllocColor(
display, lut, &xcolor);
825 XSetForeground(
display, context, xcolor.pixel);
828 if (thickness == 1) {
832 thickness, thickness);
837 bool fill,
unsigned int thickness,
unsigned int scale)
840 XSetForeground(
display, context, x_color[color.
id]);
843 xcolor.red = 256 * color.
R;
844 xcolor.green = 256 * color.
G;
845 xcolor.blue = 256 * color.
B;
846 XAllocColor(
display, lut, &xcolor);
847 XSetForeground(
display, context, xcolor.pixel);
849 XSetLineAttributes(
display, context, thickness, LineSolid, CapButt, JoinBevel);
867 XClearArea(
display, window, (
int)(iP.
get_u() / scale), (
int)(iP.
get_v() / scale), w / scale, h / scale, 0);
874 Window rootwin, childwin;
875 int root_x, root_y, win_x, win_y;
876 unsigned int modifier;
880 XCheckMaskEvent(
display, ButtonPressMask, &event);
881 XCheckMaskEvent(
display, ButtonReleaseMask, &event);
882 XMaskEvent(
display, ButtonPressMask, &event);
885 ret = XCheckMaskEvent(
display, ButtonPressMask, &event);
890 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
891 ip.
set_u((
double)event.xbutton.x * scale);
892 ip.
set_v((
double)event.xbutton.y * scale);
893 switch (event.xbutton.button) {
913 Window rootwin, childwin;
914 int root_x, root_y, win_x, win_y;
915 unsigned int modifier;
919 XCheckMaskEvent(
display, ButtonPressMask, &event);
920 XCheckMaskEvent(
display, ButtonReleaseMask, &event);
921 XMaskEvent(
display, ButtonReleaseMask, &event);
924 ret = XCheckMaskEvent(
display, ButtonReleaseMask, &event);
929 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
930 ip.
set_u((
double)event.xbutton.x * scale);
931 ip.
set_v((
double)event.xbutton.y * scale);
932 switch (event.xbutton.button) {
953 XCopyArea(
display, window, pixmap, context, 0, 0, width, height, 0, 0);
955 xi = XGetImage(
display, pixmap, 0, 0, width, height, AllPlanes, ZPixmap);
959 unsigned char *src_32 = NULL;
960 src_32 = (
unsigned char *)xi->data;
962 if (screen_depth == 16) {
963 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
964 size_t i_ = i * width;
965 for (
unsigned int j = 0; j < height; j++) {
967 unsigned long pixel = XGetPixel(xi, (
int)j, (
int)i);
968 I.
bitmap[ij_].R = (((pixel & RMask) << RShift) >> 8);
969 I.
bitmap[ij_].G = (((pixel & GMask) << GShift) >> 8);
970 I.
bitmap[ij_].B = (((pixel & BMask) << BShift) >> 8);
979 if (XImageByteOrder(
display) == 1) {
981 for (
unsigned int i = 0; i < width * height; i++) {
986 I.
bitmap[i].R = src_32[i * 4 + 1];
987 I.
bitmap[i].G = src_32[i * 4 + 2];
988 I.
bitmap[i].B = src_32[i * 4 + 3];
992 for (
unsigned int i = 0; i < width * height; i++) {
993 I.
bitmap[i].B = src_32[i * 4];
994 I.
bitmap[i].G = src_32[i * 4 + 1];
995 I.
bitmap[i].R = src_32[i * 4 + 2];
1012 XMaskEvent(
display, KeyPressMask, &event);
1015 ret = XCheckMaskEvent(
display, KeyPressMask, &event);
1026 XComposeStatus compose_status;
1031 XMaskEvent(
display, KeyPressMask, &event);
1032 XLookupString((XKeyEvent *)&event, &buffer, 1, &keysym, &compose_status);
1036 ret = XCheckMaskEvent(
display, KeyPressMask, &event);
1038 XLookupString((XKeyEvent *)&event, &buffer, 1, &keysym, &compose_status);
1049 int getMsb(
unsigned int u32val)
1053 for (i = 31; i >= 0; --i) {
1054 if (u32val & 0x80000000L)
1065 Window rootwin, childwin;
1066 int root_x, root_y, win_x, win_y;
1067 unsigned int modifier;
1069 ret = XCheckMaskEvent(
display, PointerMotionMask, &event);
1073 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
1074 ip.
set_u((
double)event.xbutton.x * scale);
1075 ip.
set_v((
double)event.xbutton.y * scale);
1085 Window rootwin, childwin;
1086 int root_x, root_y, win_x, win_y;
1087 unsigned int modifier;
1093 if (XQueryPointer(
display, window, &rootwin, &childwin, &root_x, &root_y, &win_x, &win_y, &modifier)) {
1094 ip.
set_u((
double)win_x * scale);
1095 ip.
set_v((
double)win_y * scale);
1108 if ((display_ = XOpenDisplay(NULL)) == NULL) {
1110 XDisplayName(NULL)));
1112 screen_ = DefaultScreen(display_);
1113 depth = (
unsigned int)DefaultDepth(display_, screen_);
1115 XCloseDisplay(display_);
1125 if ((display_ = XOpenDisplay(NULL)) == NULL) {
1127 XDisplayName(NULL)));
1129 screen_ = DefaultScreen(display_);
1130 w = (
unsigned int)DisplayWidth(display_, screen_);
1131 h = (
unsigned int)DisplayHeight(display_, screen_);
1133 XCloseDisplay(display_);
1136 void init(
unsigned int win_width,
unsigned int win_height,
int win_x,
int win_y,
const std::string &win_title)
1138 if (x_color == NULL) {
1146 if ((win_x < 0) || (win_y < 0)) {
1149 hints.flags = USPosition;
1154 if ((
display = XOpenDisplay(NULL)) == NULL) {
1155 vpERROR_TRACE(
"Can't connect display on server %s.\n", XDisplayName(NULL));
1159 screen = DefaultScreen(
display);
1160 lut = DefaultColormap(
display, screen);
1161 screen_depth = (
unsigned int)DefaultDepth(
display, screen);
1163 vpTRACE(
"Screen depth: %d\n", screen_depth);
1165 if ((window = XCreateSimpleWindow(
display, RootWindow(
display, screen),
1167 win_width, win_height,
1168 1, BlackPixel(
display, screen), WhitePixel(
display, screen))) == 0) {
1176 if (screen_depth == 8) {
1177 lut = XCreateColormap(
display, window, DefaultVisual(
display, screen), AllocAll);
1178 xcolor.flags = DoRed | DoGreen | DoBlue;
1180 for (
unsigned int i = 0; i < 256; i++) {
1182 xcolor.red = 256 * i;
1183 xcolor.green = 256 * i;
1184 xcolor.blue = 256 * i;
1185 XStoreColor(
display, lut, &xcolor);
1188 XSetWindowColormap(
display, window, lut);
1189 XInstallColormap(
display, lut);
1192 else if (screen_depth == 16) {
1193 for (
unsigned int i = 0; i < 256; i++) {
1195 xcolor.red = xcolor.green = xcolor.blue = 256 * i;
1196 if (XAllocColor(
display, lut, &xcolor) == 0) {
1197 vpERROR_TRACE(
"Can't allocate 256 colors. Only %d allocated.", i);
1200 colortable[i] = xcolor.pixel;
1203 XSetWindowColormap(
display, window, lut);
1204 XInstallColormap(
display, lut);
1206 Visual *visual = DefaultVisual(
display, screen);
1207 RMask = visual->red_mask;
1208 GMask = visual->green_mask;
1209 BMask = visual->blue_mask;
1211 RShift = 15 - getMsb(RMask);
1212 GShift = 15 - getMsb(GMask);
1213 BShift = 15 - getMsb(BMask);
1221 switch (screen_depth) {
1231 xcolor.
red = 256 * 192;
1232 xcolor.
green = 256 * 192;
1233 xcolor.
blue = 256 * 192;
1234 XStoreColor(
display, lut, &xcolor);
1239 xcolor.red = 256 * 128;
1240 xcolor.green = 256 * 128;
1241 xcolor.blue = 256 * 128;
1242 XStoreColor(
display, lut, &xcolor);
1247 xcolor.red = 256 * 64;
1248 xcolor.green = 256 * 64;
1249 xcolor.blue = 256 * 64;
1250 XStoreColor(
display, lut, &xcolor);
1255 xcolor.red = 256 * 255;
1256 xcolor.green = 256 * 140;
1257 xcolor.blue = 256 * 140;
1258 XStoreColor(
display, lut, &xcolor);
1263 xcolor.red = 256 * 255;
1266 XStoreColor(
display, lut, &xcolor);
1271 xcolor.red = 256 * 128;
1274 XStoreColor(
display, lut, &xcolor);
1279 xcolor.red = 256 * 140;
1280 xcolor.green = 256 * 255;
1281 xcolor.blue = 256 * 140;
1282 XStoreColor(
display, lut, &xcolor);
1288 xcolor.green = 256 * 255;
1290 XStoreColor(
display, lut, &xcolor);
1296 xcolor.green = 256 * 128;
1298 XStoreColor(
display, lut, &xcolor);
1303 xcolor.red = 256 * 140;
1304 xcolor.green = 256 * 140;
1305 xcolor.blue = 256 * 255;
1306 XStoreColor(
display, lut, &xcolor);
1313 xcolor.blue = 256 * 255;
1314 XStoreColor(
display, lut, &xcolor);
1321 xcolor.blue = 256 * 128;
1322 XStoreColor(
display, lut, &xcolor);
1327 xcolor.red = 256 * 255;
1328 xcolor.green = 256 * 255;
1330 XStoreColor(
display, lut, &xcolor);
1335 xcolor.red = 256 * 255;
1336 xcolor.green = 256 * 165;
1338 XStoreColor(
display, lut, &xcolor);
1344 xcolor.green = 256 * 255;
1345 xcolor.blue = 256 * 255;
1346 XStoreColor(
display, lut, &xcolor);
1351 xcolor.red = 256 * 128;
1353 xcolor.blue = 256 * 128;
1354 XStoreColor(
display, lut, &xcolor);
1361 xcolor.flags = DoRed | DoGreen | DoBlue;
1366 xcolor.
red = 256 * pcolor.
R;
1367 xcolor.green = 256 * pcolor.
G;
1368 xcolor.blue = 256 * pcolor.
B;
1369 XAllocColor(
display, lut, &xcolor);
1375 xcolor.
red = 256 * pcolor.
R;
1376 xcolor.green = 256 * pcolor.
G;
1377 xcolor.blue = 256 * pcolor.
B;
1378 XAllocColor(
display, lut, &xcolor);
1384 xcolor.
red = 256 * pcolor.
R;
1385 xcolor.green = 256 * pcolor.
G;
1386 xcolor.blue = 256 * pcolor.
B;
1387 XAllocColor(
display, lut, &xcolor);
1393 xcolor.
red = 256 * pcolor.
R;
1394 xcolor.green = 256 * pcolor.
G;
1395 xcolor.blue = 256 * pcolor.
B;
1396 XAllocColor(
display, lut, &xcolor);
1402 xcolor.
red = 256 * pcolor.
R;
1403 xcolor.green = 256 * pcolor.
G;
1404 xcolor.blue = 256 * pcolor.
B;
1405 XAllocColor(
display, lut, &xcolor);
1411 xcolor.
red = 256 * pcolor.
R;
1412 xcolor.green = 256 * pcolor.
G;
1413 xcolor.blue = 256 * pcolor.
B;
1414 XAllocColor(
display, lut, &xcolor);
1420 xcolor.
red = 256 * pcolor.
R;
1421 xcolor.green = 256 * pcolor.
G;
1422 xcolor.blue = 256 * pcolor.
B;
1423 XAllocColor(
display, lut, &xcolor);
1429 xcolor.
red = 256 * pcolor.
R;
1430 xcolor.green = 256 * pcolor.
G;
1431 xcolor.blue = 256 * pcolor.
B;
1432 XAllocColor(
display, lut, &xcolor);
1438 xcolor.
red = 256 * pcolor.
R;
1439 xcolor.green = 256 * pcolor.
G;
1440 xcolor.blue = 256 * pcolor.
B;
1441 XAllocColor(
display, lut, &xcolor);
1447 xcolor.
red = 256 * pcolor.
R;
1448 xcolor.green = 256 * pcolor.
G;
1449 xcolor.blue = 256 * pcolor.
B;
1450 XAllocColor(
display, lut, &xcolor);
1456 xcolor.
red = 256 * pcolor.
R;
1457 xcolor.green = 256 * pcolor.
G;
1458 xcolor.blue = 256 * pcolor.
B;
1459 XAllocColor(
display, lut, &xcolor);
1465 xcolor.
red = 256 * pcolor.
R;
1466 xcolor.green = 256 * pcolor.
G;
1467 xcolor.blue = 256 * pcolor.
B;
1468 XAllocColor(
display, lut, &xcolor);
1474 xcolor.
red = 256 * pcolor.
R;
1475 xcolor.green = 256 * pcolor.
G;
1476 xcolor.blue = 256 * pcolor.
B;
1477 XAllocColor(
display, lut, &xcolor);
1483 xcolor.
red = 256 * pcolor.
R;
1484 xcolor.green = 256 * pcolor.
G;
1485 xcolor.blue = 256 * pcolor.
B;
1486 XAllocColor(
display, lut, &xcolor);
1492 xcolor.
red = 256 * pcolor.
R;
1493 xcolor.green = 256 * pcolor.
G;
1494 xcolor.blue = 256 * pcolor.
B;
1495 XAllocColor(
display, lut, &xcolor);
1501 xcolor.
red = 256 * pcolor.
R;
1502 xcolor.green = 256 * pcolor.
G;
1503 xcolor.blue = 256 * pcolor.
B;
1504 XAllocColor(
display, lut, &xcolor);
1510 xcolor.
red = 256 * pcolor.
R;
1511 xcolor.green = 256 * pcolor.
G;
1512 xcolor.blue = 256 * pcolor.
B;
1513 XAllocColor(
display, lut, &xcolor);
1519 xcolor.
red = 256 * pcolor.
R;
1520 xcolor.green = 256 * pcolor.
G;
1521 xcolor.blue = 256 * pcolor.
B;
1522 XAllocColor(
display, lut, &xcolor);
1528 XSetStandardProperties(
display, window, win_title.c_str(), win_title.c_str(), None, 0, 0, &hints);
1532 ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask |
1533 StructureNotifyMask | PointerMotionMask);
1536 values.plane_mask = AllPlanes;
1537 values.fill_style = FillSolid;
1538 values.foreground = WhitePixel(
display, screen);
1539 values.background = BlackPixel(
display, screen);
1540 context = XCreateGC(
display, window, GCPlaneMask | GCFillStyle | GCForeground | GCBackground, &values);
1542 if (context == NULL) {
1548 pixmap = XCreatePixmap(
display, window, win_width, win_height, screen_depth);
1556 Ximage = XCreateImage(
display, DefaultVisual(
display, screen), screen_depth, ZPixmap, 0, NULL,
1557 win_width, win_height,
1560 Ximage->data = (
char *)malloc(win_height * (
unsigned int)Ximage->bytes_per_line);
1561 ximage_data_init =
true;
1566 XStoreName(
display, window, win_title.c_str());
1569 void setFont(
const std::string &fontname)
1573 stringfont = XLoadFont(
display, fontname.c_str());
1574 XSetFont(
display, context, stringfont);
1580 void setTitle(
const std::string &title)
1582 XStoreName(
display, window, title.c_str());
1587 XMoveWindow(
display, window, win_x, win_y);
1599 unsigned long *x_color;
1600 unsigned int screen_depth;
1601 unsigned short colortable[256];
1604 bool ximage_data_init;
1605 unsigned int RMask, GMask, BMask;
1606 int RShift, GShift, BShift;
1662 init(I, x, y, title);
1716 init(I, x, y, title);
1800 if (!win_title.empty())
1829 if (!win_title.empty())
1846void vpDisplayX::init(
unsigned int win_width,
unsigned int win_height,
int win_x,
int win_y,
const std::string &win_title)
1882 if (!fontname.empty()) {
1883 m_impl->setFont(fontname);
1899 m_impl->setTitle(title);
1917 m_impl->setWindowPosition(win_x, win_y);
2043 m_impl->closeDisplay();
2057 m_impl->flushDisplay();
2073 m_impl->flushDisplayROI(iP, w, h,
m_scale);
2100 unsigned int h,
unsigned int thickness)
2108 if ((std::fabs(a) <= std::numeric_limits<double>::epsilon()) &&
2109 (std::fabs(b) <= std::numeric_limits<double>::epsilon())) {
2153 m_impl->displayCharString(ip, text, color,
m_scale);
2169 unsigned int thickness)
2174 m_impl->displayCircle(center, radius, color, fill, thickness,
m_scale);
2188 unsigned int thickness)
2191 double i = ip.
get_i();
2192 double j = ip.
get_j();
2195 ip1.
set_i(i - cross_size / 2);
2197 ip2.
set_i(i + cross_size / 2);
2202 ip1.
set_j(j - cross_size / 2);
2204 ip2.
set_j(j + cross_size / 2);
2218 unsigned int thickness)
2224 m_impl->displayDotLine(ip1, ip2, color, thickness,
m_scale);
2237 unsigned int thickness)
2243 m_impl->displayLine(ip1, ip2, color, thickness,
m_scale);
2258 m_impl->displayPoint(ip, color, thickness,
m_scale);
2278 bool fill,
unsigned int thickness)
2284 m_impl->displayRectangle(topLeft, w, h, color, fill, thickness,
m_scale);
2303 bool fill,
unsigned int thickness)
2312 m_impl->displayRectangle(topLeft, w, h, color, fill, thickness,
m_scale);
2338 m_impl->displayRectangle(topLeft, w, h, color, fill, thickness,
m_scale);
2366 ret = m_impl->getClick(ip, button, blocking,
m_scale);
2394 ret = m_impl->getClick(ip, button, blocking,
m_scale);
2425 ret = m_impl->getClick(ip, button, blocking,
m_scale);
2460 ret = m_impl->getClickUp(ip, button, blocking,
m_scale);
2488 return m_impl->getScreenDepth();
2497 m_impl->getScreenSize(w, h);
2505 unsigned int width, height;
2515 unsigned int width, height;
2545 ret = m_impl->getKeyboardEvent(blocking);
2579 ret = m_impl->getKeyboardEvent(key, blocking);
2602 ret = m_impl->getPointerMotionEvent(ip,
m_scale);
2623 ret = m_impl->getPointerPosition(ip,
m_scale);
2630#elif !defined(VISP_BUILD_SHARED_LIBS)
2633void 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