[gegl] algorithms: use smaller temp buffers in gegl_downscale_2x2_generic()
- From: N/A <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] algorithms: use smaller temp buffers in gegl_downscale_2x2_generic()
- Date: Wed, 6 Sep 2017 15:44:31 +0000 (UTC)
commit a40f4f530754d60d9775a4770015d8c83167c556
Author: Ell <ell_se yahoo com>
Date: Wed Sep 6 10:50:35 2017 -0400
algorithms: use smaller temp buffers in gegl_downscale_2x2_generic()
The temporary buffers allocated by gegl_downscale_2x2_generic() are
bigger than they ought to be. Use smaller buffers, and allow for
the possiblity of src_rowstride != src_width * bpp (although it
doesn't currently happen.)
gegl/gegl-algorithms.c | 57 ++++++++++++++++++++++++++++++++++++-----------
1 files changed, 43 insertions(+), 14 deletions(-)
---
diff --git a/gegl/gegl-algorithms.c b/gegl/gegl-algorithms.c
index de60929..dcd7b42 100644
--- a/gegl/gegl-algorithms.c
+++ b/gegl/gegl-algorithms.c
@@ -79,22 +79,51 @@ gegl_downscale_2x2_generic (const Babl *format,
{
gint y;
const Babl *tmp_format = gegl_babl_rgbA_linear_float ();
+ const Babl *from_fish = babl_fish (format, tmp_format);
const Babl *to_fish = babl_fish (tmp_format, format);
- void *in_tmp = gegl_malloc (src_height * src_rowstride * 4 * 4);
- void *out_tmp = gegl_malloc (src_height * src_rowstride * 4 * 4);
- guchar *src = out_tmp;
- guchar *dst = dst_data;
-
- babl_process (babl_fish (format, tmp_format),
- src_data, in_tmp, src_width * src_height);
- gegl_downscale_2x2_float (4 * 4, src_width, src_height,
- in_tmp, src_width * 4 * 4,
- out_tmp, src_width * 4 * 4);
- for (y = 0; y < src_height / 2; y++)
+ const gint bpp = babl_format_get_bytes_per_pixel (format);
+ const gint tmp_bpp = 4 * 4;
+ gint dst_width = src_width / 2;
+ gint dst_height = src_height / 2;
+ gint in_tmp_rowstride = src_width * tmp_bpp;
+ gint out_tmp_rowstride = dst_width * tmp_bpp;
+ void *in_tmp = gegl_malloc (src_height * in_tmp_rowstride);
+ void *out_tmp = gegl_malloc (dst_height * out_tmp_rowstride);
+
+ if (src_rowstride == src_width * bpp)
{
- babl_process (to_fish, src, dst, src_width / 2);
- dst += dst_rowstride;
- src += (src_width * 4 * 4);
+ babl_process (from_fish, src_data, in_tmp, src_width * src_height);
+ }
+ else
+ {
+ guchar *src = src_data;
+ guchar *dst = in_tmp;
+
+ for (y = 0; y < src_height; y++)
+ {
+ babl_process (from_fish, src, dst, src_width);
+ src += src_rowstride;
+ dst += in_tmp_rowstride;
+ }
+ }
+ gegl_downscale_2x2_float (tmp_bpp, src_width, src_height,
+ in_tmp, in_tmp_rowstride,
+ out_tmp, out_tmp_rowstride);
+ if (dst_rowstride == dst_width * bpp)
+ {
+ babl_process (to_fish, out_tmp, dst_data, dst_width * dst_height);
+ }
+ else
+ {
+ guchar *src = out_tmp;
+ guchar *dst = dst_data;
+
+ for (y = 0; y < dst_height; y++)
+ {
+ babl_process (to_fish, src, dst, dst_width);
+ src += out_tmp_rowstride;
+ dst += dst_rowstride;
+ }
}
gegl_free (in_tmp);
gegl_free (out_tmp);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]