Panda3D
|
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 virtual bool supports_grayscale() const; 00074 }; 00075 00076 00077 // The TypedWritable interface follows. 00078 public: 00079 static void register_with_read_factory(); 00080 00081 protected: 00082 static TypedWritable *make_PNMFileTypeBMP(const FactoryParams ¶ms); 00083 00084 public: 00085 static TypeHandle get_class_type() { 00086 return _type_handle; 00087 } 00088 static void init_type() { 00089 PNMFileType::init_type(); 00090 register_type(_type_handle, "PNMFileTypeBMP", 00091 PNMFileType::get_class_type()); 00092 } 00093 virtual TypeHandle get_type() const { 00094 return get_class_type(); 00095 } 00096 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00097 00098 private: 00099 static TypeHandle _type_handle; 00100 }; 00101 00102 #endif // HAVE_BMP 00103 00104 #endif