////////////////////////////////////////////////////////////////////// // // Pixie // // Copyright © 1999 - 2003, Okan Arikan // // Contact: okan@cs.berkeley.edu // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // /////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// // // File : fbx.cpp // Classes : CXDisplay // Description : X Windows image displaying class // //////////////////////////////////////////////////////////////////////// #include "common/global.h" #include "framebuffer.h" #include "fbx.h" #define color_15_bgr(r,g,b,a) ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3) #define color_15_bgr_rev(r,g,b,a) ((g >> 3) << 13) | ((b >> 3) << 8) | ((r >> 3) << 3) | (g >> 5) #define color_15_rgb(r,g,b,a) ((b >> 3) << 10) | ((g >> 3) << 5) | (r >> 3) #define color_15_rgb_rev(r,g,b,a) ((g >> 3) << 13) | ((r >> 3) << 8) | ((b >> 3) << 3) | (g >> 5) #define color_16_bgr(r,g,b,a) ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3) #define color_16_bgr_rev(r,g,b,a) ((g >> 2) << 13) | ((b >> 3) << 8) | ((r >> 3) << 3) | (g >> 5) #define color_16_rgb(r,g,b,a) ((b >> 3) << 11) | ((g >> 2) << 5) | (r >> 3) #define color_16_rgb_rev(r,g,b,a) ((g >> 2) << 13) | ((r >> 3) << 8) | ((b >> 3) << 3) | (g >> 5) #define color_bgra(r,g,b,a) ((a << 24) | (r << 16) | (g << 8) | b) #define color_abgr(r,g,b,a) ((r << 24) | (g << 16) | (b << 8) | a) #define color_argb(r,g,b,a) ((b << 24) | (g << 16) | (r << 8) | a) #define color_rgba(r,g,b,a) ((a << 24) | (b << 16) | (g << 8) | r) #define get_pix_rgba(col) float old_r = ((col) & 0xFF); \ float old_g = (((col) >> 8) & 0xFF); \ float old_b = (((col) >> 16) & 0xFF); \ float old_a = (((col) >> 24) & 0xFF); #define get_pix_argb(col) float old_a = ((col) & 0xFF); \ float old_r = (((col) >> 8) & 0xFF); \ float old_g = (((col) >> 16) & 0xFF); \ float old_b = (((col) >> 24) & 0xFF); #define get_pix_bgra(col) float old_b = ((col) & 0xFF); \ float old_g = (((col) >> 8) & 0xFF); \ float old_r = (((col) >> 16) & 0xFF); \ float old_a = (((col) >> 24) & 0xFF); #define get_pix_abgr(col) float old_a = ((col) & 0xFF); \ float old_b = (((col) >> 8) & 0xFF); \ float old_g = (((col) >> 16) & 0xFF); \ float old_r = (((col) >> 24) & 0xFF); /////////////////////////////////////////////////////////////////////// // Function : displayThread // Description : Starts the display thread // Return Value : // Comments : // Date last edited : 11/28/2001 void *displayThread(void *w) { CXDisplay *cDisplay = (CXDisplay *) w; // The thread main loop cDisplay->main(); return NULL; } /////////////////////////////////////////////////////////////////////// // Class : CXDisplay // Method : CXDisplay // Description : Ctor // Return Value : - // Comments : // Date last edited : 8/8/2002 CXDisplay::CXDisplay(const char *name,const char *samples,int width,int height,int numSamples) : CDisplay(name,samples,width,height,numSamples) { int x,y; unsigned int *dest; unsigned short *dests; unsigned short byteOrder = 0x0100; int flipByteOrder; Visual *vis; XInitThreads(); display = XOpenDisplay (NULL); if (display == NULL) failure = TRUE; else { WM_DELETE_WINDOW = XInternAtom(display, "WM_DELETE_WINDOW", 0); WM_PROTOCOLS = XInternAtom(display, "WM_PROTOCOLS", 0); screen = DefaultScreen (display); imageDepth = DefaultDepth (display, screen); flipByteOrder = ImageByteOrder(display); vis = DefaultVisual (display,screen); flipByteOrder = (*((unsigned char*)&byteOrder) != flipByteOrder); // Allocate memory and create a checkerboard pattern switch(imageDepth){ case 15: if(vis->red_mask == 0x001F){ if(flipByteOrder) dataHandler = &CXDisplay::handleData_rgb15_rev; else dataHandler = &CXDisplay::handleData_rgb15; } else{ if(flipByteOrder) dataHandler = &CXDisplay::handleData_bgr15_rev; else dataHandler = &CXDisplay::handleData_bgr15; } imageData = malloc(width*height*sizeof(unsigned short)); dests = (unsigned short *) imageData; for (y=0;yred_mask == 0x001F){ if(flipByteOrder) dataHandler = &CXDisplay::handleData_rgb16_rev; else dataHandler = &CXDisplay::handleData_rgb16; } else{ if(flipByteOrder) dataHandler = &CXDisplay::handleData_bgr16_rev; else dataHandler = &CXDisplay::handleData_bgr16; } imageData = malloc(width*height*sizeof(unsigned short)); dests = (unsigned short *) imageData; for (y=0;yred_mask == 0x000000FF){ if(flipByteOrder) dataHandler = &CXDisplay::handleData_abgr32; else dataHandler = &CXDisplay::handleData_rgba32; } else if(vis->red_mask == 0x0000FF00){ if(flipByteOrder) dataHandler = &CXDisplay::handleData_bgra32; else dataHandler = &CXDisplay::handleData_argb32; } else if(vis->red_mask == 0x00FF0000){ if(flipByteOrder) dataHandler = &CXDisplay::handleData_argb32; else dataHandler = &CXDisplay::handleData_bgra32; } else{ if(flipByteOrder) dataHandler = &CXDisplay::handleData_rgba32; else dataHandler = &CXDisplay::handleData_abgr32; } imageData = malloc(width*height*sizeof(unsigned int)); dest = (unsigned int *) imageData; for (y=0;y*dataHandler)(x,y,w,h,d); // call the appropriate pixel writer if (windowUp) { XPutImage (display, xcanvas, image_gc, xim, x, y, x, y, w, h); XFlush(display); } return TRUE; }