ScinImageBuffer:
Filter:
Scintillator/Classes (extension) | Quarks > Scintillator > Media

ScinImageBuffer
ExtensionExtension

Represents a server-side graphics memory region for sampling static images.

Description

The ScinImageBuffer class is designed to be analagous to the SuperCollider audio Buffer class, but for reading static images for sampling. ScinImageBuffers are most commonly used inside of ScinthDef functions as arguments to VSampler instances. Currently ScinImageBuffer support is limited to reading static images, but more may be added in the future.

Class Methods

.read

Attempts to open the image file at the provided path and read the metadata. If that is successful the server will decode the image file, optionally resize it to the provided width and height, and upload it to the graphics hardware so it is ready for use.

The width and height arguments are both by default -1, which is an instruction to the server to respect the original dimensions of the image. If only one of the dimension arguments is supplied by -1, the server will scale the image to the non-negative dimension and then preserve the aspect ratio of the image by scaling the negative dimension to the appropriate size. Of course, if both dimensions are non-negative then the server will scale the image to the provided dimensions, disregarding the aspect ratio of the input image.

For example, for a source image that is 200 pixels wide and 100 pixels tall:

width requestedheight requestedbuffer widthbuffer heightnotes
400100400100Server will disregard aspect ratio of source image if both requested dimensions are nonnegative.
-15010050In order to maintain 2:1 aspect ratio server has computed a width of 50 px.
400-1400200In order to maintain 2:1 aspect ratio server has computed a height of 400 px.
-1-1200100Server has allocated width and height of source image.

Arguments:

server

The ScinServer on which to read the image and allocate the buffer. If nil, will use ScinServer.default.

path

A string containing the path to the image file to read.

width

An optional integer describing a desired width to scale the image to, or -1.

height

An optional integer describing a desired height to scale the image to, or -1.

action

An optional function to be evaluated once the image has been decoded, uploaded, and this ImageBuffer's instance variables have been updated. The function will be passed this ImageBuffer as an argument.

bufnum

An explicitly specified buffer number. While buffer numbers for ImageBuffer are set on the client, and not allocated on the server, any load or delete operations on an ImageBuffer will clobber any exising ImageBuffer with the same buffer number. So, like Buffer, the best practice is to leave this unspecified.

Instance Methods

.width

Returns the width of the ImageBuffer in pixels.

.server

The ScinServer that owns the associated buffer.

.bufnum

The integer buffer number that uniquely identifies this buffer on the server.

.height

Returns the height of the ImageBuffer in pixels.

Examples