API Docs for:
Show:

Composite.Image Class

Image Class

Constructor

Composite.Image

(
  • config
)

Parameters:

  • config Object

    Configuration Object.

Methods

_getGetAtFunction

() private

Call this function with the length of each dimension followed by the number of channels. Returns a function which accepts a pixel index and returns an at array.

Returns:

Function

_getGetPixelIndexFunction

() private

Call this function with the length of each dimension. Returns a function which accepts dimension indices and returns a pixel index.

Returns:

Function

clear

() chainable

Clears the image. This method is chainable.

clone

() Object

Returns a new identical image.

Returns:

conformChannelValue

(
  • value
  • channel
)
Number static

Conforms the given value to the channel's specifications.

Parameters:

Returns:

eachPixel

(
  • pixelParameters
  • callbackFunction
  • contextObject
)
chainable

Invokes a function for each pixel in the image. This method is chainable.

Parameters:

  • pixelParameters Object

    This object contains the following members

    • ctx - Object - Optional scope with which to call fn.
    • fn - Function - This function is invoked once per pixel. This function will receive an object with the following parameters
      • at - Array of image pixel coordinates.
      • chs - Array of image channel definitions.
      • dims - Array of image dimension lengths.
      • img - Reference to this image.
      • pch - Array of pixel channel indices.
      • pcnt - Number of pixels in this image.
      • pix - Integer index of this pixel.
      • pxl - Array of pixel channel values.
      If this function returns true, eachPixel will stop and ignore the remaining pixels.
    • pch - Array - Optional array of channel indexes. If undefined, pixels will contain all channels in order.
  • callbackFunction Function

    This function is invoked after the function has been invoked for each pixel in the image. This function will receive an object with the following members

    • chs - Array of image channel definitions.
    • dims - Array of image dimension lengths.
    • img - Reference to this image.
    • pcnt - Number of pixels in this image.
    • pix - The last integer pixel index processed. If eachPixel was not stopped early, this value should be equal to pcnt and not a valid pixel index.
  • contextObject Object

    Optional scope with which to call the callback function.

getAt

(
  • pixelIndex
)
Array

Converts a pixel index to an at array.

Parameters:

Returns:

getPixel

(
  • at
  • pixelChannels
)
Array

Accessor method to get a pixel from the image.

Parameters:

  • at Array

    Array containing pixel coordinates. The length of this array should match the number of dimensions of the image.

  • pixelChannels Array

    Optional array of channel indexes. If undefined, returned pixel will contain all channels in order.

Returns:

getPixelIndex

(
  • at
)
Number

Converts an at array to a pixel index.

Parameters:

Returns:

setPixel

(
  • at
  • pixel
  • pixelChannels
)
chainable

Accessor method to set a pixel in the image. This method is chainable.

Parameters:

  • at Array

    Array containing pixel coordinates. The length of this array should match the number of dimensions of the image.

  • pixel Array

    Array containing the pixel's channel values.

  • pixelChannels Array

    Optional array of channel indexes. If undefined, the given pixel is assumed to contain all channels in order.

Attributes

channels

Array

Defines the color space for the image.

An image can have as many channels as needed. 3 or 4 channels is most common. Usually the first channel is the red color component, the second is green, the third is blue, and the fourth is alpha.

There are various ways to represent the value of a channel. Values can either be stored as integers or floating-point numbers. Values may be constrained within a minimum and maximum value.

Most commonly red, green, and blue channels are represented by integers between 0 and 255. In this case the values 0, 0, 0 represent black and the values 255, 255, 255 represent white.

The alpha channel is commonly stored as a floating-point value from 0 to 1. 1 represents a completely visible pixel while 0 is completely transparent.

Values are not required to be constrained. For example, sometimes it is interesting or useful to store colors which have brightness beyond white.

This attribute should be set to an array of objects. This array represents the channels in order. This array should have at least one element. This should not be a sparse array. Each object must have a mode property. The mode property must be set to either 'f' for floating-point values or 'i' for integer values. Each object may include the optional maximum and/or minimum properties. Each object may include the optional blackValue and/or whiteValue properties. If undefined, blackValue will default to 0 and whiteValue will default to 255 when mode is set to 'i' or 1 otherwise.

Default: [ {maximum: 255, minimum: 0, mode:'i'}, {maximum: 255, minimum: 0, mode:'i'}, {maximum: 255, minimum: 0, mode:'i'}, {maximum: 1, minimum: 0, mode:'f'} ]

Fires event channelsChange

Fires when the value for the configuration attribute channels is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.

Parameters:

  • e EventFacade
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName String
      The name of the attribute being set.
    • subAttrName String
      If setting a property within the attribute's value, the name of the sub-attribute property being set.

dimensions

Array

Defines the pixel dimensions of the image.

An image can have as many dimensions as needed. 2 dimensions is most common. Usually the first dimension is width and the second is height.

Default: [512, 512]

Fires event dimensionsChange

Fires when the value for the configuration attribute dimensions is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.

Parameters:

  • e EventFacade
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName String
      The name of the attribute being set.
    • subAttrName String
      If setting a property within the attribute's value, the name of the sub-attribute property being set.

pixelCount

Number

Contains the number of pixels in the image.

Fires event pixelCountChange

Fires when the value for the configuration attribute pixelCount is changed. You can listen for the event using the on method if you wish to be notified before the attribute's value has changed, or using the after method if you wish to be notified after the attribute's value has changed.

Parameters:

  • e EventFacade
    An Event Facade object with the following attribute-specific properties added:
    • prevVal Any
      The value of the attribute, prior to it being set.
    • newVal Any
      The value the attribute is to be set to.
    • attrName String
      The name of the attribute being set.
    • subAttrName String
      If setting a property within the attribute's value, the name of the sub-attribute property being set.