Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There are two types of color mixing: Additive and Subtractive.

Is is possible that color mixing model be done in XOR?

share|improve this question

closed as unclear what you're asking by MichaelT, Robert Harvey, Greg Hewgill, ChrisF Dec 7 '13 at 13:46

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

Quick answer: There is bilinear color mixing. This is applied on each individual channel C = { R, G or B }, one at a time. Let C1 be the value from first input, range from 0.0 to 1.0; C2 be from the second input. Let f00, f01, f10, f11 be four weights. These weights must be non-negative, and must add up to 1.0. Then, Cmix = f00 + f01 * C1 + f10 * C2 + f11 * C1 * C2 gives the bilinear mix of the color C1 and C2. Not posting as answer because I won't be giving any citation or sources for it. – rwong Sep 15 '13 at 5:09
@est: if you like, you can call any kind of function a "mixing function" if it takes two color values, does some mathematical operation on it and returns a new color. But for what purpose? The operation should make some sense - just applying an operator like XOR because "it's there" does not seem very meaningful to me. – Doc Brown Sep 15 '13 at 7:35
up vote 6 down vote accepted

Not exactly. Additive and subtractive colour models are based on continuous physical phenomena, while XOR is a discrete operation lacking a real-world optical counterpart.

Subtractive colour models are based on mixing of pigments, which absorb certain frequencies of light and reflect others—red paint, for example, absorbs non-red frequencies from white (full-spectrum) light and thus reflects red hues. Additive colour models are based on mixing of light frequencies, as with a computer monitor.

The key thing to understand, though, is that additive and subtractive don’t refer to addition and subtraction in the algebraic sense, but rather in the frequency-response sense, which is more akin to audio mixing.

share|improve this answer
add/sub could make some algebraic sense. E.g. in RGB red+green= yellow, green+blue=cyan, but how about yellow+cyan? – est Sep 15 '13 at 8:14
@est: Yes, you can think of colour addition as (usu. clamped) vector addition in a particular colour space. However, colour spaces are best approximations of particular aspects of colour, such as monitor gamuts (RGB), printing inks (CMYK), and human perception (LAB), as well as various overlaps of these (sRGB, HSV, HSL). It’s not a simple issue! – Jon Purdy Sep 15 '13 at 8:25

Additive and subtractive mixing can be defined in terms of formulas that approximate certain real-world properties (mixing of coloured light, mixing of paint, application of successive coloured filters etc.)

XOR doesn't really make sense in this context, for two reasons:

  • XOR works with binary values, 1 and 0 (or true and false). It isn't normally defined on continuous values, which is what you need if you are dealing with colour spaces
  • What real world property are you trying to model? To my knowledge, there is nothing in nature that displays XOR-like colour mixing behaviour.

You could, of course, define an artificial mixing function that exhibits XOR-like behaviour at extreme values (0.0 and 1.0) and does something else in between. You might even get some interesting visual effects. But it's not a standard technique.

share|improve this answer
Not only binary, XOR could be applied to integer values. We don't process color as continuous on computers, they are all digital (like 0-255). – est Sep 15 '13 at 8:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.