# \[PATCH\] pixels= for pixbuf

**URL:** <https://www.ruby-forum.com/t/patch-pixels-for-pixbuf/176394>\
**Category:** Ruby-Gnome 2\
**Created:** [September 30, 2009, 1:05am UTC](https://www.ruby-forum.com/t/patch-pixels-for-pixbuf/176394 "2009-09-30T01:05:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [September 30, 2009, 1:05am UTC](https://www.ruby-forum.com/t/patch-pixels-for-pixbuf/176394/1 "2009-09-30T01:05:21Z")

</div>

Attaching patch that allows changing pixels of pixbufs.

As requested the length of the supplied string is compared to the  
length of the buffer and exception is raised if they are not the same.

This could be probably changed to a gdk assertion instead.

Also attaching a sample application that uses this new method.

Thanks

Michal

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [October 4, 2009, 3:12pm UTC](https://www.ruby-forum.com/t/patch-pixels-for-pixbuf/176394/2 "2009-10-04T15:12:10Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“[ruby-gnome2-devel-en] [PATCH] pixels= for pixbuf” on Wed, 30 Sep  
2009 01:04:30 +0200,  
Michal S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Attaching patch that allows changing pixels of pixbufs.

Could you adapt coding style in your patch to codes in the  
same file?

> — ruby-gnome2-0.19.1/gdkpixbuf/rbgdk-pixbuf.c 2008-12-10 13:04:52.000000000 +0100  
> +++ ruby-gnome2-0.19.0.mod/gdkpixbuf/rbgdk-pixbuf.c 2009-09-29 22:11:50.000000000 +0200  
> @@ -30,6 +30,7 @@  
> GDK\_PIXBUF\_ERROR,  
> GDK\_PIXBUF\_ERROR\_INSUFFICIENT\_MEMORY,  
> “Insufficient memory to load image file”);  
> +#include \<string.h\>

#include line should be placed before #define lines.

> -static VALUE  
> -get\_pixels(self)
> 
> - VALUE self;  
> +static int pixels\_size(pixbuf)
> 
> - GdkPixbuf \*pixbuf;

We use

static int  
pixels\_size(pixbuf)  
GdkPixbuf \*pixbuf;

or

static int  
pixels\_size(GdkPixbuf \*pixbuf)

style. We prefer to the later.

> - Check\_Type (pixels, T\_STRING);

We doesn’t put a space between function name and a left  
parenthesis.

> - arg\_size = NUM2INT(rb\_funcall(pixels, rb\_intern(“length”), 0));

We use RSTRING\_LEN() for getting string length.

> - 
> 
> ```
> rb_raise(rb_eRangeError, "Pixels are %i bytes, %i bytes supplied.", size, arg_size);
> 
> ```

We use %d for formatting int.

> - /\* The user currently cannot get a pointer to the actual pixels, the data is copied to a String. \*/
> - memcpy(gdk\_pixbuf\_get\_pixels(pixbuf), RSTRING(pixels)-\>ptr, MIN(RSTRING(pixels)-\>len, size));

We use RSTRING\_PTR() for getting row C string and  
RSTRING\_LEN() for getting string length.

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [October 5, 2009, 10:12pm UTC](https://www.ruby-forum.com/t/patch-pixels-for-pixbuf/176394/3 "2009-10-05T22:12:30Z")

</div>

2009/10/4 Kouhei S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 

Attaching an updated patch that hopefully resolves the code style  
issues.

For test application see the previous mail.

Thanks

Michal

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [October 11, 2009, 6:51am UTC](https://www.ruby-forum.com/t/patch-pixels-for-pixbuf/176394/4 "2009-10-11T06:51:39Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] [PATCH] pixels= for pixbuf” on Mon, 5 Oct  
2009 22:11:15 +0200,  
Michal S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > Attaching patch that allows changing pixels of pixbufs.
> > 
> > Could you adapt coding style in your patch to codes in the  
> > same file?
> 
> Attaching an updated patch that hopefully resolves the code style issues.
> 
> For test application see the previous mail.

Thanks for fixing it!  
I’ve applied your patch in trunk.

–  
kou
