diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index 2b02051cb..6a1b42a13 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -159,11 +159,15 @@ Registry::Registry() addFileExtensionAlias("tiff", "qt"); addFileExtensionAlias("gif", "qt"); addFileExtensionAlias("png", "qt"); + addFileExtensionAlias("psd", "qt"); + addFileExtensionAlias("rgb", "qt"); + addFileExtensionAlias("tga", "qt"); addFileExtensionAlias("mov", "qt"); addFileExtensionAlias("avi", "qt"); addFileExtensionAlias("mpg", "qt"); addFileExtensionAlias("mpv", "qt"); addFileExtensionAlias("dv", "qt"); + addFileExtensionAlias("mp4", "qt"); #else addFileExtensionAlias("jpg", "jpeg"); addFileExtensionAlias("jpe", "jpeg"); @@ -245,6 +249,89 @@ static osg::ApplicationUsageProxy Registry_e0(osg::ApplicationUsage::ENVIRONMENT static osg::ApplicationUsageProxy Registry_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_FILE_PATH [;path]..","Paths for locating datafiles"); #endif +#if defined(__APPLE__) + +//Executable packages should be able to load file resources from inside the packages. +//These resources should be stored in YourProgram.app/Contents/Resources, and so +//should the path list for the data files should include that path by default. +#include + +void Registry::initDataFilePathList() +{ + + FilePathList filepath; + + // + // set up data file paths + // + char *ptr; + + if( (ptr = getenv( "OSG_FILE_PATH" )) ) + { + //notify(DEBUG_INFO) << "OSG_FILE_PATH("< +#include #include "QTtexture.h" #include "QuicktimeImageStream.h" + using namespace osg; + + class ReaderWriterQT : public osgDB::ReaderWriter { public: @@ -32,6 +36,7 @@ class ReaderWriterQT : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"mov") || osgDB::equalCaseInsensitive(extension,"mpg") || osgDB::equalCaseInsensitive(extension,"mpv") || + osgDB::equalCaseInsensitive(extension,"mp4") || osgDB::equalCaseInsensitive(extension,"dv"); } @@ -44,13 +49,13 @@ class ReaderWriterQT : public osgDB::ReaderWriter osgDB::equalCaseInsensitive(extension,"jpg") || osgDB::equalCaseInsensitive(extension,"jpeg") || osgDB::equalCaseInsensitive(extension,"tif") || - osgDB::equalCaseInsensitive(extension,"tiff") || - osgDB::equalCaseInsensitive(extension,"pict") || + osgDB::equalCaseInsensitive(extension,"tiff") || osgDB::equalCaseInsensitive(extension,"gif") || osgDB::equalCaseInsensitive(extension,"png") || osgDB::equalCaseInsensitive(extension,"pict") || osgDB::equalCaseInsensitive(extension,"pct") || osgDB::equalCaseInsensitive(extension,"tga") || + osgDB::equalCaseInsensitive(extension,"psd") || acceptsMovieExtension(extension); } @@ -120,8 +125,9 @@ class ReaderWriterQT : public osgDB::ReaderWriter int i, j; // swizzle entire image in-place + unsigned char r, g, b, a; for (i=0; isetFileName(fileName.c_str()); @@ -188,6 +196,199 @@ class ReaderWriterQT : public osgDB::ReaderWriter notify(INFO) << "image read ok "< osFileTypes + std::map extmap; + + extmap.insert(std::pair("jpg", kQTFileTypeJPEG)); + extmap.insert(std::pair("jpeg", kQTFileTypeJPEG)); + extmap.insert(std::pair("bmp", kQTFileTypeBMP)); + extmap.insert(std::pair("tif", kQTFileTypeTIFF)); + extmap.insert(std::pair("tiff", kQTFileTypeTIFF)); + extmap.insert(std::pair("png", kQTFileTypePNG)); + extmap.insert(std::pair("gif", kQTFileTypeGIF)); + extmap.insert(std::pair("psd", kQTFileTypePhotoShop)); + // extmap.insert(std::pair("tga", kQTFileTypeTargaImage)); + extmap.insert(std::pair("sgi", kQTFileTypeSGIImage)); + extmap.insert(std::pair("rgb", kQTFileTypeSGIImage)); + extmap.insert(std::pair("rgba", kQTFileTypeSGIImage)); + + std::map::iterator cur = extmap.find(ext); + + // can not handle this type of file, perhaps a movie? + if (cur == extmap.end()) + return WriteResult::FILE_NOT_HANDLED; + + OSType desiredType = cur->second; + GraphicsExportComponent geComp = NULL; + + OSErr err = OpenADefaultComponent(GraphicsExporterComponentType, desiredType, &geComp); + + if (err != noErr) { + osg::notify(osg::WARN) << "ReaderWriterQT: could not open Graphics epxorter for type " << ext << ", Err: " << err << std::endl; + return WriteResult::FILE_NOT_HANDLED; + } + + GWorldPtr gw = NULL; + + // we are converting the images back to 32bit, it seems, that quicktime can't handle others + + unsigned long desiredPixelFormat = k32ARGBPixelFormat; + + + + // we need to swizzle the colours again :) + unsigned int numBytes = img.computeNumComponents(img.getPixelFormat()); + + unsigned int buffWidth = img.s(); + unsigned int buffHeight = img.t(); + char * pixels = (char*) malloc(buffHeight * buffWidth * 4); + + + + const unsigned char *srcp = img.data(); + char *dstp=pixels; + unsigned int i, j; + for (i=0; i(fileName.c_str()) ); + if (fileSpec == NULL) { + osg::notify(osg::WARN) << "ReaderWriterQT: could not get FSSpec" << std::endl; + throw err; + } + + err = GraphicsExportSetInputGWorld(geComp, gw); + if (err != noErr) { + osg::notify(osg::WARN) << "ReaderWriterQT: could not set input gworld for type " << ext << ", Err: " << err << std::endl; + throw err; + } + + err = GraphicsExportSetOutputFile(geComp, fileSpec); + if (err != noErr) { + osg::notify(osg::WARN) << "ReaderWriterQT: could not set output file for type " << ext << ", Err: " << err << std::endl; + throw err; + } + + // Set the compression quality (needed for JPEG, not necessarily for other formats) + if (desiredType == kQTFileTypeJPEG) { + err = GraphicsExportSetCompressionQuality(geComp, codecLosslessQuality); + if (err != noErr) { + osg::notify(osg::WARN) << "ReaderWriterQT: could not set compression for type " << ext << ", Err: " << err << std::endl; + throw err; + } + } + + // do the export + err = GraphicsExportDoExport(geComp, NULL); + if (err != noErr) { + osg::notify(osg::WARN) << "ReaderWriterQT: could not save file for type " << ext << ", Err: " << err << std::endl; + throw err; + } + + if (geComp != NULL) + CloseComponent(geComp); + + DisposeGWorld (gw); + if (fileSpec != NULL ) free(fileSpec); + if (pixels) free(pixels); + + return WriteResult::FILE_SAVED; + } + + + catch (...) { + + if (geComp != NULL) CloseComponent(geComp); + if (gw != NULL) DisposeGWorld (gw); + if (fileSpec != NULL ) free(fileSpec); + if (pixels) free(pixels); + + return WriteResult::ERROR_IN_WRITING_FILE; + } + + + } + + };