Jump to content

Affinity Suite: Alpha transparency calculation


Recommended Posts

Hello everyone,

When we work in the Affinity suite and create an image with a single layer, alpha transparency modifies the perception of RGB colours in the software. But how do you calculate the equivalent colour without transparency? This is an important question, because not all software handles transparency in the same way, which can lead to differences in colour rendition.

Let's take a concrete example:

Suppose we have an image consisting solely of a rectangle with RGB colour (117, 120, 123) and alpha transparency of 70%. How can we determine the resulting colour if this transparency was not applied, in other words, the ‘flattened’ colour with no alpha transparency effect?

Happy creating!

6 cœurs, 12 processus - Windows 11 pro - 4K - DirectX 12 - Suite universelle Affinity (Affinity  Publisher, Affinity Designer, Affinity Photo).

Mais je vous le demande, peut-on imaginer une police sans sérifs ?

Link to comment
Share on other sites

I would try:

  1. Add a white Fill layer, or a white Rectangle, under your existing rectangle. Sample the resulting color of the top Rectangle.
    or
  2. In Document Setup (Designer, Publisher) or the Document menu (Photo), turn off Transparent Background. Sample the resulting color of the top Rectangle.

-- Walt
Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases
PC:
    Desktop:  Windows 11 Pro 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 

    Laptop:  Windows 11 Pro 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU.
    Laptop 2: Windows 11 Pro 24H2,  16GB memory, Snapdragon(R) X Elite - X1E80100 - Qualcomm(R) Oryon(TM) 12 Core CPU 4.01 GHz, Qualcomm(R) Adreno(TM) X1-85 GPU
iPad:  iPad Pro M1, 12.9": iPadOS 18.1, Apple Pencil 2, Magic Keyboard 
Mac:  2023 M2 MacBook Air 15", 16GB memory, macOS Sequoia 15.0.1

Link to comment
Share on other sites

6 minutes ago, walt.farrell said:

turn off Transparent Background. Sample the resulting color

Oh, it's that easy! Thanks!

macOS 10.14.6 | MacBookPro Retina 15" | Eizo 27" | Affinity V1

Link to comment
Share on other sites

You're welcome, thomaso.

-- Walt
Designer, Photo, and Publisher V1 and V2 at latest retail and beta releases
PC:
    Desktop:  Windows 11 Pro 23H2, 64GB memory, AMD Ryzen 9 5900 12-Core @ 3.00 GHz, NVIDIA GeForce RTX 3090 

    Laptop:  Windows 11 Pro 23H2, 32GB memory, Intel Core i7-10750H @ 2.60GHz, Intel UHD Graphics Comet Lake GT2 and NVIDIA GeForce RTX 3070 Laptop GPU.
    Laptop 2: Windows 11 Pro 24H2,  16GB memory, Snapdragon(R) X Elite - X1E80100 - Qualcomm(R) Oryon(TM) 12 Core CPU 4.01 GHz, Qualcomm(R) Adreno(TM) X1-85 GPU
iPad:  iPad Pro M1, 12.9": iPadOS 18.1, Apple Pencil 2, Magic Keyboard 
Mac:  2023 M2 MacBook Air 15", 16GB memory, macOS Sequoia 15.0.1

Link to comment
Share on other sites

47 minutes ago, lacerto said:

---and more generally, not assuming white as the bottom layer, for each channel: 

A*(UPPER-LOWER)+LOWER

...proceeding in z-order from the bottom to the top (flattening two layers at a time). For absolute transparency flattening, the bottom layer is always white (and if there is no color, the flattened channel value is a tint).

Perhaps someone more mathematically oriented forum member can put the formula in more elegant form. 

the formula is only valid for gamma=1, which is used for RGB/32.

All other formats normally use gamma 2.2.

For layers, the gamma value can be changed in layer blend ranges - normally nobody does this.

Test layers use gamma=1.45 by default, so layer blending can differ for text and other layers (visible when layer opacity is not 100%. For a test, use a text layer and rectangle, both 50% opacity, each covering a different part, but touching at the edges. blend color will differ.)

 

for more details seee

https://en.wikipedia.org/wiki/Alpha_compositing

 

Mac mini M1 A2348 | Windows 10 - AMD Ryzen 9 5900x - 32 GB RAM - Nvidia GTX 1080

LG34WK950U-W, calibrated to DCI-P3 with LG Calibration Studio / Spider 5

iPad Air Gen 5 (2022) A2589

Special interest into procedural texture filter, edit alpha channel, RGB/16 and RGB/32 color formats, stacking, finding root causes for misbehaving files, finding creative solutions for unsolvable tasks, finding bugs in Apps.

My posts focus on technical aspects and leave out most of social grease like „maybe“, „in my opinion“, „I might be wrong“ etc. just add copy/paste all these softeners from this signature to make reading more comfortable for you. Otherwise I’m a fine person which respects you and everyone and wants to be respected.

 

Link to comment
Share on other sites

4 hours ago, Pyanepsion said:

Hello everyone,

When we work in the Affinity suite and create an image with a single layer, alpha transparency modifies the perception of RGB colours in the software. But how do you calculate the equivalent colour without transparency? This is an important question, because not all software handles transparency in the same way, which can lead to differences in colour rendition.

Let's take a concrete example:

Suppose we have an image consisting solely of a rectangle with RGB colour (117, 120, 123) and alpha transparency of 70%. How can we determine the resulting colour if this transparency was not applied, in other words, the ‘flattened’ colour with no alpha transparency effect?

Happy creating!

The questions is not fully defined.

When you take this literally, the color within the layer is independent from the alpha channel, and stays constant RGB colour (117, 120, 123).

The "resulting" color depends on what is below the "single" layer - but when you only one layer, there is nothing below.

Affinity allows 2 options for an "inherent" Background:

  • white background: this is kind of cheating, as you have a virtual second layer in the file, conflicting with the setting of "one single layer". If you ignore, you get the layer blending of a white background with your top layer. depending on the gamma value of the top layer, default 2.2. If you play with the gamma value of the layer, the result will change strongly.
  • transparent background: then there is no "resulting", as the layer color is what you set, and alpha is irrelevant.

 

 

Mac mini M1 A2348 | Windows 10 - AMD Ryzen 9 5900x - 32 GB RAM - Nvidia GTX 1080

LG34WK950U-W, calibrated to DCI-P3 with LG Calibration Studio / Spider 5

iPad Air Gen 5 (2022) A2589

Special interest into procedural texture filter, edit alpha channel, RGB/16 and RGB/32 color formats, stacking, finding root causes for misbehaving files, finding creative solutions for unsolvable tasks, finding bugs in Apps.

My posts focus on technical aspects and leave out most of social grease like „maybe“, „in my opinion“, „I might be wrong“ etc. just add copy/paste all these softeners from this signature to make reading more comfortable for you. Otherwise I’m a fine person which respects you and everyone and wants to be respected.

 

Link to comment
Share on other sites

11 hours ago, lacerto said:

this is basically just how transparency flattening is done in pragmatic terms within 8-bit color mode [Normal blend mode].

Sorry to say, that is not correct. You must consider gamma, otherwise you will get wrong results.

the correct formula is

(Blend mode normal is called “over”):

IMG_1009.thumb.jpeg.071c7011069ae7e30ce2055d1c5ab1b5.jpeg

PS: forgot to add the chapter about gamma correction which is a bit further down in the wiki

the important difference is the Greek letter gamma use as exponent

IMG_1730.thumb.jpeg.08aafacc039ef02f878099fc851039eb.jpeg

If you use color picker, you will see the same values in Photo, maybe off by 1 due to rounding.

Mac mini M1 A2348 | Windows 10 - AMD Ryzen 9 5900x - 32 GB RAM - Nvidia GTX 1080

LG34WK950U-W, calibrated to DCI-P3 with LG Calibration Studio / Spider 5

iPad Air Gen 5 (2022) A2589

Special interest into procedural texture filter, edit alpha channel, RGB/16 and RGB/32 color formats, stacking, finding root causes for misbehaving files, finding creative solutions for unsolvable tasks, finding bugs in Apps.

My posts focus on technical aspects and leave out most of social grease like „maybe“, „in my opinion“, „I might be wrong“ etc. just add copy/paste all these softeners from this signature to make reading more comfortable for you. Otherwise I’m a fine person which respects you and everyone and wants to be respected.

 

Link to comment
Share on other sites


 

The test file shows the impact of gamma. Both the text and the upper rectangle share the same global color 117/120/123, and use 70% opacity.

no matter if you use white or black background, the blendung results differs due to gamma 1.45 for text and 2.2 for all other layer types.

you cannot ignore gamma for semi-transparent layers, in RGB/8.

IMG_1012.png

IMG_1011.png

alpha blending.afphoto

Mac mini M1 A2348 | Windows 10 - AMD Ryzen 9 5900x - 32 GB RAM - Nvidia GTX 1080

LG34WK950U-W, calibrated to DCI-P3 with LG Calibration Studio / Spider 5

iPad Air Gen 5 (2022) A2589

Special interest into procedural texture filter, edit alpha channel, RGB/16 and RGB/32 color formats, stacking, finding root causes for misbehaving files, finding creative solutions for unsolvable tasks, finding bugs in Apps.

My posts focus on technical aspects and leave out most of social grease like „maybe“, „in my opinion“, „I might be wrong“ etc. just add copy/paste all these softeners from this signature to make reading more comfortable for you. Otherwise I’m a fine person which respects you and everyone and wants to be respected.

 

Link to comment
Share on other sites

5 minutes ago, lacerto said:

I think that OP and I were talking about transparency flattening, and if you try, you can see that the simplistic formula that I gave gives correct results both in 8-bit RGB and CMYK color modes within normal blend mode. For other blend modes, calculations are more complex, but for the question OP asked, the answer I gave should give an easily verifiable idea.

Again, no. The OP talked about 70% opacity, and there the simplistic formula gives wrong results. It only gives correct for 100% opacity.

i provided all evidence i could, the wikipedia article, a test file where you can reproduce, screenshots, … and step out for good.

Mac mini M1 A2348 | Windows 10 - AMD Ryzen 9 5900x - 32 GB RAM - Nvidia GTX 1080

LG34WK950U-W, calibrated to DCI-P3 with LG Calibration Studio / Spider 5

iPad Air Gen 5 (2022) A2589

Special interest into procedural texture filter, edit alpha channel, RGB/16 and RGB/32 color formats, stacking, finding root causes for misbehaving files, finding creative solutions for unsolvable tasks, finding bugs in Apps.

My posts focus on technical aspects and leave out most of social grease like „maybe“, „in my opinion“, „I might be wrong“ etc. just add copy/paste all these softeners from this signature to make reading more comfortable for you. Otherwise I’m a fine person which respects you and everyone and wants to be respected.

 

Link to comment
Share on other sites

Posted (edited)

My aim is to obtain a precise calculated result. The colour differences are not very distinct from the grey I used previously, so I'm changing to a blue-green to illustrate the calculation more clearly.

According to Wikipedia, the formula for obtaining the resulting colour from two objects a and b is as follows:

Cr = ((Ca αa + Cb αb (1- αa))/(αa + αb (1 - αa))


In our case:

α = 70 %
Initial colour: (R 66, G 152, B 181)
Background colour (White): (R 255, G 255, B 255)


According to this formula, we should obtain:

Resulting colour: (R 88, G 189, B 189)


However, we can see that the result obtained is different from this expected value.

transparency.thumb.png.d6c8478f0a6eff14c2b2ff3f6a854e2c.png

 

 

 

transparency.xlsx transparency.afdesign

Edited by Pyanepsion
Error on files.

6 cœurs, 12 processus - Windows 11 pro - 4K - DirectX 12 - Suite universelle Affinity (Affinity  Publisher, Affinity Designer, Affinity Photo).

Mais je vous le demande, peut-on imaginer une police sans sérifs ?

Link to comment
Share on other sites

1 hour ago, Pyanepsion said:

My aim is to obtain a precise calculated result. The colour differences are not very distinct from the grey I used previously, so I'm changing to a blue-green to illustrate the calculation more clearly.

According to Wikipedia, the formula for obtaining the resulting colour from two objects a and b is as follows:

Cr = ((Ca αa + Cb αb (1- αa))/(αa + αb (1 - αa))


In our case:

α = 70 %
Initial colour: (R 66, G 152, B 181)
Background colour (White): (R 255, G 255, B 255)


According to this formula, we should obtain:

Resulting colour: (R 88, G 189, B 189)


However, we can see that the result obtained is different from this expected value.

transparency.thumb.png.d6c8478f0a6eff14c2b2ff3f6a854e2c.png

 

 

 

transparency.xlsx 10.19 kB · 0 downloads transparency.afdesign

You need to add the gamma conversion. I edited my older post. The correct formulas are

IMG_1730.thumb.jpeg.08aafacc039ef02f878099fc851039eb.jpeg

Mac mini M1 A2348 | Windows 10 - AMD Ryzen 9 5900x - 32 GB RAM - Nvidia GTX 1080

LG34WK950U-W, calibrated to DCI-P3 with LG Calibration Studio / Spider 5

iPad Air Gen 5 (2022) A2589

Special interest into procedural texture filter, edit alpha channel, RGB/16 and RGB/32 color formats, stacking, finding root causes for misbehaving files, finding creative solutions for unsolvable tasks, finding bugs in Apps.

My posts focus on technical aspects and leave out most of social grease like „maybe“, „in my opinion“, „I might be wrong“ etc. just add copy/paste all these softeners from this signature to make reading more comfortable for you. Otherwise I’m a fine person which respects you and everyone and wants to be respected.

 

Link to comment
Share on other sites

Actually, Wikipedia might be slightly off wrt gamma.

some software uses a linear section for values near 0. I assume most apps ignore this detail, as the difference is probably barely noticeable or even get truncated due to rounding in RBG/8.

https://en.wikipedia.org/wiki/Gamma_correction
 

The sRGB color space standard used with most cameras, PCs, and printers does not use a simple power-law nonlinearity as above, but has a decoding gamma value near 2.2 over much of its range, as shown in the plot to the right/above. Below a compressed value of 0.04045 or a linear intensity of 0.00313, the curve is linear (encoded value proportional to intensity), so γ = 1. The dashed black curve behind the red curve is a standard γ = 2.2power-law curve, for comparison.

Mac mini M1 A2348 | Windows 10 - AMD Ryzen 9 5900x - 32 GB RAM - Nvidia GTX 1080

LG34WK950U-W, calibrated to DCI-P3 with LG Calibration Studio / Spider 5

iPad Air Gen 5 (2022) A2589

Special interest into procedural texture filter, edit alpha channel, RGB/16 and RGB/32 color formats, stacking, finding root causes for misbehaving files, finding creative solutions for unsolvable tasks, finding bugs in Apps.

My posts focus on technical aspects and leave out most of social grease like „maybe“, „in my opinion“, „I might be wrong“ etc. just add copy/paste all these softeners from this signature to make reading more comfortable for you. Otherwise I’m a fine person which respects you and everyone and wants to be respected.

 

Link to comment
Share on other sites

2 hours ago, lacerto said:

where I now disabled it so that regular (consistent) transparency flattening is now applied for text in all Adobe apps, at least.

You can do that, but there are good reasons why text uses 1.45 gamma by default.

Text rendering of small fonts gets ugly and unreadable when rasterized.

i just found a blog explaining the importance of gamma excellently:

https://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/

 

Mac mini M1 A2348 | Windows 10 - AMD Ryzen 9 5900x - 32 GB RAM - Nvidia GTX 1080

LG34WK950U-W, calibrated to DCI-P3 with LG Calibration Studio / Spider 5

iPad Air Gen 5 (2022) A2589

Special interest into procedural texture filter, edit alpha channel, RGB/16 and RGB/32 color formats, stacking, finding root causes for misbehaving files, finding creative solutions for unsolvable tasks, finding bugs in Apps.

My posts focus on technical aspects and leave out most of social grease like „maybe“, „in my opinion“, „I might be wrong“ etc. just add copy/paste all these softeners from this signature to make reading more comfortable for you. Otherwise I’m a fine person which respects you and everyone and wants to be respected.

 

Link to comment
Share on other sites

6 hours ago, NotMyFault said:

You need to add the gamma conversion. I edited my older post. The correct formulas are

I don't quite understand the explanations, or at least I can't get the result I was hoping for: to get the same look with 70% blue-green and another 100% colour obtained by calculation. Could you correct this formula?

(See previous Excel and Affinity Designer files).

Cr = ((Ca αa + Cb αb (1- αa))/(αa + αb (1 - αa))

6 cœurs, 12 processus - Windows 11 pro - 4K - DirectX 12 - Suite universelle Affinity (Affinity  Publisher, Affinity Designer, Affinity Photo).

Mais je vous le demande, peut-on imaginer une police sans sérifs ?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.