Panda3D
Loading...
Searching...
No Matches
pnmFileTypeBMP.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file pnmFileTypeBMP.cxx
10 * @author drose
11 * @date 2000-06-19
12 */
13
14#include "pnmFileTypeBMP.h"
15
16#ifdef HAVE_BMP
17
19
20#include "pnmFileTypeRegistry.h"
21#include "bamReader.h"
22
23using std::string;
24
25static const char * const extensions_bmp[] = {
26 "bmp"
27};
28static const int num_extensions_bmp = sizeof(extensions_bmp) / sizeof(const char *);
29
30TypeHandle PNMFileTypeBMP::_type_handle;
31
32/**
33 *
34 */
35PNMFileTypeBMP::
36PNMFileTypeBMP() {
37}
38
39/**
40 * Returns a few words describing the file type.
41 */
42string PNMFileTypeBMP::
43get_name() const {
44 return "Windows BMP";
45}
46
47/**
48 * Returns the number of different possible filename extensions associated
49 * with this particular file type.
50 */
51int PNMFileTypeBMP::
52get_num_extensions() const {
53 return num_extensions_bmp;
54}
55
56/**
57 * Returns the nth possible filename extension associated with this particular
58 * file type, without a leading dot.
59 */
60string PNMFileTypeBMP::
61get_extension(int n) const {
62 nassertr(n >= 0 && n < num_extensions_bmp, string());
63 return extensions_bmp[n];
64}
65
66/**
67 * Returns a suitable filename extension (without a leading dot) to suggest
68 * for files of this type, or empty string if no suggestions are available.
69 */
70string PNMFileTypeBMP::
71get_suggested_extension() const {
72 return "bmp";
73}
74
75/**
76 * Returns true if this particular file type uses a magic number to identify
77 * it, false otherwise.
78 */
79bool PNMFileTypeBMP::
80has_magic_number() const {
81 return true;
82}
83
84/**
85 * Returns true if the indicated "magic number" byte stream (the initial few
86 * bytes read from the file) matches this particular file type, false
87 * otherwise.
88 */
89bool PNMFileTypeBMP::
90matches_magic_number(const string &magic_number) const {
91 nassertr(magic_number.size() >= 2, false);
92 return (magic_number.substr(0, 2) == "BM");
93}
94
95/**
96 * Allocates and returns a new PNMReader suitable for reading from this file
97 * type, if possible. If reading from this file type is not supported,
98 * returns NULL.
99 */
100PNMReader *PNMFileTypeBMP::
101make_reader(std::istream *file, bool owns_file, const string &magic_number) {
102 init_pnm();
103 return new Reader(this, file, owns_file, magic_number);
104}
105
106/**
107 * Allocates and returns a new PNMWriter suitable for reading from this file
108 * type, if possible. If writing files of this type is not supported, returns
109 * NULL.
110 */
111PNMWriter *PNMFileTypeBMP::
112make_writer(std::ostream *file, bool owns_file) {
113 init_pnm();
114 return new Writer(this, file, owns_file);
115}
116
117
118/**
119 * Registers the current object as something that can be read from a Bam file.
120 */
121void PNMFileTypeBMP::
122register_with_read_factory() {
124 register_factory(get_class_type(), make_PNMFileTypeBMP);
125}
126
127/**
128 * This method is called by the BamReader when an object of this type is
129 * encountered in a Bam file; it should allocate and return a new object with
130 * all the data read.
131 *
132 * In the case of the PNMFileType objects, since these objects are all shared,
133 * we just pull the object from the registry.
134 */
135TypedWritable *PNMFileTypeBMP::
136make_PNMFileTypeBMP(const FactoryParams &params) {
138}
139
140#endif // HAVE_BMP
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
An instance of this class is passed to the Factory when requesting it to do its business and construc...
PNMFileType * get_type_by_handle(TypeHandle handle) const
Returns the PNMFileType instance stored in the registry for the given TypeHandle, e....
static PNMFileTypeRegistry * get_global_ptr()
Returns a pointer to the global PNMFileTypeRegistry object.
This is an abstract base class that defines the interface for reading image files of various types.
Definition pnmReader.h:27
This is an abstract base class that defines the interface for writing image files of various types.
Definition pnmWriter.h:27
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.