00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef PNMFILETYPEJPG_H
00020 #define PNMFILETYPEJPG_H
00021
00022 #include "pandabase.h"
00023
00024 #include "pnmFileType.h"
00025 #include "pnmReader.h"
00026 #include "pnmWriter.h"
00027
00028 #if defined(_WIN32)
00029 #include <windows.h>
00030 #endif
00031
00032 extern "C" {
00033 #include <stdio.h>
00034 #include <jpeglib.h>
00035 #include <setjmp.h>
00036 }
00037
00038
00039
00040
00041
00042 class EXPCL_PANDA PNMFileTypeJPG : public PNMFileType {
00043 public:
00044 PNMFileTypeJPG();
00045
00046 virtual string get_name() const;
00047
00048 virtual int get_num_extensions() const;
00049 virtual string get_extension(int n) const;
00050 virtual string get_suggested_extension() const;
00051
00052 virtual bool has_magic_number() const;
00053 virtual bool matches_magic_number(const string &magic_number) const;
00054
00055 virtual PNMReader *make_reader(istream *file, bool owns_file = true,
00056 const string &magic_number = string());
00057 virtual PNMWriter *make_writer(ostream *file, bool owns_file = true);
00058
00059 public:
00060 class Reader : public PNMReader {
00061 public:
00062 Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number);
00063 ~Reader(void);
00064
00065 virtual int read_data(xel *array, xelval *alpha);
00066
00067 private:
00068 struct jpeg_decompress_struct _cinfo;
00069 struct my_error_mgr {
00070 struct jpeg_error_mgr pub;
00071 jmp_buf setjmp_buffer;
00072 };
00073 typedef struct my_error_mgr *_my_error_ptr;
00074 struct my_error_mgr _jerr;
00075 unsigned long pos;
00076
00077 unsigned long offBits;
00078
00079 unsigned short cBitCount;
00080 int indexed;
00081 int classv;
00082
00083 pixval R[256];
00084 pixval G[256];
00085 pixval B[256];
00086
00087 bool _is_valid;
00088 };
00089
00090 class Writer : public PNMWriter {
00091 public:
00092 Writer(PNMFileType *type, ostream *file, bool owns_file);
00093
00094 virtual int write_data(xel *array, xelval *alpha);
00095 };
00096
00097
00098
00099 public:
00100 static void register_with_read_factory();
00101
00102 protected:
00103 static TypedWritable *make_PNMFileTypeJPG(const FactoryParams ¶ms);
00104
00105 public:
00106 static TypeHandle get_class_type() {
00107 return _type_handle;
00108 }
00109 static void init_type() {
00110 PNMFileType::init_type();
00111 register_type(_type_handle, "PNMFileTypeJPG",
00112 PNMFileType::get_class_type());
00113 }
00114 virtual TypeHandle get_type() const {
00115 return get_class_type();
00116 }
00117 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00118
00119 private:
00120 static TypeHandle _type_handle;
00121 };
00122
00123 #endif
00124
00125