forked from AuroraMiddleware/gtk
gdk: Rework gdk_pixbuf_get_from_texture()
Make it use gdk_memory_texture_from_texture(). Also make gdk_memory_format_alpha() privately available so that we can detect if an image contains an alpha channel.
This commit is contained in:
parent
7eceed8d4d
commit
dcba783389
@ -641,11 +641,7 @@ pixbuf_serializer (GdkContentSerializer *serializer)
|
||||
else if (G_VALUE_HOLDS (value, GDK_TYPE_TEXTURE))
|
||||
{
|
||||
GdkTexture *texture = g_value_get_object (value);
|
||||
cairo_surface_t *surface = gdk_texture_download_surface (texture);
|
||||
pixbuf = gdk_pixbuf_get_from_surface (surface,
|
||||
0, 0,
|
||||
gdk_texture_get_width (texture), gdk_texture_get_height (texture));
|
||||
cairo_surface_destroy (surface);
|
||||
pixbuf = gdk_pixbuf_get_from_texture (texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -27,12 +27,6 @@
|
||||
|
||||
typedef struct _GdkMemoryFormatDescription GdkMemoryFormatDescription;
|
||||
|
||||
typedef enum {
|
||||
GDK_MEMORY_ALPHA_PREMULTIPLIED,
|
||||
GDK_MEMORY_ALPHA_STRAIGHT,
|
||||
GDK_MEMORY_ALPHA_OPAQUE
|
||||
} GdkMemoryAlpha;
|
||||
|
||||
#define TYPED_FUNCS(name, T, R, G, B, A, bpp, scale) \
|
||||
static void \
|
||||
name ## _to_float (float *dest, \
|
||||
@ -386,6 +380,12 @@ gdk_memory_format_bytes_per_pixel (GdkMemoryFormat format)
|
||||
return memory_formats[format].bytes_per_pixel;
|
||||
}
|
||||
|
||||
GdkMemoryAlpha
|
||||
gdk_memory_format_alpha (GdkMemoryFormat format)
|
||||
{
|
||||
return memory_formats[format].alpha;
|
||||
}
|
||||
|
||||
gsize
|
||||
gdk_memory_format_alignment (GdkMemoryFormat format)
|
||||
{
|
||||
|
@ -24,7 +24,14 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum {
|
||||
GDK_MEMORY_ALPHA_PREMULTIPLIED,
|
||||
GDK_MEMORY_ALPHA_STRAIGHT,
|
||||
GDK_MEMORY_ALPHA_OPAQUE
|
||||
} GdkMemoryAlpha;
|
||||
|
||||
gsize gdk_memory_format_alignment (GdkMemoryFormat format) G_GNUC_CONST;
|
||||
GdkMemoryAlpha gdk_memory_format_alpha (GdkMemoryFormat format) G_GNUC_CONST;
|
||||
gsize gdk_memory_format_bytes_per_pixel (GdkMemoryFormat format) G_GNUC_CONST;
|
||||
gboolean gdk_memory_format_prefers_high_depth(GdkMemoryFormat format) G_GNUC_CONST;
|
||||
gboolean gdk_memory_format_gl_format (GdkMemoryFormat format,
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
#include "gdkpixbuf.h"
|
||||
|
||||
#include "gdkmemoryformatprivate.h"
|
||||
#include "gdkmemorytextureprivate.h"
|
||||
#include "gdksurface.h"
|
||||
#include "gdktextureprivate.h"
|
||||
|
||||
@ -214,6 +216,13 @@ gdk_pixbuf_get_from_surface (cairo_surface_t *surface,
|
||||
return dest;
|
||||
}
|
||||
|
||||
static void
|
||||
pixbuf_texture_unref_cb (guchar *pixels,
|
||||
gpointer texture)
|
||||
{
|
||||
g_object_unref (texture);
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_pixbuf_get_from_texture:
|
||||
* @texture: a `GdkTexture`
|
||||
@ -229,17 +238,22 @@ gdk_pixbuf_get_from_surface (cairo_surface_t *surface,
|
||||
GdkPixbuf *
|
||||
gdk_pixbuf_get_from_texture (GdkTexture *texture)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
cairo_surface_t *surface;
|
||||
int width, height;
|
||||
GdkMemoryTexture *memtex;
|
||||
gboolean alpha;
|
||||
|
||||
g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL);
|
||||
alpha = gdk_memory_format_alpha (gdk_texture_get_format (texture)) != GDK_MEMORY_ALPHA_OPAQUE;
|
||||
|
||||
width = gdk_texture_get_width (texture);
|
||||
height = gdk_texture_get_height (texture);
|
||||
surface = gdk_texture_download_surface (texture);
|
||||
pixbuf = gdk_pixbuf_get_from_surface (surface, 0, 0, width, height);
|
||||
cairo_surface_destroy (surface);
|
||||
memtex = gdk_memory_texture_from_texture (texture,
|
||||
alpha ? GDK_MEMORY_GDK_PIXBUF_ALPHA
|
||||
: GDK_MEMORY_GDK_PIXBUF_OPAQUE);
|
||||
|
||||
return pixbuf;
|
||||
return gdk_pixbuf_new_from_data (gdk_memory_texture_get_data (memtex),
|
||||
GDK_COLORSPACE_RGB,
|
||||
alpha,
|
||||
8,
|
||||
gdk_texture_get_width (GDK_TEXTURE (memtex)),
|
||||
gdk_texture_get_height (GDK_TEXTURE (memtex)),
|
||||
gdk_memory_texture_get_stride (memtex),
|
||||
pixbuf_texture_unref_cb,
|
||||
memtex);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user