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