Re: [Gimp-developer] Double tile iterators?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jul 04, 2002 at 03:31:46PM +0200, Simon Budig wrote:
>
> I should have read the code before posting my last message:
> 
> Dr William Bland (wjb@xxxxxxxxxxxxxxxxxxxx) wrote:
> > I thought about using some kind of "double tile iterator" to do this, e.g:
> > 
> >   gimp_pixel_rgn_init (&image_rgn, image_drawable,
> > 			x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE);
> >   gimp_pixel_rgn_init (&select_rgn, select_drawable,
> > 			x1, y1, (x2 - x1), (y2 - y1), TRUE, TRUE);
> >   for (p1 = gimp_pixel_rgns_register (1, &image_rgn),
> > 	 p2 = gimp_pixel_rgns_register (1, &select_rgn);
> >        (p1 != NULL) && (p2 != NULL);
> >        p1 = gimp_pixel_rgns_process (p1),
> > 	 p2 = gimp_pixel_rgns_process (p2))
> 
> this better should be
>     p1 = gimp_pixel_rgns_register (2, &image_rgn, &select_rgn);
>     p1 != NULL;
>     p1 = gimp_pixel_rgns_process (p1)
> 
> >     {
> > 	/* Interesting stuff goes in here!            */
> > 	/* Set some of the pixels in select_drawable  */
> > 	/* depending on the pixels in image_drawable. */
> >     }
> 
> Then the core will care about the stuff I mentioned in the other mail.

Hi Simon,
	Thanks!  That looks much nicer.  Unfortunately I can't get it to
work properly (sorry, like I said, I'm a newbie at this ;-).  I now have
the following code:

static void
do_stuff (GimpDrawable *image_drawable, GimpDrawable *select_drawable)
{
  GimpPixelRgn image_rgn, select_rgn;
  gint x1=0, y1=0, x2=select_drawable->width, y2=select_drawable->height;
  guchar *image_data = NULL, *select_data;
  gint i;
  gint image_bytes = image_drawable->bpp, select_bytes = select_drawable->bpp;
  gint size;
  gpointer pr;

  gimp_pixel_rgn_init (&image_rgn, image_drawable, x1, y1,
			(x2 - x1), (y2 - y1), TRUE, TRUE);
  gimp_pixel_rgn_init (&select_rgn, select_drawable, x1, y1,
			(x2 - x1), (y2 - y1), TRUE, TRUE);
  for ( pr = gimp_pixel_rgns_register (2, &select_rgn, &image_rgn);
	pr != NULL;
        pr = gimp_pixel_rgns_process (pr))
    {
      size = select_rgn.w * select_rgn.h;
      select_data = select_rgn.data;

      while (size--)
	{
	  for (i=0; i<select_bytes; i++)
	    *select_data++ = 255*(size%2);
	}
    }
  /*  merge the shadow, update the drawable  */
  gimp_drawable_flush (select_drawable);
  gimp_drawable_merge_shadow (select_drawable->id, TRUE);
  gimp_drawable_update (select_drawable->id, x1, y1, (x2 - x1), (y2 - y1));
}


Note that I'm not yet actually *doing* anything with the data in
image_rgn, only select_rgn.  Now if I start gimp, create a blank 256*256
image, select everything and then run my plugin, I get:
	http://www.abstractnonsense.com/double.png
which is clearly not right!  Some of the pixels are correct, but there is
clearly some random fluff in there as well.
If I change the iterator to a single one, so that it reads
  for ( pr = gimp_pixel_rgns_register (1, &select_rgn);
then I get:
	http://www.abstractnonsense.com/single.png
which is correct but doesn't help since I will be needing the double
iterator soon.


Any ideas what's going on here?  Thanks again for your help.
Best wishes,
		Bill.


[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux