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

panda/src/gobj/pixelBuffer.h

Go to the documentation of this file.
00001 // Filename: pixelBuffer.h
00002 // Created by:  mike (09Jan97)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 #ifndef PIXELBUFFER_H
00019 #define PIXELBUFFER_H
00020 //
00021 ////////////////////////////////////////////////////////////////////
00022 // Includes
00023 ////////////////////////////////////////////////////////////////////
00024 #include <pandabase.h>
00025 
00026 #include "imageBuffer.h"
00027 
00028 #include <pnmImage.h>
00029 #include <graphicsStateGuardianBase.h>
00030 #include <pta_uchar.h>
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 // Defines
00034 ////////////////////////////////////////////////////////////////////
00035 
00036 class RenderBuffer;
00037 class Filename;
00038 
00039 ////////////////////////////////////////////////////////////////////
00040 //       Class : PixelBuffer
00041 // Description :
00042 
00043 //               Maintains an array of pixel data corresponding to an
00044 //               image, e.g. copied from the frame buffer, or as part
00045 //               of a Texture.
00046 
00047 //               Pixel data is stored in a generic, uncompressed
00048 //               format.  Each row of pixels is laid out horizontally,
00049 //               from the top to the bottom, with no padding between
00050 //               rows.  Each pixel consumes one or more bytes,
00051 //               according to get_component_width().  If the Format
00052 //               indicates multiple components are present, they are
00053 //               stored in the order B, G, R, A.
00054 ////////////////////////////////////////////////////////////////////
00055 class EXPCL_PANDA PixelBuffer : public ImageBuffer {
00056 public:
00057   enum Type {
00058     T_unsigned_byte,
00059     T_unsigned_short,
00060     T_unsigned_byte_332,
00061     T_float,
00062   };
00063 
00064   enum Format {
00065     F_color_index,
00066     F_stencil_index,
00067     F_depth_component,
00068     F_red,
00069     F_green,
00070     F_blue,
00071     F_alpha,
00072     F_rgb,     // any suitable RGB mode, whatever the hardware prefers
00073     F_rgb5,    // specifically, 5 bits per R,G,B channel.  
00074                // this is paired with T_unsigned_byte.  really T_unsigned_byte
00075                // should not be specified for this one, it should use
00076                // T_unsigned_5bits or something
00077     F_rgb8,    // 8 bits per R,G,B channel
00078     F_rgb12,   // 12 bits per R,G,B channel
00079     F_rgb332,  // 3 bits per R & G, 2 bits for B
00080     F_rgba,    // any suitable RGBA mode, whatever the hardware prefers
00081     F_rgbm,    // as above, but only requires 1 bit for alpha (i.e. mask)
00082     F_rgba4,   // 4 bits per R,G,B,A channel
00083     F_rgba5,   // 5 bits per R,G,B channel, 1 bit alpha
00084     F_rgba8,   // 8 bits per R,G,B,A channel
00085     F_rgba12,  // 12 bits per R,G,B,A channel
00086     F_luminance,
00087     F_luminance_alpha,      // 8 bits luminance, 8 bits alpha
00088     F_luminance_alphamask   // 8 bits luminance, only needs 1 bit of alpha
00089   };
00090 
00091   PixelBuffer(void);
00092   PixelBuffer(int xsize, int ysize, int components,
00093               int component_width, Type type, Format format);
00094   PixelBuffer(int xsize, int ysize, int components,
00095               int component_width, Type type, Format format,
00096               bool bAllocateRAM);
00097   PixelBuffer(const PixelBuffer &copy);
00098   void operator = (const PixelBuffer &copy);
00099 
00100   // Some named constructors for common PixelBuffer types.
00101   INLINE static PixelBuffer rgb_buffer(int xsize, int ysize);
00102   INLINE static PixelBuffer rgba_buffer(int xsize, int ysize);
00103   INLINE static PixelBuffer depth_buffer(int xsize, int ysize);
00104   INLINE static PixelBuffer stencil_buffer(int xsize, int ysize);
00105 
00106   INLINE ~PixelBuffer(void);
00107 
00108   virtual void config( void );
00109 
00110   bool read(const Filename &name);
00111   bool write(const Filename &name) const;
00112 
00113   bool load( const PNMImage& pnmimage );
00114   bool store( PNMImage& pnmimage ) const;
00115 
00116   void copy(const PixelBuffer *pb);
00117 
00118   virtual void copy(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr);
00119   virtual void copy(GraphicsStateGuardianBase *gsg, const DisplayRegion *dr,
00120             const RenderBuffer &rb);
00121 
00122   INLINE void set_xsize(int size);
00123   INLINE void set_ysize(int size);
00124   INLINE void set_xorg(int org);
00125   INLINE void set_yorg(int org);
00126   INLINE void set_size(int x_org, int y_org, int x_size, int y_size);
00127   INLINE void set_format(Format format);
00128 
00129   INLINE int get_xsize() const;
00130   INLINE int get_ysize() const;
00131   INLINE int get_xorg() const;
00132   INLINE int get_yorg() const;
00133   INLINE int get_border() const;
00134   INLINE int get_num_components() const;
00135   INLINE int get_component_width() const;
00136   INLINE Format get_format() const;
00137   INLINE Type get_image_type() const;
00138 
00139   INLINE void set_uchar_rgb_texel(const uchar color[3],
00140                   int x, int y, int width);
00141 
00142 private:
00143   INLINE void store_unscaled_byte(int &index, int value);
00144   INLINE void store_unscaled_short(int &index, int value);
00145   INLINE void store_scaled_byte(int &index, int value, double scale);
00146   INLINE void store_scaled_short(int &index, int value, double scale);
00147   INLINE double get_unsigned_byte(int &index) const;
00148   INLINE double get_unsigned_short(int &index) const;
00149 
00150 public:
00151 
00152   static TypeHandle get_class_type() {
00153     return _type_handle;
00154   }
00155   static void init_type() {
00156     ImageBuffer::init_type();
00157     register_type(_type_handle, "PixelBuffer",
00158                   ImageBuffer::get_class_type());
00159   }
00160   virtual TypeHandle get_type() const {
00161     return get_class_type();
00162   }
00163   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00164 
00165 private:
00166 
00167   static TypeHandle _type_handle;
00168 
00169   ////////////////////////////////////////////////////////////////////
00170 
00171 protected:
00172   int _xsize;
00173   int _ysize;
00174 
00175   // pixelbuffer "origin" represents upper left screen point at which
00176   // pixelbuffer should be drawn using draw_pixel_buffer
00177   int _xorg;
00178   int _yorg;
00179   int _border;
00180   int _components;
00181   int _component_width;
00182   Format _format;
00183   Type _type;
00184 
00185   bool _loaded;
00186 
00187 public:
00188   // This is public to allow direct manipulation of the image data.
00189   // Know what you are doing!
00190   PTA_uchar _image;
00191 };
00192 
00193 #include "pixelBuffer.I"
00194 
00195 #endif

Generated on Fri May 2 00:39:42 2003 for Panda by doxygen1.3