Panda3D
pnmFileTypeJPG.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 pnmFileTypeJPG.h
10  * @author mike
11  * @date 2000-06-17
12  */
13 
14 #ifndef PNMFILETYPEJPG_H
15 #define PNMFILETYPEJPG_H
16 
17 #include "pandabase.h"
18 
19 #ifdef HAVE_JPEG
20 
21 #include "pnmFileType.h"
22 #include "pnmReader.h"
23 #include "pnmWriter.h"
24 
25 #if defined(_WIN32)
26 #ifndef WIN32_LEAN_AND_MEAN
27 #define WIN32_LEAN_AND_MEAN 1
28 #endif
29 #include <windows.h> // we need to include this before jpeglib.
30 #endif
31 
32 #ifdef HAVE_PNG
33 // If we are going to be including png.h (in the unrelated file
34 // pnmFileTypePNG.h), be sure to include it before including setjmp.h. Ugly
35 // hack due to png weirdness with setjmp.
36 #include <png.h>
37 #endif
38 
39 // jconfig.h overrides our INLINE definition.
40 #ifdef __GNUC__
41 #pragma push_macro("INLINE")
42 #endif
43 
44 extern "C" {
45 #include <stdio.h> // jpeglib requires this to be included first.
46 #include <jpeglib.h>
47 #include <setjmp.h>
48 }
49 
50 // Restore our own INLINE definition.
51 #ifdef __GNUC__
52 #pragma pop_macro("INLINE")
53 #endif
54 
55 /**
56  * For reading and writing Jpeg files.
57  */
58 class EXPCL_PANDA_PNMIMAGETYPES PNMFileTypeJPG : public PNMFileType {
59 public:
60  PNMFileTypeJPG();
61 
62  virtual std::string get_name() const;
63 
64  virtual int get_num_extensions() const;
65  virtual std::string get_extension(int n) const;
66  virtual std::string get_suggested_extension() const;
67 
68  virtual bool has_magic_number() const;
69  virtual bool matches_magic_number(const std::string &magic_number) const;
70 
71  virtual PNMReader *make_reader(std::istream *file, bool owns_file = true,
72  const std::string &magic_number = std::string());
73  virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true);
74 
75 public:
76  class Reader : public PNMReader {
77  public:
78  Reader(PNMFileType *type, std::istream *file, bool owns_file, std::string magic_number);
79  ~Reader();
80 
81  virtual void prepare_read();
82  virtual int read_data(xel *array, xelval *alpha);
83 
84  private:
85  struct jpeg_decompress_struct _cinfo;
86  struct my_error_mgr {
87  struct jpeg_error_mgr pub;
88  jmp_buf setjmp_buffer;
89  };
90  typedef struct my_error_mgr *_my_error_ptr;
91  struct my_error_mgr _jerr;
92  bool _is_valid;
93  };
94 
95  class Writer : public PNMWriter {
96  public:
97  Writer(PNMFileType *type, std::ostream *file, bool owns_file);
98 
99  virtual int write_data(xel *array, xelval *alpha);
100  };
101 
102 
103  // The TypedWritable interface follows.
104 public:
105  static void register_with_read_factory();
106 
107 protected:
108  static TypedWritable *make_PNMFileTypeJPG(const FactoryParams &params);
109 
110 public:
111  static TypeHandle get_class_type() {
112  return _type_handle;
113  }
114  static void init_type() {
115  PNMFileType::init_type();
116  register_type(_type_handle, "PNMFileTypeJPG",
117  PNMFileType::get_class_type());
118  }
119  virtual TypeHandle get_type() const {
120  return get_class_type();
121  }
122  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
123 
124 private:
125  static TypeHandle _type_handle;
126 };
127 
128 #endif // HAVE_JPEG
129 
130 #endif
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
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition: pnmFileType.h:32
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 an abstract base class that defines the interface for reading image files of various types.
Definition: pnmReader.h:27
get_extension
Returns the nth possible filename extension associated with this particular file type,...
Definition: pnmFileType.h:44
This is an abstract base class that defines the interface for writing image files of various types.
Definition: pnmWriter.h:27
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
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 PNMWriter * make_writer(std::ostream *file, bool owns_file=true)
Allocates and returns a new PNMWriter suitable for reading from this file type, if possible.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.