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

panda/src/pnmimage/pnmReader.cxx

Go to the documentation of this file.
00001 // Filename: pnmReader.cxx
00002 // Created by:  drose (14Jun00)
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 #include "pnmReader.h"
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //     Function: PNMReader::Destructor
00023 //       Access: Public, Virtual
00024 //  Description:
00025 ////////////////////////////////////////////////////////////////////
00026 PNMReader::
00027 ~PNMReader() {
00028   if (_owns_file) {
00029     delete _file;
00030   }
00031   _file = (istream *)NULL;
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: PNMReader::read_data
00036 //       Access: Public, Virtual
00037 //  Description: Reads in an entire image all at once, storing it in
00038 //               the pre-allocated _x_size * _y_size array and alpha
00039 //               pointers.  (If the image type has no alpha channel,
00040 //               alpha is ignored.)  Returns the number of rows
00041 //               correctly read.
00042 //
00043 //               Derived classes need not override this if they
00044 //               instead provide supports_read_row() and read_row(),
00045 //               below.
00046 ////////////////////////////////////////////////////////////////////
00047 int PNMReader::
00048 read_data(xel *array, xelval *alpha) {
00049   if (!is_valid()) {
00050     return 0;
00051   }
00052 
00053   int y;
00054   for (y = 0; y < _y_size; y++) {
00055     if (!read_row(array + y * _x_size, alpha + y * _x_size)) {
00056       return y;
00057     }
00058   }
00059 
00060   return _y_size;
00061 }
00062 
00063 
00064 ////////////////////////////////////////////////////////////////////
00065 //     Function: PNMReader::supports_read_row
00066 //       Access: Public, Virtual
00067 //  Description: Returns true if this particular PNMReader is capable
00068 //               of returning the data one row at a time, via repeated
00069 //               calls to read_row().  Returns false if the only way
00070 //               to read from this file is all at once, via
00071 //               read_data().
00072 ////////////////////////////////////////////////////////////////////
00073 bool PNMReader::
00074 supports_read_row() const {
00075   return false;
00076 }
00077 
00078 ////////////////////////////////////////////////////////////////////
00079 //     Function: PNMReader::read_row
00080 //       Access: Public, Virtual
00081 //  Description: If supports_read_row(), above, returns true, this
00082 //               function may be called repeatedly to read the image,
00083 //               one horizontal row at a time, beginning from the top.
00084 //               Returns true if the row is successfully read, false
00085 //               if there is an error or end of file.
00086 ////////////////////////////////////////////////////////////////////
00087 bool PNMReader::
00088 read_row(xel *, xelval *) {
00089   return false;
00090 }
00091 
00092 
00093 ////////////////////////////////////////////////////////////////////
00094 //     Function: PNMReader::supports_stream_read
00095 //       Access: Public, Virtual
00096 //  Description: Returns true if this particular PNMReader can read
00097 //               from a general stream (including pipes, etc.), or
00098 //               false if the reader must occasionally fseek() on its
00099 //               input stream, and thus only disk streams are
00100 //               supported.
00101 ////////////////////////////////////////////////////////////////////
00102 bool PNMReader::
00103 supports_stream_read() const {
00104   return false;
00105 }

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