[PATCH] pixels= for pixbuf

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

Hi,

In [email protected]
“[ruby-gnome2-devel-en] [PATCH] pixels= for pixbuf” on Wed, 30 Sep
2009 01:04:30 +0200,
Michal S. [email protected] 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

2009/10/4 Kouhei S. [email protected]:

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

For test application see the previous mail.

Thanks

Michal

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] [PATCH] pixels= for pixbuf” on Mon, 5 Oct
2009 22:11:15 +0200,
Michal S. [email protected] 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs