Cannot set pixbuf pixels - how to modify an image?

Hello

I am using:

libgtk2-ruby1.8 0.19.0-3

I get:

image.rb:27:in step': undefined method pixels=’ for
#<Gdk::Pixbuf:0xb790c970 ptr=0x8ff1c38>
from image.rb:32:in on_button_clicked' from image.rb:5:in to_proc’
from image.rb:77:in call' from image.rb:77:in main’

the pixels= method is documented here:

http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gdk%3A%3APixbuf

Without reloading the pixels the image seems unchanged.

Any advice on modifying images welcome.

I want to change individual pixels programatically and view the
results in realtime, hence the pixels accessor. I just want to
visually verify what is done to the image, I am not particularly
interested in performance. While it would be possible to draw the
image programatically as well I would prefer loading a test pattern
from a file so that it can be replaced easily.

Thanks

Michal

On 26/07/2009, Michal S. [email protected] wrote:

     from image.rb:32:in `on_button_clicked'
     from image.rb:5:in `to_proc'
     from image.rb:77:in `call'
     from image.rb:77:in `main'

the pixels= method is documented here:

http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gdk%3A%3APixbuf

Without reloading the pixels the image seems unchanged.

Which I resolved by patching the pixbuf bindings.

This still leaves some problems. After the pixel data is changed it
should be also invalidated on the image widget and its window redrawn.
Although I am drawing in the idle loop no redrawing occurs if I only
schedule it. I have to force redraw. The remaining issue is how to
find the pixel to be invalidated. For some reason the image is offset
inside the window. Perhaps the easiest solution would be packing it
into an eventbox for now.

Thanks

Michal

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] cannot set pixbuf pixels - how to modify
an image?” on Tue, 28 Jul 2009 03:13:00 +0200,
Michal S. [email protected] wrote:

#<Gdk::Pixbuf:0xb790c970 ptr=0x8ff1c38>

Which I resolved by patching the pixbuf bindings.

set_pixels:

get_pixel, set_pixel:

  • Are they needed?

Thanks,

kou

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] cannot set pixbuf pixels - how to modify
an image?” on Sun, 2 Aug 2009 08:37:15 +0200,
Michal S. [email protected] wrote:

whatever was described in README.EXT)
Please.

  • Why memmove()? Should we use memcpy()?

memmove is the safer variant. If the user got to the original pointer
somehow the copied regions might overlap. While it’s unlikely one
more check should not impact performance and should avoid some
interesting bugs.

It seems that the user can’t get the original pointer.
If the user can get the original pointer, the user doesn’t
need to set pixels. The user can only change the original
pointer.

So I think that we can use memcpy().

  • Should we require “pixbuf.pixels.size == new_pixels.size”?

I guess it’s OK to set only part of the pixels. I am not sure
returning error is appropriate if the sizes do not match.

If we provide an ‘offset’ argument, it will be reasonable.
But set_pixels doesn’t provide it.

So I think that the sizes should be matched.

get_pixel, set_pixel:

  • Are they needed?

When you do not want to set all pixels of a large bitmap they might be
faster. And they give the high-level interface so they should be the
primary access method for high-level language like ruby.

They should be probably converted to match the color format used by
other methods,though.

When they work as you said, we should consider about
{get,set}_pixel. Is it OK?

Anyway we should treat get_pixels and {get,set}_pixel with
separated patches.

Thanks,

kou

2009/8/2 Kouhei S. [email protected]:

 * We should use RSTRING_PTR() instead of RSTRING()->ptr
  and RSTRING_LEN() instead of RSTRING()->len.
 * We should return self for setter method:
  http://ruby-gnome2.sourceforge.jp/hiki.cgi?Naming+and+Conversion+Rules#Accessors+(Setter%2FGetter+methods)

OK, these are easy to change, I just used whatever worked (and
whatever was described in README.EXT)

 * Why memmove()? Should we use memcpy()?

memmove is the safer variant. If the user got to the original pointer
somehow the copied regions might overlap. While it’s unlikely one
more check should not impact performance and should avoid some
interesting bugs.

 * Should we require “pixbuf.pixels.size == new_pixels.size”?

I guess it’s OK to set only part of the pixels. I am not sure
returning error is appropriate if the sizes do not match.

get_pixel, set_pixel:

 * Are they needed?

When you do not want to set all pixels of a large bitmap they might be
faster. And they give the high-level interface so they should be the
primary access method for high-level language like ruby.

They should be probably converted to match the color format used by
other methods,though.

Thanks

Michal

2009/8/2 Kouhei S. [email protected]:

 * We should use RSTRING_PTR() instead of RSTRING()->ptr

So I think that we can use memcpy().

 * Should we require “pixbuf.pixels.size == new_pixels.size”?

I guess it’s OK to set only part of the pixels. I am not sure
returning error is appropriate if the sizes do not match.

If we provide an ‘offset’ argument, it will be reasonable.
But set_pixels doesn’t provide it.

So I think that the sizes should be matched.

Perhaps a [] interface would be better than pixels and pixels= then?

Thanks

Michal

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] cannot set pixbuf pixels - how to modify
an image?” on Mon, 3 Aug 2009 14:19:52 +0200,
Michal S. [email protected] wrote:

Perhaps a [] interface would be better than pixels and pixels= then?

I don’t think so.
It will be used for pixel and pixel= but they are the next
step. They should be considered after pixels=. OK?

Thanks,

kou