1 ;-----------------------------------------------------------
\r
3 ; MXCG.ASM - Color to gray conversion
\r
4 ; Copyright (c) 1994 by Alessandro Scotti
\r
6 ;-----------------------------------------------------------
\r
10 PUBLIC mxColorToGray
\r
12 MX_TEXT SEGMENT USE16 PARA PUBLIC 'CODE'
\r
13 ASSUME cs:MX_TEXT, ds:NOTHING, es:NOTHING
\r
15 ;-----------------------------------------------------------
\r
17 ; Converts RGB colors to gray shades.
\r
20 ; CPal = pointer to color palette
\r
21 ; GPal = pointer to destination (gray) palette
\r
22 ; Count = number of colors to convert
\r
26 ; Note: CPal and GPal may point to the same buffer.
\r
28 mxColorToGray PROC FAR
\r
31 SPal:DWORD = ARG_SIZE
\r
34 .push ds, si, es, di
\r
41 ; We use the standard formula
\r
42 ; gray=(red*30 + green*59 + blue*11)/100
\r
43 ; in the equivalent form
\r
44 ; gray=(red*77 + green*151 + blue*28)/256
\r
45 ; which doesn't need the last divide.
\r
46 mov bx, 77 SHL 8 + 151
\r
59 stosw ; Save new RGB
\r