Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages | Examples

agg_rendering_buffer.h

00001 //----------------------------------------------------------------------------
00002 // Anti-Grain Geometry - Version 2.2
00003 // Copyright (C) 2002-2004 Maxim Shemanarev (http://www.antigrain.com)
00004 //
00005 // Permission to copy, use, modify, sell and distribute this software 
00006 // is granted provided this copyright notice appears in all copies. 
00007 // This software is provided "as is" without express or implied
00008 // warranty, and with no claim as to its suitability for any purpose.
00009 //
00010 //----------------------------------------------------------------------------
00011 // Contact: mcseem@antigrain.com
00012 //          mcseemagg@yahoo.com
00013 //          http://www.antigrain.com
00014 //----------------------------------------------------------------------------
00015 //
00016 // class rendering_buffer
00017 //
00018 //----------------------------------------------------------------------------
00019 
00020 #ifndef AGG_RENDERING_BUFFER_INCLUDED
00021 #define AGG_RENDERING_BUFFER_INCLUDED
00022 
00023 #include "agg_basics.h"
00024 
00025 namespace agg
00026 {
00027 
00028     //==========================================================row_ptr_cache
00029     template<class T> class row_ptr_cache
00030     {
00031     public:
00032         //--------------------------------------------------------------------
00033         struct row_data
00034         {
00035             int x1, x2;
00036             const int8u* ptr;
00037             row_data() {}
00038             row_data(int x1_, int x2_, const int8u* ptr_) : 
00039                 x1(x1_), x2(x2_), ptr(ptr_) {}
00040         };
00041 
00042         //-------------------------------------------------------------------
00043         ~row_ptr_cache()
00044         {
00045             delete [] m_rows;
00046         }
00047 
00048         //-------------------------------------------------------------------
00049         row_ptr_cache() :
00050             m_buf(0),
00051             m_rows(0),
00052             m_width(0),
00053             m_height(0),
00054             m_stride(0),
00055             m_max_height(0)
00056         {
00057         }
00058 
00059         //--------------------------------------------------------------------
00060         row_ptr_cache(T* buf, unsigned width, unsigned height, int stride) :
00061             m_buf(0),
00062             m_rows(0),
00063             m_width(0),
00064             m_height(0),
00065             m_stride(0),
00066             m_max_height(0)
00067         {
00068             attach(buf, width, height, stride);
00069         }
00070 
00071         //--------------------------------------------------------------------
00072         void attach(T* buf, unsigned width, unsigned height, int stride)
00073         {
00074             m_buf = buf;
00075             m_width = width;
00076             m_height = height;
00077             m_stride = stride;
00078             if(height > m_max_height)
00079             {
00080                 delete [] m_rows;
00081                 m_rows = new T* [m_max_height = height];
00082             }
00083 
00084             T* row_ptr = m_buf;
00085 
00086             if(stride < 0)
00087             {
00088                 row_ptr = m_buf - int(height - 1) * stride;
00089             }
00090 
00091             T** rows = m_rows;
00092 
00093             while(height--)
00094             {
00095                 *rows++ = row_ptr;
00096                 row_ptr += stride;
00097             }
00098         }
00099 
00100         //--------------------------------------------------------------------
00101         const T* buf()    const { return m_buf;    }
00102         unsigned width()  const { return m_width;  }
00103         unsigned height() const { return m_height; }
00104         int      stride() const { return m_stride; }
00105         unsigned stride_abs() const 
00106         {
00107             return (m_stride < 0) ? 
00108                 unsigned(-m_stride) : 
00109                 unsigned(m_stride); 
00110         }
00111 
00112         //--------------------------------------------------------------------
00113         T* row(unsigned y) { return m_rows[y]; }
00114         const T* row(unsigned y) const { return m_rows[y]; }
00115         T const* const* rows() const { return m_rows; }
00116 
00117         //--------------------------------------------------------------------
00118         void copy_from(const row_ptr_cache<T>& mtx)
00119         {
00120             unsigned h = height();
00121             if(mtx.height() < h) h = mtx.height();
00122         
00123             unsigned l = stride_abs();
00124             if(mtx.stride_abs() < l) l = mtx.stride_abs();
00125         
00126             l *= sizeof(T);
00127 
00128             unsigned y;
00129             for (y = 0; y < h; y++)
00130             {
00131                 memcpy(row(y), mtx.row(y), l);
00132             }
00133         }
00134 
00135         //--------------------------------------------------------------------
00136         void clear(T value)
00137         {
00138             unsigned y;
00139             for(y = 0; y < height(); y++)
00140             {
00141                 T* p = row(y);
00142                 unsigned x;
00143                 for(x = 0; x < stride_abs(); x++)
00144                 {
00145                     *p++ = value;
00146                 }
00147             }
00148         }
00149 
00150 
00151     private:
00152         //--------------------------------------------------------------------
00153         // Prohibit copying
00154         row_ptr_cache(const row_ptr_cache<T>&);
00155         const row_ptr_cache<T>& operator = (const row_ptr_cache<T>&);
00156 
00157     private:
00158         //--------------------------------------------------------------------
00159         T*       m_buf;        // Pointer to renrdering buffer
00160         T**      m_rows;       // Pointers to each row of the buffer
00161         unsigned m_width;      // Width in pixels
00162         unsigned m_height;     // Height in pixels
00163         int      m_stride;     // Number of bytes per row. Can be < 0
00164         unsigned m_max_height; // The maximal height (currently allocated)
00165     };
00166 
00167 
00168 
00169     //========================================================rendering_buffer
00170     typedef row_ptr_cache<int8u> rendering_buffer;
00171 
00172 }
00173 
00174 
00175 #endif

Generated on Wed Feb 9 11:31:35 2005 for OpenGUI by  doxygen 1.4.0