changed code that retrieves the source drawable to iterate over the data

2008-01-27  Sven Neumann  <sven@gimp.org>

	* plug-ins/gimpressionist/gimp.c (grabarea): changed code that
	retrieves the source drawable to iterate over the data 
tile-by-tile.


svn path=/trunk/; revision=24717
This commit is contained in:
Sven Neumann
2008-01-27 13:08:08 +00:00
committed by Sven Neumann
parent feff2c6b6d
commit 08c9552711
3 changed files with 131 additions and 148 deletions

View File

@ -1,3 +1,8 @@
2008-01-27 Sven Neumann <sven@gimp.org>
* plug-ins/gimpressionist/gimp.c (grabarea): changed code that
retrieves the source drawable to iterate over the data tile-by-tile.
2008-01-26 Manish Singh <yosh@gimp.org> 2008-01-26 Manish Singh <yosh@gimp.org>
* plug-ins/pygimp/pygimp-colors.c (pygimp_rgb_from_pyobject): no * plug-ins/pygimp/pygimp-colors.c (pygimp_rgb_from_pyobject): no

View File

@ -217,15 +217,14 @@ void
grabarea (void) grabarea (void)
{ {
GimpPixelRgn src_rgn; GimpPixelRgn src_rgn;
guchar *src_row;
guchar *src;
gint alpha, bpp; gint alpha, bpp;
gboolean has_alpha; gboolean has_alpha;
gint x, y; gint x, y;
ppm_t *p; ppm_t *p;
gint x1, y1, x2, y2; gint x1, y1, x2, y2;
gint row, col; gint row, col;
int rowstride; gint rowstride;
gpointer pr;
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
@ -235,94 +234,103 @@ grabarea (void)
ppm_new (&infile, x2-x1, y2-y1); ppm_new (&infile, x2-x1, y2-y1);
p = &infile; p = &infile;
if (has_alpha) if (has_alpha)
{
ppm_new (&inalpha, x2-x1, y2-y1); ppm_new (&inalpha, x2-x1, y2-y1);
}
rowstride = p->width * 3; rowstride = p->width * 3;
src_row = g_new (guchar, (x2 - x1) * bpp);
gimp_pixel_rgn_init (&src_rgn, drawable, gimp_pixel_rgn_init (&src_rgn, drawable,
0, 0, x2 - x1, y2 - y1, 0, 0, x2 - x1, y2 - y1,
FALSE, FALSE); FALSE, FALSE);
if (bpp == 3) for (pr = gimp_pixel_rgns_register (1, &src_rgn);
{ /* RGB */ pr != NULL;
int bpr = (x2 - x1) * 3; pr = gimp_pixel_rgns_process (pr))
{
const guchar *src = src_rgn.data;
for (row = 0, y = y1; y < y2; row++, y++) switch (bpp)
{ {
gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1)); case 1:
memcpy (p->col + row * rowstride, src_row, bpr); for (y = 0, row = src_rgn.y - y1; y < src_rgn.h; y++, row++)
}
}
else if (bpp > 3)
{ /* RGBA */
for (row = 0, y = y1; y < y2; row++, y++)
{ {
const guchar *s = src;
guchar *tmprow = p->col + row * rowstride;
for (x = 0, col = src_rgn.x - x1; x < src_rgn.w; x++, col++)
{
gint k = col * 3;
tmprow[k + 0] = s[0];
tmprow[k + 1] = s[0];
tmprow[k + 2] = s[0];
s += src_rgn.bpp;
}
src += src_rgn.rowstride;
}
break;
case 2:
for (y = 0, row = src_rgn.y - y1; y < src_rgn.h; y++, row++)
{
const guchar *s = src;
guchar *tmprow = p->col + row * rowstride; guchar *tmprow = p->col + row * rowstride;
guchar *tmparow = inalpha.col + row * rowstride; guchar *tmparow = inalpha.col + row * rowstride;
gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1)); for (x = 0, col = src_rgn.x - x1; x < src_rgn.w; x++, col++)
src = src_row; {
gint k = col * 3;
for (col = 0, x = x1; x < x2; col++, x++) tmprow[k + 0] = s[0];
{ tmprow[k + 1] = s[0];
int k = col * 3; tmprow[k + 2] = s[0];
tmparow[k] = 255 - s[1];
tmprow[k+0] = src[0]; s += src_rgn.bpp;
tmprow[k+1] = src[1];
tmprow[k+2] = src[2];
tmparow[k] = 255 - src[3];
src += src_rgn.bpp;
} }
src += src_rgn.rowstride;
} }
} break;
else if (bpp == 2)
case 3:
col = src_rgn.x - x1;
for (y = 0, row = src_rgn.y - y1; y < src_rgn.h; y++, row++)
{ {
/* GrayA */ memcpy (p->col + row * rowstride + col * 3, src, src_rgn.w * 3);
for (row = 0, y = y1; y < y2; row++, y++)
src += src_rgn.rowstride;
}
break;
case 4:
for (y = 0, row = src_rgn.y - y1; y < src_rgn.h; y++, row++)
{ {
const guchar *s = src;
guchar *tmprow = p->col + row * rowstride; guchar *tmprow = p->col + row * rowstride;
guchar *tmparow = inalpha.col + row * rowstride; guchar *tmparow = inalpha.col + row * rowstride;
gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1)); for (x = 0, col = src_rgn.x - x1; x < src_rgn.w; x++, col++)
src = src_row;
for (col = 0, x = x1; x < x2; col++, x++)
{ {
int k = col * 3; gint k = col * 3;
tmprow[k+0] = src[0]; tmprow[k + 0] = s[0];
tmprow[k+1] = src[0]; tmprow[k + 1] = s[1];
tmprow[k+2] = src[0]; tmprow[k + 2] = s[2];
tmparow[k] = 255 - src[1]; tmparow[k] = 255 - s[3];
src += src_rgn.bpp;
}
}
}
else
{ /* Gray */
for (row = 0, y = y1; y < y2; row++, y++)
{
guchar *tmprow = p->col + row * rowstride;
gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1)); s += src_rgn.bpp;
src = src_row; }
for (col = 0, x = x1; x < x2; col++, x++)
{
int k = col * 3;
tmprow[k+0] = src[0]; src += src_rgn.rowstride;
tmprow[k+1] = src[0]; }
tmprow[k+2] = src[0]; break;
src += src_rgn.bpp;
} }
} }
}
g_free (src_row);
} }
static void static void
@ -337,7 +345,7 @@ gimpressionist_main (void)
ppm_t *p; ppm_t *p;
gint x1, y1, x2, y2; gint x1, y1, x2, y2;
gint row, col; gint row, col;
int rowstride; gint rowstride;
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2); gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);

View File

@ -74,38 +74,6 @@ preview_free_resources (void)
void void
updatepreview (GtkWidget *wg, gpointer d) updatepreview (GtkWidget *wg, gpointer d)
{ {
/* This portion is remmed out because of the remming out of the
* code below.
* -- Shlomi Fish
* */
#if 0
guchar buf[PREVIEWSIZE*3];
if (!PPM_IS_INITED (&infile) && d)
grabarea();
#endif
/* It seems that infile.col must be true here. (after grabarea() that is.)
* Thus, I'm removing this entire portion of the code in hope that
* it works OK afterwards.
* -- Shlomi Fish
* */
#if 0
if (!PPM_IS_INITED (&infile) && !d) {
guchar *buffer;
buffer = g_new0 (guchar, 3*PREVIEWSIZE*PREVIEWSIZE);
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
0, 0, PREVIEWSIZE, PREVIEWSIZE,
GIMP_RGB_IMAGE,
buffer,
PREVIEWSIZE * 3);
g_free (buffer);
}
else
#endif
{
if (!PPM_IS_INITED (&backup_ppm)) if (!PPM_IS_INITED (&backup_ppm))
{ {
infile_copy_to_ppm (&backup_ppm); infile_copy_to_ppm (&backup_ppm);
@ -120,6 +88,7 @@ updatepreview (GtkWidget *wg, gpointer d)
resize_fast (&alpha_backup_ppm, PREVIEWSIZE, PREVIEWSIZE); resize_fast (&alpha_backup_ppm, PREVIEWSIZE, PREVIEWSIZE);
} }
} }
if (!PPM_IS_INITED (&preview_ppm)) if (!PPM_IS_INITED (&preview_ppm))
{ {
ppm_copy (&backup_ppm, &preview_ppm); ppm_copy (&backup_ppm, &preview_ppm);
@ -127,6 +96,7 @@ updatepreview (GtkWidget *wg, gpointer d)
if (img_has_alpha) if (img_has_alpha)
ppm_copy (&alpha_backup_ppm, &alpha_ppm); ppm_copy (&alpha_backup_ppm, &alpha_ppm);
} }
if (d) if (d)
{ {
store_values (); store_values ();
@ -134,6 +104,7 @@ updatepreview (GtkWidget *wg, gpointer d)
if (GPOINTER_TO_INT (d) != 2) if (GPOINTER_TO_INT (d) != 2)
repaint (&preview_ppm, &alpha_ppm); repaint (&preview_ppm, &alpha_ppm);
} }
if (img_has_alpha) if (img_has_alpha)
drawalpha (&preview_ppm, &alpha_ppm); drawalpha (&preview_ppm, &alpha_ppm);
@ -146,7 +117,6 @@ updatepreview (GtkWidget *wg, gpointer d)
ppm_kill (&preview_ppm); ppm_kill (&preview_ppm);
if (img_has_alpha) if (img_has_alpha)
ppm_kill (&alpha_ppm); ppm_kill (&alpha_ppm);
}
} }
static void static void