Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImageToolkit/Colors.cpp view on Meta::CPAN
// 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 (!FreeImage_HasPixels(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;
}
/** @brief Applies color mapping for one or several colors on a 1-, 4- or 8-bit
palletized or a 16-, 24- or 32-bit high color image.
This function maps up to <i>count</i> colors specified in <i>srccolors</i> to
these specified in <i>dstcolors</i>. Thereby, color <i>srccolors[N]</i>,
if found in the image, will be replaced by color <i>dstcolors[N]</i>. If
parameter <i>swap</i> is TRUE, additionally all colors specified in
<i>dstcolors</i> are also mapped to these specified in <i>srccolors</i>. For
high color images, the actual image data will be modified whereas, for
palletized images only the palette will be changed.<br>
The function returns the number of pixels changed or zero, if no pixels were
changed.
Both arrays <i>srccolors</i> and <i>dstcolors</i> are assumed not to hold less
than <i>count</i> colors.<br>
For 16-bit images, all colors specified are transparently converted to their
proper 16-bit representation (either in RGB555 or RGB565 format, which is
determined by the image's red- green- and blue-mask).<br>
<b>Note, that this behaviour is different from what FreeImage_ApplyPaletteIndexMapping()
does, which modifies the actual image data on palletized images.</b>
@param dib Input/output image to be processed.
@param srccolors Array of colors to be used as the mapping source.
@param dstcolors Array of colors to be used as the mapping destination.
@param count The number of colors to be mapped. This is the size of both
<i>srccolors</i> and <i>dstcolors</i>.
@param ignore_alpha If TRUE, 32-bit images and colors are treated as 24-bit.
@param swap If TRUE, source and destination colors are swapped, that is,
each destination color is also mapped to the corresponding source color.
@return Returns the total number of pixels changed.
*/
unsigned DLL_CALLCONV
FreeImage_ApplyColorMapping(FIBITMAP *dib, RGBQUAD *srccolors, RGBQUAD *dstcolors, unsigned count, BOOL ignore_alpha, BOOL swap) {
unsigned result = 0;
if (!FreeImage_HasPixels(dib) || (FreeImage_GetImageType(dib) != FIT_BITMAP)) {
return 0;
}
// validate parameters
if ((!srccolors) || (!dstcolors)|| (count < 1)) {
return 0;
}
int bpp = FreeImage_GetBPP(dib);
switch (bpp) {
case 1:
case 4:
case 8: {
unsigned size = FreeImage_GetColorsUsed(dib);
RGBQUAD *pal = FreeImage_GetPalette(dib);
RGBQUAD *a, *b;
for (unsigned x = 0; x < size; x++) {
for (unsigned j = 0; j < count; j++) {
a = srccolors;
b = dstcolors;
for (int i = (swap ? 0 : 1); i < 2; i++) {
if ((pal[x].rgbBlue == a[j].rgbBlue)&&(pal[x].rgbGreen == a[j].rgbGreen) &&(pal[x].rgbRed== a[j].rgbRed)) {
pal[x].rgbBlue = b[j].rgbBlue;
pal[x].rgbGreen = b[j].rgbGreen;
pal[x].rgbRed = b[j].rgbRed;
result++;
j = count;
break;
}
a = dstcolors;
b = srccolors;
}
}
}
return result;
}
case 16: {
WORD *src16 = (WORD *)malloc(sizeof(WORD) * count);
if (NULL == src16) {
( run in 0.464 second using v1.01-cache-2.11-cpan-787462296c9 )