Panda3D
 All Classes Functions Variables Enumerations
pnmFileTypeJPG.h
1 // Filename: pnmFileTypeJPG.h
2 // Created by: mike (17Jun00)
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 #ifndef PNMFILETYPEJPG_H
16 #define PNMFILETYPEJPG_H
17 
18 #include "pandabase.h"
19 
20 #ifdef HAVE_JPEG
21 
22 #include "pnmFileType.h"
23 #include "pnmReader.h"
24 #include "pnmWriter.h"
25 
26 #if defined(_WIN32)
27 #ifndef WIN32_LEAN_AND_MEAN
28 #define WIN32_LEAN_AND_MEAN 1
29 #endif
30 #include <windows.h> // we need to include this before jpeglib.
31 #endif
32 
33 #ifdef HAVE_PNG
34 // If we are going to be including png.h (in the unrelated file
35 // pnmFileTypePNG.h), be sure to include it before including setjmp.h.
36 // Ugly hack due to png weirdness with setjmp.
37 #include <png.h>
38 #endif
39 
40 
41 extern "C" {
42 #include <stdio.h> // jpeglib requires this to be included first.
43 #include <jpeglib.h>
44 #include <setjmp.h>
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Class : PNMFileTypeJPG
49 // Description : For reading and writing Jpeg files.
50 ////////////////////////////////////////////////////////////////////
51 class EXPCL_PANDA_PNMIMAGETYPES PNMFileTypeJPG : public PNMFileType {
52 public:
53  PNMFileTypeJPG();
54 
55  virtual string get_name() const;
56 
57  virtual int get_num_extensions() const;
58  virtual string get_extension(int n) const;
59  virtual string get_suggested_extension() const;
60 
61  virtual bool has_magic_number() const;
62  virtual bool matches_magic_number(const string &magic_number) const;
63 
64  virtual PNMReader *make_reader(istream *file, bool owns_file = true,
65  const string &magic_number = string());
66  virtual PNMWriter *make_writer(ostream *file, bool owns_file = true);
67 
68 public:
69  class Reader : public PNMReader {
70  public:
71  Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number);
72  ~Reader();
73 
74  virtual void prepare_read();
75  virtual int read_data(xel *array, xelval *alpha);
76 
77  private:
78  struct jpeg_decompress_struct _cinfo;
79  struct my_error_mgr {
80  struct jpeg_error_mgr pub;
81  jmp_buf setjmp_buffer;
82  };
83  typedef struct my_error_mgr *_my_error_ptr;
84  struct my_error_mgr _jerr;
85  unsigned long pos;
86 
87  unsigned long offBits;
88 
89  unsigned short cBitCount;
90  int indexed;
91  int classv;
92 
93  pixval R[256]; /* reds */
94  pixval G[256]; /* greens */
95  pixval B[256]; /* blues */
96 
97  bool _is_valid;
98  };
99 
100  class Writer : public PNMWriter {
101  public:
102  Writer(PNMFileType *type, ostream *file, bool owns_file);
103 
104  virtual int write_data(xel *array, xelval *alpha);
105  };
106 
107 
108  // The TypedWritable interface follows.
109 public:
110  static void register_with_read_factory();
111 
112 protected:
113  static TypedWritable *make_PNMFileTypeJPG(const FactoryParams &params);
114 
115 public:
116  static TypeHandle get_class_type() {
117  return _type_handle;
118  }
119  static void init_type() {
120  PNMFileType::init_type();
121  register_type(_type_handle, "PNMFileTypeJPG",
122  PNMFileType::get_class_type());
123  }
124  virtual TypeHandle get_type() const {
125  return get_class_type();
126  }
127  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
128 
129 private:
130  static TypeHandle _type_handle;
131 };
132 
133 #endif // HAVE_JPEG
134 
135 #endif
136 
virtual string get_extension(int n) const
Returns the nth possible filename extension associated with this particular file type, without a leading dot.
Definition: pnmFileType.cxx:62
virtual PNMWriter * make_writer(ostream *file, bool owns_file=true)
Allocates and returns a new PNMWriter suitable for reading from this file type, if possible...
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition: pnmFileType.h:35
virtual int get_num_extensions() const
Returns the number of different possible filename extensions associated with this particular file typ...
Definition: pnmFileType.cxx:50
virtual PNMReader * make_reader(istream *file, bool owns_file=true, const string &magic_number=string())
Allocates and returns a new PNMReader suitable for reading from this file type, if possible...
virtual string get_suggested_extension() const
Returns a suitable filename extension (without a leading dot) to suggest for files of this type...
Definition: pnmFileType.cxx:75
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:89
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
This is an abstract base class that defines the interface for writing image files of various types...
Definition: pnmWriter.h:31
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual bool matches_magic_number(const string &magic_number) const
Returns true if the indicated &quot;magic number&quot; byte stream (the initial few bytes read from the file) m...