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

panda/src/pnmimage/pnmImage.h

Go to the documentation of this file.
00001 // Filename: pnmImage.h
00002 // Created by:  drose (14Jun00)
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 
00019 #ifndef PNMIMAGE_H
00020 #define PNMIMAGE_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "pnmImageHeader.h"
00025 
00026 #include "luse.h"
00027 
00028 class PNMReader;
00029 class PNMWriter;
00030 class PNMFileType;
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //       Class : PNMImage
00034 // Description : The name of this class derives from the fact that we
00035 //               originally implemented it as a layer on top of the
00036 //               "pnm library", based on netpbm, which was built to
00037 //               implement pbm, pgm, and pbm files, and is the
00038 //               underlying support of a number of public-domain image
00039 //               file converters.  Nowadays we are no longer derived
00040 //               directly from the pnm library, mainly to allow
00041 //               support of C++ iostreams instead of the C stdio FILE
00042 //               interface.
00043 //
00044 //               Conceptually, a PNMImage is a two-dimensional array
00045 //               of xels, which are the PNM-defined generic pixel
00046 //               type.  Each xel may have a red, green, and blue
00047 //               component, or (if the image is grayscale) a gray
00048 //               component.  The image may be read in, the individual
00049 //               xels manipulated, and written out again, or a black
00050 //               image may be constructed from scratch.
00051 //
00052 //               The image is of size XSize() by YSize() xels,
00053 //               numbered from top to bottom, left to right, beginning
00054 //               at zero.
00055 //
00056 //               Files can be specified by filename, or by an iostream
00057 //               pointer.  The filename "-" refers to stdin or stdout.
00058 ////////////////////////////////////////////////////////////////////
00059 class EXPCL_PANDA PNMImage : public PNMImageHeader {
00060 public:
00061   INLINE PNMImage();
00062   INLINE PNMImage(const Filename &filename, PNMFileType *type = NULL);
00063   INLINE PNMImage(int x_size, int y_size, int num_channels = 3,
00064                   xelval maxval = 255, PNMFileType *type = NULL);
00065   INLINE PNMImage(const PNMImage &copy);
00066   INLINE void operator = (const PNMImage &copy);
00067 
00068   INLINE ~PNMImage();
00069 
00070   INLINE xelval clamp_val(int input_value) const;
00071   INLINE xelval to_val(double input_value) const;
00072   INLINE double from_val(xelval input_value) const;
00073 
00074   void clear();
00075   void clear(int x_size, int y_size, int num_channels = 3,
00076              xelval maxval = 255, PNMFileType *type = NULL);
00077 
00078   void copy_from(const PNMImage &copy);
00079   void copy_header_from(const PNMImageHeader &header);
00080 
00081   INLINE void fill(double red, double green, double blue);
00082   INLINE void fill(double gray = 0.0);
00083 
00084   void fill_val(xelval red, xelval green, xelval blue);
00085   INLINE void fill_val(xelval gray = 0);
00086 
00087   INLINE void alpha_fill(double alpha = 0.0);
00088   void alpha_fill_val(xelval alpha = 0);
00089 
00090   bool read(const Filename &filename, PNMFileType *type = NULL);
00091   bool read(PNMReader *reader);
00092 
00093   bool write(const Filename &filename, PNMFileType *type = NULL) const;
00094   bool write(PNMWriter *writer) const;
00095 
00096   INLINE bool is_valid() const;
00097 
00098   INLINE void set_num_channels(int num_channels);
00099   void set_color_type(ColorType color_type);
00100 
00101   INLINE void add_alpha();
00102   INLINE void remove_alpha();
00103   INLINE void make_grayscale();
00104   void make_grayscale(double rc, double gc, double bc);
00105   INLINE void make_rgb();
00106 
00107   void set_maxval(xelval maxval);
00108 
00109   // The *_val() functions return or set the color values in the range
00110   // [0..get_maxval()].  This range may be different for different
00111   // images!  Use the corresponding functions (without _val()) to work
00112   // in the normalized range [0..1].
00113 
00114   INLINE const xel &get_xel_val(int x, int y) const;
00115   INLINE void set_xel_val(int x, int y, const xel &value);
00116   INLINE void set_xel_val(int x, int y, xelval r, xelval g, xelval b);
00117   INLINE void set_xel_val(int x, int y, xelval gray);
00118 
00119   INLINE xelval get_red_val(int x, int y) const;
00120   INLINE xelval get_green_val(int x, int y) const;
00121   INLINE xelval get_blue_val(int x, int y) const;
00122   INLINE xelval get_gray_val(int x, int y) const;
00123   INLINE xelval get_alpha_val(int x, int y) const;
00124 
00125   INLINE void set_red_val(int x, int y, xelval r);
00126   INLINE void set_green_val(int x, int y, xelval g);
00127   INLINE void set_blue_val(int x, int y, xelval b);
00128   INLINE void set_gray_val(int x, int y, xelval gray);
00129   INLINE void set_alpha_val(int x, int y, xelval a);
00130 
00131   xelval get_channel_val(int x, int y, int channel) const;
00132   void set_channel_val(int x, int y, int channel, xelval value);
00133 
00134   // The corresponding get_xel(), set_xel(), get_red(), etc. functions
00135   // automatically scale their values by get_maxval() into the range
00136   // [0..1].
00137 
00138   INLINE RGBColord get_xel(int x, int y) const;
00139   INLINE void set_xel(int x, int y, const RGBColord &value);
00140   INLINE void set_xel(int x, int y, double r, double g, double b);
00141   INLINE void set_xel(int x, int y, double gray);
00142 
00143   INLINE double get_red(int x, int y) const;
00144   INLINE double get_green(int x, int y) const;
00145   INLINE double get_blue(int x, int y) const;
00146   INLINE double get_gray(int x, int y) const;
00147   INLINE double get_alpha(int x, int y) const;
00148 
00149   INLINE void set_red(int x, int y, double r);
00150   INLINE void set_green(int x, int y, double g);
00151   INLINE void set_blue(int x, int y, double b);
00152   INLINE void set_gray(int x, int y, double gray);
00153   INLINE void set_alpha(int x, int y, double a);
00154 
00155   INLINE double get_channel(int x, int y, int channel) const;
00156   INLINE void set_channel(int x, int y, int channel, double value);
00157 
00158   INLINE double get_bright(int x, int y) const;
00159   INLINE double get_bright(int x, int y, double rc, double gc,
00160                            double bc) const;
00161   INLINE double get_bright(int x, int y, double rc, double gc,
00162                            double bc, double ac) const;
00163 
00164   INLINE void blend(int x, int y, const RGBColord &val, double alpha);
00165   void blend(int x, int y, double r, double g, double b, double alpha);
00166 
00167   // If you're used to the NetPBM library and like working with a 2-d
00168   // array of xels, and using the PNM macros to access their components,
00169   // you may treat the PNMImage as such directly.
00170 
00171   INLINE xel *operator [] (int y);
00172   INLINE const xel *operator [] (int y) const;
00173 
00174 
00175   void copy_sub_image(const PNMImage &copy, int xto, int yto,
00176                       int xfrom = 0, int yfrom = 0,
00177                       int x_size = -1, int y_size = -1);
00178 
00179   // The bodies for the non-inline *_filter() functions can be found
00180   // in the file pnm-image-filter.cxx.
00181 
00182   INLINE void box_filter(double radius = 1.0);
00183   INLINE void gaussian_filter(double radius = 1.0);
00184 
00185   void box_filter_from(double radius, const PNMImage &copy);
00186   void gaussian_filter_from(double radius, const PNMImage &copy);
00187   void quick_filter_from(const PNMImage &copy,
00188                          int xborder = 0, int yborder = 0);
00189 
00190 private:
00191   INLINE void allocate_array();
00192   INLINE void allocate_alpha();
00193 
00194   INLINE xel *row(int row) const;
00195   INLINE xelval *alpha_row(int row) const;
00196 
00197   void setup_rc();
00198 
00199 private:
00200   xel *_array;
00201   xelval *_alpha;
00202   double _default_rc, _default_gc, _default_bc;
00203 };
00204 
00205 #include "pnmImage.I"
00206 
00207 #endif

Generated on Fri May 2 00:43:08 2003 for Panda by doxygen1.3