From b26f27d9e3fd44ec5775accdc3666a339684be4c Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Mon, 1 Aug 2022 20:03:12 -0400 Subject: large changes to bitmap structure --- main.h | 134 ++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 71 insertions(+), 63 deletions(-) (limited to 'main.h') diff --git a/main.h b/main.h index 612e24f..691d915 100644 --- a/main.h +++ b/main.h @@ -1,50 +1,7 @@ -enum source_type { - source_none, - source_video, - source_image -}; - enum instruction_mode { - scalar_only, - sse_enabled, - avx_enabled -}; - -struct pixel_buffer { - void *OriginalBuffer; - void *EffectBuffer; - void *Scratch; - uint16 Width; - uint16 Height; - // IMPORTANT(fox): Since we're storing 4x4 chunks, I'm opting to pad out each - // dimension with an extra 1-3 pixels to make our lookup functions simpler. - // This has the cost of extra RAM, but it's a miniscule amount (0.2% extra - // data for a worst-case 1080p 16bpc frame, or 140 kb). - uint16 FullWidth; - uint16 FullHeight; - uint16 Pitch; - uint16 BytesPerPixel; - bool32 ToUpdate; // Set whenever effects or video frames need to be updated. -}; - -struct av_info { - AVFormatContext *FileFormatContext; - AVCodecParameters *VideoCodecParameters; - const AVCodec* VideoCodec; - const AVCodecHWConfig* VideoHWConfig; - AVPixelFormat HWPixFormat; - AVCodecContext *VideoCodecContext; - AVPacket *VideoPacket; - AVFrame *VideoFrame; - AVStream *VideoStream; - SwsContext *RGBContext; - - uint16 StreamIndex; - real32 FPS; - int32 IntFPS; - real32 AvgPTSPerSecond; - real32 AvgPTSPerFrame; - uint64 LastPTS; + instruction_mode_scalar, + instruction_mode_sse, + instruction_mode_avx }; struct cache { @@ -79,9 +36,10 @@ enum memory_table_list { F_Strings, P_UIState, - P_SourceData, + P_AVInfo, - B_Scratch, + B_LayerBitmaps, + B_LoadedBitmaps, }; struct memory_table { @@ -97,8 +55,12 @@ struct global_memory { uint64 Size; }; +struct cached_bitmap_block; + struct memory { memory_table Slot[16]; + cached_bitmap_block *CacheBlock[256]; + uint16 NumberOfCachedBlocks; }; struct property_channel; @@ -127,7 +89,7 @@ enum var_type }; -global_variable char* BlendmodeNames[] = { +static char* BlendmodeNames[] = { "Normal", "Multiply", "Color Burn", @@ -213,6 +175,8 @@ struct property_header val MaxVal; }; +struct pixel_buffer {}; + struct effect_header { char *Name; @@ -233,20 +197,63 @@ struct effect { }; -// Note how pixel_buffer is first in both so we can cast to image_source if we -// don't care about the AV info. +// Information about a particular file. -struct video_source { - struct pixel_buffer Raster; - av_info AV; - int32 VideoFrameOffset; // the "true" position of video layers, separate from StartFrame - int32 VideoCurrentFrame; +enum source_type { + source_type_none, + source_type_video, + source_type_image }; -struct image_source { - struct pixel_buffer Raster; +// Probably best to consider source_info a part of the file data so we don't +// have to re-check each source on every project load. (except for AVInfo) + +struct source_info { + // Image and video + uint16 Width; + uint16 Height; + uint16 BytesPerPixel; + + // Video only + real32 FPS; + void* AVCodecInfo; // Internal data for the video decoder library. }; +struct source { + char *Path; + source_type SourceType; + source_info Info; +}; + +// Bitmaps from files are loaded into these temporary cache blocks. + +struct cached_bitmap_block { + source *SourceOwner; // Which source the data belongs to. + void *Data; // Unpacked data loaded from the source file. + uint32 StartFrame; + uint32 NumberOfCachedFrames; +}; + +struct layer_bitmap_info { + // Image and video + void *BitmapBuffer; // Each layer has a persistent bitmap that the source data gets packed into. + bool32 ToUpdate = 1; + + // Video only + int32 FrameOffset; // the "true" position of video layers, separate from StartFrame + int32 CurrentFrame = -1; // The last frame number rendered to the bitmap. + void *AVPacketInfo; // Internal data containing current frame info +}; + +struct comp_buffer { + uint16 Width; + uint16 Height; + uint16 BytesPerPixel; + void *PackedBuffer; + void *UnpackedBuffer; +}; + + struct transform_info { real32 XAxisPX; real32 XAxisPY; @@ -288,8 +295,8 @@ struct project_layer { bool32 IsSelected; - void *RenderInfo; - source_type SourceType; + source *Source; + layer_bitmap_info BitmapInfo; effect *Effect[MAX_EFFECTS]; uint16 NumberOfEffects; @@ -303,6 +310,7 @@ struct project_layer { transform_info TransformInfo; }; + // NOTE(fox): I have no idea how people normally do selection; currently I'm // treating it more "immediate." Instead of updating a selection state as // things are selected, I'm just calling functions that go through all the @@ -336,7 +344,7 @@ struct project_data uint16 NumberOfSelectedLayers; uint16 NumberOfLayers; - char *Source[MAX_SOURCES]; + source Source[MAX_SOURCES]; uint16 NumberOfSources; }; @@ -358,7 +366,7 @@ enum transforms_hotkey_interact { struct main_sdl { - pixel_buffer Buffer; + // pixel_buffer Buffer; SDL_Texture *Texture; SDL_Event Event; SDL_Window *Window; @@ -510,7 +518,7 @@ struct render_queue { project_data *File; project_state *State; - pixel_buffer *CompBuffer; + comp_buffer *CompBuffer; }; struct thread_info -- cgit v1.2.3