163 if (entry ==
nullptr) {
178 if (id_copy !=
nullptr) {
192 for (
const auto &thumb : item.value.frames) {
209 if (entry ==
nullptr) {
235 entry.
frames.append({frame_index, stream_index, thumb, used_at,
false});
241 if (*cache ==
nullptr) {
242 *cache = MEM_new<ThumbnailCache>(__func__);
249 if (scene ==
nullptr || scene->
ed ==
nullptr) {
257 const float aspect =
float(r_width) /
float(r_height);
258 if (r_width > r_height) {
270 if (scene ==
nullptr || scene->
ed ==
nullptr || strip ==
nullptr) {
287 strip->scene != scene)
299 if (strip->scene_camera !=
nullptr) {
302 if (strip->scene_view_layer_name !=
nullptr) {
310 float timeline_frame)
314 switch (strip->
type) {
317 if (s_elem !=
nullptr) {
325 filepath,
sizeof(filepath), strip->
data->dirpath, strip->
data->stripdata->filename);
346 if (ibuf ==
nullptr) {
360 if (ibuf ==
nullptr) {
373 int height = ibuf->
y;
386 constexpr int width = THUMB_SIZE;
387 constexpr int height = THUMB_SIZE;
396 const float *src = mask_buffer.
data();
398 for (
int i = 0; i < width * height; i++) {
399 dst[0] = dst[1] = dst[2] =
uchar(*src * 255.0f);
409 Scene *scene_ =
nullptr;
419 static void end_fn(
void *customdata);
420 static void free_fn(
void *customdata);
431 "Generating strip thumbnails...",
435 ThumbGenerationJob *tj = MEM_new<ThumbGenerationJob>(
"ThumbGenerationJob", scene, cache);
444void ThumbGenerationJob::free_fn(
void *customdata)
460 if (cur_id_copy !=
nullptr) {
462 cur_id_copy =
nullptr;
473void ThumbGenerationJob::run_fn(
void *customdata,
wmJobWorkerStatus *worker_status)
475#ifdef DEBUG_PRINT_THUMB_JOB_TIMES
476 clock_t t0 = clock();
477 std::atomic<int> total_thumbs = 0, total_images = 0, total_movies = 0;
482 while (!worker_status->
stop) {
490 requests.
reserve(job->cache_->requests_.size());
491 for (
const auto &request : job->cache_->requests_) {
501 std::ranges::sort(requests,
502 [](
const ThumbnailCache::Request &a,
const ThumbnailCache::Request &
b) {
503 if (a.source_key !=
b.source_key) {
504 return a.source_key <
b.source_key;
506 if (a.stream_index !=
b.stream_index) {
507 return a.stream_index <
b.stream_index;
509 return a.frame_index <
b.frame_index;
520 MovieReader *cur_anim =
nullptr;
521 std::string cur_anim_path;
529 ID *cur_id_copy =
nullptr;
531 for (
const ThumbnailCache::Request &request : requests) {
532 if (worker_status->
stop) {
536#ifdef DEBUG_PRINT_THUMB_JOB_TIMES
539 ImBuf *thumb =
nullptr;
542#ifdef DEBUG_PRINT_THUMB_JOB_TIMES
549#ifdef DEBUG_PRINT_THUMB_JOB_TIMES
554 if (request.source_key.path != cur_anim_path || request.stream_index != cur_stream) {
555 if (cur_anim !=
nullptr) {
560 cur_anim_path = request.source_key.path;
561 cur_stream = request.stream_index;
565 if (cur_anim !=
nullptr) {
574 if (cur_anim !=
nullptr) {
585 MovieClip *clip =
reinterpret_cast<MovieClip *
>(
586 get_id_copy(job->cache_, request, cur_id_copy, cur_source_generation));
587 if (clip !=
nullptr) {
588 MovieClipUser clip_user = {};
590 const short build_sizes = clip->proxy.build_size_flag & 0x0F;
604 get_id_copy(job->cache_, request, cur_id_copy, cur_source_generation));
616 ThumbnailCache::SourceEntry *val = job->cache_->map_.lookup_ptr(request.source_key);
617 if (val !=
nullptr && val->generation == request.source_generation) {
618 val->used_at =
math::max(val->used_at, request.requested_at);
620 *val, request.frame_index, request.stream_index, thumb, request.requested_at);
626 job->cache_->requests_.remove(request);
633 if (cur_anim !=
nullptr) {
637 if (cur_id_copy !=
nullptr) {
639 cur_id_copy =
nullptr;
644#ifdef DEBUG_PRINT_THUMB_JOB_TIMES
645 clock_t t1 = clock();
646 printf(
"VSE thumb job: %i thumbs (%i img, %i movie) in %.3f sec\n",
650 double(t1 - t0) / CLOCKS_PER_SEC);
654void ThumbGenerationJob::end_fn(
void *customdata)
663 float timeline_frame,
670 if (val ==
nullptr) {
675 cache.
map_.add_new(key, value);
676 val = cache.
map_.lookup_ptr(key);
678 BLI_assert_msg(val !=
nullptr,
"Thumbnail cache value should never be null here");
684 if (strip->streamindex != val->
frames[
index].stream_index) {
688 if (score < best_score) {
700 const bool needs_new_thumb = (best_score > 0) ||
701 (best_index >= 0 && val->
frames[best_index].stale);
715 else if (needs_new_thumb) {
722 const ID *source_id =
nullptr;
724 source_id = &strip->clip->id;
727 source_id = &strip->mask->id;
729 if (source_id !=
nullptr) {
731 return BKE_id_copy_ex(
732 nullptr, source_id, nullptr, LIB_ID_COPY_LOCALIZE | LIB_ID_COPY_NO_ANIMDATA);
748 if (best_index < 0) {
755 return val->
frames[best_index].thumb;
761 float timeline_frame)
772 frame_index += strip->anim_startofs;
775 ImBuf *res =
nullptr;
790 if (scene ==
nullptr || scene->
ed ==
nullptr) {
800 if (scene ==
nullptr || scene->
ed ==
nullptr) {
806 const Strip *strip =
nullptr;
810 bool more_pending =
false;
818 strip = first_request->scene_strip;
819 key = first_request->source_key;
820 frame_index = first_request->frame_index;
821 source_generation = first_request->source_generation;
829 Scene *scene_from_uid =
reinterpret_cast<Scene *
>(
833 bool rendered_thumb =
false;
835 strip->scene !=
nullptr)
839 bmain, scene, strip,
float(frame_index), THUMB_SIZE);
840 if (thumb !=
nullptr) {
847 if (val ==
nullptr || val->
generation != source_generation) {
854 rendered_thumb =
true;
859 return rendered_thumb || more_pending;
871 bool invalidated =
false;
875 if (cache !=
nullptr) {
878 if (elem !=
nullptr) {
882 paths_count = strip->
data->stripdata_num;
886 for (
int i = 0; i < paths_count; i++, elem++) {
914 if (cache !=
nullptr) {
923 for (
const auto &item : cache->
map_.items()) {
924 entries += item.value.frames.size();
925 if (item.value.used_at < oldest_time) {
926 oldest_key = item.key;
927 oldest_time = item.value.used_at;
928 oldest_entries = item.value.frames.size();
935 entries -= oldest_entries;
941 for (
const auto &item : cache->
map_.items()) {
942 for (
int64_t i = 0; i < item.value.frames.size(); i++) {
943 if (item.value.frames[i].used_at < cache->
logical_time_ - 100) {
945 item.value.frames.remove_and_reorder(i);
958 if (cache !=
nullptr) {
960 return request.timeline_frame < rect.
xmin || request.timeline_frame > rect.
xmax ||
961 request.channel < rect.
ymin || request.channel > rect.
ymax;
972 if (cache !=
nullptr) {
981 if (cache !=
nullptr) {
#define BLI_path_join(...)
#define ID_BLEND_PATH_FROM_GLOBAL(_id)
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
const Value * lookup_ptr(const Key &key) const
ValueIterator values() const &
void remove_contained(const Key &key)
Value pop_default(const Key &key, const Value &default_value)
ItemIterator items() const &
int64_t remove_if(Predicate &&predicate)
constexpr bool contains(const T &value) const
void append(const T &value)
void reserve(const int64_t min_capacity)
const T & data(const Action &owning_action) const
static void ensure_job(const bContext *C, ThumbnailCache *cache)
ThumbGenerationJob(Scene *scene, ThumbnailCache *cache)
T max(const T &a, const T &b)
void ensure_ibuf_is_sequencer_space(const Scene *scene, ImBuf *ibuf, bool make_float)
static ThumbnailCache::SourceKey get_key_from_strip(const Scene *scene, const Strip *strip, float timeline_frame)
ImBuf * render_scene_strip_thumbnail(Main *bmain, Scene *timeline_scene, const Strip *strip, float frame_index, int size)
void thumbnail_cache_invalidate_strip(Scene *scene, const Strip *strip)
Span< Strip * > lookup_strips_by_scene(Editing *ed, const Scene *key)
float give_frame_index(const Scene *scene, const Strip *strip, float timeline_frame)
bool strip_can_have_thumbnail(const Scene *scene, const Strip *strip)
void thumbnail_cache_clear(Scene *scene)
static ImBuf * make_thumb_for_image(const Scene *scene, const ThumbnailCache::Request &request)
static ImBuf * render_mask_thumb(Mask *mask, float frame_index)
ImBuf * thumbnail_cache_get(const bContext *C, Scene *scene, const Strip *strip, float timeline_frame)
static ImBuf * query_thumbnail(ThumbnailCache &cache, const ThumbnailCache::SourceKey &key, int frame_index, float timeline_frame, const bContext *C, const Strip *strip)
static Mutex thumb_cache_mutex
static ThumbnailCache::SourceKey get_key_from_scene_strip(const Strip *strip)
static constexpr int MAX_THUMBNAILS
void image_size_to_thumb_size(int &r_width, int &r_height, int size)
static void scale_to_thumbnail_size(ImBuf *ibuf)
static void entry_add_or_replace_frame(ThumbnailCache::SourceEntry &entry, int frame_index, int stream_index, ImBuf *thumb, int64_t used_at)
void thumbnail_cache_discard_requests_outside(Scene *scene, const rctf &rect)
static ID * get_id_copy(ThumbnailCache *cache, const ThumbnailCache::Request &request, ID *&cur_id_copy, uint64_t &cur_source_generation)
static ThumbnailCache * query_thumbnail_cache(Scene *scene)
static ThumbnailCache * ensure_thumbnail_cache(Scene *scene)
void thumbnail_cache_destroy(Scene *scene)
bool thumbnail_cache_update_scene_thumbs(const bContext *C, Scene *scene)
bool thumbnail_cache_has_pending_scene_requests(Scene *scene)
StripElem * render_give_stripelem(const Scene *scene, const Strip *strip, int timeline_frame)
void thumbnail_cache_maintain_capacity(Scene *scene)
void WM_main_add_notifier(uint type, void *reference)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
void IMB_free_byte_pixels(ImBuf *ibuf)
Scene * CTX_data_sequencer_scene(const bContext *C)
void WM_jobs_callbacks(wmJob *wm_job, wm_jobs_start_callback startjob, void(*initjob)(void *), void(*update)(void *), void(*endjob)(void *))
MaskRasterHandle * BKE_maskrasterize_handle_new()
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
MINLINE int round_fl_to_int(float a)
ID * BKE_libblock_find_session_uid(Main *bmain, short type, uint32_t session_uid)
void MOV_close(MovieReader *anim)
@ WM_JOB_TYPE_SEQ_DRAW_THUMBNAIL
ImBuf * MOV_decode_frame(MovieReader *anim, int frame_index, IMB_Proxy_Size preview_size)
void IMB_refImBuf(ImBuf *ibuf)
wmWindow * CTX_wm_window(const bContext *C)
void WM_jobs_customdata_set(wmJob *wm_job, void *customdata, void(*free)(void *customdata))
@ MCLIP_PROXY_RENDER_USE_FALLBACK_RENDER
eMovieClipProxy_RenderSize
void BKE_mask_evaluate(Mask *mask, float ctime, bool do_newframe)
MINLINE int bitscan_forward_i(int a)
void WM_jobs_start(wmWindowManager *wm, wmJob *wm_job)
MovieReader * MOV_open_file(const char *filepath, const ImBufFlags ib_flags, const int streamindex, const bool keep_original_colorspace, ColorManagedColorspaceSettings *colorspace_settings)
void IMB_freeImBuf(ImBuf *ibuf)
wmWindowManager * CTX_wm_manager(const bContext *C)
void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, Mask *mask, int width, int height, bool do_aspect_correct, bool do_mask_aa, bool do_feather)
void BKE_maskrasterize_handle_free(MaskRasterHandle *mr_handle)
void BKE_id_free(Main *bmain, void *idv)
void BKE_movieclip_user_set_frame(MovieClipUser *user, int framenr)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, ImBufFlags flags)
Main * CTX_data_main(const bContext *C)
void IMB_byte_from_float(ImBuf *ibuf)
ImBuf * BKE_movieclip_get_ibuf_flag(MovieClip *clip, const MovieClipUser *user, MovieClipFlag flag, MovieClipCacheFlag cache_flag)
wmJob * WM_jobs_get(wmWindowManager *wm, wmWindow *win, const void *owner, const char *name, const eWM_JobFlag flag, const eWM_JobType job_type)
int MOV_get_existing_proxies(const MovieReader *anim)
constexpr uint64_t hash_string(StringRef str)
ImBuf * IMB_thumb_load_image(const char *filepath, size_t max_thumb_size, ColorManagedColorspaceSettings *colorspace_settings, IMBThumbLoadFlags load_flags=IMBThumbLoadFlags::Zero)
void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle, unsigned int width, unsigned int height, float *buffer)
Rasterize a buffer from a single mask (threaded execution).
bool IMB_scale(ImBuf *ibuf, int2 new_size, IMBScaleFilter filter, bool threaded=true)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
void WM_jobs_timer(wmJob *wm_job, double time_step, uint note, uint endnote, void(*timer_step)(void *))
void IMB_free_float_pixels(ImBuf *ibuf)
bool WM_jobs_is_running(const wmJob *wm_job)
void mask(PageMask &srt, TileMaps &tilemaps, const uint3 global_id, const uint local_tile_index)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
seq::EditingRuntime * runtime
const uint8_t * byte_data() const
uint8_t * byte_data_for_write()
const float * float_data() const
ThumbnailCache * thumbnail_cache
uint64_t source_generation
const Strip * scene_strip
Request(const SourceKey &source_key, int frame, int stream, StripType type, int64_t logical_time, uint64_t source_generation, float time_frame, int ch)
friend bool operator==(const Request &a, const Request &b)
Vector< FrameEntry > frames
SourceKey(const std::string &path)
friend auto operator<=>(const SourceKey &a, const SourceKey &b)=default
Set< Request > scene_requests_
bool remove_entry(const SourceKey &key)
bool invalidate_entry(const SourceKey &key)
Map< SourceKey, SourceEntry > map_
Map< uint64_t, ID * > id_copies_
uint64_t next_generation_