Class: GdkPixbuf::Pixbuf
- Inherits:
-
Object
- Object
- GdkPixbuf::Pixbuf
- Extended by:
- GLib::Deprecatable
- Defined in:
- lib/gdk_pixbuf2/pixbuf.rb,
lib/gdk_pixbuf2/deprecated.rb
Overview
A pixel buffer.
GdkPixbuf contains information about an image's pixel data,
its color space, bits per sample, width and height, and the
rowstride (the number of bytes between the start of one row
and the start of the next).
Creating new GdkPixbuf
The most basic way to create a pixbuf is to wrap an existing pixel
buffer with a [classGdkPixbuf.Pixbuf] instance. You can use the
[ctor<b>GdkPixbuf</b>.Pixbuf.new_from_data] function to do this.
Every time you create a new GdkPixbuf instance for some data, you
will need to specify the destroy notification function that will be
called when the data buffer needs to be freed; this will happen when
a GdkPixbuf is finalized by the reference counting functions. If
you have a chunk of static data compiled into your application, you
can pass in NULL as the destroy notification function so that the
data will not be freed.
The [ctor<b>GdkPixbuf</b>.Pixbuf.new] constructor function can be used
as a convenience to create a pixbuf with an empty buffer; this is
equivalent to allocating a data buffer using malloc() and then
wrapping it with gdk_pixbuf_new_from_data(). The gdk_pixbuf_new()
function will compute an optimal rowstride so that rendering can be
performed with an efficient algorithm.
As a special case, you can use the [ctor<b>GdkPixbuf</b>.Pixbuf.new_from_xpm_data]
function to create a pixbuf from inline XPM image data.
You can also copy an existing pixbuf with the [methodPixbuf.copy] function. This is not the same as just acquiring a reference to the old pixbuf instance: the copy function will actually duplicate the pixel data in memory and create a new [classPixbuf] instance for it.
Reference counting
GdkPixbuf structures are reference counted. This means that an
application can share a single pixbuf among many parts of the
code. When a piece of the program needs to use a pixbuf, it should
acquire a reference to it by calling g_object_ref(); when it no
longer needs the pixbuf, it should release the reference it acquired
by calling g_object_unref(). The resources associated with a
GdkPixbuf will be freed when its reference count drops to zero.
Newly-created GdkPixbuf instances start with a reference count
of one.
Image Data
Image data in a pixbuf is stored in memory in an uncompressed, packed format. Rows in the image are stored top to bottom, and in each row pixels are stored from left to right.
There may be padding at the end of a row.
The "rowstride" value of a pixbuf, as returned by [method<b>GdkPixbuf</b>.Pixbuf.get_rowstride],
indicates the number of bytes between rows.
NOTE: If you are copying raw pixbuf data with memcpy() note that the
last row in the pixbuf may not be as wide as the full rowstride, but rather
just as wide as the pixel data needs to be; that is: it is unsafe to do
memcpy (dest, pixels, rowstride * height) to copy a whole pixbuf. Use
[methodGdkPixbuf.Pixbuf.copy] instead, or compute the width in bytes of the
last row as:
last_row = width * ((n_channels * bits_per_sample + 7) / 8);
The same rule applies when iterating over each row of a GdkPixbuf pixels
array.
The following code illustrates a simple put_pixel()
function for RGB pixbufs with 8 bits per channel with an alpha
channel.
static void
put_pixel (GdkPixbuf *pixbuf,
int x,
int y,
guchar red,
guchar green,
guchar blue,
guchar alpha)
{
int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
// Ensure that the pixbuf is valid
g_assert (gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB);
g_assert (gdk_pixbuf_get_bits_per_sample (pixbuf) == 8);
g_assert (gdk_pixbuf_get_has_alpha (pixbuf));
g_assert (n_channels == 4);
int width = gdk_pixbuf_get_width (pixbuf);
int height = gdk_pixbuf_get_height (pixbuf);
// Ensure that the coordinates are in a valid range
g_assert (x >= 0 && x < width);
g_assert (y >= 0 && y < height);
int rowstride = gdk_pixbuf_get_rowstride (pixbuf);
// The pixel buffer in the GdkPixbuf instance
guchar *pixels = gdk_pixbuf_get_pixels (pixbuf);
// The pixel we wish to modify
guchar *p = pixels + y * rowstride + x * n_channels;
p[0] = red;
p[1] = green;
p[2] = blue;
p[3] = alpha;
}
Loading images
The GdkPixBuf class provides a simple mechanism for loading
an image from a file in synchronous and asynchronous fashion.
For GUI applications, it is recommended to use the asynchronous stream API to avoid blocking the control flow of the application.
Additionally, GdkPixbuf provides the [classGdkPixbuf.PixbufLoader`]
API for progressive image loading.
Saving images
The GdkPixbuf class provides methods for saving image data in
a number of file formats. The formatted data can be written to a
file or to a memory buffer. GdkPixbuf can also call a user-defined
callback on the data, which allows to e.g. write the image
to a socket or store it in a database.
Class Method Summary collapse
-
.calculate_rowstride(colorspace, has_alpha, bits_per_sample, width, height) ⇒ Integer
Calculates the rowstride that an image created with those values would have.
-
.formats ⇒ GLib::SList<GdkPixbuf::PixbufFormat>
Obtains the available information about the image formats supported by GdkPixbuf.
-
.get_file_info(filename, width, height) ⇒ GdkPixbuf::PixbufFormat
Parses an image file far enough to determine its format and size.
-
.get_file_info_async(filename, cancellable, callback, user_data) ⇒ nil
Asynchronously parses an image file far enough to determine its format and size.
-
.get_file_info_finish(async_result, width, height) ⇒ GdkPixbuf::PixbufFormat
Finishes an asynchronous pixbuf parsing operation started with gdk_pixbuf_get_file_info_async().
-
.init_modules(path) ⇒ Boolean
Initalizes the gdk-pixbuf loader modules referenced by the
loaders.cachefile present inside that directory. - .new(*args, &block) ⇒ Object
-
.new_from_stream_async(stream, cancellable, callback, user_data) ⇒ nil
Creates a new pixbuf by asynchronously loading an image from an input stream.
-
.new_from_stream_at_scale_async(stream, width, height, preserve_aspect_ratio, cancellable, callback, user_data) ⇒ nil
Creates a new pixbuf by asynchronously loading an image from an input stream.
-
.save_to_stream_finish(async_result) ⇒ Boolean
Finishes an asynchronous pixbuf save operation started with gdk_pixbuf_save_to_stream_async().
Instance Method Summary collapse
-
#add_alpha(substitute_color, r, g, b) ⇒ GdkPixbuf::Pixbuf
Takes an existing pixbuf and adds an alpha channel to it.
-
#apply_embedded_orientation ⇒ GdkPixbuf::Pixbuf
Takes an existing pixbuf and checks for the presence of an associated "orientation" option.
-
#bits_per_sample ⇒ Integer
The number of bits per sample.
-
#bits_per_sample=(bits_per_sample) ⇒ Integer
The number of bits per sample.
-
#byte_length ⇒ Integer
Returns the length of the pixel data, in bytes.
-
#colorspace ⇒ GdkPixbuf::Colorspace
The color space of the pixbuf.
-
#colorspace=(colorspace) ⇒ GdkPixbuf::Colorspace
The color space of the pixbuf.
-
#composite(options) ⇒ nil
Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y.
- #composite!(source, options) ⇒ Object
-
#composite_color(dest, dest_x, dest_y, dest_width, dest_height, offset_x, offset_y, scale_x, scale_y, interp_type, overall_alpha, check_x, check_y, check_size, color1, color2) ⇒ nil
Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y, then alpha blends the rectangle (dest_x ,dest_y, dest_width, dest_height) of the resulting image with a checkboard of the colors color1 and color2 and renders it onto the destination image.
-
#composite_color_simple(dest_width, dest_height, interp_type, overall_alpha, check_size, color1, color2) ⇒ GdkPixbuf::Pixbuf
Creates a new pixbuf by scaling
srctodest_widthxdest_heightand alpha blending the result with a checkboard of colorscolor1andcolor2. -
#composite_raw ⇒ nil
Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y.
-
#copy ⇒ GdkPixbuf::Pixbuf
Creates a new
GdkPixbufwith a copy of the information in the specifiedpixbuf. -
#copy_area(src_x, src_y, width, height, dest_pixbuf, dest_x, dest_y) ⇒ nil
Copies a rectangular area from
src_pixbuftodest_pixbuf. -
#copy_options(dest_pixbuf) ⇒ Boolean
Copies the key/value pair options attached to a
GdkPixbufto anotherGdkPixbuf. - #dup ⇒ Object
-
#fill(pixel) ⇒ nil
Clears a pixbuf to the given RGBA value, converting the RGBA value into the pixbuf's pixel format.
- #fill!(pixel) ⇒ Object
-
#flip(horizontal) ⇒ GdkPixbuf::Pixbuf
Flips a pixbuf horizontally or vertically and returns the result in a new pixbuf.
-
#get_option(key) ⇒ String
Looks up key in the list of options that may have been attached to the pixbuf when it was loaded, or that may have been attached by another function using gdk_pixbuf_set_option().
-
#get_pixels_with_length(length) ⇒ Array<Integer>
Queries a pointer to the pixel data of a pixbuf.
-
#has_alpha ⇒ Boolean
Queries whether a pixbuf has an alpha channel (opacity information).
-
#has_alpha=(has_alpha) ⇒ Boolean
Whether the pixbuf has an alpha channel.
-
#has_alpha? ⇒ Boolean
Whether the pixbuf has an alpha channel.
-
#height ⇒ Integer
The number of rows of the pixbuf.
-
#height=(height) ⇒ Integer
The number of rows of the pixbuf.
-
#initialize(*args) ⇒ GdkPixbuf::Pixbuf
constructor
Creates a new pixbuf by parsing XPM data in memory.
-
#initialize_raw ⇒ GdkPixbuf::Pixbuf
Creates a new pixbuf by parsing XPM data in memory.
-
#n_channels ⇒ Integer
The number of samples per pixel.
-
#n_channels=(n_channels) ⇒ Integer
The number of samples per pixel.
-
#new_subpixbuf(src_x, src_y, width, height) ⇒ GdkPixbuf::Pixbuf
Creates a new pixbuf which represents a sub-region of
src_pixbuf. -
#options ⇒ GLib::HashTable<String>
Returns a
GHashTablewith a list of all the options that may have been attached to thepixbufwhen it was loaded, or that may have been attached by another function using [methodGdkPixbuf.Pixbuf.set_option]. -
#pixel_bytes ⇒ GLib::Bytes
Pixel-bytes.
- #pixel_bytes=(pixel_bytes) ⇒ GLib::Bytes
-
#pixels=(pixels) ⇒ GObject
A pointer to the pixel data of the pixbuf.
-
#read_pixel_bytes ⇒ GLib::Bytes
Provides a #GBytes buffer containing the raw pixel data; the data must not be modified.
-
#read_pixels ⇒ Integer
Provides a read-only pointer to the raw pixel data.
-
#ref ⇒ GdkPixbuf::Pixbuf
Adds a reference to a pixbuf.
-
#remove_option(key) ⇒ Boolean
Removes the key/value pair option attached to a
GdkPixbuf. - #rotate(angle) ⇒ Object
-
#rotate_simple(angle) ⇒ GdkPixbuf::Pixbuf
Rotates a pixbuf by a multiple of 90 degrees, and returns the result in a new pixbuf.
-
#rowstride ⇒ Integer
(also: #row_stride)
The number of bytes between the start of a row and the start of the next row.
-
#rowstride=(rowstride) ⇒ Integer
The number of bytes between the start of a row and the start of the next row.
-
#saturate_and_pixelate(saturation, pixelate) ⇒ nil
Modifies saturation and optionally pixelates
src, placing the result indest. -
#saturate_and_pixelate_raw ⇒ nil
Modifies saturation and optionally pixelates
src, placing the result indest. - #save(*args) ⇒ Object
-
#save_to_buffer(buffer, buffer_size, type, error, array) ⇒ Boolean
Saves pixbuf to a new buffer in format
type, which is currently "jpeg", "png", "tiff", "ico" or "bmp". -
#save_to_bufferv(buffer, buffer_size, type, option_keys, option_values) ⇒ Boolean
Vector version of
gdk_pixbuf_save_to_buffer(). -
#save_to_callback(save_func, user_data, type, error, array) ⇒ Boolean
Saves pixbuf in format
typeby feeding the produced data to a callback. -
#save_to_callbackv(save_func, user_data, type, option_keys, option_values) ⇒ Boolean
Vector version of
gdk_pixbuf_save_to_callback(). -
#save_to_stream(stream, type, cancellable, error, array) ⇒ Boolean
Saves
pixbufto an output stream. -
#save_to_stream_async(stream, type, cancellable, callback, user_data, array) ⇒ nil
Saves
pixbufto an output stream asynchronously. -
#save_to_streamv(stream, type, option_keys, option_values, cancellable) ⇒ Boolean
Saves
pixbufto an output stream. -
#save_to_streamv_async(stream, type, option_keys, option_values, cancellable, callback, user_data) ⇒ nil
Saves
pixbufto an output stream asynchronously. -
#savev(filename, type, option_keys, option_values) ⇒ Boolean
Vector version of
gdk_pixbuf_save(). -
#scale(*args) ⇒ Object
TODO: test TODO: Improve API by Hash.
-
#scale!(source, *args) ⇒ Object
TODO: test TODO: Improve API by Hash.
-
#scale_raw ⇒ nil
Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y, then renders the rectangle (dest_x, dest_y, dest_width, dest_height) of the resulting image onto the destination image replacing the previous contents.
-
#scale_simple(dest_width, dest_height, interp_type) ⇒ GdkPixbuf::Pixbuf
Create a new pixbuf containing a copy of
srcscaled todest_widthxdest_height. -
#set_option(key, value) ⇒ Boolean
Attaches a key/value pair as an option to a
GdkPixbuf. -
#unref ⇒ nil
Removes a reference from a pixbuf.
-
#width ⇒ Integer
The number of columns of the pixbuf.
-
#width=(width) ⇒ Integer
The number of columns of the pixbuf.
Constructor Details
#initialize(*args) ⇒ GdkPixbuf::Pixbuf
Creates a new pixbuf by parsing XPM data in memory.
This data is commonly the result of including an XPM file into a program's C source.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/gdk_pixbuf2/pixbuf.rb', line 21 def initialize(*args) case args.size when 1 case args[0] when Hash initialize_with_hash(args[0]) when String = "#{caller[0]}: #{self.class}.new(path) is deprecated. " << "Use #{self.class}.new(:file => path) instead." warn initialize_raw(args[0]) when Array = "#{caller[0]}: #{self.class}.new(xpm) is deprecated. " << "Use #{self.class}.new(:xpm => xpm) instead." warn initialize_new_from_xpm_data(args[0]) else raise ArgumentError, "must be options: #{args[0].inspect}" end when 2 = "#{caller[0]}: " << "#{self.class}.new(data, copy_pixels) is deprecated. " << "Use Gio::Resource instead." warn initialize_from_inline(*args) when 3 = "#{caller[0]}: " << "#{self.class}.new(path, width, height) is deprecated. " << "Use #{self.class}.new(:file => path, :width => width, " << ":height => height) instead." warn initialize_new_from_file_at_size(*args) when 4 = "#{caller[0]}: " << "#{self.class}.new(path, width, height, " << "preserve_aspect_ratio) is deprecated. " << "Use #{self.class}.new(:file => path, :width => width, " << ":height => height, " << ":preserve_aspect_ratio => preserve_aspect_ratio) instead." warn initialize_new_from_file_at_scale(*args) when 5 = "#{caller[0]}: " << "#{self.class}.new(colorspace, has_alpha, bits_per_sample, " << "width, height) is deprecated. " << "Use #{self.class}.new(:colorspace => colorspace, " << ":has_alpha => has_alpha, " << ":bits_per_sample => bits_per_sample, " << ":width => width, " << ":height => height) instead." warn initialize_new(*args) when 7 = "#{caller[0]}: " << "#{self.class}.new(data, colorspace, has_alpha, " << "bits_per_sample, width, height) is deprecated. " << "Use #{self.class}.new(:data => data, " << ":colorspace => colorspace, " << ":has_alpha => has_alpha, " << ":bits_per_sample => bits_per_sample, " << ":width => width, " << ":height => height) instead." warn initialize_new_from_data(*args) else super end end |
Class Method Details
.calculate_rowstride(colorspace, has_alpha, bits_per_sample, width, height) ⇒ Integer
Calculates the rowstride that an image created with those values would have.
This function is useful for front-ends and backends that want to check
image values without needing to create a GdkPixbuf.
.formats ⇒ GLib::SList<GdkPixbuf::PixbufFormat>
Obtains the available information about the image formats supported by GdkPixbuf.
.get_file_info(filename, width, height) ⇒ GdkPixbuf::PixbufFormat
Parses an image file far enough to determine its format and size.
.get_file_info_async(filename, cancellable, callback, user_data) ⇒ nil
Asynchronously parses an image file far enough to determine its format and size.
For more details see gdk_pixbuf_get_file_info(), which is the synchronous version of this function.
When the operation is finished, callback will be called in the main thread. You can then call gdk_pixbuf_get_file_info_finish() to get the result of the operation.
.get_file_info_finish(async_result, width, height) ⇒ GdkPixbuf::PixbufFormat
Finishes an asynchronous pixbuf parsing operation started with gdk_pixbuf_get_file_info_async().
.init_modules(path) ⇒ Boolean
Initalizes the gdk-pixbuf loader modules referenced by the loaders.cache
file present inside that directory.
This is to be used by applications that want to ship certain loaders in a different location from the system ones.
This is needed when the OS or runtime ships a minimal number of loaders so as to reduce the potential attack surface of carefully crafted image files, especially for uncommon file types. Applications that require broader image file types coverage, such as image viewers, would be expected to ship the gdk-pixbuf modules in a separate location, bundled with the application in a separate directory from the OS or runtime- provided modules.
.new(*args, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/gdk_pixbuf2/deprecated.rb', line 26 def new(*args, &block) if args[0].is_a?(Pixbuf) = "#{caller[0]}: #{self}.new(pixbuf, ...) is deprecated. " << "Use pixbuf.subpixbuf(...) instead." warn() args[0].subpixbuf(*args[1..-1]) elsif args.size == 1 and args[0].is_a?(Hash) = args[0] src_pixbuf = [:src_pixbuf] if src_pixbuf = "#{caller[0]}: " << "#{self}.new(:src_pixbuf => pixbuf, ...) is deprecated. " << "Use pixbuf.subpixbuf(...) instead." warn() src_pixbuf.subpixbuf([:src_x], [:src_y], [:width], [:height]) else super end else super end end |
.new_from_stream_async(stream, cancellable, callback, user_data) ⇒ nil
Creates a new pixbuf by asynchronously loading an image from an input stream.
For more details see gdk_pixbuf_new_from_stream(), which is the synchronous version of this function.
When the operation is finished, callback will be called in the main thread. You can then call gdk_pixbuf_new_from_stream_finish() to get the result of the operation.
.new_from_stream_at_scale_async(stream, width, height, preserve_aspect_ratio, cancellable, callback, user_data) ⇒ nil
Creates a new pixbuf by asynchronously loading an image from an input stream.
For more details see gdk_pixbuf_new_from_stream_at_scale(), which is the synchronous version of this function.
When the operation is finished, callback will be called in the main thread. You can then call gdk_pixbuf_new_from_stream_finish() to get the result of the operation.
.save_to_stream_finish(async_result) ⇒ Boolean
Finishes an asynchronous pixbuf save operation started with gdk_pixbuf_save_to_stream_async().
Instance Method Details
#add_alpha(substitute_color, r, g, b) ⇒ GdkPixbuf::Pixbuf
Takes an existing pixbuf and adds an alpha channel to it.
If the existing pixbuf already had an alpha channel, the channel values are copied from the original; otherwise, the alpha channel is initialized to 255 (full opacity).
If substitute_color is TRUE, then the color specified by the
(r, g, b) arguments will be assigned zero opacity. That is,
if you pass (255, 255, 255) for the substitute color, all white
pixels will become fully transparent.
If substitute_color is FALSE, then the (r, g, b) arguments
will be ignored.
#apply_embedded_orientation ⇒ GdkPixbuf::Pixbuf
Takes an existing pixbuf and checks for the presence of an associated "orientation" option.
The orientation option may be provided by the JPEG loader (which reads the exif orientation tag) or the TIFF loader (which reads the TIFF orientation tag, and compensates it for the partial transforms performed by libtiff).
If an orientation option/tag is present, the appropriate transform will be performed so that the pixbuf is oriented correctly.
#bits_per_sample ⇒ Integer
The number of bits per sample.
Currently only 8 bit per sample are supported.
#bits_per_sample=(bits_per_sample) ⇒ Integer
The number of bits per sample.
Currently only 8 bit per sample are supported.
#byte_length ⇒ Integer
Returns the length of the pixel data, in bytes.
#colorspace ⇒ GdkPixbuf::Colorspace
The color space of the pixbuf.
Currently, only GDK_COLORSPACE_RGB is supported.
#colorspace=(colorspace) ⇒ GdkPixbuf::Colorspace
The color space of the pixbuf.
Currently, only GDK_COLORSPACE_RGB is supported.
#composite(options) ⇒ nil
Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y.
This gives an image in the coordinates of the destination pixbuf. The rectangle (dest_x, dest_y, dest_width, dest_height) is then alpha blended onto the corresponding rectangle of the original destination image.
When the destination rectangle contains parts not in the source image, the data at the edges of the source image is replicated to infinity.

305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/gdk_pixbuf2/pixbuf.rb', line 305 def composite() destination = [:destination] || [:dest] dest_x = [:destination_x] || [:dest_x] || 0 dest_y = [:destination_y] || [:dest_y] || 0 dest_width = [:destination_width] || [:dest_width] dest_height = [:destination_height] || [:dest_height] destination ||= Pixbuf.new(:colorspace => colorspace, :has_alpha => has_alpha?, :bits_per_sample => bits_per_sample, :width => dest_x + dest_width, :height => dest_y + dest_height) destination.composite!(self, ) destination end |
#composite!(source, options) ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/gdk_pixbuf2/pixbuf.rb', line 321 def composite!(source, ) dest_x = [:destination_x] || [:dest_x] || 0 dest_y = [:destination_y] || [:dest_y] || 0 dest_width = [:destination_width] || [:dest_width] dest_height = [:destination_height] || [:dest_height] offset_x = [:offset_x] || 0.0 offset_y = [:offset_y] || 0.0 scale_x = [:scale_x] || (dest_width / source.width.to_f) scale_y = [:scale_y] || (dest_height / source.height.to_f) interpolation_type = [:interpolation_type] || [:interp_type] || :bilinear overall_alpha = [:overall_alpha] || 255 check_x = [:check_x] || 0 check_y = [:check_y] || 0 check_size = [:check_size] color1 = [:color1] || 0x999999 color2 = [:color2] || 0xdddddd if check_size source.composite_color(self, dest_x, dest_y, dest_width, dest_height, offset_x, offset_y, scale_x, scale_y, interpolation_type, overall_alpha, check_x, check_y, check_size, color1, color2) else source.composite_raw(self, dest_x, dest_y, dest_width, dest_height, offset_x, offset_y, scale_x, scale_y, interpolation_type, overall_alpha) end end |
#composite_color(dest, dest_x, dest_y, dest_width, dest_height, offset_x, offset_y, scale_x, scale_y, interp_type, overall_alpha, check_x, check_y, check_size, color1, color2) ⇒ nil
Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y, then alpha blends the rectangle (dest_x ,dest_y, dest_width, dest_height) of the resulting image with a checkboard of the colors color1 and color2 and renders it onto the destination image.
If the source image has no alpha channel, and overall_alpha is 255, a fast path is used which omits the alpha blending and just performs the scaling.
See gdk_pixbuf_composite_color_simple() for a simpler variant of this function suitable for many tasks.
#composite_color_simple(dest_width, dest_height, interp_type, overall_alpha, check_size, color1, color2) ⇒ GdkPixbuf::Pixbuf
Creates a new pixbuf by scaling src to dest_width x dest_height
and alpha blending the result with a checkboard of colors color1
and color2.
#composite_raw ⇒ nil
Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y.
This gives an image in the coordinates of the destination pixbuf. The rectangle (dest_x, dest_y, dest_width, dest_height) is then alpha blended onto the corresponding rectangle of the original destination image.
When the destination rectangle contains parts not in the source image, the data at the edges of the source image is replicated to infinity.

|
|
# File 'lib/gdk_pixbuf2/pixbuf.rb', line 304
|
#copy ⇒ GdkPixbuf::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.
#copy_area(src_x, src_y, width, height, dest_pixbuf, dest_x, dest_y) ⇒ nil
Copies a rectangular area from src_pixbuf to dest_pixbuf.
Conversion of pixbuf formats is done automatically.
If the source rectangle overlaps the destination rectangle on the same pixbuf, it will be overwritten during the copy operation. Therefore, you can not use this function to scroll a pixbuf.
#copy_options(dest_pixbuf) ⇒ Boolean
Copies the key/value pair options attached to a GdkPixbuf to another
GdkPixbuf.
This is useful to keep original metadata after having manipulated a file. However be careful to remove metadata which you've already applied, such as the "orientation" option after rotating the image.
#dup ⇒ Object
176 177 178 |
# File 'lib/gdk_pixbuf2/pixbuf.rb', line 176 def dup copy end |
#fill(pixel) ⇒ nil
Clears a pixbuf to the given RGBA value, converting the RGBA value into the pixbuf's pixel format.
The alpha component will be ignored if the pixbuf doesn't have an alpha channel.
#fill!(pixel) ⇒ Object
186 187 188 |
# File 'lib/gdk_pixbuf2/pixbuf.rb', line 186 def fill!(pixel) fill(pixel) end |
#flip(horizontal) ⇒ GdkPixbuf::Pixbuf
Flips a pixbuf horizontally or vertically and returns the result in a new pixbuf.
#get_option(key) ⇒ String
Looks up key in the list of options that may have been attached to the pixbuf when it was loaded, or that may have been attached by another function using gdk_pixbuf_set_option().
For instance, the ANI loader provides "Title" and "Artist" options. The ICO, XBM, and XPM loaders provide "x_hot" and "y_hot" hot-spot options for cursor definitions. The PNG loader provides the tEXt ancillary chunk key/value pairs as options. Since 2.12, the TIFF and JPEG loaders return an "orientation" option string that corresponds to the embedded TIFF/Exif orientation tag (if present). Since 2.32, the TIFF loader sets the "multipage" option string to "yes" when a multi-page TIFF is loaded. Since 2.32 the JPEG and PNG loaders set "x-dpi" and "y-dpi" if the file contains image density information in dots per inch. Since 2.36.6, the JPEG loader sets the "comment" option with the comment EXIF tag.
#get_pixels_with_length(length) ⇒ Array<Integer>
Queries a pointer to the pixel data of a pixbuf.
This function will cause an implicit copy of the pixbuf data if the pixbuf was created from read-only data.
Please see the section on image data for information about how the pixel data is stored in memory. pixel data.
#has_alpha ⇒ Boolean
Queries whether a pixbuf has an alpha channel (opacity information).
#has_alpha=(has_alpha) ⇒ Boolean
Whether the pixbuf has an alpha channel.
#has_alpha? ⇒ Boolean
Whether the pixbuf has an alpha channel.
#height ⇒ Integer
The number of rows of the pixbuf.
#height=(height) ⇒ Integer
The number of rows of the pixbuf.
#initialize_raw ⇒ GdkPixbuf::Pixbuf
Creates a new pixbuf by parsing XPM data in memory.
This data is commonly the result of including an XPM file into a program's C source.
|
|
# File 'lib/gdk_pixbuf2/pixbuf.rb', line 19
|
#n_channels ⇒ Integer
The number of samples per pixel.
Currently, only 3 or 4 samples per pixel are supported.
#n_channels=(n_channels) ⇒ Integer
The number of samples per pixel.
Currently, only 3 or 4 samples per pixel are supported.
#new_subpixbuf(src_x, src_y, width, height) ⇒ GdkPixbuf::Pixbuf
Creates a new pixbuf which represents a sub-region of src_pixbuf.
The new pixbuf shares its pixels with the original pixbuf, so
writing to one affects both. The new pixbuf holds a reference to
src_pixbuf, so src_pixbuf will not be finalized until the new
pixbuf is finalized.
Note that if src_pixbuf is read-only, this function will force it
to be mutable.
#options ⇒ GLib::HashTable<String>
Returns a GHashTable with a list of all the options that may have been
attached to the pixbuf when it was loaded, or that may have been
attached by another function using [methodGdkPixbuf.Pixbuf.set_option].
#pixel_bytes ⇒ GLib::Bytes
Returns pixel-bytes.
#pixel_bytes=(pixel_bytes) ⇒ GLib::Bytes
#pixels=(pixels) ⇒ GObject
A pointer to the pixel data of the pixbuf.
#read_pixel_bytes ⇒ GLib::Bytes
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.
#read_pixels ⇒ Integer
Provides a read-only pointer to the raw pixel data.
This function allows skipping the implicit copy that must be made if gdk_pixbuf_get_pixels() is called on a read-only pixbuf.
#ref ⇒ GdkPixbuf::Pixbuf
Adds a reference to a pixbuf.
#remove_option(key) ⇒ Boolean
Removes the key/value pair option attached to a GdkPixbuf.
#rotate(angle) ⇒ Object
190 191 192 |
# File 'lib/gdk_pixbuf2/pixbuf.rb', line 190 def rotate(angle) rotate_simple(angle) end |
#rotate_simple(angle) ⇒ GdkPixbuf::Pixbuf
Rotates a pixbuf by a multiple of 90 degrees, and returns the result in a new pixbuf.
If angle is 0, this function will return a copy of src.
#rowstride ⇒ Integer Also known as: row_stride
The number of bytes between the start of a row and the start of the next row.
This number must (obviously) be at least as large as the width of the pixbuf.
#rowstride=(rowstride) ⇒ Integer
The number of bytes between the start of a row and the start of the next row.
This number must (obviously) be at least as large as the width of the pixbuf.
#saturate_and_pixelate(saturation, pixelate) ⇒ nil
Modifies saturation and optionally pixelates src, placing the result in
dest.
The src and dest pixbufs must have the same image format, size, and
rowstride.
The src and dest arguments may be the same pixbuf with no ill effects.
If saturation is 1.0 then saturation is not changed. If it's less than 1.0,
saturation is reduced (the image turns toward grayscale); if greater than
1.0, saturation is increased (the image gets more vivid colors).
If pixelate is TRUE, then pixels are faded in a checkerboard pattern to
create a pixelated image.
195 196 197 198 199 |
# File 'lib/gdk_pixbuf2/pixbuf.rb', line 195 def saturate_and_pixelate(saturation, pixelate) dest = dup saturate_and_pixelate_raw(dest, saturation, pixelate) dest end |
#saturate_and_pixelate_raw ⇒ nil
Modifies saturation and optionally pixelates src, placing the result in
dest.
The src and dest pixbufs must have the same image format, size, and
rowstride.
The src and dest arguments may be the same pixbuf with no ill effects.
If saturation is 1.0 then saturation is not changed. If it's less than 1.0,
saturation is reduced (the image turns toward grayscale); if greater than
1.0, saturation is increased (the image gets more vivid colors).
If pixelate is TRUE, then pixels are faded in a checkerboard pattern to
create a pixelated image.
|
|
# File 'lib/gdk_pixbuf2/pixbuf.rb', line 194
|
#save(type, options = {}) ⇒ String, void #save(filename, type, options = {}) ⇒ void
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/gdk_pixbuf2/pixbuf.rb', line 226 def save(*args) case args.size when 1 arg1 = args[0] if arg1.respond_to?(:to_path) filename = arg1.to_path elsif arg1.is_a?(String) and arg1.include?(".") filename = args[0] else filename = nil type = arg1 end if filename type = File.extname(filename).gsub(/\A\./, "").downcase case type when "jpg" type = "jpeg" end end = {} when 2 if args.last.is_a?(Hash) type, = args if .key?(:filename) = .dup filename = .delete(:filename) else filename = nil end else filename, type = args = {} end when 3 filename, type, = args else = "wrong number of arguments (given #{args.size}, expected 1..3)" raise ArgumentError, end keys = [] values = [] .each do |key, value| key = key.to_s if key.is_a?(Symbol) keys << key values << value end if filename savev(filename, type, keys, values) else _, data = save_to_bufferv(type, keys, values) data.pack("C*") end end |
#save_to_buffer(buffer, buffer_size, type, error, array) ⇒ Boolean
Saves pixbuf to a new buffer in format type, which is currently "jpeg",
"png", "tiff", "ico" or "bmp".
This is a convenience function that uses gdk_pixbuf_save_to_callback()
to do the real work.
Note that the buffer is not NUL-terminated and may contain embedded NUL
characters.
If error is set, FALSE will be returned and buffer will be set to
NULL. Possible errors include those in the GDK_PIXBUF_ERROR
domain.
See gdk_pixbuf_save() for more details.
#save_to_bufferv(buffer, buffer_size, type, option_keys, option_values) ⇒ Boolean
Vector version of gdk_pixbuf_save_to_buffer().
Saves pixbuf to a new buffer in format type, which is currently "jpeg", "tiff", "png", "ico" or "bmp".
See [methodGdkPixbuf.Pixbuf.save_to_buffer] for more details.
#save_to_callback(save_func, user_data, type, error, array) ⇒ Boolean
Saves pixbuf in format type by feeding the produced data to a
callback.
This function can be used when you want to store the image to something other than a file, such as an in-memory buffer or a socket.
If error is set, FALSE will be returned. Possible errors
include those in the GDK_PIXBUF_ERROR domain and whatever the save
function generates.
See [methodGdkPixbuf.Pixbuf.save] for more details.
#save_to_callbackv(save_func, user_data, type, option_keys, option_values) ⇒ Boolean
Vector version of gdk_pixbuf_save_to_callback().
Saves pixbuf to a callback in format type, which is currently "jpeg", "png", "tiff", "ico" or "bmp".
If error is set, FALSE will be returned.
See [methodGdkPixbuf.Pixbuf.save_to_callback] for more details.
#save_to_stream(stream, type, cancellable, error, array) ⇒ Boolean
Saves pixbuf to an output stream.
Supported file formats are currently "jpeg", "tiff", "png", "ico" or
"bmp". See gdk_pixbuf_save_to_buffer() for more details.
The cancellable can be used to abort the operation from another
thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED
will be returned. Other possible errors are in the GDK_PIXBUF_ERROR
and G_IO_ERROR domains.
The stream is not closed at the end of this call.
#save_to_stream_async(stream, type, cancellable, callback, user_data, array) ⇒ nil
Saves pixbuf to an output stream asynchronously.
For more details see gdk_pixbuf_save_to_stream(), which is the synchronous version of this function.
When the operation is finished, callback will be called in the main thread.
You can then call gdk_pixbuf_save_to_stream_finish() to get the result of the operation.
#save_to_streamv(stream, type, option_keys, option_values, cancellable) ⇒ Boolean
Saves pixbuf to an output stream.
Supported file formats are currently "jpeg", "tiff", "png", "ico" or "bmp".
See [methodGdkPixbuf.Pixbuf.save_to_stream] for more details.
#save_to_streamv_async(stream, type, option_keys, option_values, cancellable, callback, user_data) ⇒ nil
Saves pixbuf to an output stream asynchronously.
For more details see gdk_pixbuf_save_to_streamv(), which is the synchronous version of this function.
When the operation is finished, callback will be called in the main thread.
You can then call gdk_pixbuf_save_to_stream_finish() to get the result of the operation.
#savev(filename, type, option_keys, option_values) ⇒ Boolean
Vector version of gdk_pixbuf_save().
Saves pixbuf to a file in type, which is currently "jpeg", "png", "tiff", "ico" or "bmp".
If error is set, FALSE will be returned.
See [methodGdkPixbuf.Pixbuf.save] for more details.
#scale(*args) ⇒ Object
TODO: test TODO: Improve API by Hash
284 285 286 287 288 289 290 291 292 293 |
# File 'lib/gdk_pixbuf2/pixbuf.rb', line 284 def scale(*args) case args.size when 2, 3 width, height, interp_type = args interp_type ||= :bilinear scale_simple(width, height, interp_type) else scale_raw(*args) end end |
#scale!(source, *args) ⇒ Object
TODO: test TODO: Improve API by Hash
297 298 299 300 301 302 |
# File 'lib/gdk_pixbuf2/pixbuf.rb', line 297 def scale!(source, *args) if args.size == 8 args << :bilinear end source.scale_raw(self, *args) end |
#scale_raw ⇒ nil
Creates a transformation of the source image src by scaling by scale_x and scale_y then translating by offset_x and offset_y, then renders the rectangle (dest_x, dest_y, dest_width, dest_height) of the resulting image onto the destination image replacing the previous contents.
Try to use gdk_pixbuf_scale_simple() first; this function is the industrial-strength power tool you can fall back to, if gdk_pixbuf_scale_simple() isn't powerful enough.
If the source rectangle overlaps the destination rectangle on the same pixbuf, it will be overwritten during the scaling which results in rendering artifacts.
|
|
# File 'lib/gdk_pixbuf2/pixbuf.rb', line 281
|
#scale_simple(dest_width, dest_height, interp_type) ⇒ GdkPixbuf::Pixbuf
Create a new pixbuf containing a copy of src scaled to
dest_width x dest_height.
This function leaves src unaffected.
The interp_type should be GDK_INTERP_NEAREST if you want maximum
speed (but when scaling down GDK_INTERP_NEAREST is usually unusably
ugly). The default interp_type should be GDK_INTERP_BILINEAR which
offers reasonable quality and speed.
You can scale a sub-portion of src by creating a sub-pixbuf
pointing into src; see [methodGdkPixbuf.Pixbuf.new_subpixbuf].
If dest_width and dest_height are equal to the width and height of
src, this function will return an unscaled copy of src.
For more complicated scaling/alpha blending see [methodGdkPixbuf.Pixbuf.scale] and [methodGdkPixbuf.Pixbuf.composite].
#set_option(key, value) ⇒ Boolean
Attaches a key/value pair as an option to a GdkPixbuf.
If key already exists in the list of options attached to the pixbuf,
the new value is ignored and FALSE is returned.
#unref ⇒ nil
Removes a reference from a pixbuf.
#width ⇒ Integer
The number of columns of the pixbuf.
#width=(width) ⇒ Integer
The number of columns of the pixbuf.