FreeImage.AdjustColors Method

FreeImage.NET

FreeImageAdjustColors Method
Adjusts an image's brightness, contrast and gamma as well as it may optionally invert the image within a single operation.

Namespace: FreeImageAPI
Assembly: FreeImageNET (in FreeImageNET.dll) Version: 3.17.0.4 (3.17.0)
Syntax
C#
public static bool AdjustColors(
	FIBITMAP dib,
	double brightness,
	double contrast,
	double gamma,
	bool invert
)

Parameters

dib
Type: FreeImageAPIFIBITMAP
Handle to a FreeImage bitmap.
brightness
Type: SystemDouble
Percentage brightness value where -100 <= brightness <= 100.

A value of 0 means no change, less than 0 will make the image darker and greater than 0 will make the image brighter.

contrast
Type: SystemDouble
Percentage contrast value where -100 <= contrast <= 100.

A value of 0 means no change, less than 0 will decrease the contrast and greater than 0 will increase the contrast of the image.

gamma
Type: SystemDouble
Gamma value to be used for gamma correction.

A value of 1.0 leaves the image alone, less than one darkens it, and greater than one lightens it.

This parameter must not be zero or smaller than zero. If so, it will be ignored and no gamma correction will be performed on the image.
invert
Type: SystemBoolean
If set to true, the image will be inverted.

Return Value

Type: Boolean
Returns true on success, false on failure.
Remarks
This function adjusts an image's brightness, contrast and gamma as well as it may optionally invert the image within a single operation. If more than one of these image display properties need to be adjusted, using this function should be preferred over calling each adjustment function separately. That's particularly true for huge images or if performance is an issue.

This function relies on GetAdjustColorsLookupTable(Byte, Double, Double, Double, Boolean), which creates a single lookup table, that combines all adjustment operations requested.

Furthermore, the lookup table created by GetAdjustColorsLookupTable(Byte, Double, Double, Double, Boolean) does not depend on the order, in which each single adjustment operation is performed. Due to rounding and byte casting issues, it actually matters in which order individual adjustment operations are performed. Both of the following snippets most likely produce different results:

// snippet 1: contrast, brightness
AdjustContrast(dib, 15.0);
AdjustBrightness(dib, 50.0);

// snippet 2: brightness, contrast
AdjustBrightness(dib, 50.0);
AdjustContrast(dib, 15.0);

Better and even faster would be snippet 3:

// snippet 3:
AdjustColors(dib, 50.0, 15.0, 1.0, false);

See Also