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:
@@ -63,6 +63,10 @@ static osg::ApplicationUsageProxy Registry_e1(osg::ApplicationUsage::ENVIRONMENT
|
||||
static osg::ApplicationUsageProxy Registry_e2(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_BUILD_KDTREES on/off","Enable/disable the automatic building of KdTrees for each loaded Geometry.");
|
||||
|
||||
|
||||
// from MimeTypes.cpp
|
||||
extern const char* builtinMimeTypeExtMappings[];
|
||||
|
||||
|
||||
class Registry::AvailableReaderWriterIterator
|
||||
{
|
||||
public:
|
||||
@@ -331,9 +335,17 @@ Registry::Registry()
|
||||
addFileExtensionAlias("pgm", "pnm");
|
||||
addFileExtensionAlias("ppm", "pnm");
|
||||
|
||||
// add built-in mime-type extension mappings
|
||||
for( int i=0; ; i+=2 )
|
||||
{
|
||||
std::string mimeType = builtinMimeTypeExtMappings[i];
|
||||
if ( mimeType.length() == 0 )
|
||||
break;
|
||||
addMimeTypeExtensionMapping( mimeType, builtinMimeTypeExtMappings[i+1] );
|
||||
}
|
||||
|
||||
// register http-protocol, so the curl can handle it, if necessary
|
||||
registerProtocol("http");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -587,6 +599,11 @@ void Registry::addFileExtensionAlias(const std::string mapExt, const std::string
|
||||
_extAliasMap[mapExt] = toExt;
|
||||
}
|
||||
|
||||
void Registry::addMimeTypeExtensionMapping(const std::string fromMimeType, const std::string toExt)
|
||||
{
|
||||
_mimeTypeExtMap[fromMimeType] = toExt;
|
||||
}
|
||||
|
||||
bool Registry::readPluginAliasConfigurationFile( const std::string& file )
|
||||
{
|
||||
std::string fileName = osgDB::findDataFile( file );
|
||||
@@ -825,6 +842,14 @@ ReaderWriter* Registry::getReaderWriterForExtension(const std::string& ext)
|
||||
|
||||
}
|
||||
|
||||
ReaderWriter* Registry::getReaderWriterForMimeType(const std::string& mimeType)
|
||||
{
|
||||
MimeTypeExtensionMap::const_iterator i = _mimeTypeExtMap.find( mimeType );
|
||||
return i != _mimeTypeExtMap.end()?
|
||||
getReaderWriterForExtension( i->second ) :
|
||||
NULL;
|
||||
}
|
||||
|
||||
struct concrete_wrapper: basic_type_wrapper
|
||||
{
|
||||
virtual ~concrete_wrapper() {}
|
||||
|
||||
Reference in New Issue
Block a user