tints

TintCache( filter ) constructor
TintCache.setImage( image )
TintCache.setFactors( hue, saturation, brightness )
TintCache.getTintedImage()
TintingFilter class
TintFilter() : AbstractTintingFilter constructor
SetTintFilter() : AbstractTintingFilter constructor
ReplaceFilter() constructor
Tintable
Tintable.setTint( hue, saturation, brightness )
Tintable.getTint()

TintCache( filter ) constructor

A TintCache creates tinted versions of an image. The most recent result is cached, so repeatedly requesting an image with the same tint factors and source image is very fast. To create a new tint cache, you must pass in a new instance of the tinting filter class that you wish to use. This will usually be an instance of TintFilter.

For example:

 var frontTinter = new TintCache( new TintFilter() );
 frontTinter.setImage( frontImage );

 // ...

 frontTinter.setFactors( hueShift, saturationScale, brightnessScale );
 var tintedImage = frontTinter.getTintedImage();

TintCache.setImage( image )

Sets the source image that will have tinting applied to it.
image a BufferedImage that will be tinted using the tinting filter

TintCache.setFactors( hue, saturation, brightness )

Set the HSB tinting factors to use when tinting the source image.
hue the hue adjustment; the exact effect depends on the filter used
saturation the saturation adjustment; the exact effect depends on the filter used
brightness the brightness adjustment; the exact effect depends on the filter used

TintCache.getTintedImage()

Returns a tinted image that is created by applying the tinting filter used to construct this cache to the current source image, using the current HSB factors. If the image and factors have not changed since the last call, this may return a cached result.

If the current source image data has been modified by writing to the image, then you should force any cached result to be cleared before calling this method. An example:

 var tc = new TintCache( new TintFilter() );
 tc.setFactors( -0.25, 1, 0.8 );
 tc.setImage( source );
 var tinted = TintCache.getTintedImage();

 var g = source.createGraphics();
 try {
     // ...
     // modify the pixels in "source"
     // ...
 } finally {
     g.dispose();
 }

 // force clearing cached results before getting tinted version
 // of the modified source image
 tc.setImage( null );
 tc.setImage( source );
 tinted = TintCache.getTintedImage();

returns a tinted version of the source image

TintingFilter class

This interface is implemented by all filters that can be used with a TintCache. More Information

TintFilter() : AbstractTintingFilter constructor

This filter shifts the hue angle and scales the saturation and brightness of every pixel in an image. The image's alpha (opacity) channel is not affected, so translucent areas remain translucent.

The hue angle is measured using a scale in which 1 is equal to 360 degrees (a full circle). Values will normally range from -0.5 to +0.5 (-180 to +180 degrees), but values outside of this range are acceptable. A value of 0 leaves the original hue unchanged.

The saturation and brightness values are factors multiplied against the saturation and brightness of the source pixel. Factors less than 0 are treated as 0. Factors may be more than 1 (100%). If the scaled value for a given pixel is more than 1, it is clamped at 1 in the result.

If using an HSBPanel, it will always provide a hue between -0.5 and +0.5, and saturation and brightness values between 0 and 1. Depending on the saturation and brightness of the source image, you may wish to scale those values up or down before passing them to the TintCache. Otherwise, using the panel it will only be possible to decrease the brightness and saturation (or keep it the same). For example, if you wanted the maximum brightness scale to be 1.2 (120%), multiply the value returned from the HSBPanel by 1.2. When choosing the default brightness, use 1/1.2 if you want the default settings to work out to the original image (1/1.2 * 1.2 = 1).

For convenience, the class TintFilter.ScaledTintFilter can perform scaling for you:

 // scale saturation to 120%, brightness to 200%
 var f = new TintFilter.ScaledTintFilter( h, s, b, 1.2, 2.0 );
A ScaledTintFilter gets and sets factors between 0 and 1 as usual, but internally applies the requested scaling factors.

SetTintFilter() : AbstractTintingFilter constructor

This filter sets the entire source image to the same HSB colour value (without affecting transparency).

ReplaceFilter() constructor

This filter replaces the hue and saturation, and scales the brightness, of the pixels in the source image. This filter can be used to tint a greyscale (black and white) source image. Depending on the brightness of the source image, you may wish to scale the brightness value passed to the filter up in order to cover a wider range of possible tints. (For example, if the average brightness of the source image is 50%, you might scale the brightness value by 2.)

Tintable

Tintable is a Java interface that is implemented by objects that can act as models for an HSBPanel. Panels read their initial settings by calling the Tintable's getTint method, and call its setTint method when the tint controls are adjusted. By implementing the Tintable interface you can process messages from the control panel yourself. Normally, however, you do not need to implement this interface. A standard implementation is provided through the uibindings library that can read and write tints to a private setting on a component.

Tintable.setTint( hue, saturation, brightness )

Called to set the tint being managed by this Tintable.

Tintable.getTint()

Returns an array of three floats that represent the current hue, saturation, and brightness values of the tint being managed by this Tintable.

Index    Contents