/** * gdk_pixbuf_copy: * @pixbuf: A pixbuf. * * Creates a new #GdkPixbuf with a copy of the information in the specified * @pixbuf. Note that this does not copy the options set on the original #GdkPixbuf, * use gdk_pixbuf_copy_options() for this. * * Return value: (nullable) (transfer full): A newly-created pixbuf with a reference count of 1, or %NULL if * not enough memory could be allocated. **/ GdkPixbuf * gdk_pixbuf_copy (const GdkPixbuf *pixbuf) { guchar *buf; int size; g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL); /* Calculate a semi-exact size. Here we copy with full rowstrides; * maybe we should copy each row individually with the minimum * rowstride? */ size = gdk_pixbuf_get_byte_length (pixbuf); buf = g_try_malloc (size); if (!buf) return NULL; memcpy (buf, gdk_pixbuf_read_pixels (pixbuf), size); return gdk_pixbuf_new_from_data (buf, pixbuf->colorspace, pixbuf->has_alpha, pixbuf->bits_per_sample, pixbuf->width, pixbuf->height, pixbuf->rowstride, free_buffer, NULL); }
/** * gdk_pixbuf_read_pixel_bytes: * @pixbuf: A pixbuf * * Returns: (transfer full): A new reference to a read-only copy of * the pixel data. Note that for mutable pixbufs, this function will * incur a one-time copy of the pixel data for conversion into the * returned #GBytes. * * Since: 2.32 */ GBytes * gdk_pixbuf_read_pixel_bytes (const GdkPixbuf *pixbuf) { g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL); if (pixbuf->bytes) { return g_bytes_ref (pixbuf->bytes); } else { return g_bytes_new (pixbuf->pixels, gdk_pixbuf_get_byte_length (pixbuf)); } }
/** * gdk_pixbuf_get_pixels_with_length: (rename-to gdk_pixbuf_get_pixels) * @pixbuf: A pixbuf. * @length: (out): The length of the binary data. * * Queries a pointer to the pixel data of a pixbuf. * * Return value: (array length=length): A pointer to the pixbuf's * pixel data. Please see the section on [image data][image-data] * for information about how the pixel data is stored in memory. * * This function will cause an implicit copy of the pixbuf data if the * pixbuf was created from read-only data. * * Since: 2.26 */ guchar * gdk_pixbuf_get_pixels_with_length (const GdkPixbuf *pixbuf, guint *length) { g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL); downgrade_to_pixels (pixbuf); g_assert (pixbuf->storage == STORAGE_PIXELS); if (length) *length = gdk_pixbuf_get_byte_length (pixbuf); return pixbuf->s.pixels.pixels; }
/** * gdk_pixbuf_read_pixel_bytes: * @pixbuf: A pixbuf * * Provides a #GBytes buffer containing the raw pixel data; the data * must not be modified. This function allows skipping the implicit * copy that must be made if gdk_pixbuf_get_pixels() is called on a * read-only pixbuf. * * Returns: (transfer full): A new reference to a read-only copy of * the pixel data. Note that for mutable pixbufs, this function will * incur a one-time copy of the pixel data for conversion into the * returned #GBytes. * * Since: 2.32 */ GBytes * gdk_pixbuf_read_pixel_bytes (const GdkPixbuf *pixbuf) { g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL); switch (pixbuf->storage) { case STORAGE_PIXELS: return g_bytes_new (pixbuf->s.pixels.pixels, gdk_pixbuf_get_byte_length (pixbuf)); case STORAGE_BYTES: return g_bytes_ref (pixbuf->s.bytes.bytes); default: g_assert_not_reached (); } }
/** * gdk_pixbuf_get_pixels_with_length: (rename-to gdk_pixbuf_get_pixels) * @pixbuf: A pixbuf. * @length: (out): The length of the binary data. * * Queries a pointer to the pixel data of a pixbuf. * * Return value: (array length=length): A pointer to the pixbuf's * pixel data. Please see the section on [image data](image-data) * for information about how the pixel data is stored in memory. * * This function will cause an implicit copy of the pixbuf data if the * pixbuf was created from read-only data. * * Since: 2.26 */ guchar * gdk_pixbuf_get_pixels_with_length (const GdkPixbuf *pixbuf, guint *length) { g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL); if (pixbuf->bytes) { GdkPixbuf *mut_pixbuf = (GdkPixbuf*)pixbuf; gsize len; mut_pixbuf->pixels = g_bytes_unref_to_data (pixbuf->bytes, &len); mut_pixbuf->bytes = NULL; } if (length) *length = gdk_pixbuf_get_byte_length (pixbuf); return pixbuf->pixels; }
static void g_paste_image_item_set_size (GPasteItem *self) { GPasteImageItemPrivate *priv = g_paste_image_item_get_instance_private (G_PASTE_IMAGE_ITEM (self)); GdkPixbuf *image = priv->image; if (image) { if (!priv->additional_size) { priv->additional_size += strlen (priv->checksum) + 1 + gdk_pixbuf_get_byte_length (image); g_paste_item_add_size (self, priv->additional_size); } } else { g_paste_item_remove_size (self, priv->additional_size); priv->additional_size = 0; } }
static gboolean pixdata_equal (GdkPixbuf *p1, GdkPixbuf *p2) { if (gdk_pixbuf_get_colorspace (p1) != gdk_pixbuf_get_colorspace (p2)) return FALSE; if (gdk_pixbuf_get_n_channels (p1) != gdk_pixbuf_get_n_channels (p2)) return FALSE; if (gdk_pixbuf_get_bits_per_sample (p1) != gdk_pixbuf_get_bits_per_sample (p2)) return FALSE; if (gdk_pixbuf_get_width (p1) != gdk_pixbuf_get_width (p2)) return FALSE; if (gdk_pixbuf_get_height (p1) != gdk_pixbuf_get_height (p2)) return FALSE; if (gdk_pixbuf_get_rowstride (p1) != gdk_pixbuf_get_rowstride (p2)) return FALSE; if (memcmp (gdk_pixbuf_get_pixels (p1), gdk_pixbuf_get_pixels (p2), gdk_pixbuf_get_byte_length (p1)) != 0) return FALSE; return TRUE; }