Inherits from NSObject
Declared in AKImageEffect.h
AKImageEffect.m

Overview

The AKImageEffect class is the heart and soul of AmazeKit. Image effects represent a single layer of an image, like layers of an onion. The final image produced is the result of taking all of the image effects and layering them on top of one another.

Tasks

Creating an Image Effect

Customizing Appearance

  •   alpha

    The opacity of the effect. 1 is fully opaque, 0 is fully transparent.

    property
  •   blendMode

    The blend mode to use when rendering the effect on the layer below it. See Apple’s documentation for all supported blend modes.

    property

Rendering

Caching

  • + isImmutable

    Returns the mutability of the image effect.

  • – cacheRenderedImage:

    Stores the rendered image in a cache. Do not implement your own cache.

  •   dirty

    Mutable image effects should set the value of dirty to YES when they change. Setting dirty to YES will result in the representativeHash: method recomputing the hash.

    property
  • – representativeHash

    For efficient caching, the output from the reprsesentativeDictionary method is converted into minified canonical JSON, then stored as a sha1 hash.

  • – previouslyRenderedImageForSize:atScale:

    Loads an image from the cache for the appropriate size and scale.

Representation

Properties

alpha

The opacity of the effect. 1 is fully opaque, 0 is fully transparent.

@property (readonly) CGFloat alpha

Declared In

AKImageEffect.h

blendMode

The blend mode to use when rendering the effect on the layer below it. See Apple’s documentation for all supported blend modes.

@property (readonly) CGBlendMode blendMode

Declared In

AKImageEffect.h

dirty

Mutable image effects should set the value of dirty to YES when they change. Setting dirty to YES will result in the representativeHash: method recomputing the hash.

@property (getter=isDirty) BOOL dirty

Declared In

AKImageEffect.h

Class Methods

canRenderIndividually

If the image effect can be rendered using image data from other layers, return YES. Otherwise, return NO.

+ (BOOL)canRenderIndividually

Return Value

YES if the effect can be rendered on its own, NO if it relies on image data from other layers.

Declared In

AKImageEffect.h

effectWithRepresentativeDictionary:

Parses a dictionary representing an image effect, creates a new image effect, and initializes it with values from the dictionary.

+ (id)effectWithRepresentativeDictionary:(NSDictionary *)representativeDictionary

Parameters

representativeDictionary

The dictionary to parse into an image effect.

Return Value

An AKImageEffect or AKImageEffect subclass initilaized with values from the dictionary.

Declared In

AKImageEffect.h

isImmutable

Returns the mutability of the image effect.

+ (BOOL)isImmutable

Return Value

YES if the class is immutable (the default), NO if it is mutable.

Declared In

AKImageEffect.h

Instance Methods

applyAppearanceProperties

In the implementation of renderImageFromSourceImage:withSize: in an image effect subclass, call this method to apply appearance properties defined in AKImageEffect, currently alpha and blendMode.

- (void)applyAppearanceProperties

Discussion

This method expects you to have set up a graphics context and will therefore call UIGraphicsGetCurrentContext() or the equivalent in its implementation.

Declared In

AKImageEffect.h

cacheRenderedImage:

Stores the rendered image in a cache. Do not implement your own cache.

- (void)cacheRenderedImage:(UIImage *)image

Parameters

image

The rendered image.

Declared In

AKImageEffect.h

initWithAlpha:blendMode:

The designated initializer for a base image effect.

- (id)initWithAlpha:(CGFloat)alpha blendMode:(CGBlendMode)blendMode

Parameters

alpha

The value for the alpha property.

blendMode

The value for the blendMode property.

Return Value

An initialized image effect.

Discussion

Because image effects are immutable (for performance reasons), you’ll need to set the proper values for the properties at time of creation. Subclasses should specify additional parameters in their own initializers.

Declared In

AKImageEffect.h

initWithRepresentativeDictionary:

Initializes an image effect with values from a dictionary.

- (id)initWithRepresentativeDictionary:(NSDictionary *)representativeDictionary

Parameters

representativeDictionary

The dictionary to parse into an image effect.

Return Value

An AKImageEffect or AKImageEffect subclass initilaized with values from the dictionary.

Declared In

AKImageEffect.h

obtainLock

If an image effect maintains internal state and cannot render multiple images concurrently, use this method to obtain a lock during rendering.

- (void)obtainLock

Declared In

AKImageEffect.h

previouslyRenderedImageForSize:atScale:

Loads an image from the cache for the appropriate size and scale.

- (UIImage *)previouslyRenderedImageForSize:(CGSize)size atScale:(CGFloat)scale

Parameters

size

The size of the cached image to load.

scale

The scale of the cached image to load.

Return Value

If a cached image is found, the image. Otherwise, nil.

Declared In

AKImageEffect.h

releaseLock

Releases a lock obtained with the obtainLock method.

- (void)releaseLock

Declared In

AKImageEffect.h

renderedImageForSize:atScale:

This method should be implemented by image effects that do not depend on other layers to render.

- (UIImage *)renderedImageForSize:(CGSize)size atScale:(CGFloat)scale

Parameters

size

The size in points to render.

scale

The scale to use when rendering. Retina displays, for instance, will have a scale of 2.

Declared In

AKImageEffect.h

renderedImageFromSourceImage:

This method should be implemented by image effects that depend on the layer beneath them to render (and so their class will return NO in its implementation of canRenderIndividually).

- (UIImage *)renderedImageFromSourceImage:(UIImage *)sourceImage

Parameters

sourceImage

The composited layer image effects to render on top of.

Return Value

The rendered image in its entirety.

Declared In

AKImageEffect.h

representativeDictionary

Every image effect can be represented by a dictionary. This can be converted to and from JSON, allowing image properties to be stored in a lightweight text format, read from a server, etc.

- (NSDictionary *)representativeDictionary

Return Value

An NSDictionary completely representing the image effect.

Declared In

AKImageEffect.h

representativeHash

For efficient caching, the output from the reprsesentativeDictionary method is converted into minified canonical JSON, then stored as a sha1 hash.

- (NSString *)representativeHash

Return Value

The hashed dictionary data as an NSString.

Declared In

AKImageEffect.h