Commit 9d33a9a9 authored by Michael Natterer's avatar Michael Natterer 😴

plug-ins: port animation-optimize to GEGL, stupid 8-bit port only

parent acea533a
...@@ -263,6 +263,7 @@ animation_optimize_LDADD = \ ...@@ -263,6 +263,7 @@ animation_optimize_LDADD = \
$(libgimpbase) \ $(libgimpbase) \
$(CAIRO_LIBS) \ $(CAIRO_LIBS) \
$(GDK_PIXBUF_LIBS) \ $(GDK_PIXBUF_LIBS) \
$(GEGL_LIBS) \
$(RT_LIBS) \ $(RT_LIBS) \
$(INTLLIBS) \ $(INTLLIBS) \
$(animation_optimize_RC) $(animation_optimize_RC)
......
...@@ -103,7 +103,6 @@ static gint32 image_id; ...@@ -103,7 +103,6 @@ static gint32 image_id;
static gint32 new_image_id; static gint32 new_image_id;
static gint32 total_frames; static gint32 total_frames;
static gint32 *layers; static gint32 *layers;
static GimpDrawable *drawable;
static GimpImageBaseType imagetype; static GimpImageBaseType imagetype;
static GimpImageType drawabletype_alpha; static GimpImageType drawabletype_alpha;
static guchar pixelstep; static guchar pixelstep;
...@@ -240,6 +239,7 @@ run (const gchar *name, ...@@ -240,6 +239,7 @@ run (const gchar *name,
run_mode = param[0].data.d_int32; run_mode = param[0].data.d_int32;
INIT_I18N (); INIT_I18N ();
gegl_init (NULL, NULL);
if (run_mode == GIMP_RUN_NONINTERACTIVE && n_params != 3) if (run_mode == GIMP_RUN_NONINTERACTIVE && n_params != 3)
{ {
...@@ -296,6 +296,26 @@ total_alpha (guchar *imdata, ...@@ -296,6 +296,26 @@ total_alpha (guchar *imdata,
memset (imdata, 0, numpix * bytespp); memset (imdata, 0, numpix * bytespp);
} }
static const Babl *
get_format (gint32 drawable_ID)
{
if (gimp_drawable_is_rgb (drawable_ID))
{
if (gimp_drawable_has_alpha (drawable_ID))
return babl_format ("R'G'B'A u8");
else
return babl_format ("R'G'B' u8");
}
else if (gimp_drawable_is_gray (drawable_ID))
{
if (gimp_drawable_has_alpha (drawable_ID))
return babl_format ("Y'A u8");
else
return babl_format ("Y' u8");
}
return gimp_drawable_get_format (drawable_ID);
}
static void static void
compose_row (gint frame_num, compose_row (gint frame_num,
...@@ -303,12 +323,13 @@ compose_row (gint frame_num, ...@@ -303,12 +323,13 @@ compose_row (gint frame_num,
gint row_num, gint row_num,
guchar *dest, guchar *dest,
gint dest_width, gint dest_width,
GimpDrawable *drawable, gint32 drawable_ID,
gboolean cleanup) gboolean cleanup)
{ {
static guchar *line_buf = NULL; static guchar *line_buf = NULL;
GeglBuffer *src_buffer;
const Babl *format;
guchar *srcptr; guchar *srcptr;
GimpPixelRgn pixel_rgn;
gint rawx, rawy, rawbpp, rawwidth, rawheight; gint rawx, rawy, rawbpp, rawwidth, rawheight;
gint i; gint i;
gboolean has_alpha; gboolean has_alpha;
...@@ -329,20 +350,20 @@ compose_row (gint frame_num, ...@@ -329,20 +350,20 @@ compose_row (gint frame_num,
total_alpha (dest, dest_width, pixelstep); total_alpha (dest, dest_width, pixelstep);
} }
gimp_drawable_offsets (drawable->drawable_id, gimp_drawable_offsets (drawable_ID, &rawx, &rawy);
&rawx,
&rawy);
rawheight = gimp_drawable_height (drawable->drawable_id); rawwidth = gimp_drawable_width (drawable_ID);
rawheight = gimp_drawable_height (drawable_ID);
/* this frame has nothing to give us for this row; return */ /* this frame has nothing to give us for this row; return */
if (row_num >= rawheight + rawy || if (row_num >= rawheight + rawy ||
row_num < rawy) row_num < rawy)
return; return;
rawbpp = gimp_drawable_bpp (drawable->drawable_id); format = get_format (drawable_ID);
rawwidth = gimp_drawable_width (drawable->drawable_id);
has_alpha = gimp_drawable_has_alpha (drawable->drawable_id); has_alpha = gimp_drawable_has_alpha (drawable_ID);
rawbpp = babl_format_get_bytes_per_pixel (format);
if (line_buf) if (line_buf)
{ {
...@@ -353,16 +374,14 @@ compose_row (gint frame_num, ...@@ -353,16 +374,14 @@ compose_row (gint frame_num,
/* Initialise and fetch the raw new frame row */ /* Initialise and fetch the raw new frame row */
gimp_pixel_rgn_init (&pixel_rgn, src_buffer = gimp_drawable_get_buffer (drawable_ID);
drawable,
0, row_num - rawy, gegl_buffer_get (src_buffer, GEGL_RECTANGLE (0, row_num - rawy,
rawwidth, 1, rawwidth, 1), 1.0,
FALSE, format, line_buf,
FALSE); GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
gimp_pixel_rgn_get_rect (&pixel_rgn,
line_buf, g_object_unref (src_buffer);
0, row_num - rawy,
rawwidth, 1);
/* render... */ /* render... */
...@@ -380,13 +399,13 @@ compose_row (gint frame_num, ...@@ -380,13 +399,13 @@ compose_row (gint frame_num,
{ {
dest[i*pixelstep +pi] = *(srcptr + pi); dest[i*pixelstep +pi] = *(srcptr + pi);
} }
dest[i*pixelstep + pixelstep - 1] = 255; dest[i*pixelstep + pixelstep - 1] = 255;
} }
} }
srcptr += rawbpp; srcptr += rawbpp;
} }
} }
...@@ -394,7 +413,6 @@ static gint32 ...@@ -394,7 +413,6 @@ static gint32
do_optimizations (GimpRunMode run_mode, do_optimizations (GimpRunMode run_mode,
gboolean diff_only) gboolean diff_only)
{ {
GimpPixelRgn pixel_rgn;
static guchar *rawframe = NULL; static guchar *rawframe = NULL;
guchar *srcptr; guchar *srcptr;
guchar *destptr; guchar *destptr;
...@@ -443,9 +461,6 @@ do_optimizations (GimpRunMode run_mode, ...@@ -443,9 +461,6 @@ do_optimizations (GimpRunMode run_mode,
imagetype = gimp_image_base_type (image_id); imagetype = gimp_image_base_type (image_id);
pixelstep = (imagetype == GIMP_RGB) ? 4 : 2; pixelstep = (imagetype == GIMP_RGB) ? 4 : 2;
/* gimp_tile_cache_ntiles(total_frames * (width / gimp_tile_width() + 1) );*/
drawabletype_alpha = (imagetype == GIMP_RGB) ? GIMP_RGBA_IMAGE : drawabletype_alpha = (imagetype == GIMP_RGB) ? GIMP_RGBA_IMAGE :
((imagetype == GIMP_INDEXED) ? GIMP_INDEXEDA_IMAGE : GIMP_GRAYA_IMAGE); ((imagetype == GIMP_INDEXED) ? GIMP_INDEXEDA_IMAGE : GIMP_GRAYA_IMAGE);
...@@ -510,21 +525,17 @@ do_optimizations (GimpRunMode run_mode, ...@@ -510,21 +525,17 @@ do_optimizations (GimpRunMode run_mode,
for (this_frame_num=0; this_frame_num<total_frames; this_frame_num++) for (this_frame_num=0; this_frame_num<total_frames; this_frame_num++)
{ {
drawable = gint32 drawable_ID = layers[total_frames-(this_frame_num+1)];
gimp_drawable_get (layers[total_frames-(this_frame_num+1)]);
dispose = get_frame_disposal (this_frame_num); dispose = get_frame_disposal (this_frame_num);
compose_row(this_frame_num, compose_row (this_frame_num,
dispose, dispose,
row, row,
these_rows[this_frame_num], these_rows[this_frame_num],
width, width,
drawable, drawable_ID,
FALSE FALSE);
);
gimp_drawable_detach(drawable);
} }
for (this_frame_num=0; this_frame_num<total_frames; this_frame_num++) for (this_frame_num=0; this_frame_num<total_frames; this_frame_num++)
...@@ -637,6 +648,9 @@ do_optimizations (GimpRunMode run_mode, ...@@ -637,6 +648,9 @@ do_optimizations (GimpRunMode run_mode,
if (opmode == OPBACKGROUND) if (opmode == OPBACKGROUND)
{ {
GeglBuffer *buffer;
const Babl *format;
new_layer_id = gimp_layer_new (new_image_id, new_layer_id = gimp_layer_new (new_image_id,
"Backgroundx", "Backgroundx",
width, height, width, height,
...@@ -646,17 +660,15 @@ do_optimizations (GimpRunMode run_mode, ...@@ -646,17 +660,15 @@ do_optimizations (GimpRunMode run_mode,
gimp_image_insert_layer (new_image_id, new_layer_id, -1, 0); gimp_image_insert_layer (new_image_id, new_layer_id, -1, 0);
drawable = gimp_drawable_get (new_layer_id); buffer = gimp_drawable_get_buffer (new_layer_id);
gimp_pixel_rgn_init (&pixel_rgn, drawable, format = get_format (new_layer_id);
0, 0,
width, height, gegl_buffer_set (buffer, GEGL_RECTANGLE (0, 0, width, height), 0,
TRUE, FALSE); format, back_frame,
gimp_pixel_rgn_set_rect (&pixel_rgn, back_frame, GEGL_ABYSS_NONE);
0, 0,
width, height); g_object_unref (buffer);
gimp_drawable_flush (drawable);
gimp_drawable_detach (drawable);
} }
else else
{ {
...@@ -666,12 +678,11 @@ do_optimizations (GimpRunMode run_mode, ...@@ -666,12 +678,11 @@ do_optimizations (GimpRunMode run_mode,
* BUILD THIS FRAME into our 'this_frame' buffer. * BUILD THIS FRAME into our 'this_frame' buffer.
*/ */
drawable = gint32 drawable_ID = layers[total_frames-(this_frame_num+1)];
gimp_drawable_get (layers[total_frames-(this_frame_num+1)]);
/* Image has been closed/etc since we got the layer list? */ /* Image has been closed/etc since we got the layer list? */
/* FIXME - How do we tell if a gimp_drawable_get() fails? */ /* FIXME - How do we tell if a gimp_drawable_get() fails? */
if (gimp_drawable_width (drawable->drawable_id) == 0) if (gimp_drawable_width (drawable_ID) == 0)
{ {
gimp_quit (); gimp_quit ();
} }
...@@ -686,15 +697,11 @@ do_optimizations (GimpRunMode run_mode, ...@@ -686,15 +697,11 @@ do_optimizations (GimpRunMode run_mode,
row, row,
&this_frame[pixelstep*width * row], &this_frame[pixelstep*width * row],
width, width,
drawable, drawable_ID,
FALSE FALSE
); );
} }
/* clean up */
gimp_drawable_detach(drawable);
if (opmode == OPFOREGROUND) if (opmode == OPFOREGROUND)
{ {
gint xit, yit, byteit; gint xit, yit, byteit;
...@@ -1056,6 +1063,9 @@ do_optimizations (GimpRunMode run_mode, ...@@ -1056,6 +1063,9 @@ do_optimizations (GimpRunMode run_mode,
} }
else else
{ {
GeglBuffer *buffer;
const Babl *format;
cumulated_delay = this_delay; cumulated_delay = this_delay;
last_true_frame = last_true_frame =
...@@ -1070,23 +1080,24 @@ do_optimizations (GimpRunMode run_mode, ...@@ -1070,23 +1080,24 @@ do_optimizations (GimpRunMode run_mode,
gimp_image_insert_layer (new_image_id, new_layer_id, -1, 0); gimp_image_insert_layer (new_image_id, new_layer_id, -1, 0);
drawable = gimp_drawable_get (new_layer_id); buffer = gimp_drawable_get_buffer (new_layer_id);
gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, format = get_format (new_layer_id);
bbox_right-bbox_left,
bbox_bottom-bbox_top, gegl_buffer_set (buffer,
TRUE, FALSE); GEGL_RECTANGLE (0, 0,
gimp_pixel_rgn_set_rect (&pixel_rgn, opti_frame, 0, 0, bbox_right-bbox_left,
bbox_right-bbox_left, bbox_bottom-bbox_top), 0,
bbox_bottom-bbox_top); format, opti_frame,
gimp_drawable_flush (drawable); GEGL_AUTO_ROWSTRIDE);
gimp_drawable_detach (drawable);
gimp_item_transform_translate (new_layer_id, bbox_left, bbox_top); g_object_unref (buffer);
} }
gimp_progress_update (((gdouble) this_frame_num + 1.0) / gimp_progress_update (((gdouble) this_frame_num + 1.0) /
((gdouble) total_frames)); ((gdouble) total_frames));
} }
gimp_progress_update (1.0); gimp_progress_update (1.0);
} }
......
%plugins = ( %plugins = (
'align-layers' => { ui => 1 }, 'align-layers' => { ui => 1 },
'animation-optimize' => {}, 'animation-optimize' => { gegl => 1},
# FIXME 'animation-play' => { ui => 1, gegl => 1 }, # FIXME 'animation-play' => { ui => 1, gegl => 1 },
'blinds' => { ui => 1, gegl => 1 }, 'blinds' => { ui => 1, gegl => 1 },
'border-average' => { ui => 1, gegl => 1 }, 'border-average' => { ui => 1, gegl => 1 },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment