summaryrefslogtreecommitdiff
path: root/createcalls.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'createcalls.cpp')
-rw-r--r--createcalls.cpp174
1 files changed, 118 insertions, 56 deletions
diff --git a/createcalls.cpp b/createcalls.cpp
index a767db8..a15ab70 100644
--- a/createcalls.cpp
+++ b/createcalls.cpp
@@ -7,36 +7,6 @@ IncrementFrame(project_data *File, int16 Amount) {
}
}
-static void
-Bitmap_CalcPackedDimensions(uint16 Width, uint16 Height, uint16 *WidthP, uint16 *HeightP) {
- uint16 ExtraWidth = 4 - (Width % 4);
- if (ExtraWidth == 4)
- ExtraWidth = 0;
- uint16 ExtraHeight = 4 - (Height % 4);
- if (ExtraHeight == 4)
- ExtraHeight = 0;
- *WidthP = Width + ExtraWidth;
- *HeightP = Height + ExtraHeight;
-}
-
-static uint16
-Bitmap_CalcByteOffset(uint16 BytesPerPixel) {
- uint16 ByteOffset = BytesPerPixel;
- if (InstructionMode == instruction_mode_avx)
- ByteOffset = 8*BytesPerPixel;
- if (InstructionMode == instruction_mode_sse)
- ByteOffset = 4*BytesPerPixel;
- return ByteOffset;
-}
-
-static uint64
-Bitmap_CalcTotalBytes(uint16 Width, uint16 Height, uint16 BytesPerPixel) {
- uint16 WidthP, HeightP;
- Bitmap_CalcPackedDimensions(Width, Height, &WidthP, &HeightP);
- uint64 TotalBytes = (uint64)WidthP*HeightP*BytesPerPixel;
- return TotalBytes;
-}
-
static bool32
Source_Generate(project_data *File, memory *Memory, char *Path)
{
@@ -148,6 +118,7 @@ CreateDebugLayer(project_data *File, memory *Memory, uint16 Width, uint16 Height
}
*/
+// Note we use total bytes here so we can use this memory for both packed and unpacked bitmaps.
void * Layer_AllocateBitmap(memory *Memory, uint16 Width, uint16 Height, uint16 BytesPerPixel)
{
uint64 TotalBytes = Bitmap_CalcTotalBytes(Width, Height, BytesPerPixel);
@@ -182,7 +153,10 @@ Cache_CheckBitmap(source *Source, layer_bitmap_info *BitmapInfo, memory *Memory,
{
memory_table *Table = &Memory->Slot[B_LoadedBitmaps];
int32 FrameToSeek = TimelineFrame - BitmapInfo->FrameOffset;
- if (FrameToSeek < 0) { FrameToSeek = 0; };
+ // Stills have a frame index of zero.
+ if (FrameToSeek < 0 || Source->SourceType == source_type_image) {
+ FrameToSeek = 0;
+ };
for (int i = 0; i < Table->NumberOfPointers; i++) {
cached_bitmap *Bitmap = &Memory->Bitmap[i];
if (Bitmap->Frame == FrameToSeek && Bitmap->SourceOwner == Source) {
@@ -192,33 +166,55 @@ Cache_CheckBitmap(source *Source, layer_bitmap_info *BitmapInfo, memory *Memory,
return 0;
}
+static cached_bitmap *
+STB_LoadStill(source *Source, layer_bitmap_info *BitmapInfo, memory *Memory)
+{
+ int n = 0;
+ int h, w;
+ void *temp = stbi_load(Source->Path, &w, &h, &n, 4);
+ Assert(temp);
+ cached_bitmap *Bitmap = Memory_RollingBitmap(Memory, Source, 0);
+ // Note the use of Unpacked since we haven't packed the bitmap and don't have any padding.
+ uint64 Size = Bitmap_CalcUnpackedBytes(Source->Info.Width, Source->Info.Height, Source->Info.BytesPerPixel);
+ Bitmap_CopyToPointer(temp, Bitmap->Data, Source->Info.BytesPerPixel, Size);
+ return Bitmap;
+}
+
+
static void
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);
+ if (!Bitmap) {
+ if (Source->SourceType == source_type_image) {
+ Bitmap = STB_LoadStill(Source, BitmapInfo, Memory);
+ } else {
+ Bitmap = AV_LoadVideoFrame(Source, BitmapInfo, Memory, CurrentFrame);
+ }
}
+ uint16 Width = Source->Info.Width;
+ uint16 Height = Source->Info.Height;
+ uint16 BytesPerPixel = Source->Info.BytesPerPixel;
+ void *DestBuffer = BitmapInfo->BitmapBuffer;
+ uint64 Size = Bitmap_CalcUnpackedBytes(Source->Info.Width, Source->Info.Height, Source->Info.BytesPerPixel);
+ Bitmap_CopyToPointer(Bitmap->Data, DestBuffer, BytesPerPixel, Size);
+ TestGL_InitTexture(&BitmapInfo->Test, DestBuffer, Width, Height);
for (int i = 0; i < Layer->NumberOfEffects; i++)
{
if (Layer->Effect[i]->IsActive)
Layer->Effect[i]->func(Source, BitmapInfo, Memory, Layer->Effect[i]->Property);
}
+ Bitmap_ConvertPacking(DestBuffer, Memory->Scratch, Width, Height, BytesPerPixel, 0);
+ Bitmap_CopyToPointer(Memory->Scratch, DestBuffer, BytesPerPixel, Size);
}
static void
Layer_InitSource(project_layer *Layer, source *Source, memory *Memory)
{
Layer->Source = Source;
- uint16 Height = Source->Info.Height;
uint16 Width = Source->Info.Width;
+ uint16 Height = Source->Info.Height;
uint16 BytesPerPixel = Source->Info.BytesPerPixel;
Layer->BitmapInfo.BitmapBuffer = Layer_AllocateBitmap(Memory, Width, Height, BytesPerPixel);
}
@@ -239,6 +235,48 @@ Layer_CreateFromSource(project_data *File, project_state *State, memory *Memory,
State->UpdateFrame = true;
}
+static ImVec2
+Layer_LocalToScreenSpace(project_layer *Layer, ui *UI, comp_buffer CompBuffer, v2 Point)
+{
+ real32 Rad = (Layer->rotation.CurrentValue.f * (PI / 180));
+ real32 s = Layer->scale.CurrentValue.f;
+ real32 AX = Layer->ax.CurrentValue.f;
+ real32 AY = Layer->ay.CurrentValue.f;
+ source *Source = Layer->Source;
+
+ v2 XAxis = (Point.x - AX*Source->Info.Width) * s * V2(cos(Rad), sin(Rad));
+ v2 YAxis = (Point.y - AY*Source->Info.Height) * -s * V2(sin(Rad), -cos(Rad));
+ v2 LocalPoint = XAxis + YAxis;
+ v2 CompUV = V2((Layer->x.CurrentValue.f + LocalPoint.x) / CompBuffer.Width,
+ (Layer->y.CurrentValue.f + LocalPoint.y) / CompBuffer.Height);
+ v2 ScreenPoint = V2(UI->CompPos.x + CompUV.x * UI->CompZoom.x,
+ UI->CompPos.y + CompUV.y * UI->CompZoom.y);
+
+ return ImVec2(ScreenPoint.x, ScreenPoint.y);
+}
+
+static void
+Mask_AddPoint(mask *Mask, ImVec2 Pos, ImVec2 TangentLeft, ImVec2 TangentRight,
+ ImVec2 Ratio0, ImVec2 Ratio1, uint16 Index)
+{
+ mask_point *Point = &Mask->Point[Index];
+ mask_point *NextPoint = &Mask->Point[Index+1];
+
+ Point->TangentRight = -V2(Ratio0);
+ NextPoint->TangentLeft = -V2(Ratio1);
+
+ for (int i = Mask->NumberOfPoints - 1; i > Index; i--) {
+ Mask->Point[i+1] = Mask->Point[i];
+ }
+ mask_point *PointToAdd = &Mask->Point[Index+1];
+ PointToAdd->Pos = {Pos.x, Pos.y};
+ PointToAdd->TangentLeft = {-TangentLeft.x, -TangentLeft.y};
+ PointToAdd->TangentRight = {-TangentRight.x, -TangentRight.y};
+ PointToAdd->TangentLeft = {-TangentLeft.x, -TangentLeft.y};
+ PointToAdd->TangentRight = {-TangentRight.x, -TangentRight.y};
+ Mask->NumberOfPoints++;
+}
+
static void
LoadTestFootage(project_data *File, project_state *State, memory *Memory)
{
@@ -247,27 +285,51 @@ LoadTestFootage(project_data *File, project_state *State, memory *Memory)
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;
+ AddEffect(File->Layer[0], Memory, 3);
+ mask *Mask = &File->Layer[0]->Mask[0];
+ File->Layer[0]->NumberOfMasks = 1;
+ Mask->Point[0].Pos = V2(200, 200);
+ Mask->Point[1].Pos = V2(1280, 0);
+ Mask->Point[2].Pos = V2(1280, 720);
+ Mask->Point[3].Pos = V2(0, 720);
+
+ Mask->Point[0].TangentLeft = V2(-50, 0);
+ Mask->Point[1].TangentLeft = V2(-50, 0);
+ Mask->Point[2].TangentLeft = V2(-50, 0);
+ Mask->Point[3].TangentLeft = V2(-50, 0);
+
+ Mask->Point[0].TangentRight = V2(50, 0);
+ Mask->Point[1].TangentRight = V2(50, 0);
+ Mask->Point[2].TangentRight = V2(50, 0);
+ Mask->Point[3].TangentRight = V2(50, 0);
+
+ Mask->NumberOfPoints = 4;
+ // 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);
- Layer2->StartFrame = 11;
- Layer2->EndFrame = 23;
+ // source *Source2 = &File->Source[1];
+ // project_layer *Layer2 = Layer_Init(File, Memory);
+ // AV_Init(Source2, &Layer2->BitmapInfo, Memory);
+ // Layer_InitSource(Layer2, Source2, Memory);
+ // Layer2->StartFrame = 11;
+ // Layer2->EndFrame = 23;
+
+ // if (!Source_Generate(File, Memory, "../asset/b.jpg"))
+ // PostMsg(State, "File open fail...");
+ // source *Source2 = &File->Source[2];
+ // project_layer *Layer2 = Layer_Init(File, Memory);
+ // Layer_InitSource(Layer2, Source2, Memory);
// AddEffect(File->Layer[0], Memory, 2);
// project_layer *Layer1 = CreateDebugLayer(&File, &Memory, 9, 14);