* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
-#include <gdk-pixbuf/gdk-pixbuf.h>
+
+#include "gdkpixbuf.h"
#include "gdkcolor.h"
#include "gdkwindow.h"
-#include "gdkpixbuf.h"
#include "gdkinternals.h"
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+/**
+ * SECTION:pixbufs
+ * @Short_description: Functions for obtaining pixbufs
+ * @Title: Pixbufs
+ *
+ * Pixbufs are client-side images. For details on how to create
+ * and manipulate pixbufs, see the #GdkPixbuf API documentation.
+ *
+ * The functions described here allow to obtain pixbufs from
+ * #GdkWindows and cairo surfaces.
+ */
-/* Exported functions */
/**
* gdk_pixbuf_get_from_window:
* representation inside a #GdkPixbuf. In other words, copies
* image data from a server-side drawable to a client-side RGB(A) buffer.
* This allows you to efficiently read individual pixels on the client side.
- *
+ *
* This function will create an RGB pixbuf with 8 bits per channel with
* the same size specified by the @width and @height arguments. The pixbuf
* will contain an alpha channel if the @window contains one.
* it returns %NULL; so check the return value.)
*
* Return value: (transfer full): A newly-created pixbuf with a reference
- * count of 1, or %NULL on error
- **/
+ * count of 1, or %NULL on error
+ */
GdkPixbuf *
-gdk_pixbuf_get_from_window (GdkWindow *src,
- int src_x, int src_y,
- int width, int height)
+gdk_pixbuf_get_from_window (GdkWindow *src,
+ gint src_x,
+ gint src_y,
+ gint width,
+ gint height)
{
cairo_surface_t *surface;
GdkPixbuf *dest;
-
+
g_return_val_if_fail (GDK_IS_WINDOW (src), NULL);
g_return_val_if_fail (gdk_window_is_viewable (src), NULL);
- surface = _gdk_drawable_ref_cairo_surface (src);
+ surface = _gdk_window_ref_cairo_surface (src);
dest = gdk_pixbuf_get_from_surface (surface,
src_x, src_y,
width, height);
return dest;
}
-
+
static cairo_format_t
gdk_cairo_format_for_content (cairo_content_t content)
{
static cairo_surface_t *
gdk_cairo_surface_coerce_to_image (cairo_surface_t *surface,
- cairo_content_t content,
- int width,
- int height)
+ cairo_content_t content,
+ int src_x,
+ int src_y,
+ int width,
+ int height)
{
cairo_surface_t *copy;
cairo_t *cr;
- if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE &&
- cairo_surface_get_content (surface) == content &&
- cairo_image_surface_get_width (surface) >= width &&
- cairo_image_surface_get_height (surface) >= height)
- return cairo_surface_reference (surface);
-
copy = cairo_image_surface_create (gdk_cairo_format_for_content (content),
width,
height);
cr = cairo_create (copy);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
- cairo_set_source_surface (cr, surface, 0, 0);
+ cairo_set_source_surface (cr, surface, -src_x, -src_y);
cairo_paint (cr);
cairo_destroy (cr);
}
static void
-convert_alpha (guchar *dest_data,
- int dest_stride,
- guchar *src_data,
- int src_stride,
- int src_x,
- int src_y,
- int width,
- int height)
+convert_alpha (guchar *dest_data,
+ int dest_stride,
+ guchar *src_data,
+ int src_stride,
+ int src_x,
+ int src_y,
+ int width,
+ int height)
{
int x, y;
}
static void
-convert_no_alpha (guchar *dest_data,
- int dest_stride,
- guchar *src_data,
- int src_stride,
- int src_x,
- int src_y,
- int width,
- int height)
+convert_no_alpha (guchar *dest_data,
+ int dest_stride,
+ guchar *src_data,
+ int src_stride,
+ int src_x,
+ int src_y,
+ int width,
+ int height)
{
int x, y;
* individual pixels from cairo surfaces. For #GdkWindows, use
* gdk_pixbuf_get_from_window() instead.
*
- * This function will create an RGB pixbuf with 8 bits per channel. The pixbuf
- * will contain an alpha channel if the @surface contains one.
+ * This function will create an RGB pixbuf with 8 bits per channel.
+ * The pixbuf will contain an alpha channel if the @surface contains one.
*
- * Return value: (transfer full): A newly-created pixbuf with a reference count
- * of 1, or %NULL on error
- **/
+ * Return value: (transfer full): A newly-created pixbuf with a reference
+ * count of 1, or %NULL on error
+ */
GdkPixbuf *
gdk_pixbuf_get_from_surface (cairo_surface_t *surface,
- int src_x,
- int src_y,
- int width,
- int height)
+ gint src_x,
+ gint src_y,
+ gint width,
+ gint height)
{
cairo_content_t content;
GdkPixbuf *dest;
-
+
/* General sanity checks */
g_return_val_if_fail (surface != NULL, NULL);
- g_return_val_if_fail (src_x >= 0 && src_y >= 0, NULL);
g_return_val_if_fail (width > 0 && height > 0, NULL);
content = cairo_surface_get_content (surface) | CAIRO_CONTENT_COLOR;
8,
width, height);
- surface = gdk_cairo_surface_coerce_to_image (surface, content, src_x + width, src_y + height);
+ surface = gdk_cairo_surface_coerce_to_image (surface, content,
+ src_x, src_y,
+ width, height);
cairo_surface_flush (surface);
if (cairo_surface_status (surface) || dest == NULL)
{
gdk_pixbuf_get_rowstride (dest),
cairo_image_surface_get_data (surface),
cairo_image_surface_get_stride (surface),
- src_x, src_y,
+ 0, 0,
width, height);
else
convert_no_alpha (gdk_pixbuf_get_pixels (dest),
gdk_pixbuf_get_rowstride (dest),
cairo_image_surface_get_data (surface),
cairo_image_surface_get_stride (surface),
- src_x, src_y,
+ 0, 0,
width, height);
cairo_surface_destroy (surface);
return dest;
}
-