Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

target_ximage_std.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: target_ximage_std.cpp,v 1.1 2001/03/06 15:09:19 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 */
00014 
00015 #include "Core/precomp.h"
00016 
00017 #include "API/Core/System/cl_assert.h"
00018 #include <API/Display/Display/palette.h>
00019 #include <Display/Display/X11/target_ximage_std.h>
00020 #include <API/Core/Math/rect.h>
00021 
00022 #include <iostream>
00023 #include <string.h>
00024 
00025 CL_Target_XImage_Std::CL_Target_XImage_Std(
00026         XVisualInfo visual_info,
00027         Display *dpy,
00028         unsigned int width,
00029         unsigned int height)
00030 {
00031         m_visual_info = visual_info;
00032         m_dpy = dpy;
00033         m_width = width;
00034         m_height = height;
00035 
00036         // Figure out what the depth and pitch is:
00037         int num_formats;
00038         XPixmapFormatValues *formats = XListPixmapFormats(m_dpy, &num_formats);
00039         for (int i=0; i<num_formats; i++)
00040         {
00041                 if (formats[i].depth == m_visual_info.depth)
00042                 {
00043                         m_depth = formats[i].bits_per_pixel;
00044                         m_pitch = (width*m_depth+formats[i].scanline_pad-1)/formats[i].scanline_pad;
00045                         m_pitch *= formats[i].scanline_pad;
00046                         m_pitch = (m_pitch+7)/8;
00047                         break;
00048                 }
00049         }
00050         XFree(formats);
00051 
00052         // Create XImage:
00053         int image_size = get_pitch()*height;
00054         char *image_data = new char[image_size];
00055         
00056         m_std_image = XCreateImage(
00057                 dpy,
00058                 visual_info.visual,
00059                 visual_info.depth, // PTC does this: DefaultDepth(dpy,0),
00060                 ZPixmap,
00061                 0,
00062                 image_data,
00063                 width,
00064                 height,
00065                 8, // bitmap_pad
00066                 0);
00067         
00068         cl_assert(m_std_image != NULL);
00069         
00070         m_delete_ximage = true;
00071 }
00072 
00073 CL_Target_XImage_Std::CL_Target_XImage_Std(
00074         XVisualInfo visual_info,
00075         Display *dpy,
00076         unsigned int width,
00077         unsigned int height,
00078         XImage *image,
00079         bool delete_ximage)
00080 {
00081         m_visual_info = visual_info;
00082         m_dpy = dpy;
00083         m_width = width;
00084         m_height = height;
00085         
00086         m_std_image = image;
00087         m_delete_ximage = delete_ximage;
00088 }
00089                 
00090 CL_Target_XImage_Std::~CL_Target_XImage_Std()
00091 {
00092         if (m_delete_ximage)
00093                 XDestroyImage(m_std_image);
00094 }
00095 
00096 void CL_Target_XImage_Std::put_image(int x, int y, Drawable win, GC gc)
00097 {
00098         XPutImage(
00099                 m_dpy,
00100                 win,
00101                 gc,
00102                 m_std_image,
00103                 0, 0,
00104                 x, y,
00105                 m_width,
00106                 m_height);
00107 }
00108 
00109 void CL_Target_XImage_Std::put_image(
00110         int x, int y,
00111         const class CL_Rect &rect,
00112         Drawable win, GC gc)
00113 {
00114         XPutImage(
00115                 m_dpy,
00116                 win,
00117                 gc,
00118                 m_std_image,
00119                 rect.x1, rect.y1,
00120                 x, y,
00121                 rect.x2 - rect.x1,
00122                 rect.y2 - rect.y1);
00123 }
00124 
00125 void CL_Target_XImage_Std::lock()
00126 {
00127 //      return true;
00128 }
00129         
00130 void CL_Target_XImage_Std::unlock()
00131 {
00132 }
00133 
00134 void *CL_Target_XImage_Std::get_data() const
00135 {
00136         return m_std_image->data;
00137 }
00138 
00139 unsigned int CL_Target_XImage_Std::get_width() const
00140 {
00141         return m_width;
00142 }
00143 
00144 bool CL_Target_XImage_Std::is_indexed() const
00145 {
00146         return false;
00147 }
00148 
00149 unsigned int CL_Target_XImage_Std::get_height() const
00150 {
00151         return m_height;
00152 }
00153 
00154 unsigned int CL_Target_XImage_Std::get_pitch() const
00155 {
00156         int bytes_per_pixel = (get_depth()+7)/8;
00157 
00158         return m_width*bytes_per_pixel;
00159 }
00160         
00161 unsigned int CL_Target_XImage_Std::get_depth() const
00162 {
00163         int hack = (m_visual_info.bits_per_rgb+7)/8;
00164         return hack*8;
00165 }
00166 
00167 unsigned int CL_Target_XImage_Std::get_red_mask() const
00168 {
00169         return m_visual_info.red_mask;
00170 }
00171 
00172 unsigned int CL_Target_XImage_Std::get_green_mask() const
00173 {
00174         return m_visual_info.green_mask;
00175 }
00176 
00177 unsigned int CL_Target_XImage_Std::get_blue_mask() const
00178 {
00179         return m_visual_info.blue_mask;
00180 }
00181 
00182 unsigned int CL_Target_XImage_Std::get_alpha_mask() const
00183 {
00184 //      return m_visual_info.alpha_mask; // no alpha mask in visualinfo struct!?
00185         return 0;
00186 }
00187 
00188 CL_Palette *CL_Target_XImage_Std::get_palette() const
00189 {
00190         return NULL;
00191 }

Generated at Wed Apr 4 19:54:04 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001