Panda3D
pnmFileTypeStbImage.h
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 pnmFileTypeStbImage.h
10  * @author rdb
11  * @date 2016-03-31
12  */
13 
14 #ifndef PNMFILETYPESTBIMAGE_H
15 #define PNMFILETYPESTBIMAGE_H
16 
17 #include "pandabase.h"
18 
19 #ifdef HAVE_STB_IMAGE
20 
21 #include "pnmFileType.h"
22 #include "pnmReader.h"
23 #include "pnmWriter.h"
24 
25 /**
26  * For reading images via the public domain stb_image.h library. This is used
27  * when compiling without support for more specific libraries that are more
28  * full-featured, such as libpng or libjpeg.
29  */
30 class EXPCL_PANDA_PNMIMAGETYPES PNMFileTypeStbImage : public PNMFileType {
31 public:
32  PNMFileTypeStbImage();
33 
34  virtual std::string get_name() const;
35 
36  virtual int get_num_extensions() const;
37  virtual std::string get_extension(int n) const;
38 
39  virtual bool has_magic_number() const;
40  virtual bool matches_magic_number(const std::string &magic_number) const;
41 
42  virtual PNMReader *make_reader(std::istream *file, bool owns_file = true,
43  const std::string &magic_number = std::string());
44 
45 public:
46  static void register_with_read_factory();
47 
48 protected:
49  static TypedWritable *make_PNMFileTypeStbImage(const FactoryParams &params);
50 
51 public:
52  static TypeHandle get_class_type() {
53  return _type_handle;
54  }
55  static void init_type() {
56  PNMFileType::init_type();
57  register_type(_type_handle, "PNMFileTypeStbImage",
58  PNMFileType::get_class_type());
59  }
60  virtual TypeHandle get_type() const {
61  return get_class_type();
62  }
63  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
64 
65 private:
66  static TypeHandle _type_handle;
67 };
68 
69 #endif // HAVE_STB_IMAGE
70 
71 #endif
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition: pnmFileType.h:32
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:76
virtual PNMReader * make_reader(std::istream *file, bool owns_file=true, const std::string &magic_number=std::string())
Allocates and returns a new PNMReader suitable for reading from this file type, if possible.
Definition: pnmFileType.cxx:96
get_num_extensions
Returns the number of different possible filename extensions associated with this particular file typ...
Definition: pnmFileType.h:44
get_extension
Returns the nth possible filename extension associated with this particular file type,...
Definition: pnmFileType.h:44
virtual bool matches_magic_number(const std::string &magic_number) const
Returns true if the indicated "magic number" byte stream (the initial few bytes read from the file) m...
Definition: pnmFileType.cxx:86
This is an abstract base class that defines the interface for reading image files of various types.
Definition: pnmReader.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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22