00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef PIXELBUFFER_H
00019 #define PIXELBUFFER_H
00020
00021
00022
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
00034
00035
00036 class RenderBuffer;
00037 class Filename;
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
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,
00073 F_rgb5,
00074
00075
00076
00077 F_rgb8,
00078 F_rgb12,
00079 F_rgb332,
00080 F_rgba,
00081 F_rgbm,
00082 F_rgba4,
00083 F_rgba5,
00084 F_rgba8,
00085 F_rgba12,
00086 F_luminance,
00087 F_luminance_alpha,
00088 F_luminance_alphamask
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 ©);
00098 void operator = (const PixelBuffer ©);
00099
00100
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
00176
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
00189
00190 PTA_uchar _image;
00191 };
00192
00193 #include "pixelBuffer.I"
00194
00195 #endif