00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
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 ©);
00066 INLINE void operator = (const PNMImage ©);
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 ©);
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
00110
00111
00112
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
00135
00136
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
00168
00169
00170
00171 INLINE xel *operator [] (int y);
00172 INLINE const xel *operator [] (int y) const;
00173
00174
00175 void copy_sub_image(const PNMImage ©, int xto, int yto,
00176 int xfrom = 0, int yfrom = 0,
00177 int x_size = -1, int y_size = -1);
00178
00179
00180
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 ©);
00186 void gaussian_filter_from(double radius, const PNMImage ©);
00187 void quick_filter_from(const PNMImage ©,
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