00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef PNMFILETYPESGI_H
00016 #define PNMFILETYPESGI_H
00017
00018 #include "pandabase.h"
00019
00020 #ifdef HAVE_SGI_RGB
00021
00022 #include "pnmFileType.h"
00023 #include "pnmReader.h"
00024 #include "pnmWriter.h"
00025
00026
00027
00028
00029
00030 class EXPCL_PANDA_PNMIMAGETYPES PNMFileTypeSGI : public PNMFileType {
00031 public:
00032 PNMFileTypeSGI();
00033
00034 virtual string get_name() const;
00035
00036 virtual int get_num_extensions() const;
00037 virtual string get_extension(int n) const;
00038 virtual string get_suggested_extension() const;
00039
00040 virtual bool has_magic_number() const;
00041 virtual bool matches_magic_number(const string &magic_number) const;
00042
00043 virtual PNMReader *make_reader(istream *file, bool owns_file = true,
00044 const string &magic_number = string());
00045 virtual PNMWriter *make_writer(ostream *file, bool owns_file = true);
00046
00047 public:
00048 class Reader : public PNMReader {
00049 public:
00050 Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number);
00051 virtual ~Reader();
00052
00053 virtual bool supports_read_row() const;
00054 virtual bool read_row(xel *array, xelval *alpha, int x_size, int y_size);
00055
00056 typedef struct {
00057 long start;
00058 long length;
00059 } TabEntry;
00060
00061 private:
00062 TabEntry *table;
00063 long table_start;
00064 int current_row;
00065 int bpc;
00066 };
00067
00068 class Writer : public PNMWriter {
00069 public:
00070 Writer(PNMFileType *type, ostream *file, bool owns_file);
00071 virtual ~Writer();
00072
00073 virtual bool supports_write_row() const;
00074 virtual bool write_header();
00075 virtual bool write_row(xel *array, xelval *alpha);
00076
00077 typedef struct {
00078 long start;
00079 long length;
00080 } TabEntry;
00081
00082 typedef short ScanElem;
00083 typedef struct {
00084 ScanElem * data;
00085 long length;
00086 } ScanLine;
00087
00088 private:
00089 TabEntry &Table(int chan) {
00090 return table[chan * _y_size + current_row];
00091 }
00092
00093 void write_rgb_header(const char *imagename);
00094 void write_table();
00095 void write_channels(ScanLine channel[], void (*put)(ostream *, short));
00096 void build_scanline(ScanLine output[], xel *row_data, xelval *alpha_data);
00097 ScanElem *compress(ScanElem *temp, ScanLine &output);
00098 int rle_compress(ScanElem *inbuf, int size);
00099
00100 TabEntry *table;
00101 long table_start;
00102 int current_row;
00103 int bpc;
00104 int dimensions;
00105 int new_maxval;
00106
00107 ScanElem *rletemp;
00108 };
00109
00110
00111
00112 public:
00113 static void register_with_read_factory();
00114
00115 protected:
00116 static TypedWritable *make_PNMFileTypeSGI(const FactoryParams ¶ms);
00117
00118 public:
00119 static TypeHandle get_class_type() {
00120 return _type_handle;
00121 }
00122 static void init_type() {
00123 PNMFileType::init_type();
00124 register_type(_type_handle, "PNMFileTypeSGI",
00125 PNMFileType::get_class_type());
00126 }
00127 virtual TypeHandle get_type() const {
00128 return get_class_type();
00129 }
00130 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00131
00132 private:
00133 static TypeHandle _type_handle;
00134 };
00135
00136 #endif // HAVE_SGI_RGB
00137
00138 #endif
00139
00140