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