Files
OpenSceneGraph/src/osgDB/MimeTypes.cpp
Robert Osfield 38b02a26a9 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"
"
2009-04-09 14:00:16 +00:00

128 lines
3.9 KiB
C++

/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
const char* builtinMimeTypeExtMappings[] =
{
"application/dxf","dxf",
"application/gnutar","tgz",
"application/pdf","pdf",
"application/plain","text",
"application/postscript","ps",
"application/x-bzip","bz",
"application/x-bzip2","bz2",
"application/x-compressed","zip",
"application/x-gzip","gz",
"application/x-inventor","iv",
"application/x-javascript","js",
"application/xml","xml",
"application/x-tar","tar",
"application/x-vrml","wrl",
"application/x-world","wrl",
"application/x-zip-compressed","zip",
"application/zip","zip",
"drawing/x-dwf(old)","dwf",
"image/bmp","bmp",
"image/cmu-raster","ras",
"image/fif","fif",
"image/florian","flo",
"image/g3fax","g3",
"image/gif","gif",
"image/ief","ief",
"image/jpeg","jpg",
"image/jutvision","jut",
"image/naplps","nap",
"image/naplps","naplps",
"image/pict","pic",
"image/pjpeg","jpg",
"image/png","png",
"image/tiff","tif",
"image/vasa","mcf",
"image/vnd.dwg","dxf",
"image/vnd.fpx","fpx",
"image/vnd.net-fpx","fpx",
"image/vnd.rn-realflash","rf",
"image/vnd.rn-realpix","rp",
"image/vnd.wap.wbmp","wbmp",
"image/vnd.xiff","xif",
"image/xbm","xbm",
"image/x-cmu-raster","ras",
"image/x-dwg","dxf",
"image/x-icon","ico",
"image/x-jg","art",
"image/x-jps","jps",
"image/x-niff","nif",
"image/x-pcx","pcx",
"image/x-pict","pct",
"image/xpm","xpm",
"image/x-portable-anymap","pnm",
"image/x-portable-bitmap","pbm",
"image/x-portable-graymap","pgm",
"image/x-portable-greymap","pgm",
"image/x-portable-pixmap","ppm",
"image/x-quicktime","qif",
"image/x-rgb","rgb",
"image/x-tiff","tif",
"image/x-windows-bmp","bmp",
"image/x-xbitmap","xbm",
"image/x-xbm","xbm",
"image/x-xpixmap","xpm",
"image/x-xwd","xwd",
"image/x-xwindowdump","xwd",
"i-world/i-vrml","ivr",
"model/iges","igs",
"model/vnd.dwf","dwf",
"model/vrml","wrl",
"model/x-pov","pov",
"multipart/x-gzip","gzip",
"multipart/x-ustar","ustar",
"multipart/x-zip","zip",
"video/animaflex","afl",
"video/avi","avi",
"video/avs-video","avs",
"video/dl","dl",
"video/fli","fli",
"video/gl","gl",
"video/mpeg","mpg",
"video/msvideo","avi",
"video/quicktime","qt",
"video/vdo","vdo",
"video/vivo","viv",
"video/vnd.rn-realvideo","rv",
"video/vnd.vivo","viv",
"video/vosaic","vos",
"video/x-amt-demorun","xdr",
"video/x-amt-showrun","xsr",
"video/x-atomic3d-feature","fmf",
"video/x-dl","dl",
"video/x-dv","dv",
"video/x-fli","fli",
"video/x-gl","gl",
"video/x-isvideo","isu",
"video/x-motion-jpeg","mjpg",
"video/x-mpeg","mp3",
"video/x-mpeq2a","mp2",
"video/x-ms-asf","asf",
"video/x-ms-asf-plugin","asx",
"video/x-msvideo","avi",
"video/x-qtc","qtc",
"video/x-scm","scm",
"video/x-sgi-movie","movie",
"windows/metafile","wmf",
"xgl/drawing","xgz",
"xgl/movie","xmz",
"x-world/x-3dmf","3dm",
"x-world/x-svr","svr",
"x-world/x-vrml","wrl",
"x-world/x-vrt","vrt",
"" // end of list
};