From 8c5f06c37f3c267ecd8f867cd49765c366b5f47c Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Thu, 18 Aug 2022 23:11:29 -0400 Subject: many additions --- createcalls.cpp | 132 +++++++++++++++++++++++++++----------------------------- 1 file changed, 64 insertions(+), 68 deletions(-) (limited to 'createcalls.cpp') diff --git a/createcalls.cpp b/createcalls.cpp index 5564264..2e754af 100644 --- a/createcalls.cpp +++ b/createcalls.cpp @@ -12,25 +12,13 @@ Source_Generate(project_data *File, memory *Memory, void *Path) { Assert(File->NumberOfSources < MAX_SOURCES); source *Source = &File->Source[File->NumberOfSources]; + bool32 IsVideo = 0; - bool32 Found = 0; - - /* - // TODO(fox): Unbreak stbi! - int w, h; - if (stbi_info(Path, &w, &h, NULL)) { - Source->SourceType = source_type_image; - Found = true; - } - */ - - // TODO(fox): This cast won't work above STRING_MAX. - if (!Found && AV_IsFileSupported((char *)Path)) { - Source->SourceType = source_type_video; - Found = true; - } - - if (Found) { + if (AV_IsFileSupported((char *)Path, &IsVideo)) { + if (IsVideo) + Source->SourceType = source_type_video; + else + Source->SourceType = source_type_image; Action_Entry_Commit(Memory, action_entry_default, "Add source"); Action_Change_Commit(Memory, &Source->Path, &Source->Path, &Path, action_change_ptr); uint32 i = File->NumberOfSources + 1; @@ -44,32 +32,6 @@ Source_Generate(project_data *File, memory *Memory, void *Path) return 0; } - /* -static pixel_buffer -LoadImage(memory *Memory, char *filename) -{ - pixel_buffer Buffer = {}; - Buffer.BytesPerPixel = 4; - - int n = 0; - int h, w; - void *temp = stbi_load(filename, &w, &h, &n, 4); - // printf("%s", stbi_failure_reason()); - Buffer.Height = h; - Buffer.Width = w; - CalculateFull(&Buffer); - Buffer.Pitch = Buffer.FullWidth*Buffer.BytesPerPixel; - // TODO(fox): Implement custom malloc in stbi so we don't have to do this. - Buffer.OriginalBuffer = MoveImportToBitmap(Memory, &Buffer, temp); - stbi_image_free(temp); - Buffer.EffectBuffer = AllocateMemory(Memory, Buffer.FullWidth * Buffer.FullHeight * Buffer.BytesPerPixel, B_Scratch); - BitmapPackRGB(&Buffer); - Buffer.ToUpdate = true; - return Buffer; -} - - */ - static property_channel InitFloatProperty(char *Name, real32 Val, real32 ScrubVal, real32 MinVal = PROPERTY_REAL_MIN, real32 MaxVal = PROPERTY_REAL_MAX) { property_channel Property = {}; @@ -83,7 +45,6 @@ InitFloatProperty(char *Name, real32 Val, real32 ScrubVal, real32 MinVal = PROPE return Property; } - static void CreateKeyframeBlock(property_channel *Property, memory *Memory) { @@ -211,15 +172,29 @@ Mask_RasterizePoints(mask *Mask) if (i+1 == Mask->NumberOfPoints) Point1 = Mask->Point[0]; - if (Point0.HandleBezier || Point1.HandleBezier) { + if (Point0.HandleBezier && Point1.HandleBezier) { Bezier_CubicCalcPoints(Point0.Pos, Point0.Pos + Point0.TangentRight, Point1.Pos + Point1.TangentLeft, Point1.Pos, Mask->TriangulatedPointCache, &Mask->NumberOfVerts); + } else if (Point0.HandleBezier) { + Bezier_CubicCalcPoints(Point0.Pos, Point0.Pos + Point0.TangentRight, Point1.Pos, Point1.Pos, + Mask->TriangulatedPointCache, &Mask->NumberOfVerts); + } else if (Point1.HandleBezier) { + Bezier_CubicCalcPoints(Point0.Pos, Point0.Pos, Point1.Pos + Point1.TangentLeft, Point1.Pos, + Mask->TriangulatedPointCache, &Mask->NumberOfVerts); } else { real32 *Data = (real32 *)Mask->TriangulatedPointCache + Mask->NumberOfVerts*3; *(Data++) = Point0.Pos.x; *(Data++) = Point0.Pos.y; *(Data++) = 0; - Mask->NumberOfVerts += 1; + // NOTE(fox): CubicCalcPoints sometimes misses generating the start + // point of the next path in the above two cases, so I'm making + // straight lines always add both points as a hotfix. This leads + // to cases of duplicate verts, but it doesn't seem like it harms + // the rendering in any way. + *(Data++) = Point1.Pos.x; + *(Data++) = Point1.Pos.y; + *(Data++) = 0; + Mask->NumberOfVerts += 2; } } } @@ -354,7 +329,7 @@ Layer_UpdateBitmap(project_data *File, project_layer *Layer, memory *Memory, int cached_bitmap *Bitmap = Cache_CheckBitmap(Source, BitmapInfo, Memory, CurrentFrame); if (!Bitmap) { if (Source->SourceType == source_type_image) { - Bitmap = STB_LoadStill(Source, BitmapInfo, Memory); + Bitmap = AV_LoadVideoFrame(Source, BitmapInfo, Memory, 1); } else { Bitmap = AV_LoadVideoFrame(Source, BitmapInfo, Memory, CurrentFrame); } @@ -364,26 +339,35 @@ Layer_UpdateBitmap(project_data *File, project_layer *Layer, memory *Memory, int uint16 BytesPerPixel = Source->Info.BytesPerPixel; void *DestBuffer = BitmapInfo->BitmapBuffer; uint64 UnpackedSize = Bitmap_CalcUnpackedBytes(Source->Info.Width, Source->Info.Height, Source->Info.BytesPerPixel); +#if PACKEDRGB uint64 PackedSize = Bitmap_CalcTotalBytes(Source->Info.Width, Source->Info.Height, Source->Info.BytesPerPixel); - Bitmap_CopyToPointer(Bitmap->Data, DestBuffer, BytesPerPixel, UnpackedSize); - - TestGL_InitTexture(&BitmapInfo->Test, DestBuffer, Width, Height); - if (Layer->NumberOfMasks) { - for (int i = 0; i < Layer->NumberOfMasks; i++) { - mask *Mask = &Layer->Mask[i]; - if (Mask->IsClosed) - Mask_TriangulateAndRasterize(Memory, Layer, Mask); + if (Layer->NumberOfMasks == 0 && Layer->NumberOfEffects == 0) { + Bitmap_ConvertPacking(Bitmap->Data, Memory->Scratch, Width, Height, BytesPerPixel, 0); + Bitmap_CopyToPointer(Memory->Scratch, DestBuffer, BytesPerPixel, PackedSize); + } else { + Bitmap_CopyToPointer(Bitmap->Data, DestBuffer, BytesPerPixel, UnpackedSize); + TestGL_InitTexture(&BitmapInfo->Test, DestBuffer, Width, Height); + + if (Layer->NumberOfMasks) { + for (int i = 0; i < Layer->NumberOfMasks; i++) { + mask *Mask = &Layer->Mask[i]; + if (Mask->IsClosed) + Mask_TriangulateAndRasterize(Memory, Layer, Mask); + } } - } - for (int i = 0; i < Layer->NumberOfEffects; i++) - { - if (Layer->Effect[i]->IsActive) - Layer->Effect[i]->func(Source, BitmapInfo, Memory, Layer->Effect[i]->Property); + 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, PackedSize); } - Bitmap_ConvertPacking(DestBuffer, Memory->Scratch, Width, Height, BytesPerPixel, 0); - Bitmap_CopyToPointer(Memory->Scratch, DestBuffer, BytesPerPixel, PackedSize); +#else + Bitmap_CopyToPointer(Bitmap->Data, DestBuffer, BytesPerPixel, UnpackedSize); +#endif } static ImVec2 @@ -422,10 +406,19 @@ LoadTestFootage(project_data *File, project_state *State, memory *Memory) Source_Generate(File, Memory, SourceString); source *Source = &File->Source[0]; Layer_CreateFromSource(File, State, Memory, Source); - // Action_Undo(Memory); - // Action_Redo(Memory); - SelectLayer(File->Layer[0], State, 0); + property_channel *Property = &File->Layer[0]->x; + // for (int i = 0; i < 15; i++) + // ManualKeyframeInsertF(Property, Memory, i*2, i*2*100); + ManualKeyframeInsertF(Property, Memory, 1, 100); + ManualKeyframeInsertF(Property, Memory, 3, 300); + ManualKeyframeInsertF(Property, Memory, 23, 2300); + ManualKeyframeInsertF(Property, Memory, 5, 500); + Property->IsToggled = true; + Property->IsGraphToggled = true; + Property->GraphLength = 150; + Property->GraphYOffset = (Property->GraphWindowHeight - Property->GraphLength)/2; + // AddEffect(File->Layer[0], Memory, 3); /* @@ -484,9 +477,12 @@ LoadTestFootage(project_data *File, project_state *State, memory *Memory) // Layer2->StartFrame = 11; // Layer2->EndFrame = 23; - // if (!Source_Generate(File, Memory, "../asset/b.jpg")) + // void *SourceString1 = String_GenerateFromChar(Memory, "../asset/b.jpg"); + // if (!Source_Generate(File, Memory, SourceString1)) // PostMsg(State, "File open fail..."); - // source *Source2 = &File->Source[2]; + // source *Source1 = &File->Source[1]; + // for (int i = 0; i < 25; i++) + // Layer_CreateFromSource(File, State, Memory, Source1); // project_layer *Layer2 = Layer_Init(File, Memory); // Layer_InitSource(Layer2, Source2, Memory); -- cgit v1.2.3