2762 Commits

Author SHA1 Message Date
Aras Pranckevicius
facb17b0e3 Cleanup: BLI ENUM_OPERATORS cleanup/robustness
BLI code for enums that are meant to be used as "bit flags" defined
an ENUM_OPERATORS macro in BLI_utildefines.h. This cleans up things
related to said macro:

- Move it out into a separate BLI_enum_flags.hh header, instead of
  "random bag of things" that is the current place,
- Update it to no longer need manual indication of highest individual
  bit value. This originally was added in a31a87f89 (2020 Oct), in
  order to silence some UBSan warnings that were coming
  from GPU related structures (looking at current GPU code, I don't
  think this is happening anymore). However, that caused actual
  user-visible bugs due to incorrectly specified max. enum bit value,
  and today 14% of all usages have incorrect highest individual
  bit value spelled out.
    - I have reviewed all usages of operator ~ and none of them are
      used for directly producing a DNA-serialized value; all the
      usages are for masking out other bits for which the new ~
      behavior that just flips all bits is fine.
- Make the macro define flag_is_set() function to ease check of bits
  that are set in C++ enum class cases; update existing cases to use
  that instead of three other ways that were used.

Pull Request: https://projects.blender.org/blender/blender/pulls/148230
2025-10-17 12:57:50 +02:00
Campbell Barton
649a909206 Merge branch 'blender-v5.0-release' 2025-10-15 09:43:57 +11:00
Jorn Visser
b3ba6465f4 Fix #139387: Crash reading invalid images from network drives on WIN32
Improve mmap handling of IO errors on WIN32.

Make MMAP gracefully handle IO errors on Windows by replacing the
mapping with zeros using a vectored exception handler when an
EXCEPTION_IN_PAGE_ERROR is raised. This is similar to how such errors
are handled on non-Windows platforms.

On Windows, this is implemented by first creating a placeholder
allocation and then mapping the file into it. When an error occurs, the
exception handler unmaps the file, keeping the placeholder intact, and
creates an anonymous mapping into it, after which execution can
continue.

Since some required functions don't exist on older Windows versions,
the error handling will only work on Windows 10, version 1803 or newer.

Ref !139739
2025-10-14 22:38:10 +00:00
Aras Pranckevicius
72ffd4e0a1 Merge branch 'blender-v5.0-release' 2025-10-13 09:53:37 +03:00
Aras Pranckevicius
218317b8b9 Fix #147381: VSE preview shows incorrect transparency for masks
Since VSE HDR preview was implemented (18110744a2), the preview image
is put into RGBA 16F format "color texture", and the overlay
(checkerboard, grids etc.) is put into RGBA 8U format "overlay texture".
This was rendering the color image as NON premultiplied alpha in
the viewport color texture, which is not what happens in other places
(e.g. image space).

Later commit (c279d894db) fixed transparency of the overlay texture,
in order to make pure emissive (color non zero, alpha zero) colors
from EXR files show up in VSE preview. However that exposed the issue
that underlying color texture is not premultiplied.

Fix this by premultiplying the output color in gpu_shader_display_transform
that is used by VSE preview. This is done at the end of the shader
isntead of using fixed function blending, since premultiplication needs
to happen in a way that preserves pure-emissive colors.

Comparison images in the PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/147892
2025-10-13 08:52:33 +02:00
Campbell Barton
ffa750fd5e Cleanup: use doxygen style doc-strings for IMB 2025-10-12 01:12:52 +00:00
Falk David
f694ef839d Cleanup: VSE: Rename for_each_callback to foreach_strip
The function name `for_each_callback` is ambigous (what are we iterating?)
and also doesn't align with the naming of other "for each" functions in Blender
which usually are named `foreach_<thing>` like `IndexMask::foreach_index`
or `animrig::foreach_fcurve_in_action` etc.

Pull Request: https://projects.blender.org/blender/blender/pulls/147440
2025-10-06 14:02:32 +02:00
Hans Goudey
a68d39e9d9 Cleanup: Formatting
Run `make format` after the library update in the previous commit.
2025-10-02 12:55:42 -04:00
Brecht Van Lommel
e238970bd9 Color Management: Update for new extended sRGB naming conventions in OCIO
Recognize srgbe_ prefix for interop ID, and edr-video encoding as HDR.

Pull Request: https://projects.blender.org/blender/blender/pulls/147205
2025-10-02 17:20:35 +02:00
Campbell Barton
b78c5fadf3 Cleanup: various non functional changes for C++ 2025-10-01 23:22:44 +00:00
Brecht Van Lommel
b168a96083 Refactor: Use enum class instead of bool video
Pull Request: https://projects.blender.org/blender/blender/pulls/146888
2025-09-29 19:01:39 +02:00
Brecht Van Lommel
df12a448ba Color Management: Save and load HDR images with 203 nits
Based on extensive testing, this gives matching HDR brighness across most
application, with both PNG and AVIF. Video remains at 100 nits as that
appears to tbe convention there.

This is implemented by adding two modified PQ and HLG color spaces to the
OCIO config on startup, and for the specific cases of image save and loaded
these will replace the regular PQ and HLG color spaces.

This was chosen rather than adding them as color spaces in the OCIO config,
so that it can work for any config with appropriate interop IDs, including
the ACES config. Additionally, it would be unclear how to make this work with
view + display transforms, we wouldn't want to burden the users with having
to pick a different display depending if they are saving images or video.

Ref #145855, #144911

Pull Request: https://projects.blender.org/blender/blender/pulls/146888
2025-09-29 19:01:33 +02:00
Brecht Van Lommel
fff8d35e3f Color Management: Add option to control display emulation
In Render properties > Color Management > Display.

* Off: Directly output image as produced by OpenColorIO. This is not correct
  in general, but may be used when the system configuration and actual display
  device is known to match the chosen display.
* Automatic: Display images consistent with most other applications, to preview
  images and video for export. A best effort is made to emulate the chosen
  display on the actual display device.

The option is grayed out when the current OpenColorIO config and display/view
does not support emulation.

Ref #145022, #144911

Pull Request: https://projects.blender.org/blender/blender/pulls/146808
2025-09-26 17:05:18 +02:00
Campbell Barton
9ebc02fc99 Cleanup: spelling, repeated words (make check_spelling_*) 2025-09-26 22:00:27 +10:00
Brecht Van Lommel
e91c8300a6 OpenEXR: Write colorspace metadata for multilayer EXR
Previously it was only working for the single layer case. For multipart
we write the colorspace in each part. For single part we write the first
non-data colorspace, and hope data passes will be identified based on channel
name like Blender does (e.g. XYZ instead of RGB).

Reading is unchanged and still the same as before, in that it only reads the
colorspace from the first part. There is only one color space per image
datablock, so we can not store anything more currently. In practice it
would be unusual for all passes in a file not to either have the same
colorspace or be data.

All the compositor file output test images were updated to include the
metadata, so that the test will check if the metadata is there.

Ref #144911

Pull Request: https://projects.blender.org/blender/blender/pulls/146809
2025-09-25 23:27:14 +02:00
Brecht Van Lommel
be1619f4ad OpenEXR: Multi-part writing
New "Interleave" option in image format settings, enabled by default in old
files and disabled by default in new files to write multi-part files.

By not storing all channels interleaved, it is possible for other applications
to load individual passes more efficiently. This might also work better with
compression.

We follow the OpenEXR docs in that the channel name is the full
Layer.Pass.Channel rather than just Channel. Some other renderers
(e.g. Houdini Karma) write just the channel and that is what our reading
code assumed so far.

I've verified that Nuke can read the multipart EXR files produced by Blender,
including multiview and cryptomatte.

Fix #123727

Pull Request: https://projects.blender.org/blender/blender/pulls/146650
2025-09-25 22:58:11 +02:00
Brecht Van Lommel
9851e34c71 Refactor: OpenEXR: Simplify multi layer read and write implementation
* Read directly into ExrChannel, eliminate intermediate MultiViewChannelName
* Pass multiple channels to EXR writer together in IMB_exr_add_channels
* Avoid various channel name parsing by passing components separately
* Simplify logic for writing multichannel and multiview metadata
* Remove unused global EXR handle storage
* No longer use void pointer for EXR handle.
* Use blender::Vector and std::string.
* Slightly reshuffle code so multipart support will have smaller diff.
* Add various comments.

Pull Request: https://projects.blender.org/blender/blender/pulls/146650
2025-09-25 22:58:09 +02:00
Brecht Van Lommel
662dc95a50 OpenEXR: Support reading multipart files with full channel names
The reading code currently assumes that the part name may be for example
"ViewLayer.Combined" and then the channel within the part may be "R". For
example Houdini writes files like this.

However according to the docs the part name should be ignored and the
channel name in each part should be complete like "ViewLayer.Combined.R".
https://openexr.com/en/latest/MultiViewOpenEXR.html

To support both cases we now only prepend the part name if it's not already
there.

Pull Request: https://projects.blender.org/blender/blender/pulls/146650
2025-09-25 22:57:59 +02:00
Brecht Van Lommel
fd9edf5b89 Color Management: Support for HDR PNG read and write
### Color Management: Support image CICP read/write

The CICP support will enable reading and writing HDR PNGs, following
the recently released PNG spec:
https://www.w3.org/TR/png-3/#cICP-chunk

More useful for exporting to the web with reasonable file size would
be AVIF support, but that will have to wait for the next library update
in Blender 5.1 to add libheif.

Note this will only starting working once the 5.0 libraries have landed,
which should happen somewhere in the next week.

Pull Request: https://projects.blender.org/blender/blender/pulls/145612
2025-09-25 15:16:11 +02:00
Brecht Van Lommel
59eebc8654 Color Management: Add "Working Space" as a color space choice in the enum
And make it the default in the compositing Convert Color Space node. This is
useful to create compositing nodes that give the same result regardless of
the working space, particularly for node group assets. For example you might
convert from the working space to a log space, do some color correction
operations and convert back.

I'm less certain about including this also for images. I can imagine use
cases for that too, for example with an Image node in the compositor that is
known to read back the EXR sequence written from the current scene. But it's
a bit more obscure and there is some potential for using this when it's not
appropriate. Still there is nothing that automatically selects it, so it seems
fine.

Ref #144911

Pull Request: https://projects.blender.org/blender/blender/pulls/146598
2025-09-25 15:00:02 +02:00
Brecht Van Lommel
ca2a13991e Color Management: Reduce reliance on untonemapped view
No longer use it for display of images without View as Render, color swatches
and color picker, and 3D viewport in solid mode. Instead go directly to extended
sRGB matching the system graphics buffer.

We still use it for setting the image colorspace after Save as Render, and for
color value inspection in the image editor and tooltips.

Ref #144911

Pull Request: https://projects.blender.org/blender/blender/pulls/146487
2025-09-25 13:50:20 +02:00
Brecht Van Lommel
059a3f3568 Color Management: Log added displays, views and color spaces
Ref #144911

Pull Request: https://projects.blender.org/blender/blender/pulls/146487
2025-09-25 13:50:20 +02:00
Brecht Van Lommel
239706c6b9 Color Management: Perform display emulation using display colorspaces
Rather than relying on an untonemapped view, use the OpenColorIO v2
display color spaces. This provides a generic way of converting between
display referred color spaces using the cie_xyz_d65_interchange role
as the intermediate display linear space.

On older configs without such display color spaces, display emulation
will be disabled.

Ref #144911

Pull Request: https://projects.blender.org/blender/blender/pulls/146487
2025-09-25 13:50:20 +02:00
Clément Foucault
fe213f80a4 GPU: Shader: Make info files generated
This is the first step of moving the create infos
back inside shader sources.

All info files are now treated as source files.
However, they are not considered in the include tree
yet. This will come in another following PR.

Each shader source file now generate a `.info` file
containing only the create info declarations.

This renames all info files so that they do not
conflict with their previous versions that were
copied (non-generated).

Pull Request: https://projects.blender.org/blender/blender/pulls/146676
2025-09-25 10:57:02 +02:00
Jesse Yurkovich
12cdfb5856 Image: Log errors during image write when using OpenImageIO
Before this change, any accumulated errors from OpenImageIO would be
lost and a nonsensical use of `errno` would be used instead.

An example of the new error log:
```
00:23.188  image.write      | ERROR OpenImageIO write failed: sgi image resolution may not exceed 65535x65535, you asked for 65536x1
```

Pull Request: https://projects.blender.org/blender/blender/pulls/146554
2025-09-22 20:26:55 +02:00
Brecht Van Lommel
c857c9d4f5 Refactor: Move video CICP logic to be reusable for images
Ref #145612

Pull Request: https://projects.blender.org/blender/blender/pulls/146606
2025-09-22 19:20:42 +02:00
Brecht Van Lommel
acb6faf8eb Color Management: Better preserve views when switching between displays
Also match prefixes, so that switching between PQ and HLG keeps an
ACES view regardless of the HDR nits.

Pull Request: https://projects.blender.org/blender/blender/pulls/146504
2025-09-20 13:55:38 +02:00
Brecht Van Lommel
92a4aee3f9 Fix: Crash with certain OCIO configs in display descriptions
This was incorrectly assuming displays have a corresponding colorspace
with the same name.

Pull Request: https://projects.blender.org/blender/blender/pulls/146481
2025-09-20 13:14:04 +02:00
Campbell Barton
4a6268e092 Cleanup: various non functional changes for C++ 2025-09-20 16:28:02 +10:00
Damien Picard
0c06204864 Fix: Color Management: Warning in fallback display description
The fallback OCIO display description method would attempt to call
description, which was actually itself.

Pull Request: https://projects.blender.org/blender/blender/pulls/146467
2025-09-19 16:12:47 +02:00
Damien Picard
dd0eb2f90c Color Management: Show descriptions for displays, views, and looks
Descriptions for these types of data are specified in the OCIO config,
but were not shown in the UI.

Pull Request: https://projects.blender.org/blender/blender/pulls/146339
2025-09-18 19:41:36 +02:00
Brecht Van Lommel
6bef804d17 Fix: Save as Render does not work for some OCIO configs
There was an incorrect assumption that the display colorspace of a
view + display transform uniquely identifies it. But with modern OCIO
configs there is no longer a unique display colorspace per view.

The same wrong assumption was made in the code that refreshes the image
editor after save, and that was fixed as well.

Ref #145519

Pull Request: https://projects.blender.org/blender/blender/pulls/146449
2025-09-18 19:39:29 +02:00
Brecht Van Lommel
e753460e95 Fix: Working color space name on Blender startup is wrong
It was copying the wrong name.

Pull Request: https://projects.blender.org/blender/blender/pulls/146443
2025-09-18 19:33:35 +02:00
Clément Foucault
50283b9573 GPU: Split GLSL, C++ and metal shader defines
This makes all the defines and boiler plate code use
the generated source include system.

This makes source hierarchy more understandable.

Pull Request: https://projects.blender.org/blender/blender/pulls/146289
2025-09-15 17:22:19 +02:00
Brecht Van Lommel
924d72e05b Fix #146192: Wrong HDR mastering display max luminance in videos
Pull Request: https://projects.blender.org/blender/blender/pulls/146217
2025-09-13 15:06:37 +02:00
Brecht Van Lommel
f43566f8bc Color Management: Improve handling of missing working spaces
* Fix: OpenColorIO config defined working space disappears from menu. It
  was incorrectly using the current scene linear instead of default space.
* Warn users about missing working space.
* Don't detect lin_ap0_scene working space, we don't offer it in the menu.

Pull Request: https://projects.blender.org/blender/blender/pulls/146149
2025-09-12 19:35:29 +02:00
Campbell Barton
84511b8509 Core: add type checks to ID property accessors
Since moving the C++ ID property access macros cast "const" away,
replace with get/set accessors and add asserts that correct types
are used.
2025-09-12 06:29:42 +00:00
Sergey Sharybin
a927c98d5a Fix #146042: Fix when view transform is set to non-existing color space
Some of the color space settings are not validated on load to be set to
a valid values. To deal with those cases better bake it so color management
module does not make assumption on validness of the input data.

This is an oversight in the !140729.

Pull Request: https://projects.blender.org/blender/blender/pulls/146084
2025-09-11 14:09:20 +02:00
Brecht Van Lommel
a599ce0908 Video: Add mastering display metadata to HDR videos
For most players this appears to made no difference. But one case it fixes
is that with this metadata, on Youtube with SDR, 10bit PQ looks the same as
12bit PQ, where it was previously too desaturated.

10bit and 12bit HLG was already consistent without this metadata and there
appears to be no impact, though it remains inconsistent with PQ.

It seems good practice to be explicit about the mastering display regardless.

The way we get the max luminance is not ideal though. We get it from the
view transform name containing "HDR XXXX nits" as used in the Blender and
ACES configs. There is currently no way to query this information from
OpenColorIO.

In the future we can add a user control for this. For now if we can not
determine the max luminance this way, we don't write mastering display
metadata. The video player will then make some default assumption for tone
mapping, often 1000 nits.

Pull Request: https://projects.blender.org/blender/blender/pulls/144378
2025-09-08 11:47:48 +02:00
Brecht Van Lommel
10027d9a6d Color Management: Use working space from custom OCIO config in startup blend
When using the default Blender config use what was saved in the startup blend.
But when using a custom config it's likely the scene linear space from that config
is wanted. And not using it can lead to some confusing situations, where you end
up with an ACES config and the Linear Rec.709 working space.

Pull Request: https://projects.blender.org/blender/blender/pulls/145884
2025-09-07 21:32:17 +02:00
Brecht Van Lommel
514b9f4ec3 Fix: Working space menu shows blank entry with custom OCIO config
If the name of the scene linear space is different in another config, make
sure we update bmain to use that name.

Pull Request: https://projects.blender.org/blender/blender/pulls/145884
2025-09-07 21:32:09 +02:00
Brecht Van Lommel
9a5ac6d5ec Color Management: Add BLENDER_OCIO environment variable
THis works the same as OCIO, but is Blender specific in case you want to
use a different one than other applications.

Pull Request: https://projects.blender.org/blender/blender/pulls/145882
2025-09-07 21:30:54 +02:00
Brecht Van Lommel
2825f98f80 Fix: Color picker does not refresh properly when changing working space
Clear outdated cached transforms.

Pull Request: https://projects.blender.org/blender/blender/pulls/145878
2025-09-07 18:54:03 +02:00
Brecht Van Lommel
2143d495af Color Management: Read and write interop ID for OpenEXR
This is a new feature in the upcoming OpenEXR 3.4.0, but it's a string
attribute that we can already support.

Pull Request: https://projects.blender.org/blender/blender/pulls/145837
2025-09-07 13:20:24 +02:00
Brecht Van Lommel
4a67368ddd Color Management: Assign interop ID to non-color data
This one can not be handled with an alias because it is a role too.

Pull Request: https://projects.blender.org/blender/blender/pulls/145837
2025-09-07 13:20:20 +02:00
Brecht Van Lommel
8ac0a1541b Images: OpenEXR: Write "Software" metadata with Blender name and version
This can be helpful debugging problems with image files.

Pull Request: https://projects.blender.org/blender/blender/pulls/145837
2025-09-07 13:19:00 +02:00
Brecht Van Lommel
6a083a5464 Color Management: Add working color space for blend files
* Store scene linear to XYZ conversion matrix in each blend file, along
  with the colorspace name. The matrix is the source of truth. The name
  is currently only used for error logging about unknown color spaces.
* Add Working Space option in color management panel, to change the
  working space for the entire blend file. Changing this will pop up
  a dialog, with a default enabled option to convert all colors in
  the blend file to the new working space. Note this is necessarily only
  an approximation.
* Link and append automatically converts to the color space of the main
  open blend file.
* There is builtin support for Rec.709, Rec.2020 and ACEScg working spaces,
  in addition to the working space of custom OpenColorIO configs.
* Undo of working space for linked datablocks isn't quite correct when going
  to a smaller gamut working space. This can be fixed by reloading the file
  so the linked datablocks are reloaded.

Compatibility with blend files saved with a custom OpenColorIO config
is tricky, as we can not detect this.

* We assume that if the blend file has no information about the scene
  linear color space, it is the default one from the active OCIO config.
  And the same for any blend files linked or appended. This is effectively
  the same behavior as before.
* Now that there is a warning when color spaces are missing, it is more
  likely that a user will notice something is wrong and only save the
  blend file with the correct config active.
* As no automatic working space conversion happens on file load, there is
  an opportunity to correct things by changing the working space with
  "Convert Colors" disabled. This can also be scripted for all blend files
  in a project.

Ref #144911

Pull Request: https://projects.blender.org/blender/blender/pulls/145476
2025-09-05 19:04:47 +02:00
Brecht Van Lommel
b4c3685313 Refactor: Color Management: Add function to change scene linear role
There is a bad const cast here, but seems to work ok in practice. Creating a
whole new config would be tricky, though something we should support in the
future for other reasons.

Pull Request: https://projects.blender.org/blender/blender/pulls/145476
2025-09-05 19:03:24 +02:00
Aras Pranckevicius
44b7d7592d ImBuf: multi-thread IMB_byte_from_float / IMB_float_from_byte
Both were largely or completely single threaded.

They are used in various places, but testing their usage in VSE
compositor modifier branch (!139634), applying a default "do nothing"
compositor modifier on a 1080p image (on Ryzen 5950X):
51.4ms -> 12.2ms

Details about IMB_byte_from_float:
- No longer allocate a full new float buffer, instead do all work in
  a local small (32KB size, half of typical L1 cache) job-local buffer.
- Previous code was doing un-premultiply + OCIO + premultiply
  + un-premultiply again. That is pointless; just do
  un-premultiply once.

Details about IMB_float_from_byte / IMB_float_from_byte_ex:
- Remove incorrect code around"allocate float buffer outside of image
  buffer" since it was not actually true to begin with.
- Inside threaded part, do color space conversion and premultiply at
  once per-scanline, so that data stays in CPU caches more.

Pull Request: https://projects.blender.org/blender/blender/pulls/145716
2025-09-05 18:59:18 +02:00
Harley Acheson
68e5851615 UI: Correction & Improvements to File Browser Font Tooltips
The tooltips for fonts in the file browser, while in list view, now
shows either no preview or a blank white square (depending if you
viewed them with thumbnails in the current session). This PR corrects
that to always show a preview. It also shows this preview while in
thumbnail view.

Pull Request: https://projects.blender.org/blender/blender/pulls/145685
2025-09-05 18:41:18 +02:00