From 8875d0226f0d38a1e5ef946e56cd15810627f5ac Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Wed, 3 Aug 2022 16:57:07 -0400 Subject: caching introduced --- createcalls.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 79 insertions(+), 11 deletions(-) (limited to 'createcalls.cpp') diff --git a/createcalls.cpp b/createcalls.cpp index 42ab9b1..892be0a 100644 --- a/createcalls.cpp +++ b/createcalls.cpp @@ -55,7 +55,6 @@ Source_Generate(project_data *File, memory *Memory, char *Path) if (!Found && AV_IsFileSupported(Path)) { Source->SourceType = source_type_video; - AV_CodecInfo_Init(Path, Source, Memory); Found = true; } @@ -178,27 +177,96 @@ project_layer * Layer_Init(project_data *File, memory *Memory) return File->Layer[a]; } +static cached_bitmap * +Cache_CheckBitmap(source *Source, layer_bitmap_info *BitmapInfo, memory *Memory, int32 TimelineFrame) +{ + memory_table *Table = &Memory->Slot[B_LoadedBitmaps]; + int32 FrameToSeek = TimelineFrame - BitmapInfo->FrameOffset; + if (FrameToSeek < 0) { FrameToSeek = 0; }; + for (int i = 0; i < Table->NumberOfPointers; i++) { + cached_bitmap *Bitmap = &Memory->Bitmap[i]; + if (Bitmap->Frame == FrameToSeek && Bitmap->SourceOwner == Source) { + return Bitmap; + } + } + return 0; +} + static void -Layer_UpdateBitmap(source *Source, layer_bitmap_info *BitmapInfo, memory *Memory, int32 CurrentFrame) { - AV_LoadVideoFrame(Source, BitmapInfo, Memory, CurrentFrame); - // UpdateEffects(Layer, Memory); +Layer_UpdateBitmap(project_layer *Layer, memory *Memory, int32 CurrentFrame) { + source *Source = Layer->Source; + layer_bitmap_info *BitmapInfo = &Layer->BitmapInfo; + cached_bitmap *Bitmap = Cache_CheckBitmap(Source, BitmapInfo, Memory, CurrentFrame); + if (Bitmap) { + uint16 Width = Source->Info.Width; + uint16 Height = Source->Info.Height; + uint16 BytesPerPixel = Source->Info.BytesPerPixel; + void *DestBuffer = BitmapInfo->BitmapBuffer; + Bitmap_ConvertPacking(Bitmap->Data, DestBuffer, Width, Height, BytesPerPixel, 0); + } else { + AV_LoadVideoFrame(Source, BitmapInfo, Memory, CurrentFrame); + } + for (int i = 0; i < Layer->NumberOfEffects; i++) + { + if (Layer->Effect[i]->IsActive) + Layer->Effect[i]->func(Source, BitmapInfo, Memory, Layer->Effect[i]->Property); + } } static void -LoadTestFootage(project_data *File, project_state *State, memory *Memory) +Layer_InitSource(project_layer *Layer, source *Source, memory *Memory) { - if (!Source_Generate(File, Memory, "../asset/24.mp4")) - PostMsg(State, "File open fail..."); - source *Source = &File->Source[0]; - project_layer *Layer = Layer_Init(File, Memory); Layer->Source = Source; - AV_PacketInfo_Init(&Layer->BitmapInfo, Memory); uint16 Height = Source->Info.Height; uint16 Width = Source->Info.Width; uint16 BytesPerPixel = Source->Info.BytesPerPixel; - Layer_AllocateBitmap(Memory, Width, Height, BytesPerPixel); + Layer->BitmapInfo.BitmapBuffer = Layer_AllocateBitmap(Memory, Width, Height, BytesPerPixel); +} +static void +Layer_PositionCenter(project_layer *Layer, uint16 Width, uint16 Height) { + Layer->x.CurrentValue.f = Width/2; + Layer->y.CurrentValue.f = Height/2; +} + +static void +Layer_CreateFromSource(project_data *File, project_state *State, memory *Memory, source *Source) +{ + project_layer *Layer = Layer_Init(File, Memory); + AV_Init(Source, &Layer->BitmapInfo, Memory); + Layer_InitSource(Layer, Source, Memory); + Layer_PositionCenter(Layer, File->Width, File->Height); + State->UpdateFrame = true; +} + +static void +LoadTestFootage(project_data *File, project_state *State, memory *Memory) +{ + if (!Source_Generate(File, Memory, "../asset/24.mp4")) + PostMsg(State, "File open fail..."); + source *Source = &File->Source[0]; + Layer_CreateFromSource(File, State, Memory, Source); SelectLayer(File->Layer[0], State, 0); + AddEffect(File->Layer[0], Memory, 2); + property_channel *Property = &File->Layer[0]->x; + ManualKeyframeInsertF(Property, Memory, 1, 500); + ManualKeyframeInsertF(Property, Memory, 30, 800); + ManualKeyframeInsertF(Property, Memory, 15, 400); + ManualKeyframeInsertF(Property, Memory, 20, 100); + Property->IsToggled = true; + Property->IsGraphToggled = true; + Property->GraphLength = 150; + Property->GraphYOffset = (Property->GraphWindowHeight - Property->GraphLength)/2; + + // Layer_CreateFromSource(File, State, Memory, Source); + + if (!Source_Generate(File, Memory, "../asset/p.mp4")) + PostMsg(State, "File open fail..."); + source *Source2 = &File->Source[1]; + project_layer *Layer2 = Layer_Init(File, Memory); + AV_Init(Source2, &Layer2->BitmapInfo, Memory); + Layer_InitSource(Layer2, Source2, Memory); + // AddEffect(File->Layer[0], Memory, 2); // project_layer *Layer1 = CreateDebugLayer(&File, &Memory, 9, 14); // project_layer *Layer1 = CreateSolidLayer(&File, &Memory, 9, 13, V4(1.0, 1.0, 1.0, 1.0)); -- cgit v1.2.3