Example #1
0
BOOL fipImage::adjustCurve(BYTE *LUT, FREE_IMAGE_COLOR_CHANNEL channel) {
	if(_dib) {
		_bHasChanged = TRUE;

		return FreeImage_AdjustCurve(_dib, LUT, channel);
	}
	return FALSE;
}
Example #2
0
/** @brief Adjusts the contrast of a 8, 24 or 32-bit image by a certain amount.

@param src Input image to be processed.
@param percentage Where -100 <= percentage <= 100<br>
A value 0 means no change, less than 0 will decrease the contrast 
and greater than 0 will increase the contrast of the image.
@return Returns TRUE if successful, FALSE otherwise.
*/
BOOL DLL_CALLCONV 
FreeImage_AdjustContrast(FIBITMAP *src, double percentage) {
	BYTE LUT[256];		// Lookup table
	double value;

	if(!src)
		return FALSE;
	
	// Build the lookup table
	for(int i = 0; i < 256; i++) {
		value = 128 + (i - 128) * (100 + percentage) / 100;
		value = MAX(0.0, MIN(value, 255.0));
		LUT[i] = (BYTE)floor(value + 0.5);
	}
	return FreeImage_AdjustCurve(src, LUT, FICC_RGB);
}
Example #3
0
/** @brief Adjusts the brightness of a 8, 24 or 32-bit image by a certain amount.

@param src Input image to be processed.
@param percentage Where -100 <= percentage <= 100<br>
A value 0 means no change, less than 0 will make the image darker 
and greater than 0 will make the image brighter.
@return Returns TRUE if successful, FALSE otherwise.
*/
BOOL DLL_CALLCONV 
FreeImage_AdjustBrightness(FIBITMAP *src, double percentage) {
	BYTE LUT[256];		// Lookup table
	double value;

	if(!src)
		return FALSE;
	
	// Build the lookup table
	const double scale = (100 + percentage) / 100;
	for(int i = 0; i < 256; i++) {
		value = i * scale;
		value = MAX(0.0, MIN(value, 255.0));
		LUT[i] = (BYTE)floor(value + 0.5);
	}
	return FreeImage_AdjustCurve(src, LUT, FICC_RGB);
}
Example #4
0
/** @brief Adjusts an image's brightness, contrast and gamma as well as it may
 optionally invert the image within a single operation.
 
 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 FreeImage_GetAdjustColorsLookupTable(), which creates a
 single lookup table, that combines all adjustment operations requested.
 
 Furthermore, the lookup table created by FreeImage_GetAdjustColorsLookupTable()
 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
 FreeImage_AdjustContrast(dib, 15.0);
 FreeImage_AdjustBrightness(dib, 50.0); 
 
 // snippet 2: brightness, contrast
 FreeImage_AdjustBrightness(dib, 50.0);
 FreeImage_AdjustContrast(dib, 15.0);
 
 Better and even faster would be snippet 3:
 
 // snippet 3:
 FreeImage_AdjustColors(dib, 50.0, 15.0, 1.0, FALSE);
 
 @param dib Input/output image to be processed.
 @param brightness Percentage brightness value where -100 <= brightness <= 100<br>
 A value of 0 means no change, less than 0 will make the image darker and greater
 than 0 will make the image brighter.
 @param contrast Percentage contrast value where -100 <= contrast <= 100<br>
 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.
 @param gamma 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.<br>
 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.
 @param invert If set to TRUE, the image will be inverted.
 @return Returns TRUE on success, FALSE otherwise (e.g. when the bitdeph of the
 source dib cannot be handled).
 */
BOOL DLL_CALLCONV
FreeImage_AdjustColors(FIBITMAP *dib, double brightness, double contrast, double gamma, BOOL invert) {
	BYTE LUT[256];

	if ((!dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP)) {
		return FALSE;
	}

	int bpp = FreeImage_GetBPP(dib);
	if ((bpp != 8) && (bpp != 24) && (bpp != 32)) {
		return FALSE;
	}

	if (FreeImage_GetAdjustColorsLookupTable(LUT, brightness, contrast, gamma, invert)) {
		return FreeImage_AdjustCurve(dib, LUT, FICC_RGB);
	}
	return FALSE;
}
Example #5
0
/** @brief Performs gamma correction on a 8, 24 or 32-bit image.

@param src Input image to be processed.
@param gamma Gamma value to use. A value of 1.0 leaves the image alone, 
less than one darkens it, and greater than one lightens it.
@return Returns TRUE if successful, FALSE otherwise.
*/
BOOL DLL_CALLCONV 
FreeImage_AdjustGamma(FIBITMAP *src, double gamma) {
	BYTE LUT[256];		// Lookup table

	if(!src || (gamma <= 0))
		return FALSE;
	
	// Build the lookup table

	double exponent = 1 / gamma;
	double v = 255.0 * (double)pow((double)255, -exponent);
	for(int i = 0; i < 256; i++) {
		double color = (double)pow((double)i, exponent) * v;
		if(color > 255)
			color = 255;
		LUT[i] = (BYTE)floor(color + 0.5);
	}

	// Apply the gamma correction
	return FreeImage_AdjustCurve(src, LUT, FICC_RGB);
}