graphic function ttg_rgb2gray()

If you have a colored image, this function can turn it into grayscale (Red, Green and Blue intensity are equal). There are quite a few algorithms described to recon a gray value from color intensities (Red, Green, Blue). Tool&Task currently offers three procedures:
method | function |
---|---|
AV -> Average | Gray = int((Red + Green + Blue) / 3) |
LI -> Lightness | Gray = int((max(Red, Green, Blue) + min(Red, Green, Blue)) /2) |
LU -> Luminosity | Gray = int(0.21 * Red + 0.72 * Green + 0.07 * Blue) |
Parameters:
1. Source Bitmap (RGB)2. Target Bitmap (Grayscale)
3. Method
***************************** | |
* Tool&Task example program * | |
* ttg_rgb2gray() * | |
* last compile: 12.07.2022 * | |
***************************** |
LOCAL lx, ly, lh, lw, linfile, loutfile, loh, low, lnh, lnw | |
LOCAL lx0add, ly0add, loutav, loutli, loutlu, lfont | |
ttg_new() | |
ttg_createbmp(148, 148, FORMCOLOR) | |
* the area is divided in 4 rectangles | |
lx = 3 |
&& upper left x coordinate |
ly = 3 |
&& upper left y coordinate |
lh = 74 |
&& half the original space |
lw = 74 - 6 |
&& width and height of subareas |
* resize Logo to lw/lw | |
loutfile = gUserDataTT + 'graphics\pill_resized.bmp' | |
linfile = gUserDataTT + 'graphics\tt_pill.bmp' | |
lwh = ttg_getimage(linfile) |
&& width and height original |
low = get_x(lwh) |
&& width of original file |
loh = get_y(lwh) |
&& height of original file |
lmax = MAX(low, loh) |
&& the longer side must fit |
lfaktor = lw / lmax | |
lwh = ttg_resize(linfile, loutfile, lfaktor) | |
lrw = get_x(lwh) |
&& width of resized file |
lrh = get_y(lwh) |
&& width of resized file |
lx0add = INT((lw - lrw) / 2) |
&& this will center horizontally |
ly0add = INT((lh - lrh) / 2) |
&& this will center vertically |
loutav = gUserDataTT + "temp\av.bmp" | |
loutli = gUserDataTT + "temp\li.bmp" | |
loutlu = gUserDataTT + "temp\lu.bmp" | |
ttg_rgb2gray(loutfile, loutav, "AV") |
&& method AVerage |
ttg_rgb2gray(loutfile, loutli, "LI") |
&& method LIghtness |
ttg_rgb2gray(loutfile, loutlu, "LU") |
&& method LUminosity |
ttg_insertbmp(lx + lx0add, ly + ly0add, loutfile) | |
ttg_insertbmp(74 + lx + lx0add, ly + ly0add, loutav) | |
ttg_insertbmp(lx + lx0add, 74 + ly + ly0add, loutli) | |
ttg_insertbmp(74+lx+lx0add,74+ly+ly0add,loutlu) | |
ttg_execute(gUserDataTT + "temp\meta.bmp") |
&& insert the images |
*now the metafile holds 4 images and text can be added | |
ttg_openbmp(gUserDataTT + "temp\meta.bmp") |
&& mark the three grey scales |
ttg_font('G', "Courier new", 10, "000", 100, 300, BLUE) | |
ttg_fontselect('G') | |
lx0add = lx0add + 4 |
&& 4 pixels from the corner |
ly0add = ly0add + 4 |
&& 4 pixels from the corner |
ttg_text(74 + lx, ly, "AV") |
&& upper right -> AV |
ttg_text(lx, 74 + ly, "LI") |
&& lower left -> LI |
ttg_text(74 + lx, 74 + ly, "LU") |
&& lower right -> LU |
ttg_execute() | |
ttg_display() | |
ERASE (gUserDataTT + "temp\meta.bmp") |
&& example for FoxPro® erase |