From fc8040d695644aaca4596adebeca4ea1369ef630 Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Fri, 22 Jul 2022 20:45:08 -0400 Subject: first --- caching.cpp | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 caching.cpp (limited to 'caching.cpp') diff --git a/caching.cpp b/caching.cpp new file mode 100644 index 0000000..d84377a --- /dev/null +++ b/caching.cpp @@ -0,0 +1,171 @@ + +internal void +CacheFrame(cache *Cache, pixel_buffer *CompBuffer) +{ + + int MinX = 0; + int MinY = 0; + int MaxX = CompBuffer->Width; + int MaxY = CompBuffer->Height; + + + uint8 *Row = ((uint8 *)Cache->Address + + CompBuffer->BytesPerPixel + + MinY*CompBuffer->Pitch); + uint8 *CompRow = ((uint8 *)CompBuffer->OriginalBuffer + + CompBuffer->BytesPerPixel + + CompBuffer->Pitch); + for(int Y = MinY; + Y < MaxY; + ++Y) + { + uint32 *Pixel = (uint32 *)Row + MinX; + uint32 *CompPixel = (uint32 *)CompRow; + for(int X = MinX; + X < MaxX; + ++X) + { + *(uint32 *)Pixel++ = *(uint32 *)CompPixel; + CompPixel++; + } + Row += CompBuffer->Pitch; + CompRow += CompBuffer->Pitch; + } +} + +internal void +FetchCache(cache *Cache, pixel_buffer *CompBuffer) +{ + + int MinX = 0; + int MinY = 0; + int MaxX = CompBuffer->Width; + int MaxY = CompBuffer->Height; + + + uint8 *Row = ((uint8 *)Cache->Address + + CompBuffer->BytesPerPixel + + MinY*CompBuffer->Pitch); + uint8 *CompRow = ((uint8 *)CompBuffer->OriginalBuffer + + CompBuffer->BytesPerPixel + + CompBuffer->Pitch); + for(int Y = MinY; + Y < MaxY; + ++Y) + { + uint32 *Pixel = (uint32 *)Row + MinX; + uint32 *CompPixel = (uint32 *)CompRow; + for(int X = MinX; + X < MaxX; + ++X) + { + *(uint32 *)CompPixel = *(uint32 *)Pixel++; + CompPixel++; + } + Row += CompBuffer->Pitch; + CompRow += CompBuffer->Pitch; + } +} + +internal void +InteractToComp(pixel_buffer *CompBuffer, cache_pool *Cache) +{ + int MinX = 0; + int MinY = 0; + int MaxX = CompBuffer->Width; + int MaxY = CompBuffer->Height; + + uint8 *CompRow = ((uint8 *)CompBuffer->OriginalBuffer + + CompBuffer->BytesPerPixel + + CompBuffer->Pitch); + uint8 *Row0 = ((uint8 *)Cache->Intermediate[0].Address + + CompBuffer->BytesPerPixel + + CompBuffer->Pitch); + uint8 *Row1 = ((uint8 *)Cache->Intermediate[1].Address + + CompBuffer->BytesPerPixel + + CompBuffer->Pitch); + uint8 *Row2 = ((uint8 *)Cache->Intermediate[2].Address + + CompBuffer->BytesPerPixel + + CompBuffer->Pitch); + for(int Y = MinY; + Y < MaxY; + ++Y) + { + uint32 *CompPixel = (uint32 *)CompRow; + uint32 *Pixel0 = (uint32 *)Row0; + uint32 *Pixel1 = (uint32 *)Row1; + uint32 *Pixel2 = (uint32 *)Row2; + for(int X = MinX; + X < MaxX; + ++X) + { + RenderAlpha(CompPixel, *Pixel0); + RenderAlpha(CompPixel, *Pixel1); + RenderAlpha(CompPixel, *Pixel2); + CompPixel++; + Pixel0++; + Pixel1++; + Pixel2++; + } + CompRow += CompBuffer->Pitch; + Row0 += CompBuffer->Pitch; + Row1 += CompBuffer->Pitch; + Row2 += CompBuffer->Pitch; + } +} + +internal void +UncacheFrames(int16 Min, int16 Max, cache_pool *Cache) +{ + for (int16 i = Min; i < Max; i++) + Cache->Frame[i].Cached = false; +}; + +#if 0 +internal void +CacheKeyframeAtIndex(uint16 i, struct property_channel *Property, cache_pool *Cache) +{ + Assert(Property->NumberOfKeyframes > 0); + uint16 *Sorted = Property->Sorted + i; + if (Property->NumberOfKeyframes == 1) { + // nothing happens + } else if (Property->NumberOfKeyframes == 2) { + UncacheFrames(Property->Keyframe[0].FrameNumber, Property->Keyframe[1].FrameNumber, Cache); + } else if (i == 0) { + UncacheFrames(Property->Keyframe[*Sorted].FrameNumber, Property->Keyframe[*(Sorted+1)].FrameNumber, Cache); + } else if (i == Property->NumberOfKeyframes - 1) { + UncacheFrames(Property->Keyframe[*(Sorted-1)].FrameNumber, Property->Keyframe[*Sorted].FrameNumber, Cache); + } else { + UncacheFrames(Property->Keyframe[*(Sorted-1)].FrameNumber, Property->Keyframe[*(Sorted+1)].FrameNumber, Cache); + } +} + +internal void +SortAndCacheKeyframeAtFrame(uint16 f, struct property_channel *Property, cache_pool *Cache) +{ + Assert(Property->NumberOfKeyframes > 0); + if (Property->NumberOfKeyframes == 1) { + } else if (Property->NumberOfKeyframes == 2) { + UncacheFrames(Property->KeyframePTR[0]->FrameNumber, Property->KeyframePTR[1]->FrameNumber, Cache); + } else { + int i = 0; + for (; i < Property->NumberOfKeyframes - 1; i++) { + if (Property->KeyframePTR[i]->FrameNumber > Property->KeyframePTR[i+1]->FrameNumber) { + struct keyframe *Temp = Property->KeyframePTR[i]; + Property->KeyframePTR[i] = Property->KeyframePTR[i+1]; + Property->KeyframePTR[i+1] = Temp; + break; + } + if (Property->KeyframePTR[i]->FrameNumber >= f) + break; + } + if (i == 0) { + UncacheFrames(Property->KeyframePTR[i]->FrameNumber, Property->KeyframePTR[i+1]->FrameNumber, Cache); + } else if (i == Property->NumberOfKeyframes - 1) { + UncacheFrames(Property->KeyframePTR[i-1]->FrameNumber, Property->KeyframePTR[i]->FrameNumber, Cache); + } else { + UncacheFrames(Property->KeyframePTR[i-1]->FrameNumber, Property->KeyframePTR[i+1]->FrameNumber, Cache); + } + } +} +#endif -- cgit v1.2.3