Panda3D

pnmFileTypeBMP.h

00001 // Filename: pnmFileTypeBMP.h
00002 // Created by:  drose (17Jun00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef PNMFILETYPEBMP_H
00016 #define PNMFILETYPEBMP_H
00017 
00018 #include "pandabase.h"
00019 
00020 #ifdef HAVE_BMP
00021 
00022 #include "pnmFileType.h"
00023 #include "pnmReader.h"
00024 #include "pnmWriter.h"
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : PNMFileTypeBMP
00028 // Description : For reading and writing Windows BMP files.
00029 ////////////////////////////////////////////////////////////////////
00030 class EXPCL_PANDA_PNMIMAGETYPES PNMFileTypeBMP : public PNMFileType {
00031 public:
00032   PNMFileTypeBMP();
00033 
00034   virtual string get_name() const;
00035 
00036   virtual int get_num_extensions() const;
00037   virtual string get_extension(int n) const;
00038   virtual string get_suggested_extension() const;
00039 
00040   virtual bool has_magic_number() const;
00041   virtual bool matches_magic_number(const string &magic_number) const;
00042 
00043   virtual PNMReader *make_reader(istream *file, bool owns_file = true,
00044                                  const string &magic_number = string());
00045   virtual PNMWriter *make_writer(ostream *file, bool owns_file = true);
00046 
00047 public:
00048   class Reader : public PNMReader {
00049   public:
00050     Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number);
00051 
00052     virtual int read_data(xel *array, xelval *alpha);
00053 
00054   private:
00055     unsigned long       pos;
00056 
00057     unsigned long offBits;
00058 
00059     unsigned short  cBitCount;
00060     int             indexed;
00061     int             classv;
00062 
00063     pixval R[256];      /* reds */
00064     pixval G[256];      /* greens */
00065     pixval B[256];      /* blues */
00066   };
00067 
00068   class Writer : public PNMWriter {
00069   public:
00070     Writer(PNMFileType *type, ostream *file, bool owns_file);
00071 
00072     virtual int write_data(xel *array, xelval *alpha);
00073   };
00074 
00075 
00076   // The TypedWritable interface follows.
00077 public:
00078   static void register_with_read_factory();
00079 
00080 protected:
00081   static TypedWritable *make_PNMFileTypeBMP(const FactoryParams &params);
00082 
00083 public:
00084   static TypeHandle get_class_type() {
00085     return _type_handle;
00086   }
00087   static void init_type() {
00088     PNMFileType::init_type();
00089     register_type(_type_handle, "PNMFileTypeBMP",
00090                   PNMFileType::get_class_type());
00091   }
00092   virtual TypeHandle get_type() const {
00093     return get_class_type();
00094   }
00095   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00096 
00097 private:
00098   static TypeHandle _type_handle;
00099 };
00100 
00101 #endif  // HAVE_BMP
00102 
00103 #endif
 All Classes Functions Variables Enumerations