Teek API Documentation

CPU-side RGBA pixel buffer backed by Tk’s “photo image” format.

Despite the name, this is really a raw pixel manipulation surface. Tk has two built-in image types: “bitmap” (two colors ` transparency) and “photo” (full-color, 32-bit RGBA). The naming reflects Tk’s image type system, not the contents — a “photo” is just Tk’s term for a full-color pixel buffer.

Think of it as a software framebuffer: you pack RGBA bytes, write them in bulk, read them back, zoom/subsample, and blit to a canvas or label for display. All work is CPU-driven — there is no GPU acceleration.

The C methods (#put_block, #get_image, #get_pixel, etc.) call Tk_PhotoPutBlock / Tk_PhotoGetImage directly, bypassing Tcl string parsing for much better performance than the Tcl-level `$photo put+ command. Designed for games, visualizations, and real-time drawing.

Inherits: Object

Class Methods

next_name

@api private

Instance Methods

==(other)

blank

Clear the image to fully transparent.

Returns self

delete

Delete this photo image and free its resources.

Returns void

exist?

Check if this photo image still exists.

Returns Boolean

expand(width, height)

Expand image to at least the given dimensions. Will not shrink.

Parameters
  • width Integer — minimum width
  • height Integer — minimum height

Returns self

@note Has no effect on photos created with explicit width: / height: options. Only works on auto-sized photos (those whose size was set by writing pixel data). This is a Tk limitation.

get_image(x: nil, y: nil, width: nil, height: nil, unpack: false)

Read pixel data from the image.

Parameters
  • x Integer — source X offset
  • y Integer — source Y offset
  • width Integer, nil — region width (nil for full image)
  • height Integer, nil — region height (nil for full image)
  • unpack Boolean — if true, return flat array of integers instead of binary string

Returns Hash<code>data: String, width: Integer, height: Integer</code> or <code>pixels: Array&lt;Integer&gt;, width: Integer, height: Integer</code> if unpack is true

get_pixel(x, y)

Read a single pixel.

Parameters
  • x Integer — X coordinate
  • y Integer — Y coordinate

Returns Array<Integer> — [r, g, b, a] values (0-255)

get_size

Get image dimensions.

Returns Array<Integer> — [width, height]

hash

initialize(app, name: nil, width: nil, height: nil, file: nil, data: nil, format: nil, palette: nil, gamma: nil)

Create a new photo image.

Parameters
  • app Teek::App — the application instance
  • name String, nil — Tcl image name (auto-generated if nil)
  • width Integer, nil — image width in pixels
  • height Integer, nil — image height in pixels
  • file String, nil — path to an image file to load
  • data String, nil — base64-encoded image data
  • format String, nil — image format (e.g. "png", "gif")
  • palette String, nil — palette specification
  • gamma Float, nil — gamma correction value

Returns Photo — a new instance of Photo

inspect

put_block(pixel_data, width, height, x: 0, y: 0, format: :rgba, composite: :set)

Write RGBA pixel data to the image.

Parameters
  • pixel_data String — binary string, 4 bytes (RGBA) per pixel
  • width Integer — width of the pixel block
  • height Integer — height of the pixel block
  • x Integer — destination X offset
  • y Integer — destination Y offset
  • format :rgba, :argb — pixel format
  • composite :set, :overlay — compositing rule

Returns self

put_zoomed_block(pixel_data, width, height, x: 0, y: 0, zoom_x: 1, zoom_y: 1, subsample_x: 1, subsample_y: 1, format: :rgba, composite: :set)

Write RGBA pixel data with zoom and subsample.

Zoom replicates each pixel (zoom=3 makes each source pixel 3x3). Subsample skips source pixels (subsample=2 takes every other pixel).

Parameters
  • pixel_data String — binary string, 4 bytes (RGBA) per pixel
  • width Integer — source width in pixels
  • height Integer — source height in pixels
  • x Integer — destination X offset
  • y Integer — destination Y offset
  • zoom_x Integer — horizontal zoom factor
  • zoom_y Integer — vertical zoom factor
  • subsample_x Integer — horizontal subsample factor
  • subsample_y Integer — vertical subsample factor
  • format :rgba, :argb — pixel format
  • composite :set, :overlay — compositing rule

Returns self

set_size(width, height)

Set image dimensions. May crop or add transparent pixels.

Parameters
  • width Integer — new width
  • height Integer — new height

Returns self

to_s

Returns String — the Tcl image name

Attributes

app [R]

Returns the value of attribute app.

name [R]

Returns the value of attribute name.