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

panda/src/pnmimage/pnmImageHeader.h

Go to the documentation of this file.
00001 // Filename: pnmImageHeader.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 PNMIMAGEHEADER_H
00020 #define PNMIMAGEHEADER_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "pnmimage_base.h"
00025 
00026 #include "typedObject.h"
00027 #include "filename.h"
00028 
00029 class PNMFileType;
00030 class PNMReader;
00031 class PNMWriter;
00032 
00033 ////////////////////////////////////////////////////////////////////
00034 //       Class : PNMImageHeader
00035 // Description : This is the base class of PNMImage, PNMReader, and
00036 //               PNMWriter.  It encapsulates all the information
00037 //               associated with an image that describes its size,
00038 //               number of channels, etc; that is, all the information
00039 //               about the image except the image data itself.  It's
00040 //               the sort of information you typically read from the
00041 //               image file's header.
00042 ////////////////////////////////////////////////////////////////////
00043 class EXPCL_PANDA PNMImageHeader {
00044 public:
00045   INLINE PNMImageHeader();
00046   INLINE PNMImageHeader(const PNMImageHeader &copy);
00047   INLINE void operator = (const PNMImageHeader &copy);
00048   INLINE ~PNMImageHeader();
00049 
00050   // This enumerated type indicates the number of channels in the
00051   // image, and also implies an image type.  You can treat it either
00052   // as an integer number of channels or as an enumerated image type.
00053   enum ColorType {
00054     CT_invalid      = 0,
00055     CT_grayscale    = 1,
00056     CT_two_channel  = 2,
00057     CT_color        = 3,
00058     CT_four_channel = 4,
00059   };
00060 
00061   INLINE ColorType get_color_type() const;
00062   INLINE int get_num_channels() const;
00063 
00064   INLINE static bool is_grayscale(ColorType color_type);
00065   INLINE bool is_grayscale() const;
00066 
00067   INLINE static bool has_alpha(ColorType color_type);
00068   INLINE bool has_alpha() const;
00069 
00070   INLINE xelval get_maxval() const;
00071 
00072   INLINE int get_x_size() const;
00073   INLINE int get_y_size() const;
00074 
00075   INLINE bool has_type() const;
00076   INLINE PNMFileType *get_type() const;
00077   INLINE void set_type(PNMFileType *type);
00078 
00079   bool read_header(const Filename &filename, PNMFileType *type = NULL);
00080 
00081   PNMReader *make_reader(const Filename &filename,
00082                          PNMFileType *type = NULL) const;
00083   PNMReader *make_reader(istream *file, bool owns_file = true,
00084                          const Filename &filename = Filename(),
00085                          string magic_number = string(),
00086                          PNMFileType *type = NULL) const;
00087 
00088   PNMWriter *make_writer(const Filename &filename,
00089                          PNMFileType *type = NULL) const;
00090   PNMWriter *make_writer(ostream *file, bool owns_file = true,
00091                          const Filename &filename = Filename(),
00092                          PNMFileType *type = NULL) const;
00093 
00094   static bool read_magic_number(istream *file, string &magic_number,
00095                                 int num_bytes);
00096 
00097   void output(ostream &out) const;
00098 
00099 protected:
00100   int _x_size, _y_size;
00101   int _num_channels;
00102   xelval _maxval;
00103   PNMFileType *_type;
00104 };
00105 
00106 INLINE ostream &operator << (ostream &out, const PNMImageHeader &header) {
00107   header.output(out);
00108   return out;
00109 }
00110 
00111 #include "pnmImageHeader.I"
00112 
00113 #endif

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