00001 // Filename: pnmFileTypeJPG2000.cxx 00002 // Created by: mike (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 "pnmFileTypeJPG2000.h" 00020 #include "config_pnmimagetypes.h" 00021 00022 #include "pnmFileTypeRegistry.h" 00023 #include "bamReader.h" 00024 00025 static const char * const extensions_jpg2000[] = { 00026 "JP2","JPC" 00027 }; 00028 static const int num_extensions_jpg2000 = sizeof(extensions_jpg2000) / sizeof(const char *); 00029 00030 TypeHandle PNMFileTypeJPG2000::_type_handle; 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Function: PNMFileTypeJPG2000::Constructor 00034 // Access: Public 00035 // Description: 00036 //////////////////////////////////////////////////////////////////// 00037 PNMFileTypeJPG2000:: 00038 PNMFileTypeJPG2000() { 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: PNMFileTypeJPG2000::get_name 00043 // Access: Public, Virtual 00044 // Description: Returns a few words describing the file type. 00045 //////////////////////////////////////////////////////////////////// 00046 string PNMFileTypeJPG2000:: 00047 get_name() const { 00048 return "JPEG 2000"; 00049 } 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: PNMFileTypeJPG2000::get_num_extensions 00053 // Access: Public, Virtual 00054 // Description: Returns the number of different possible filename 00055 // extensions_jpg2000 associated with this particular file type. 00056 //////////////////////////////////////////////////////////////////// 00057 int PNMFileTypeJPG2000:: 00058 get_num_extensions() const { 00059 return num_extensions_jpg2000; 00060 } 00061 00062 //////////////////////////////////////////////////////////////////// 00063 // Function: PNMFileTypeJPG2000::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 PNMFileTypeJPG2000:: 00070 get_extension(int n) const { 00071 nassertr(n >= 0 && n < num_extensions_jpg2000, string()); 00072 return extensions_jpg2000[n]; 00073 } 00074 00075 //////////////////////////////////////////////////////////////////// 00076 // Function: PNMFileTypeJPG2000::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 PNMFileTypeJPG2000:: 00083 get_suggested_extension() const { 00084 return "JP2"; 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: PNMFileTypeJPG2000::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 PNMFileTypeJPG2000:: 00094 has_magic_number() const { 00095 return true; 00096 } 00097 00098 //////////////////////////////////////////////////////////////////// 00099 // Function: PNMFileTypeJPG2000::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 PNMFileTypeJPG2000:: 00106 matches_magic_number(const string &magic_number) const { 00107 nassertr(magic_number.size() >= 2, false); 00108 return ((char)magic_number[0] == (char)0xff && 00109 (char)magic_number[1] == (char)0xd8); 00110 } 00111 00112 //////////////////////////////////////////////////////////////////// 00113 // Function: PNMFileTypeJPG2000::make_reader 00114 // Access: Public, Virtual 00115 // Description: Allocates and returns a new PNMReader suitable for 00116 // reading from this file type, if possible. If reading 00117 // from this file type is not supported, returns NULL. 00118 //////////////////////////////////////////////////////////////////// 00119 PNMReader *PNMFileTypeJPG2000:: 00120 make_reader(istream *file, bool owns_file, const string &magic_number) { 00121 init_pnm(); 00122 return new Reader(this, file, owns_file, magic_number); 00123 } 00124 00125 //////////////////////////////////////////////////////////////////// 00126 // Function: PNMFileTypeJPG2000::make_writer 00127 // Access: Public, Virtual 00128 // Description: Allocates and returns a new PNMWriter suitable for 00129 // reading from this file type, if possible. If writing 00130 // files of this type is not supported, returns NULL. 00131 //////////////////////////////////////////////////////////////////// 00132 PNMWriter *PNMFileTypeJPG2000:: 00133 make_writer(ostream *file, bool owns_file) { 00134 init_pnm(); 00135 return new Writer(this, file, owns_file); 00136 } 00137 00138 00139 //////////////////////////////////////////////////////////////////// 00140 // Function: PNMFileTypeJPG2000::register_with_read_factory 00141 // Access: Public, Static 00142 // Description: Registers the current object as something that can be 00143 // read from a Bam file. 00144 //////////////////////////////////////////////////////////////////// 00145 void PNMFileTypeJPG2000:: 00146 register_with_read_factory() { 00147 BamReader::get_factory()-> 00148 register_factory(get_class_type(), make_PNMFileTypeJPG2000); 00149 } 00150 00151 //////////////////////////////////////////////////////////////////// 00152 // Function: PNMFileTypeJPG2000::make_PNMFileTypeJPG2000 00153 // Access: Protected, Static 00154 // Description: This method is called by the BamReader when an object 00155 // of this type is encountered in a Bam file; it should 00156 // allocate and return a new object with all the data 00157 // read. 00158 // 00159 // In the case of the PNMFileType objects, since these 00160 // objects are all shared, we just pull the object from 00161 // the registry. 00162 //////////////////////////////////////////////////////////////////// 00163 TypedWritable *PNMFileTypeJPG2000:: 00164 make_PNMFileTypeJPG2000(const FactoryParams ¶ms) { 00165 return PNMFileTypeRegistry::get_ptr()->get_type_by_handle(get_class_type()); 00166 }