static void QT_CreateMyVideoTrack(int rectx, int recty, ReportList *reports) { OSErr err = noErr; Rect trackFrame; // MatrixRecord myMatrix; trackFrame.top = 0; trackFrame.left = 0; trackFrame.bottom = recty; trackFrame.right = rectx; qtexport->theTrack = NewMovieTrack (qtexport->theMovie, FixRatio(trackFrame.right,1), FixRatio(trackFrame.bottom,1), 0); CheckError( GetMoviesError(), "NewMovieTrack error", reports ); // SetIdentityMatrix(&myMatrix); // ScaleMatrix(&myMatrix, fixed1, Long2Fix(-1), 0, 0); // TranslateMatrix(&myMatrix, 0, Long2Fix(trackFrame.bottom)); // SetMovieMatrix(qtexport->theMovie, &myMatrix); qtexport->theMedia = NewTrackMedia (qtexport->theTrack, VideoMediaType, qtdata->kVideoTimeScale, nil, 0); CheckError( GetMoviesError(), "NewTrackMedia error", reports ); err = BeginMediaEdits (qtexport->theMedia); CheckError( err, "BeginMediaEdits error", reports ); QT_StartAddVideoSamplesToMedia (&trackFrame, rectx, recty, reports); }
bool qtCanvas::Impl::setupTrack() { mTrack = NewMovieTrack(mMovie, FixRatio(mWidth,1), FixRatio(mHeight,1), (short)kNoVolume); if (!CheckMoviesError("NewMovieTrack")) return false; SCTemporalSettings temporal; SCGetInfo(mSCComponent, scTemporalSettingsType, &temporal); mMedia = NewTrackMedia(mTrack, VideoMediaType, (TimeScale)temporal.frameRate, nil, 0); if (!CheckMoviesError("NewTrackMedia" )) return false; MediaHandler mh = GetMediaHandler(mMedia); if (!CheckMoviesError("GetMediaHandler")) return false; ComponentResult err; err = MediaSetGraphicsMode(mh, graphicsModePreMulColorAlpha, NULL); if (!CheckError(err, "MediaSetGraphicsMode")) return false; BeginMediaEdits(mMedia); if (!CheckMoviesError("BeginMediaEdits" )) return false; return true; }
void QTVideo_CreateMyVideoTrack(Movie theMovie) { Track theTrack; Media theMedia; OSErr err = noErr; Rect trackFrame = {0,0,100,320}; theTrack = NewMovieTrack (theMovie, FixRatio(trackFrame.right,1), FixRatio(trackFrame.bottom,1), kNoVolume); CheckError( GetMoviesError(), "NewMovieTrack error" ); theMedia = NewTrackMedia (theTrack, VideoMediaType, kVideoTimeScale, /* Video Time Scale */ nil, 0); CheckError( GetMoviesError(), "NewTrackMedia error" ); err = BeginMediaEdits (theMedia); CheckError( err, "BeginMediaEdits error" ); QTVideo_AddVideoSamplesToMedia (theMedia, &trackFrame); err = EndMediaEdits (theMedia); CheckError( err, "EndMediaEdits error" ); err = InsertMediaIntoTrack (theTrack, kTrackStart,/* track start time */ kMediaStart, /* media start time */ GetMediaDuration (theMedia), fixed1); CheckError( err, "InsertMediaIntoTrack error" ); }
void LCD_resize(Lcd *x) { Rect r; short hor,ver; #ifdef debug post("LCD_Resize"); #endif r = x->lcd_box.b_rect; hor = x->cols = FixRound(FixRatio(((r.right-r.left-(2*BORDER_WIDTH))),x->f_width)); ver = x->rows = FixRound(FixRatio(((r.bottom-r.top-(2*BORDER_HEIGHT))),x->f_height)); #ifdef FORCEDResize x->lcd_box.b_rect.right = r.left + (2*BORDER_WIDTH) + hor*x->f_width; x->lcd_box.b_rect.bottom = r.top + (2*BORDER_HEIGHT) + ver*x->f_height; #endif if (x->lcd_region) DisposeRgn(x->lcd_region); x->lcd_oldRect = r = x->lcd_box.b_rect; InsetRect(&r,1,1); x->lcd_region = NewRgn(); RectRgn(x->lcd_region,&r); /* DDZ simpler way to make a rectangular region */ }
OSErr QTDR_CreateTrackInRAM (Movie theMovie) { Track myTrack = NULL; Media myMedia = NULL; Handle myDataRef = NULL; unsigned long myAtomHeader[2]; OSErr myErr = noErr; if (theMovie == NULL) return(paramErr); myDataRef = NewHandleClear(sizeof(Handle) + sizeof(char)); if (myDataRef == NULL) return(MemError()); myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader)); myAtomHeader[1] = EndianU32_NtoB(kDataRefExtensionInitializationData); myErr = PtrAndHand(myAtomHeader, myDataRef, sizeof(myAtomHeader)); if (myErr != noErr) goto bail; // create the movie track and media myTrack = NewMovieTrack(theMovie, FixRatio(kVideoTrackWidth, 1), FixRatio(kVideoTrackHeight, 1), kNoVolume); myErr = GetMoviesError(); if (myErr != noErr) goto bail; myMedia = NewTrackMedia(myTrack, VideoMediaType, kVideoTimeScale, myDataRef, HandleDataHandlerSubType); myErr = GetMoviesError(); if (myErr != noErr) goto bail; // create the media samples myErr = BeginMediaEdits(myMedia); if (myErr != noErr) goto bail; myErr = QTDR_AddVideoSamplesToMedia(myMedia, kVideoTrackWidth, kVideoTrackHeight); if (myErr != noErr) goto bail; myErr = EndMediaEdits(myMedia); if (myErr != noErr) goto bail; // add the media to the track myErr = InsertMediaIntoTrack(myTrack, 0, 0, GetMediaDuration(myMedia), fixed1); bail: if (myDataRef != NULL) DisposeHandle(myDataRef); return(myErr); }
/*------------------------------------ deferred_Rate ---*/ static Pvoid deferred_Rate(QtPtr xx, PSymbol ss, short argc, PAtom argv) { #pragma unused(argc, ss) EnterCallback(); if (xx->fCurrentMovie) { short numerator = short(argv->a_w.w_long); short denominator = short((argv + 1)->a_w.w_long); if (! denominator) denominator = 1; xx->fCurrentRate = FixRatio(numerator, denominator); SetMovieRate(xx->fCurrentMovie, xx->fCurrentRate); xx->fStopSignalled = false; qtAdjustController(xx); } else { LOG_ERROR_1(OUTPUT_PREFIX "no movies loaded") SignalError(xx); } ExitMaxMessageHandler() } /* deferred_Rate */
static void init_header(struct ExtSoundHeader *header, Ptr samples, unsigned int nsamples, unsigned int channels, unsigned int speed, unsigned int bits) { double dspeed = speed; header->samplePtr = samples; header->numChannels = channels; header->sampleRate = FixRatio(speed, 1); header->loopStart = 0; header->loopEnd = 0; header->encode = extSH; header->baseFrequency = kMiddleC; header->numFrames = nsamples; dtox80(&dspeed, &header->AIFFSampleRate); header->markerChunk = 0; header->instrumentChunks = 0; header->AESRecording = 0; header->sampleSize = bits; header->futureUse1 = 0; header->futureUse2 = 0; header->futureUse3 = 0; header->futureUse4 = 0; }
RGBColor GetRGBColor(double val) { RGBColor rgb; HSVColor hsv; hsv.hue = (SmallFract)Fix2SmallFract(FixRatio(32768*val*.8,32768)); //hsv.hue = (SmallFract)Fix2SmallFract(FixRatio(32767*val*.8,32767)); // tweak to change color scheme hsv.saturation = (SmallFract)0xFFFF; hsv.value = (SmallFract)0xFFFF; HSV2RGB(&hsv,&rgb); return rgb; }
void UIDisplayBase::Sanitise(void) { m_refreshRate = FixRate(m_refreshRate); m_aspectRatio = FixRatio((double)m_physicalSize.width() / (double)m_physicalSize.height()); if (!IsStandardScreenRatio(m_aspectRatio)) { // try to fix aspect ratios that are based on innacurate EDID physical size data (EDID only provides // centimeter accuracy by default). Use the raw pixel aspect ratio as a hint. double rawpar = (double)m_pixelSize.width() / (double)m_pixelSize.height(); if (IsStandardScreenRatio(rawpar) && (abs(m_aspectRatio - rawpar) < 0.1)) { LOG(VB_GENERAL, LOG_INFO, QString("Adjusting screen aspect ratio from %1 to %2").arg(m_aspectRatio).arg(rawpar)); m_aspectRatio = rawpar; } } m_pixelAspectRatio = FixRatio(((double)m_pixelSize.width() / (double)m_pixelSize.height()) / m_aspectRatio); LOG(VB_GENERAL, LOG_INFO, QString("Using screen %1 of %2") .arg(m_screen + 1).arg(m_screenCount)); LOG(VB_GENERAL, LOG_INFO, QString("Screen size : %1mm x %2mm (aspect %3)") .arg(m_physicalSize.width()).arg(m_physicalSize.height()).arg(m_aspectRatio)); LOG(VB_GENERAL, LOG_INFO, QString("Screen size : %1px x %2px") .arg(m_pixelSize.width()).arg(m_pixelSize.height())); LOG(VB_GENERAL, LOG_INFO, QString("Refresh rate: %1Hz").arg(m_refreshRate)); if (m_variableRefreshRate) { LOG(VB_GENERAL, LOG_INFO, "Available rate: Any"); } else { QList<UIDisplayMode>::iterator it = m_modes.begin(); for ( ; it != m_modes.end(); ++it) LOG(VB_GENERAL, LOG_INFO, QString("Available rate: %1Hz%2").arg((*it).m_rate).arg((*it).m_interlaced ? QString(" Interlaced") : "")); } if (m_originalRefreshRate < 0.0f) m_originalRefreshRate = m_refreshRate; }
static void MacQTOpenVideoComponent(ComponentInstance *rci) { OSStatus err; ComponentInstance ci; ci = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType); CheckError((ci == nil), 01); CFDataRef data; data = (CFDataRef) CFPreferencesCopyAppValue(CFSTR("QTVideoSetting"), kCFPreferencesCurrentApplication); if (data) { CFIndex len; Handle hdl; len = CFDataGetLength(data); hdl = NewHandleClear((Size) len); if (MemError() == noErr) { HLock(hdl); CFDataGetBytes(data, CFRangeMake(0, len), (unsigned char *) *hdl); err = SCSetInfo(ci, scSettingsStateType, &hdl); DisposeHandle(hdl); } CFRelease(data); } else { SCSpatialSettings ss; SCTemporalSettings ts; ss.codecType = kAnimationCodecType; ss.codec = 0; ss.depth = 16; ss.spatialQuality = codecMaxQuality; err = SCSetInfo(ci, scSpatialSettingsType, &ss); ts.frameRate = FixRatio(Memory.ROMFramesPerSecond, 1); ts.keyFrameRate = Memory.ROMFramesPerSecond; ts.temporalQuality = codecMaxQuality; err = SCSetInfo(ci, scTemporalSettingsType, &ts); } *rci = ci; }
void QFontEngineMac::getUnscaledGlyph(glyph_t glyph, QPainterPath *path, glyph_metrics_t *metrics) { ATSUStyle unscaledStyle; ATSUCreateAndCopyStyle(style, &unscaledStyle); int emSquare = properties().emSquare.toInt(); const int maxAttributeCount = 4; ATSUAttributeTag tags[maxAttributeCount + 1]; ByteCount sizes[maxAttributeCount + 1]; ATSUAttributeValuePtr values[maxAttributeCount + 1]; int attributeCount = 0; Fixed size = FixRatio(emSquare, 1); tags[attributeCount] = kATSUSizeTag; sizes[attributeCount] = sizeof(size); values[attributeCount] = &size; ++attributeCount; Q_ASSERT(attributeCount < maxAttributeCount + 1); OSStatus err = ATSUSetAttributes(unscaledStyle, attributeCount, tags, sizes, values); Q_ASSERT(err == noErr); Q_UNUSED(err); GlyphID atsuGlyph = glyph; ATSGlyphScreenMetrics atsuMetrics; ATSUGlyphGetScreenMetrics(unscaledStyle, 1, &atsuGlyph, 0, /* iForcingAntiAlias =*/ false, /* iAntiAliasSwitch =*/true, &atsuMetrics); metrics->width = int(atsuMetrics.width); metrics->height = int(atsuMetrics.height); metrics->x = QFixed::fromReal(atsuMetrics.topLeft.x); metrics->y = -QFixed::fromReal(atsuMetrics.topLeft.y); metrics->xoff = QFixed::fromReal(atsuMetrics.deviceAdvance.x); metrics->yoff = QFixed::fromReal(atsuMetrics.deviceAdvance.y); QFixedPoint p; ::addGlyphsToPath(unscaledStyle, &glyph, &p, 1, path); ATSUDisposeStyle(unscaledStyle); }
OSStatus CreateATSUIStyleFromFontFullNameAndSize (const char *fontName, int fontSize, ATSUStyle *theStyle) { OSStatus err; ATSUStyle localStyle; ATSUFontID atsuFont; Fixed atsuSize; ATSUAttributeTag theTags[] = { kATSUFontTag, kATSUSizeTag }; ByteCount theSizes[] = { sizeof(ATSUFontID), sizeof(Fixed) }; ATSUAttributeValuePtr theValues[] = { NULL, NULL }; atsuFont = 0; atsuSize = FixRatio(fontSize, 1); localStyle = NULL; theValues[0] = &atsuFont; theValues[1] = &atsuSize; err = ATSUFindFontFromName(fontName, strlen(fontName), kFontFullName, kFontNoPlatform, kFontNoScript, kFontNoLanguage, &atsuFont); if (err == noErr) { err = ATSUCreateStyle(&localStyle); if (err == noErr) { err = ATSUSetAttributes(localStyle, sizeof(theTags) / sizeof(theTags[0]), theTags, theSizes, theValues); if (err == noErr) { *theStyle = localStyle; return (noErr); } } } if (localStyle != NULL) err = ATSUDisposeStyle(localStyle); return (err); }
void MacQTStartRecording(char *path) { OSStatus err; CFStringRef str; CFURLRef url; memset(&sqt, 0, sizeof(sqt)); // storage str = CFStringCreateWithCString(kCFAllocatorDefault, path, MAC_PATH_ENCODING); url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, str, kCFURLPOSIXPathStyle, false); err = QTNewDataReferenceFromCFURL(url, 0, &(sqt.dataRef), &(sqt.dataRefType)); CheckError(err, 21); CFRelease(url); CFRelease(str); err = CreateMovieStorage(sqt.dataRef, sqt.dataRefType, 'TVOD', smSystemScript, createMovieFileDeleteCurFile | newMovieActive, &(sqt.dataHandler), &(sqt.movie)); CheckError(err, 22); // video MacQTOpenVideoComponent(&(sqt.vci)); SCTemporalSettings ts; err = SCGetInfo(sqt.vci, scTemporalSettingsType, &ts); ts.frameRate = FixRatio(Memory.ROMFramesPerSecond, 1); if (ts.keyFrameRate < 1) ts.keyFrameRate = Memory.ROMFramesPerSecond; sqt.keyFrame = sqt.keyFrameCount = ts.keyFrameRate; sqt.frameSkip = sqt.frameSkipCount = (macQTMovFlag & 0xFF00) >> 8; err = SCSetInfo(sqt.vci, scTemporalSettingsType, &ts); sqt.frame.top = 0; sqt.frame.left = 0; sqt.frame.right = ((macQTMovFlag & kMovDoubleSize) ? 2 : 1) * SNES_WIDTH; sqt.frame.bottom = ((macQTMovFlag & kMovDoubleSize) ? 2 : 1) * ((macQTMovFlag & kMovExtendedHeight) ? SNES_HEIGHT_EXTENDED : SNES_HEIGHT); sqt.pw = sqt.ph = 0; sqt.firstFrame = true; Rect rct; SetRect(&rct, 0, 0, SNES_WIDTH * 2, SNES_HEIGHT_EXTENDED * 2 + 4); InitGWorld(&(sqt.bw), &rct, 16); sqt.vTrack = NewMovieTrack(sqt.movie, FixRatio(sqt.frame.right, 1), FixRatio(sqt.frame.bottom, 1), kNoVolume); CheckError(GetMoviesError(), 23); sqt.vMedia = NewTrackMedia(sqt.vTrack, VideoMediaType, Memory.ROMFramesPerSecond, nil, 0); CheckError(GetMoviesError(), 24); err = BeginMediaEdits(sqt.vMedia); CheckError(err, 25); // sound sqt.soundDesc = (SoundDescriptionHandle) NewHandleClear(sizeof(SoundDescription)); CheckError(MemError(), 26); (**sqt.soundDesc).descSize = sizeof(SoundDescription); #ifdef __BIG_ENDIAN__ (**sqt.soundDesc).dataFormat = Settings.SixteenBitSound ? k16BitBigEndianFormat : k8BitOffsetBinaryFormat; #else (**sqt.soundDesc).dataFormat = Settings.SixteenBitSound ? k16BitLittleEndianFormat : k8BitOffsetBinaryFormat; #endif (**sqt.soundDesc).numChannels = Settings.Stereo ? 2 : 1; (**sqt.soundDesc).sampleSize = Settings.SixteenBitSound ? 16 : 8; (**sqt.soundDesc).sampleRate = (UnsignedFixed) FixRatio(Settings.SoundPlaybackRate, 1); sqt.samplesPerSec = Settings.SoundPlaybackRate / Memory.ROMFramesPerSecond; sqt.soundBufferSize = sqt.samplesPerSec; if (Settings.SixteenBitSound) sqt.soundBufferSize <<= 1; if (Settings.Stereo) sqt.soundBufferSize <<= 1; sqt.soundBuffer = NewHandleClear(sqt.soundBufferSize); CheckError(MemError(), 27); HLock(sqt.soundBuffer); sqt.sTrack = NewMovieTrack(sqt.movie, 0, 0, kFullVolume); CheckError(GetMoviesError(), 28); sqt.sMedia = NewTrackMedia(sqt.sTrack, SoundMediaType, Settings.SoundPlaybackRate, nil, 0); CheckError(GetMoviesError(), 29); err = BeginMediaEdits(sqt.sMedia); CheckError(err, 30); }
void QFontDatabase::load(const QFontPrivate *d, int script) { // sanity checks if(!qApp) qWarning("QFont: Must construct a QApplication before a QFont"); Q_ASSERT(script >= 0 && script < QUnicodeTables::ScriptCount); Q_UNUSED(script); QFontDef req = d->request; req.pixelSize = qt_mac_pixelsize(req, d->dpi); // set the point size to 0 to get better caching req.pointSize = 0; QFontCache::Key key = QFontCache::Key(req, QUnicodeTables::Common, d->screen); if(!(d->engineData = QFontCache::instance()->findEngineData(key))) { d->engineData = new QFontEngineData; QFontCache::instance()->insertEngineData(key, d->engineData); } else { d->engineData->ref.ref(); } if(d->engineData->engine) // already loaded return; // set it to the actual pointsize, so QFontInfo will do the right thing req.pointSize = qRound(qt_mac_pointsize(d->request, d->dpi)); QFontEngine *e = QFontCache::instance()->findEngine(key); if(!e && qt_enable_test_font && req.family == QLatin1String("__Qt__Box__Engine__")) { e = new QTestFontEngine(req.pixelSize); e->fontDef = req; } if(e) { e->ref.ref(); d->engineData->engine = e; return; // the font info and fontdef should already be filled } //find the font QStringList family_list = familyList(req); const char *stylehint = styleHint(req); if (stylehint) family_list << QLatin1String(stylehint); // add QFont::defaultFamily() to the list, for compatibility with // previous versions family_list << QApplication::font().defaultFamily(); ATSFontFamilyRef familyRef = 0; ATSFontRef fontRef = 0; QMutexLocker locker(fontDatabaseMutex()); QFontDatabasePrivate *db = privateDb(); if (!db->count) initializeDb(); for(int i = 0; i < family_list.size(); ++i) { for (int k = 0; k < db->count; ++k) { if (db->families[k]->name.compare(family_list.at(i), Qt::CaseInsensitive) == 0) { QByteArray family_name = db->families[k]->name.toUtf8(); familyRef = ATSFontFamilyFindFromName(QCFString(db->families[k]->name), kATSOptionFlagsDefault); if (familyRef) { fontRef = ATSFontFindFromName(QCFString(db->families[k]->name), kATSOptionFlagsDefault); goto FamilyFound; } else { #if defined(QT_MAC_USE_COCOA) // ATS and CT disagrees on what the family name should be, // use CT to look up the font if ATS fails. QCFString familyName = QString::fromAscii(family_name); QCFType<CTFontRef> CTfontRef = CTFontCreateWithName(familyName, 12, NULL); QCFType<CTFontDescriptorRef> fontDescriptor = CTFontCopyFontDescriptor(CTfontRef); QCFString displayName = (CFStringRef)CTFontDescriptorCopyAttribute(fontDescriptor, kCTFontDisplayNameAttribute); familyRef = ATSFontFamilyFindFromName(displayName, kATSOptionFlagsDefault); if (familyRef) { fontRef = ATSFontFindFromName(displayName, kATSOptionFlagsDefault); goto FamilyFound; } #endif } } } } FamilyFound: //fill in the engine's font definition QFontDef fontDef = d->request; //copy.. if(fontDef.pointSize < 0) fontDef.pointSize = qt_mac_pointsize(fontDef, d->dpi); else fontDef.pixelSize = qt_mac_pixelsize(fontDef, d->dpi); #if 0 ItemCount name_count; if(ATSUCountFontNames(fontID, &name_count) == noErr && name_count) { ItemCount actualName_size; if(ATSUGetIndFontName(fontID, 0, 0, 0, &actualName_size, 0, 0, 0, 0) == noErr && actualName_size) { QByteArray actualName(actualName_size); if(ATSUGetIndFontName(fontID, 0, actualName_size, actualName.data(), &actualName_size, 0, 0, 0, 0) == noErr && actualName_size) fontDef.family = QString::fromUtf8(actualName); } } #else { QCFString actualName; if(ATSFontFamilyGetName(familyRef, kATSOptionFlagsDefault, &actualName) == noErr) fontDef.family = actualName; } #endif #ifdef QT_MAC_USE_COCOA QFontEngine *engine = new QCoreTextFontEngineMulti(familyRef, fontRef, fontDef, d->kerning); #elif 1 QFontEngine *engine = new QFontEngineMacMulti(familyRef, fontRef, fontDef, d->kerning); #else ATSFontFamilyRef atsFamily = familyRef; ATSFontFamilyRef atsFontRef = fontRef; FMFont fontID; FMFontFamily fmFamily; FMFontStyle fntStyle = 0; fmFamily = FMGetFontFamilyFromATSFontFamilyRef(atsFamily); if (fmFamily == kInvalidFontFamily) { // Use the ATSFont then... fontID = FMGetFontFromATSFontRef(atsFontRef); } else { if (fontDef.weight >= QFont::Bold) fntStyle |= ::bold; if (fontDef.style != QFont::StyleNormal) fntStyle |= ::italic; FMFontStyle intrinsicStyle; FMFont fnt = 0; if (FMGetFontFromFontFamilyInstance(fmFamily, fntStyle, &fnt, &intrinsicStyle) == noErr) fontID = FMGetATSFontRefFromFont(fnt); } OSStatus status; const int maxAttributeCount = 5; ATSUAttributeTag tags[maxAttributeCount + 1]; ByteCount sizes[maxAttributeCount + 1]; ATSUAttributeValuePtr values[maxAttributeCount + 1]; int attributeCount = 0; Fixed size = FixRatio(fontDef.pixelSize, 1); tags[attributeCount] = kATSUSizeTag; sizes[attributeCount] = sizeof(size); values[attributeCount] = &size; ++attributeCount; tags[attributeCount] = kATSUFontTag; sizes[attributeCount] = sizeof(fontID); values[attributeCount] = &fontID; ++attributeCount; CGAffineTransform transform = CGAffineTransformIdentity; if (fontDef.stretch != 100) { transform = CGAffineTransformMakeScale(float(fontDef.stretch) / float(100), 1); tags[attributeCount] = kATSUFontMatrixTag; sizes[attributeCount] = sizeof(transform); values[attributeCount] = &transform; ++attributeCount; } ATSUStyle style; status = ATSUCreateStyle(&style); Q_ASSERT(status == noErr); Q_ASSERT(attributeCount < maxAttributeCount + 1); status = ATSUSetAttributes(style, attributeCount, tags, sizes, values); Q_ASSERT(status == noErr); QFontEngine *engine = new QFontEngineMac(style, fontID, fontDef, /*multiEngine*/ 0); ATSUDisposeStyle(style); #endif d->engineData->engine = engine; engine->ref.ref(); //a ref for the engineData->engine QFontCache::instance()->insertEngine(key, engine); }
void MolDisplayWin::WriteQTMovie(wxString & filepath) { //Create a QuickTime movie using the standard animation codecs with normal quality, and //temporal compression. The final file is flattened for cross platform compatability QTExport * QTOptions = new QTExport(this); //setup controls for the current data if (MainData->GetNumFrames() > 1) { //default to frame animation QTOptions->SetMovieChoice(0); } else { QTOptions->EnableFrameMovie(false); } if (MainData->cFrame->GetNumberNormalModes() <= 0) { QTOptions->EnableModeMovie(false); } if (QTOptions->ShowModal() != wxID_OK) { //user cancelled the operation QTOptions->Destroy(); return; } //retrieve the value of each option int MovieType = QTOptions->GetMovieChoice(); bool IncludeEPlot = QTOptions->AddEnergyPlot(); int compressorChoice = QTOptions->GetCompressorChoice(); int keyFrameRate = QTOptions->GetKeyFrameRate(); if (keyFrameRate < 0) keyFrameRate = 0; QTOptions->Destroy(); CodecType mCodec; switch (compressorChoice) { case 0: mCodec = kCinepakCodecType; break; case 1: mCodec = kGraphicsCodecType; break; case 2: mCodec = kAnimationCodecType; break; case 3: default: mCodec = kMPEG4VisualCodecType; } OSStatus s; OSErr myErr = myErr; FSSpec targetSpec; //ugh I need to get an FSSpec to hand to quicktime, but these calls only seem to work if //the file already exists... const char * t = filepath.mb_str(wxConvUTF8); FILE * temp = fopen(t, "wb"); fclose(temp); #ifdef __WXOSX_COCOA__ //This function is not found in the wxCocoa implementation, it is probably possible to work around it //Otherwise the code appears to link and run currently. However, it is probably better to redue the //code to use the Cocoa qtKit framework rather than the old Carbon QT library. //This path is not tested as the current Cocoa code does not properly support the extended save dialog. // void wxMacFilename2FSSpec( const wxString& path , FSSpec *spec ) { OSStatus err = noErr; FSRef fsRef; wxMacPathToFSRef( filepath , &fsRef ); err = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &targetSpec, NULL); verify_noerr( err ); } #else wxMacFilename2FSSpec(filepath, &targetSpec); #endif Movie theMovie = NULL; FSSpec tempSpec = targetSpec; strcpy((char *) &(tempSpec.name[1]), "MacMolPlt8933tempMovie"); tempSpec.name[0] = 22; BeginOperation(); ProgressInd->ChangeText("Creating movie..."); myErr = EnterMovies(); //initialize the quicktime manager if (myErr != noErr) { FinishOperation(); MessageAlert("Error initializing QuickTime!"); return; } //Create the movie file and initialize file data //Use Quicktime creator code 'TVOD' instead of simpletext 'ttxt' short resRefNum = 0; short resId = 0; myErr = CreateMovieFile(&tempSpec, 'TVOD', smCurrentScript, createMovieFileDeleteCurFile, &resRefNum, &theMovie); if (myErr != noErr) { MessageAlert("Error creating movie file!"); } else { bool KillEPlot = false; int width, height, savedEPlotWidth, savedEPlotHeight; glCanvas->GetClientSize(&width, &height); Rect lDisplayRect={0,0,0,0}; lDisplayRect.right = width; lDisplayRect.bottom = height; Rect gRect = lDisplayRect; Rect EPlotRect = lDisplayRect; //If we are including an energy plot add space for it here if (IncludeEPlot && (MovieType == 0)) { EPlotRect.left = EPlotRect.right; EPlotRect.right = EPlotRect.left + height; if (!energyPlotWindow) { energyPlotWindow = new EnergyPlotDialog(this); KillEPlot = true; } else { energyPlotWindow->GetSize(&savedEPlotWidth, &savedEPlotHeight); } gRect.right += height; width += height; energyPlotWindow->Show(false); energyPlotWindow->SetSize(height, height); energyPlotWindow->Update(); //This is needed to initialise the window if we just created it } LocalToGlobal ((Point *) &(gRect.top)); LocalToGlobal ((Point *) &(gRect.bottom)); WindowRef TempWindow; s = CreateNewWindow(kDocumentWindowClass, kWindowNoAttributes, &gRect, &TempWindow); if (s == noErr) { //Create the video track Track theTrack = NewMovieTrack (theMovie, FixRatio(width,1), FixRatio(height,1), kNoVolume); if ((noErr == GetMoviesError())&&theTrack) { Media theMedia = NewTrackMedia (theTrack, VideoMediaType, 60, // Video Time Scale NULL, 0); if ((noErr == GetMoviesError())&&theMedia) { myErr = BeginMediaEdits (theMedia); if (myErr == noErr) { //create the actual movie frames GWorldPtr lgWorld=NULL; if (! NewGWorld (&lgWorld, 0, &gRect, (CTabHandle) NULL, (GDHandle) NULL, (GWorldFlags) (pixPurge + useTempMem))) { long MaxCompressedSize; ImageSequence seqID; ImageDescriptionHandle imageDesc = (ImageDescriptionHandle)NewHandle(4); PixMapHandle myPixMap = GetPortPixMap(lgWorld); LockPixels (myPixMap); myErr = CompressSequenceBegin(&seqID, myPixMap, NULL, &gRect, &gRect, 0, mCodec, bestCompressionCodec, codecNormalQuality, codecNormalQuality, keyFrameRate, NULL, codecFlagUpdatePreviousComp, imageDesc); GetMaxCompressionSize (myPixMap, &gRect, 0, codecNormalQuality, mCodec, (CompressorComponent) anyCodec, &MaxCompressedSize); Handle Buffer = TempNewHandle(MaxCompressedSize, &myErr); if (!Buffer) Buffer = NewHandle(MaxCompressedSize); if (Buffer) { qtData myqtData = {theMedia, imageDesc, seqID, lDisplayRect, gRect}; if (MovieType == 0) { CreateFrameMovie(lgWorld, Buffer, myqtData, IncludeEPlot); } else { CreateModeMovie(lgWorld, Buffer, myqtData); } DisposeHandle(Buffer); } myErr = CDSequenceEnd(seqID); if (lgWorld != NULL) DisposeGWorld (lgWorld); if (imageDesc) DisposeHandle((Handle) imageDesc); } myErr = EndMediaEdits (theMedia); } myErr = InsertMediaIntoTrack (theTrack, 0,/* track start time */ 0, /* media start time */ GetMediaDuration (theMedia), FixRatio(1,1)); } myErr = AddMovieResource (theMovie, resRefNum, &resId, NULL); } if (resRefNum) { //Create the actual file as a flat data fork so it can be placed on the www ProgressInd->ChangeText("Flattening movieÉ"); FlattenMovie(theMovie, flattenAddMovieToDataFork, &targetSpec, 'TVOD', smCurrentScript, createMovieFileDeleteCurFile, &resId, NULL); CloseMovieFile (resRefNum); } DisposeWindow(TempWindow); } DisposeMovie (theMovie); DeleteMovieFile (&tempSpec); //delete the temp file after disposing of the movie if (energyPlotWindow) { if (KillEPlot) { delete energyPlotWindow; energyPlotWindow = NULL; } else { energyPlotWindow->SetSize(savedEPlotWidth, savedEPlotHeight); energyPlotWindow->FrameChanged(); energyPlotWindow->Show(true); } } } ExitMovies(); //Close out quicktime as we are done with it for now FinishOperation(); }
static int RasterizeFile (FILE *stream, AWindowRecord *myWindow, short wx, short wy) { char *buffer; /* input buffer */ long blockSize; /* METABUFFERSIZE */ long blockUsed; /* actual buffer size used */ long itemCounter; /* number of commands in buffer */ char *data; /* data pointer in buffer */ short fx,fy; /* file screen size */ Fixed sx,sy; /* scaling factors */ int i,error,j,size; char opCode; short x,y,r,g,b,n,lw,ts,m,ms,w; short x1,y1,x2,y2; short xx[SIZE],yy[SIZE]; PolyHandle myPoly; char s[CSIZE]; unsigned char c; RGBColor newColor; PaletteHandle myPalette; long l; /* get file parameters */ rewind(stream); error = fread(&blockSize,4,1,stream); if (error!=1) return(1); /* block size */ error = fread(&fx,2,1,stream); if (error!=1) return(1); /* x size */ error = fread(&fy,2,1,stream); if (error!=1) return(1); /* y size */ /* compute scaling factors */ sx = FixRatio(wx-1,fx-1); sy = FixRatio(wy-1,fy-1); /* default values */ lw = 1; ts = 12; m = 0; ms = 6; /* allocate input buffer */ buffer = malloc(blockSize); if (buffer==NULL) return(1); SetPort((GrafPtr)(myWindow->theWindow)); EraseRect(&(myWindow->usableRect)); /* loop through the blocks */ while (!feof(stream)) { /* read block parameters */ error = fread(&blockUsed,4,1,stream); if (error!=1) {free(buffer); return(1);} error = fread(&itemCounter,4,1,stream); if (error!=1) {free(buffer); return(1);} error = fread(buffer,blockUsed,1,stream);if (error!=1) {free(buffer); return(1);} /* init pointer to next item */ data = buffer; /* for all items */ for (i=0; i<itemCounter; i++) { /* get op code */ opCode = *(data++); switch (opCode) { case opMove : x = *((short *)data); data += 2; y = *((short *)data); data += 2; TRFMX(x); TRFMY(y); MoveTo(x,y); break; case opDraw : x = *((short *)data); data += 2; y = *((short *)data); data += 2; TRFMX(x); TRFMY(y); LineTo(x,y); break; case opPolyline : n = *((short *)data); data += 2; if (n>=SIZE) {free(buffer); return(2);} size = n<<1; memcpy(xx,data,size); data += size; memcpy(yy,data,size); data += size; for (j=0; j<n; j++) { TRFMX(xx[j]); TRFMY(yy[j]); } MoveTo(xx[0],yy[0]); for (j=1; j<n; j++) LineTo(xx[j],yy[j]); break; case opPolygon : n = *((short *)data); data += 2; if (n>=SIZE) {free(buffer); return(2);} size = n<<1; memcpy(xx,data,size); data += size; memcpy(yy,data,size); data += size; for (j=0; j<n; j++) { TRFMX(xx[j]); TRFMY(yy[j]); } if (n<3) break; myPoly = OpenPoly(); MoveTo(xx[0],yy[0]); for (j=1; j<n; j++) LineTo(xx[j],yy[j]); LineTo(xx[0],yy[0]); ClosePoly(); PaintPoly(myPoly); FramePoly(myPoly); KillPoly(myPoly); break; case opPolymark : n = *((short *)data); data += 2; if (n>=SIZE) {free(buffer); return(2);} size = n<<1; memcpy(xx,data,size); data += size; memcpy(yy,data,size); data += size; for (j=0; j<n; j++) { TRFMX(xx[j]); TRFMY(yy[j]); } for (j=0; j<n; j++) Marker(m,ms,xx[j],yy[j]); break; case opText : n = *((short *)data); data += 2; if (n>=CSIZE-1) {free(buffer); return(2);} memcpy(s,data,n); s[n] = 0; data += n; DrawString((ConstStr255Param)c2pstr(s)); break; case opCenteredText : x = *((short *)data); data += 2; y = *((short *)data); data += 2; TRFMX(x); TRFMY(y); n = *((short *)data); data += 2; if (n>=CSIZE-1) {free(buffer); return(2);} memcpy(s,data,n); s[n] = 0; data += n; c2pstr(s); w = StringWidth((ConstStr255Param)s); MoveTo(x-w/2,y+ts/2); DrawString((ConstStr255Param)s); break; case opSetLineWidth : n = *((short *)data); data += 2; lw = n; PenSize(n,n); break; case opSetTextSize : n = *((short *)data); data += 2; ts = n; TextSize(n); break; case opSetMarker : n = *((short *)data); data += 2; m = n; break; case opSetMarkerSize : n = *((short *)data); data += 2; ms = n; break; case opSetColor : c = *((unsigned char *)data); data++; PmForeColor((short)c); break; case opSetEntry : c = *((unsigned char *)data); data++; r = (short) (*((unsigned char *)data)); data++; g = (short) (*((unsigned char *)data)); data++; b = (short) (*((unsigned char *)data)); data++; myPalette = GetPalette(myWindow->theWindow); myWindow->red[c] = newColor.red = r<<8; myWindow->green[c] = newColor.green = g<<8; myWindow->blue[c] = newColor.blue = b<<8; SetEntryColor(myPalette,(short) c,&newColor); ActivatePalette(myWindow->theWindow); break; case opSetPalette : x = (short) (*((unsigned char *)data)); data++; y = (short) (*((unsigned char *)data)); data++; myPalette = GetPalette(myWindow->theWindow); for (j=x; j<=y; j++) { r = (short) (*((unsigned char *)data)); data++; g = (short) (*((unsigned char *)data)); data++; b = (short) (*((unsigned char *)data)); data++; myWindow->red[j] = newColor.red = r<<8; myWindow->green[j] = newColor.green = g<<8; myWindow->blue[j] = newColor.blue = b<<8; SetEntryColor(myPalette,(short) j,&newColor); } ActivatePalette(myWindow->theWindow); break; case opNewLine : lw = *((unsigned char *)data); data++; c = *((unsigned char *)data); data++; x1 = *((short *)data); data += 2; y1 = *((short *)data); data += 2; x2 = *((short *)data); data += 2; y2 = *((short *)data); data += 2; TRFMX(x1); TRFMY(y1); TRFMX(x2); TRFMY(y2); PenSize(lw,lw); PmForeColor((short)c); MoveTo(x1,y1); LineTo(x2,y2); break; case opNewPolyline : lw = *((unsigned char *)data); data++; c = *((unsigned char *)data); data++; n = *((short *)data); data += 2; if (n>=SIZE) {free(buffer); return(2);} size = n<<1; memcpy(xx,data,size); data += size; memcpy(yy,data,size); data += size; for (j=0; j<n; j++) { TRFMX(xx[j]); TRFMY(yy[j]); } PenSize(lw,lw); PmForeColor((short)c); MoveTo(xx[0],yy[0]); for (j=1; j<n; j++) LineTo(xx[j],yy[j]); break; case opNewPolygon : c = *((unsigned char *)data); data++; n = *((short *)data); data += 2; if (n>=SIZE) {free(buffer); return(2);} size = n<<1; memcpy(xx,data,size); data += size; memcpy(yy,data,size); data += size; for (j=0; j<n; j++) { TRFMX(xx[j]); TRFMY(yy[j]); } if (n<3) break; PmForeColor((short)c); myPoly = OpenPoly(); MoveTo(xx[0],yy[0]); for (j=1; j<n; j++) LineTo(xx[j],yy[j]); LineTo(xx[0],yy[0]); ClosePoly(); PaintPoly(myPoly); FramePoly(myPoly); KillPoly(myPoly); break; case opNewPolymark : m = *((unsigned char *)data); data++; ms = *((unsigned char *)data); data++; c = *((unsigned char *)data); data++; n = *((short *)data); data += 2; if (n>=SIZE) {free(buffer); return(2);} size = n<<1; memcpy(xx,data,size); data += size; memcpy(yy,data,size); data += size; for (j=0; j<n; j++) { TRFMX(xx[j]); TRFMY(yy[j]); } PmForeColor((short)c); for (j=0; j<n; j++) Marker(m,ms,xx[j],yy[j]); break; case opNewText : ts = *((unsigned char *)data); data++; c = *((unsigned char *)data); data++; x = *((short *)data); data += 2; y = *((short *)data); data += 2; TRFMX(x); TRFMY(y); n = *((short *)data); data += 2; if (n>=CSIZE-1) {free(buffer); return(2);} memcpy(s,data,n); s[n] = 0; data += n; MoveTo(x,y); TextSize(ts); PmForeColor((short)c); DrawString((ConstStr255Param)c2pstr(s)); break; case opNewCenteredText : ts = *((unsigned char *)data); data++; c = *((unsigned char *)data); data++; x = *((short *)data); data += 2; y = *((short *)data); data += 2; TRFMX(x); TRFMY(y); n = *((short *)data); data += 2; if (n>=CSIZE-1) {free(buffer); return(2);} memcpy(s,data,n); s[n] = 0; data += n; c2pstr(s); w = StringWidth((ConstStr255Param)s); TextSize(ts); PmForeColor((short)c); MoveTo(x-w/2,y+ts/2); DrawString((ConstStr255Param)c2pstr(s)); break; default : break; } } } return(0); }
void ZoomRect (Rect *smallrect, Rect *bigrect, Boolean zoomup) { #if USE_DRAG_MANAGER_FOR_ZOOMS if (gZoomOn) { if (zoomup) ZoomRects(smallrect,bigrect,10,kZoomNoAcceleration); else ZoomRects(bigrect,smallrect,10,kZoomNoAcceleration); } #else Fixed factor; Rect rect1, rect2, rect3, rect4; GrafPtr savePort, deskPort; int i; long tm; if (gZoomOn) { GetPort (&savePort); OpenPort (deskPort = (GrafPtr) NewPtr (sizeof (GrafPort))); InitPort (deskPort); SetPort (deskPort); PenPat (&qd.gray); //¥ Original, comment for black zoom. // PenPat (&qd.black); //¥ Uncomment for black zoom. PenMode (notPatXor); //¥ Original, comment for black zoom. // PenMode (patXor); //¥ Uncomment for black zoom. if (zoomup) { rect1 = *smallrect; factor = FixRatio (6, 5); fract = FixRatio (541, 10000); } else { rect1 = *bigrect; factor = FixRatio (5, 6); fract = ONE; } rect2 = rect1; rect3 = rect1; FrameRect (&rect1); for (i = 1; i <= ZOOMSTEPS; i++) { rect4.left = Blend (smallrect->left, bigrect->left); rect4.right = Blend (smallrect->right, bigrect->right); rect4.top = Blend (smallrect->top, bigrect->top); rect4.bottom = Blend (smallrect->bottom, bigrect->bottom); FrameRect (&rect4); FrameRect (&rect1); rect1 = rect2; rect2 = rect3; rect3 = rect4; fract = FixMul (fract, factor); tm = TickCount (); // These two lines are a crude waitvbl while (tm == TickCount ()); } FrameRect (&rect1); FrameRect (&rect2); FrameRect (&rect3); ClosePort (deskPort); DisposePtr ((Ptr) deskPort); PenNormal (); SetPort (savePort); } #endif }
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 TextToSpeechPrivate::setVolume(int volume) { fVolume = FixRatio(volume, 100); }
// ###################################################################### QuickTimeGrabber::Impl::Impl(const Dims& dims) : itsSeqGrab(0, &CloseComponent), itsSGChanVideo(&itsSeqGrab.it), itsDrawSeq(0), itsTimeScale(0), itsTimeBase(0), itsQueuedFrameCount(0), itsSkipFrameCount(0), itsSkipFrameCountTotal(0), itsPrevTime(0), itsFrameCount(0), itsGWorld(0), itsGotFrame(false), itsCurrentImage(), itsErrorMsg(), itsStreamStarted(false) { OSErr err; EnterMovies(); // open the default sequence grabber itsSeqGrab.it = OpenDefaultComponent(SeqGrabComponentType, 0); if (itsSeqGrab.it == NULL) LFATAL("OpenDefaultComponent() failed"); // initialize the default sequence grabber component if (noErr != (err = SGInitialize(itsSeqGrab.it))) LFATAL("SGInitialize() failed (err=%ld)", (long) err); Rect scaleRect; MacSetRect(&scaleRect, 0, 0, dims.w(), dims.h()); ASSERT(itsGWorld == 0); QTNewGWorld(&itsGWorld, k32ARGBPixelFormat, &scaleRect, NULL, NULL, kNativeEndianPixMap); // set its graphics world if (noErr != (err = SGSetGWorld(itsSeqGrab.it, itsGWorld, NULL))) LFATAL("SGSetGWorld() failed (err=%ld)", (long) err); // specify the destination data reference for a record operation // tell it we're not making a movie if the flag seqGrabDontMakeMovie // is used, the sequence grabber still calls your data function, but // does not write any data to the movie file writeType will always // be set to seqGrabWriteAppend if (noErr != (err = SGSetDataRef(itsSeqGrab.it, 0, 0, seqGrabDontMakeMovie | seqGrabDataProcIsInterruptSafe))) LFATAL("SGSetDataRef() failed (err=%ld)", (long) err); Impl::SGChannelHolder sgchanSound(&itsSeqGrab.it); if (noErr != (err = SGNewChannel(itsSeqGrab.it, VideoMediaType, &itsSGChanVideo.it))) LFATAL("SGNewChannel(video) failed (err=%ld)", (long) err); if (noErr != (err = SGNewChannel(itsSeqGrab.it, SoundMediaType, &sgchanSound.it))) { // don't care if we couldn't get a sound channel sgchanSound.it = NULL; LERROR("SGNewChannel(audio) failed (err=%ld)", (long) err); } // get the active rectangle Rect srcBounds; if (noErr != (err = SGGetSrcVideoBounds(itsSGChanVideo.it, &srcBounds))) LFATAL("SGGetSrcVideoBounds() failed (err=%ld)", (long) err); // we always want all the source setVideoChannelBounds(itsSGChanVideo.it, &srcBounds, &srcBounds); // set usage for new video channel to avoid playthrough // note we don't set seqGrabPlayDuringRecord if (noErr != (err = SGSetChannelUsage(itsSGChanVideo.it, seqGrabRecord | seqGrabLowLatencyCapture | seqGrabAlwaysUseTimeBase))) LFATAL("SGSetChannelUsage(video) failed (err=%ld)", (long) err); if (noErr != (err = SGSetChannelUsage(sgchanSound.it, seqGrabRecord | //seqGrabPlayDuringRecord | seqGrabLowLatencyCapture | seqGrabAlwaysUseTimeBase))) LERROR("SGSetChannelUsage(audio) failed (err=%ld)", (long) err); // specify a sequence grabber data function if (noErr != (err = SGSetDataProc(itsSeqGrab.it, NewSGDataUPP(Impl::grabDataProc), (long)(this)))) LFATAL("SGSetDataProc() failed (err=%ld)", (long) err); SGSetChannelRefCon(itsSGChanVideo.it, (long)(this)); // set up the video bottlenecks so we can get our queued frame count VideoBottles vb = { 0 }; if (noErr != (err = SGGetVideoBottlenecks(itsSGChanVideo.it, &vb))) LFATAL("SGGetVideoBottlenecks() failed (err=%ld)", (long) err); vb.procCount = 9; // there are 9 bottleneck procs; this must be filled in vb.grabCompressCompleteProc = NewSGGrabCompressCompleteBottleUPP (Impl::grabCompressCompleteBottle); if (noErr != (err = SGSetVideoBottlenecks(itsSGChanVideo.it, &vb))) LFATAL("SGSetVideoBottlenecks() failed (err=%ld)", (long) err); SGSetFrameRate(itsSGChanVideo.it, FixRatio(30, 1)); }
QFontEngineMacMulti::QFontEngineMacMulti(const ATSFontFamilyRef &atsFamily, const ATSFontRef &atsFontRef, const QFontDef &fontDef, bool kerning) : QFontEngineMulti(0) { this->fontDef = fontDef; this->kerning = kerning; FMFontFamily fmFamily; FMFontStyle fntStyle = 0; fmFamily = FMGetFontFamilyFromATSFontFamilyRef(atsFamily); if (fmFamily == kInvalidFontFamily) { // Use the ATSFont then... fontID = FMGetFontFromATSFontRef(atsFontRef); } else { if (fontDef.weight >= QFont::Bold) fntStyle |= ::bold; if (fontDef.style != QFont::StyleNormal) fntStyle |= ::italic; FMFontStyle intrinsicStyle; FMFont fnt = 0; if (FMGetFontFromFontFamilyInstance(fmFamily, fntStyle, &fnt, &intrinsicStyle) == noErr) fontID = FMGetATSFontRefFromFont(fnt); } OSStatus status; status = ATSUCreateTextLayout(&textLayout); Q_ASSERT(status == noErr); const int maxAttributeCount = 5; ATSUAttributeTag tags[maxAttributeCount + 1]; ByteCount sizes[maxAttributeCount + 1]; ATSUAttributeValuePtr values[maxAttributeCount + 1]; int attributeCount = 0; Fixed size = FixRatio(fontDef.pixelSize, 1); tags[attributeCount] = kATSUSizeTag; sizes[attributeCount] = sizeof(size); values[attributeCount] = &size; ++attributeCount; tags[attributeCount] = kATSUFontTag; sizes[attributeCount] = sizeof(fontID); values[attributeCount] = &this->fontID; ++attributeCount; transform = CGAffineTransformIdentity; if (fontDef.stretch != 100) { transform = CGAffineTransformMakeScale(float(fontDef.stretch) / float(100), 1); tags[attributeCount] = kATSUFontMatrixTag; sizes[attributeCount] = sizeof(transform); values[attributeCount] = &transform; ++attributeCount; } status = ATSUCreateStyle(&style); Q_ASSERT(status == noErr); Q_ASSERT(attributeCount < maxAttributeCount + 1); status = ATSUSetAttributes(style, attributeCount, tags, sizes, values); Q_ASSERT(status == noErr); QFontEngineMac *fe = new QFontEngineMac(style, fontID, fontDef, this); fe->ref.ref(); engines.append(fe); }
void TLevelWriter3gp::save(const TImageP &img, int frameIndex) { if (m_cancelled) return; TRasterImageP image(img); int lx = image->getRaster()->getLx(); int ly = image->getRaster()->getLy(); //void *buffer = image->getRaster()->getRawData(); int pixSize = image->getRaster()->getPixelSize(); if (pixSize != 4) throw TImageException(getFilePath(), "Unsupported pixel type"); QMutexLocker sl(&m_mutex); if (!m_properties) m_properties = new Tiio::MovWriterProperties(); Tiio::MovWriterProperties *prop = (Tiio::MovWriterProperties *)(m_properties); //CodecType compression = StandardCompressionType; prop->getCurrentCodec(); //CodecQ quality = StandardQualityType; prop->getCurrentQuality(); if (!m_initDone) { //FSSpec fspec; Rect frame; long max_compressed_size; QDErr err; m_videoTrack = NewMovieTrack(m_movie, FixRatio((short)lx, 1), FixRatio((short)ly, 1), kNoVolume); if ((err = GetMoviesError() != noErr)) throw TImageException(getFilePath(), "can't create video track"); m_dataRef = nil; m_hMovieData = NewHandle(0); // Construct the Handle data reference err = PtrToHand(&m_hMovieData, &m_dataRef, sizeof(Handle)); if ((err = GetMoviesError() != noErr)) throw TImageException(getFilePath(), "can't create Data Ref"); m_videoMedia = NewTrackMedia(m_videoTrack, VideoMediaType, (TINT32)m_frameRate, m_dataRef, HandleDataHandlerSubType); OpenADefaultComponent(MovieExportType, '3gpp', &m_myExporter); // err = (short)MovieExportDoUserDialog(m_myExporter, m_movie, 0, 0, 0, &m_cancelled); // if (m_cancelled) // throw TImageException(getFilePath(), "User abort of 3GP render"); if ((err = GetMoviesError() != noErr)) throw TImageException(getFilePath(), "can't create video media"); if ((err = BeginMediaEdits(m_videoMedia)) != noErr) throw TImageException(getFilePath(), "can't begin edit video media"); frame.left = 0; frame.top = 0; frame.right = lx; frame.bottom = ly; #if 0 if ((err = NewGWorld(&(m_gworld), pixSize * 8, &frame, 0, 0, 0))!=noErr) #else /* Mac OSX 10.7 later */ if ((err = QTNewGWorld(&(m_gworld), pixSize * 8, &frame, 0, 0, 0)) != noErr) #endif throw TImageException(getFilePath(), "can't create movie buffer"); #ifdef WIN32 LockPixels(m_gworld->portPixMap); if ((err = GetMaxCompressionSize(m_gworld->portPixMap, &frame, 0, quality, compression, anyCodec, &max_compressed_size)) != noErr) throw TImageException(getFilePath(), "can't get max compression size"); #else #if 0 PixMapHandle pixmapH = GetPortPixMap (m_gworld); LockPixels(pixmapH); #else PixMapHandle pixmapH = NULL; #endif max_compressed_size = lx * ly * 4 * 20; /*if ((err = GetMaxCompressionSize(pixmapH, &frame, 0, quality, compression,anyCodec, &max_compressed_size))!=noErr) throw TImageException(getFilePath(), "can't get max compression size");*/ #endif m_compressedData = NewHandle(max_compressed_size); if ((err = MemError()) != noErr) throw TImageException(getFilePath(), "can't allocate compressed data for movie"); MoveHHi(m_compressedData); HLock(m_compressedData); if ((err = MemError()) != noErr) throw TImageException(getFilePath(), "can't allocate img handle"); #if 0 m_pixmap = GetGWorldPixMap(m_gworld); if (!LockPixels(m_pixmap)) throw TImageException(getFilePath(), "can't lock pixels"); buf = (PixelXRGB*) GetPixBaseAddr(m_pixmap); #else m_pixmap = NULL; buf = NULL; #endif buf_lx = lx; buf_ly = ly; m_initDone = true; } unsigned short rowBytes = (unsigned short)(((short)(*(m_pixmap))->rowBytes & ~(3 << 14))); Rect frame; ImageDescriptionHandle img_descr; Ptr compressed_data_ptr; QDErr err; frame.left = 0; frame.top = 0; frame.right = lx; frame.bottom = ly; TRasterP ras = image->getRaster(); #ifdef WIN32 compressed_data_ptr = StripAddress(*(m_compressedData)); copy(ras, buf, buf_lx, buf_ly); #else compressed_data_ptr = *m_compressedData; copy(ras, buf, buf_lx, buf_ly, rowBytes); #endif img_descr = (ImageDescriptionHandle)NewHandle(4); #ifdef WIN32 if ((err = CompressImage(m_gworld->portPixMap, &frame, quality, compression, img_descr, compressed_data_ptr)) != noErr) throw TImageException(getFilePath(), "can't compress image"); #else #if 0 PixMapHandle pixmapH = GetPortPixMap (m_gworld); if ((err = CompressImage(pixmapH, &frame, codecNormalQuality, kJPEGCodecType, img_descr, compressed_data_ptr))!=noErr) { throw TImageException(getFilePath(), "can't compress image"); } #endif #endif if ((err = AddMediaSample(m_videoMedia, m_compressedData, 0, (*img_descr)->dataSize, 1, (SampleDescriptionHandle)img_descr, 1, 0, 0)) != noErr) throw TImageException(getFilePath(), "can't add image to movie media"); DisposeHandle((Handle)img_descr); }
OSStatus MovieMaker::setupMovie() { OSStatus error = noErr; FSRef fileRef; FSSpec fileSpec; rowBytes = width * 4; bufferSize = height * rowBytes; buffer = (char*)malloc(bufferSize); invertedBuffer = (char*)malloc(bufferSize); rect.left = 0; rect.top = 0; rect.right = width; rect.bottom = height; error = NewGWorldFromPtr(&gworld, k32ARGBPixelFormat, &rect, 0, 0, 0, buffer, rowBytes); if (error == noErr) { LockPixels(GetGWorldPixMap(gworld)); } // MBW -- I think this needs to happen after all the dialogs, etc. // if (error == noErr) // { // Microseconds(&lastFrameTime); // error = grabFrame(); // } if (error == noErr) { error = EnterMovies(); } if (error == noErr) { ci = OpenDefaultComponent(StandardCompressionType,StandardCompressionSubType); if(ci == NULL) error = paramErr; } if (error == noErr) { long flags; SCGetInfo(ci,scPreferenceFlagsType,&flags); flags &= ~scShowBestDepth; flags |= scAllowZeroFrameRate; SCSetInfo(ci,scPreferenceFlagsType,&flags); } if (error == noErr) { send_agent_pause(); gViewerWindow->mWindow->beforeDialog(); error = SCRequestSequenceSettings(ci); gViewerWindow->mWindow->afterDialog(); send_agent_resume(); if (error == scUserCancelled) { // deal with user cancelling. EndCapture(); } } if (error == noErr) { // This is stoopid. I have to take the passed full path, create the file so I can get an FSRef, and Get Info to get the FSSpec for QuickTime. Could Apple make this any more difficult... FILE* file = LLFile::fopen(fname, "w"); /* Flawfinder: ignore */ if (file) { fclose(file); error = FSPathMakeRef((UInt8*)fname, &fileRef, NULL); if (error == noErr) error = FSGetCatalogInfo(&fileRef, 0, NULL, NULL, &fileSpec, NULL); } else { error = paramErr; } } if (error == noErr) { error = CreateMovieFile(&fileSpec, 'TVOD', smCurrentScript, createMovieFileDeleteCurFile | createMovieFileDontCreateResFile, &movieResRef, &movie); } if (error == noErr) { track = NewMovieTrack(movie, FixRatio(width, 1), FixRatio(height, 1), kNoVolume); error = GetMoviesError(); } if (error == noErr) { media = NewTrackMedia(track, VideoMediaType, 600, NULL, 0); error = GetMoviesError(); } if (error == noErr) { Microseconds(&lastFrameTime); error = grabFrame(); } if (error == noErr) { error = SCCompressSequenceBegin(ci,GetPortPixMap(gworld),nil,&idh); } if (error == noErr) { error = BeginMediaEdits(media); } if (error != noErr) { media = NULL; } return error; }
OSErr QTTarg_AddIconMovieSamplesToMedia (Media theMedia) { QTAtomContainer mySample = NULL; QTAtomContainer mySpriteData = NULL; QTAtom myActionAtom = 0; QTAtom myTargetAtom = 0; RGBColor myKeyColor; Point myLocation; short isVisible, myIndex; Fixed myDegrees; FixedPoint myPoint; OSErr myErr = noErr; ////////// // // create a key frame sample containing the sprite images // ////////// // create a new, empty key frame sample myErr = QTNewAtomContainer(&mySample); if (myErr != noErr) goto bail; myKeyColor.red = myKeyColor.green = myKeyColor.blue = 0xffff; // white myPoint.x = Long2Fix(kIconDimension / 2); myPoint.y = Long2Fix(kIconDimension / 2); // add images to the key frame sample SpriteUtils_AddPICTImageToKeyFrameSample(mySample, kOldQTIconID, &myKeyColor, kOldQTIconSpriteAtomID, &myPoint, NULL); SpriteUtils_AddPICTImageToKeyFrameSample(mySample, kNewQTIconID, &myKeyColor, kNewQTIconSpriteAtomID, &myPoint, NULL); ////////// // // add the initial sprite properties and actions to the key frame sample // ////////// // the old QT icon sprite myErr = QTNewAtomContainer(&mySpriteData); if (myErr != noErr) goto bail; myLocation.h = kIconDimension + (kIconDimension / 2); myLocation.v = ((kIconSpriteTrackHeight - kIconDimension) / 2) + (kIconDimension / 2); isVisible = true; myIndex = kOldQTIconImageIndex; SpriteUtils_SetSpriteData(mySpriteData, &myLocation, &isVisible, NULL, &myIndex, NULL, NULL, NULL); WiredUtils_AddQTEventAndActionAtoms(mySpriteData, kParentAtomIsContainer, kQTEventMouseClickEndTriggerButton, kActionSpriteRotate, &myActionAtom); myDegrees = EndianS32_NtoB(FixRatio(90, 1)); WiredUtils_AddActionParameterAtom(mySpriteData, myActionAtom, kFirstParam, sizeof(myDegrees), &myDegrees, NULL); WiredUtils_AddSpriteIDActionTargetAtom(mySpriteData, myActionAtom, 2, NULL); SpriteUtils_AddSpriteToSample(mySample, mySpriteData, kOldQTIconSpriteAtomID); QTDisposeAtomContainer(mySpriteData); // the new QT icon sprite myErr = QTNewAtomContainer(&mySpriteData); if (myErr != noErr) goto bail; myLocation.h = kIconSpriteTrackWidth - (kIconDimension + (kIconDimension / 2)); myLocation.v = ((kIconSpriteTrackHeight - kIconDimension) / 2) + (kIconDimension / 2); isVisible = true; myIndex = kNewQTIconImageIndex; SpriteUtils_SetSpriteData(mySpriteData, &myLocation, &isVisible, NULL, &myIndex, NULL, NULL, NULL); WiredUtils_AddQTEventAndActionAtoms(mySpriteData, kParentAtomIsContainer, kQTEventMouseClickEndTriggerButton, kActionSpriteRotate, &myActionAtom); myDegrees = EndianS32_NtoB(FixRatio(90, 1)); WiredUtils_AddActionParameterAtom(mySpriteData, myActionAtom, kFirstParam, sizeof(myDegrees), &myDegrees, NULL); WiredUtils_AddSpriteIDActionTargetAtom(mySpriteData, myActionAtom, 1, NULL); SpriteUtils_AddSpriteToSample(mySample, mySpriteData, kNewQTIconSpriteAtomID); SpriteUtils_AddSpriteSampleToMedia(theMedia, mySample, kSpriteMediaFrameDurationIcon, true, NULL); bail: if (mySample != NULL) QTDisposeAtomContainer(mySample); if (mySpriteData != NULL) QTDisposeAtomContainer(mySpriteData); return(myErr); }
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; }
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); }
void setVolume(int v) { volume = FixRatio(v, 100); }
OSErr QTDR_CreateMovieInRAM (void) { Movie myMovie = NULL; Track myTrack = NULL; Media myMedia = NULL; short myResRefNum = 0; short myResID = 0; Handle myDataRef = NULL; Handle myHandle = NULL; FSSpec myFSSpec; OSErr myErr = noErr; // create a new handle to hold the media data myHandle = NewHandleClear(0); if (myHandle == NULL) goto bail; // create a data reference to that handle myDataRef = QTDR_MakeHandleDataRef(myHandle); if (myDataRef == NULL) goto bail; myMovie = NewMovie(newMovieActive); if (myMovie == NULL) goto bail; myErr = SetMovieDefaultDataRef(myMovie, myDataRef, HandleDataHandlerSubType); if (myErr != noErr) goto bail; // create the movie track and media myTrack = NewMovieTrack(myMovie, FixRatio(kVideoTrackWidth, 1), FixRatio(kVideoTrackHeight, 1), kNoVolume); myErr = GetMoviesError(); if (myErr != noErr) goto bail; myMedia = NewTrackMedia(myTrack, VideoMediaType, kVideoTimeScale, NULL, 0); myErr = GetMoviesError(); if (myErr != noErr) goto bail; // create the media samples myErr = BeginMediaEdits(myMedia); if (myErr != noErr) goto bail; myErr = QTDR_AddVideoSamplesToMedia(myMedia, kVideoTrackWidth, kVideoTrackHeight); if (myErr != noErr) goto bail; myErr = EndMediaEdits(myMedia); if (myErr != noErr) goto bail; // add the media to the track myErr = InsertMediaIntoTrack(myTrack, 0, 0, GetMediaDuration(myMedia), fixed1); if (myErr != noErr) goto bail; // add the movie atom to the movie file myErr = AddMovieResource(myMovie, myResRefNum, &myResID, NULL); myFSSpec.name[0] = (unsigned char)0; myFSSpec.parID = 0; myFSSpec.vRefNum = 0; QTFrame_OpenMovieInWindow(myMovie, &myFSSpec); bail: if (myDataRef != NULL) DisposeHandle(myDataRef); return(myErr); }