@@ -247,19 +247,6 @@ TSharedPtr<FSceneViewport> UStableDiffusionSubsystem::GetCapturingViewport()
247247 return OutSceneViewport;
248248}
249249
250- void UStableDiffusionSubsystem::StartCapturingViewport ()
251- {
252- // Find active viewport
253- TSharedPtr<FSceneViewport> OutSceneViewport = GetCapturingViewport ();
254- SetCaptureViewport (OutSceneViewport.ToSharedRef (), OutSceneViewport->GetSize ());
255- }
256-
257- void UStableDiffusionSubsystem::SetCaptureViewport (TSharedRef<FSceneViewport> Viewport, FIntPoint FrameSize)
258- {
259- ViewportCapture = MakeShared<FFrameGrabber>(Viewport, FrameSize);
260- ViewportCapture->StartCapturingFrames ();
261- }
262-
263250void UStableDiffusionSubsystem::GenerateImage (FStableDiffusionInput Input, EInputImageSource ImageSourceType)
264251{
265252 if (!GeneratorBridge)
@@ -588,9 +575,6 @@ void UStableDiffusionSubsystem::CaptureFromViewportSource(FStableDiffusionInput
588575{
589576 auto ViewportSize = GetCapturingViewport ()->GetSizeXY ();
590577
591- // Make sure viewport capture objects are available
592- StartCapturingViewport ();
593-
594578 FIntPoint MinBounds, MaxBounds;
595579 CalculateOverlayBounds (float (Input.Options .OutSizeX ) / float (Input.Options .OutSizeY ), MinBounds, MaxBounds);
596580 FIntRect FrameBounds (MinBounds.X , MinBounds.Y , MaxBounds.X , MaxBounds.Y );
@@ -618,31 +602,22 @@ void UStableDiffusionSubsystem::CaptureFromViewportSource(FStableDiffusionInput
618602 SceneCapture.SceneCapture ->Destroy ();
619603 }
620604
621- // Create a frame payload we will wait on to be filled with a frame
622- auto framePtr = MakeShared<FCapturedFramePayload>();
623- framePtr->OnFrameCapture .AddLambda ([=](FColor* Pixels, FIntPoint BufferSize, FIntPoint TargetSize) mutable {
624- // Copy frame data
625- TArray<FColor> CopiedFrame = CopyFrameData (FrameBounds, BufferSize, Pixels);
626-
627- // Find a final colour layer as a destination for our captured frame
628- auto FinalColorProcessor = Input.ProcessedLayers .FindByPredicate ([](const FLayerData& Layer) { return Layer.Processor ->IsA <UFinalColorLayerProcessor>(); });
629- if (FinalColorProcessor) {
630- FinalColorProcessor->LayerPixels = MoveTemp (CopiedFrame);
631- }
632-
633- // Don't need to keep capturing whilst generating
634- ViewportCapture->StopCapturingFrames ();
605+ // Take the screenshot of the active viewport
606+ TArray<FColor> Pixels;
607+ GetViewportScreenShot (UStableDiffusionSubsystem::GetCapturingViewport ().Get (), Pixels, FrameBounds);
635608
636- // Set size from viewport
637- Input.Options .InSizeX = FrameBounds.Size ().X ;
638- Input.Options .InSizeY = FrameBounds.Size ().Y ;
609+ // Find a final colour layer as a destination for our captured frame
610+ auto FinalColorProcessor = Input.ProcessedLayers .FindByPredicate ([](const FLayerData& Layer) { return Layer.Processor ->IsA <UFinalColorLayerProcessor>(); });
611+ if (FinalColorProcessor) {
612+ FinalColorProcessor->LayerPixels = MoveTemp (Pixels);
613+ }
639614
640- // Only start image generation when we have a frame
641- StartImageGeneration ( Input) ;
642- }) ;
615+ // Set size from viewport
616+ Input. Options . InSizeX = FrameBounds. Size (). X ;
617+ Input. Options . InSizeY = FrameBounds. Size (). Y ;
643618
644- // Start frame capture
645- ViewportCapture-> CaptureThisFrame (framePtr );
619+ // Only start image generation when we have a frame
620+ StartImageGeneration (Input );
646621}
647622
648623void UStableDiffusionSubsystem::CaptureFromSceneCaptureSource (FStableDiffusionInput Input)
@@ -745,7 +720,7 @@ EModelStatus UStableDiffusionSubsystem::GetModelStatus() const
745720 return EModelStatus::Unloaded;
746721}
747722
748- TArray<FColor> UStableDiffusionSubsystem::CopyFrameData (FIntRect Bounds, FIntPoint BufferSize, FColor* ColorBuffer)
723+ TArray<FColor> UStableDiffusionSubsystem::CopyFrameData (FIntRect Bounds, FIntPoint BufferSize, const FColor* ColorBuffer)
749724{
750725 // Copy frame data
751726 TArray<FColor> CopiedFrame;
0 commit comments