Jump to content
You must now use your email address to sign in [click for more info] ×

How to blend in RGB and export in sRGB?


Recommended Posts

I made a simple 16x16 pixel file with a black vector triangle.

image.png.5a1c90a44952ce0cf3e80fd186e6414e.png

I export this to PNG using the default settings, and inspect the result in MS Paint.

image.png.50ffca66d381635f6fcdfa17f7a91cdb.png

The channel values of the center diagonal of grey pixels are 127, revealing that either the document has been saved in linear RGB or colors have been blended in sRGB color space.

This matches what is visible while viewing and editing the project within Affinity Designer with "Pixel View mode" enabled:

image.png.33a242b86ade873d8cfa588a59b66478.png

I want color information to be saved in sRGB.

More precisely, I want all color blending operations to happen in linear RGB, and color display and export to happen in sRGB.

Embedding the correct color profile into the file is not sufficient, as converting every channel to byte is already a highly lossy operation.

How can I achieve this?

 

Edited by Zyl
Link to comment
Share on other sites

For comparison, the following is the result of the same in Photoshop with blending using gamma enabled:

image.png.8edeac7f7245b03485fd59a93915d53a.png

Each channel assumes a value of 188, which is the nearest sRGB representation for a pixel with 50% white and 50% black coverage in byte-encoding.

image.png.1a4f8c513b14982d3a7a0962eac27059.png

Link to comment
Share on other sites

A quite good explanation for linear RGB vs sRGB can be found in the answers here. - AFAI recall tools like Maya do allow a linear workflow here. Basically linear RGB vs sRGB is nearly Gamma 1.0 vs Gamma 2.2, see also the following about brightness subpixel transformation here.

☛ Affinity Designer 1.10.8 ◆ Affinity Photo 1.10.8 ◆ Affinity Publisher 1.10.8 ◆ OSX El Capitan
☛ Affinity V2.3 apps ◆ MacOS Sonoma 14.2 ◆ iPad OS 17.2

Link to comment
Share on other sites

Here is a comparison which makes the advantage of blending in linear RGB quite apparent.

Affinity:

image.png.ad12505f8ca575fb600f9c3d64496033.png

Photoshop:

image.png.2d00d807e39bc4b9a7bc2f205b2aabef.png

In case you have a high DPI display, I follow up with the same but at 2x resolution, with nearest neighbor interpolation.

Affinity:

image.png.2cc9a065a9f79e3b94f6fd73ee5958ab.png

Photoshop:

image.png.eb8e65954bfbb71640593be1db7e2264.png

The keen eye will be able to tell that the edges of the shape are more jagged in Affinity Designer's output. The cause of this outcome is purely mathematical. Blending in sRGB violates conservation of energy.

Link to comment
Share on other sites

  • Staff
On 9/23/2020 at 7:20 PM, Zyl said:

I want color information to be saved in sRGB.

More precisely, I want all color blending operations to happen in linear RGB, and color display and export to happen in sRGB.

Embedding the correct color profile into the file is not sufficient, as converting every channel to byte is already a highly lossy operation.

How can I achieve this?

Apologies if I’ve misunderstood this, but couldn’t you just use 32-bit format for your document? 32-bit in all the apps uses linear compositing but has a gamma-corrected view transform applied non-destructively so the document view looks consistent with the exported result (as you would typically export to a non-linear format with gamma encoded values). You can toggle this behaviour on the 32-bit preview panel if you need the linear unmanaged view (or an OpenColorIO transform) but it defaults to ICC Display Transform which is the exact workflow you describe: all colour blending operations happen in linear space, with a final view transform to non-linear space.

If you wanted linear compositing within a non-linear RGB document format (so 8-bit or 16-bit), you could approximate this by using two live Procedural Texture layers: one underneath the layers you wish to blend in linear space, and one above. The one beneath you would create equation fields for each channel and transform the channel value by 2.2 (e.g. R^2.2), then the one above you would transform by the reciprocal power value, so R^0.454 etc. Just an approximation, but perhaps close enough for your needs?
 

I’ve attached some screen grabs: I exported two 16x16 images with a black triangle—one composited in 32-bit, one in 16-bit. To visualise them, I loaded them back into Photo and screen grabbed the resulting document views:

588C4769-DF6F-416A-AE27-4C188EE953FE.png4577A44F-A242-48EF-80FF-6E5EF8F273A0.png
 

Finally, here is a 16-bit non-linear sRGB document using the live Procedural Texture technique I mentioned above:

82430579-B750-458D-8AC6-6B91D91330C1.png


Hope that helps!

Product Expert (Affinity Photo) & Product Expert Team Leader

@JamesR_Affinity for tutorial sneak peeks and more
Official Affinity Photo tutorials

Link to comment
Share on other sites

Thanks for the detailed response. Unfortunately, I cannot reproduce the behavior you describe.

Here is what I do:

image.png.8c82d7993b3499083ba9183ac8c741ad.png

image.png.4844c6bf50bfef73e031a3f446f10edb.png

image.png.3d9034fa7042dc834f37113e91ac17ed.png

It's still blended in sRGB, even after export, despite having chosen 32 bit color format as you advised. What is wrong?

Link to comment
Share on other sites

1 hour ago, Zyl said:

Thanks for the detailed response. Unfortunately, I cannot reproduce the behavior you describe.

Here is what I do:

image.png.8c82d7993b3499083ba9183ac8c741ad.png

image.png.4844c6bf50bfef73e031a3f446f10edb.png

image.png.3d9034fa7042dc834f37113e91ac17ed.png

It's still blended in sRGB, even after export, despite having chosen 32 bit color format as you advised. What is wrong?

 

I suspect you did not have a white object as the background in the linear 32 bpc Affinity document. 
In the Affinity view of the linear document, the matting of the anti-aliased black object against the canvas white would have been done in the linear colour space. 
However, when exporting to a gamma encoded 8 or 16 bpc file, the anti-aliased black object will have been matted against white in the gamma encoded colour space of the export. 
To get the export result that you want, you need to use an actual white object as the background, not empty canvas.

By the way, the blend options for an object (click the cog wheel at top-right of Layers panel) allow you to specify linear blending for that object when working in the gamma-encoded colour space of an 8 or 16 bpc document. It doesn't work correctly for everything, but it will for your example. Remember to use an actual white background, not empty canvas, though.

 

Link to comment
Share on other sites

2 hours ago, anon2 said:

I suspect you did not have a white object as the background

Yep, that was it. I have to admit though I don't really understand why the background is subject to special treatment like so.

Quote

By the way, the blend options for an object (click the cog wheel at top-right of Layers panel) allow you to specify linear blending for that object when working in the gamma-encoded colour space of an 8 or 16 bpc document.

This is good to know!

I'm not really sure what are some use cases to want to blend in sRGB specifically. I imagine an overwhelming amount of hobbyists, and even some professionals, aren't even aware that getting this wrong can negatively affect their results. Even if they notice pixelated lines or such, they might just shrug it off as consequence of too low DPI, not knowing that something can be done about it. As a hobbyist, I can only attest to having learned about it by chance, and that thus I strongly feel that defaulting to anything other than blending in linear RGB is undesirable.

Anyways, I got everything indistinguishably close to what Photoshop produces (the exact values are off by up to 2 in the 8 bit export, but that doesn't matter) and it's looking good, so I call this a closed case. Thanks, all!

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.