To some extent, yes, but you will lose quality and the color may be a different shade from the original base color.
For 32-bit colors, a component ranges between 0 and 255. For the 16-bit colors, a component ranges from 0 to 31. So first you need to convert the 32bit color to the smaller range.
r0 r1
--- = --
255 31
r1 = (r0*31)/255
You would do that conversion for each channel; red, green, blue.
Assuming the 16-bit color is stored into a Word in this manner: ARRRRRGGGGGBBBBB
Apply some bitwise math:
color16 = 32768 + b1 + (g1 << 15) + (r1 << 10)
I'll have to reboot back into XP to double check my math in DB, hopefully I'm not too far off. The reason for adding 32768 is to set the 16th bit to 1, which is the alpha channel.
Ok, I'm back. Hey my math worked! Here's an example:
Rem define 32-bit color
color32 as dword
color32 = rgb(117, 190, 88)
r0 = rgbr(color32)
g0 = rgbg(color32)
b0 = rgbb(color32)
Rem calculate 16-bit color
r1 = (r0*31)/255
g1 = (g0*31)/255
b1 = (b0*31)/255
color16 as word
color16 = 32768 + b1 + (g1 << 5) + (r1 << 10)
Rem display binary form of both colors
printBinary(color32)
print r0, ", ", g0, ", ", b0
print
printBinary(color16)
print r1, ", ", g1, ", ", b1
wait key
end
function printBinary(x)
b$ = right$(bin$(x), 32)
b1$ = left$(b$, 8)
b2$ = right$(left$(b$, 16), 8)
b3$ = right$(left$(b$, 24), 8)
b4$ = right$(b$, 8)
print b1$, " ", b2$, " ", b3$, " ", b4$
endfunction