Re: gtkmm: Pixbuf::get_pixels()

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: gtkmm: Pixbuf::get_pixels()

Murray Cumming-5
On Thu, 2017-03-16 at 14:34 +0100, Kjell Ahlstedt wrote:

> The const usage is wrong in both get_pixels() methods. Should be
>   _WRAP_METHOD(guint8* get_pixels(), gdk_pixbuf_get_pixels)
>   _WRAP_METHOD(guint8* get_pixels(guint& length),
> gdk_pixbuf_get_pixels_with_length)
> and perhaps
>   _WRAP_METHOD(const guint8* get_pixels() const,
> gdk_pixbuf_get_pixels, constversion)
>   _WRAP_METHOD(const guint8* get_pixels(guint& length) const,
> gdk_pixbuf_get_pixels_with_length, constversion)
>
> The documentation of gdk_pixbuf_get_pixels[_with_length]() says
> "This function will cause an implicit copy of the pixbuf data if the
> pixbuf was created from read-only data."
> I take this to mean that it's alright for the caller to change the
> pixel data. (The implicit copy is owned by the GdkPixbuf object. The
> caller shall not delete it.) There is also the
> gdk_pixbuf_read_pixels() function (not yet wrapped in Gdk::Pixbuf)
> which returns a const guint8*. It's perhaps a better choice when you
> don't want to change the pixels, because it does not make a copy of
> read-only data.

Thanks. I didn't know about that. I've changed it as you suggest:
https://git.gnome.org/browse/gtkmm/commit/?id=422c202a31740d2d52c045e97
975b4b7a9f15be4

--
Murray Cumming
[hidden email]
www.murrayc.com

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: gtkmm: Pixbuf::get_pixels()

Daniel Boles
The copy is done as follows, to support copy-on-write:

 * This function will cause an implicit copy of the pixbuf data if the
 * pixbuf was created from read-only data.

https://git.gnome.org/browse/gdk-pixbuf/tree/gdk-pixbuf/gdk-pixbuf.c#n674

I thought as long as the apparent functioning of the object is still the same to external users, then it is allowed to make internal changes even on a const instance? Using mutable members.

If so, then maybe it would still be OK to wrap that as a const method.

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: gtkmm: Pixbuf::get_pixels()

Murray Cumming-5
On Fri, 2017-03-17 at 07:55 +0000, Daniel Boles wrote:

> The copy is done as follows, to support copy-on-write:
>
>  * This function will cause an implicit copy of the pixbuf data if
> the
>  * pixbuf was created from read-only data.
>
> https://git.gnome.org/browse/gdk-pixbuf/tree/gdk-pixbuf/gdk-pixbuf.c#
> n674
>
> I thought as long as the apparent functioning of the object is still
> the same to external users, then it is allowed to make internal
> changes even on a const instance? Using mutable members.
>
> If so, then maybe it would still be OK to wrap that as a const
> method.

We are wrapping that as a const method. But we don't need to make
anything mutable. We just const_cast the GdkPixbuf*. C doesn't do full
C++-like const, so this is often necessary.

If I have misunderstood, maybe you could suggest a particular patch.
Thanks.

--
Murray Cumming
[hidden email]
www.murrayc.com

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Loading...