void wxMacToolTip::Clear() { m_mark++ ; if ( m_timer ) { delete m_timer ; m_timer = NULL ; } if ( !m_shown ) return ; #if TARGET_CARBON HMHideTag() ; m_helpTextRef.Release() ; #else if ( m_window == s_ToolTipWindowRef && m_backpict ) { wxMacPortStateHelper help( (GrafPtr) GetWindowPort(m_window) ) ; m_shown = false ; BackColor( whiteColor ) ; ForeColor(blackColor ) ; DrawPicture(m_backpict, &m_rect); KillPicture(m_backpict); m_backpict = NULL ; } #endif }
static void SaveToPICT (SFReply *reply) { Rect MyPicFrame ; CQDProcs MyPicProcs,*SavePtr ; OSErr error ; long LongZero, LongCount ; short Counter ; CGrafPtr theCGrafPort; WindowPtr theWindow; OpenCPicParams myOpenCPicParams; /* get my window */ theWindow = myWindow.theWindow; theCGrafPort = (CGrafPtr) theWindow; error = FSOpen(reply->fName, reply->vRefNum, &FileSys_RefNR ) ; SetStdCProcs ( &MyPicProcs ) ; SavePtr = (CQDProcs *) theWindow->grafProcs; theWindow->grafProcs = (QDProcs *) (&MyPicProcs) ; MyPicProcs.putPicProc = NewQDPutPicProc(MyPutPicData) ; LongZero = 0 ; LongCount = 4 ; PicCounter = sizeof(Picture) ; for (Counter=1 ; Counter <= 128+sizeof(Picture) ; Counter++ ) error = FSWrite(FileSys_RefNR, &LongCount, &LongZero ); error = SetFPos(FileSys_RefNR, fsFromStart, 512+sizeof(Picture)) ; SetPort((GrafPtr)(theWindow)); MyPicFrame = ((GrafPtr)(theWindow))->portRect; MyPicFrame.right = MyPicFrame.right-16; MyPicFrame.bottom = MyPicFrame.bottom-16; MyPicHand = NULL ; myOpenCPicParams.srcRect = MyPicFrame; myOpenCPicParams.hRes = cHRes; myOpenCPicParams.vRes = cVRes; myOpenCPicParams.version = -2; myOpenCPicParams.reserved1 = 0; myOpenCPicParams.reserved2 = 0; MyPicHand = OpenCPicture ( &myOpenCPicParams ); ClipRect(&MyPicFrame); /* draw picture */ RefreshCommand(); ClosePicture() ; /* close File */ error = SetFPos(FileSys_RefNR, fsFromStart, 512) ; LongCount = sizeof(Picture) ; error = FSWrite(FileSys_RefNR, &LongCount, (void *) (*MyPicHand) ); error = FSClose(FileSys_RefNR) ; KillPicture(MyPicHand); theWindow->grafProcs = (QDProcs *) SavePtr ; return; }
void wxBitmapDataObject::Clear() { if ( m_pictCreated && m_pictHandle ) { KillPicture( (PicHandle) m_pictHandle ) ; } m_pictHandle = NULL ; }
wxMetafileRefData::~wxMetafileRefData(void) { if (m_metafile) { KillPicture( (PicHandle) m_metafile ) ; m_metafile = 0; #if wxMAC_USE_CORE_GRAPHICS QDPictRelease( m_qdPictRef ) ; m_qdPictRef = NULL ; #endif } }
void wxBitmapDataObject::Clear() { if (m_pictHandle != NULL) { #if wxMAC_USE_CORE_GRAPHICS DisposeHandle( (Handle) m_pictHandle ); #else if (m_pictCreated) KillPicture( (PicHandle)m_pictHandle ); #endif m_pictHandle = NULL; } m_pictCreated = false; }
void _HYPlatformGraphicPane::_CopyToClipboard (void) { _HYGraphicPane* parent = (_HYGraphicPane*)this; #ifdef TARGET_API_MAC_CARBON ClearCurrentScrap(); #else ZeroScrap(); #endif Rect bRect; bRect.left = bRect.top = 0; bRect.right = parent->w; bRect.bottom = parent->h; PicHandle pic = OpenPicture (&bRect); GrafPtr topPort; GetPort (&topPort); LockPixels (GetGWorldPixMap(thePane)); #ifdef OPAQUE_TOOLBOX_STRUCTS CopyBits (GetPortBitMapForCopyBits(thePane),GetPortBitMapForCopyBits(topPort), &bRect,&bRect,srcCopy,(RgnHandle)nil); #else CopyBits ((BitMap*)*GetGWorldPixMap(thePane), (BitMap*)&(topPort->portBits),&bRect,&bRect, srcCopy,(RgnHandle)nil); #endif UnlockPixels (GetGWorldPixMap(thePane)); ClosePicture (); HLock ((Handle)pic); #ifdef TARGET_API_MAC_CARBON ScrapRef theScrapRef; GetCurrentScrap(&theScrapRef); PutScrapFlavor(theScrapRef, 'PICT', kScrapFlavorMaskNone,GetHandleSize((Handle)pic),*pic); #else PutScrap (GetHandleSize((Handle)pic),'PICT',*pic); #endif KillPicture (pic); }
static TQ3ShaderObject QD3DSupport_CreateShaderFromTexture(LPTSTR grndTextureFilePath) { TQ3ShaderObject shaderObject = NULL; PicHandle picH; Rect picRect; ComponentResult result; result = Utils_Win32_GetPicFromFile(grndTextureFilePath, &picH, &picRect); if (picH == NULL) { Utils_DisplayFatalErrorMsg("Failure retrieving ground textures!"); } shaderObject = TextureMap_Get(picH, &picRect); /* release memory occupied by picture */ KillPicture(picH); return shaderObject; }
OSErr SpriteUtils_AddPICTImageToKeyFrameSample (QTAtomContainer theKeySample, short thePictID, RGBColor *theKeyColor, QTAtomID theID, FixedPoint *theRegistrationPoint, StringPtr theImageName) { PicHandle myPicture = NULL; Handle myCompressedPicture = NULL; ImageDescriptionHandle myImageDesc = NULL; OSErr myErr = noErr; // get picture from resource myPicture = (PicHandle)GetPicture(thePictID); if (myPicture == NULL) myErr = resNotFound; if (myErr != noErr) goto bail; DetachResource((Handle)myPicture); // convert it to image data compressed by the animation compressor myErr = ICUtils_RecompressPictureWithTransparency(myPicture, theKeyColor, NULL, &myImageDesc, &myCompressedPicture); if (myErr != noErr) goto bail; // add it to the key sample HLock(myCompressedPicture); myErr = SpriteUtils_AddCompressedImageToKeyFrameSample(theKeySample, myImageDesc, GetHandleSize(myCompressedPicture), *myCompressedPicture, theID, theRegistrationPoint, theImageName); bail: if (myPicture != NULL) KillPicture(myPicture); if (myCompressedPicture != NULL) DisposeHandle(myCompressedPicture); if (myImageDesc != NULL) DisposeHandle((Handle)myImageDesc); return(myErr); }
/* ------------ Local code */ static void add_overhead_thumbnail( FileSpecifier &File) { PicHandle picture; PicHandle preview; RgnHandle clip_region; FontInfo info; short text_x, text_y; short text_length; Str255 temporary; GWorldPtr old_gworld; GDHandle old_device; struct overhead_map_data overhead_data; Rect bounds; AEDesc aeFileSpec; FSSpec *SpecPtr; // Skip all this if there's no nav services to install the preview if(!machine_has_nav_services() || NavLibraryVersion() < kNavServicesVersion_2_0) return; GetGWorld(&old_gworld, &old_device); SetGWorld(world_pixels, (GDHandle) NULL); // Note well. We're using world_pixels to create our thumbnail pict within. // If world_pixels is runing as a postage stamp (low-res + small display space) // Then it is actually smaller than the size we're looking to build a thumbnail // within. But seeing as we're generating pict images and using drawing commands // instead of bit-wise operations. It all works out. /* Create the bounding rectangle */ SetRect(&bounds, 0, 0, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT); /* Start recording.. */ picture= OpenPicture(&bounds); PaintRect(&bounds); overhead_data.scale= OVERHEAD_MAP_MINIMUM_SCALE; overhead_data.origin.x= local_player->location.x; overhead_data.origin.y= local_player->location.y; overhead_data.half_width= RECTANGLE_WIDTH(&bounds)/2; overhead_data.half_height= RECTANGLE_HEIGHT(&bounds)/2; overhead_data.width= RECTANGLE_WIDTH(&bounds); overhead_data.height= RECTANGLE_HEIGHT(&bounds); overhead_data.mode= _rendering_saved_game_preview; _render_overhead_map(&overhead_data); RGBForeColor(&rgb_black); PenSize(1, 1); TextFont(0); TextFace(normal); TextSize(0); ClosePicture(); // JTP: Add Nav Services style preview SetRect(&bounds, 0, 0, PREVIEW_WIDTH, PREVIEW_HEIGHT); preview= OpenPicture(&bounds); SetRect(&bounds, PREVIEW_IMAGE_X, PREVIEW_IMAGE_Y, THUMBNAIL_WIDTH + PREVIEW_IMAGE_X, THUMBNAIL_HEIGHT + PREVIEW_IMAGE_Y); clip_region= NewRgn(); GetClip(clip_region); ClipRect(&bounds); DrawPicture(picture, &bounds); SetClip(clip_region); /* Center the text in the rectangle */ // LP: Classic doesn't have this function #ifdef TARGET_API_MAC_CARBON CopyCStringToPascal(static_world->level_name, temporary); #else strncpy((char *)temporary,static_world->level_name,LEVEL_NAME_LENGTH); c2pstr((char *)temporary); #endif // LP: fix to allow lengths more than 127 bytes (not really necessary, but...) text_length = *ptemporary; TruncText(PREVIEW_WIDTH, (char *)temporary+1, &text_length, smTruncEnd); *ptemporary = text_length; GetFontInfo(&info); text_y= PREVIEW_HEIGHT - info.descent; text_x= PREVIEW_LABEL_X + (PREVIEW_WIDTH-StringWidth(temporary))/2; MoveTo(text_x, text_y); DrawString(temporary); ClosePicture(); // This requires NavServices 2.0, what's the inline check? // From FSS get a AEDesc OSStatus err; SpecPtr = &File.GetSpec(); err = AECreateDesc(typeFSS, SpecPtr, sizeof(FSSpec), &aeFileSpec); HLock((Handle)preview); err = NavCreatePreview(&aeFileSpec, 'PICT', *preview, GetHandleSize((Handle)preview)); HUnlock((Handle)preview); AEDisposeDesc(&aeFileSpec); KillPicture(preview); KillPicture(picture); DisposeRgn(clip_region); SetGWorld(old_gworld, old_device); }
void QTEffects_RespondToDialogSelection (OSErr theErr) { Boolean myDialogWasCancelled = false; short myResID = movieInDataForkResID; UInt16 myMovieIter; short mySrcMovieRefNum = 0; Movie myPrevSrcMovie = NULL; Track myPrevSrcTrack = NULL; Movie myNextSrcMovie = NULL; Track myNextSrcTrack = NULL; short myDestMovieRefNum = 0; FSSpec myFile; Boolean myIsSelected = false; Boolean myIsReplacing = false; StringPtr myPrompt = QTUtils_ConvertCToPascalString(kEffectsSaveMoviePrompt); StringPtr myFileName = QTUtils_ConvertCToPascalString(kEffectsSaveMovieFileName); Movie myDestMovie = NULL; Fixed myDestMovieWidth, myDestMovieHeight; ImageDescriptionHandle myDesc = NULL; Track videoTrackFX, videoTrackA, videoTrackB; Media videoMediaFX, videoMediaA, videoMediaB; TimeValue myCurrentDuration = 0; TimeValue myReturnedDuration; Boolean isFirstTransition = true; TimeValue myMediaTransitionDuration; TimeValue myMediaFXStartTime, myMediaFXDuration; OSType myEffectCode; long myFlags = createMovieFileDeleteCurFile | createMovieFileDontCreateResFile; long myLong; OSErr myErr = noErr; // standard parameter box has been dismissed, so remember that fact gEffectsDialog = 0L; myDialogWasCancelled = (theErr == userCanceledErr); // we're finished with the effect list and movie posters QTDisposeAtomContainer(gEffectList); if (gPosterA != NULL) KillPicture(gPosterA); if (gPosterB != NULL) KillPicture(gPosterB); // when the sign says stop, then stop if (myDialogWasCancelled) goto bail; // add atoms naming the sources to gEffectSample myLong = EndianU32_NtoB(kSourceOneName); QTInsertChild(gEffectSample, kParentAtomIsContainer, kEffectSourceName, 1, 0, sizeof(myLong), &myLong, NULL); myLong = EndianU32_NtoB(kSourceTwoName); QTInsertChild(gEffectSample, kParentAtomIsContainer, kEffectSourceName, 2, 0, sizeof(myLong), &myLong, NULL); // extract the 'what' atom to find out what kind of effect it is { QTAtom myEffectAtom; QTAtomID myEffectAtomID; long myEffectCodeSize; Ptr myEffectCodePtr; myEffectAtom = QTFindChildByIndex(gEffectSample, kParentAtomIsContainer, kParameterWhatName, kParameterWhatID, &myEffectAtomID); myErr = QTLockContainer(gEffectSample); BailError(myErr); myErr = QTGetAtomDataPtr(gEffectSample, myEffectAtom, &myEffectCodeSize, &myEffectCodePtr); BailError(myErr); if (myEffectCodeSize != sizeof(OSType)) { myErr = paramErr; goto bail; } myEffectCode = *(OSType *)myEffectCodePtr; // "tsk" myEffectCode = EndianU32_BtoN(myEffectCode); // because the data is read from an atom container myErr = QTUnlockContainer(gEffectSample); BailError(myErr); } // ask the user for the name of the new movie file QTFrame_PutFile(myPrompt, myFileName, &myFile, &myIsSelected, &myIsReplacing); if (!myIsSelected) goto bail; // deal with user cancelling // create a movie file for the destination movie myErr = CreateMovieFile(&myFile, FOUR_CHAR_CODE('TVOD'), 0, myFlags, &myDestMovieRefNum, &myDestMovie); BailError(myErr); // open the first file as a movie; call the first movie myPrevSrcMovie myErr = OpenMovieFile(&gSpecList[0], &mySrcMovieRefNum, fsRdPerm); BailError(myErr); myErr = NewMovieFromFile(&myPrevSrcMovie, mySrcMovieRefNum, NULL, NULL, 0, NULL); BailError(myErr); myErr = CloseMovieFile(mySrcMovieRefNum); BailError(myErr); // if the movie is shorter than kMinimumDuration, scale it to that length SetMovieTimeScale(myPrevSrcMovie, kTimeScale); myErr = QTEffects_GetFirstVideoTrackInMovie(myPrevSrcMovie, &myPrevSrcTrack); BailNil(myPrevSrcTrack); if (GetTrackDuration(myPrevSrcTrack) < kMinimumDuration) { myErr = ScaleTrackSegment(myPrevSrcTrack, 0, GetTrackDuration(myPrevSrcTrack), kMinimumDuration); BailError(myErr); } // find out how big the first movie is; we'll use it as the size of all our tracks GetTrackDimensions(myPrevSrcTrack, &myDestMovieWidth, &myDestMovieHeight); #if USES_MAKE_IMAGE_DESC_FOR_EFFECT // create a new sample description for the effect, // which is just an image description specifying the effect and its dimensions myErr = MakeImageDescriptionForEffect(myEffectCode, &myDesc); if (myErr != noErr) BailError(myErr); #else // create a new sample description for the effect, // which is just an image description specifying the effect and its dimensions myDesc = (ImageDescriptionHandle)NewHandleClear(sizeof(ImageDescription)); BailNil(myDesc); (**myDesc).idSize = sizeof(ImageDescription); (**myDesc).cType = myEffectCode; (**myDesc).hRes = 72L << 16; (**myDesc).vRes = 72L << 16; (**myDesc).dataSize = 0L; (**myDesc).frameCount = 1; (**myDesc).depth = 0; (**myDesc).clutID = -1; #endif // fill in the fields of the sample description (**myDesc).vendor = kAppleManufacturer; (**myDesc).temporalQuality = codecNormalQuality; (**myDesc).spatialQuality = codecNormalQuality; (**myDesc).width = FixRound(myDestMovieWidth); (**myDesc).height = FixRound(myDestMovieHeight); // add three video tracks to the destination movie: // - videoTrackFX is where the effects and stills live; it's user-visible. // - videoTrackA is where the "source A"s for effects live; it's hidden by the input map // - videoTrackB is where the "source B"s for effects live; it's hidden by the input map videoTrackFX = NewMovieTrack(myDestMovie, myDestMovieWidth, myDestMovieHeight, 0); BailNil(videoTrackFX); videoMediaFX = NewTrackMedia(videoTrackFX, VideoMediaType, kTimeScale, NULL, 0); BailNil(videoMediaFX); myErr = BeginMediaEdits(videoMediaFX); BailError(myErr); videoTrackA = NewMovieTrack(myDestMovie, myDestMovieWidth, myDestMovieHeight, 0); BailNil(videoTrackA); videoMediaA = NewTrackMedia(videoTrackA, VideoMediaType, kTimeScale, NULL, 0); BailNil(videoMediaA); videoTrackB = NewMovieTrack(myDestMovie, myDestMovieWidth, myDestMovieHeight, 0); BailNil(videoTrackB); videoMediaB = NewTrackMedia(videoTrackB, VideoMediaType, kTimeScale, NULL, 0); BailNil(videoMediaB); // create the input map { long myRefIndex1, myRefIndex2; QTAtomContainer myInputMap; QTAtom myInputAtom; OSType myInputType; QTNewAtomContainer(&myInputMap); // first input if (videoTrackA) { AddTrackReference(videoTrackFX, videoTrackA, kTrackModifierReference, &myRefIndex1); QTInsertChild(myInputMap, kParentAtomIsContainer, kTrackModifierInput, myRefIndex1, 0, 0, NULL, &myInputAtom); myInputType = EndianU32_NtoB(kTrackModifierTypeImage); QTInsertChild(myInputMap, myInputAtom, kTrackModifierType, 1, 0, sizeof(myInputType), &myInputType, NULL); myLong = EndianU32_NtoB(kSourceOneName); QTInsertChild(myInputMap, myInputAtom, kEffectDataSourceType, 1, 0, sizeof(myLong), &myLong, NULL); } // second input if (videoTrackB) { AddTrackReference(videoTrackFX, videoTrackB, kTrackModifierReference, &myRefIndex2); QTInsertChild(myInputMap, kParentAtomIsContainer, kTrackModifierInput, myRefIndex2, 0, 0, NULL, &myInputAtom); myInputType = EndianU32_NtoB(kTrackModifierTypeImage); QTInsertChild(myInputMap, myInputAtom, kTrackModifierType, 1, 0, sizeof(myInputType), &myInputType, NULL); myLong = EndianU32_NtoB(kSourceTwoName); QTInsertChild(myInputMap, myInputAtom, kEffectDataSourceType, 1, 0, sizeof(myLong), &myLong, NULL); } // set that map SetMediaInputMap(GetTrackMedia(videoTrackFX), myInputMap); QTDisposeAtomContainer(myInputMap); } myCurrentDuration = 0; #if MAKE_STILL_SECTIONS // copy the first sample of the first video track of the first movie to videoTrackFX, with duration kStillDuration. myErr = CopyPortionOfTrackToTrack(myPrevSrcTrack, eStartPortion + eMiddlePortion, videoTrackFX, myCurrentDuration, &myReturnedDuration); BailError(myErr); myCurrentDuration += myReturnedDuration; #endif // now process any remaining files myMovieIter = 1; while (myMovieIter < gSpecCount) { // open the next file as a movie; call it nextSourceMovie myErr = OpenMovieFile(&gSpecList[myMovieIter], &mySrcMovieRefNum, fsRdPerm); BailError(myErr); myErr = NewMovieFromFile(&myNextSrcMovie, mySrcMovieRefNum, NULL, NULL, 0, NULL); BailError(myErr); // we're done with the movie file, so close it myErr = CloseMovieFile(mySrcMovieRefNum); BailError(myErr); // if the movie is shorter than kMinimumDuration, scale it to that length SetMovieTimeScale(myNextSrcMovie, kTimeScale); myErr = QTEffects_GetFirstVideoTrackInMovie(myNextSrcMovie, &myNextSrcTrack); BailNil(myNextSrcTrack); if (GetTrackDuration(myNextSrcTrack) < kMinimumDuration) { myErr = ScaleTrackSegment(myNextSrcTrack, 0, GetTrackDuration(myNextSrcTrack), kMinimumDuration); BailError(myErr); } // create a transition effect from the previous source movie's first video sample to the next source movie's first video sample // (the effect should have duration kEffectDuration); // this involves adding one sample to each of the three video tracks: // sample from previous source movie -> videoTrackA myErr = QTEffects_CopyPortionOfTrackToTrack(myPrevSrcTrack, eFinishPortion, videoTrackA, myCurrentDuration, &myReturnedDuration); BailError(myErr); // sample from next source movie -> videoTrackB myErr = QTEffects_CopyPortionOfTrackToTrack(myNextSrcTrack, eStartPortion, videoTrackB, myCurrentDuration, &myReturnedDuration); BailError(myErr); // effect sample -> videoTrackFX if (isFirstTransition) { myMediaTransitionDuration = myReturnedDuration; myMediaFXStartTime = GetMediaDuration(videoMediaFX); myErr = AddMediaSample(videoMediaFX, gEffectSample, 0, GetHandleSize(gEffectSample), myMediaTransitionDuration, (SampleDescriptionHandle)myDesc, 1, 0, NULL); BailError(myErr); myMediaFXDuration = GetMediaDuration(videoMediaFX) - myMediaFXStartTime; isFirstTransition = false; } myErr = InsertMediaIntoTrack(videoTrackFX, myCurrentDuration, myMediaFXStartTime, myMediaFXDuration, FixRatio(myReturnedDuration, myMediaTransitionDuration)); BailError(myErr); myCurrentDuration += myReturnedDuration; #if MAKE_STILL_SECTIONS // copy the first video sample of myNextSrcMovie to videoTrackFX, with duration kStillDuration. myErr = QTEffects_CopyPortionOfTrackToTrack(myNextSrcTrack, eMiddlePortion + (myMovieIter + 1 == theSpecCount) ? eFinishPortion : 0, videoTrackFX, myCurrentDuration, &myReturnedDuration); BailError(myErr); myCurrentDuration += myReturnedDuration; #endif // MAKE_STILL_SECTIONS // dispose of previous source movie. DisposeMovie(myPrevSrcMovie); myPrevSrcMovie = myNextSrcMovie; myPrevSrcTrack = myNextSrcTrack; myNextSrcMovie = NULL; myNextSrcTrack = NULL; myMovieIter++; } // while myErr = EndMediaEdits(videoMediaFX); BailError(myErr); myErr = AddMovieResource(myDestMovie, myDestMovieRefNum, &myResID, "\pMovie 1"); BailError(myErr); CloseMovieFile(myDestMovieRefNum); if (myPrevSrcMovie != NULL) DisposeMovie(myPrevSrcMovie); DisposeMovie(myDestMovie); bail: free(myPrompt); free(myFileName); QTDisposeAtomContainer(gEffectSample); DisposeHandle((Handle)myDesc); return; }
void MacQTVideoConfig(WindowRef parent) { OSStatus err; ComponentInstance ci; if (running) return; MacQTOpenVideoComponent(&ci); long flag; flag = scListEveryCodec | scAllowZeroKeyFrameRate | scDisableFrameRateItem; err = SCSetInfo(ci, scPreferenceFlagsType, &flag); PicHandle pict; Rect rct; int width, height; width = IPPU.RenderedScreenWidth; height = IPPU.RenderedScreenHeight; pict = GetScreenAsPicHandle(width, height, width, height); HNoPurge((Handle) pict); rct.left = (width - scTestImageWidth) >> 1; rct.top = (height - scTestImageHeight) >> 1; rct.right = rct.left + scTestImageWidth; rct.bottom = rct.top + scTestImageHeight; err = SCSetTestImagePictHandle(ci, pict, &rct, scPreferCropping); SCWindowSettings ws; ws.size = sizeof(SCWindowSettings); ws.windowRefKind = scWindowRefKindCarbon; ws.parentWindow = parent; err = SCSetInfo(ci, scWindowOptionsType, &ws); err = SCRequestSequenceSettings(ci); if (err == noErr) { CFDataRef data; Handle hdl; err = SCGetInfo(ci, scSettingsStateType, &hdl); if (err == noErr) { HLock(hdl); data = CFDataCreate(kCFAllocatorDefault, (unsigned char *) *hdl, GetHandleSize(hdl)); if (data) { CFPreferencesSetAppValue(CFSTR("QTVideoSetting"), data, kCFPreferencesCurrentApplication); CFRelease(data); } DisposeHandle(hdl); } } MacQTCloseVideoComponent(ci); KillPicture(pict); }
void saveToPICTFile() { /* Saving a PixMap as a PICT file isn't too hard. 1. Open a Picture with the port set to the destination of #2. 2. CopyBits the PixMap onto itself or another port. (Because CopyBits is recorded in Pictures. 3. Close the picture. 4. Open the data fork for the file. 5. Write out 512 bytes of zeros followed by the contents of the Picture handle. 6. Close the file. */ PicHandle picHandle; OSErr anErr = noErr; OSType fileTypeToSave = 'PICT'; OSType creatorType = 'ogle'; NavReplyRecord reply; NavDialogOptions dialogOptions; FSSpec documentFSSpec; long inOutCount; short refNum, count; AEKeyword theKeyword; DescType actualType; unsigned char header[512]; Size actualSize; Rect tempRect1; CopyBits(GetPortBitMapForCopyBits(GetWindowPort(FrontWindow())), (BitMap*) &gPixMap, GetPortBounds(GetWindowPort(gWindow), &tempRect1), &gPixMap.bounds, srcCopy, 0L); SetPortWindowPort(gWindow); picHandle = OpenPicture(&gPixMap.bounds); CopyBits((BitMap*) &gPixMap, GetPortBitMapForCopyBits(GetWindowPort(FrontWindow())), &gPixMap.bounds, GetPortBounds(GetWindowPort(gWindow), &tempRect1), srcCopy, 0L); ClosePicture(); for (count = 0; count < 512; count++) header[count] = 0x00; anErr = NavGetDefaultDialogOptions(&dialogOptions); dialogOptions.dialogOptionFlags |= kNavSelectDefaultLocation; anErr = NavPutFile( nil, &reply, &dialogOptions, nil, fileTypeToSave, creatorType, nil ); if (anErr == noErr && reply.validRecord) { anErr = AEGetNthPtr(&(reply.selection), 1, typeFSS, &theKeyword, &actualType, &documentFSSpec, sizeof(documentFSSpec), &actualSize ); if (anErr == noErr) { anErr = FSpCreate(&documentFSSpec, creatorType, fileTypeToSave, smSystemScript); if (anErr == dupFNErr) { anErr = FSpDelete(&documentFSSpec); anErr = FSpCreate(&documentFSSpec, creatorType, fileTypeToSave, smSystemScript); } // this is quick 'n' dirty or there'd be more robust handling here // write the file FSpOpenDF(&documentFSSpec, fsRdWrPerm, &refNum ); inOutCount = 512; anErr = FSWrite(refNum, &inOutCount, header); // write the header if (anErr == noErr) { inOutCount = GetHandleSize((Handle)picHandle); anErr = FSWrite(refNum,&inOutCount,*picHandle); } FSClose( refNum ); } reply.translationNeeded = false; anErr = NavCompleteSave(&reply, kNavTranslateInPlace); NavDisposeReply(&reply); } KillPicture(picHandle); }
void CreateSprites (void) { long lIndex; PicHandle hpicImage; OSErr nErr; RGBColor rgbcKeyColor; SetRect(&gDestRects[0], 132, 132, 132 + kSpaceShipWidth, 132 + kSpaceShipHeight); SetRect(&gDestRects[1], 50, 50, 50 + kSpaceShipWidth, 50 + kSpaceShipHeight); SetRect(&gDestRects[2], 100, 100, 100 + kSpaceShipWidth, 100 + kSpaceShipHeight); SetRect(&gDestRects[3], 130, 130, 130 + kSpaceShipWidth, 130 + kSpaceShipHeight); gDeltas[0].h = -3; gDeltas[0].v = 0; gDeltas[1].h = -5; gDeltas[1].v = 3; gDeltas[2].h = 4; gDeltas[2].v = -6; gDeltas[3].h = 6; gDeltas[3].v = 4; gCurrentImages[0] = 0; gCurrentImages[1] = kNumSpaceShipImages / 4; gCurrentImages[2] = kNumSpaceShipImages / 2; gCurrentImages[3] = kNumSpaceShipImages * 4 / 3; rgbcKeyColor.red = 0; rgbcKeyColor.green = 0; rgbcKeyColor.blue = 0; // recompress PICT images to make them transparent for (lIndex = 0; lIndex < kNumSpaceShipImages; lIndex++) { hpicImage = (PicHandle)GetPicture(lIndex + kFirstSpaceShipPictID); DetachResource((Handle)hpicImage); nErr = RecompressPictureWithTransparency(hpicImage, &rgbcKeyColor, nil, &gImageDescriptions[lIndex], &gCompressedPictures[lIndex]); KillPicture(hpicImage); } // create the sprites for the sprite world for (lIndex = 0; lIndex < kNumSprites; lIndex++) { MatrixRecord matrix; SetIdentityMatrix(&matrix); matrix.matrix[2][0] = ((long)gDestRects[lIndex].left << 16); matrix.matrix[2][1] = ((long)gDestRects[lIndex].top << 16); nErr = NewSprite(&(gSprites[lIndex]), /* on return, the ID of the new sprite */ gSpriteWorld, /* the sprite world for this sprite */ gImageDescriptions[lIndex], /* image description of the spriteÕs image. */ *gCompressedPictures[lIndex], /* sprite image data */ &matrix, /* sprite matrix */ true, /* is sprite visible? */ lIndex); /* sprite layer */ } }
static void TkMacOSXDrawControl( MacButton *mbPtr, /* Mac button. */ GWorldPtr destPort, /* Off screen GWorld. */ GC gc, /* The GC we are drawing into - needed for the * bevel button */ Pixmap pixmap) /* The pixmap we are drawing into - needed for * the bevel button */ { TkButton *butPtr = (TkButton *) mbPtr; TkWindow *winPtr; Rect paneRect, cntrRect; int active, enabled; int rebuild; winPtr = (TkWindow *) butPtr->tkwin; paneRect.left = winPtr->privatePtr->xOff; paneRect.top = winPtr->privatePtr->yOff; paneRect.right = paneRect.left + Tk_Width(butPtr->tkwin); paneRect.bottom = paneRect.top + Tk_Height(butPtr->tkwin); cntrRect = paneRect; /* cntrRect.left += butPtr->inset; cntrRect.top += butPtr->inset; cntrRect.right -= butPtr->inset; cntrRect.bottom -= butPtr->inset; */ cntrRect.left += DEF_INSET_LEFT; cntrRect.top += DEF_INSET_TOP; cntrRect.right -= DEF_INSET_RIGHT; cntrRect.bottom -= DEF_INSET_BOTTOM; /* * The control has been previously initialised. * It may need to be re-initialised */ #if 0 rebuild = (winPtr->flags & TK_REBUILD_TOPLEVEL); winPtr->flags &= ~TK_REBUILD_TOPLEVEL; #else rebuild = 0; #endif if (mbPtr->flags) { MacControlParams params; TkMacOSXComputeControlParams(butPtr, ¶ms); if (rebuild || bcmp(¶ms, &mbPtr->params, sizeof(params))) { /* * The type of control has changed. * Clean it up and clear the flag. */ if (mbPtr->userPane) { DisposeControl(mbPtr->userPane); mbPtr->userPane = NULL; mbPtr->control = NULL; } mbPtr->flags = 0; } } if (!(mbPtr->flags & CONTROL_INITIALIZED)) { if (TkMacOSXInitControl(mbPtr, destPort, gc, pixmap, &paneRect, &cntrRect)) { return; } } SetControlBounds(mbPtr->userPane, &paneRect); SetControlBounds(mbPtr->control, &cntrRect); if (!mbPtr->useTkText) { Str255 controlTitle; ControlFontStyleRec fontStyle; Tk_Font font; int len; if (((mbPtr->info.image == NULL) && (mbPtr->info.bitmap == None)) || (mbPtr->info.compound != COMPOUND_NONE)) { len = TkFontGetFirstTextLayout(butPtr->textLayout, &font, (char*) controlTitle); controlTitle[len] = 0; } else { len = 0; controlTitle[0] = 0; } if (rebuild || bcmp(mbPtr->controlTitle, controlTitle, len+1)) { CFStringRef cf = CFStringCreateWithCString(NULL, (char*) controlTitle, kCFStringEncodingUTF8); if (cf != NULL) { SetControlTitleWithCFString(mbPtr->control, cf); CFRelease(cf); } bcopy(controlTitle, mbPtr->controlTitle, len+1); } if (len) { TkMacOSXInitControlFontStyle(font, &fontStyle); if (bcmp(&mbPtr->fontStyle, &fontStyle, sizeof(fontStyle)) ) { ChkErr(SetControlFontStyle, mbPtr->control, &fontStyle); bcopy(&fontStyle, &mbPtr->fontStyle, sizeof(fontStyle)); } } } if (mbPtr->params.isBevel) { /* * Initialiase the image/button parameters. */ SetupBevelButton(mbPtr, mbPtr->control, destPort, gc, pixmap); } if (butPtr->flags & SELECTED) { SetControlValue(mbPtr->control, 1); #if 0 } else if (butPtr->flags & TRISTATED) { SetControlValue(mbPtr->control, 2); #endif } else { SetControlValue(mbPtr->control, 0); } active = ((mbPtr->flags & ACTIVE) != 0); if (active != IsControlActive(mbPtr->control)) { if (active) { ChkErr(ActivateControl, mbPtr->control); } else { ChkErr(DeactivateControl, mbPtr->control); } } enabled = !(butPtr->state == STATE_DISABLED); if (enabled != IsControlEnabled(mbPtr->control)) { if (enabled) { ChkErr(EnableControl, mbPtr->control); } else { ChkErr(DisableControl, mbPtr->control); } } if (active && enabled) { if (butPtr->state == STATE_ACTIVE) { if (mbPtr->params.isBevel) { HiliteControl(mbPtr->control, kControlButtonPart); } else { switch (butPtr->type) { case TYPE_BUTTON: HiliteControl(mbPtr->control, kControlButtonPart); break; case TYPE_RADIO_BUTTON: HiliteControl(mbPtr->control, kControlRadioButtonPart); break; case TYPE_CHECK_BUTTON: HiliteControl(mbPtr->control, kControlCheckBoxPart); break; } } } else { HiliteControl(mbPtr->control, kControlNoPart); } } UpdateControlColors(mbPtr); if (butPtr->type == TYPE_BUTTON && !mbPtr->params.isBevel) { Boolean isDefault; if (butPtr->defaultState == STATE_ACTIVE) { isDefault = true; } else { isDefault = false; } ChkErr(SetControlData, mbPtr->control, kControlNoPart, kControlPushButtonDefaultTag, sizeof(isDefault), &isDefault); } if (mbPtr->flags & FIRST_DRAW) { ShowControl(mbPtr->userPane); ShowControl(mbPtr->control); mbPtr->flags ^= FIRST_DRAW; } else { SetControlVisibility(mbPtr->control, true, true); Draw1Control(mbPtr->userPane); } if (mbPtr->params.isBevel) { if (mbPtr->bevelButtonContent.contentType == kControlContentPictHandle) { KillPicture(mbPtr->bevelButtonContent.u.picture); } } }
OSErr QTInfo_MakeFilePreview (Movie theMovie, short theRefNum, ICMProgressProcRecordPtr theProgressProc) { unsigned long myModDate; PreviewResourceRecord myPNOTRecord; long myEOF; long mySize; unsigned long myAtomHeader[2]; // an atom header: size and type OSType myPreviewType; OSErr myErr = noErr; ////////// // // determine whether theRefNum is a file reference number of a data fork or a resource fork; // if it's a resource fork, then we'll just call the existing ICM function MakeFilePreview // ////////// if (QTInfo_IsRefNumOfResourceFork(theRefNum)) { myErr = MakeFilePreview(theRefNum, theProgressProc); goto bail; } ////////// // // determine the preview type // ////////// // if the movie has a movie preview, use that as the file preview; otherwise use a thumbnail // of the movie poster frame as the file preview if (QTInfo_MovieHasPreview(theMovie)) myPreviewType = MovieAID; else myPreviewType = kQTFileTypePicture; ////////// // // construct the 'pnot' atom // ////////// // fill in the 'pnot' atom header myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + sizeof(myPNOTRecord)); myAtomHeader[1] = EndianU32_NtoB(ShowFilePreviewComponentType); // fill in the 'pnot' atom data GetDateTime(&myModDate); myPNOTRecord.modDate = EndianU32_NtoB(myModDate); // the modification time of the preview myPNOTRecord.version = EndianS16_NtoB(0); // version number; must be 0 myPNOTRecord.resType = EndianU32_NtoB(myPreviewType); // atom type containing preview myPNOTRecord.resID = EndianS16_NtoB(1); // the 1-based index of the atom of the specified type to use ////////// // // write the 'pnot' atom at the end of the data fork // ////////// // get the current logical end-of-file and extend it by the desired amount myErr = GetEOF(theRefNum, &myEOF); if (myErr != noErr) goto bail; myErr = SetEOF(theRefNum, myEOF + sizeof(myAtomHeader) + sizeof(myPNOTRecord)); if (myErr != noErr) goto bail; // set the file mark myErr = SetFPos(theRefNum, fsFromStart, myEOF); if (myErr != noErr) goto bail; // write the atom header into the file mySize = sizeof(myAtomHeader); myErr = FSWrite(theRefNum, &mySize, myAtomHeader); if (myErr != noErr) goto bail; // write the atom data into the file mySize = sizeof(myPNOTRecord); myErr = FSWrite(theRefNum, &mySize, &myPNOTRecord); if (myErr != noErr) goto bail; ////////// // // write the preview data atom at the end of the data fork // ////////// if (myPreviewType == MovieAID) { // in theory, we don't need to do anything here, since our 'pnot' atom points // to the 'moov' atom; in practice, this doesn't work correctly (it seems like // a bug in StandardGetFilePreview) } if (myPreviewType == kQTFileTypePicture) { PicHandle myPicture = NULL; PicHandle myThumbnail = NULL; // get the poster frame picture myPicture = GetMoviePosterPict(theMovie); if (myPicture != NULL) { // create a thumbnail myThumbnail = (PicHandle)NewHandleClear(4); if (myThumbnail != NULL) { myErr = MakeThumbnailFromPicture(myPicture, 0, myThumbnail, theProgressProc); if (myErr == noErr) { myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + GetHandleSize((Handle)myThumbnail)); myAtomHeader[1] = EndianU32_NtoB(myPreviewType); // write the atom header into the file mySize = sizeof(myAtomHeader); myErr = FSWrite(theRefNum, &mySize, myAtomHeader); if (myErr == noErr) { // write the atom data into the file mySize = GetHandleSize((Handle)myThumbnail); myErr = FSWrite(theRefNum, &mySize, *myThumbnail); } } KillPicture(myThumbnail); } KillPicture(myPicture); } } #if 0 // here's how you'd add a text preview; note that the text is hard-coded here.... if (myPreviewType == kQTFileTypeText) { char myText[] = "The penguin gradually appears from the mist of the ice floe."; myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + strlen(myText)); myAtomHeader[1] = EndianU32_NtoB(myPreviewType); // write the atom header into the file mySize = sizeof(myAtomHeader); myErr = FSWrite(theRefNum, &mySize, myAtomHeader); if (myErr != noErr) goto bail; // write the atom data into the file mySize = strlen(myText); myErr = FSWrite(theRefNum, &mySize, myText); if (myErr != noErr) goto bail; } #endif #if TARGET_OS_MAC if (myErr == noErr) { short myVolNum; // flush the volume myErr = GetVRefNum(theRefNum, &myVolNum); if (myErr != noErr) goto bail; myErr = FlushVol(NULL, myVolNum); } #endif bail: return(myErr); }
void TkpDisplayMenuButton( ClientData clientData) /* Information about widget. */ { TkMenuButton *butPtr = (TkMenuButton *) clientData; Tk_Window tkwin = butPtr->tkwin; TkWindow * winPtr; Pixmap pixmap; MacMenuButton * mbPtr = (MacMenuButton *) butPtr; GWorldPtr dstPort; CGrafPtr saveWorld; GDHandle saveDevice; int hasImageOrBitmap = 0; int width, height; int err; ControlButtonGraphicAlignment theAlignment; Rect paneRect, cntrRect; butPtr->flags &= ~REDRAW_PENDING; if ((butPtr->tkwin == NULL) || !Tk_IsMapped(tkwin)) { return; } pixmap = ( Pixmap )Tk_WindowId(tkwin); GetGWorld(&saveWorld, &saveDevice); dstPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin)); SetGWorld(dstPort, NULL); TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin)); winPtr=(TkWindow *)butPtr->tkwin; paneRect.left=winPtr->privatePtr->xOff; paneRect.top=winPtr->privatePtr->yOff; paneRect.right=paneRect.left+Tk_Width(butPtr->tkwin)-1; paneRect.bottom=paneRect.top+Tk_Height(butPtr->tkwin)-1; cntrRect=paneRect; cntrRect.left+=butPtr->inset; cntrRect.top+=butPtr->inset; cntrRect.right-=butPtr->inset; cntrRect.bottom-=butPtr->inset; if (mbPtr->userPane) { MenuButtonControlParams params; bzero(¶ms, sizeof(params)); ComputeMenuButtonControlParams(butPtr, ¶ms ); if (bcmp(¶ms,&mbPtr->params,sizeof(params))) { if (mbPtr->userPane) { DisposeControl(mbPtr->userPane); mbPtr->userPane = NULL; mbPtr->control = NULL; } } } if (!mbPtr->userPane) { if (MenuButtonInitControl(mbPtr,&paneRect,&cntrRect ) ) { fprintf(stderr,"Init Control failed\n" ); return; } } SetControlBounds(mbPtr->userPane,&paneRect); SetControlBounds(mbPtr->control,&cntrRect); /* * We need to cache the title and its style */ if (!(mbPtr->flags&2)) { ControlTitleParams titleParams; int titleChanged; int styleChanged; ComputeControlTitleParams(butPtr,&titleParams); CompareControlTitleParams(&titleParams,&mbPtr->titleParams, &titleChanged,&styleChanged); if (titleChanged) { CFStringRef cf; cf = CFStringCreateWithCString(NULL, titleParams.title, kCFStringEncodingUTF8); if (hasImageOrBitmap) { SetControlTitleWithCFString(mbPtr->control, cf); } else { SetMenuItemTextWithCFString(mbPtr->menuRef, 1, cf); } CFRelease(cf); bcopy(titleParams.title,mbPtr->titleParams.title,titleParams.len+1); mbPtr->titleParams.len = titleParams.len; } if ((titleChanged||styleChanged) && titleParams .len) { if (hasImageOrBitmap) { if ((err=SetControlFontStyle(mbPtr->control,&titleParams.style))!=noErr) { fprintf(stderr,"SetControlFontStyle failed %d\n", err); return; } } bcopy(&titleParams.style,&mbPtr->titleParams.style,sizeof(titleParams.style)); } } if (butPtr->image != None) { Tk_SizeOfImage(butPtr->image, &width, &height); hasImageOrBitmap = 1; } else if (butPtr->bitmap != None) { Tk_SizeOfBitmap(butPtr->display, butPtr->bitmap, &width, &height); hasImageOrBitmap = 1; } if (hasImageOrBitmap) { mbPtr->picParams.srcRect.right = width; mbPtr->picParams.srcRect.bottom = height; /* Set the flag to circumvent clipping and bounds problems with OS 10.0.4 */ tkPictureIsOpen = 1; if (!(mbPtr->bevelButtonContent.u.picture = OpenCPicture(&mbPtr->picParams)) ) { fprintf(stderr,"OpenCPicture failed\n"); } /* * TO DO - There is one case where XCopyPlane calls CopyDeepMask, * which does not get recorded in the picture. So the bitmap code * will fail in that case. */ if (butPtr->image != NULL) { Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap, 0, 0); } else { XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, NULL, 0, 0, (unsigned int) width, (unsigned int) height, 0, 0, 1); } ClosePicture(); tkPictureIsOpen = 0; if ( (err=SetControlData(mbPtr->control, kControlButtonPart, kControlBevelButtonContentTag, sizeof(ControlButtonContentInfo), (char *) &mbPtr->bevelButtonContent)) != noErr ) { fprintf(stderr,"SetControlData BevelButtonContent failed, %d\n", err ); } switch (butPtr->anchor) { case TK_ANCHOR_N: theAlignment = kControlBevelButtonAlignTop; break; case TK_ANCHOR_NE: theAlignment = kControlBevelButtonAlignTopRight; break; case TK_ANCHOR_E: theAlignment = kControlBevelButtonAlignRight; break; case TK_ANCHOR_SE: theAlignment = kControlBevelButtonAlignBottomRight; break; case TK_ANCHOR_S: theAlignment = kControlBevelButtonAlignBottom; break; case TK_ANCHOR_SW: theAlignment = kControlBevelButtonAlignBottomLeft; break; case TK_ANCHOR_W: theAlignment = kControlBevelButtonAlignLeft; break; case TK_ANCHOR_NW: theAlignment = kControlBevelButtonAlignTopLeft; break; case TK_ANCHOR_CENTER: theAlignment = kControlBevelButtonAlignCenter; break; } if ((err=SetControlData(mbPtr->control, kControlButtonPart, kControlBevelButtonGraphicAlignTag, sizeof(ControlButtonGraphicAlignment), (char *) &theAlignment)) != noErr ) { fprintf(stderr,"SetControlData BevelButtonGraphicAlign failed, %d\n", err ); } } if (butPtr->flags & GOT_FOCUS) { HiliteControl(mbPtr->control,kControlButtonPart); } else { HiliteControl(mbPtr->control,kControlNoPart); } UpdateControlColors(mbPtr); if (mbPtr->flags&2) { ShowControl(mbPtr->control); ShowControl(mbPtr->userPane); mbPtr->flags ^= 2; } else { Draw1Control(mbPtr->userPane); SetControlVisibility(mbPtr->control, true, true); } if (hasImageOrBitmap) { KillPicture(mbPtr->bevelButtonContent.u.picture); } SetGWorld(saveWorld, saveDevice); }
void QTCmpr_CompressSequence (WindowObject theWindowObject) { ComponentInstance myComponent = NULL; GWorldPtr myImageWorld = NULL; // the graphics world we draw the images in PixMapHandle myPixMap = NULL; Movie mySrcMovie = NULL; Track mySrcTrack = NULL; Movie myDstMovie = NULL; Track myDstTrack = NULL; Media myDstMedia = NULL; Rect myRect; PicHandle myPicture = NULL; CGrafPtr mySavedPort = NULL; GDHandle mySavedDevice = NULL; SCTemporalSettings myTimeSettings; SCDataRateSettings myRateSettings; FSSpec myFile; Boolean myIsSelected = false; Boolean myIsReplacing = false; short myRefNum = -1; StringPtr myMoviePrompt = QTUtils_ConvertCToPascalString(kQTCSaveMoviePrompt); StringPtr myMovieFileName = QTUtils_ConvertCToPascalString(kQTCSaveMovieFileName); MatrixRecord myMatrix; ImageDescriptionHandle myImageDesc = NULL; TimeValue myCurMovieTime = 0L; TimeValue myOrigMovieTime = 0L; // current movie time, when compression is begun short myFrameNum; long myFlags = 0L; long myNumFrames = 0L; long mySrcMovieDuration = 0L; // duration of source movie OSErr myErr = noErr; #if USE_ASYNC_COMPRESSION ICMCompletionProcRecord myICMComplProcRec; ICMCompletionProcRecordPtr myICMComplProcPtr = NULL; OSErr myICMComplProcErr = noErr; myICMComplProcRec.completionProc = NULL; myICMComplProcRec.completionRefCon = 0L; #endif if (theWindowObject == NULL) goto bail; ////////// // // get the movie and the first video track in the movie // ////////// mySrcMovie = (**theWindowObject).fMovie; if (mySrcMovie == NULL) goto bail; mySrcTrack = GetMovieIndTrackType(mySrcMovie, 1, VideoMediaType, movieTrackMediaType); if (mySrcTrack == NULL) goto bail; // stop the movie; we don't want it to be playing while we're (re)compressing it SetMovieRate(mySrcMovie, (Fixed)0L); // get the current movie time, when compression is begun; we'll restore this later myOrigMovieTime = GetMovieTime(mySrcMovie, NULL); ////////// // // configure and display the Standard Image Compression dialog box // ////////// // open an instance of the Standard Image Compression dialog component myComponent = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType); if (myComponent == NULL) goto bail; // turn off "best depth" option in the compression dialog, because all of our // buffering is done at 32-bits (regardless of the depth of the source data) // // a more ambitious approach would be to loop through each of the video sample // descriptions in each of the video tracks looking for the deepest depth, and // using that for the best depth; better yet, we could find out which compressors // were used and set one of those as the default in the compression dialog SCGetInfo(myComponent, scPreferenceFlagsType, &myFlags); myFlags &= ~scShowBestDepth; SCSetInfo(myComponent, scPreferenceFlagsType, &myFlags); // because we are recompressing a movie that may have a variable frame rate, // we want to allow the user to leave the frame rate text field blank (in which // case we can preserve the frame durations of the source movie); if the user // enters a number, we will resample the movie at a new frame rate; if we don't // clear this flag, the compression dialog will not allow zero in the frame rate field // // NOTE: we could have set this flag above when we cleared the scShowBestDepth flag; // it is done here for clarity. SCGetInfo(myComponent, scPreferenceFlagsType, &myFlags); myFlags |= scAllowZeroFrameRate; SCSetInfo(myComponent, scPreferenceFlagsType, &myFlags); // get the number of video frames in the movie myNumFrames = QTUtils_GetFrameCount(mySrcTrack); // get the bounding rectangle of the movie, create a 32-bit GWorld with those // dimensions, and draw the movie poster picture into it; this GWorld will be // used for the test image in the compression dialog box and for rendering movie // frames myPicture = GetMoviePosterPict(mySrcMovie); if (myPicture == NULL) goto bail; GetMovieBox(mySrcMovie, &myRect); myErr = NewGWorld(&myImageWorld, 32, &myRect, NULL, NULL, 0L); if (myErr != noErr) goto bail; // get the pixmap of the GWorld; we'll lock the pixmap, just to be safe myPixMap = GetGWorldPixMap(myImageWorld); if (!LockPixels(myPixMap)) goto bail; // draw the movie poster image into the GWorld GetGWorld(&mySavedPort, &mySavedDevice); SetGWorld(myImageWorld, NULL); EraseRect(&myRect); DrawPicture(myPicture, &myRect); KillPicture(myPicture); SetGWorld(mySavedPort, mySavedDevice); // set the picture to be displayed in the dialog box; passing NULL for the rect // means use the entire image; passing 0 for the flags means to use the default // system method of displaying the test image, which is currently a combination // of cropping and scaling; personally, I prefer scaling (your mileage may vary) SCSetTestImagePixMap(myComponent, myPixMap, NULL, scPreferScaling); // install the custom procs, if requested // we can install two kinds of custom procedures for use in connection with // the standard dialog box: (1) a modal-dialog filter function, and (2) a hook // function to handle the custom button in the dialog box if (gUseExtendedProcs) QTCmpr_InstallExtendedProcs(myComponent, (long)myPixMap); // set up some default settings for the compression dialog SCDefaultPixMapSettings(myComponent, myPixMap, true); // clear out the default frame rate chosen by Standard Compression (a frame rate // of 0 means to use the rate of the source movie) myErr = SCGetInfo(myComponent, scTemporalSettingsType, &myTimeSettings); if (myErr != noErr) goto bail; myTimeSettings.frameRate = 0; SCSetInfo(myComponent, scTemporalSettingsType, &myTimeSettings); // request image compression settings from the user; in other words, put up the dialog box myErr = SCRequestSequenceSettings(myComponent); if (myErr == scUserCancelled) goto bail; // get a copy of the temporal settings the user entered; we'll need them for some // of our calculations (in a simpler application, we'd never have to look at them) SCGetInfo(myComponent, scTemporalSettingsType, &myTimeSettings); ////////// // // adjust the data rate [to be supplied][relevant only for movies that have sound tracks] // ////////// ////////// // // adjust the sample count // // if the user wants to resample the frame rate of the movie (as indicated a non-zero // value in the frame rate field) calculate the number of frames and duration for the new movie // ////////// if (myTimeSettings.frameRate != 0) { long myDuration = GetMovieDuration(mySrcMovie); long myTimeScale = GetMovieTimeScale(mySrcMovie); float myFloat = (float)myDuration * myTimeSettings.frameRate; myNumFrames = myFloat / myTimeScale / 65536; if (myNumFrames == 0) myNumFrames = 1; } ////////// // // get the name and location of the new movie file // ////////// // prompt the user for a file to put the compressed image into; in theory, the name // should have a file extension appropriate to the type of compressed data selected by the user; // this is left as an exercise for the reader QTFrame_PutFile(myMoviePrompt, myMovieFileName, &myFile, &myIsSelected, &myIsReplacing); if (!myIsSelected) goto bail; // delete any existing file of that name if (myIsReplacing) { myErr = DeleteMovieFile(&myFile); if (myErr != noErr) goto bail; } ////////// // // create the target movie // ////////// myErr = CreateMovieFile(&myFile, sigMoviePlayer, smSystemScript, createMovieFileDeleteCurFile | createMovieFileDontCreateResFile, &myRefNum, &myDstMovie); if (myErr != noErr) goto bail; // create a new video movie track with the same dimensions as the entire source movie myDstTrack = NewMovieTrack(myDstMovie, (long)(myRect.right - myRect.left) << 16, (long)(myRect.bottom - myRect.top) << 16, kNoVolume); if (myDstTrack == NULL) goto bail; // create a media for the new track with the same time scale as the source movie; // because the time scales are the same, we don't have to do any time scale conversions. myDstMedia = NewTrackMedia(myDstTrack, VIDEO_TYPE, GetMovieTimeScale(mySrcMovie), 0, 0); if (myDstMedia == NULL) goto bail; // copy the user data and settings from the source to the dest movie CopyMovieSettings(mySrcMovie, myDstMovie); // set movie matrix to identity and clear the movie clip region (because the conversion // process transforms and composites all video tracks into one untransformed video track) SetIdentityMatrix(&myMatrix); SetMovieMatrix(myDstMovie, &myMatrix); SetMovieClipRgn(myDstMovie, NULL); // set the movie to highest quality imaging SetMoviePlayHints(mySrcMovie, hintsHighQuality, hintsHighQuality); myImageDesc = (ImageDescriptionHandle)NewHandleClear(sizeof(ImageDescription)); if (myImageDesc == NULL) goto bail; // prepare for adding frames to the movie myErr = BeginMediaEdits(myDstMedia); if (myErr != noErr) goto bail; ////////// // // compress the image sequence // // we are going to step through the source movie, compress each frame, and then add // the compressed frame to the destination movie // ////////// myErr = SCCompressSequenceBegin(myComponent, myPixMap, NULL, &myImageDesc); if (myErr != noErr) goto bail; #if USE_ASYNC_COMPRESSION myFlags = codecFlagUpdatePrevious + codecFlagUpdatePreviousComp + codecFlagLiveGrab; SCSetInfo(myComponent, scCodecFlagsType, &myFlags); #endif // clear out our image GWorld and set movie to draw into it SetGWorld(myImageWorld, NULL); EraseRect(&myRect); SetMovieGWorld(mySrcMovie, myImageWorld, GetGWorldDevice(myImageWorld)); // set current time value to beginning of the source movie myCurMovieTime = 0; // get a value we'll need inside the loop mySrcMovieDuration = GetMovieDuration(mySrcMovie); // loop through all of the interesting times we counted above for (myFrameNum = 0; myFrameNum < myNumFrames; myFrameNum++) { short mySyncFlag; TimeValue myDuration; long myDataSize; Handle myCompressedData; ////////// // // get the next frame of the source movie // ////////// // if we are resampling the movie, step to the next frame if (myTimeSettings.frameRate) { myCurMovieTime = myFrameNum * mySrcMovieDuration / (myNumFrames - 1); myDuration = mySrcMovieDuration / myNumFrames; } else { OSType myMediaType = VIDEO_TYPE; myFlags = nextTimeMediaSample; // if this is the first frame, include the frame we are currently on if (myFrameNum == 0) myFlags |= nextTimeEdgeOK; // if we are maintaining the frame durations of the source movie, // skip to the next interesting time and get the duration for that frame GetMovieNextInterestingTime(mySrcMovie, myFlags, 1, &myMediaType, myCurMovieTime, 0, &myCurMovieTime, &myDuration); } SetMovieTimeValue(mySrcMovie, myCurMovieTime); MoviesTask(mySrcMovie, 0); MoviesTask(mySrcMovie, 0); MoviesTask(mySrcMovie, 0); // if data rate constraining is being done, tell Standard Compression the // duration of the current frame in milliseconds; we only need to do this // if the frames have variable durations if (!SCGetInfo(myComponent, scDataRateSettingsType, &myRateSettings)) { myRateSettings.frameDuration = myDuration * 1000 / GetMovieTimeScale(mySrcMovie); SCSetInfo(myComponent, scDataRateSettingsType, &myRateSettings); } ////////// // // compress the current frame of the source movie and add it to the destination movie // ////////// // if SCCompressSequenceFrame completes successfully, myCompressedData will hold // a handle to the newly-compressed image data and myDataSize will be the size of // the compressed data (which will usually be different from the size of the handle); // also mySyncFlag will be a value that that indicates whether or not the frame is a // key frame (and which we pass directly to AddMediaSample); note that we do not need // to dispose of myCompressedData, since SCCompressSequenceEnd will do that for us #if !USE_ASYNC_COMPRESSION myErr = SCCompressSequenceFrame(myComponent, myPixMap, &myRect, &myCompressedData, &myDataSize, &mySyncFlag); if (myErr != noErr) goto bail; #else if (myICMComplProcPtr == NULL) { myICMComplProcRec.completionProc = NewICMCompletionProc(QTCmpr_CompletionProc); myICMComplProcRec.completionRefCon = (long)&myICMComplProcErr; myICMComplProcPtr = &myICMComplProcRec; } myICMComplProcErr = kAsyncDefaultValue; myErr = SCCompressSequenceFrameAsync(myComponent, myPixMap, &myRect, &myCompressedData, &myDataSize, &mySyncFlag, myICMComplProcPtr); if (myErr != noErr) goto bail; // spin our wheels while we're waiting for the compress call to complete while (myICMComplProcErr == kAsyncDefaultValue) { EventRecord myEvent; WaitNextEvent(0, &myEvent, 60, NULL); SCAsyncIdle(myComponent); } myErr = myICMComplProcErr; #endif myErr = AddMediaSample(myDstMedia, myCompressedData, 0, myDataSize, myDuration, (SampleDescriptionHandle)myImageDesc, 1, mySyncFlag, NULL); if (myErr != noErr) goto bail; } // close the compression sequence; this will dispose of the image description // and compressed data handles allocated by SCCompressSequenceBegin SCCompressSequenceEnd(myComponent); ////////// // // add the media data to the destination movie // ////////// myErr = EndMediaEdits(myDstMedia); if (myErr != noErr) goto bail; InsertMediaIntoTrack(myDstTrack, 0, 0, GetMediaDuration(myDstMedia), fixed1); // add the movie resource to the dst movie file. myErr = AddMovieResource(myDstMovie, myRefNum, NULL, NULL); if (myErr != noErr) goto bail; // flatten the movie data [to be supplied] // close the movie file CloseMovieFile(myRefNum); bail: // close the Standard Compression component if (myComponent != NULL) CloseComponent(myComponent); if (mySrcMovie != NULL) { // restore the source movie's original graphics port and device SetMovieGWorld(mySrcMovie, mySavedPort, mySavedDevice); // restore the source movie's original movie time SetMovieTimeValue(mySrcMovie, myOrigMovieTime); } // restore the original graphics port and device SetGWorld(mySavedPort, mySavedDevice); // delete the GWorld we were drawing frames into if (myImageWorld != NULL) DisposeGWorld(myImageWorld); #if USE_ASYNC_COMPRESSION if (myICMComplProcRec.completionProc != NULL) DisposeICMCompletionUPP(myICMComplProcRec.completionProc); #endif free(myMoviePrompt); free(myMovieFileName); }