1

Imagine we have two ARGB colors c1 and c2.

Is there any difference between 50% (alpha) c1 on background c2, vs 50% c2 on background c1?

Using the formula out = alpha * new + (1 - alpha) * old (from another thread), both would have the same result:

50% blue on 100% red = 0.5 * blue + (1 - 0.5) red = 0.5 * blue + 0.5 red
100% red on 50% blue = 0.5 * red + (1 - 0.5) blue = 0.5 * red + 0.5 blue
thus, 50% blue on 100% red = 100% red on 50% blue

However, Photoshop CS5 claims that "50% red on 100% blue" is #80007f and "50% blue on 100% red" is #7f0080.

Thus, I'm wondering is the above algorithm just for simple real-life approximations?

Is there another formula that gives us truer results? (Since Adobe is quite up-there in terms of graphics, I would think it quite unlikely that they have made such a simple rounding off error)

Community
  • 1
  • 1
Pacerier
  • 86,231
  • 106
  • 366
  • 634
  • 1
    Not really a programming question... – Oliver Charlesworth Mar 30 '13 at 11:15
  • @OliCharlesworth, the RGB colors used for displays do not exist in the real world. They are only related to computers. Should a programmer render 50% blue on 100% red the same as 50% red on 100% blue? – Pacerier Mar 30 '13 at 11:20
  • Why are you suprised by the outcome? A red background with a blue overlay is different from a blue background with a red overlay. The results would be the same if both had 50% transparancy for example. If blue is over red, then - based on transparancy - more red is showing if the opacity is lower. The other way around more blue would be showing. It's similar to using a white background with a blue or a red overlay. They do not look the same because their transparancy is both 50% ... – Joshua - Pendo Mar 30 '13 at 11:26
  • @PENDO, I calculated the outcome using the formula given by http://stackoverflow.com/a/746937/632951 – Pacerier Mar 30 '13 at 11:35
  • Given alpha is 255, while you are trying to divide it by 2, the rounding errors are imminent. Photoshop rounds overlay alpha down, and I expect "50% blue" color to be 0x7f0000ff, where first 7F bits correspond to alpha. – Vesper Mar 30 '13 at 11:37
  • 1
    Interesting, wasn't aware of that :). I deleted my answer. I stand corrected! :) – Joshua - Pendo Mar 30 '13 at 11:37
  • Are you sure of your data? You say it gives _#7f0000 for blue-on-red_, but that's just dark red, it doesn't have any blue on it. – Shahbaz Mar 30 '13 at 11:51
  • @Shahbaz, Yes you are right my eyes (font size) are playing tricks on me. Edited to #7f0080. – Pacerier Mar 30 '13 at 12:04

1 Answers1

3

50% c1 on c2 and 50% c2 on c1 should give the exact same color, as you have noticed by the very simply algorithm.

So mixing red (#ff0000) and blue (#0000ff) 50-50 should give you #7f007f. If you get #80007f it's close enough and the error could be due to some other reason, for example if your image is not in RGB mode but in HSL, or if photoshop chose to internally represent it with HSL.

Other errors could arouse from floating point calculations and rounding errors. Nevertheless, #80007f and #7f007f are pretty much the same, so if photoshop developers are aware of this imprecision, they probably chose to ignore it.

Shahbaz
  • 46,337
  • 19
  • 116
  • 182