plug-ins: do not needlessly free/malloc() buffer of same size.
In an animated WebP, chances that layers/frame have the same size is high. It is uneeded to free then malloc again a buffer at each frame, unless we need more allocated memory. This is probably not so significant, but still feels nicer.
This commit is contained in:
@ -481,6 +481,7 @@ save_animation (const gchar *filename,
|
|||||||
gboolean status = TRUE;
|
gboolean status = TRUE;
|
||||||
FILE *outfile = NULL;
|
FILE *outfile = NULL;
|
||||||
guchar *buffer = NULL;
|
guchar *buffer = NULL;
|
||||||
|
gint buffer_size = 0;
|
||||||
gint w, h;
|
gint w, h;
|
||||||
gint bpp;
|
gint bpp;
|
||||||
gboolean has_alpha;
|
gboolean has_alpha;
|
||||||
@ -584,13 +585,21 @@ save_animation (const gchar *filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Attempt to allocate a buffer of the appropriate size */
|
/* Attempt to allocate a buffer of the appropriate size */
|
||||||
buffer = g_try_malloc (w * h * bpp);
|
if (! buffer || buffer_size < w * h * bpp)
|
||||||
|
{
|
||||||
|
buffer = g_try_realloc (buffer, w * h * bpp);
|
||||||
|
|
||||||
if (! buffer)
|
if (! buffer)
|
||||||
{
|
{
|
||||||
g_printerr ("Buffer error: 'buffer null'\n");
|
g_printerr ("Buffer error: 'buffer null'\n");
|
||||||
status = FALSE;
|
status = FALSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer_size = w * h * bpp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WebPConfigPreset (&config, params->preset, params->quality);
|
WebPConfigPreset (&config, params->preset, params->quality);
|
||||||
|
|
||||||
@ -638,7 +647,6 @@ save_animation (const gchar *filename,
|
|||||||
{
|
{
|
||||||
status = WebPPictureImportRGBA (&picture, buffer, w * bpp);
|
status = WebPPictureImportRGBA (&picture, buffer, w * bpp);
|
||||||
}
|
}
|
||||||
g_free (buffer);
|
|
||||||
|
|
||||||
if (! status)
|
if (! status)
|
||||||
{
|
{
|
||||||
@ -663,6 +671,7 @@ save_animation (const gchar *filename,
|
|||||||
gimp_progress_update ((loop + 1.0) / nLayers);
|
gimp_progress_update ((loop + 1.0) / nLayers);
|
||||||
frame_timestamp += (delay <= 0 || force_delay) ? default_delay : delay;
|
frame_timestamp += (delay <= 0 || force_delay) ? default_delay : delay;
|
||||||
}
|
}
|
||||||
|
g_free (buffer);
|
||||||
|
|
||||||
if (status == FALSE)
|
if (status == FALSE)
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user