Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImageToolkit/Colors.cpp view on Meta::CPAN
bits += bytespp;
}
}
break;
case FICC_ALPHA :
if(32 == bpp) {
for(y = 0; y < FreeImage_GetHeight(src); y++) {
bits = FreeImage_GetScanLine(src, y);
for(x = 0; x < FreeImage_GetWidth(src); x++) {
bits[FI_RGBA_ALPHA] = LUT[ bits[FI_RGBA_ALPHA] ]; // A
bits += bytespp;
}
}
}
break;
default:
break;
}
break;
}
}
return TRUE;
}
/** @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(!FreeImage_HasPixels(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);
}
/** @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(!FreeImage_HasPixels(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);
}
/** @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(!FreeImage_HasPixels(src))
return FALSE;
// Build the lookup table
const double scale = (100 + percentage) / 100;
for(int i = 0; i < 256; i++) {
value = 128 + (i - 128) * scale;
value = MAX(0.0, MIN(value, 255.0));
LUT[i] = (BYTE)floor(value + 0.5);
}
return FreeImage_AdjustCurve(src, LUT, FICC_RGB);
}
/** @brief Computes image histogram
For 24-bit and 32-bit images, histogram can be computed from red, green, blue and
black channels. For 8-bit images, histogram is computed from the black channel. Other
bit depth is not supported (nothing is done).
@param src Input image to be processed.
@param histo Histogram array to fill. <b>The size of 'histo' is assumed to be 256.</b>
@param channel Color channel to use
@return Returns TRUE if succesful, returns FALSE if the image bit depth isn't supported.
*/
BOOL DLL_CALLCONV
FreeImage_GetHistogram(FIBITMAP *src, DWORD *histo, FREE_IMAGE_COLOR_CHANNEL channel) {
BYTE pixel;
BYTE *bits = NULL;
unsigned x, y;
if(!FreeImage_HasPixels(src) || !histo) return FALSE;
unsigned width = FreeImage_GetWidth(src);
unsigned height = FreeImage_GetHeight(src);
unsigned bpp = FreeImage_GetBPP(src);
if(bpp == 8) {
// clear histogram array
memset(histo, 0, 256 * sizeof(DWORD));
// compute histogram for black channel
for(y = 0; y < height; y++) {
bits = FreeImage_GetScanLine(src, y);
for(x = 0; x < width; x++) {
// get pixel value
pixel = bits[x];
histo[pixel]++;
}
}
return TRUE;
}
else if((bpp == 24) || (bpp == 32)) {
int bytespp = bpp / 8; // bytes / pixel
// clear histogram array
memset(histo, 0, 256 * sizeof(DWORD));
switch(channel) {
case FICC_RED:
// compute histogram for red channel
for(y = 0; y < height; y++) {
bits = FreeImage_GetScanLine(src, y);
for(x = 0; x < width; x++) {
pixel = bits[FI_RGBA_RED]; // R
histo[pixel]++;
bits += bytespp;
}
( run in 1.594 second using v1.01-cache-2.11-cpan-adec679a428 )