Commit 08c95527 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

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
parent feff2c6b
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>
* plug-ins/pygimp/pygimp-colors.c (pygimp_rgb_from_pyobject): no
......
......@@ -217,15 +217,14 @@ void
grabarea (void)
{
GimpPixelRgn src_rgn;
guchar *src_row;
guchar *src;
gint alpha, bpp;
gboolean has_alpha;
gint x, y;
ppm_t *p;
gint x1, y1, x2, y2;
gint row, col;
int rowstride;
gint rowstride;
gpointer pr;
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
......@@ -235,94 +234,103 @@ grabarea (void)
ppm_new (&infile, x2-x1, y2-y1);
p = &infile;
if (has_alpha)
{
ppm_new (&inalpha, x2-x1, y2-y1);
}
ppm_new (&inalpha, x2-x1, y2-y1);
rowstride = p->width * 3;
src_row = g_new (guchar, (x2 - x1) * bpp);
gimp_pixel_rgn_init (&src_rgn, drawable,
0, 0, x2 - x1, y2 - y1,
FALSE, FALSE);
if (bpp == 3)
{ /* RGB */
int bpr = (x2 - x1) * 3;
for (pr = gimp_pixel_rgns_register (1, &src_rgn);
pr != NULL;
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));
memcpy (p->col + row * rowstride, src_row, bpr);
}
}
else if (bpp > 3)
{ /* RGBA */
for (row = 0, y = y1; y < y2; row++, y++)
{
guchar *tmprow = p->col + row * rowstride;
guchar *tmparow = inalpha.col + row * rowstride;
case 1:
for (y = 0, row = src_rgn.y - y1; y < src_rgn.h; y++, row++)
{
const guchar *s = src;
guchar *tmprow = p->col + row * rowstride;
gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1));
src = src_row;
for (x = 0, col = src_rgn.x - x1; x < src_rgn.w; x++, col++)
{
gint k = col * 3;
for (col = 0, x = x1; x < x2; col++, x++)
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++)
{
int k = col * 3;
const guchar *s = src;
guchar *tmprow = p->col + row * rowstride;
guchar *tmparow = inalpha.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];
tmparow[k] = 255 - s[1];
tmprow[k+0] = src[0];
tmprow[k+1] = src[1];
tmprow[k+2] = src[2];
tmparow[k] = 255 - src[3];
src += src_rgn.bpp;
s += src_rgn.bpp;
}
src += src_rgn.rowstride;
}
}
}
else if (bpp == 2)
{
/* GrayA */
for (row = 0, y = y1; y < y2; row++, y++)
{
guchar *tmprow = p->col + row * rowstride;
guchar *tmparow = inalpha.col + row * rowstride;
break;
gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1));
src = src_row;
case 3:
col = src_rgn.x - x1;
for (col = 0, x = x1; x < x2; col++, x++)
for (y = 0, row = src_rgn.y - y1; y < src_rgn.h; y++, row++)
{
int k = col * 3;
memcpy (p->col + row * rowstride + col * 3, src, src_rgn.w * 3);
tmprow[k+0] = src[0];
tmprow[k+1] = src[0];
tmprow[k+2] = src[0];
tmparow[k] = 255 - src[1];
src += src_rgn.bpp;
src += src_rgn.rowstride;
}
}
}
else
{ /* Gray */
for (row = 0, y = y1; y < y2; row++, y++)
{
guchar *tmprow = p->col + row * rowstride;
break;
gimp_pixel_rgn_get_row (&src_rgn, src_row, x1, y, (x2 - x1));
src = src_row;
for (col = 0, x = x1; x < x2; col++, x++)
case 4:
for (y = 0, row = src_rgn.y - y1; y < src_rgn.h; y++, row++)
{
int k = col * 3;
const guchar *s = src;
guchar *tmprow = p->col + row * rowstride;
guchar *tmparow = inalpha.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[1];
tmprow[k + 2] = s[2];
tmparow[k] = 255 - s[3];
s += src_rgn.bpp;
}
tmprow[k+0] = src[0];
tmprow[k+1] = src[0];
tmprow[k+2] = src[0];
src += src_rgn.bpp;
src += src_rgn.rowstride;
}
break;
}
}
g_free (src_row);
}
static void
......@@ -337,7 +345,7 @@ gimpressionist_main (void)
ppm_t *p;
gint x1, y1, x2, y2;
gint row, col;
int rowstride;
gint rowstride;
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
......
......@@ -74,79 +74,49 @@ preview_free_resources (void)
void
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))
{
infile_copy_to_ppm (&backup_ppm);
if ((backup_ppm.width != PREVIEWSIZE) ||
(backup_ppm.height != PREVIEWSIZE))
resize_fast (&backup_ppm, PREVIEWSIZE, PREVIEWSIZE);
if (img_has_alpha)
{
infile_copy_alpha_to_ppm (&alpha_backup_ppm);
if ((alpha_backup_ppm.width != PREVIEWSIZE) ||
(alpha_backup_ppm.height != PREVIEWSIZE))
resize_fast (&alpha_backup_ppm, PREVIEWSIZE, PREVIEWSIZE);
}
}
if (!PPM_IS_INITED (&preview_ppm))
{
ppm_copy (&backup_ppm, &preview_ppm);
if (img_has_alpha)
ppm_copy (&alpha_backup_ppm, &alpha_ppm);
}
if (d)
{
store_values ();
if (GPOINTER_TO_INT (d) != 2)
repaint (&preview_ppm, &alpha_ppm);
}
if (!PPM_IS_INITED (&backup_ppm))
{
infile_copy_to_ppm (&backup_ppm);
if ((backup_ppm.width != PREVIEWSIZE) ||
(backup_ppm.height != PREVIEWSIZE))
resize_fast (&backup_ppm, PREVIEWSIZE, PREVIEWSIZE);
if (img_has_alpha)
drawalpha (&preview_ppm, &alpha_ppm);
{
infile_copy_alpha_to_ppm (&alpha_backup_ppm);
if ((alpha_backup_ppm.width != PREVIEWSIZE) ||
(alpha_backup_ppm.height != PREVIEWSIZE))
resize_fast (&alpha_backup_ppm, PREVIEWSIZE, PREVIEWSIZE);
}
}
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
0, 0, PREVIEWSIZE, PREVIEWSIZE,
GIMP_RGB_IMAGE,
preview_ppm.col,
PREVIEWSIZE * 3);
if (!PPM_IS_INITED (&preview_ppm))
{
ppm_copy (&backup_ppm, &preview_ppm);
ppm_kill (&preview_ppm);
if (img_has_alpha)
ppm_kill (&alpha_ppm);
ppm_copy (&alpha_backup_ppm, &alpha_ppm);
}
if (d)
{
store_values ();
if (GPOINTER_TO_INT (d) != 2)
repaint (&preview_ppm, &alpha_ppm);
}
if (img_has_alpha)
drawalpha (&preview_ppm, &alpha_ppm);
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
0, 0, PREVIEWSIZE, PREVIEWSIZE,
GIMP_RGB_IMAGE,
preview_ppm.col,
PREVIEWSIZE * 3);
ppm_kill (&preview_ppm);
if (img_has_alpha)
ppm_kill (&alpha_ppm);
}
static void
......
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