1.40 <GdkTexture>

Class: <GdkTexture>

It derives from <GObject>.

Refers to pixel data in various forms.

It is primarily meant for pixel data that will not change over multiple frames, and will be used for a long time.

There are various ways to create <GdkTexture> objects from a <GdkPixbuf>, or from bytes stored in memory, a file, or a <GResource>.

The ownership of the pixel data is transferred to the <GdkTexture> instance; you can only make a copy of it, via texture:download.

<GdkTexture> is an immutable object: That means you cannot change anything about it other than increasing the reference count via object:ref, and consequently, it is a threadsafe object.

GDK provides a number of threadsafe texture loading functions: texture:new-from-resource, texture:new-from-bytes, texture:new-from-file, texture:new-from-filename, texture:new-for-pixbuf. Note that these are meant for loading icons and resources that are shipped with the toolkit or application. It is recommended that you use a dedicated image loading framework such as glycin, if you need to load untrusted image data.

Properties

Property: texture:color-state self

The color state of the texture.

Its value is a <GdkColorState>, or #f.

It can only be set when the object is made, with #:color-state.

Property: texture:height self

The height of the texture, in pixels.

Its value is a 32-bit integer.

It can only be set when the object is made, with #:height.

Property: texture:width self

The width of the texture, in pixels.

Its value is a 32-bit integer.

It can only be set when the object is made, with #:width.

Procedures

Method: texture:download self data stride
Method: download self data stride

Downloads the self into local memory.

This may be an expensive operation, as the actual texture data may reside on a GPU or on a remote display server.

The data format of the downloaded data is equivalent to argb32, so every downloaded pixel requires 4 bytes of memory.

Downloading a texture into a Cairo image surface:

surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                      gdk_texture_get_width (texture),
                                      gdk_texture_get_height (texture));
gdk_texture_download (texture,
                      cairo_image_surface_get_data (surface),
                      cairo_image_surface_get_stride (surface));
cairo_surface_mark_dirty (surface);

For more flexible download capabilities, see <GdkTextureDownloader>.

self

Passed: a <GdkTexture>.

a <GdkTexture>

data

Passed: a foreign pointer, or a bytevector.

pointer to enough memory to be filled with the downloaded data of self

stride

Passed: an unsigned 64-bit integer.

rowstride in bytes

Method: texture:get-color-state self ⇒ %return
Method: get-color-state self ⇒ %return

Returns the color state associated with the texture.

self

Passed: a <GdkTexture>.

a <GdkTexture>

%return

Returned: a <GdkColorState>.

the color state of the <GdkTexture>

Method: texture:get-format self ⇒ %return
Method: get-format self ⇒ %return

Gets the memory format most closely associated with the data of the texture.

Note that it may not be an exact match for texture data stored on the GPU or with compression.

The format can give an indication about the bit depth and opacity of the texture and is useful to determine the best format for downloading the texture.

self

Passed: a <GdkTexture>.

a GdkTexture

%return

Returned: a <GdkMemoryFormat>.

the preferred format for the texture’s data

Method: texture:get-height self ⇒ %return
Method: get-height self ⇒ %return

Returns the height of the self, in pixels.

self

Passed: a <GdkTexture>.

a <GdkTexture>

%return

Returned: a 32-bit integer.

the height of the <GdkTexture>

Method: texture:get-width self ⇒ %return
Method: get-width self ⇒ %return

Returns the width of self, in pixels.

self

Passed: a <GdkTexture>.

a <GdkTexture>

%return

Returned: a 32-bit integer.

the width of the <GdkTexture>

Procedure: texture:new-for-pixbuf pixbuf ⇒ %return

Creates a new texture object representing the <GdkPixbuf>.

This function is threadsafe, so that you can e.g. use GTask and task:run-in-thread to avoid blocking the main thread while loading a big image.

pixbuf

Passed: a <GdkPixbuf>.

a <GdkPixbuf>

%return

Returned: a <GdkTexture>.

a new <GdkTexture>

Procedure: texture:new-from-bytes bytes ⇒ %return

Creates a new texture by loading an image from memory,

The file format is detected automatically. The supported formats are PNG, JPEG and TIFF, though more formats might be available.

If NULL is returned, then error will be set.

This function is threadsafe, so that you can e.g. use GTask and task:run-in-thread to avoid blocking the main thread while loading a big image.

::: warning Note that this function should not be used with untrusted data. Use a proper image loading framework such as libglycin, which can load many image formats into a <GdkTexture>.

bytes

Passed: a <GBytes>.

a <GBytes> containing the data to load

%return

Returned: a <GdkTexture>.

A newly-created <GdkTexture>

Procedure: texture:new-from-file file ⇒ %return

Creates a new texture by loading an image from a file.

The file format is detected automatically. The supported formats are PNG, JPEG and TIFF, though more formats might be available.

If NULL is returned, then error will be set.

This function is threadsafe, so that you can e.g. use GTask and task:run-in-thread to avoid blocking the main thread while loading a big image.

::: warning Note that this function should not be used with untrusted data. Use a proper image loading framework such as libglycin, which can load many image formats into a <GdkTexture>.

file

Passed: a <GFile>.

<GFile> to load

%return

Returned: a <GdkTexture>.

A newly-created <GdkTexture>

Procedure: texture:new-from-filename path ⇒ %return

Creates a new texture by loading an image from a file.

The file format is detected automatically. The supported formats are PNG, JPEG and TIFF, though more formats might be available.

If NULL is returned, then error will be set.

This function is threadsafe, so that you can e.g. use GTask and task:run-in-thread to avoid blocking the main thread while loading a big image.

::: warning Note that this function should not be used with untrusted data. Use a proper image loading framework such as libglycin, which can load many image formats into a <GdkTexture>.

path

Passed: a file name, as a string.

the filename to load

%return

Returned: a <GdkTexture>.

A newly-created <GdkTexture>

Procedure: texture:new-from-resource resource-path ⇒ %return

Creates a new texture by loading an image from a resource.

The file format is detected automatically. The supported formats are PNG, JPEG and TIFF, though more formats might be available.

It is a fatal error if resource-path does not specify a valid image resource and the program will abort if that happens. If you are unsure about the validity of a resource, use texture:new-from-file to load it.

This function is threadsafe, so that you can e.g. use GTask and task:run-in-thread to avoid blocking the main thread while loading a big image.

resource-path

Passed: a string.

the path of the resource file

%return

Returned: a <GdkTexture>.

A newly-created <GdkTexture>

Method: texture:save-to-png-bytes self ⇒ %return
Method: save-to-png-bytes self ⇒ %return

Store the given self in memory as a PNG file.

Use texture:new-from-bytes to read it back.

If you want to serialize a texture, this is a convenient and portable way to do that.

If you need more control over the generated image, such as attaching metadata, you should look into an image handling library such as the libglycin library.

If you are dealing with high dynamic range float data, you might also want to consider texture:save-to-tiff-bytes instead.

self

Passed: a <GdkTexture>.

a <GdkTexture>

%return

Returned: a <GBytes>.

a newly allocated <GBytes> containing PNG data

Method: texture:save-to-png? self filename ⇒ %return
Method: save-to-png? self filename ⇒ %return

Store the given self to the filename as a PNG file.

This is a utility function intended for debugging and testing. If you want more control over formats, proper error handling or want to store to a <GFile> or other location, you might want to use texture:save-to-png-bytes or look into the libglycin library.

self

Passed: a <GdkTexture>.

a <GdkTexture>

filename

Passed: a file name, as a string.

the filename to store to

%return

Returned: a boolean.

#t if saving succeeded, #f on failure.

Method: texture:save-to-tiff-bytes self ⇒ %return
Method: save-to-tiff-bytes self ⇒ %return

Store the given self in memory as a TIFF file.

Use texture:new-from-bytes to read it back.

This function is intended to store a representation of the texture’s data that is as accurate as possible. This is particularly relevant when working with high dynamic range images and floating-point texture data.

If that is not your concern and you are interested in a smaller size and a more portable format, you might want to use texture:save-to-png-bytes.

self

Passed: a <GdkTexture>.

a <GdkTexture>

%return

Returned: a <GBytes>.

a newly allocated <GBytes> containing TIFF data

Method: texture:save-to-tiff? self filename ⇒ %return
Method: save-to-tiff? self filename ⇒ %return

Store the given self to the filename as a TIFF file.

GTK will attempt to store data without loss.

self

Passed: a <GdkTexture>.

a <GdkTexture>

filename

Passed: a file name, as a string.

the filename to store to

%return

Returned: a boolean.

#t if saving succeeded, #f on failure.