Panda3D
 All Classes Functions Variables Enumerations
pnmFileTypeSGI.h
1 // Filename: pnmFileTypeSGI.h
2 // Created by: drose (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 PNMFILETYPESGI_H
16 #define PNMFILETYPESGI_H
17 
18 #include "pandabase.h"
19 
20 #ifdef HAVE_SGI_RGB
21 
22 #include "pnmFileType.h"
23 #include "pnmReader.h"
24 #include "pnmWriter.h"
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : PNMFileTypeSGI
28 // Description : For reading and writing SGI RGB files.
29 ////////////////////////////////////////////////////////////////////
30 class EXPCL_PANDA_PNMIMAGETYPES PNMFileTypeSGI : public PNMFileType {
31 public:
32  PNMFileTypeSGI();
33 
34  virtual string get_name() const;
35 
36  virtual int get_num_extensions() const;
37  virtual string get_extension(int n) const;
38  virtual string get_suggested_extension() const;
39 
40  virtual bool has_magic_number() const;
41  virtual bool matches_magic_number(const string &magic_number) const;
42 
43  virtual PNMReader *make_reader(istream *file, bool owns_file = true,
44  const string &magic_number = string());
45  virtual PNMWriter *make_writer(ostream *file, bool owns_file = true);
46 
47 public:
48  class Reader : public PNMReader {
49  public:
50  Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number);
51  virtual ~Reader();
52 
53  virtual bool supports_read_row() const;
54  virtual bool read_row(xel *array, xelval *alpha, int x_size, int y_size);
55 
56  typedef struct {
57  long start; /* offset in file */
58  long length; /* length of compressed scanline */
59  } TabEntry;
60 
61  private:
62  TabEntry *table;
63  long table_start;
64  int current_row;
65  int bpc;
66  };
67 
68  class Writer : public PNMWriter {
69  public:
70  Writer(PNMFileType *type, ostream *file, bool owns_file);
71  virtual ~Writer();
72 
73  virtual bool supports_write_row() const;
74  virtual bool write_header();
75  virtual bool write_row(xel *array, xelval *alpha);
76 
77  typedef struct {
78  long start; /* offset in file */
79  long length; /* length of compressed scanline */
80  } TabEntry;
81 
82  typedef short ScanElem;
83  typedef struct {
84  ScanElem * data;
85  long length;
86  } ScanLine;
87 
88  private:
89  TabEntry &Table(int chan) {
90  return table[chan * _y_size + current_row];
91  }
92 
93  void write_rgb_header(const char *imagename);
94  void write_table();
95  void write_channels(ScanLine channel[], void (*put)(ostream *, short));
96  void build_scanline(ScanLine output[], xel *row_data, xelval *alpha_data);
97  ScanElem *compress(ScanElem *temp, ScanLine &output);
98  int rle_compress(ScanElem *inbuf, int size);
99 
100  TabEntry *table;
101  long table_start;
102  int current_row;
103  int bpc;
104  int dimensions;
105  int new_maxval;
106 
107  ScanElem *rletemp;
108  };
109 
110 
111  // The TypedWritable interface follows.
112 public:
113  static void register_with_read_factory();
114 
115 protected:
116  static TypedWritable *make_PNMFileTypeSGI(const FactoryParams &params);
117 
118 public:
119  static TypeHandle get_class_type() {
120  return _type_handle;
121  }
122  static void init_type() {
123  PNMFileType::init_type();
124  register_type(_type_handle, "PNMFileTypeSGI",
125  PNMFileType::get_class_type());
126  }
127  virtual TypeHandle get_type() const {
128  return get_class_type();
129  }
130  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
131 
132 private:
133  static TypeHandle _type_handle;
134 };
135 
136 #endif // HAVE_SGI_RGB
137 
138 #endif
139 
140 
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 "magic number" byte stream (the initial few bytes read from the file) m...