From Glenn Waldron, "Here is a first cut at the mime-type support we discussed a little while ago

(http://www.mail-archive.com/osg-users@lists.openscenegraph.org/msg23098.html)

Background: when you access a file over HTTP, you cannot rely on a file extension being present; instead the file's mime-type is conveyed in the HTTP Content-Type response header. This facility adds a mime-type-to-extension map to the registry to handle this.

There are two new osgDB::Registry functions which are pretty self-explanatory:

void addMimeTypeExtensionMapping( mime-type, extension )
ReaderWriter* getReaderWriterForMimeType( mime-type )

I also added the file osgDB/MimeTypes.cpp which houses a hard-coded list of built-in types. I took the list from here (http://www.webmaster-toolkit.com/mime-types.shtml) and then pared it down to include mostly image and video types, editing them to map to existing plugins where possible.

In addition, I updated the CURL plugin to a) install a set of built-in mime-type mappings, and b) use them to look up an extension in the event that the target filename does not have an extension.

Here is a test case. This URL pulls down a JPEG (without a file extension):
osgviewer --image "http://us.maps3.yimg.com/aerial.maps.yimg.com/ximg?v=1.8&s=256&t=a&r=1&x=0&y=0&z=2"
"
This commit is contained in:
Robert Osfield
2009-04-09 14:00:16 +00:00
parent 53a19190ce
commit 38b02a26a9
6 changed files with 213 additions and 7 deletions

View File

@@ -94,6 +94,12 @@ class OSGDB_EXPORT Registry : public osg::Referenced
* method. Lines can be commented out with an initial '#' character.*/
bool readPluginAliasConfigurationFile( const std::string& file );
/** Registers a mapping of a mime-type to an extension. A process fetching data
* over HTTP can use this facility to determine the proper ReaderWriter to use
* when there is no filename extension to rely upon.
*/
void addMimeTypeExtensionMapping(const std::string fromMimeType, const std::string toExt);
void addDotOsgWrapper(DotOsgWrapper* wrapper);
void removeDotOsgWrapper(DotOsgWrapper* wrapper);
@@ -129,6 +135,10 @@ class OSGDB_EXPORT Registry : public osg::Referenced
/** get a reader writer which handles specified extension.*/
ReaderWriter* getReaderWriterForExtension(const std::string& ext);
/** gets a reader/writer that handles the extension mapped to by one of
* the registered mime-types. */
ReaderWriter* getReaderWriterForMimeType(const std::string& mimeType);
/** get list of all registered ReaderWriters.*/
ReaderWriterList& getReaderWriterList() { return _rwList; }
@@ -492,6 +502,7 @@ class OSGDB_EXPORT Registry : public osg::Referenced
typedef std::map< std::string, osg::ref_ptr<DotOsgWrapper> > DotOsgWrapperMap;
typedef std::vector< osg::ref_ptr<DynamicLibrary> > DynamicLibraryList;
typedef std::map< std::string, std::string> ExtensionAliasMap;
typedef std::map< std::string, std::string> MimeTypeExtensionMap;
typedef std::vector< std::string> ArchiveExtensionList;
typedef std::pair<osg::ref_ptr<osg::Object>, double > ObjectTimeStampPair;
@@ -592,6 +603,9 @@ class OSGDB_EXPORT Registry : public osg::Referenced
// map to alias to extensions to plugins.
ExtensionAliasMap _extAliasMap;
// maps mime-types to extensions.
MimeTypeExtensionMap _mimeTypeExtMap;
// Utility: Removes whitespace from both ends of a string.
static std::string trim( const std::string& str );