#include "l_bitmap.h"
L_LTIMGCLR_API L_INT L_GrayScaleToMultitone(pBitmap, uToneType, uDistType, pColor, pGradient, uFlags)
Converts a grayscale bitmap into a colored one by mixing or replacing the original values of the pixels with one or more new colors.
Pointer to the bitmap handle referencing the bitmap.
Flag that indicates the number of colors to add to the grayscale bitmap. Possible values are:
Value | Meaning |
---|---|
DT_MONOTONE | [0x0000] Add one color. |
DT_DUOTONE | [0x0001] Add two colors. |
DT_TRITONE | [0x0002] Add three colors. |
DT_QUADTONE | [0x0003] Add four colors. |
Flag that indicates the source of the colors to be added to the bitmap. Possible values are:
Value | Meaning |
---|---|
DT_LINEAR | [0] Use the linear gradient from dark to light, generated by the toolkit. If this flag is set, LEADTOOLS will ignore the pGradient parameter and update the pColor parameter with an array of colors generated by the toolkit. |
DT_USERDEFINE | [1] Use the user-defined gradient in the pGradient parameter. |
Pointer to an array of RGB colors, that will be added to the grayscale bitmap. This parameter is ignored when the uDistType
parameter is set to DT_USER. If the toolkit is generating the gradient colors, the user sets the desired base color(s) in this parameter when L_GrayScaleToMultitone is called. The number of entries in the array depends on the value of uToneType
: 1 for DT_MONOTONE, 2 for DT_DUOTONE, 3 for DT_TRITONE, 4 for DT_QUADTONE. When the toolkit generates the array of gradient colors, this parameter will be updated with that array.
Pointer to a user-defined array of palette entries that will hold the set of color shade gradients. This parameter is used when the uDistType
parameter is set to DT_USER.
The number of entries in this array should be 256 entries for each TONE.
Flag used to determine whether the new colors replace the old colors, or whether the new colors will be mixed with the old colors. Possible values are:
Value | Meaning |
---|---|
DT_MIX | [0x0000] Mix the old colors with the new ones |
DT_REPLACE | [0x0001] Replace the old colors with the new ones |
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.
This function was designed for use with grayscale bitmaps. If the bitmap being used is not grayscale, this function only affects those pixels or areas of the bitmap where Red=Green=Blue.
Monotone conversion is possible by setting uFlags
to DT_REPLACE, which clears the palette.
This function gives you the option of having the toolkit generate the array of colors to use or creating the array of colors to use yourself.
To have the toolkit generate the array of colors:
If the bitmap is binary, call L_GrayScaleToMultitone with uToneType set to DT_MONOTONE, uDistType
set to DT_LINEAR and the color you wish to use set in pColor. The L_IsGrayScaleBitmap function will be called by L_GrayScaleToDuotone to determine the kind of grayscale palette being used. If L_IsGrayScaleBitmap returns GRAY_ORDEREDINVERSE or GRAY_NOTORDERED, then the color passed in the pColor parameter to L_GrayScaleToMultitone will become the first color in the array generated by the toolkit, and the toolkit will create the second color in the array. The pColor
array will be updated with these two colors.
If L_IsGrayScaleBitmap returns a value other than GRAY_ORDEREDINVERSE or GRAY_NOTORDERED, then the color passed in the pColor parameter to L_GrayScaleToMultitone will become the second color in the array generated by the toolkit, and the toolkit will create the first color in the array. The pColor parameter will be updated with these two colors.
If the bitmap is grayscale (not binary) call L_GrayScaleToMultitone with uDistType set to DT_LINEAR. The L_GrayScaleToMultitone function will take the color(s) passed to it in the pColor parameter and generate a 256 color gradient for each color.
If the uToneType is set to DT_DUOTONE, set two colors in the pColor parameter. The toolkit will create a 256 color array for each color. The pColor array will be updated with all 512 colors.
If the uToneType
is set to DT_TRITONE, set three colors in the pColor
parameter. The toolkit will create a 256 color array for each color. The pColor array will be updated with all 768 colors.
If the uToneType is set to DT_QUADTONE, set four colors in the pColor parameter. The toolkit will create a 256 color array for each color. The pColor array will be updated with all 1024 colors.
If the bitmap is not grayscale (it is color) call L_GrayScaleToMultitone with uDistType
set to DT_LINEAR. The L_GrayScaleToMultitone function will take the color(s) passed to it in the pColor
parameter and generate a 256 color gradient for each color. (See the expanded explanation in i, ii and iii of (b) above.) These colors will be used to change only those pixels in the color image for which Red = Green = Blue.
To use a user-defined array of colors:
If the bitmap is binary, call L_GrayScaleToMultitone with uToneType set to DT_MONOTONE, uDistType set to DT_USER and the two colors you wish to use in the pGradient
parameter.
If the bitmap is grayscale (not binary) call L_GrayScaleToMultitone with uDistType set to DT_USER.
If the uToneType is set to DT_DUOTONE, set 512 colors (256 for each basic color) in the pGradient parameter.
If the uToneType is set to DT_TRITONE, set 768 colors (256 for each basic color) in the pGradient parameter.
If the uToneType
is set to DT_QUADTONE, set 1024 colors (256 for each basic color) in the pGradient
parameter.
If the bitmap is not grayscale (it is color) call L_GrayScaleToMultitone with uDistType
set to DT_USER. (See the expanded explanation in i, ii and iii of (b) above.) These colors will be used to change only those pixels in the color image for which Red = Green = Blue.
This function supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available in the Document and Medical Imaging toolkits.
This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.
Required DLLs and Libraries
Win32, x64, Linux.
This example loads a bitmap and applies Duotone conversion to it.
L_INT GrayScaleToMultitoneExample(L_VOID)
{
L_INT nRet;
BITMAPHANDLE LeadBitmap; /* Bitmap handle to hold the loaded image. */
COLORREF crColor[2]; /* New Color */
/* Load the bitmap, keeping the bits per pixel of the file */
nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Beauty16.jpg")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL);
if(nRet !=SUCCESS)
return nRet;
/* Change the bitmap to grayscale bitmap*/
nRet = L_GrayScaleBitmap (&LeadBitmap, 8);
if(nRet !=SUCCESS)
return nRet;
//free Bitmap
/* The new colors */
crColor[0] = RGB(255, 255, 0);
crColor[1] = RGB(255, 0, 0);
/* Apply Multitone conversion */
nRet = L_GrayScaleToMultitone(&LeadBitmap, DT_DUOTONE, DT_LINEAR, crColor, NULL, DT_MIX);
if(nRet !=SUCCESS)
return nRet;
nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 24, 0, NULL);
if(nRet !=SUCCESS)
return nRet;
//free bitmap
if(LeadBitmap.Flags.Allocated)
L_FreeBitmap(&LeadBitmap);
return SUCCESS;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document