Panda3D
pnmFileTypeJPG.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 pnmFileTypeJPG.cxx
10 * @author mike
11 * @date 2000-06-19
12 */
13
14#include "pnmFileTypeJPG.h"
15
16#ifdef HAVE_JPEG
17
19
20#include "pnmFileTypeRegistry.h"
21#include "bamReader.h"
22
23using std::string;
24
25static const char *const extensions_jpg[] = {
26 "jpg", "jpeg"
27};
28static const int num_extensions_jpg = sizeof(extensions_jpg) / sizeof(const char *);
29
30TypeHandle PNMFileTypeJPG::_type_handle;
31
32/**
33 *
34 */
35PNMFileTypeJPG::
36PNMFileTypeJPG() {
37}
38
39/**
40 * Returns a few words describing the file type.
41 */
42string PNMFileTypeJPG::
43get_name() const {
44 return "JPEG";
45}
46
47/**
48 * Returns the number of different possible filename extensions associated
49 * with this particular file type.
50 */
51int PNMFileTypeJPG::
52get_num_extensions() const {
53 return num_extensions_jpg;
54}
55
56/**
57 * Returns the nth possible filename extension associated with this particular
58 * file type, without a leading dot.
59 */
60string PNMFileTypeJPG::
61get_extension(int n) const {
62 nassertr(n >= 0 && n < num_extensions_jpg, string());
63 return extensions_jpg[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 PNMFileTypeJPG::
71get_suggested_extension() const {
72 return "jpg";
73}
74
75/**
76 * Returns true if this particular file type uses a magic number to identify
77 * it, false otherwise.
78 */
79bool PNMFileTypeJPG::
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 PNMFileTypeJPG::
90matches_magic_number(const string &magic_number) const {
91 nassertr(magic_number.size() >= 2, false);
92 return ((char)magic_number[0] == (char)0xff &&
93 (char)magic_number[1] == (char)0xd8);
94}
95
96/**
97 * Allocates and returns a new PNMReader suitable for reading from this file
98 * type, if possible. If reading from this file type is not supported,
99 * returns NULL.
100 */
101PNMReader *PNMFileTypeJPG::
102make_reader(std::istream *file, bool owns_file, const string &magic_number) {
103 init_pnm();
104 return new Reader(this, file, owns_file, magic_number);
105}
106
107/**
108 * Allocates and returns a new PNMWriter suitable for reading from this file
109 * type, if possible. If writing files of this type is not supported, returns
110 * NULL.
111 */
112PNMWriter *PNMFileTypeJPG::
113make_writer(std::ostream *file, bool owns_file) {
114 init_pnm();
115 return new Writer(this, file, owns_file);
116}
117
118
119/**
120 * Registers the current object as something that can be read from a Bam file.
121 */
122void PNMFileTypeJPG::
123register_with_read_factory() {
125 register_factory(get_class_type(), make_PNMFileTypeJPG);
126}
127
128/**
129 * This method is called by the BamReader when an object of this type is
130 * encountered in a Bam file; it should allocate and return a new object with
131 * all the data read.
132 *
133 * In the case of the PNMFileType objects, since these objects are all shared,
134 * we just pull the object from the registry.
135 */
136TypedWritable *PNMFileTypeJPG::
137make_PNMFileTypeJPG(const FactoryParams &params) {
139}
140
141#endif // HAVE_JPEG
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...
Definition: factoryParams.h:36
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.
Definition: typedWritable.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.