From 62544e52d2b30a51dd213680ce1dac0f7552470f Mon Sep 17 00:00:00 2001 From: Sch <3516520171@qq.com> Date: Sat, 8 Jul 2023 10:41:34 +0800 Subject: [PATCH] tarAthgiLegfU7 --- .../Cut5/Interface/CutMainWidgetInterface.h | 2 ++ Source/Cut5/Utils/OpencvUtils.cpp | 20 ++++++++--------- Source/Cut5/Utils/OpencvUtils.h | 2 +- Source/Cut5/Widgets/DefineGlobal.h | 2 +- Source/Cut5/Widgets/SCutMainWindow.cpp | 10 ++++++--- Source/Cut5/Widgets/SCutMainWindow.h | 1 + Source/Cut5/Widgets/STimelineClip.cpp | 14 +++++++++++- Source/Cut5/Widgets/STimelineClip.h | 2 ++ Source/Cut5/Widgets/STrackBody.cpp | 22 +++++++++++++++++-- Source/Cut5/Widgets/SVideoPlayer.h | 1 + 10 files changed, 58 insertions(+), 18 deletions(-) diff --git a/Source/Cut5/Interface/CutMainWidgetInterface.h b/Source/Cut5/Interface/CutMainWidgetInterface.h index e45ebbc..471177f 100644 --- a/Source/Cut5/Interface/CutMainWidgetInterface.h +++ b/Source/Cut5/Interface/CutMainWidgetInterface.h @@ -3,6 +3,7 @@ #pragma once #include "CoreMinimal.h" +#include "Engine/Texture2D.h" #include "UObject/Interface.h" #include "CutMainWidgetInterface.generated.h" @@ -24,5 +25,6 @@ class CUT5_API ICutMainWidgetInterface public: virtual void OnUpdateVideo(FGuid UUID, UTexture2D* Texture) {}; + virtual void OnUpdateLightArray(const TArray& LightArray) {}; }; diff --git a/Source/Cut5/Utils/OpencvUtils.cpp b/Source/Cut5/Utils/OpencvUtils.cpp index 425226e..ca57ab4 100644 --- a/Source/Cut5/Utils/OpencvUtils.cpp +++ b/Source/Cut5/Utils/OpencvUtils.cpp @@ -24,26 +24,26 @@ int32 FOpencvUtils::GetVideoFrameCount(FString VideoPath) return FrameCount; } -TArray FOpencvUtils::GetVideoFrameLightArray(FString VideoPath, int32 Width, int32 Height) +TArray> FOpencvUtils::GetVideoFrameLightArray(FString VideoPath, int32 X, int32 Y) { cv::VideoCapture VideoCapture; VideoCapture.open(TCHAR_TO_UTF8(*VideoPath)); - TArray LightArray; + + + TArray> Colors; while (VideoCapture.isOpened()) { cv::Mat Array; if (VideoCapture.grab()) { + TArray LightArray; VideoCapture.retrieve(Array); - cv::resize(Array, Array, cv::Size(Width, Height)); - for (int32 i = 0; i < Array.rows; i++) + cv::resize(Array, Array, cv::Size(X, Y)); + for (int32 i = 0; i < Array.cols * Array.rows; i++) { - for (int32 j = 0; j < Array.cols; j++) - { - cv::Vec3b Pixel = Array.at(i, j); - LightArray.Add(FColor(Pixel[2], Pixel[1], Pixel[0])); - } + LightArray.Add(FColor(Array.data[i * 3 + 0], Array.data[i * 3 + 1], Array.data[i * 3 + 2], 255)); } + Colors.Add(LightArray); } if (Array.empty()) { @@ -51,5 +51,5 @@ TArray FOpencvUtils::GetVideoFrameLightArray(FString VideoPath, int32 Wi } } VideoCapture.release(); - return LightArray; + return Colors; } diff --git a/Source/Cut5/Utils/OpencvUtils.h b/Source/Cut5/Utils/OpencvUtils.h index 3a87d08..3da92b6 100644 --- a/Source/Cut5/Utils/OpencvUtils.h +++ b/Source/Cut5/Utils/OpencvUtils.h @@ -6,6 +6,6 @@ class FOpencvUtils { public: static int32 GetVideoFrameCount(FString VideoPath); - static TArray GetVideoFrameLightArray(FString VideoPath, int32 Width, int32 Height); + static TArray> GetVideoFrameLightArray(FString VideoPath, int32 X, int32 Y); }; diff --git a/Source/Cut5/Widgets/DefineGlobal.h b/Source/Cut5/Widgets/DefineGlobal.h index 05bbe67..ccaa2a8 100644 --- a/Source/Cut5/Widgets/DefineGlobal.h +++ b/Source/Cut5/Widgets/DefineGlobal.h @@ -91,7 +91,7 @@ struct CUT5_API FClipData // Light Array - TArray LightArrayData; + TArray> LightArrayData; diff --git a/Source/Cut5/Widgets/SCutMainWindow.cpp b/Source/Cut5/Widgets/SCutMainWindow.cpp index 016e0ae..1ef28cf 100644 --- a/Source/Cut5/Widgets/SCutMainWindow.cpp +++ b/Source/Cut5/Widgets/SCutMainWindow.cpp @@ -129,14 +129,18 @@ void SCutMainWindow::OnUpdateVideo(FGuid UUID, UTexture2D* Texture) { const int32 X = Texture->GetSizeX() / FGlobalData::LightArrayX; const int32 Y = Texture->GetSizeY() / FGlobalData::LightArrayY; - const int32 ColorIndex = X * i + j * Y * Texture->GetSizeX(); - LightArrayPanel->UpdateLightArray(i, j, *(Colors + ColorIndex)); + // const int32 ColorIndex = X * i + j * Y * Texture->GetSizeX(); + // LightArrayPanel->UpdateLightArray(i, j, *(Colors + ColorIndex)); } } Texture->GetPlatformData()->Mips[0].BulkData.Unlock(); } - +void SCutMainWindow::OnUpdateLightArray(const TArray& LightArray) +{ + ICutMainWidgetInterface::OnUpdateLightArray(LightArray); + LightArrayPanel->LightGridColors = LightArray; +} END_SLATE_FUNCTION_BUILD_OPTIMIZATION diff --git a/Source/Cut5/Widgets/SCutMainWindow.h b/Source/Cut5/Widgets/SCutMainWindow.h index 9132be1..a8dc331 100644 --- a/Source/Cut5/Widgets/SCutMainWindow.h +++ b/Source/Cut5/Widgets/SCutMainWindow.h @@ -35,5 +35,6 @@ public: virtual void OnUpdateVideo(FGuid UUID, UTexture2D* Texture) override; + virtual void OnUpdateLightArray(const TArray& LightArray) override; }; diff --git a/Source/Cut5/Widgets/STimelineClip.cpp b/Source/Cut5/Widgets/STimelineClip.cpp index a50c0c3..186405f 100644 --- a/Source/Cut5/Widgets/STimelineClip.cpp +++ b/Source/Cut5/Widgets/STimelineClip.cpp @@ -4,6 +4,8 @@ #include "STimelineClip.h" #include "SlateOptMacros.h" +#include "Engine/Engine.h" +#include "Engine/Texture2D.h" BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION @@ -93,7 +95,6 @@ void STimelineClip::Seek(int32 Frame) // ClipData->VideoCapture->read(Read); UTexture2D* Texture = UTexture2D::CreateTransient(Read.cols, Read.rows, PF_B8G8R8A8); - if (Texture) { A = FDateTime::Now(); @@ -116,6 +117,17 @@ void STimelineClip::Seek(int32 Frame) } break; + case ETrackType::LightArrayTrack: + { + const int32 Offset = Frame - (ClipData->ClipStartTime / FGlobalData::DefaultTimeTickSpace); + const int32 SeekMovieFrame = ClipData->VideoStartFrame + Offset; + if (SeekMovieFrame < ClipData->LightArrayData.Num()) + { + MainWidgetInterface->OnUpdateLightArray(ClipData->LightArrayData[SeekMovieFrame]); + } + break; + } + default: break; } diff --git a/Source/Cut5/Widgets/STimelineClip.h b/Source/Cut5/Widgets/STimelineClip.h index 5afa653..448eb9d 100644 --- a/Source/Cut5/Widgets/STimelineClip.h +++ b/Source/Cut5/Widgets/STimelineClip.h @@ -11,6 +11,8 @@ #include #include +#include "Widgets/Layout/SBox.h" + /** * */ diff --git a/Source/Cut5/Widgets/STrackBody.cpp b/Source/Cut5/Widgets/STrackBody.cpp index 61447d0..9dd8083 100644 --- a/Source/Cut5/Widgets/STrackBody.cpp +++ b/Source/Cut5/Widgets/STrackBody.cpp @@ -4,6 +4,8 @@ #include "STrackBody.h" #include "SlateOptMacros.h" +#include "Cut5/Utils/OpencvUtils.h" +#include "Engine/Engine.h" #include "Widgets/Layout/SConstraintCanvas.h" BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION @@ -72,7 +74,17 @@ FReply STrackBody::OnDrop(const FGeometry& MyGeometry, const FDragDropEvent& Dra { const FTrackClipDragOperation& ClipDragOperation = static_cast(DragDropEvent.GetOperation().ToSharedRef().Get()); if (ClipDragOperation.TimelinePropertyData.Type != TrackHead->TrackData.TrackType) - return FReply::Handled().EndDragDrop(); + { + if (ClipDragOperation.TimelinePropertyData.Type == ETrackType::VideoTrack && TrackHead->TrackData.TrackType == ETrackType::LightArrayTrack) + { + } + else + { + return FReply::Handled().EndDragDrop(); + } + } + + FClipData NewClipData; NewClipData.ClipGuid = FGuid::NewGuid(); NewClipData.ClipType = ClipDragOperation.TimelinePropertyData.Type; @@ -83,10 +95,16 @@ FReply STrackBody::OnDrop(const FGeometry& MyGeometry, const FDragDropEvent& Dra NewClipData.MoviePath = ClipDragOperation.TimelinePropertyData.MoviePath; NewClipData.ClipEndTime = NewClipData.ClipStartTime + ClipDragOperation.TimelinePropertyData.MovieFrameLength * FGlobalData::DefaultTimeTickSpace; NewClipData.VideoCapture = ClipDragOperation.VideoCapture; + if (TrackHead->TrackData.TrackType == ETrackType::LightArrayTrack) + { + NewClipData.ClipType = ETrackType::LightArrayTrack; + NewClipData.LightArrayData = FOpencvUtils::GetVideoFrameLightArray(ClipDragOperation.TimelinePropertyData.MoviePath, FGlobalData::LightArrayX, FGlobalData::LightArrayY); + } } - else + else if (ClipDragOperation.TimelinePropertyData.Type == ETrackType::LightArrayTrack) { NewClipData.ClipEndTime = NewClipData.ClipStartTime + 200; + } diff --git a/Source/Cut5/Widgets/SVideoPlayer.h b/Source/Cut5/Widgets/SVideoPlayer.h index 4ba5d2a..09e5b1b 100644 --- a/Source/Cut5/Widgets/SVideoPlayer.h +++ b/Source/Cut5/Widgets/SVideoPlayer.h @@ -3,6 +3,7 @@ #pragma once #include "CoreMinimal.h" +#include "Engine/Texture2D.h" #include "Widgets/SCompoundWidget.h" /**