Panda3D
 All Classes Functions Variables Enumerations
pnmFileTypeAndroid.cxx
1 // Filename: pnmFileTypeAndroid.cxx
2 // Created by: rdb (11Jan13)
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 #include "pnmFileTypeAndroid.h"
16 
17 #ifdef ANDROID
18 
19 #include "config_pnmimagetypes.h"
20 
21 #include "pnmFileTypeRegistry.h"
22 #include "bamReader.h"
23 
24 static const char * const extensions_android[] = {
25  "jpg", "jpeg", "gif", "png",//"webp" (android 4.0+)
26 };
27 static const int num_extensions_android = sizeof(extensions_android) / sizeof(const char *);
28 
29 TypeHandle PNMFileTypeAndroid::_type_handle;
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: PNMFileTypeAndroid::Constructor
33 // Access: Public
34 // Description:
35 ////////////////////////////////////////////////////////////////////
36 PNMFileTypeAndroid::
37 PNMFileTypeAndroid() {
38 }
39 
40 ////////////////////////////////////////////////////////////////////
41 // Function: PNMFileTypeAndroid::get_name
42 // Access: Public, Virtual
43 // Description: Returns a few words describing the file type.
44 ////////////////////////////////////////////////////////////////////
45 string PNMFileTypeAndroid::
46 get_name() const {
47  return "Android Bitmap";
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: PNMFileTypeAndroid::get_num_extensions
52 // Access: Public, Virtual
53 // Description: Returns the number of different possible filename
54 // extensions associated with this particular file type.
55 ////////////////////////////////////////////////////////////////////
56 int PNMFileTypeAndroid::
57 get_num_extensions() const {
58  return num_extensions_android;
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: PNMFileTypeAndroid::get_extension
63 // Access: Public, Virtual
64 // Description: Returns the nth possible filename extension
65 // associated with this particular file type, without a
66 // leading dot.
67 ////////////////////////////////////////////////////////////////////
68 string PNMFileTypeAndroid::
69 get_extension(int n) const {
70  nassertr(n >= 0 && n < num_extensions_android, string());
71  return extensions_android[n];
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: PNMFileTypeAndroid::has_magic_number
76 // Access: Public, Virtual
77 // Description: Returns true if this particular file type uses a
78 // magic number to identify it, false otherwise.
79 ////////////////////////////////////////////////////////////////////
80 bool PNMFileTypeAndroid::
81 has_magic_number() const {
82  return false;
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: PNMFileTypeAndroid::make_reader
87 // Access: Public, Virtual
88 // Description: Allocates and returns a new PNMReader suitable for
89 // reading from this file type, if possible. If reading
90 // from this file type is not supported, returns NULL.
91 ////////////////////////////////////////////////////////////////////
92 PNMReader *PNMFileTypeAndroid::
93 make_reader(istream *file, bool owns_file, const string &magic_number) {
94  init_pnm();
95  return new Reader(this, file, owns_file, magic_number);
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: PNMFileTypeAndroid::register_with_read_factory
100 // Access: Public, Static
101 // Description: Registers the current object as something that can be
102 // read from a Bam file.
103 ////////////////////////////////////////////////////////////////////
104 void PNMFileTypeAndroid::
105 register_with_read_factory() {
107  register_factory(get_class_type(), make_PNMFileTypeAndroid);
108 }
109 
110 ////////////////////////////////////////////////////////////////////
111 // Function: PNMFileTypeAndroid::make_PNMFileTypeAndroid
112 // Access: Protected, Static
113 // Description: This method is called by the BamReader when an object
114 // of this type is encountered in a Bam file; it should
115 // allocate and return a new object with all the data
116 // read.
117 //
118 // In the case of the PNMFileType objects, since these
119 // objects are all shared, we just pull the object from
120 // the registry.
121 ////////////////////////////////////////////////////////////////////
122 TypedWritable *PNMFileTypeAndroid::
123 make_PNMFileTypeAndroid(const FactoryParams &params) {
124  return PNMFileTypeRegistry::get_global_ptr()->get_type_by_handle(get_class_type());
125 }
126 
127 #endif // ANDROID
PNMFileType * get_type_by_handle(TypeHandle handle) const
Returns the PNMFileType instance stored in the registry for the given TypeHandle, e...
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
static PNMFileTypeRegistry * get_global_ptr()
Returns a pointer to the global PNMFileTypeRegistry object.
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
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85