# Where Can I Find Blend Mode Math Accurate to Photoshop?

Most results from Google offer equations/formulas for blend modes that aren't reproducible in Photoshop, especially those that involve division such as Color Burn and Color Dodge. For example, RGB(255,0,0) with Color Burn over RGB (0,0,255) is supposed to yield RGB(0,0,0) according to this website, but in fact it yields RGB(0,0,255). The only place where I've found accurate formulas is this Gimp website, but it lacks a lot of blend modes.

Where can I find blend mode formulas that are accurate for Photoshop?

Some of the blending modes can be found as a part of PDF specification. Check this : https://printtechnologies.org/wp-content/uploads/2020/03/pdf-reference-1.6-addendum-blend-modes.pdf

All calculation formulas seem to be absent in Photoshop's user quides. I guess you need an in-group contact to get exact blending equations or you must reverse engineer Adobe's program code. That is probably forbidden in the usage license.

Nothing quarantees Photoshop uses PDF blending modes exactly. Color burn seems to test in the beginning if the backdrop has R,G or B =255 and in that case the result is 255. If the backdrop has 0...254, then the PDF calculation seems to be used in Photoshop, too.

BTW. This has been wondered a long time. You are not the first one. See this older case. I copied the guessed explanation from there after trying it:

Why is color burn not affecting a white channel?

In color dodge there seems to be in the beginning a test if there's R, G or B =0 in the backdrop. In that case the result is 0, otherwise It's calculated with PDF formula

• Even that one fails to accurately describe Color Burn and Color Dodge. I don't get it at all. Jun 29, 2019 at 21:34
• @Vun-HughVaw dont remember where i saw it but burn formula is off by the 0 divide theres a fixed formula somewhere floating around Jun 30, 2019 at 19:58
• @joojaa both of the problematic blendings have a division + an "if" rule to avoid division by zero. I presented a couple of "enhancements" i.e. new if-rules in Photoshop which seem to be inserted to define differently the result when the division alone would be 0/0 Jun 30, 2019 at 21:00
• According to the Gimp page, the pure 0-1 algorithms don't always correspond 0-255 values which are neatly integers. So there are measures to prevent division by 0, for example by adding 1 to the denominator and using the factor 255+1=256 instead of 255. It's not as simple as clipping back to 0 if the denominator is 0 as those 0-1 algorithms suggest. Jul 1, 2019 at 7:39
• So for the "Color Burn" mode for example, `if foreground == 0 and background == 255 then result = 0` is wrong. It's actually `if foreground == 0 and background == 255 then result = 255 - 256*(255 - 255)/(0 + 1) = 255` Jul 1, 2019 at 7:47

You can find some of them here (code by ben): https://www.shadertoy.com/view/XdS3RW

Keep in mind, however, that it's a very common problem that does not have a perfect known solution (at least to my knowledge). Most of the time you can approximate what PS does, but every now and then there's a subtle difference that no one just knows what's happening.

One of pain points that I noticed is that a lot of PS tools are not sRGB-correct even if you do enable sRGB in options. So if you're trying to reverse-engineer something in adobe's products (same thing for Illustrator), and something does not exactly match, try disabling sRGB correction for some intermediate values, which's incredibly dirty/incorrect, but it's the way it seems to work internally in PS.

Consider for a moment the blending of just the blue pixel in your example, and how programs like Photoshop and GIMP treat it as a real map from [0,1] -> [0,1].

Let a be the top layer and b, the bottom. Then if you examine the plot of color burn c:(a,b) -> 1-((1-b)/a) considered without the [0,1] truncation, you can more easily see the discontinuity at (0,1), depicted below: The line c:(a,1) -> 1-((1-1)/a) = 1 has a removable discontinuity at a = 0. If you approach (0,1) along any other line, there's no removable discontinuity.

So, at least there's a logic to setting (0,1) to 1 and thus defining Color Burn as you see it in Photoshop.