Class: Caman
Defined in: | src/core/caman.coffee |
Inherits: | Module |
Overview
Here it begins. Caman is defined. There are many different initialization for Caman, which are described on the Guides.
Initialization is tricky because we need to make sure everything we need is actually fully loaded in the DOM before proceeding. When initialized on an image, we need to make sure that the image is done loading before converting it to a canvas element and writing the pixel data. If we do this prematurely, the browser will throw a DOM Error, and chaos will ensue. In the event that we initialize Caman on a canvas element while specifying an image URL, we need to create a new image element, load the image, then continue with initialization.
The main goal for Caman was simplicity, so all of this is handled transparently to the end-user.
Property Summary
- (Boolean) DEBUG
-
Debug mode enables console logging.
Class Method Summary
- + (String) toString() Custom toString()
- + (String) getAttrId(canvas) Get the ID assigned to this canvas by Caman.
Instance Method Summary
- - (Caman) constructor() Constructor The Caman function.
- - (void) domIsLoaded(cb) Checks to ensure the DOM is loaded.
- - (void) parseArguments(args) Parses the arguments given to the Caman function, and sets the appropriate properties on this instance.
- - (void) setInitObject(obj) Sets the initialization object for this instance.
- - (void) setup() Begins the setup process, which differs depending on whether we're in NodeJS, or if an image or canvas object was provided.
- - (void) initNode() Initialization function for NodeJS.
- - (void) initImage() Initialization function for the browser and image objects.
- - (void) initCanvas() Initialization function for the browser and canvas objects.
- - (void) imageAdjustments() Automatically check for a HiDPI capable screen and swap out the image if possible.
- - (void) waitForImageLoaded() Utility function that fires Caman#imageLoaded once the image is finished loading.
- - (Boolean) isImageLoaded() Checks if the given image is finished loading.
- - (Number) imageWidth() Internet Explorer has issues figuring out image dimensions when they aren't explicitly defined, apparently.
- - (Number) imageHeight()
- - (void) imageLoaded() Function that is called once the initialization image is finished loading.
- - (void) finishInit() Final step of initialization.
- - (void) reloadCanvasData() If you have a separate context reference to this canvas outside of CamanJS and you make a change to the canvas outside of CamanJS, you will have to call this function to update our context reference to include those changes.
- - (void) resetOriginalPixelData() Reset the canvas pixels to the original state at initialization.
- - (Boolean) hasId() Does this instance have an ID assigned?
- - (void) assignId() Assign a unique ID to this instance.
- - (Boolean) hiDPIDisabled() Is HiDPI support disabled via the HTML data attribute?
- - (void) hiDPIAdjustments() Perform HiDPI adjustments to the canvas.
- - (Number) hiDPIRatio() Calculate the HiDPI ratio of this display based on the backing store and the pixel ratio.
- - (Boolean) hiDPICapable() Is this display HiDPI capable?
- - (Boolean) needsHiDPISwap() Do we need to perform an image swap with a HiDPI image?
- - (String) hiDPIReplacement() Gets the HiDPI replacement for the initialization image.
- - (void) replaceCanvas(newCanvas) Replaces the current canvas with a new one, and properly updates all of the applicable references for this instance.
- - (void) render(callback = function() {}) Begins the rendering process.
- - (void) revert(updateContext = true) Reverts the canvas back to it's original state while maintaining any cropped or resized dimensions.
- - (void) reset() Completely resets the canvas back to it's original state.
- - (Array) originalVisiblePixels() Returns the original pixel data while maintaining any cropping or resizing that may have occured.
- - (Caman) process(name, processFn) Pushes the filter callback that modifies the RGBA object into the render queue.
- - (Caman) processKernel(name, adjust, divisor = null, bias = 0) Pushes the kernel into the render queue.
- - (Caman) processPlugin(plugin, args) Adds a standalone plugin into the render queue.
- - (Caman) newLayer(callback) Pushes a new layer operation into the render queue and calls the layer callback.
- - (void) executeLayer(layer) Pushes the layer context and moves to the next operation.
- - (void) pushContext(layer) Set all of the relevant data to the new layer.
- - (void) popContext() Restore the previous layer context.
- - (void) applyCurrentLayer() Applies the current layer to its parent layer.
Inherited Method Summary
Methods inherited from Module
.extends, .includes, .delegate, .aliasFunction, .aliasProperty, .included
Class Method Details
+ (String) toString()
Custom toString()
+ (String) getAttrId(canvas)
Get the ID assigned to this canvas by Caman.
Constructor Details
- (Caman) Caman(initializer)
- (Caman) Caman(initializer, callback)
- (Caman) Caman(initializer, url)
- (Caman) Caman(initializer, url, callback)
- (Caman) Caman(file)
- (Caman) Caman(file, callback)
The Caman function. While technically a constructor, it was made to be called without
the new
keyword. Caman will figure it out.
Instance Method Details
- (void) domIsLoaded(cb)
Checks to ensure the DOM is loaded. Ensures the callback is always fired, even if the DOM is already loaded before it's invoked. The callback is also always called asynchronously.
- (void) parseArguments(args)
Parses the arguments given to the Caman function, and sets the appropriate properties on this instance.
@params [Array] args Array of arguments passed to Caman.
- (void) setInitObject(obj)
Sets the initialization object for this instance.
- (void) setup()
Begins the setup process, which differs depending on whether we're in NodeJS, or if an image or canvas object was provided.
- (void) initNode()
Initialization function for NodeJS.
- (void) initImage()
Initialization function for the browser and image objects.
- (void) initCanvas()
Initialization function for the browser and canvas objects.
- (void) imageAdjustments()
Automatically check for a HiDPI capable screen and swap out the image if possible. Also checks the image URL to see if it's a cross-domain request, and attempt to proxy the image. If a cross-origin type is configured, the proxy will be ignored.
- (void) waitForImageLoaded()
Utility function that fires Caman#imageLoaded once the image is finished loading.
- (Boolean) isImageLoaded()
Checks if the given image is finished loading.
- (Number) imageWidth()
Internet Explorer has issues figuring out image dimensions when they aren't explicitly defined, apparently. We check the normal width/height properties first, but fall back to natural sizes if they are 0.
- (Number) imageHeight()
- (void) imageLoaded()
Function that is called once the initialization image is finished loading. We make sure that the canvas dimensions are properly set here.
- (void) finishInit()
Final step of initialization. We finish setting up our canvas element, and we draw the image to the canvas (if applicable).
- (void) reloadCanvasData()
If you have a separate context reference to this canvas outside of CamanJS and you make a change to the canvas outside of CamanJS, you will have to call this function to update our context reference to include those changes.
- (void) resetOriginalPixelData()
Reset the canvas pixels to the original state at initialization.
- (Boolean) hasId()
Does this instance have an ID assigned?
- (void) assignId()
Assign a unique ID to this instance.
- (Boolean) hiDPIDisabled()
Is HiDPI support disabled via the HTML data attribute?
- (void) hiDPIAdjustments()
Perform HiDPI adjustments to the canvas. This consists of changing the scaling and the dimensions to match that of the display.
- (Number) hiDPIRatio()
Calculate the HiDPI ratio of this display based on the backing store and the pixel ratio.
- (Boolean) hiDPICapable()
Is this display HiDPI capable?
- (Boolean) needsHiDPISwap()
Do we need to perform an image swap with a HiDPI image?
- (String) hiDPIReplacement()
Gets the HiDPI replacement for the initialization image.
- (void) replaceCanvas(newCanvas)
Replaces the current canvas with a new one, and properly updates all of the applicable references for this instance.
- (void) render(callback = function() {})
Begins the rendering process. This will execute all of the filter functions called either since initialization or the previous render.
- (void) revert(updateContext = true)
Reverts the canvas back to it's original state while maintaining any cropped or resized dimensions.
- (void) reset()
Completely resets the canvas back to it's original state. Any size adjustments will also be reset.
- (Array) originalVisiblePixels()
Returns the original pixel data while maintaining any cropping or resizing that may have occured. Warning: this is currently in beta status.
- (Caman) process(name, processFn)
Pushes the filter callback that modifies the RGBA object into the render queue.
- (Caman) processKernel(name, adjust, divisor = null, bias = 0)
Pushes the kernel into the render queue.
- (Caman) processPlugin(plugin, args)
Adds a standalone plugin into the render queue.
- (Caman) newLayer(callback)
Pushes a new layer operation into the render queue and calls the layer callback.
- (void) executeLayer(layer)
Pushes the layer context and moves to the next operation.
- (void) pushContext(layer)
Set all of the relevant data to the new layer.
- (void) popContext()
Restore the previous layer context.
- (void) applyCurrentLayer()
Applies the current layer to its parent layer.