Or this:This is in case you need the complementary of the light color palette. If you need the complementary for the ink color palette then I think you should use CMYK (Cyan Magenta Yellow and Ink) colors, and I don't know well how to use them since I'd never programed using that palette.
function ComplementaryColor(AColor: TColor): TColor; begin Result := clWhite - ColorToRGB(AColor); end;
bby the way, your complementary color algorithm is correct.In this case you should use circular's routine (reply #3), it is much more efficient and does exactly the same.
You can probably use a cast a mask and the not operator?
You can probably use a cast a mask and the not operator? Should be faster than subtraction. It does a bit-wise negation.I was worried by that in the past but in practice it made no difference. Subtracting is not so complicated, for example if you compare that to multiplication.
The main thing, is that I didn't understand that ( déjà vu ):Yep.
To call or not to call SwapRedBlue depends from my material context, and the purpose of this call:
- depending on the CPU processor type (Motorola versus Intel), I will write - in a file - AColor's RGB in that order ie RGB; or inversed ie BGR (cross-compilation problems are not yet fully in my head).
- depending on the logic of use: let's say I found a pretty #aabbcc color on a website, i.e. a hexdecimal representation in @string format ==> it means that Red='#aa', Green='#bb', and Blue='#cc'. If you want to assign this same compiled color, then $aabbcc to a Canvas property, it will not work: indeed, the binary bits are read from right to left (as @circular pointed out). So, the compiled equivalent will have to be: Red=$cc, Green=$bb Blue=$cc (lately, I've been developing with interpreted Javascript code).
PS: another simple manipulation of the bytes, to obtain 3 differents colors - which contrast with each other at most - is the "triadic color scheme": if color_base=aabbcc ==> triad_1=bbccaa, triad_2=ccaabb.Indeed.
Well, not or negation operates on only one register, subtraction on two.... On arm it makes a difference. That was my ratio.You can probably use a cast a mask and the not operator? Should be faster than subtraction. It does a bit-wise negation.I was worried by that in the past but in practice it made no difference. Subtracting is not so complicated, for example if you compare that to multiplication.
PS: another simple manipulation of the bytes, to obtain 3 differents colors - which contrast with each other at most - is the "triadic color scheme": if color_base=aabbcc ==> triad_1=bbccaa, triad_2=ccaabb.In this algorithm, the original and modified colors will have no or little contrast when aa, bb and cc are equal or almost equal.
But the complementary and trid colors are the only 2 algorithms, to obtain colors by simple manipulations of R, G and B.Be careful with absolute statements ("the only 2 algorithms"). I know a third one, the result is less distracting than the multicolored ComplemantaryColor:
Well, not or negation operates on only one register, subtraction on two.... On arm it makes a difference. That was my ratio.Not sure how you could use only one register here as the not is applied to 3 bytes, not the highest byte.
But I never applied this on graphics, only on audio.
Not sure how you could use only one register here as the not is applied to 3 bytes, not the highest byte.
Processor registers are four (or eight) bytes long, so no problem, is there? I mean, the highest pixel format is 32 bit: it just fits in a 386 register.Sure but the not instruction cannot be applied on 3 bytes. To invert only part of the value, one could do a xor with a mask, but where does the mask come from? Either a register or an immediate value.
Sure but the not instruction cannot be applied on 3 bytes. To invert only part of the value, one could do a xor with a mask, but where does the mask come from? Either a register or an immediate value.Hence the mask on a 32 bit values, masking out the least significant byte.. You can also not the individual bytes of course, but that would be slower.
Hi,
I was using the Jedi's method JvgUtils.ComplementaryColor(AColor: TColor): TColor; , under Delphi.
Is there an equivalent in FPC or LCL packages?