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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/toolx/X11/pixwin (Version 11.3.0) and /externals/g4tools/include/toolx/X11/pixwin (Version 11.2.2)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef toolx_X11_pixwin                            4 #ifndef toolx_X11_pixwin
  5 #define toolx_X11_pixwin                            5 #define toolx_X11_pixwin
  6                                                     6 
  7 #include "colors"                                   7 #include "colors"
  8 #include <tools/sg/zb_viewer>                       8 #include <tools/sg/zb_viewer>
  9 //#include <tools/sys/atime>                        9 //#include <tools/sys/atime>
 10                                                    10 
 11 #include <X11/Xlib.h>                              11 #include <X11/Xlib.h>
 12 #include <X11/Xutil.h> //XPutPixel                 12 #include <X11/Xutil.h> //XPutPixel
 13                                                    13 
 14 namespace toolx {                                  14 namespace toolx {
 15 namespace X11 {                                    15 namespace X11 {
 16                                                    16 
 17 class pixwin {                                     17 class pixwin {
 18 public:                                            18 public:
 19   pixwin(std::ostream& a_out,unsigned int a_mo     19   pixwin(std::ostream& a_out,unsigned int a_monitor,Display* a_display)
 20   :m_out(a_out)                                    20   :m_out(a_out)
 21   ,m_monitor(a_monitor)                            21   ,m_monitor(a_monitor)
 22   ,m_display(a_display)                            22   ,m_display(a_display)
 23   ,m_GC(0)                                         23   ,m_GC(0)
 24   ,m_image(0)                                      24   ,m_image(0)
 25   {                                                25   {
 26     if(!m_display) return;                         26     if(!m_display) return;
 27     m_GC = ::XCreateGC(m_display,XRootWindow(m     27     m_GC = ::XCreateGC(m_display,XRootWindow(m_display,m_monitor),0,0);
 28   }                                                28   }
 29   virtual ~pixwin() {                              29   virtual ~pixwin() {
 30     free_pixels();                                 30     free_pixels();
 31     m_colors.clear();                              31     m_colors.clear();
 32     if(m_GC) ::XFreeGC(m_display,m_GC);            32     if(m_GC) ::XFreeGC(m_display,m_GC);
 33     free_XImage();                                 33     free_XImage();
 34   }                                                34   }
 35 protected:                                         35 protected:
 36   pixwin(const pixwin& a_from)                     36   pixwin(const pixwin& a_from)
 37   :m_out(a_from.m_out)                             37   :m_out(a_from.m_out)
 38   ,m_monitor(0)                                    38   ,m_monitor(0)
 39   ,m_display(0)                                    39   ,m_display(0)
 40   ,m_GC(0)                                         40   ,m_GC(0)
 41   ,m_image(0)                                      41   ,m_image(0)
 42   {}                                               42   {}
 43   pixwin& operator=(const pixwin&){                43   pixwin& operator=(const pixwin&){
 44     m_monitor = 0;                                 44     m_monitor = 0;
 45     m_display = 0;                                 45     m_display = 0;
 46     m_GC = 0;                                      46     m_GC = 0;
 47     m_image = 0;                                   47     m_image = 0;
 48     return *this;                                  48     return *this;
 49   }                                                49   }
 50 public:                                            50 public:
 51   void put_buffer(Window a_win,unsigned int a_     51   void put_buffer(Window a_win,unsigned int a_ww,unsigned int a_wh,const unsigned char* a_rgbas) {
 52     if(!m_display) return;                         52     if(!m_display) return;
 53     if(!m_GC) return;                              53     if(!m_GC) return;
 54     if(!m_image) alloc_XImage(a_ww,a_wh);          54     if(!m_image) alloc_XImage(a_ww,a_wh);
 55     if(!m_image) return;                           55     if(!m_image) return;
 56   //tools::atime start = tools::atime::now();      56   //tools::atime start = tools::atime::now();
 57     const unsigned int* pos = (const unsigned      57     const unsigned int* pos = (const unsigned int*)a_rgbas;
 58     unsigned int row,col;                          58     unsigned int row,col;
 59     toolx::X11::Pixel pixel;                       59     toolx::X11::Pixel pixel;
 60     for(row=0;row<a_wh;row++) {                    60     for(row=0;row<a_wh;row++) {
 61     for(col=0;col<a_ww;col++) {                    61     for(col=0;col<a_ww;col++) {
 62       if(!get_pixel(m_display,m_monitor,m_pixe     62       if(!get_pixel(m_display,m_monitor,m_pixels,m_colors,*pos,pixel)) {}
 63       pos++;                                       63       pos++;
 64       XPutPixel(m_image,col,row,pixel);            64       XPutPixel(m_image,col,row,pixel);
 65     }}                                             65     }}
 66   //::printf("debug : map::colors %lu, pixels      66   //::printf("debug : map::colors %lu, pixels %lu\n",m_colors.size(),m_pixels.size());
 67     ::XPutImage(m_display,a_win,m_GC,m_image,0     67     ::XPutImage(m_display,a_win,m_GC,m_image,0,0,0,0,a_ww,a_wh);
 68   //m_out << "pu_buffer : XImage " << tools::a     68   //m_out << "pu_buffer : XImage " << tools::atime::elapsed(start) << std::endl;
 69   }                                                69   }
 70   void set_size(unsigned int a_ww,unsigned int     70   void set_size(unsigned int a_ww,unsigned int a_wh) {
 71     free_XImage();                                 71     free_XImage();
 72     alloc_XImage(a_ww,a_wh);                       72     alloc_XImage(a_ww,a_wh);
 73   }                                                73   }
 74 protected:                                         74 protected:
 75   void alloc_XImage(unsigned int a_ww,unsigned     75   void alloc_XImage(unsigned int a_ww,unsigned int a_wh) {
 76     if(m_image) return; //done.                    76     if(m_image) return; //done.
 77     if(!m_display) return;                         77     if(!m_display) return;
 78     Screen* screen = ::XScreenOfDisplay(m_disp     78     Screen* screen = ::XScreenOfDisplay(m_display,m_monitor);
 79     m_image = ::XCreateImage(m_display,::XDefa     79     m_image = ::XCreateImage(m_display,::XDefaultVisualOfScreen(screen),::XDefaultDepthOfScreen(screen),ZPixmap,0,NULL,a_ww,a_wh,8,0);
 80     if(!m_image) {                                 80     if(!m_image) {
 81       m_out << "toolx::X11::pixwin::alloc_XIma     81       m_out << "toolx::X11::pixwin::alloc_XImage : can't create an XImage." << std::endl;
 82       return;                                      82       return;
 83     }                                              83     }
 84     //warning : a priori, a_ww*3 != m_image->b     84     //warning : a priori, a_ww*3 != m_image->bytes_per_line.
 85     m_image->data = new char[a_wh*m_image->byt     85     m_image->data = new char[a_wh*m_image->bytes_per_line];
 86     if(!m_image->data) {                           86     if(!m_image->data) {
 87       m_out << "toolx::X11::pixwin::alloc_XIma     87       m_out << "toolx::X11::pixwin::alloc_XImage : can't alloc buffer." << std::endl;
 88       ::XFree((char*)m_image);                     88       ::XFree((char*)m_image);
 89       m_image = 0;                                 89       m_image = 0;
 90       return;                                      90       return;
 91     }                                              91     }
 92   }                                                92   }
 93   void free_XImage() {                             93   void free_XImage() {
 94     if(!m_image) return;                           94     if(!m_image) return;
 95     delete [] m_image->data;                       95     delete [] m_image->data;
 96     ::XFree((char*)m_image);                       96     ::XFree((char*)m_image);
 97     m_image = 0;                                   97     m_image = 0;
 98   }                                                98   }
 99   void free_pixels() {                             99   void free_pixels() {
100     if(!m_display) return;                        100     if(!m_display) return;
101     Screen* screen = ::XScreenOfDisplay(m_disp    101     Screen* screen = ::XScreenOfDisplay(m_display,m_monitor);
102     tools_vforit(toolx::X11::Pixel,m_pixels,it    102     tools_vforit(toolx::X11::Pixel,m_pixels,it) {
103       ::XFreeColors(m_display,XDefaultColormap    103       ::XFreeColors(m_display,XDefaultColormapOfScreen(screen),&(*it),1,0);
104     }                                             104     }
105     m_pixels.clear();                             105     m_pixels.clear();
106   }                                               106   }
107 protected:                                        107 protected:
108   std::ostream& m_out;                            108   std::ostream& m_out;
109   unsigned int m_monitor;                         109   unsigned int m_monitor;
110   Display* m_display;                             110   Display* m_display;
111   GC m_GC;                                        111   GC m_GC;
112   std::vector<toolx::X11::Pixel> m_pixels;        112   std::vector<toolx::X11::Pixel> m_pixels;
113   colors_t m_colors;                              113   colors_t m_colors;
114   XImage* m_image;                                114   XImage* m_image;
115 };                                                115 };
116                                                   116 
117 }}                                                117 }}
118                                                   118 
119                                                   119 
120 #endif                                            120 #endif
121                                                   121