Class pyglet.image.ImageGrid

        AbstractImage --+
                        |
AbstractImageSequence --+
                        |
                       ImageGrid

An imaginary grid placed over an image allowing easy access to regular regions of that image.

The grid can be accessed either as a complete image, or as a sequence of images. The most useful applications are to access the grid as a TextureGrid:

image_grid = ImageGrid(...)
texture_grid = image_grid.get_texture_sequence()

or as a Texture3D:

image_grid = ImageGrid(...)
texture_3d = Texture3D.create_for_image_grid(image_grid)

Methods

  __init__(self, image, rows, columns, item_width=None, item_height=None, row_padding=0, column_padding=0)
Construct a grid for the given image.
Texture get_texture(self, rectangle=False)
A Texture view of this image.
ImageData get_image_data(self)
Get an ImageData view of this image.
TextureSequence get_texture_sequence(self)
Get a TextureSequence.
  __len__(self)
AbstractImage __getitem__(self, index)
Retrieve a (list of) image.
Iterator __iter__(self)
Iterate over the images in sequence.
  __repr__(self) (Inherited from pyglet.image.AbstractImage)
  __setitem__(self, slice, image)
Replace one or more images in the sequence.
(Inherited from pyglet.image.AbstractImageSequence)
  blit(self, x, y, z=0)
Draw this image to the active framebuffers.
(Inherited from pyglet.image.AbstractImage)
  blit_into(self, source, x, y, z)
Draw source on this image.
(Inherited from pyglet.image.AbstractImage)
  blit_to_texture(self, target, level, x, y, z=0)
Draw this image on the currently bound texture at target.
(Inherited from pyglet.image.AbstractImage)
Animation get_animation(self, period, loop=True)
Create an animation over this image sequence for the given constant framerate.
(Inherited from pyglet.image.AbstractImageSequence)
Texture get_mipmapped_texture(self)
Retrieve a Texture instance with all mipmap levels filled in.
(Inherited from pyglet.image.AbstractImage)
AbstractImage get_region(self, x, y, width, height)
Retrieve a rectangular region of this image.
(Inherited from pyglet.image.AbstractImage)
  save(self, filename=None, file=None, encoder=None)
Save this image to a file.
(Inherited from pyglet.image.AbstractImage)

Properties

ImageData image_data
An ImageData view of this image.
(Inherited from pyglet.image.AbstractImage)
Texture mipmapped_texture
A Texture view of this image.
(Inherited from pyglet.image.AbstractImage)
Texture texture
Get a Texture view of this image.
(Inherited from pyglet.image.AbstractImage)
TextureSequence texture_sequence
Access this image sequence as a texture sequence.
(Inherited from pyglet.image.AbstractImageSequence)

Instance Variables

int anchor_x = 0
X coordinate of anchor, relative to left edge of image data
(Inherited from pyglet.image.AbstractImage)
int anchor_y = 0
Y coordinate of anchor, relative to bottom edge of image data
(Inherited from pyglet.image.AbstractImage)
int height
Height of image
(Inherited from pyglet.image.AbstractImage)
int width
Width of image
(Inherited from pyglet.image.AbstractImage)

Method Details

__init__

(Constructor) __init__(self, image, rows, columns, item_width=None, item_height=None, row_padding=0, column_padding=0)

Construct a grid for the given image.

You can specify parameters for the grid, for example setting the padding between cells. Grids are always aligned to the bottom-left corner of the image.

Parameters:
image : AbstractImage
Image over which to construct the grid.
rows : int
Number of rows in the grid.
columns : int
Number of columns in the grid.
item_width : int
Width of each column. If unspecified, is calculated such that the entire image width is used.
item_height : int
Height of each row. If unspecified, is calculated such that the entire image height is used.
row_padding : int
Pixels separating adjacent rows. The padding is only inserted between rows, not at the edges of the grid.
column_padding : int
Pixels separating adjacent columns. The padding is only inserted between columns, not at the edges of the grid.
Overrides:
AbstractImage.__init__

get_texture

get_texture(self, rectangle=False)

A Texture view of this image.

By default, textures are created with dimensions that are powers of two. Smaller images will return a TextureRegion that covers just the image portion of the larger texture. This restriction is required on older video cards, and for compressed textures, or where texture repeat modes will be used, or where mipmapping is desired.

If the rectangle parameter is True, this restriction is ignored and a texture the size of the image may be created if the driver supports the GL_ARB_texture_rectangle or GL_NV_texture_rectangle extensions. If the extensions are not present or the image already is a texture, the rectangle parameter is ignored.

Examine Texture.target to determine if the returned texture is a rectangle (GL_TEXTURE_RECTANGLE_ARB or GL_TEXTURE_RECTANGLE_NV) or not (GL_TEXTURE_2D).

Changes to the returned instance may or may not be reflected in this image.

Returns: Texture
Overrides:
AbstractImage.get_texture

Since: pyglet 1.1

get_image_data

get_image_data(self)

Get an ImageData view of this image.

Changes to the returned instance may or may not be reflected in this image.

Returns: ImageData
Overrides:
AbstractImage.get_image_data

Since: pyglet 1.1

get_texture_sequence

get_texture_sequence(self)
Get a TextureSequence.
Returns: TextureSequence
Overrides:
AbstractImageSequence.get_texture_sequence

Since: pyglet 1.1

__len__

(Length operator) __len__(self)
Overrides:
AbstractImageSequence.__len__

__getitem__

(Indexing operator) __getitem__(self, index)
Retrieve a (list of) image.
Returns: AbstractImage
Overrides:
AbstractImageSequence.__getitem__

__iter__

__iter__(self)
Iterate over the images in sequence.
Returns: Iterator
Overrides:
AbstractImageSequence.__iter__

Since: pyglet 1.1