commit c44b241509c0aec7b22d70f56507c659e31fdaca Author: Simon Budig Date: Sun Jun 10 19:40:18 2012 +0200 force buffer refresh, get bigger chunks diff --git a/soundfumble.c b/soundfumble.c index af8e568..6d30b51 100644 --- a/soundfumble.c +++ b/soundfumble.c @@ -16,7 +16,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include + +#include #include #include @@ -27,6 +28,8 @@ #include #include +#define N_ROWS 8 + typedef struct { gint samplerate; @@ -94,7 +97,7 @@ query (void) "Copyright amir@viel-zu.org", "2011", "_Sound Fumble", - "RGB*, GRAY*", + "*", GIMP_PLUGIN, G_N_ELEMENTS (args), 0, args, NULL); @@ -191,7 +194,8 @@ fumble (gint32 drawable_id) gint width, height, bpp; gint type; gint tile_height; - guchar *row; + guchar *rows; + gint buflen; gint channels; /* get the gegl buffer of the specified image */ @@ -199,8 +203,9 @@ fumble (gint32 drawable_id) buffer_format = gegl_buffer_get_format(buffer); width = gegl_buffer_get_width (buffer); height = gegl_buffer_get_height (buffer); - type = gimp_drawable_type (drawable_id); - row = g_new (guchar, width * bpp); + bpp = babl_format_get_bytes_per_pixel (buffer_format); + buflen = width * bpp * N_ROWS; + rows = g_new (guchar, buflen); /* gimp_drawable_mask_bounds (drawable_id, @@ -217,23 +222,39 @@ fumble (gint32 drawable_id) end = pcmconf.lines; while (pcmconf.loop == -1 || (loops++ <= pcmconf.loop)) { - for (begin = 0; begin < height; begin++) { + for (begin = 0; begin < height; begin += N_ROWS) { if(begin % (height/100) == 0) gimp_progress_update(((gdouble) begin) / height); - gegl_buffer_get(buffer, GEGL_RECTANGLE (0, begin, width, 1), 1.0, - buffer_format, row, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); - gint off; - gint len = 1024; + gegl_buffer_get(buffer, + GEGL_RECTANGLE (0, begin, width, + MIN (N_ROWS, height - begin)), + 1.0, buffer_format, rows, + GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); - for(off = 0; off < width; off+=len) { - pcm_write(row + off, len); - } + gint off; + gint len = MIN (N_ROWS, height - begin) * bpp * width; + + for (off = 0; off < len;) + off += pcm_write (rows + off, len - off); + + g_object_unref (buffer); + buffer = gimp_drawable_get_buffer(drawable_id); + buffer_format = gegl_buffer_get_format(buffer); + width = gegl_buffer_get_width (buffer); + height = gegl_buffer_get_height (buffer); + bpp = babl_format_get_bytes_per_pixel (buffer_format); + if (buflen != width * bpp * N_ROWS) + { + g_free (rows); + buflen = width * bpp * N_ROWS; + rows = g_new (guchar, buflen); + } } } gimp_progress_update(1); - g_free (row); + g_free (rows); g_object_unref (buffer); playback_quit();