void MolDisplayWin::CreateModeMovie(GWorldPtr lgWorld, Handle CompressedData, const qtData & myqtData) { float offsetFactor; bool savedrawmode=false; Rect lDisplayRect = myqtData.DisplayRect; if (!MainData->cFrame->Vibs) return; Frame * lFrame = MainData->cFrame; if (MainData->GetDrawMode()) { savedrawmode = true; if (!Prefs->GetAnimateMode()) MainData->SetDrawMode(false); } long cmode = (lFrame->NumAtoms)*(lFrame->Vibs->CurrentMode); offsetFactor = 1.0/(4.5*Prefs->GetAnimationSpeed()); float VectorScale = Prefs->GetVectorScale(); long AnimationSpeed = Prefs->GetAnimationSpeed(); CPoint3D * ModeOffset = new CPoint3D[lFrame->NumAtoms]; CPoint3D * SavedAtoms = new CPoint3D[lFrame->NumAtoms]; if (!ModeOffset || !SavedAtoms) { return; //insufficient memory } mpAtom * lAtoms = lFrame->Atoms; long iatm; for (iatm=0; iatm<(lFrame->NumAtoms); iatm++) { SavedAtoms[iatm] = lAtoms[iatm].Position; ModeOffset[iatm] = lFrame->Vibs->NormMode[iatm+cmode]; ModeOffset[iatm] *= VectorScale; } MainData->ResetRotation(); ReleaseLists(); DrawGL(); OSErr myErr; long npoint = 0; long inc = 1; ProgressInd->SetScaleFactor(100.0/((float) 4*AnimationSpeed)); for (long i=0; i<4*AnimationSpeed; i++) { ProgressInd->UpdateProgress(i); if ((npoint==AnimationSpeed)||(npoint==-AnimationSpeed)) { inc *= -1; offsetFactor *= -1.0; } npoint += inc; // create a pict of the current molecule display wxImage mImage = glCanvas->getImage(0,0); wxBitmap * mBitmap = new wxBitmap(mImage); //The following utilizes a Mac specific internal pair of calls //to get a PicHandle from a wxBitmap. wxBitmapRefData * mBitmapData = mBitmap->GetBitmapData(); PicHandle tempPict = mBitmapData->GetPictHandle(); CGrafPtr lSavedPort; GDHandle lSavedGDH; long dataSize; unsigned char similarity; if (tempPict) { //Got a PICT, draw it into the GWorld HLock(CompressedData); Ptr compressedDataPtr = *CompressedData; GetGWorld (&lSavedPort, &lSavedGDH); SetGWorld (lgWorld, NULL); EraseRect(&lDisplayRect); DrawPicture(tempPict, &(lDisplayRect)); delete mBitmap; SetGWorld (lSavedPort, lSavedGDH); PixMapHandle myPixMap = GetPortPixMap(lgWorld); myErr = CompressSequenceFrame(myqtData.seqID, myPixMap, &lDisplayRect, codecFlagUpdatePreviousComp, compressedDataPtr, &dataSize, &similarity, NULL); TimeValue test;//I don't use this value, but Carbon requires it myErr = AddMediaSample(myqtData.theMedia, CompressedData, 0, /* no offset in data */ dataSize, 1, (SampleDescriptionHandle)myqtData.imageDesc, 1, /* one sample */ 0, /* self-contained samples */ &test); } for (iatm=0; iatm<(lFrame->NumAtoms); iatm++) { lAtoms[iatm].Position.x += offsetFactor*(ModeOffset[iatm].x); lAtoms[iatm].Position.y += offsetFactor*(ModeOffset[iatm].y); lAtoms[iatm].Position.z += offsetFactor*(ModeOffset[iatm].z); } MainData->ResetRotation(); ReleaseLists(); DrawGL(); } for (iatm=0; iatm<(lFrame->NumAtoms); iatm++) { lAtoms[iatm].Position = SavedAtoms[iatm]; } MainData->ResetRotation(); if (ModeOffset) delete [] ModeOffset; if (SavedAtoms) delete [] SavedAtoms; MainData->SetDrawMode(savedrawmode); ReleaseLists(); DrawGL(); }
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ OSErr cres; long framesizemax; UInt8 similarity=0; long compressedsize; OSType in_format=kYUVSPixelFormat; int width = mpi->width; int height = mpi->height; int stride = width*2; if(!codec_initialized){ FrameRect.top=0; FrameRect.left=0; FrameRect.right=width; FrameRect.bottom=height; cres = QTNewGWorldFromPtr( &frame_GWorld_in, in_format, &FrameRect, 0, 0, 0, mpi->planes[0], stride); mp_msg(MSGT_MENCODER,MSGL_DBG2,"NewGWorldFromPtr returned:%i\n",cres&0xFFFF); //dunno what todo about this frame_prev = malloc(stride * height); cres = QTNewGWorldFromPtr( &frame_GWorld_prev, in_format, &FrameRect, 0, 0, 0, frame_prev, stride); mp_msg(MSGT_MENCODER,MSGL_DBG2,"height:%i width:%i stride:%i\n",height,width,stride); mp_msg(MSGT_MENCODER,MSGL_DBG2,"NewGWorldFromPtr returned:%i\n",cres&0xFFFF); cres= GetMaxCompressionSize ( GetGWorldPixMap(frame_GWorld_in), &FrameRect, 24, codecNormalQuality, bswap_32(format), compressor, &framesizemax ); mp_msg(MSGT_MENCODER,MSGL_DBG2,"GetMaxCompressionSize returned:%i : MaxSize:%li\n",cres&0xFFFF,framesizemax); frame_comp=malloc(framesizemax); desc = (ImageDescriptionHandle)NewHandleClear(MAX_IDSIZE); //memory where the desc will be stored (*desc)->idSize=MAX_IDSIZE; cres= CompressSequenceBegin ( &seq, GetGWorldPixMap( frame_GWorld_in), GetGWorldPixMap( frame_GWorld_prev), &FrameRect, &FrameRect, 24, // color depth bswap_32(format), // fourcc compressor, // codec component codecNormalQuality, //codecNormalQuality, codecMaxQuality, //codecNormalQuality, 10*30, // keyframe rate 0, 0, desc); mp_msg(MSGT_MENCODER,MSGL_DBG2,"CompressSequenceBegin returned:%i\n",cres&0xFFFF); mp_msg(MSGT_MENCODER,MSGL_DBG2,"Sequence ID:%i\n",seq); if (mp_msg_test(MSGT_MENCODER, MSGL_DBG2)) dump_ImageDescription(*desc); codec_initialized++; } cres = CompressSequenceFrame ( seq, GetGWorldPixMap(frame_GWorld_in), &FrameRect, 0, (char*)mux_v->buffer, &compressedsize, &similarity, 0); if(cres&0xFFFF)mp_msg(MSGT_MENCODER,MSGL_DBG2,"CompressSequenceFrame returned:%i\n",cres&0xFFFF); #if 0 printf("Size %i->%i \n",stride*height,compressedsize); printf("Ratio: %i:1\n",(stride*height)/compressedsize); #endif muxer_write_chunk(mux_v, compressedsize , similarity?0:0x10, MP_NOPTS_VALUE, MP_NOPTS_VALUE); if(((*desc)->idSize)>MAX_IDSIZE){ mp_msg(MSGT_MENCODER,MSGL_ERR,"FATAL! idSize=%d too big, increase MAX_IDSIZE in ve_qtvideo.c!\n",((*desc)->idSize)); } else { // according to QT docs, imagedescription may be changed while encoding // a frame (even its size may (and does!) change!) memcpy(mux_v->bih+1,*desc,(*desc)->idSize); } return 1; }
void MolDisplayWin::CreateFrameMovie(GWorldPtr lgWorld, Handle CompressedData, const qtData & myqtData, bool IncludeEPlot) { OSErr myErr; long AnimateTime = Prefs->GetAnimateTime(); if (AnimateTime <= 0) AnimateTime = 1; long SavedFrameNum = MainData->GetCurrentFrame(); Rect lDisplayRect = myqtData.DisplayRect; Rect EPlotRect; EPlotRect = myqtData.DisplayRect; EPlotRect.left = EPlotRect.right; EPlotRect.right = myqtData.FullRect.right; ProgressInd->SetScaleFactor(100.0/((float) MainData->NumFrames)); for (long i=1; i<=MainData->NumFrames; i++) { ProgressInd->UpdateProgress(i); MainData->SetCurrentFrame(i); //Check for and update any surfaces depending on the screen plane Surface * temp = MainData->cFrame->SurfaceList; while (temp) { temp->RotateEvent(MainData); temp = temp->GetNextSurface(); } MainData->ResetRotation(); ReleaseLists(); DrawGL(); // create a pict of the current molecule display wxImage mImage = glCanvas->getImage(0,0); wxBitmap * mBitmap = new wxBitmap(mImage); //The following utilizes a Mac specific internal pair of calls //to get a PicHandle from a wxBitmap. wxBitmapRefData * mBitmapData = mBitmap->GetBitmapData(); PicHandle tempPict = mBitmapData->GetPictHandle(); CGrafPtr lSavedPort; GDHandle lSavedGDH; long dataSize; unsigned char similarity; if (tempPict) { //Got a PICT, draw it into the GWorld HLock(CompressedData); Ptr compressedDataPtr = *CompressedData; GetGWorld (&lSavedPort, &lSavedGDH); SetGWorld (lgWorld, NULL); EraseRect(&lDisplayRect); DrawPicture(tempPict, &(lDisplayRect)); delete mBitmap; if (IncludeEPlot) { energyPlotWindow->FrameChanged(); wxBitmap * ePlotBitMap = NULL; energyPlotWindow->CopyToBitMap(&ePlotBitMap); if (ePlotBitMap) { wxBitmapRefData * mBitmapData = mBitmap->GetBitmapData(); PicHandle tempPict = mBitmapData->GetPictHandle(); if (tempPict) { SetGWorld (lgWorld, NULL); EraseRect(&EPlotRect); DrawPicture(tempPict, &(EPlotRect)); } delete ePlotBitMap; } } SetGWorld (lSavedPort, lSavedGDH); PixMapHandle myPixMap = GetPortPixMap(lgWorld); myErr = CompressSequenceFrame(myqtData.seqID, myPixMap, &(myqtData.FullRect), codecFlagUpdatePreviousComp, compressedDataPtr, &dataSize, &similarity, NULL); TimeValue test;//I don't use this value, but Carbon requires it myErr = AddMediaSample(myqtData.theMedia, CompressedData, 0, /* no offset in data */ dataSize, AnimateTime, (SampleDescriptionHandle)myqtData.imageDesc, 1, /* one sample */ 0, /* self-contained samples */ &test); } } MainData->SetCurrentFrame(SavedFrameNum); MainData->ResetRotation(); ReleaseLists(); DrawGL(); }