From 5b7718ea45b52b7b9d8028a99d1efa718921e384 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 3 Mar 2003 11:02:35 +0000 Subject: [PATCH] Updates to the quicktime plugin from Bob Kuehne. --- src/osgDB/Registry.cpp | 9 ++++++- .../quicktime/{QTtexture.c => QTtexture.cpp} | 25 +++++++++++++------ src/osgPlugins/quicktime/QTtexture.h | 20 +++++++++++++++ src/osgPlugins/quicktime/ReaderWriterQT.cpp | 16 ++++-------- 4 files changed, 51 insertions(+), 19 deletions(-) rename src/osgPlugins/quicktime/{QTtexture.c => QTtexture.cpp} (95%) create mode 100644 src/osgPlugins/quicktime/QTtexture.h diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index 1fefb1558..622aeb578 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -65,10 +65,17 @@ Registry::Registry() addFileExtensionAlias("inta", "rgb"); addFileExtensionAlias("bw", "rgb"); +#if defined(__DARWIN_OSX__) + addFileExtensionAlias("jpg", "qt"); + addFileExtensionAlias("jpe", "qt"); + addFileExtensionAlias("jpeg", "qt"); + addFileExtensionAlias("tif", "qt"); + addFileExtensionAlias("tiff", "qt"); +#else addFileExtensionAlias("jpg", "jpeg"); addFileExtensionAlias("jpe", "jpeg"); - addFileExtensionAlias("tif", "tiff"); +#endif // remove geo to lwo alias as the new Carbon Graphics GEO format // also uses the .geo. It is still possible to load light wave .geo diff --git a/src/osgPlugins/quicktime/QTtexture.c b/src/osgPlugins/quicktime/QTtexture.cpp similarity index 95% rename from src/osgPlugins/quicktime/QTtexture.c rename to src/osgPlugins/quicktime/QTtexture.cpp index 8fc95e884..09496198d 100644 --- a/src/osgPlugins/quicktime/QTtexture.c +++ b/src/osgPlugins/quicktime/QTtexture.cpp @@ -60,6 +60,8 @@ PORTIONS OF THIS CODE ARE COPYRIGHT APPLE COMPUTER - #include // for OpenGL API #include // for OpenGL extension support +#include "QTTexture.h" + // ================================== enum // how to scale image to power of two on read if scaling @@ -189,7 +191,7 @@ static unsigned char * LoadBufferFromImageFile ( FSSpec fsspecImage, long *pBufferWidth, long *pBufferHeight, long *pBufferDepth) { unsigned char * pImageBuffer = NULL; - int scalefac, xoffs, yoffs; + int scalefac; GWorldPtr pGWorld = NULL; OSType pixelFormat; long rowStride; // length, in bytes, of a pixel row in the image @@ -255,7 +257,14 @@ static unsigned char * LoadBufferFromImageFile ( FSSpec fsspecImage, } SetRect (&rectImage, 0, 0, (short) *pBufferWidth, (short) *pBufferHeight); // l, t, r. b set image rectangle for creation of GWorld rowStride = *pBufferWidth * *pBufferDepth >> 3; // set stride in bytes width of image * pixel depth in bytes - pImageBuffer = (unsigned char *) NewPtrClear (rowStride * *pBufferHeight); // build new buffer exact size of image (stride * height) + + const long len = rowStride * *pBufferHeight; + + pImageBuffer = new unsigned char [ len ]; // build new buffer exact size of image (stride * height) + + // pImageBuffer = (unsigned char *) NewPtrClear (rowStride * *pBufferHeight); // build new buffer exact size of image (stride * height) + + if (NULL == pImageBuffer) { sprintf ( errMess, "failed to allocate image buffer"); @@ -267,7 +276,8 @@ static unsigned char * LoadBufferFromImageFile ( FSSpec fsspecImage, if (NULL == pGWorld) { sprintf ( errMess, "failed to create GWorld"); - DisposePtr ((Ptr) pImageBuffer); // dump image buffer + // DisposePtr ((Ptr) pImageBuffer); // dump image buffer + delete [] pImageBuffer; pImageBuffer = NULL; CloseComponent(giComp); return NULL; // if we failed to create gworld @@ -295,7 +305,8 @@ static unsigned char * LoadBufferFromImageFile ( FSSpec fsspecImage, DisposeGWorld (pGWorld); // dump gworld pGWorld = NULL; - DisposePtr ((Ptr) pImageBuffer); // dump image buffer + // DisposePtr ((Ptr) pImageBuffer); // dump image buffer + delete [] pImageBuffer; pImageBuffer = NULL; CloseComponent(giComp); // dump component return NULL; @@ -340,14 +351,14 @@ FSSpec *darwinPathToFSSpec (char *fname ) { unsigned char* -LoadBufferFromDarwinPath ( char *fname, long *origWidth, long *origHeight, long *origDepth, +LoadBufferFromDarwinPath ( const char *fname, long *origWidth, long *origHeight, long *origDepth, long *buffWidth, long *buffHeight, long *buffDepth) { FSSpec *fs; - sprintf ( errMess, ""); + sprintf ( errMess, "" ); - fs=darwinPathToFSSpec ( fname ); + fs=darwinPathToFSSpec ( const_cast( fname ) ); if (fs == NULL) { return NULL; diff --git a/src/osgPlugins/quicktime/QTtexture.h b/src/osgPlugins/quicktime/QTtexture.h new file mode 100644 index 000000000..0836a8f01 --- /dev/null +++ b/src/osgPlugins/quicktime/QTtexture.h @@ -0,0 +1,20 @@ +#ifndef __QTTEXTURE_H__ +#define __QTTEXTURE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +unsigned char* +LoadBufferFromDarwinPath ( const char *fname, long *origWidth, + long *origHeight, long *origDepth, + long *buffWidth, long *buffHeight, long *buffDepth); + +char * +QTfailureMessage(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/osgPlugins/quicktime/ReaderWriterQT.cpp b/src/osgPlugins/quicktime/ReaderWriterQT.cpp index f2132ed53..b8fd3975a 100644 --- a/src/osgPlugins/quicktime/ReaderWriterQT.cpp +++ b/src/osgPlugins/quicktime/ReaderWriterQT.cpp @@ -16,12 +16,7 @@ # define SEEK_SET 0 #endif -extern "C" unsigned char* -LoadBufferFromDarwinPath ( const char *fname, long *origWidth, long *origHeight, long *origDepth, - long *buffWidth, long *buffHeight, long *buffDepth); - -extern "C" char * -QTfailureMessage(void); +#include "QTTexture.h" using namespace osg; @@ -149,17 +144,16 @@ class ReaderWriterQT : public osgDB::ReaderWriter } } } - - // DisposePtr ((Ptr) pixels); - + Image* image = new Image(); image->setFileName(fileName.c_str()); image->setImage(buffWidth,buffHeight,1, buffDepth >> 3, pixelFormat, GL_UNSIGNED_BYTE, - pixels ); - + pixels, + osg::Image::USE_NEW_DELETE ); + notify(INFO) << "image read ok "<