Skip to content

Commit

Permalink
main: undo buffer lz4 compression
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-niklaus committed Mar 22, 2024
1 parent 2ba3cd3 commit 3b78643
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
44 changes: 21 additions & 23 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@
#include <stddef.h>
#include <string.h>
#include <stdlib.h>

#include <lz4.h>
#include <unistd.h>


#include <lz4.h>

#include "cairo.h"
#include "callbacks.h"
Expand Down Expand Up @@ -487,7 +484,6 @@ void redo_drawing (GromitData *data)
g_printerr("DEBUG: Redo drawing.\n");
}


/*
* compress image data and store it in undo_temp_buffer
*
Expand All @@ -501,16 +497,20 @@ void undo_compress(GromitData *data, cairo_surface_t *surface)
size_t src_bytes = rows * bytes_per_row;

size_t dest_bytes;
for (;;) {
for (;;)
{
dest_bytes = LZ4_compress_default(raw_data, data->undo_temp, src_bytes, data->undo_temp_size);
if (dest_bytes == 0) {
data->undo_temp_size *= 2;
data->undo_temp = g_realloc(data->undo_temp, data->undo_temp_size);
} else {
data->undo_temp_used = dest_bytes;
break;
}
}
if (dest_bytes == 0)
{
data->undo_temp_size *= 2;
data->undo_temp = g_realloc(data->undo_temp, data->undo_temp_size);
}
else
{
data->undo_temp_used = dest_bytes;
break;
}
}
}


Expand All @@ -519,18 +519,16 @@ void undo_compress(GromitData *data, cairo_surface_t *surface)
*/
void undo_temp_buffer_to_slot(GromitData *data, gint undo_slot)
{
size_t required = data->undo_temp_used;
if (data->undo_buffer_size[undo_slot] < required) {
data->undo_buffer[undo_slot] =
g_realloc(data->undo_buffer[undo_slot], required);
const size_t required = data->undo_temp_used;
if (data->undo_buffer_size[undo_slot] < required)
{
data->undo_buffer[undo_slot] = g_realloc(data->undo_buffer[undo_slot], required);
data->undo_buffer_size[undo_slot] = required;
}
data->undo_buffer_used[undo_slot] = required;

memcpy(data->undo_buffer[undo_slot], data->undo_temp, required);
}
data->undo_buffer_used[undo_slot] = required;
memcpy(data->undo_buffer[undo_slot], data->undo_temp, required);
}


/*
* decompress undo slot data and store it in cairo surface
*/
Expand Down
1 change: 0 additions & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ typedef struct
size_t undo_temp_used;
gint undo_head, undo_depth, redo_depth;


gboolean show_intro_on_startup;

} GromitData;
Expand Down

0 comments on commit 3b78643

Please sign in to comment.