/*============================================ SUMiscUtils::LinkListenerToControls Note: This is the same as the UReanimator method, but this will work with any broadcaster instead of just LControl. ==============================================*/ void SUMiscUtils::LinkListenerToControls( LListener *inListener, LView *inControlContainer, ResIDT inResListID) { #pragma options align=mac68k typedef struct { SInt16 numberOfItems; PaneIDT itemID[1]; } SResList, *SResListP; #pragma options align=reset StResource idList('RidL', inResListID); HLockHi(idList.mResourceH); SResListP resListP = (SResListP) *idList.mResourceH; for (SInt16 i = 0; i < resListP->numberOfItems; i++) { LPane* thePane = inControlContainer->FindPaneByID(resListP->itemID[i] ) ; LBroadcaster *theBroad = dynamic_cast<LBroadcaster*>(thePane); if (theBroad != nil) { theBroad->AddListener( inListener ); } } }
Ptr GC_MacTemporaryNewPtr(size_t size, Boolean clearMemory) { static Boolean firstTime = true; OSErr result; TemporaryMemoryHandle tempMemBlock; Ptr tempPtr = nil; tempMemBlock = (TemporaryMemoryHandle)TempNewHandle(size + sizeof(TemporaryMemoryBlock), &result); if (tempMemBlock && result == noErr) { HLockHi((Handle)tempMemBlock); tempPtr = (**tempMemBlock).data; if (clearMemory) memset(tempPtr, 0, size); tempPtr = StripAddress(tempPtr); // keep track of the allocated blocks. (**tempMemBlock).nextBlock = theTemporaryMemory; theTemporaryMemory = tempMemBlock; } # if !defined(SHARED_LIBRARY_BUILD) // install an exit routine to clean up the memory used at the end. if (firstTime) { atexit(&GC_MacFreeTemporaryMemory); firstTime = false; } # endif return tempPtr; }
void BuildLibPath( void ) { Handle searchPath; // make the search path handle // and fill it with the initial search path // use strlen neat so as to chop off trailing null! searchPath = NewHandle( strlen( INITIAL_SEARCH_PATH ) ); if( (searchPath != NULL) && ( ResError() == noErr ) ) { HLock( searchPath ); BlockMove( INITIAL_SEARCH_PATH, *searchPath, strlen( INITIAL_SEARCH_PATH ) ); HUnlock( searchPath ); // Try to get the application support folder FindFolderPath( searchPath, kApplicationSupportFolderType, FOLDER_SEARCH_PATH ); // Try to get the extensions folder FindFolderPath( searchPath, kExtensionFolderType, FOLDER_SEARCH_PATH ); // lock it out of the way, // null terminate it, overwriting the last \t, making a c string // and set LIBDIR to it HLockHi( searchPath ); (*searchPath)[ GetHandleSize( searchPath ) -1 ] = '\0'; LIBDIR = *searchPath; } }
void ofQtVideoSaver::setup( int width , int height, string movieName){ w = width; h = height; fileName = (ofToDataPath(movieName)); //pszFlatFilename = flatFileName; initializeQuicktime(); /* Load the FSSpec structure to describe the receiving file. For a description of this and related calls see http://developer.apple.com/quicktime/icefloe/dispatch004.html. ================================================================ */ #ifdef TARGET_WIN32 //FILE * pFile = NULL; //pFile = fopen (fileName.c_str(),"w"); //fclose (pFile); char fileNameStr[255]; sprintf(fileNameStr, "%s", fileName.c_str()); osErr = NativePathNameToFSSpec (fileNameStr, &fsSpec, 0); #endif #ifdef TARGET_OSX /// kill a file and make a new one if needed: FILE * pFile; pFile = fopen (fileName.c_str(),"w"); fclose (pFile); Boolean isdir; osErr = FSPathMakeRef((const UInt8*)fileName.c_str(), &fsref, &isdir); osErr = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, &fsSpec, NULL); #endif if (osErr && (osErr != fnfErr)) /* File-not-found error is ok */ { printf ("getting FSS spec failed %d\n", osErr); goto bail; } /* Step 1: Create a new, empty movie file and a movie that references that file (CreateMovieFile). ======================================================================== */ osErr = CreateMovieFile ( &fsSpec, /* FSSpec specifier */ FOUR_CHAR_CODE('TVOD'), /* file creator type, TVOD = QT player*/ smCurrentScript, /* movie script system to use */ createMovieFileDeleteCurFile /* movie file creation flags */ | createMovieFileDontCreateResFile, &sResRefNum, /* returned file ref num to data fork */ &movie /* returned handle to open empty movie*/ /* that references the created file */ ); if (osErr) { printf ("CreateMovieFile failed %d\n", osErr); goto bail; } /* Step 2: Add a new track to that movie (NewMovieTrack). ======================================================= */ track = NewMovieTrack ( movie, /* the movie to add track to */ ((long) w << 16), /* width of track in pixels (Fixed) */ FixRatio (h, 1), /* height of track in pixels (Fixed) */ kNoVolume /* default volume level */ ); osErr = GetMoviesError (); if (osErr) { printf ("NewMovieTrack failed %d\n", osErr); goto bail; } /* Step 3: Add a new media to that track (NewTrackMedia). ======================================================= */ media = NewTrackMedia ( track, /* the track to add the media to */ VideoMediaType, /* media type, e.g. SoundMediaType */ 600, /* num media time units that elapse/sec*/ NULL, /* ptr to file that holds media sampls*/ 0 /* type of ptr to media samples */ ); osErr = GetMoviesError (); if (osErr) { printf ("NewTrackMedia failed %d\n", osErr); goto bail; } /* Step 4: Add media samples to the media. ======================================== */ BeginMediaEdits (media); /* Inform the Movie Toolbox that we */ /* want to change the media samples */ /* referenced by a track's media. */ /* This opens the media container */ /* and makes it ready to receive */ /* and/or remove sample data. */ // Step 5: setup graphics port for qt movie and compression type --- /* Create a new offscreen graphics world that will hold the movie's drawing surface. draw_image() copies the image of IceFlow to this surface with varying amounts of transparency. ================================================================= */ MacSetRect (&rect, 0, 0, w, h); osErr = NewGWorld ( &pMovieGWorld, /* receives the new GWorld. */ 24, /* pixel depth in bits/pixel */ &rect, /* desired size of the GWorld. */ NULL, NULL, (GWorldFlags) 0 ); if (osErr != noErr) { printf ("NewGWorld 1 failed %d\n", osErr); goto bail; } /* Retrieve the pixel map associated with that graphics world and lock the pixel map in memory. GetMaxCompressionSize() and CompressImage() only operate on pixel maps, not graphics worlds. ===================================================================== */ pixMapHandle = GetGWorldPixMap (pMovieGWorld); if (pixMapHandle == NULL) { printf ("GetGWorldPixMap failed\n"); goto bail; } LockPixels (pixMapHandle); /* Get the maximum number of bytes required to hold an image having the specified characteristics compressed using the specified compressor. ==================================================================== */ osErr = GetMaxCompressionSize ( pixMapHandle, /* the pixel map to compress from. */ &rect, /* the image rectangle. */ 0, /* let ICM choose image bit depth. */ codecHighQuality, /* compression quality specifier. */ kRawCodecType, /* desired compression type */ // < set to RAW in case we set to a new compression type... (CompressorComponent) anyCodec, /* codec specifier. */ &lMaxCompressionSize /* receives max bytes needed for cmp. */ ); if (osErr != noErr) { printf ("GetMaxCompressionSize failed %d\n", osErr); goto bail; } /* Allocate a buffer to hold the compressed image data by creating a new handle. ===================================================================== */ hCompressedData = NewHandle (lMaxCompressionSize); if (hCompressedData == NULL) { printf ("NewHandle(%ld) failed\n", lMaxCompressionSize); goto bail; } /* Lock the handle and then dereference it to obtain a pointer to the data buffer because CompressImage() wants us to pass it a pointer, not a handle. ======================================================================= */ HLockHi (hCompressedData); pCompressedData = *hCompressedData; /* Create an image description object in memory of minimum size to pass to CompressImage(). CompressImage() will resize the memory as necessary so create it small here. ==================================================================== */ hImageDescription = (ImageDescriptionHandle) NewHandle (4); if (hImageDescription == NULL) { printf ("NewHandle(4) failed\n"); goto bail; } bSetupForRecordingMovie = true; return; bail: printf("got to bail somehows \n"); if (sResRefNum != 0) CloseMovieFile (sResRefNum); if (movie != NULL) DisposeMovie (movie); //ExitMovies (); /* Finalize Quicktime */ return; }
// -------------------------------------------------------------------------------------- void ReleaseIconDataBrowserItemData(ControlRef iconDataBrowser) { Handle itemsHandle; DataBrowserItemID *items; int itemNumber; IconDBItemDataRec *itemsData[kNumberOfRows]; UInt16 referenceCount; Boolean needRelease = false; itemsHandle = NewHandle(0); // GetDataBrowserItems will resize this for us GetDataBrowserItems(iconDataBrowser, kDataBrowserNoItem, false, kDataBrowserItemAnyState, itemsHandle); /* At this point we have the following: Handle -> Pointer -> DataBrowserItemID[] In our icon data browser, DataBrowserItemID = IconDBItemDataRec pointer So that means we have: Handle -> Pointer -> IconDBItemDataRec pointer -> IconDBItemDataRec */ HLockHi(itemsHandle); // since we're about to dereference this, we need it to stay put items = (DataBrowserItemID *)*itemsHandle; /* While this is technically unnecessary, it will save us a lot of awkward multiple dereferencings and generally make things much easier to read. */ for (itemNumber = 0; itemNumber < kNumberOfRows; itemNumber++) itemsData[itemNumber] = (IconDBItemDataRec *)*(items + itemNumber); GetIconRefOwners((itemsData[0])->icon, &referenceCount); // first, unregister and/or release the icons if (referenceCount == 1) // if this is the last instance of the { // IconRefs we should unregister them OSType iconType; /* UnregisterIconRef doesn't decrement the reference count on some versions of Mac OS X (it does on 10.1.5, doesn't on 10.2.8, and does on 10.3.4). To account for this we will retain/acquire the icon, unregister it, then check the reference/owner count. If it's the same then we will also release the icons. We can't release the icons first or UnregisterIconRef will return noSuchIconErr (because the icons will already be disposed). Likewise we can't just release the icons afterwards because they may get disposed of when they're unregistered. */ AcquireIconRef((itemsData[0])->icon); for (iconType = 'Cat0'; iconType <= 'Cat9'; iconType++) UnregisterIconRef(kAppSignature, iconType); gIconsRegistered = false; GetIconRefOwners((itemsData[0])->icon, &referenceCount); if (referenceCount > 1) needRelease = true; ReleaseIconRef((itemsData[0])->icon); } else // otherwise simply release the icons needRelease = true; if (needRelease) { for (itemNumber = 0; itemNumber < kNumberOfRows; itemNumber++) ReleaseIconRef((itemsData[itemNumber])->icon); } // second, release the strings for (itemNumber = 0; itemNumber < kNumberOfRows; itemNumber++) CFRelease((itemsData[itemNumber])->name); DisposeHandle(itemsHandle); // finally, release our callbacks gCallbackRefCount--; if (gCallbackRefCount == 0) { DisposeDataBrowserItemNotificationUPP(gIconDBCallbacks.u.v1.itemNotificationCallback); DisposeDataBrowserDrawItemUPP(gIconDBCustomCallbacks.u.v1.drawItemCallback); } }
static int mac_open(register gx_device *dev) { gx_device_macos * mdev = (gx_device_macos *)dev; static short picHeader[42] = { 0x0000, // picture size 0x0000, 0x0000, 0x0318, 0x0264, // bounding rect at 72dpi 0x0011, 0x02ff, 0x0c00, 0xfffe, 0x0000, // version/header opcodes 0x0048, 0x0000, // best x resolution 0x0048, 0x0000, // best y resolution 0x0000, 0x0000, 0x0318, 0x0264, // optimal src rect at 72dpi 0x0000, // reserved 0x0000, 0x001e, // DefHilite 0x0008, 0x0048, // PenMode 0x001a, 0x0000, 0x0000, 0x0000, // RGBFgCol = Black 0x001b, 0xFFFF, 0xFFFF, 0xFFFF, // RGBBkCol = White 0x0001, 0x000A, // set clipping 0x0000, 0x0000, 0x0318, 0x0264, // clipping rect 0x0032, 0x0000, 0x0000, 0x0318, 0x0264 // erase rect }; mac_set_colordepth(dev, mdev->color_info.depth); mdev->numUsedFonts = 0; mdev->lastFontFace = -1; mdev->lastFontSize = -1; mdev->lastFontID = -1; mdev->pic = (PicHandle) NewHandle(500000); if (mdev->pic == 0) // error, not enough memory return gs_error_VMerror; HLockHi((Handle) mdev->pic); // move handle high and lock it mdev->currPicPos = (short*) *mdev->pic; memcpy(mdev->currPicPos, picHeader, 42*2); mdev->currPicPos += 42; // enter correct dimensions and resolutions ((short*)(*mdev->pic))[ 3] = mdev->MediaSize[1]; ((short*)(*mdev->pic))[ 4] = mdev->MediaSize[0]; ((short*)(*mdev->pic))[16] = ((short*)(*mdev->pic))[35] = ((short*)(*mdev->pic))[40] = mdev->height; ((short*)(*mdev->pic))[17] = ((short*)(*mdev->pic))[36] = ((short*)(*mdev->pic))[41] = mdev->width; ((short*)(*mdev->pic))[10] = (((long) X2Fix( mdev->x_pixels_per_inch )) & 0xFFFF0000) >> 16; ((short*)(*mdev->pic))[11] = ((long) X2Fix( mdev->x_pixels_per_inch )) & 0x0000FFFF; ((short*)(*mdev->pic))[12] = (((long) X2Fix( mdev->y_pixels_per_inch )) & 0xFFFF0000) >> 16; ((short*)(*mdev->pic))[13] = ((long) X2Fix( mdev->y_pixels_per_inch )) & 0x0000FFFF; // finish picture, but dont increment pointer, we want to go on drawing *mdev->currPicPos = 0x00ff; // notify the caller that a new device was opened if (pgsdll_callback) (*pgsdll_callback) (GSDLL_DEVICE, (char *)mdev, 1); return 0; }
OSErr SpriteUtils_AddCompressedSpriteSampleToMedia (Media theMedia, QTAtomContainer theSample, TimeValue theDuration, Boolean isKeyFrame, OSType theDataCompressorType, TimeValue *theSampleTime) { SpriteDescriptionHandle mySampleDesc = NULL; Handle myCompressedSample = NULL; ComponentInstance myComponent = NULL; OSErr myErr = noErr; myErr = OpenADefaultComponent(DataCompressorComponentType, theDataCompressorType, &myComponent); if (myErr != noErr) goto bail; mySampleDesc = (SpriteDescriptionHandle)NewHandleClear(sizeof(SpriteDescription)); if (mySampleDesc == NULL) { myErr = MemError(); goto bail; } if (myComponent != NULL) { UInt32 myCompressBufferSize, myActualCompressedSize, myDecompressSlop = 0; UInt32 myUncompressedSize; SignedByte mySaveState = HGetState(theSample); myErr = (OSErr)DataCodecGetCompressBufferSize(myComponent, GetHandleSize(theSample), &myCompressBufferSize); if (myErr != noErr) goto bail; myCompressedSample = NewHandle(sizeof(UInt32) + myCompressBufferSize); myErr = MemError(); if (myErr != noErr) goto bail; HLockHi(theSample); HLockHi(myCompressedSample); myErr = (OSErr)DataCodecCompress(myComponent, *theSample, GetHandleSize(theSample), *myCompressedSample + sizeof(UInt32), // room for size at beginning myCompressBufferSize, &myActualCompressedSize, &myDecompressSlop); HSetState(theSample, mySaveState); HUnlock(myCompressedSample); if (myErr != noErr) goto bail; SetHandleSize(myCompressedSample, sizeof(UInt32) + myActualCompressedSize); myErr = MemError(); if (myErr != noErr) goto bail; (**mySampleDesc).decompressorType = EndianU32_NtoB(theDataCompressorType); myUncompressedSize = GetHandleSize(theSample); (*(UInt32*) *myCompressedSample) = EndianU32_NtoB(myUncompressedSize); // add uncompressed size at beginning myErr = AddMediaSample(theMedia, (Handle)myCompressedSample, 0, GetHandleSize(myCompressedSample), theDuration, (SampleDescriptionHandle)mySampleDesc, 1, (short)(isKeyFrame ? 0 : mediaSampleNotSync), theSampleTime); } else { myErr = AddMediaSample(theMedia, (Handle)theSample, 0, GetHandleSize(theSample), theDuration, (SampleDescriptionHandle)mySampleDesc, 1, (short)(isKeyFrame ? 0 : mediaSampleNotSync), theSampleTime); } bail: if (myCompressedSample != NULL) DisposeHandle(myCompressedSample); if (mySampleDesc != NULL) DisposeHandle((Handle)mySampleDesc); if (myComponent != NULL) CloseComponent(myComponent); return(myErr); }
static OSErr QTDR_AddVideoSamplesToMedia (Media theMedia, short theTrackWidth, short theTrackHeight) { GWorldPtr myGWorld = NULL; PixMapHandle myPixMap = NULL; CodecType myCodecType = kJPEGCodecType; long myNumSample; long myMaxComprSize = 0L; Handle myComprDataHdl = NULL; Ptr myComprDataPtr = NULL; ImageDescriptionHandle myImageDesc = NULL; CGrafPtr mySavedPort = NULL; GDHandle mySavedDevice = NULL; Rect myRect; OSErr myErr = noErr; MacSetRect(&myRect, 0, 0, theTrackWidth, theTrackHeight); myErr = NewGWorld(&myGWorld, kPixelDepth, &myRect, NULL, NULL, (GWorldFlags)0); if (myErr != noErr) goto bail; myPixMap = GetGWorldPixMap(myGWorld); if (myPixMap == NULL) goto bail; LockPixels(myPixMap); myErr = GetMaxCompressionSize( myPixMap, &myRect, 0, // let ICM choose depth codecNormalQuality, myCodecType, (CompressorComponent)anyCodec, &myMaxComprSize); if (myErr != noErr) goto bail; myComprDataHdl = NewHandle(myMaxComprSize); if (myComprDataHdl == NULL) goto bail; HLockHi(myComprDataHdl); #if TARGET_CPU_68K myComprDataPtr = StripAddress(*myComprDataHdl); #else myComprDataPtr = *myComprDataHdl; #endif myImageDesc = (ImageDescriptionHandle)NewHandle(4); if (myImageDesc == NULL) goto bail; GetGWorld(&mySavedPort, &mySavedDevice); SetGWorld(myGWorld, NULL); for (myNumSample = 1; myNumSample <= kNumVideoFrames; myNumSample++) { EraseRect(&myRect); QTDR_DrawFrame(theTrackWidth, theTrackHeight, myNumSample, myGWorld); myErr = CompressImage( myPixMap, &myRect, codecNormalQuality, myCodecType, myImageDesc, myComprDataPtr); if (myErr != noErr) goto bail; myErr = AddMediaSample( theMedia, myComprDataHdl, 0, // no offset in data (**myImageDesc).dataSize, kVideoFrameDuration, // frame duration (SampleDescriptionHandle)myImageDesc, 1, // one sample 0, // self-contained samples NULL); if (myErr != noErr) goto bail; } bail: SetGWorld(mySavedPort, mySavedDevice); if (myImageDesc != NULL) DisposeHandle((Handle)myImageDesc); if (myComprDataHdl != NULL) DisposeHandle(myComprDataHdl); if (myGWorld != NULL) DisposeGWorld(myGWorld); return(myErr); }
quicktime_recorder* quicktime_recorder::create( const char *path2, int width, int height, float fps ) { OSErr err; OSType dataRefType; Handle dataRef = NULL; impl *m = new impl(width, height); std::string pathStd = path2; #ifdef WIN32 for (std::string::iterator p = pathStd.begin(); p != pathStd.end(); ++p) if (*p == '/') *p = '\\'; #endif CFStringRef cfPath = CFStringCreateWithCString(NULL, pathStd.c_str(), kCFStringEncodingISOLatin1); err = QTNewDataReferenceFromFullPathCFString(cfPath, kQTNativeDefaultPathStyle, 0, &dataRef, &dataRefType); CFRelease(cfPath); if (err != noErr) { delete m; return NULL; } err = CreateMovieStorage(dataRef, dataRefType, FOUR_CHAR_CODE('TVOD'), smSystemScript, createMovieFileDeleteCurFile | createMovieFileDontCreateResFile, &m->data_handler, &m->movie); DisposeHandle(dataRef); if (err != noErr) { delete m; return NULL; } m->track = NewMovieTrack(m->movie, FixRatio(m->width, 1), FixRatio(m->height, 1), kNoVolume); err &= GetMoviesError(); TimeScale timeScale = (TimeScale)(fps * 100.0f); m->media = NewTrackMedia(m->track, VideoMediaType, timeScale, nil, 0 ); err &= GetMoviesError(); if (err != noErr) { delete m; return NULL; } SetMovieTimeScale(m->movie, timeScale); m->buffer = new unsigned char[4 * m->width * m->height]; Rect rect; rect.left = rect.top = 0; rect.right = m->width; rect.bottom = m->height; err = QTNewGWorldFromPtr(&m->gworld, k32BGRAPixelFormat, &rect, NULL, NULL, 0, m->buffer, 4 * m->width); if (err != noErr) { delete m; return NULL; } m->pixmap = GetGWorldPixMap(m->gworld); if (!m->pixmap) { delete m; return NULL; } LockPixels(m->pixmap); long maxSize = 0; err = GetMaxCompressionSize(m->pixmap, &rect, 0, codecNormalQuality, kPNGCodecType, anyCodec, &maxSize); if (err != noErr) { delete m; return NULL; } m->handle = NewHandle(maxSize); if (!m->handle) { delete m; return NULL; } HLockHi(m->handle); m->ptr = *m->handle; m->image_desc = (ImageDescriptionHandle)NewHandle(4); if (!m->image_desc) { delete m; return NULL; } err = BeginMediaEdits( m->media ); if (err != noErr) { delete m; return NULL; } return new quicktime_recorder(m); }