Panda3D
pnmFileTypeBMP.h
1 // Filename: pnmFileTypeBMP.h
2 // Created by: drose (17Jun00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PNMFILETYPEBMP_H
16 #define PNMFILETYPEBMP_H
17 
18 #include "pandabase.h"
19 
20 #ifdef HAVE_BMP
21 
22 #include "pnmFileType.h"
23 #include "pnmReader.h"
24 #include "pnmWriter.h"
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : PNMFileTypeBMP
28 // Description : For reading and writing Windows BMP files.
29 ////////////////////////////////////////////////////////////////////
30 class EXPCL_PANDA_PNMIMAGETYPES PNMFileTypeBMP : public PNMFileType {
31 public:
32  PNMFileTypeBMP();
33 
34  virtual string get_name() const;
35 
36  virtual int get_num_extensions() const;
37  virtual string get_extension(int n) const;
38  virtual string get_suggested_extension() const;
39 
40  virtual bool has_magic_number() const;
41  virtual bool matches_magic_number(const string &magic_number) const;
42 
43  virtual PNMReader *make_reader(istream *file, bool owns_file = true,
44  const string &magic_number = string());
45  virtual PNMWriter *make_writer(ostream *file, bool owns_file = true);
46 
47 public:
48  class Reader : public PNMReader {
49  public:
50  Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number);
51 
52  virtual int read_data(xel *array, xelval *alpha);
53 
54  private:
55  unsigned long pos;
56 
57  unsigned long offBits;
58 
59  unsigned short cBitCount;
60  int indexed;
61  int classv;
62 
63  pixval R[256]; /* reds */
64  pixval G[256]; /* greens */
65  pixval B[256]; /* blues */
66  };
67 
68  class Writer : public PNMWriter {
69  public:
70  Writer(PNMFileType *type, ostream *file, bool owns_file);
71 
72  virtual int write_data(xel *array, xelval *alpha);
73  virtual bool supports_grayscale() const;
74  };
75 
76 
77  // The TypedWritable interface follows.
78 public:
79  static void register_with_read_factory();
80 
81 protected:
82  static TypedWritable *make_PNMFileTypeBMP(const FactoryParams &params);
83 
84 public:
85  static TypeHandle get_class_type() {
86  return _type_handle;
87  }
88  static void init_type() {
89  PNMFileType::init_type();
90  register_type(_type_handle, "PNMFileTypeBMP",
91  PNMFileType::get_class_type());
92  }
93  virtual TypeHandle get_type() const {
94  return get_class_type();
95  }
96  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
97 
98 private:
99  static TypeHandle _type_handle;
100 };
101 
102 #endif // HAVE_BMP
103 
104 #endif
virtual string get_extension(int n) const
Returns the nth possible filename extension associated with this particular file type, without a leading dot.
Definition: pnmFileType.cxx:62
virtual PNMWriter * make_writer(ostream *file, bool owns_file=true)
Allocates and returns a new PNMWriter suitable for reading from this file type, if possible...
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition: pnmFileType.h:35
virtual PNMReader * make_reader(istream *file, bool owns_file=true, const string &magic_number=string())
Allocates and returns a new PNMReader suitable for reading from this file type, if possible...
virtual bool matches_magic_number(const string &magic_number) const
Returns true if the indicated "magic number" byte stream (the initial few bytes read from the file) m...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This is an abstract base class that defines the interface for reading image files of various types...
Definition: pnmReader.h:31
This is an abstract base class that defines the interface for writing image files of various types...
Definition: pnmWriter.h:31
virtual bool has_magic_number() const
Returns true if this particular file type uses a magic number to identify it, false otherwise...
Definition: pnmFileType.cxx:89
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual int get_num_extensions() const
Returns the number of different possible filename extensions associated with this particular file typ...
Definition: pnmFileType.cxx:50
virtual string get_suggested_extension() const
Returns a suitable filename extension (without a leading dot) to suggest for files of this type...
Definition: pnmFileType.cxx:75