Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/pnmimagetypes/pnmFileTypeSGI.h

Go to the documentation of this file.
00001 // Filename: pnmFileTypeSGI.h
00002 // Created by:  drose (17Jun00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef PNMFILETYPESGI_H
00020 #define PNMFILETYPESGI_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "pnmFileType.h"
00025 #include "pnmReader.h"
00026 #include "pnmWriter.h"
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //       Class : PNMFileTypeSGI
00030 // Description : For reading and writing SGI RGB files.
00031 ////////////////////////////////////////////////////////////////////
00032 class EXPCL_PANDA PNMFileTypeSGI : public PNMFileType {
00033 public:
00034   PNMFileTypeSGI();
00035 
00036   virtual string get_name() const;
00037 
00038   virtual int get_num_extensions() const;
00039   virtual string get_extension(int n) const;
00040   virtual string get_suggested_extension() const;
00041 
00042   virtual bool has_magic_number() const;
00043   virtual bool matches_magic_number(const string &magic_number) const;
00044 
00045   virtual PNMReader *make_reader(istream *file, bool owns_file = true,
00046                                  const string &magic_number = string());
00047   virtual PNMWriter *make_writer(ostream *file, bool owns_file = true);
00048 
00049 public:
00050   class Reader : public PNMReader {
00051   public:
00052     Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number);
00053     virtual ~Reader();
00054 
00055     virtual bool supports_read_row() const;
00056     virtual bool read_row(xel *array, xelval *alpha);
00057 
00058     typedef struct {
00059       long start;     /* offset in file */
00060       long length;    /* length of compressed scanline */
00061     } TabEntry;
00062 
00063   private:
00064     TabEntry *table;
00065     long table_start;
00066     int current_row;
00067     int bpc;
00068   };
00069 
00070   class Writer : public PNMWriter {
00071   public:
00072     Writer(PNMFileType *type, ostream *file, bool owns_file);
00073     virtual ~Writer();
00074 
00075     virtual bool supports_write_row() const;
00076     virtual bool write_header();
00077     virtual bool write_row(xel *array, xelval *alpha);
00078 
00079     typedef struct {
00080       long start;     /* offset in file */
00081       long length;    /* length of compressed scanline */
00082     } TabEntry;
00083 
00084     typedef short ScanElem;
00085     typedef struct {
00086       ScanElem *  data;
00087       long        length;
00088     } ScanLine;
00089 
00090   private:
00091     TabEntry &Table(int chan) {
00092       return table[chan * _y_size + current_row];
00093     }
00094 
00095     void write_rgb_header(const char *imagename);
00096     void write_table();
00097     void write_channels(ScanLine channel[], void (*put)(ostream *, short));
00098     void build_scanline(ScanLine output[], xel *row_data, xelval *alpha_data);
00099     ScanElem *compress(ScanElem *temp, ScanLine &output);
00100     int rle_compress(ScanElem *inbuf, int size);
00101 
00102     TabEntry *table;
00103     long table_start;
00104     int current_row;
00105     int bpc;
00106     int dimensions;
00107     int new_maxval;
00108 
00109     ScanElem *rletemp;
00110   };
00111 
00112 
00113   // The TypedWritable interface follows.
00114 public:
00115   static void register_with_read_factory();
00116 
00117 protected:
00118   static TypedWritable *make_PNMFileTypeSGI(const FactoryParams &params);
00119 
00120 public:
00121   static TypeHandle get_class_type() {
00122     return _type_handle;
00123   }
00124   static void init_type() {
00125     PNMFileType::init_type();
00126     register_type(_type_handle, "PNMFileTypeSGI",
00127                   PNMFileType::get_class_type());
00128   }
00129   virtual TypeHandle get_type() const {
00130     return get_class_type();
00131   }
00132   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00133 
00134 private:
00135   static TypeHandle _type_handle;
00136 };
00137 
00138 #endif
00139 
00140 

Generated on Fri May 2 00:43:20 2003 for Panda by doxygen1.3