summaryrefslogtreecommitdiff
path: root/memory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'memory.cpp')
-rw-r--r--memory.cpp89
1 files changed, 76 insertions, 13 deletions
diff --git a/memory.cpp b/memory.cpp
index 47252fe..3a7697d 100644
--- a/memory.cpp
+++ b/memory.cpp
@@ -105,21 +105,16 @@ Block_Loop(memory *Memory, property_channel *Property, uint32 TotalCount, int *H
static uint32
Memory_Block_PrincipalBitmap_AllocateNew(project_data *File, project_state *State, memory *Memory)
{
- uint32 LastVal = 0;
- uint32 LastBlock = 0;
- uint32 c = 0;
- uint32 r = 0;
- while (r < File->Source_Count) {
- block_source Source = *(block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, c);
- if (Source.Occupied != 0) {
- LastBlock = (Source.Bitmap_Index > LastBlock) ? Source.Bitmap_Index : LastBlock;
- LastVal = r;
- r++;
- }
- c++;
+ int h = 0, c = 0, i = 0;
+ int MaxBlockIndex = 0;
+ while (Block_Loop(Memory, F_Sources, File->Source_Count, &h, &c, &i)) {
+ block_source *Source = (block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, i);
+ if (Source->Bitmap_Index > MaxBlockIndex)
+ MaxBlockIndex = i;
}
- block_source Source = *(block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, r);
+ block_source Source = *(block_source *)Memory_Block_AddressAtIndex(Memory, F_Sources, MaxBlockIndex);
+ uint32 LastBlock = Source.Bitmap_Index;
uint32 BlockSize = ((Source.Width * Source.Height * Source.BytesPerPixel) / BitmapBlockSize) + 1;
uint32 Blocks_Max = Memory->Slot[B_CachedBitmaps].Size / BitmapBlockSize;
@@ -296,3 +291,71 @@ Arbitrary_ShiftData(uint8 *Address_Start, uint8 *Address_End, uint64 ShiftAmount
}
}
}
+
+static uint64
+Data_Compress(memory *Memory, void *DataSource, uint64 DataSize, void *DataBuffer, uint64 DataBufferSize, int CompressionLevel)
+{
+ z_stream stream = {};
+ stream.next_in = (uint8 *)DataSource;
+ stream.avail_in = DataSize;
+ stream.next_out = (uint8 *)DataBuffer;
+ stream.avail_out = DataBufferSize;
+
+ if (deflateInit(&stream, CompressionLevel) != Z_OK)
+ {
+ Assert(0);
+ }
+
+ int status;
+ for ( ; ; )
+ {
+ status = deflate(&stream, Z_SYNC_FLUSH);
+
+ if (status == Z_STREAM_END || !stream.avail_in)
+ break;
+ else
+ Assert(0);
+ }
+
+ uint64 CompressedSize = stream.total_out;
+
+ if (deflateEnd(&stream) != Z_OK)
+ {
+ Assert(0);
+ }
+
+ return CompressedSize;
+}
+
+static void
+Data_Decompress(memory *Memory, void *CompressedLocation, uint64 CompressedSize, void *BitmapLocation, uint64 ExpectedSize)
+{
+ z_stream stream = {};
+ stream.next_in = (uint8 *)CompressedLocation;
+ stream.avail_in = CompressedSize;
+ stream.next_out = (uint8 *)BitmapLocation;
+ stream.avail_out = 2147483648;
+
+ if (inflateInit(&stream))
+ {
+ Assert(0);
+ }
+
+ int status;
+ for ( ; ; )
+ {
+ status = inflate(&stream, Z_NO_FLUSH);
+
+ if (status == Z_STREAM_END || !stream.avail_in)
+ break;
+ else
+ Assert(0);
+ }
+
+ // Assert(stream.total_out == ExpectedSize);
+
+ if (inflateEnd(&stream) != Z_OK)
+ {
+ Assert(0);
+ }
+}