summaryrefslogtreecommitdiff
path: root/createcalls.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'createcalls.cpp')
-rw-r--r--createcalls.cpp466
1 files changed, 240 insertions, 226 deletions
diff --git a/createcalls.cpp b/createcalls.cpp
index 7088694..42ab9b1 100644
--- a/createcalls.cpp
+++ b/createcalls.cpp
@@ -1,4 +1,4 @@
-internal void
+static void
IncrementFrame(project_data *File, int16 Amount) {
if ((File->CurrentFrame <= 0 && Amount < File->StartFrame) || (File->CurrentFrame >= File->EndFrame)) {
File->CurrentFrame = 0;
@@ -7,46 +7,70 @@ IncrementFrame(project_data *File, int16 Amount) {
}
}
-internal void
-CalculateFull(pixel_buffer *Buffer) {
- uint16 ExtraWidth = 4 - (Buffer->Width % 4);
+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 - (Buffer->Height % 4);
+ uint16 ExtraHeight = 4 - (Height % 4);
if (ExtraHeight == 4)
ExtraHeight = 0;
- Buffer->FullWidth = Buffer->Width + ExtraWidth;
- Buffer->FullHeight = Buffer->Height + ExtraHeight;
+ *WidthP = Width + ExtraWidth;
+ *HeightP = Height + ExtraHeight;
}
-internal pixel_buffer
-CreateBuffer(int Width, int Height, memory *Memory)
-{
- pixel_buffer Buffer = {};
- Buffer.BytesPerPixel = 4;
- Buffer.Width = Width;
- Buffer.Height = Height;
- CalculateFull(&Buffer);
- Buffer.Pitch = Buffer.FullWidth*Buffer.BytesPerPixel;
- Buffer.OriginalBuffer = AllocateMemory(Memory, Buffer.FullWidth * Buffer.FullHeight * Buffer.BytesPerPixel, B_Scratch);
- Buffer.EffectBuffer = AllocateMemory(Memory, Buffer.FullWidth * Buffer.FullHeight * Buffer.BytesPerPixel, B_Scratch);
- Buffer.ToUpdate = true;
- return Buffer;
+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;
}
-internal void
-AddSource(project_data *File, memory *Memory, char *Path)
+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)
{
- int16 a = File->NumberOfSources++;
- Assert(a < MAX_SOURCES);
- if (Path == NULL) {
- File->Source[a] = (char *)AllocateMemory(Memory, STRING_SIZE, F_Strings);
- } else {
- File->Source[a] = Path;
+ Assert(File->NumberOfSources < MAX_SOURCES);
+ source *Source = &File->Source[File->NumberOfSources];
+
+ bool32 Found = 0;
+
+ int w, h;
+ if (stbi_info(Path, &w, &h, NULL)) {
+ Source->Info.Width = w;
+ Source->Info.Height = h;
+ Source->SourceType = source_type_image;
+ Found = true;
+ }
+
+ if (!Found && AV_IsFileSupported(Path)) {
+ Source->SourceType = source_type_video;
+ AV_CodecInfo_Init(Path, Source, Memory);
+ Found = true;
+ }
+
+ if (Found) {
+ Source->Info.BytesPerPixel = 4;
+ Source->Path = Path;
+ File->NumberOfSources++;
+ return 1;
}
+
+ return 0;
}
-internal pixel_buffer
+ /*
+static pixel_buffer
LoadImage(memory *Memory, char *filename)
{
pixel_buffer Buffer = {};
@@ -69,110 +93,9 @@ LoadImage(memory *Memory, char *filename)
return Buffer;
}
-internal pixel_buffer
-CreateSolidBitmap(memory *Memory, uint16 Height, uint16 Width, v4 Color) {
- pixel_buffer Buffer = {};
- Buffer.BytesPerPixel = 4;
- Buffer.Height = Height;
- Buffer.Width = Width;
- CalculateFull(&Buffer);
- Buffer.Pitch = Buffer.FullWidth*Buffer.BytesPerPixel;
- Buffer.OriginalBuffer = AllocateMemory(Memory, Buffer.FullHeight * Buffer.FullWidth * Buffer.BytesPerPixel, B_Scratch);
- Buffer.EffectBuffer = AllocateMemory(Memory, Buffer.FullHeight * Buffer.FullWidth * Buffer.BytesPerPixel, B_Scratch);
- DebugFillSolid(&Buffer, Color);
- BitmapPackRGB(&Buffer);
- Buffer.ToUpdate = true;
- return Buffer;
-}
-
-internal pixel_buffer
-CreateDebugBitmap(memory *Memory, uint16 Height, uint16 Width) {
- pixel_buffer Buffer = {};
- Buffer.BytesPerPixel = 4;
- Buffer.Height = Height;
- Buffer.Width = Width;
- CalculateFull(&Buffer);
- Buffer.Pitch = Buffer.FullWidth*Buffer.BytesPerPixel;
- Buffer.OriginalBuffer = AllocateMemory(Memory, Buffer.FullHeight * Buffer.FullWidth * Buffer.BytesPerPixel, B_Scratch);
- Buffer.EffectBuffer = AllocateMemory(Memory, Buffer.FullHeight * Buffer.FullWidth * Buffer.BytesPerPixel, B_Scratch);
- DebugBitmap(&Buffer);
- BitmapPackRGB(&Buffer);
- Buffer.ToUpdate = true;
- return Buffer;
-}
-
-
-internal void
-DrawHistogram(project_layer *Layer, pixel_buffer *UIBuffer, void *Scratch, memory *Memory, sdl_input Input, project_state *State,
- rectangle Box)
-{
- uint16 Padding = 20; //UI->LayerPadding / 5;
- uint16 Margin = 100;
-
- uint16 *Levels = (uint16 *)Scratch;
-
- uint16 *Mean = (Levels + 256*7);
-
- uint32 Color = 0;
- uint32 AltColor = ColToUint32(V4(0.1,0.1,0.1,1.0));
-
- // this is a bad idea
- real32 *Zoom = (real32 *)(Levels + 256*6);
- if (*Zoom < 0.0f)
- *Zoom = 0.0f;
- uint16 *SelectedChannel = (uint16 *)(Levels + 256*6 + 3);
-
- if (*SelectedChannel == 0) {
- Color = ColToUint32(V4(0.6,0.6,0.6,1.0));
- } else if (*SelectedChannel == 1) {
- Levels += 256;
- Color = ColToUint32(V4(0.6,0.0,0.0,1.0));
- } else if (*SelectedChannel == 2) {
- Levels += 256*2;
- Color = ColToUint32(V4(0.0,0.6,0.0,1.0));
- } else if (*SelectedChannel == 3) {
- Levels += 256*3;
- Color = ColToUint32(V4(0.0,0.0,0.6,1.0));
- } else if (*SelectedChannel == 4) {
- Levels += 256*4;
- Color = ColToUint32(V4(0.9,0.9,0.9,1.0));
- }
-
-
- /*
- if (TestRectangle(Box, Input.Mouse) &&
- Input.MouseButton[0].IsDown)
- {
- State->ArbitrarySlide = 1;
- State->Sliding.RandomPointer = Zoom;
- }
*/
- uint8 *Row = ((uint8 *)UIBuffer->OriginalBuffer +
- UIBuffer->BytesPerPixel +
- UIBuffer->Pitch);
- for (int Y = 0;
- Y > Box.Min.y;
- Y--)
- {
- uint32 *Pixel = (uint32 *)Row + Box.Min.x;
- for(int X = Box.Min.x;
- X < Box.Max.x;
- ++X)
- {
- real32 Span = (Box.Max.x - Box.Min.x) / 256.0f;
- int16 XLocal = (X - Box.Min.x) / Span;
- int16 YLocal = -(Y - Box.Max.y);
- if (*(Levels + XLocal) > (YLocal * RoundReal32ToInt32(*Zoom)) && XLocal < 256)
- *Pixel++ = Color;
- else
- *Pixel++ = AltColor;
- }
- Row -= UIBuffer->Pitch;
- }
-}
-
-internal property_channel
+static property_channel
InitFloatProperty(char *Name, real32 Val, real32 ScrubVal, real32 MinVal = PROPERTY_REAL_MIN, real32 MaxVal = PROPERTY_REAL_MAX) {
property_channel Property = {};
Property.Name = Name;
@@ -185,66 +108,55 @@ InitFloatProperty(char *Name, real32 Val, real32 ScrubVal, real32 MinVal = PROPE
return Property;
}
-internal bool32
-IsSupportedFile(source_type *Type, char *filename) {
- bool32 Result = 0;
- if (stbi_info(filename, NULL, NULL, NULL)) {
- *Type = source_image;
- Result = 1;
- } else if (TestAV(filename)) {
- *Type = source_video;
- Result = 1;
- }
- return Result;
-}
-internal void
-CreateRenderInfo(project_layer *Layer, memory *Memory, project_data File, source_type Type, char *filename)
+static void
+CreateKeyframeBlock(property_channel *Property, memory *Memory)
{
- if (Type == source_image) {
- Layer->RenderInfo = AllocateMemory(Memory, sizeof(image_source), P_SourceData);
- image_source *Source = (image_source *)Layer->RenderInfo;
- Source->Raster = LoadImage(Memory, filename);
- Layer->SourceType = source_image;
-
- Layer->x.CurrentValue.f = 1280/2;
- Layer->y.CurrentValue.f = 720/2;
- Layer->StartFrame = 0;
- Layer->EndFrame = File.EndFrame;
- }
- else if (Type == source_video) {
- Layer->RenderInfo = AllocateMemory(Memory, sizeof(video_source), P_SourceData);
- video_source *Source = (video_source *)Layer->RenderInfo;
- InitAV(filename, &Source->AV);
-
- Layer->SourceType = source_video;
- Source->VideoCurrentFrame = -1;
+ int16 a = Property->NumberOfKeyframeBlocks++;
+ Assert(a < MAX_KEYFRAME_BLOCKS);
- int32 Width = Source->AV.VideoCodecContext->width;
- int32 Height = Source->AV.VideoCodecContext->height;
- Source->Raster = CreateBuffer(Width, Height, Memory);
+ Property->KeyframeBlock[a] = (keyframe_block *)AllocateMemory(Memory, sizeof(keyframe_block), F_Keyframes);
+}
- Layer->x.CurrentValue.f = 1280/2;
- Layer->y.CurrentValue.f = 720/2;
- Layer->StartFrame = 0;
- Layer->EndFrame = File.EndFrame;
- } else {
- Assert(0);
- }
+static void
+PostMsg(project_state *State, char *msg)
+{
+ State->MsgTime = 120;
+ State->Msg = msg;
}
+/*
+static project_layer *
+CreateSolidLayer(project_data *File, memory *Memory, uint16 Width, uint16 Height, v4 Col)
+{
+ project_layer *Layer = CreateLayer(File, Memory);
+ Layer->RenderInfo = AllocateMemory(Memory, sizeof(source_image), P_SourceData);
+ source_image *Source = (source_image *)Layer->RenderInfo;
+ Source->Raster = CreateSolidBitmap(Memory, Width, Height, Col);
+ Layer->SourceType = source_type_image;
+ return Layer;
+}
-internal void
-CreateKeyframeBlock(property_channel *Property, memory *Memory)
+static project_layer *
+CreateDebugLayer(project_data *File, memory *Memory, uint16 Width, uint16 Height, int i)
{
- int16 a = Property->NumberOfKeyframeBlocks++;
- Assert(a < MAX_KEYFRAME_BLOCKS);
+ project_layer *Layer = CreateLayer(File, Memory);
+ Layer->RenderInfo = AllocateMemory(Memory, sizeof(source_image), P_SourceData);
+ source_image *Source = (source_image *)Layer->RenderInfo;
+ Source->Raster = CreateDebugBitmap(Memory, Width, Height);
+ Layer->SourceType = source_type_image;
+ return Layer;
+}
+*/
- Property->KeyframeBlock[a] = (keyframe_block *)AllocateMemory(Memory, sizeof(keyframe_block), F_Keyframes);
+void * Layer_AllocateBitmap(memory *Memory, uint16 Width, uint16 Height, uint16 BytesPerPixel)
+{
+ uint64 TotalBytes = Bitmap_CalcTotalBytes(Width, Height, BytesPerPixel);
+ void *Address = AllocateMemory(Memory, TotalBytes, B_LayerBitmaps);
+ return Address;
}
-internal project_layer *
-CreateLayer(project_data *File, memory *Memory)
+project_layer * Layer_Init(project_data *File, memory *Memory)
{
int16 a = File->NumberOfLayers++;
Assert(a < MAX_LAYERS);
@@ -266,54 +178,28 @@ CreateLayer(project_data *File, memory *Memory)
return File->Layer[a];
}
-internal void
-PostMsg(project_state *State, char *msg)
-{
- State->MsgTime = 120;
- State->Msg = msg;
-}
-
-internal void
-CreateLayerFromSource(project_data *File, project_state *State, memory *Memory, char *filename)
-{
- source_type Type = source_none;
- if (IsSupportedFile(&Type, filename)) {
- project_layer *Layer = CreateLayer(File, Memory);
- CreateRenderInfo(Layer, Memory, *File, Type, filename);
- State->UpdateFrame = true;
- State->DemoButton = true;
- } else {
- PostMsg(State, "File open fail...");
- }
-}
-
-
-internal project_layer *
-CreateSolidLayer(project_data *File, memory *Memory, uint16 Width, uint16 Height, v4 Col)
-{
- project_layer *Layer = CreateLayer(File, Memory);
- Layer->RenderInfo = AllocateMemory(Memory, sizeof(image_source), P_SourceData);
- image_source *Source = (image_source *)Layer->RenderInfo;
- Source->Raster = CreateSolidBitmap(Memory, Width, Height, Col);
- Layer->SourceType = source_image;
- return Layer;
+static void
+Layer_UpdateBitmap(source *Source, layer_bitmap_info *BitmapInfo, memory *Memory, int32 CurrentFrame) {
+ AV_LoadVideoFrame(Source, BitmapInfo, Memory, CurrentFrame);
+ // UpdateEffects(Layer, Memory);
}
-internal project_layer *
-CreateDebugLayer(project_data *File, memory *Memory, uint16 Width, uint16 Height, int i)
-{
- project_layer *Layer = CreateLayer(File, Memory);
- Layer->RenderInfo = AllocateMemory(Memory, sizeof(image_source), P_SourceData);
- image_source *Source = (image_source *)Layer->RenderInfo;
- Source->Raster = CreateDebugBitmap(Memory, Width, Height);
- Layer->SourceType = source_image;
- return Layer;
-}
-
-internal void
+static void
LoadTestFootage(project_data *File, project_state *State, memory *Memory)
{
- CreateLayerFromSource(File, State, Memory, "../asset/24.mp4");
+ 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);
+
+ SelectLayer(File->Layer[0], State, 0);
+ // 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));
// Layer1->x.CurrentValue.f = 7;
@@ -322,9 +208,10 @@ LoadTestFootage(project_data *File, project_state *State, memory *Memory)
// Layer1->EndFrame = File.EndFrame;
}
-internal void
+static void
CreateDemoScene(project_data *File, memory *Memory)
{
+#if 0
project_layer *Layer1 = CreateSolidLayer(File, Memory, 720, 1280, V4(0.0, 0.0, 0.0, 1.0));
Layer1->x.CurrentValue.f = 1280/2;
Layer1->y.CurrentValue.f = 720/2;
@@ -350,9 +237,11 @@ CreateDemoScene(project_data *File, memory *Memory)
ManualKeyframeInsertF(&Layer3->x, Memory, 60, Layer3->x.CurrentValue.f+(1280/3));
Layer3->x.IsToggled = true;
Layer3->y.IsToggled = true;
+#endif
}
-internal void
+#if 0
+static void
CreateGrid(project_data *File, memory *Memory) {
uint16 Amount = 8;
real32 XInc = File->Width / Amount;
@@ -370,3 +259,128 @@ CreateGrid(project_data *File, memory *Memory) {
}
}
}
+#endif
+#if 0
+static void
+DrawHistogram(project_layer *Layer, pixel_buffer *UIBuffer, void *Scratch, memory *Memory, sdl_input Input, project_state *State,
+ rectangle Box)
+{
+ uint16 Padding = 20; //UI->LayerPadding / 5;
+ uint16 Margin = 100;
+
+ uint16 *Levels = (uint16 *)Scratch;
+
+ uint16 *Mean = (Levels + 256*7);
+
+ uint32 Color = 0;
+ uint32 AltColor = ColToUint32(V4(0.1,0.1,0.1,1.0));
+
+ // this is a bad idea
+ real32 *Zoom = (real32 *)(Levels + 256*6);
+ if (*Zoom < 0.0f)
+ *Zoom = 0.0f;
+ uint16 *SelectedChannel = (uint16 *)(Levels + 256*6 + 3);
+
+ if (*SelectedChannel == 0) {
+ Color = ColToUint32(V4(0.6,0.6,0.6,1.0));
+ } else if (*SelectedChannel == 1) {
+ Levels += 256;
+ Color = ColToUint32(V4(0.6,0.0,0.0,1.0));
+ } else if (*SelectedChannel == 2) {
+ Levels += 256*2;
+ Color = ColToUint32(V4(0.0,0.6,0.0,1.0));
+ } else if (*SelectedChannel == 3) {
+ Levels += 256*3;
+ Color = ColToUint32(V4(0.0,0.0,0.6,1.0));
+ } else if (*SelectedChannel == 4) {
+ Levels += 256*4;
+ Color = ColToUint32(V4(0.9,0.9,0.9,1.0));
+ }
+
+
+ /*
+ if (TestRectangle(Box, Input.Mouse) &&
+ Input.MouseButton[0].IsDown)
+ {
+ State->ArbitrarySlide = 1;
+ State->Sliding.RandomPointer = Zoom;
+ }
+ */
+
+ uint8 *Row = ((uint8 *)UIBuffer->OriginalBuffer +
+ UIBuffer->BytesPerPixel +
+ UIBuffer->Pitch);
+ for (int Y = 0;
+ Y > Box.Min.y;
+ Y--)
+ {
+ uint32 *Pixel = (uint32 *)Row + Box.Min.x;
+ for(int X = Box.Min.x;
+ X < Box.Max.x;
+ ++X)
+ {
+ real32 Span = (Box.Max.x - Box.Min.x) / 256.0f;
+ int16 XLocal = (X - Box.Min.x) / Span;
+ int16 YLocal = -(Y - Box.Max.y);
+ if (*(Levels + XLocal) > (YLocal * RoundReal32ToInt32(*Zoom)) && XLocal < 256)
+ *Pixel++ = Color;
+ else
+ *Pixel++ = AltColor;
+ }
+ Row -= UIBuffer->Pitch;
+ }
+}
+
+static pixel_buffer
+CreateSolidBitmap(memory *Memory, uint16 Height, uint16 Width, v4 Color) {
+ pixel_buffer Buffer = {};
+ Buffer.BytesPerPixel = 4;
+ Buffer.Height = Height;
+ Buffer.Width = Width;
+ CalculateFull(&Buffer);
+ Buffer.Pitch = Buffer.FullWidth*Buffer.BytesPerPixel;
+ Buffer.OriginalBuffer = AllocateMemory(Memory, Buffer.FullHeight * Buffer.FullWidth * Buffer.BytesPerPixel, B_Scratch);
+ Buffer.EffectBuffer = AllocateMemory(Memory, Buffer.FullHeight * Buffer.FullWidth * Buffer.BytesPerPixel, B_Scratch);
+ DebugFillSolid(&Buffer, Color);
+ BitmapPackRGB(&Buffer);
+ Buffer.ToUpdate = true;
+ return Buffer;
+}
+
+static pixel_buffer
+CreateDebugBitmap(memory *Memory, uint16 Height, uint16 Width) {
+ pixel_buffer Buffer = {};
+ Buffer.BytesPerPixel = 4;
+ Buffer.Height = Height;
+ Buffer.Width = Width;
+ CalculateFull(&Buffer);
+ Buffer.Pitch = Buffer.FullWidth*Buffer.BytesPerPixel;
+ Buffer.OriginalBuffer = AllocateMemory(Memory, Buffer.FullHeight * Buffer.FullWidth * Buffer.BytesPerPixel, B_Scratch);
+ Buffer.EffectBuffer = AllocateMemory(Memory, Buffer.FullHeight * Buffer.FullWidth * Buffer.BytesPerPixel, B_Scratch);
+ DebugBitmap(&Buffer);
+ BitmapPackRGB(&Buffer);
+ Buffer.ToUpdate = true;
+ return Buffer;
+}
+
+/*
+{
+ Layer->RenderInfo = AllocateMemory(Memory, sizeof(source_image), P_SourceData);
+ Layer->RenderInfo = AllocateMemory(Memory, sizeof(source_video), P_SourceData);
+ source_image *Source = (source_image *)Layer->RenderInfo;
+ Source->Raster = LoadImage(Memory, filename);
+ Layer->EndFrame = File.EndFrame;
+ Layer->x.CurrentValue.f = 1280/2;
+ Layer->y.CurrentValue.f = 720/2;
+ Layer->StartFrame = 0;
+
+
+ Layer->x.CurrentValue.f = 1280/2;
+ Layer->y.CurrentValue.f = 720/2;
+ Layer->StartFrame = 0;
+ Layer->EndFrame = File.EndFrame;
+}
+*/
+
+
+#endif