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

panda/src/pnmimagetypes/pnmFileTypeBMP.cxx

Go to the documentation of this file.
00001 // Filename: pnmFileTypeBMP.cxx
00002 // Created by:  drose (19Jun00)
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 "pnmFileTypeBMP.h"
00020 #include "config_pnmimagetypes.h"
00021 
00022 #include "pnmFileTypeRegistry.h"
00023 #include "bamReader.h"
00024 
00025 static const char * const extensions_bmp[] = {
00026   "bmp"
00027 };
00028 static const int num_extensions_bmp = sizeof(extensions_bmp) / sizeof(const char *);
00029 
00030 TypeHandle PNMFileTypeBMP::_type_handle;
00031 
00032 ////////////////////////////////////////////////////////////////////
00033 //     Function: PNMFileTypeBMP::Constructor
00034 //       Access: Public
00035 //  Description:
00036 ////////////////////////////////////////////////////////////////////
00037 PNMFileTypeBMP::
00038 PNMFileTypeBMP() {
00039 }
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //     Function: PNMFileTypeBMP::get_name
00043 //       Access: Public, Virtual
00044 //  Description: Returns a few words describing the file type.
00045 ////////////////////////////////////////////////////////////////////
00046 string PNMFileTypeBMP::
00047 get_name() const {
00048   return "Windows BMP";
00049 }
00050 
00051 ////////////////////////////////////////////////////////////////////
00052 //     Function: PNMFileTypeBMP::get_num_extensions
00053 //       Access: Public, Virtual
00054 //  Description: Returns the number of different possible filename
00055 //               extensions associated with this particular file type.
00056 ////////////////////////////////////////////////////////////////////
00057 int PNMFileTypeBMP::
00058 get_num_extensions() const {
00059   return num_extensions_bmp;
00060 }
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //     Function: PNMFileTypeBMP::get_extension
00064 //       Access: Public, Virtual
00065 //  Description: Returns the nth possible filename extension
00066 //               associated with this particular file type, without a
00067 //               leading dot.
00068 ////////////////////////////////////////////////////////////////////
00069 string PNMFileTypeBMP::
00070 get_extension(int n) const {
00071   nassertr(n >= 0 && n < num_extensions_bmp, string());
00072   return extensions_bmp[n];
00073 }
00074 
00075 ////////////////////////////////////////////////////////////////////
00076 //     Function: PNMFileTypeBMP::get_suggested_extension
00077 //       Access: Public, Virtual
00078 //  Description: Returns a suitable filename extension (without a
00079 //               leading dot) to suggest for files of this type, or
00080 //               empty string if no suggestions are available.
00081 ////////////////////////////////////////////////////////////////////
00082 string PNMFileTypeBMP::
00083 get_suggested_extension() const {
00084   return "bmp";
00085 }
00086 
00087 ////////////////////////////////////////////////////////////////////
00088 //     Function: PNMFileTypeBMP::has_magic_number
00089 //       Access: Public, Virtual
00090 //  Description: Returns true if this particular file type uses a
00091 //               magic number to identify it, false otherwise.
00092 ////////////////////////////////////////////////////////////////////
00093 bool PNMFileTypeBMP::
00094 has_magic_number() const {
00095   return true;
00096 }
00097 
00098 ////////////////////////////////////////////////////////////////////
00099 //     Function: PNMFileTypeBMP::matches_magic_number
00100 //       Access: Public, Virtual
00101 //  Description: Returns true if the indicated "magic number" byte
00102 //               stream (the initial few bytes read from the file)
00103 //               matches this particular file type, false otherwise.
00104 ////////////////////////////////////////////////////////////////////
00105 bool PNMFileTypeBMP::
00106 matches_magic_number(const string &magic_number) const {
00107   nassertr(magic_number.size() >= 2, false);
00108   return (magic_number.substr(0, 2) == "BM");
00109 }
00110 
00111 ////////////////////////////////////////////////////////////////////
00112 //     Function: PNMFileTypeBMP::make_reader
00113 //       Access: Public, Virtual
00114 //  Description: Allocates and returns a new PNMReader suitable for
00115 //               reading from this file type, if possible.  If reading
00116 //               from this file type is not supported, returns NULL.
00117 ////////////////////////////////////////////////////////////////////
00118 PNMReader *PNMFileTypeBMP::
00119 make_reader(istream *file, bool owns_file, const string &magic_number) {
00120   init_pnm();
00121   return new Reader(this, file, owns_file, magic_number);
00122 }
00123 
00124 ////////////////////////////////////////////////////////////////////
00125 //     Function: PNMFileTypeBMP::make_writer
00126 //       Access: Public, Virtual
00127 //  Description: Allocates and returns a new PNMWriter suitable for
00128 //               reading from this file type, if possible.  If writing
00129 //               files of this type is not supported, returns NULL.
00130 ////////////////////////////////////////////////////////////////////
00131 PNMWriter *PNMFileTypeBMP::
00132 make_writer(ostream *file, bool owns_file) {
00133   init_pnm();
00134   return new Writer(this, file, owns_file);
00135 }
00136 
00137 
00138 ////////////////////////////////////////////////////////////////////
00139 //     Function: PNMFileTypeBMP::register_with_read_factory
00140 //       Access: Public, Static
00141 //  Description: Registers the current object as something that can be
00142 //               read from a Bam file.
00143 ////////////////////////////////////////////////////////////////////
00144 void PNMFileTypeBMP::
00145 register_with_read_factory() {
00146   BamReader::get_factory()->
00147     register_factory(get_class_type(), make_PNMFileTypeBMP);
00148 }
00149 
00150 ////////////////////////////////////////////////////////////////////
00151 //     Function: PNMFileTypeBMP::make_PNMFileTypeBMP
00152 //       Access: Protected, Static
00153 //  Description: This method is called by the BamReader when an object
00154 //               of this type is encountered in a Bam file; it should
00155 //               allocate and return a new object with all the data
00156 //               read.
00157 //
00158 //               In the case of the PNMFileType objects, since these
00159 //               objects are all shared, we just pull the object from
00160 //               the registry.
00161 ////////////////////////////////////////////////////////////////////
00162 TypedWritable *PNMFileTypeBMP::
00163 make_PNMFileTypeBMP(const FactoryParams &params) {
00164   return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type());
00165 }

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