Commit Graph

83 Commits

Author SHA1 Message Date
Campbell Barton
640e70b6e8 Cleanup: various non-functional changes for C++ 2025-02-13 13:33:09 +11:00
Aras Pranckevicius
4f0fd32d6f VSE: Over Drop effect was not doing anything useful, map it to Alpha Over
Behavior of it was exactly the same as Alpha Over for the last 18 years (since
327d413eb3 in 2006 March), so just remap it to regular alpha over on file read.

Pull Request: https://projects.blender.org/blender/blender/pulls/134342
2025-02-10 16:10:01 +01:00
Bastien Montagne
87a4c0d3a8 Refactor: Make Library.runtime an allocated pointer.
Move `Library.runtime` to be a pointer, move the related
`LibraryRuntime` struct to `BKE_library.hh`. Similar to e.g.
Mesh.runtime, that pointer is expected to always be valid, and is
allocated at readtime or when creating a new Library ID.

Related smaller changes:
* Write code now uses standard ID writing codepath for Library IDs too.
  * Runtime pointer is reset to nullptr before writing.
* Looking up a library by its absolute path is now handled through a
  dedicated utils, `search_filepath_abs`, instead of using
  `BLI_findstring`.

Pull Request: https://projects.blender.org/blender/blender/pulls/134188
2025-02-07 17:47:16 +01:00
Aras Pranckevicius
2b39897d18 Fix #133799: render of VSE 10/12bpp videos broken unless source strips are float
10/12bpp movie writing code assumes that input image is properly
floating point for these cases. That is always true for regular
rendering, however VSE can produce 8bpp images, if there
are no float/HDR strips in there. Make these convert into a float
image in the render pipeline when needed.

Pull Request: https://projects.blender.org/blender/blender/pulls/133802
2025-01-30 14:55:41 +01:00
Richard Antalik
bf19960937 Refactor: VSE: Use C++ matrix BLI API
This PR explicitly declares integer type for `image_center_offs`, which
formalizes accidentally implemented correct behavior. Previously type
was float, all rhs types in expression were integers, so result was int
cast to float.

Comment is also added clarifying why integer must be used - float may
cause images to be interpolated, even when translation is set to 0.

There should be no functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/133573
2025-01-28 02:01:07 +01:00
Aras Pranckevicius
5ef08c2a96 Fix #112586: VSE can't use multi-layer EXR images
The rest of blender does handle multi-layer EXR images, using the
"combined" or RGBA/RGB layers when the visual result is needed. Make
VSE do the same.

While fixing this, I found several issues in other not well tested code
and had to fix them:

- IMB_buffer_float_from_float_threaded was wrongly using source channels
  as destination channels, producing garbage result.
- IMB_scale_into_new was not assigning channels to destination image.

Pull Request: https://projects.blender.org/blender/blender/pulls/132790
2025-01-08 10:45:24 +01:00
Falk David
ff91c27481 Cleanup: VSE: Rename SequenceType to StripType as well as flags
Rename the flags from `SEQ_TYPE_*` to `STRIP_TYPE_*`.

Pull Request: https://projects.blender.org/blender/blender/pulls/132753
2025-01-07 16:10:36 +01:00
Falk David
82cfa92233 Cleanup: VSE: Rename seq_ functions/variables to strip_
This should only rename functions and variables that are
referring to (operations on) a single `Strip`.

Pull Request: https://projects.blender.org/blender/blender/pulls/132748
2025-01-07 16:03:11 +01:00
Falk David
8541296e9d Cleanup: VSE: Rename Strip *seq variables to strip
This only renames variables named `seq` and not other variants,
like `seq_*` or `seq1`.

Pull Request: https://projects.blender.org/blender/blender/pulls/132736
2025-01-07 14:09:45 +01:00
Aras Pranckevicius
016167e8f3 Fix #132529: VSE strip scaled to 0.0 occludes strips below it
The "does a strip cover whole screen" logic did not handle the case
of completely zero size strip, and thus was wrongly deciding
that the strip is opaque.

Pull Request: https://projects.blender.org/blender/blender/pulls/132714
2025-01-07 10:01:11 +01:00
Aras Pranckevicius
ab1fc88f2e Fix #132646: VSE proxy strip incorrectly occludes strips below it
Depending on proxy size and scaling factor, the "does proxy cover
whole screen" code was producing wrong results, due to mismatched
resolutions it was working on: SeqRenderData at that point contains
proxy resolution (reduced), but SEQ_image_transform_final_quad_get
works at full resolution. The produced quad needs to be scaled down
to what the render context is operating at.
2025-01-07 10:01:10 +01:00
Falk David
655a17a6ab Refactor: VSE: Rename Sequence to Strip
This renames the struct `Sequence` to `Strip`.

While the motivation for this partially comes from
the "Sequence Design" #131329, it seems like this
is a good refactor whether the design gets implemented
or not.

The `Sequence` represents what users see as strips in the
VSE. Many places in the code already refere to a `Sequence`
as "strip". It's the C-style "base class" of all strip types.

This also renames the python RNA type `bpy.types.Sequence`
to `bpy.types.Strip` which means that this technically breaks
the python API.

Pull Request: https://projects.blender.org/blender/blender/pulls/132179
2025-01-06 14:19:24 +01:00
Aras Pranckevicius
4546367bb3 Cleanup: Add ibuf channel expectation asserts in VSE code
Whole of VSE assumes that all images are always 4 channels. Add
asserts in several places to more clearly indicate that.

Pull Request: https://projects.blender.org/blender/blender/pulls/132546
2025-01-02 14:33:52 +01:00
Aras Pranckevicius
c26db69f58 VSE: Simplify and optimize effect multi-threading
Cleanup (and make slightly faster as a side effect) the way VSE effects
do multi-threading. Previously (some of them) were using
IMB_processor_apply_threaded with C-like machinery (which internally
uses a task pool), switch that over to a helper apply_effect_op
(which internally uses a parallel for). Based on profiling, parallel
for is slightly more efficient (task pool takes a bit until all the
tasks are "pushed" into the pool). Note however that some VSE effects
were already doing parallel for internally; these are not affected.

VSE scene at 4K resolution, with four 4K resolution PNG images blended
over each other, time it takes to do render_strip_stack:
- Ryzen 5950X (Win/VS2022): 38.9ms -> 34.7ms
- Mac M4 Max: 21.9ms -> 19.8ms

Now that all VSE effects are internally threaded via parallel for,
there's no need for the init_execution and execute_slice machinery,
so remove all that.

You might also notice that half of "over drop" effect code is gone.
It was accidentally not doing anything whatsoever for the last 18 years
(since 2.42), and currently observed behavior matches documentation
and "internet knowledge", so let's  accept it as correct.

Pull Request: https://projects.blender.org/blender/blender/pulls/132380
2025-01-01 11:11:49 +01:00
Aras Pranckevicius
2720bd529d Refactor: split off VSE effects code into separate files
Part of #130975: split off overly large VSE effects.cc (almost 4000
lines) into separate source files. No behavior changes.

- Add / Subtract / Multiply all go into one source file,
- Blend Over / Blend Under / Over Drop / other blend modes all go
  into one source file,
- Cross and Gamma Cross go into one source file,
- All others go into their own files.

Pull Request: https://projects.blender.org/blender/blender/pulls/132323
2024-12-27 12:52:38 +01:00
Falk David
a7d3ced570 Refactor: VSE: Rename Strip to StripData
This renames the `Strip` struct to `StripData` and also renames
the `Sequence::strip` member to `Sequence::data`.

This is a first step towards naming the `Sequence` struct to `Strip`.

Pull Request: https://projects.blender.org/blender/blender/pulls/132165
2024-12-20 18:02:31 +01:00
Aras Pranckevicius
e99252d7fd Refactor: more cleanups and renamed to movie/ffmpeg related files
- All movie related public headers now have MOV_ prefix instead of
  IMB_movie_.
- All movie related public functions now have MOV_ prefix as well,
  instead of IMB_movie_ or IMB_anim_.
- IMB_anim.hh -> MOV_read.hh (also ImBufAnim -> MovieReader), and
  various utility functions not related to playback were split off
  into MOV_util.hh.
- Other function name tweaks for clarity, e.g. IMB_suffix_anim
  -> MOV_set_multiview_suffix and so on.
- All except one usages of MOV_get_fps (nee IMB_anim_get_fps) were
  ultimately just converting returned value into a float. So make
  MOV_get_fps just return that directly. For the (exactly just one)
  place that needs numerator and denominator, have
  MOV_get_fps_num_denom.
- Code comments on the public header functions.
- Removed never-used code paths inside movie timecode proxy building
  file.

It might be easier to review each commit separately.

Pull Request: https://projects.blender.org/blender/blender/pulls/132145
2024-12-20 13:23:08 +01:00
Aras Pranckevicius
974efe7d23 Refactor: move ffmpeg/video related code into one place
Previously, code related to reading/writing movie files via ffmpeg was
scattered around: some under blenkernel, some directly in generic
imbuf headers, some under intern/ffmpeg. Some of the files were named
with not exactly clear names. Some parts not directly related to movies
were including ffmpeg headers directly (rna_scene.cc).

What is in this PR:

Movie and ffmpeg related code is now under imbuf/movie:
- IMB_anim.hh: movie reading, proxy querying, various utility functions.
- IMB_movie_enums.hh: simple enum definitions,
- IMB_movie_write.hh: movie writing functions.
- intern: actual implementation and private headers.
    - ffmpeg_compat.h: various ffmpeg version difference handling
      utilities,
    - ffmpeg_swscale.hh/cc: scaling and format conversion utilities
      for ffmpeg libswscale,
    - ffmpeg_util.hh/cc: misc utilities related to ffmpeg,
    - movie_proxy_indexer.hh/cc: proxies and timecode indexing for movies,
    - movie_read.hh/cc: decoding of movies into images,
    - movie_write.cc: encoding of images into movies.
- tests: basic ffmpeg library unit tests that previously
  lived under intern/ffmpeg.

Interface changes (at C++ level, no Python API changes):
- Mostly just movie related functions that were BKE_ previously, are now IMB_.
- I did one large-ish change though, and that is to remove bMovieHandle
  struct that had pointers to several functions. Now that is
  IMB_movie_write_begin, IMB_movie_write_append, IMB_movie_write_end
  functions using a single opaque struct handle. As a result, usages
  of that in pipeline.cc and render_opengl.cc have changed.

Pull Request: https://projects.blender.org/blender/blender/pulls/132074
2024-12-19 12:34:30 +01:00
Bastien Montagne
b325142d17 Merge branch 'blender-v4.3-release' 2024-11-12 16:55:40 +01:00
Bastien Montagne
0b3a7cbe69 Cleanup: Move BKE_image.h and related headers to C++.
NOTE: This also required some changes to Cycles code itself, who is now
directly including `BKE_image.hh` instead of declaring a few prototypes
of these functions in its `blender/utils.h` header (due to C++ functions
names mangling, this was not working anymore).

Pull Request: https://projects.blender.org/blender/blender/pulls/130174
2024-11-12 16:53:54 +01:00
Richard Antalik
f27220f6b6 Merge branch 'blender-v4.3-release' 2024-11-06 05:44:11 +01:00
Richard Antalik
6ee1eb49be Fix #126167: Speed effect does not interpolate frame numbers
Only convert frame number to integer when image interpolation is not
used.

Pull Request: https://projects.blender.org/blender/blender/pulls/129839
2024-11-06 05:39:30 +01:00
Jacques Lucke
a17ac76d13 BLI: support accessing underlying memory buffer of Vector container
This extends the `Vector` API to support transfering ownership of a memory
buffer to and from a `Vector`. This reduces the need for unnecessary copies in
some cases which converting between data-structures. A new
`VectorSet::extract_vector` method is added that takes O(1) time. Previously,
this was only possible in O(n) time by copying the entire array.

The `Vector::release` method can be used to e.g. build a vector with the C++
container, but then extract it for use in DNA data.

Pull Request: https://projects.blender.org/blender/blender/pulls/129736
2024-11-03 12:09:05 +01:00
Richard Antalik
580b4a1a2d Fix #127479: VSE produces blank scene offscreen renders
If conditions are not met for offscreen rendering, render job is used as
fallback. This can be skipped if there is possibility of race condition.
This was only considered for case where `context->for_render` was false,
since this indicates that call is invoked by the job itself.

If scene strip display is set to `OB_RENDER`, it needs to start the
render job. So variable `do_seq_gl` was renamed to `is_preview` and
reused in race avoidance connditon. This was done to convey clearer
meaning and match comments.

This change does make code less safe - race is avoided by UI not
allowing to run F12 render and opengl render at the same time. However,
I don't think, this could be easily resolved on VSE side without
suspending thread or being able to run multiple render jobs.

Pull Request: https://projects.blender.org/blender/blender/pulls/127926
2024-09-27 18:41:26 +02:00
Campbell Barton
381898b6dc Refactor: move BLI_path_util header to C++, rename to BLI_path_utils
Move to a C++ header to allow C++ features to be used there,
use the "utils" suffix as it's preferred for new files.

Ref !128147
2024-09-26 21:13:39 +10:00
Aras Pranckevicius
ecce5f45ac Cleanup: rename MAXSEQ -> SEQ_MAX_CHANNELS and make it C++ constexpr
When I was learning VSE code, MAXSEQ constant (a preprocessor define!) was
confusing. It makes it sound like it is "max sequences", but it is actually
"max channels". So rename it to SEQ_MAX_CHANNELS and make it C++ constexpr int
instead of preprocessor macro.

Pull Request: https://projects.blender.org/blender/blender/pulls/128024
2024-09-23 15:43:45 +02:00
Campbell Barton
2360a3911c BLI_listbase: add a utility to check the number of items in the list
To avoid unnecessary looping over listbase items the function
`BLI_listbase_count_at_most` was used however it resulting in an awkward
expression: `BLI_listbase_count_at_most(list, count + 1) == count`
replace this with `BLI_listbase_count_is_equal_to(list, count)`.
2024-09-16 11:39:00 +10:00
Aras Pranckevicius
78972f8559 Fix #127192: VSE Tonemap now works as expected on strips that don't cover whole screen
When doing average/min/max luminance calculations for tonemapping, ignore
pixels that are outside of the strip rectangle. Due to how VSE innards work,
when a strip is positioned to not cover the whole screen, "the rest" is filled
with transparent black. For tonemapping, this was dragging average calculated
luminance way down.

Images of the issue in PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/127207
2024-09-11 12:42:03 +02:00
Aras Pranckevicius
0d9b793dfa VSE: Multi-thread Saturation and Multiply strip color controls
Image/movie strip controls color controls: "Saturation" and "Multiply" were
both single-threaded code. Multi-thread both of them. Timings to apply them
on a 4K resolution byte image, on Ryzen 5950X (Win10/VS2022):

- Saturation: 97ms -> 6.3ms
- Multiply: 11.5ms -> 1.1ms

Pull Request: https://projects.blender.org/blender/blender/pulls/127409
2024-09-11 12:37:50 +02:00
Aras Pranckevicius
9d3b2b51a7 Cleanup: None of VSE effects have three image inputs
So remove all code related to "ibuf3" handling since it is just always null.

Pull Request: https://projects.blender.org/blender/blender/pulls/127348
2024-09-09 18:02:59 +02:00
Aras Pranckevicius
577630d24f VSE: Optimize away some pointless image copies when applying modifiers
SEQ_modifier_apply_stack is called from exactly one place, and it always
was throwing away the input image, and taking the newly produced image.
Which means, we can stop copying it. Just run the modifiers on the
input image.

In a test file that is HD (1080p) resolution, two EXR image sequences,
adjustment layer with Color Balance, and a text strip on top,
playback framerate (Ryzen 5950X, Win10/VS2022) goes 20.8 -> 22.1 fps

Pull Request: https://projects.blender.org/blender/blender/pulls/127346
2024-09-09 14:55:24 +02:00
Aras Pranckevicius
5c259a1bae VSE: Faster processing of alpha-over strip at the bottom of strip stack
When a strip with alpha-over blend mode (which is default) has an alpha
channel and is at the bottom of the whole stack, there's no point in
blending it with black color; the result will be identical.

So stop doing that. Also, whenever some other case happens at the bottom
of the stack (e.g. some other blend mode), create the fake "black input"
image at the needed color type (float or byte) and with the correct
color space already applied. Otherwise, especially for floats, VSE
spends much time converting this fake black input from byte to float,
and then converting it to sequencer color space.

Test case of two EXR files blended over each other, at 4K resolution,
on Ryzen 5950X (Win10/VS2022):
- whole sequencer_preview_region_draw 115ms -> 75ms
- seq_render_give_ibuf part: 64ms -> 24ms

Pull Request: https://projects.blender.org/blender/blender/pulls/127310
2024-09-09 13:16:12 +02:00
Aras Pranckevicius
528471541b VSE: Faster and more consistent thumbnails
Implementing part of design outlined in #126087.

- VSE thumbnail cache has a new implementation, hopefully simpler
  and easier to understand.
    - Instead of cache key being a VSE strip, frame index, plus
      complicated logic for cache items linking etc.,
    - The cache is keyed by media file path (if multiple strips
      use the same input file, they will share cache entries), frame
      index within media file, and any extra data (e.g. steam index
      for multi-steam videos)
- Much reduced cache flickering and strange/weird thumbnail choices.
    - Likewise, thumbnails no longer disappear-and-reload on operations
      like Undo, dragging new video strip into timeline, or F12 render.
- Thumbnails now load faster.
    - Images use dedicated/faster thumbnail loading routines when a
      format can do that (e.g. JPG and EXR can).
    - Movies reuse ffmpeg decoding context for neighboring strips
      that use the same file (as often happens when cutting footage)
    - Thumbnail requests are processed on several threads now too.

Images and more detail in PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/126405
2024-08-29 08:27:12 +02:00
Bastien Montagne
c607ead4b7 Refactor: Makesrna: move generated code further in C++.
This commit moves generated `RNA_blender.h`, `RNA_prototype.h` and
`RNA_blender_cpp.h` headers to become C++ header files.

It also removes the now useless `RNA_EXTERN_C` defines, and just
directly use the `extern` keyword. We do not need anymore `extern "C"`
declarations here.

Pull Request: https://projects.blender.org/blender/blender/pulls/124469
2024-07-15 16:39:45 +02:00
Aras Pranckevicius
2aee84a611 Fix #123579: VSE, no magenta preview for missing scene strips
Code that implemented "show missing media in magenta" in VSE preview
only implemented that for images and movies, and forgot that scene
strips can also be missing.

Pull Request: https://projects.blender.org/blender/blender/pulls/124124
2024-07-04 10:27:52 +02:00
Richard Antalik
952f41a9fd Fix: VSE frame interpolation is broken
Caused by incorrect output of `SEQ_give_frame_index` for effect strips.
Also since output value is float, it has to be truncated to integer,
when image bufferes are rendered for the effect.

Pull Request: https://projects.blender.org/blender/blender/pulls/123914
2024-07-01 23:07:23 +02:00
Richard Antalik
db5cc08714 Revert "Fix #118505: Incorrect strip image transformation"
This reverts commit 3d17217025.
2024-06-28 21:02:38 +02:00
Richard Antalik
3d17217025 Fix #118505: Incorrect strip image transformation
When preview is downscaled and transformation origin is not the center
of the image, this causes unexpected offset. This happened, because one
matrix combined image downscaling, so it fits into preview and user
defined scale. When origin was not center of the image, this results in
incorrect offset.

Solved by splitting 1 matrix in `sequencer_image_crop_transform_matrix`
into 2 matrices. First matrix just centers and scales image to expected
size. Second matrix performs rest of transform operations. This code is
bit easier to read as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/123776
2024-06-28 17:11:17 +02:00
Sergey Sharybin
0081c4b64a Fix #123576: VSE Crash: Preview render fails if two Scene strips are stacked
The issue was caused by the ImBuf of the scene strip render sharing the float
buffer pixels with the ImBuf from the render result. If the render result is
ever gets freed (i.e., by a request to perform another render) it'll leave the
strip ImBuf pointing to a freed memory.

This was caused by the #109788.

The simple solution is to restore the code to the state prior to the ImBuf
refactor in the RenderRsult. A better solution would be to use implicit
sharing, similar to how it was done in the #108045.

Pull Request: https://projects.blender.org/blender/blender/pulls/123731
2024-06-26 09:58:46 +02:00
Aras Pranckevicius
59d98f3314 Fix #123259: VSE alpha over not working with a Mask modifier
A strip was wrongly deemed to be opaque (and thus strips below it
were skipped from rendering), if the strip content was opaque, but
it gained transparency via presence of a Mask modifier.

While at it, I also noticed that a strip could have been wrongly deemed
opaque when it had a Multiplier < 1.0 with "multiply alpha" option
checked under strip Color settings. So fixed that too.

The whole logic of that factored out into is_opaque_alpha_over function
to make the call site clearer.

Pull Request: https://projects.blender.org/blender/blender/pulls/123303
2024-06-17 11:43:28 +02:00
Campbell Barton
57707ca9ae Cleanup: const pointers for FCurves where possible 2024-05-21 13:17:35 +10:00
Aras Pranckevicius
31e56797f0 VSE: indicate missing media in timeline/display
Sequencer timeline displays red tint & appropriate icons for strips that are
missing media file (images, movies, audio, or meta strips that contain such).

Sequencer preview and rendering displays missing media strips as magenta,
similar to missing textures elsewhere in Blender. This is on by default,
sequencer view settings have an option to turn it off.

Pull Request: https://projects.blender.org/blender/blender/pulls/116869
2024-04-24 19:54:44 +02:00
Campbell Barton
fd589fdca4 Cleanup: various non functional C++ changes 2024-04-20 13:46:14 +10:00
Campbell Barton
7ce68904eb Cleanup: replace suspicious use of "&" with "&&" 2024-04-01 22:20:09 +11:00
Campbell Barton
5685481fcb Cleanup: rename "name" to "filepath" for full paths 2024-03-28 20:57:50 +11:00
Falk David
a11335d19a Cleanup: Move BKE_fcurve.h to C++
No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/119094
2024-03-05 18:39:08 +01:00
Richard Antalik
fc32b9c5dd Fix: Crash when multiview movie right view is missing.
Ultimately this was due to missing nullptr check before trying to
process the image, but this should have been caught when loading
ImBufAnims. If any is missing, cancel multiview loading and load
movie as if it was single view only.
2024-03-02 18:12:47 +01:00
Bastien Montagne
de5451b112 Cleanup: Move BKE_anim_data header to be fully C++. 2024-02-28 11:51:03 +01:00
Aras Pranckevicius
f4f708a54f VSE: Skip rendering lower strips that are behind opaque strips above them
Often in previs setups, you have several "variations" of image/movie strips
for review, where the topmost one completely covers the others under it. VSE
rendering already had an optimization where if there's a fully opaque strip
that covers the whole screen, then the lower strips are skipped from
processing/rendering. However, it was not handling the case of non-fullscreen
strips (e.g. you'd have a Color strip near top & bottom for letterboxing, and
an opaque strip "in the middle").

This adds a simple "occluder tracking", and skips strips that are completely
covered by any single opaque strip that is above it (like outlined in #117790
task).

Playback of Gold previs between 1:42 and 1:55, on Windows/Ryzen5950X:
- Average frame time 28.5ms -> 23.8ms
- Median frame time 24.1ms -> 21.5ms
- Two slowest frames: 263->189ms, 194->178ms

Rendering the Gold previs movie: 325s -> 304s (93% of previous time)

Pull Request: https://projects.blender.org/blender/blender/pulls/118396
2024-02-21 20:16:44 +01:00
Aras Pranckevicius
b4c6c69632 ImBuf: do not clear newly allocated image pixels when not needed
In some/many cases, an `ImBuf` is allocated, and all the pixels are
immediately filled by some code. Doing the memory clear within allocation
is just memory traffic for no good reason.

Add a flag to skip initialization of ImBuf pixels (IB_uninitialized_pixels)
and use that in some parts of VSE effects/rendering/cache/scopes, as well
as image loading code.

Rendering out VSE movie, on Windows/VS2022/Ryzen5950X:
- Sprite Fright: 443sec -> 414sec (takes 93% of previous time)
- Gold previs: 367sec -> 325sec (takes 88% of prev time)

Pull Request: https://projects.blender.org/blender/blender/pulls/118321
2024-02-15 14:54:57 +01:00