Commit Graph

2603 Commits

Author SHA1 Message Date
Campbell Barton
84694bf635 Cleanup: add inline array size comments and minor corrections 2025-05-23 14:03:20 +10:00
Brecht Van Lommel
f165c75e14 Refactor: Add various DNA_*_enums.h and DNA_*_types.h files
* Move colorband and theme DNA to own headers
* Move some anim, curve, modifier and space enums to new headers
* Move data transfer enums to DNA
* Duplicate imbuf proxy and GPU backend enums

For a few reasons:
* Reduce number of includes in DNA headers
* Don't define enums used in DNA outside of DNA
* Move theme settings to separate header for userdef_default_theme.c
* Prepare for using default initializers in DNA headers. (#134531)

Pull Request: https://projects.blender.org/blender/blender/pulls/138831
2025-05-20 13:26:43 +02:00
Campbell Barton
b3dfde88f3 Cleanup: spelling in comments (check_spelling_* target)
Also uppercase acronyms: API, UTF & ASCII.
2025-05-17 10:17:37 +10:00
Sergey Sharybin
a3748b549b Fix #138868: Slow start up on when using certain OCIO config
Regression caused by #138433

Somehow the lazy nature of the is_linear and is_srgb got lost in
the refactor and the fields were greedily initialized on startup
and it is not a cheap operation.

Pull Request: https://projects.blender.org/blender/blender/pulls/138945
2025-05-15 20:26:02 +02:00
Brecht Van Lommel
a94a911e10 Fix: Slow USD import with certain OpenColorIO configs
As evidenced by #138868, checking all colorspaces to see if they are sRGB
can be very slow, due to loading all LUTs into memory. Instead use a simpler
check by a list of names only, which is still better than the hardcoded
single name used in Blender 4.4.

Ideally recent configs will use the ColorInterop Forum alias so we can
find the sRGB colorspace reliably.
2025-05-15 19:33:37 +02:00
Campbell Barton
e97e9c2904 Cleanup: various non functional changes for C++ 2025-05-15 10:26:47 +10:00
Martin Vignali
1d21d496f2 FFmpeg: Add support for 16 bits FFV1 output
This adds 16-bit/channel option for FFV1 video codec to
output render videos with high precision

Pull Request: https://projects.blender.org/blender/blender/pulls/138624
2025-05-13 11:10:33 +02:00
Martin-Vignali
ca6571383a FFmpeg: Use Gray8 when rendering black and white with Quicktime Qtrle and Png
Also be more explicit about RGB pixel format
(instead of trusting first encoder pixel format)
File have been tested with After Effects CC 2025, and load as expected.

Co-authored-by: Jokyo <jokyo@MacBook-Pro-de-Jokyo-2019.local>
Pull Request: https://projects.blender.org/blender/blender/pulls/138601
2025-05-13 08:55:26 +02:00
Sergey Sharybin
3c8138cdc5 Cleanup: Unused variable warning 2025-05-12 17:54:19 +02:00
Campbell Barton
5e75a9c1e8 Cleanup: spelling in comments 2025-05-11 17:00:47 +10:00
Sergey Sharybin
cd70b9d730 Fix #138637: EXR Sequencer preview is broken
The issue was caused by the shader always applying exposure even if
it is 1. When the input image had negative values this lead to nan
values to the input of the shader which converts to the display
space.

Solved by only doing to-scene-linear transform in the shader which
does this.

Caused by 18110744a2

Pull Request: https://projects.blender.org/blender/blender/pulls/138666
2025-05-09 23:20:35 +02:00
Brecht Van Lommel
5697918905 Cleanup: Compiler warning 2025-05-09 19:10:14 +02:00
Sergey Sharybin
9d4b236d13 Fix: Class memory access on the color management tear-down
Pull Request: https://projects.blender.org/blender/blender/pulls/138670
2025-05-09 16:22:57 +02:00
Sergey Sharybin
8a6951a986 Cleanup: Use Blender::Mutex in OpenColorIO integration 2025-05-09 14:05:04 +02:00
Sergey Sharybin
7ceb4495c5 Refactor: OpenColorIO integration
Briefly about this change:
- OpenColorIO C-API is removed.
- The information about color spaces in ImBuf module is removed.
  It was stored in global ListBase in colormanagement.cc.
- Both OpenColorIO and fallback implementation supports GPU drawing.
- Fallback implementation supports white point, RGB curves, etc.
- Removed check for support of GPU drawing in IMB.

Historically it was implemented in a separate library with C-API, this
is because way back C++ code needed to stay in intern. This causes all
sort of overheads, and even calls that are strictly considered bad
level.

This change moves OpenColorIO integration into a module within imbuf,
next to movie, and next to IMB_colormanagement which is the main user
of it. This allows to avoid copy of color spaces, displays, views etc
in the ImBuf: they were used to help quickly querying information to
be shown on the interface. With this change it can be stored in the
same data structures as what is used by the OpenColorIO integration.
While it might not be fully avoiding duplication it is now less, and
there is no need in the user code to maintain the copies.

In a lot of cases this change also avoids allocations done per access
to the OpenColorIO. For example, it is not needed anymore to allocate
image descriptor in a heap.

The bigger user-visible change is that the fallback implementation now
supports GLSL drawing, with the whole list of supported features, such
as curve mapping and white point. This should help simplifying code
which relies on color space conversion on GPU: there is no need to
figure out fallback solution in such cases. The only case when drawing
will not work is when there is some actual bug, or driver issue, and
shader has failed to compile.

The change avoids having an opaque type for color space, and instead
uses forward declaration. It is a bit verbose on declaration, but helps
avoiding unsafe type-casts. There are ways to solve this in the future,
like having a header for forward declaration, or to flatten the name
space a bit.

There should be no user-level changes under normal operation.
When building without OpenColorIO or the configuration has a typo or
is missing a fuller set of color management tools is applies (such as the
white point correction).

Pull Request: https://projects.blender.org/blender/blender/pulls/138433
2025-05-09 14:01:43 +02:00
Nathan Vegdahl
e0beb7afe6 Templates for render output paths
This adds basic templating support to render output paths. By putting
"{variable_name}" in the path string, it will be replaced by the named
variable's value when generating the actual output path. This is similar
to how "//" is already substituted with the path to the blend file's
current directory.

This templating system is implemented for both the primary render output
path as well as the File Output node in the compositing nodes. Support
for using templates in other places can be implemented in future PRs.

In addition to the "{variable_name}" syntax, some additional syntax is
also supported:

- Since "{" and "}" now have special meaning, "{{" and "}}" are now
  escape sequences for literal "{" and "}".
- "{variable_name:format_specifier}", where "format_specifier" is a
  special syntax using "#", which allows the user to specify how numeric
  variables should be formatted:
  - "{variable_name:###}" will format the number as an integer with at
    least 3 characters (padding with zeros as needed).
  - "{variable_name:.##}" will format the number as a float with
    precisely 2 fractional digits.
  - "{variable_name:###.##}" will format the number as a float with at
    least 3 characters for the integer part and precisely 2 for the
    fractional part.

For the primary render output path: if there is a template syntax error,
a variable doesn't exist, or a format specifier isn't valid (e.g. trying
to format a string with "##"), the render that needs to write to the
output path fails with a descriptive error message.

For both the primary and File Output node paths: if there are template
syntax errors the field is highlighted in red in the UI, and a tooltip
describes the offending syntax errors. Note that these do *not* yet
reflect errors due to missing variables. That will be for a follow-up
PR.

In addition to the general system, this PR also implements a limited set
of variables for use in templates, but more can be implemented in future
PRs. The variables added in this PR are:

- `blend_name`: the name of the current blend file without the file
  extension.
- `fps`: the frames per second of the current scene.
- `resolution_x` and `resolution_y`: the render output resolution.

Pull Request: https://projects.blender.org/blender/blender/pulls/134860
2025-05-08 15:37:28 +02:00
Martin-Vignali
9049645d0f FFmpeg: Add support for 10/12 bits FFV1 output
FFV1 supports more than 8 bits by pixel. Add support for 10 and 12 bit
depth (FFV1 encoder uses planar pixel format for these bitdepths).
Fix pixel format for 8 bit output. Previously it was always RGBA.

Co-authored-by: mvji <33432858+mvji@users.noreply.github.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/138192
2025-05-08 02:34:56 +02:00
Sergey Sharybin
24a28ea38d Cleanup: Const-correctness in ImBuf metadata drawing 2025-05-07 16:21:06 +02:00
Jacques Lucke
b7a1325c3c BLI: use blender::Mutex by default which wraps tbb::mutex
This patch adds a new `BLI_mutex.hh` header which adds `blender::Mutex` as alias
for either `tbb::mutex` or `std::mutex` depending on whether TBB is enabled.

Description copied from the patch:
```
/**
 * blender::Mutex should be used as the default mutex in Blender. It implements a subset of the API
 * of std::mutex but has overall better guaranteed properties. It can be used with RAII helpers
 * like std::lock_guard. However, it is not compatible with e.g. std::condition_variable. So one
 * still has to use std::mutex for that case.
 *
 * The mutex provided by TBB has these properties:
 * - It's as fast as a spin-lock in the non-contended case, i.e. when no other thread is trying to
 *   lock the mutex at the same time.
 * - In the contended case, it spins a couple of times but then blocks to avoid draining system
 *   resources by spinning for a long time.
 * - It's only 1 byte large, compared to e.g. 40 bytes when using the std::mutex of GCC. This makes
 *   it more feasible to have many smaller mutexes which can improve scalability of algorithms
 *   compared to using fewer larger mutexes. Also it just reduces "memory slop" across Blender.
 * - It is *not* a fair mutex, i.e. it's not guaranteed that a thread will ever be able to lock the
 *   mutex when there are always more than one threads that try to lock it. In the majority of
 *   cases, using a fair mutex just causes extra overhead without any benefit. std::mutex is not
 *   guaranteed to be fair either.
 */
 ```

The performance benchmark suggests that the impact is negilible in almost
all cases. The only benchmarks that show interesting behavior are the once
testing foreach zones in Geometry Nodes. These tests are explicitly testing
overhead, which I still have to reduce over time. So it's not unexpected that
changing the mutex has an impact there. What's interesting is that on macos the
performance improves a lot while on linux it gets worse. Since that overhead
should eventually be removed almost entirely, I don't really consider that
blocking.

Links:
* Documentation of different mutex flavors in TBB:
  https://www.intel.com/content/www/us/en/docs/onetbb/developer-guide-api-reference/2021-12/mutex-flavors.html
* Older implementation of a similar mutex by me:
  https://archive.blender.org/developer/differential/0016/0016711/index.html
* Interesting read regarding how a mutex can be this small:
  https://webkit.org/blog/6161/locking-in-webkit/

Pull Request: https://projects.blender.org/blender/blender/pulls/138370
2025-05-07 04:53:16 +02:00
Brecht Van Lommel
321e9e049e Fix: USD material reader uses fixed colorspace names
For other OpenColorIO configurations these may not exist or have a
different meaning.
2025-05-02 17:39:56 +02:00
Brecht Van Lommel
af4a7efaed Fix #138262: Movie file colorspace can't be changed
Regression from recent ccd7bc2078, restore previous logic and add
comments.
2025-05-02 17:39:56 +02:00
Sergey Sharybin
5b29ba488f Color management: Implement shader to convert to scene linear
Previous conversion to scene linear was done in the display transform
shader. Having a separate shader to convert texture to scene linear
allows drawing input textures with different color spaces into a
viewport and apply display transform on all of them.

Currently unused, but is required for !138094. It could also be used
in the future to avoid host-side linearization in the image engine.

Internally it uses a lot of the same logic for shader caching and
binding, but the code is refactored a bit to make it easier to have
a stronger separation in the future if needed.

Ref #138094

Pull Request: https://projects.blender.org/blender/blender/pulls/138308
2025-05-02 16:51:46 +02:00
Aras Pranckevicius
8528feb7ee Cleanup: replace some spinlocks with atomics or mutexes
- ImBuf reference counting: turn that into just an atomic integer
- Cachefile safety: turn into a mutex, since work under the spinlock
  was quite heavy (hashtable creation, other memory allocations)
- Movie clip editor: turn into a mutex, since work under the spinlock
  was very heavy (reading files from disk, etc.)
- Mesh intersect: remove the previously commented out spinlock path;
  replace BLI mutex with C++ mutex for shorter code

Pull Request: https://projects.blender.org/blender/blender/pulls/137989
2025-04-29 10:42:45 +02:00
Campbell Barton
2d4290f285 Cleanup: spelling in comments (make check_spelling_*)
Also inconsistent capitalization.
2025-04-24 22:45:22 +00:00
Brecht Van Lommel
fb2ba20b67 Refactor: Use more typed MEM_calloc<> and MEM_malloc<>
Pull Request: https://projects.blender.org/blender/blender/pulls/137822
2025-04-22 11:22:18 +02:00
Brecht Van Lommel
d061b00455 Refactor: Eliminate various unsafe memcpy and memset
Some of these already have warnings with clang-tidy, others are more
safe in case these structs get (copy) constructors in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +02:00
Brecht Van Lommel
637c6497e9 Refactor: Use more typed MEM_calloc<>, avoid unnecessary size_t cast
Handle some cases that were missed in previous refactor. And eliminate
unnecessary size_t casts as these could hide issues.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +02:00
Campbell Barton
3933f45f52 Cleanup: move doc-strings to declarations
Move into headers or to the top of the function body for internal
implementation details, in some cases remove duplicate doc-strings.
2025-04-18 22:58:36 +10:00
Campbell Barton
217406ec42 Cleanup: move IMB_convert_rgba_to_abgr to a static function
This is a fairly specific function and was only used by the IRIS format.
2025-04-15 12:08:08 +10:00
Campbell Barton
578bf16537 Fix: integer overflow in rect buffer filling on large buffers
Other changes include:

- Replace buffer out of bounds check with an assert
  (it was only done for the byte).
- Step over pixels on each X span
  instead of calculating the offset for each pixel.
- Use const variables.
2025-04-12 05:48:04 +00:00
Campbell Barton
3b2c0b6cd5 Fix: integer overflows calculating the number of pixels
Note that moving to the templated versions of array allocation functions
in [0] caused integer overflow regressions because multiplying by the
`sizeof(type)` caused the following values to be cast to a size_t.

[0]: e85ebb24fe
2025-04-12 01:28:30 +00:00
Campbell Barton
309bdc491b Fix: integer overflow scaling large images 2025-04-12 11:04:53 +10:00
Campbell Barton
f9b9644cbb Fix: failure to save an existing Cineon file
Saving a Cineon fail a second time would fail because it would
default to 8 bits per sample, where only 10 bits is supported.
2025-04-11 22:31:05 +10:00
Campbell Barton
f6757abae2 Fix: crash saving large Cineon images
When the offset exceeded INT_MAX, the offset would wrap to a
negative number then attempt to read/write outside the buffer bounds.
2025-04-11 22:31:05 +10:00
Campbell Barton
6d6c695619 Fix: integer overflows calculating the number of pixels in imbuf
Use IMB_get_pixel_count to prevent integer overflow.
2025-04-11 18:52:38 +10:00
Campbell Barton
d256b7f688 Fix: crash loading & saving large Iris images
Integer overflow in IMB_convert_rgba_to_abgr assigned a negative value
to size_t resulting in a large value which wrote past the buffer bounds.
2025-04-11 17:40:11 +10:00
Campbell Barton
37148d6711 Fix: crash saving large WebP images
WebP images can be at most 16383x16383,
however saving sizes which overflowed an integer would crash.

- Early exit with an error when the image is too large.
- Replace integer offsets with size_t.
2025-04-11 07:33:48 +00:00
Campbell Barton
2cbb07d7ad Fix: error reading RLE compressed Iris images
Regression in [0] which used a 4x large size bounds check
to prevent a buffer read overflow reading the RLE table.

[0]: 829916f4e5
2025-04-11 15:22:17 +10:00
Campbell Barton
b2dbfa7d77 Cleanup: spelling in comments, use doxygen comments 2025-04-10 13:02:29 +10:00
Campbell Barton
24f8819c78 Fix: correct check for Iris image dimensions
Mistake in [0], missed width check.

[0]: 7a23d7aba4
2025-04-10 10:50:10 +10:00
Jesse Yurkovich
7afcba7da6 Cleanup: Movie: Adjust DNA and comments from recent ProRes addition
A few tidy ups from the recent ProRes addition[1]
- Reduce size of DNA structs
- Follow coding guidelines for multi-line comments

[1] 7d75c5e2bc

Pull Request: https://projects.blender.org/blender/blender/pulls/137231
2025-04-09 21:41:29 +02:00
Campbell Barton
12f0164eb0 CMake: match defines & CMake variable names
Avoid mistakes with these variables getting mixed up
(see: bf03a2684b).

Ref !137183
2025-04-09 08:44:36 +00:00
Campbell Barton
b024fe041e Cleanup: use more descriptive names for the IRIS format
Also add some code-comments.
2025-04-09 01:47:02 +00:00
Campbell Barton
6d8d37558a Cleanup: replace outdated function names in __func__ in error messages 2025-04-09 11:32:21 +10:00
Campbell Barton
7a23d7aba4 Fix: error writing & loading corrupt IRIS files
- Files cannot exceed 65535 width or height,
  attempting to write 65536 would write a zero sized image.
- Ensure that zero sized imbufs are never loaded.
2025-04-09 11:28:58 +10:00
Campbell Barton
35f5877ac3 Fix: incorrect iris image header detection
The first two bytes were being checked in the wrong order,
if files using this header were loaded they would detect as IRIS files
from imb_is_a_iris which would then fail to load (printing errors).
2025-04-09 11:05:47 +10:00
Campbell Barton
2dc4a94e8b Cleanup: use consistent "format_" prefix for imbuf image formats 2025-04-09 00:16:20 +00:00
Campbell Barton
7657afc8cb Correct error in 5d3496625d 2025-04-08 15:43:38 +10:00
Campbell Barton
5d3496625d Fix: regression storing density in BMP I/O
Regression in [0] which broke support for writing DPI.

[0]: aa3bdfd76a

Ref: !137122
2025-04-08 05:40:43 +00:00
Campbell Barton
01dc87d841 ImBuf: write the aspect ratio to EXR images
Only rendered EXR's had the aspect ratio written.
2025-04-08 10:14:36 +10:00