[gtkmm] Gdk::Pixbuf: Throw exception from ctor, add get_pixels(guint& length)



commit b136c8948f026b396622cbfb46c5cf69b08bbca4
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Fri Mar 3 16:56:46 2017 +0100

    Gdk::Pixbuf: Throw exception from ctor, add get_pixels(guint& length)
    
    Throw an exception from a constructor instead of creating an invalid object.
    In the documentation, remove references to the removed constructor that took
    a Gdk::Window. Add get_pixels(guint& length).

 gdk/src/pixbuf.ccg |    6 ++++--
 gdk/src/pixbuf.hg  |   24 ++++++++++++------------
 2 files changed, 16 insertions(+), 14 deletions(-)
---
diff --git a/gdk/src/pixbuf.ccg b/gdk/src/pixbuf.ccg
index 65960d5..64dd6b7 100644
--- a/gdk/src/pixbuf.ccg
+++ b/gdk/src/pixbuf.ccg
@@ -18,7 +18,6 @@
 
 #include <glibmm/vectorutils.h>
 
-#include <gdkmm/window.h>
 #include <gdk/gdk.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
@@ -53,7 +52,10 @@ Pixbuf::Pixbuf(const ::Cairo::RefPtr< ::Cairo::Surface>& src,
 :
   Object((GObject*) gdk_pixbuf_get_from_surface(
     src->cobj(), src_x, src_y, width, height))
-{}
+{
+  if (!gobj())
+    throw PixbufError(PixbufError::FAILED, "Could not construct Pixbuf from Cairo::Surface");
+}
 
 Glib::RefPtr<Pixbuf> Pixbuf::create_from_data(const guint8* data, Colorspace colorspace,
                                               bool has_alpha, int bits_per_sample,
diff --git a/gdk/src/pixbuf.hg b/gdk/src/pixbuf.hg
index 4a6c8ff..5b2a04a 100644
--- a/gdk/src/pixbuf.hg
+++ b/gdk/src/pixbuf.hg
@@ -21,7 +21,6 @@ _CONFIGINCLUDE(gdkmmconfig.h)
 
 #include <vector>
 
-//#include <gdkmm/window.h>
 #include <gdkmm/pixbufformat.h>
 #include <gdkmm/types.h>
 #include <giomm/inputstream.h>
@@ -40,8 +39,6 @@ _PINCLUDE(glibmm/private/object_p.h)
 namespace Gdk
 {
 
-class Window;
-
 _CC_INCLUDE(gdk-pixbuf/gdk-pixbuf.h)
 _WRAP_ENUM(Colorspace, GdkColorspace)
 _WRAP_ENUM(InterpType, GdkInterpType)
@@ -62,13 +59,12 @@ class Pixbuf
 
 protected:
 
-  //TODO: Throw an exception when the C function returns NULL?
   /** Transfers image data from a Cairo::Surface and converts it to an RGB(A)
    * representation inside a Gdk::Pixbuf. This allows you to efficiently read
-   * individual pixels from cairo surfaces. For Gdk::Windows, use the
-   * constructor that takes a Gdk::Window instead.
+   * individual pixels from cairo surfaces.
    *
-   * This will create an RGB pixbuf with 8 bits per channel. The pixbuf will contain an alpha channel if the 
surface contains one.
+   * This will create an RGB pixbuf with 8 bits per channel.
+   * The pixbuf will contain an alpha channel if the surface contains one.
    *
    * @param src Surface to copy from.
    * @param src_x Source X coordinate within the surface.
@@ -76,6 +72,8 @@ protected:
    * @param width Width in pixels of region to get.
    * @param height Height in pixels of region to get.
    *
+   * @throw Gdk::PixbufError
+   *
    * @newin{2,30}
    */
   Pixbuf(const ::Cairo::RefPtr< ::Cairo::Surface>& src,
@@ -84,14 +82,14 @@ protected:
 
 
 public:
-  typedef sigc::slot<void(const guint8*)> SlotDestroyData;
+  using SlotDestroyData = sigc::slot<void(const guint8*)>;
 
   /** Transfers image data from a Cairo::Surface and converts it to an RGB(A)
    * representation inside a Gdk::Pixbuf. This allows you to efficiently read
-   * individual pixels from cairo surfaces. For Gdk::Windows, use the
-   * create() method that takes a Gdk::Window instead.
+   * individual pixels from cairo surfaces.
    *
-   * This will create an RGB pixbuf with 8 bits per channel. The pixbuf will contain an alpha channel if the 
surface contains one.
+   * This will create an RGB pixbuf with 8 bits per channel.
+   * The pixbuf will contain an alpha channel if the surface contains one.
    *
    * @param src Surface to copy from.
    * @param src_x Source X coordinate within the surface.
@@ -99,6 +97,8 @@ public:
    * @param width Width in pixels of region to get.
    * @param height Height in pixels of region to get.
    *
+   * @throw Gdk::PixbufError
+   *
    * @newin{2,30}
    */
   _WRAP_CREATE(const ::Cairo::RefPtr< ::Cairo::Surface>& src,
@@ -219,7 +219,7 @@ public:
   _WRAP_METHOD(bool get_has_alpha() const, gdk_pixbuf_get_has_alpha)
   _WRAP_METHOD(int get_bits_per_sample() const, gdk_pixbuf_get_bits_per_sample)
   _WRAP_METHOD(guint8* get_pixels() const, gdk_pixbuf_get_pixels)
-  //TODO: _WRAP_METHOD(guint8* get_pixels(guint& length) const, gdk_pixbuf_get_pixels_with_length)
+  _WRAP_METHOD(guint8* get_pixels(guint& length) const, gdk_pixbuf_get_pixels_with_length)
   _WRAP_METHOD(int get_width() const, gdk_pixbuf_get_width)
   _WRAP_METHOD(int get_height() const, gdk_pixbuf_get_height)
   _WRAP_METHOD(int get_rowstride() const, gdk_pixbuf_get_rowstride)


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