Panda3D
Loading...
Searching...
No Matches
pnmFileTypeSGI.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 pnmFileTypeSGI.cxx
10 * @author drose
11 * @date 2000-06-17
12 */
13
14#include "pnmFileTypeSGI.h"
15
16#ifdef HAVE_SGI_RGB
17
19#include "sgi.h"
20
21#include "pnmFileTypeRegistry.h"
22#include "bamReader.h"
23
24using std::string;
25
26static const char * const extensions_sgi[] = {
27 "rgb", "rgba", "sgi"
28};
29static const int num_extensions_sgi = sizeof(extensions_sgi) / sizeof(const char *);
30
31TypeHandle PNMFileTypeSGI::_type_handle;
32
33/**
34 *
35 */
36PNMFileTypeSGI::
37PNMFileTypeSGI() {
38}
39
40/**
41 * Returns a few words describing the file type.
42 */
43string PNMFileTypeSGI::
44get_name() const {
45 return "SGI RGB";
46}
47
48/**
49 * Returns the number of different possible filename extensions associated
50 * with this particular file type.
51 */
52int PNMFileTypeSGI::
53get_num_extensions() const {
54 return num_extensions_sgi;
55}
56
57/**
58 * Returns the nth possible filename extension associated with this particular
59 * file type, without a leading dot.
60 */
61string PNMFileTypeSGI::
62get_extension(int n) const {
63 nassertr(n >= 0 && n < num_extensions_sgi, string());
64 return extensions_sgi[n];
65}
66
67/**
68 * Returns a suitable filename extension (without a leading dot) to suggest
69 * for files of this type, or empty string if no suggestions are available.
70 */
71string PNMFileTypeSGI::
72get_suggested_extension() const {
73 return "rgb";
74}
75
76/**
77 * Returns true if this particular file type uses a magic number to identify
78 * it, false otherwise.
79 */
80bool PNMFileTypeSGI::
81has_magic_number() const {
82 return true;
83}
84
85/**
86 * Returns true if the indicated "magic number" byte stream (the initial few
87 * bytes read from the file) matches this particular file type, false
88 * otherwise.
89 */
90bool PNMFileTypeSGI::
91matches_magic_number(const string &magic_number) const {
92 nassertr(magic_number.size() >= 2, false);
93 int mn =
94 ((unsigned char)magic_number[0] << 8) |
95 ((unsigned char)magic_number[1]);
96 return (mn == SGI_MAGIC);
97}
98
99/**
100 * Allocates and returns a new PNMReader suitable for reading from this file
101 * type, if possible. If reading from this file type is not supported,
102 * returns NULL.
103 */
104PNMReader *PNMFileTypeSGI::
105make_reader(std::istream *file, bool owns_file, const string &magic_number) {
106 init_pnm();
107 return new Reader(this, file, owns_file, magic_number);
108}
109
110/**
111 * Allocates and returns a new PNMWriter suitable for reading from this file
112 * type, if possible. If writing files of this type is not supported, returns
113 * NULL.
114 */
115PNMWriter *PNMFileTypeSGI::
116make_writer(std::ostream *file, bool owns_file) {
117 init_pnm();
118 return new Writer(this, file, owns_file);
119}
120
121
122/**
123 * Registers the current object as something that can be read from a Bam file.
124 */
125void PNMFileTypeSGI::
126register_with_read_factory() {
128 register_factory(get_class_type(), make_PNMFileTypeSGI);
129}
130
131/**
132 * This method is called by the BamReader when an object of this type is
133 * encountered in a Bam file; it should allocate and return a new object with
134 * all the data read.
135 *
136 * In the case of the PNMFileType objects, since these objects are all shared,
137 * we just pull the object from the registry.
138 */
139TypedWritable *PNMFileTypeSGI::
140make_PNMFileTypeSGI(const FactoryParams &params) {
142}
143
144#endif // HAVE_SGI_RGB
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.