2011-11-07 12:55:18 +00:00
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2011 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2011-11-07 12:55:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
|
|
#ifndef WIN32
|
2013-12-12 13:10:03 +06:00
|
|
|
# include <unistd.h>
|
2011-11-07 12:55:18 +00:00
|
|
|
#else
|
2013-12-12 13:10:03 +06:00
|
|
|
# include <io.h>
|
2011-11-07 12:55:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_constraint_types.h"
|
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
#include "DNA_space_types.h"
|
|
|
|
|
#include "DNA_movieclip_types.h"
|
2012-10-01 07:54:37 +00:00
|
|
|
#include "DNA_node_types.h"
|
2011-11-07 12:55:18 +00:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
#include "DNA_view3d_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
#include "BLI_ghash.h"
|
|
|
|
|
#include "BLI_math.h"
|
|
|
|
|
#include "BLI_threads.h"
|
|
|
|
|
|
2012-02-15 16:06:48 +00:00
|
|
|
#include "BKE_animsys.h"
|
Color Management, Stage 2: Switch color pipeline to use OpenColorIO
Replace old color pipeline which was supporting linear/sRGB color spaces
only with OpenColorIO-based pipeline.
This introduces two configurable color spaces:
- Input color space for images and movie clips. This space is used to convert
images/movies from color space in which file is saved to Blender's linear
space (for float images, byte images are not internally converted, only input
space is stored for such images and used later).
This setting could be found in image/clip data block settings.
- Display color space which defines space in which particular display is working.
This settings could be found in scene's Color Management panel.
When render result is being displayed on the screen, apart from converting image
to display space, some additional conversions could happen.
This conversions are:
- View, which defines tone curve applying before display transformation.
These are different ways to view the image on the same display device.
For example it could be used to emulate film view on sRGB display.
- Exposure affects on image exposure before tone map is applied.
- Gamma is post-display gamma correction, could be used to match particular
display gamma.
- RGB curves are user-defined curves which are applying before display
transformation, could be used for different purposes.
All this settings by default are only applying on render result and does not
affect on other images. If some particular image needs to be affected by this
transformation, "View as Render" setting of image data block should be set to
truth. Movie clips are always affected by all display transformations.
This commit also introduces configurable color space in which sequencer is
working. This setting could be found in scene's Color Management panel and
it should be used if such stuff as grading needs to be done in color space
different from sRGB (i.e. when Film view on sRGB display is use, using VD16
space as sequencer's internal space would make grading working in space
which is close to the space using for display).
Some technical notes:
- Image buffer's float buffer is now always in linear space, even if it was
created from 16bit byte images.
- Space of byte buffer is stored in image buffer's rect_colorspace property.
- Profile of image buffer was removed since it's not longer meaningful.
- OpenGL and GLSL is supposed to always work in sRGB space. It is possible
to support other spaces, but it's quite large project which isn't so
much important.
- Legacy Color Management option disabled is emulated by using None display.
It could have some regressions, but there's no clear way to avoid them.
- If OpenColorIO is disabled on build time, it should make blender behaving
in the same way as previous release with color management enabled.
More details could be found at this page (more details would be added soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Color_Management
--
Thanks to Xavier Thomas, Lukas Toene for initial work on OpenColorIO
integration and to Brecht van Lommel for some further development and code/
usecase review!
2012-09-15 10:05:07 +00:00
|
|
|
#include "BKE_colortools.h"
|
2019-07-28 13:24:18 +02:00
|
|
|
#include "BKE_global.h"
|
2011-11-07 12:55:18 +00:00
|
|
|
#include "BKE_library.h"
|
|
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_movieclip.h"
|
2012-10-01 07:54:37 +00:00
|
|
|
#include "BKE_node.h"
|
2019-04-17 06:17:24 +02:00
|
|
|
#include "BKE_image.h" /* openanim */
|
2011-11-07 12:55:18 +00:00
|
|
|
#include "BKE_tracking.h"
|
|
|
|
|
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
#include "IMB_moviecache.h"
|
|
|
|
|
|
2018-03-16 11:14:38 +01:00
|
|
|
#include "DEG_depsgraph.h"
|
2019-03-14 15:16:56 +01:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2018-03-16 11:14:38 +01:00
|
|
|
|
2019-04-02 16:05:22 +02:00
|
|
|
#include "GPU_texture.h"
|
|
|
|
|
|
2013-02-28 14:25:00 +00:00
|
|
|
#ifdef WITH_OPENEXR
|
2013-12-12 13:10:03 +06:00
|
|
|
# include "intern/openexr/openexr_multi.h"
|
2013-02-28 14:25:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
/*********************** movieclip buffer loaders *************************/
|
|
|
|
|
|
2012-04-07 16:37:55 +00:00
|
|
|
static int sequence_guess_offset(const char *full_name, int head_len, unsigned short numlen)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
char num[FILE_MAX] = {0};
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(num, full_name + head_len, numlen + 1);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return atoi(num);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
static int rendersize_to_proxy(const MovieClipUser *user, int flag)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if ((flag & MCLIP_USE_PROXY) == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return IMB_PROXY_NONE;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
switch (user->render_size) {
|
|
|
|
|
case MCLIP_PROXY_RENDER_SIZE_25:
|
|
|
|
|
return IMB_PROXY_25;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
case MCLIP_PROXY_RENDER_SIZE_50:
|
|
|
|
|
return IMB_PROXY_50;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
case MCLIP_PROXY_RENDER_SIZE_75:
|
|
|
|
|
return IMB_PROXY_75;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
case MCLIP_PROXY_RENDER_SIZE_100:
|
|
|
|
|
return IMB_PROXY_100;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
case MCLIP_PROXY_RENDER_SIZE_FULL:
|
|
|
|
|
return IMB_PROXY_NONE;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return IMB_PROXY_NONE;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int rendersize_to_number(int render_size)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
switch (render_size) {
|
|
|
|
|
case MCLIP_PROXY_RENDER_SIZE_25:
|
|
|
|
|
return 25;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
case MCLIP_PROXY_RENDER_SIZE_50:
|
|
|
|
|
return 50;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
case MCLIP_PROXY_RENDER_SIZE_75:
|
|
|
|
|
return 75;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
case MCLIP_PROXY_RENDER_SIZE_100:
|
|
|
|
|
return 100;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
case MCLIP_PROXY_RENDER_SIZE_FULL:
|
|
|
|
|
return 100;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return 100;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int get_timecode(MovieClip *clip, int flag)
|
|
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if ((flag & MCLIP_USE_PROXY) == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return IMB_TC_NONE;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return clip->proxy.tc;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void get_sequence_fname(const MovieClip *clip, const int framenr, char *name)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
unsigned short numlen;
|
|
|
|
|
char head[FILE_MAX], tail[FILE_MAX];
|
|
|
|
|
int offset;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(name, clip->name, sizeof(clip->name));
|
|
|
|
|
BLI_stringdec(name, head, tail, &numlen);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-06-17 12:51:53 +10:00
|
|
|
/* Movie-clips always points to first image from sequence, auto-guess offset for now.
|
|
|
|
|
* Could be something smarter in the future. */
|
2019-04-17 06:17:24 +02:00
|
|
|
offset = sequence_guess_offset(clip->name, strlen(head), numlen);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (numlen) {
|
|
|
|
|
BLI_stringenc(
|
|
|
|
|
name, head, tail, numlen, offset + framenr - clip->start_frame + clip->frame_offset);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_strncpy(name, clip->name, sizeof(clip->name));
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_path_abs(name, ID_BLEND_PATH_FROM_GLOBAL(&clip->id));
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* supposed to work with sequences only */
|
2019-04-17 06:17:24 +02:00
|
|
|
static void get_proxy_fname(
|
|
|
|
|
const MovieClip *clip, int proxy_render_size, bool undistorted, int framenr, char *name)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int size = rendersize_to_number(proxy_render_size);
|
|
|
|
|
char dir[FILE_MAX], clipdir[FILE_MAX], clipfile[FILE_MAX];
|
|
|
|
|
int proxynr = framenr - clip->start_frame + 1 + clip->frame_offset;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_split_dirfile(clip->name, clipdir, clipfile, FILE_MAX, FILE_MAX);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->flag & MCLIP_USE_PROXY_CUSTOM_DIR) {
|
|
|
|
|
BLI_strncpy(dir, clip->proxy.dir, sizeof(dir));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_snprintf(dir, FILE_MAX, "%s/BL_proxy", clipdir);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (undistorted) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_snprintf(name, FILE_MAX, "%s/%s/proxy_%d_undistorted/%08d", dir, clipfile, size, proxynr);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_snprintf(name, FILE_MAX, "%s/%s/proxy_%d/%08d", dir, clipfile, size, proxynr);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_path_abs(name, BKE_main_blendfile_path_from_global());
|
|
|
|
|
BLI_path_frame(name, 1, 0);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
strcat(name, ".jpg");
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2019-02-05 16:50:57 +01:00
|
|
|
#ifdef WITH_OPENEXR
|
|
|
|
|
|
2019-02-05 16:23:53 +01:00
|
|
|
typedef struct MultilayerConvertContext {
|
2019-04-17 06:17:24 +02:00
|
|
|
float *combined_pass;
|
|
|
|
|
int num_combined_channels;
|
2019-02-05 16:23:53 +01:00
|
|
|
} MultilayerConvertContext;
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void *movieclip_convert_multilayer_add_view(void *UNUSED(ctx_v),
|
|
|
|
|
const char *UNUSED(view_name))
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void *movieclip_convert_multilayer_add_layer(void *ctx_v, const char *UNUSED(layer_name))
|
|
|
|
|
{
|
|
|
|
|
/* Return dummy non-NULL value, we don't use layer handle but need to return
|
|
|
|
|
* something, so render API invokes the add_pass() callbacks. */
|
|
|
|
|
return ctx_v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void movieclip_convert_multilayer_add_pass(void *UNUSED(layer),
|
|
|
|
|
void *ctx_v,
|
|
|
|
|
const char *pass_name,
|
|
|
|
|
float *rect,
|
|
|
|
|
int num_channels,
|
|
|
|
|
const char *chan_id,
|
|
|
|
|
const char *UNUSED(view_name))
|
|
|
|
|
{
|
|
|
|
|
/* NOTE: This function must free pass pixels data if it is not used, this
|
|
|
|
|
* is how IMB_exr_multilayer_convert() is working. */
|
|
|
|
|
MultilayerConvertContext *ctx = ctx_v;
|
|
|
|
|
/* If we've found a first combined pass, skip all the rest ones. */
|
|
|
|
|
if (ctx->combined_pass != NULL) {
|
|
|
|
|
MEM_freeN(rect);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (STREQ(pass_name, RE_PASSNAME_COMBINED) || STREQ(chan_id, "RGBA") || STREQ(chan_id, "RGB")) {
|
|
|
|
|
ctx->combined_pass = rect;
|
|
|
|
|
ctx->num_combined_channels = num_channels;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
MEM_freeN(rect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* WITH_OPENEXR */
|
2019-02-05 16:50:57 +01:00
|
|
|
|
2019-02-05 16:23:53 +01:00
|
|
|
/* Will try to make image buffer usable when originating from the multi-layer
|
|
|
|
|
* source.
|
|
|
|
|
* Internally finds a first combined pass and uses that as a buffer. Not ideal,
|
|
|
|
|
* but is better than a complete empty buffer. */
|
2019-02-05 16:50:57 +01:00
|
|
|
void BKE_movieclip_convert_multilayer_ibuf(struct ImBuf *ibuf)
|
2019-02-05 16:23:53 +01:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ibuf == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-02-05 16:50:57 +01:00
|
|
|
#ifdef WITH_OPENEXR
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ibuf->ftype != IMB_FTYPE_OPENEXR || ibuf->userdata == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
MultilayerConvertContext ctx;
|
|
|
|
|
ctx.combined_pass = NULL;
|
|
|
|
|
ctx.num_combined_channels = 0;
|
|
|
|
|
IMB_exr_multilayer_convert(ibuf->userdata,
|
|
|
|
|
&ctx,
|
|
|
|
|
movieclip_convert_multilayer_add_view,
|
|
|
|
|
movieclip_convert_multilayer_add_layer,
|
|
|
|
|
movieclip_convert_multilayer_add_pass);
|
|
|
|
|
if (ctx.combined_pass != NULL) {
|
|
|
|
|
BLI_assert(ibuf->rect_float == NULL);
|
|
|
|
|
ibuf->rect_float = ctx.combined_pass;
|
|
|
|
|
ibuf->channels = ctx.num_combined_channels;
|
|
|
|
|
ibuf->flags |= IB_rectfloat;
|
|
|
|
|
ibuf->mall |= IB_rectfloat;
|
|
|
|
|
}
|
|
|
|
|
IMB_exr_close(ibuf->userdata);
|
|
|
|
|
ibuf->userdata = NULL;
|
2019-02-05 16:50:57 +01:00
|
|
|
#endif
|
2019-02-05 16:23:53 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
static ImBuf *movieclip_load_sequence_file(MovieClip *clip,
|
|
|
|
|
const MovieClipUser *user,
|
|
|
|
|
int framenr,
|
|
|
|
|
int flag)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
struct ImBuf *ibuf;
|
|
|
|
|
char name[FILE_MAX];
|
|
|
|
|
int loadflag;
|
|
|
|
|
bool use_proxy = false;
|
|
|
|
|
char *colorspace;
|
|
|
|
|
|
|
|
|
|
use_proxy = (flag & MCLIP_USE_PROXY) && user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL;
|
|
|
|
|
if (use_proxy) {
|
|
|
|
|
int undistort = user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT;
|
|
|
|
|
get_proxy_fname(clip, user->render_size, undistort, framenr, name);
|
|
|
|
|
|
|
|
|
|
/* Well, this is a bit weird, but proxies for movie sources
|
|
|
|
|
* are built in the same exact color space as the input,
|
|
|
|
|
*
|
|
|
|
|
* But image sequences are built in the display space.
|
|
|
|
|
*/
|
|
|
|
|
if (clip->source == MCLIP_SRC_MOVIE) {
|
|
|
|
|
colorspace = clip->colorspace_settings.name;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
colorspace = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
get_sequence_fname(clip, framenr, name);
|
|
|
|
|
colorspace = clip->colorspace_settings.name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadflag = IB_rect | IB_multilayer | IB_alphamode_detect | IB_metadata;
|
|
|
|
|
|
|
|
|
|
/* read ibuf */
|
|
|
|
|
ibuf = IMB_loadiffname(name, loadflag, colorspace);
|
|
|
|
|
BKE_movieclip_convert_multilayer_ibuf(ibuf);
|
|
|
|
|
|
|
|
|
|
return ibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-26 15:57:00 +00:00
|
|
|
static void movieclip_open_anim_file(MovieClip *clip)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
char str[FILE_MAX];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!clip->anim) {
|
|
|
|
|
BLI_strncpy(str, clip->name, FILE_MAX);
|
|
|
|
|
BLI_path_abs(str, ID_BLEND_PATH_FROM_GLOBAL(&clip->id));
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* FIXME: make several stream accessible in image editor, too */
|
|
|
|
|
clip->anim = openanim(str, IB_rect, 0, clip->colorspace_settings.name);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->anim) {
|
|
|
|
|
if (clip->flag & MCLIP_USE_PROXY_CUSTOM_DIR) {
|
|
|
|
|
char dir[FILE_MAX];
|
|
|
|
|
BLI_strncpy(dir, clip->proxy.dir, sizeof(dir));
|
|
|
|
|
BLI_path_abs(dir, BKE_main_blendfile_path_from_global());
|
|
|
|
|
IMB_anim_set_index_dir(clip->anim, dir);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-26 15:57:00 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
static ImBuf *movieclip_load_movie_file(MovieClip *clip,
|
|
|
|
|
const MovieClipUser *user,
|
|
|
|
|
int framenr,
|
|
|
|
|
int flag)
|
2012-03-26 15:57:00 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ImBuf *ibuf = NULL;
|
|
|
|
|
int tc = get_timecode(clip, flag);
|
|
|
|
|
int proxy = rendersize_to_proxy(user, flag);
|
2012-03-26 15:57:00 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
movieclip_open_anim_file(clip);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->anim) {
|
|
|
|
|
int fra = framenr - clip->start_frame + clip->frame_offset;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ibuf = IMB_anim_absolute(clip->anim, fra, tc, proxy);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-26 13:30:53 +00:00
|
|
|
static void movieclip_calc_length(MovieClip *clip)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->source == MCLIP_SRC_MOVIE) {
|
|
|
|
|
movieclip_open_anim_file(clip);
|
|
|
|
|
|
|
|
|
|
if (clip->anim) {
|
|
|
|
|
clip->len = IMB_anim_get_duration(clip->anim, clip->proxy.tc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (clip->source == MCLIP_SRC_SEQUENCE) {
|
|
|
|
|
unsigned short numlen;
|
|
|
|
|
char name[FILE_MAX], head[FILE_MAX], tail[FILE_MAX];
|
|
|
|
|
|
|
|
|
|
BLI_stringdec(clip->name, head, tail, &numlen);
|
|
|
|
|
|
|
|
|
|
if (numlen == 0) {
|
|
|
|
|
/* there's no number group in file name, assume it's single framed sequence */
|
|
|
|
|
clip->len = 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
clip->len = 0;
|
|
|
|
|
for (;;) {
|
|
|
|
|
get_sequence_fname(clip, clip->len + clip->start_frame, name);
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (BLI_exists(name)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
clip->len++;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-26 13:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
/*********************** image buffer cache *************************/
|
|
|
|
|
|
|
|
|
|
typedef struct MovieClipCache {
|
2019-04-17 06:17:24 +02:00
|
|
|
/* regular movie cache */
|
|
|
|
|
struct MovieCache *moviecache;
|
|
|
|
|
|
|
|
|
|
/* cached postprocessed shot */
|
|
|
|
|
struct {
|
|
|
|
|
ImBuf *ibuf;
|
|
|
|
|
int framenr;
|
|
|
|
|
int flag;
|
|
|
|
|
|
|
|
|
|
/* cache for undistorted shot */
|
|
|
|
|
float principal[2];
|
|
|
|
|
float polynomial_k1, polynomial_k2, polynomial_k3;
|
|
|
|
|
float division_k1, division_k2;
|
|
|
|
|
short distortion_model;
|
|
|
|
|
bool undistortion_used;
|
|
|
|
|
|
|
|
|
|
int proxy;
|
|
|
|
|
short render_flag;
|
|
|
|
|
} postprocessed;
|
|
|
|
|
|
|
|
|
|
/* cache for stable shot */
|
|
|
|
|
struct {
|
|
|
|
|
ImBuf *reference_ibuf;
|
|
|
|
|
|
|
|
|
|
ImBuf *ibuf;
|
|
|
|
|
int framenr;
|
|
|
|
|
int postprocess_flag;
|
|
|
|
|
|
|
|
|
|
float loc[2], scale, angle, aspect;
|
|
|
|
|
int proxy, filter;
|
|
|
|
|
short render_flag;
|
|
|
|
|
} stabilized;
|
|
|
|
|
|
|
|
|
|
int sequence_offset;
|
|
|
|
|
|
|
|
|
|
bool is_still_sequence;
|
2011-11-07 12:55:18 +00:00
|
|
|
} MovieClipCache;
|
|
|
|
|
|
|
|
|
|
typedef struct MovieClipImBufCacheKey {
|
2019-04-17 06:17:24 +02:00
|
|
|
int framenr;
|
|
|
|
|
int proxy;
|
|
|
|
|
short render_flag;
|
2011-11-07 12:55:18 +00:00
|
|
|
} MovieClipImBufCacheKey;
|
|
|
|
|
|
2012-07-10 14:43:50 +00:00
|
|
|
typedef struct MovieClipCachePriorityData {
|
2019-04-17 06:17:24 +02:00
|
|
|
int framenr;
|
2012-07-10 14:43:50 +00:00
|
|
|
} MovieClipCachePriorityData;
|
|
|
|
|
|
2013-03-25 15:32:11 +00:00
|
|
|
static int user_frame_to_cache_frame(MovieClip *clip, int framenr)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int index;
|
2013-03-25 15:32:11 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
index = framenr - clip->start_frame + clip->frame_offset;
|
2013-03-25 15:32:11 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->source == MCLIP_SRC_SEQUENCE) {
|
|
|
|
|
if (clip->cache->sequence_offset == -1) {
|
|
|
|
|
unsigned short numlen;
|
|
|
|
|
char head[FILE_MAX], tail[FILE_MAX];
|
2013-03-25 15:32:11 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_stringdec(clip->name, head, tail, &numlen);
|
2013-03-25 15:32:11 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* see comment in get_sequence_fname */
|
|
|
|
|
clip->cache->sequence_offset = sequence_guess_offset(clip->name, strlen(head), numlen);
|
|
|
|
|
}
|
2013-03-25 15:32:11 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
index += clip->cache->sequence_offset;
|
|
|
|
|
}
|
2013-03-25 15:32:11 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (index < 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return framenr - index;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-25 15:32:11 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return framenr;
|
2013-03-25 15:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
static void moviecache_keydata(void *userkey, int *framenr, int *proxy, int *render_flags)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const MovieClipImBufCacheKey *key = userkey;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
*framenr = key->framenr;
|
|
|
|
|
*proxy = key->proxy;
|
|
|
|
|
*render_flags = key->render_flag;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned int moviecache_hashhash(const void *keyv)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const MovieClipImBufCacheKey *key = keyv;
|
|
|
|
|
int rval = key->framenr;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return rval;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-25 06:15:52 +10:00
|
|
|
static bool moviecache_hashcmp(const void *av, const void *bv)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const MovieClipImBufCacheKey *a = av;
|
|
|
|
|
const MovieClipImBufCacheKey *b = bv;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ((a->framenr != b->framenr) || (a->proxy != b->proxy) ||
|
|
|
|
|
(a->render_flag != b->render_flag));
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-15 01:52:28 +00:00
|
|
|
static void *moviecache_getprioritydata(void *key_v)
|
2012-07-10 14:43:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey *)key_v;
|
|
|
|
|
MovieClipCachePriorityData *priority_data;
|
2012-07-10 14:43:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
priority_data = MEM_callocN(sizeof(*priority_data), "movie cache clip priority data");
|
|
|
|
|
priority_data->framenr = key->framenr;
|
2012-07-10 14:43:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return priority_data;
|
2012-07-10 14:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-15 01:52:28 +00:00
|
|
|
static int moviecache_getitempriority(void *last_userkey_v, void *priority_data_v)
|
2012-07-10 14:43:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MovieClipImBufCacheKey *last_userkey = (MovieClipImBufCacheKey *)last_userkey_v;
|
|
|
|
|
MovieClipCachePriorityData *priority_data = (MovieClipCachePriorityData *)priority_data_v;
|
2012-07-10 14:43:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return -abs(last_userkey->framenr - priority_data->framenr);
|
2012-07-10 14:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-15 01:52:28 +00:00
|
|
|
static void moviecache_prioritydeleter(void *priority_data_v)
|
2012-07-10 14:43:50 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MovieClipCachePriorityData *priority_data = (MovieClipCachePriorityData *)priority_data_v;
|
2012-07-10 14:43:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(priority_data);
|
2012-07-10 14:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static ImBuf *get_imbuf_cache(MovieClip *clip, const MovieClipUser *user, int flag)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->cache) {
|
|
|
|
|
MovieClipImBufCacheKey key;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!clip->cache->is_still_sequence) {
|
|
|
|
|
key.framenr = user_frame_to_cache_frame(clip, user->framenr);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
key.framenr = 1;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (flag & MCLIP_USE_PROXY) {
|
|
|
|
|
key.proxy = rendersize_to_proxy(user, flag);
|
|
|
|
|
key.render_flag = user->render_flag;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
key.proxy = IMB_PROXY_NONE;
|
|
|
|
|
key.render_flag = 0;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return IMB_moviecache_get(clip->cache->moviecache, &key);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-03 18:55:59 +11:00
|
|
|
static bool has_imbuf_cache(MovieClip *clip, MovieClipUser *user, int flag)
|
2013-03-20 17:03:20 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->cache) {
|
|
|
|
|
MovieClipImBufCacheKey key;
|
2013-03-20 17:03:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
key.framenr = user_frame_to_cache_frame(clip, user->framenr);
|
2013-03-20 17:03:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (flag & MCLIP_USE_PROXY) {
|
|
|
|
|
key.proxy = rendersize_to_proxy(user, flag);
|
|
|
|
|
key.render_flag = user->render_flag;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
key.proxy = IMB_PROXY_NONE;
|
|
|
|
|
key.render_flag = 0;
|
|
|
|
|
}
|
2013-03-20 17:03:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return IMB_moviecache_has_frame(clip->cache->moviecache, &key);
|
|
|
|
|
}
|
2013-03-20 17:03:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2013-03-20 17:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static bool put_imbuf_cache(
|
|
|
|
|
MovieClip *clip, const MovieClipUser *user, ImBuf *ibuf, int flag, bool destructive)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MovieClipImBufCacheKey key;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->cache == NULL) {
|
|
|
|
|
struct MovieCache *moviecache;
|
2012-07-10 14:43:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
// char cache_name[64];
|
|
|
|
|
// BLI_snprintf(cache_name, sizeof(cache_name), "movie %s", clip->id.name);
|
2012-07-10 14:43:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
clip->cache = MEM_callocN(sizeof(MovieClipCache), "movieClipCache");
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
moviecache = IMB_moviecache_create(
|
|
|
|
|
"movieclip", sizeof(MovieClipImBufCacheKey), moviecache_hashhash, moviecache_hashcmp);
|
2012-07-10 14:43:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_moviecache_set_getdata_callback(moviecache, moviecache_keydata);
|
|
|
|
|
IMB_moviecache_set_priority_callback(moviecache,
|
|
|
|
|
moviecache_getprioritydata,
|
|
|
|
|
moviecache_getitempriority,
|
|
|
|
|
moviecache_prioritydeleter);
|
2012-07-10 14:43:50 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
clip->cache->moviecache = moviecache;
|
|
|
|
|
clip->cache->sequence_offset = -1;
|
|
|
|
|
if (clip->source == MCLIP_SRC_SEQUENCE) {
|
|
|
|
|
unsigned short numlen;
|
|
|
|
|
BLI_stringdec(clip->name, NULL, NULL, &numlen);
|
|
|
|
|
clip->cache->is_still_sequence = (numlen == 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!clip->cache->is_still_sequence) {
|
|
|
|
|
key.framenr = user_frame_to_cache_frame(clip, user->framenr);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
key.framenr = 1;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (flag & MCLIP_USE_PROXY) {
|
|
|
|
|
key.proxy = rendersize_to_proxy(user, flag);
|
|
|
|
|
key.render_flag = user->render_flag;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
key.proxy = IMB_PROXY_NONE;
|
|
|
|
|
key.render_flag = 0;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (destructive) {
|
|
|
|
|
IMB_moviecache_put(clip->cache->moviecache, &key, ibuf);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return IMB_moviecache_put_if_possible(clip->cache->moviecache, &key, ibuf);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static bool moviecache_check_free_proxy(ImBuf *UNUSED(ibuf), void *userkey, void *UNUSED(userdata))
|
2014-12-15 22:20:06 +05:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey *)userkey;
|
2014-12-15 22:20:06 +05:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return !(key->proxy == IMB_PROXY_NONE && key->render_flag == 0);
|
2014-12-15 22:20:06 +05:00
|
|
|
}
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
/*********************** common functions *************************/
|
|
|
|
|
|
|
|
|
|
/* only image block itself */
|
2013-02-05 12:46:15 +00:00
|
|
|
static MovieClip *movieclip_alloc(Main *bmain, const char *name)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MovieClip *clip;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
clip = BKE_libblock_alloc(bmain, ID_MC, name, 0);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
clip->aspx = clip->aspy = 1.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_tracking_settings_init(&clip->tracking);
|
|
|
|
|
BKE_color_managed_colorspace_settings_init(&clip->colorspace_settings);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
clip->proxy.build_size_flag = IMB_PROXY_25;
|
|
|
|
|
clip->proxy.build_tc_flag = IMB_TC_RECORD_RUN | IMB_TC_FREE_RUN |
|
|
|
|
|
IMB_TC_INTERPOLATED_REC_DATE_FREE_RUN | IMB_TC_RECORD_RUN_NO_GAPS;
|
|
|
|
|
clip->proxy.quality = 90;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
clip->start_frame = 1;
|
|
|
|
|
clip->frame_offset = 0;
|
2012-06-05 18:38:09 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return clip;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2016-06-08 22:25:23 +10:00
|
|
|
static void movieclip_load_get_size(MovieClip *clip)
|
2012-06-17 16:40:16 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int width, height;
|
|
|
|
|
MovieClipUser user = {0};
|
2012-06-17 16:40:16 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
user.framenr = 1;
|
|
|
|
|
BKE_movieclip_get_size(clip, &user, &width, &height);
|
2012-06-17 16:40:16 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (width && height) {
|
|
|
|
|
clip->tracking.camera.principal[0] = ((float)width) / 2.0f;
|
|
|
|
|
clip->tracking.camera.principal[1] = ((float)height) / 2.0f;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
clip->lastsize[0] = clip->lastsize[1] = IMG_SIZE_FALLBACK;
|
|
|
|
|
}
|
2012-06-17 16:40:16 +00:00
|
|
|
}
|
|
|
|
|
|
2018-06-05 15:10:33 +02:00
|
|
|
static void detect_clip_source(Main *bmain, MovieClip *clip)
|
2012-11-05 10:32:47 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ImBuf *ibuf;
|
|
|
|
|
char name[FILE_MAX];
|
2012-11-05 10:32:47 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(name, clip->name, sizeof(name));
|
|
|
|
|
BLI_path_abs(name, BKE_main_blendfile_path(bmain));
|
2012-11-05 10:32:47 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ibuf = IMB_testiffname(name, IB_rect | IB_multilayer);
|
|
|
|
|
if (ibuf) {
|
|
|
|
|
clip->source = MCLIP_SRC_SEQUENCE;
|
|
|
|
|
IMB_freeImBuf(ibuf);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
clip->source = MCLIP_SRC_MOVIE;
|
|
|
|
|
}
|
2012-11-05 10:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
/* checks if image was already loaded, then returns same image
|
2012-03-03 20:19:11 +00:00
|
|
|
* otherwise creates new.
|
|
|
|
|
* does not load ibuf itself
|
|
|
|
|
* pass on optional frame for #name images */
|
2013-02-05 12:46:15 +00:00
|
|
|
MovieClip *BKE_movieclip_file_add(Main *bmain, const char *name)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MovieClip *clip;
|
|
|
|
|
int file;
|
|
|
|
|
char str[FILE_MAX];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(str, name, sizeof(str));
|
|
|
|
|
BLI_path_abs(str, BKE_main_blendfile_path(bmain));
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* exists? */
|
|
|
|
|
file = BLI_open(str, O_BINARY | O_RDONLY, 0);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (file == -1) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
close(file);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* ** add new movieclip ** */
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* create a short library name */
|
|
|
|
|
clip = movieclip_alloc(bmain, BLI_path_basename(name));
|
|
|
|
|
BLI_strncpy(clip->name, name, sizeof(clip->name));
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
detect_clip_source(bmain, clip);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
movieclip_load_get_size(clip);
|
|
|
|
|
if (clip->lastsize[0]) {
|
|
|
|
|
int width = clip->lastsize[0];
|
2012-06-18 18:22:49 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
clip->tracking.camera.focal = 24.0f * width / clip->tracking.camera.sensor_width;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
movieclip_calc_length(clip);
|
2012-03-26 13:30:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return clip;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-06 19:40:15 +11:00
|
|
|
MovieClip *BKE_movieclip_file_add_exists_ex(Main *bmain, const char *filepath, bool *r_exists)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MovieClip *clip;
|
|
|
|
|
char str[FILE_MAX], strtest[FILE_MAX];
|
2015-10-06 19:40:15 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_strncpy(str, filepath, sizeof(str));
|
|
|
|
|
BLI_path_abs(str, BKE_main_blendfile_path(bmain));
|
2015-10-06 19:40:15 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* first search an identical filepath */
|
|
|
|
|
for (clip = bmain->movieclips.first; clip; clip = clip->id.next) {
|
|
|
|
|
BLI_strncpy(strtest, clip->name, sizeof(clip->name));
|
|
|
|
|
BLI_path_abs(strtest, ID_BLEND_PATH(bmain, &clip->id));
|
2015-10-06 19:40:15 +11:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (BLI_path_cmp(strtest, str) == 0) {
|
|
|
|
|
id_us_plus(&clip->id); /* officially should not, it doesn't link here! */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (r_exists) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*r_exists = true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return clip;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-06 19:40:15 +11:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (r_exists) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*r_exists = false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
return BKE_movieclip_file_add(bmain, filepath);
|
2015-10-06 19:40:15 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MovieClip *BKE_movieclip_file_add_exists(Main *bmain, const char *filepath)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BKE_movieclip_file_add_exists_ex(bmain, filepath, NULL);
|
2015-10-06 19:40:15 +11:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void real_ibuf_size(
|
|
|
|
|
const MovieClip *clip, const MovieClipUser *user, const ImBuf *ibuf, int *width, int *height)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
*width = ibuf->x;
|
|
|
|
|
*height = ibuf->y;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->flag & MCLIP_USE_PROXY) {
|
|
|
|
|
switch (user->render_size) {
|
|
|
|
|
case MCLIP_PROXY_RENDER_SIZE_25:
|
|
|
|
|
(*width) *= 4;
|
|
|
|
|
(*height) *= 4;
|
|
|
|
|
break;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
case MCLIP_PROXY_RENDER_SIZE_50:
|
|
|
|
|
(*width) *= 2.0f;
|
|
|
|
|
(*height) *= 2.0f;
|
|
|
|
|
break;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
case MCLIP_PROXY_RENDER_SIZE_75:
|
|
|
|
|
*width = ((float)*width) * 4.0f / 3.0f;
|
|
|
|
|
*height = ((float)*height) * 4.0f / 3.0f;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
static ImBuf *get_undistorted_ibuf(MovieClip *clip,
|
|
|
|
|
struct MovieDistortion *distortion,
|
|
|
|
|
ImBuf *ibuf)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ImBuf *undistibuf;
|
2012-01-15 13:31:25 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (distortion) {
|
2019-04-17 06:17:24 +02:00
|
|
|
undistibuf = BKE_tracking_distortion_exec(
|
|
|
|
|
distortion, &clip->tracking, ibuf, ibuf->x, ibuf->y, 0.0f, 1);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
undistibuf = BKE_tracking_undistort_frame(&clip->tracking, ibuf, ibuf->x, ibuf->y, 0.0f);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-01-15 13:31:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_scaleImBuf(undistibuf, ibuf->x, ibuf->y);
|
2012-01-15 13:31:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return undistibuf;
|
2012-01-15 13:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-18 12:01:40 -07:00
|
|
|
static bool need_undistortion_postprocess(const MovieClipUser *user, int clip_flag)
|
2012-01-15 13:31:25 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bool result = 0;
|
|
|
|
|
const bool uses_full_frame = ((clip_flag & MCLIP_USE_PROXY) == 0) ||
|
|
|
|
|
(user->render_size == MCLIP_PROXY_RENDER_SIZE_FULL);
|
|
|
|
|
/* Only full undistorted render can be used as on-fly undistorting image. */
|
|
|
|
|
result |= uses_full_frame && (user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT) != 0;
|
|
|
|
|
return result;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-18 12:01:40 -07:00
|
|
|
static bool need_postprocessed_frame(const MovieClipUser *user,
|
|
|
|
|
int clip_flag,
|
|
|
|
|
int postprocess_flag)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bool result = (postprocess_flag != 0);
|
|
|
|
|
result |= need_undistortion_postprocess(user, clip_flag);
|
|
|
|
|
return result;
|
2012-01-15 13:31:25 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
static bool check_undistortion_cache_flags(const MovieClip *clip)
|
2012-01-15 13:31:25 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const MovieClipCache *cache = clip->cache;
|
|
|
|
|
const MovieTrackingCamera *camera = &clip->tracking.camera;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* check for distortion model changes */
|
|
|
|
|
if (!equals_v2v2(camera->principal, cache->postprocessed.principal)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-02-20 19:41:05 +06:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (camera->distortion_model != cache->postprocessed.distortion_model) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!equals_v3v3(&camera->k1, &cache->postprocessed.polynomial_k1)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-02-20 19:41:05 +06:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!equals_v2v2(&camera->division_k1, &cache->postprocessed.division_k1)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
static ImBuf *get_postprocessed_cached_frame(const MovieClip *clip,
|
|
|
|
|
const MovieClipUser *user,
|
|
|
|
|
int flag,
|
|
|
|
|
int postprocess_flag)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
const MovieClipCache *cache = clip->cache;
|
|
|
|
|
int framenr = user->framenr;
|
|
|
|
|
short proxy = IMB_PROXY_NONE;
|
|
|
|
|
int render_flag = 0;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (flag & MCLIP_USE_PROXY) {
|
|
|
|
|
proxy = rendersize_to_proxy(user, flag);
|
|
|
|
|
render_flag = user->render_flag;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* no cache or no cached postprocessed image */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!clip->cache || !clip->cache->postprocessed.ibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* postprocessing happened for other frame */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cache->postprocessed.framenr != framenr) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-01-15 13:31:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* cached ibuf used different proxy settings */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cache->postprocessed.render_flag != render_flag || cache->postprocessed.proxy != proxy) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-01-15 13:31:58 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cache->postprocessed.flag != postprocess_flag) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-01-15 13:31:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (need_undistortion_postprocess(user, flag)) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!check_undistortion_cache_flags(clip)) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
else if (cache->postprocessed.undistortion_used) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_refImBuf(cache->postprocessed.ibuf);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return cache->postprocessed.ibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static ImBuf *postprocess_frame(
|
|
|
|
|
MovieClip *clip, const MovieClipUser *user, ImBuf *ibuf, int flag, int postprocess_flag)
|
2014-02-04 15:16:21 +06:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ImBuf *postproc_ibuf = NULL;
|
2014-02-04 15:16:21 +06:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (need_undistortion_postprocess(user, flag)) {
|
|
|
|
|
postproc_ibuf = get_undistorted_ibuf(clip, NULL, ibuf);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
postproc_ibuf = IMB_dupImBuf(ibuf);
|
|
|
|
|
}
|
2014-02-04 15:16:21 +06:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (postprocess_flag) {
|
|
|
|
|
bool disable_red = (postprocess_flag & MOVIECLIP_DISABLE_RED) != 0;
|
|
|
|
|
bool disable_green = (postprocess_flag & MOVIECLIP_DISABLE_GREEN) != 0;
|
|
|
|
|
bool disable_blue = (postprocess_flag & MOVIECLIP_DISABLE_BLUE) != 0;
|
|
|
|
|
bool grayscale = (postprocess_flag & MOVIECLIP_PREVIEW_GRAYSCALE) != 0;
|
2014-02-04 15:16:21 +06:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (disable_red || disable_green || disable_blue || grayscale) {
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_tracking_disable_channels(postproc_ibuf, disable_red, disable_green, disable_blue, 1);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-02-04 15:16:21 +06:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return postproc_ibuf;
|
2014-02-04 15:16:21 +06:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void put_postprocessed_frame_to_cache(
|
|
|
|
|
MovieClip *clip, const MovieClipUser *user, ImBuf *ibuf, int flag, int postprocess_flag)
|
|
|
|
|
{
|
|
|
|
|
MovieClipCache *cache = clip->cache;
|
|
|
|
|
MovieTrackingCamera *camera = &clip->tracking.camera;
|
|
|
|
|
|
|
|
|
|
cache->postprocessed.framenr = user->framenr;
|
|
|
|
|
cache->postprocessed.flag = postprocess_flag;
|
|
|
|
|
|
|
|
|
|
if (flag & MCLIP_USE_PROXY) {
|
|
|
|
|
cache->postprocessed.proxy = rendersize_to_proxy(user, flag);
|
|
|
|
|
cache->postprocessed.render_flag = user->render_flag;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
cache->postprocessed.proxy = IMB_PROXY_NONE;
|
|
|
|
|
cache->postprocessed.render_flag = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (need_undistortion_postprocess(user, flag)) {
|
|
|
|
|
cache->postprocessed.distortion_model = camera->distortion_model;
|
|
|
|
|
copy_v2_v2(cache->postprocessed.principal, camera->principal);
|
|
|
|
|
copy_v3_v3(&cache->postprocessed.polynomial_k1, &camera->k1);
|
|
|
|
|
copy_v2_v2(&cache->postprocessed.division_k1, &camera->division_k1);
|
|
|
|
|
cache->postprocessed.undistortion_used = true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
cache->postprocessed.undistortion_used = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IMB_refImBuf(ibuf);
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cache->postprocessed.ibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_freeImBuf(cache->postprocessed.ibuf);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
cache->postprocessed.ibuf = ibuf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ImBuf *movieclip_get_postprocessed_ibuf(
|
|
|
|
|
MovieClip *clip, const MovieClipUser *user, int flag, int postprocess_flag, int cache_flag)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ImBuf *ibuf = NULL;
|
|
|
|
|
int framenr = user->framenr;
|
|
|
|
|
bool need_postprocess = false;
|
|
|
|
|
|
|
|
|
|
/* cache isn't threadsafe itself and also loading of movies
|
|
|
|
|
* can't happen from concurrent threads that's why we use lock here */
|
|
|
|
|
BLI_thread_lock(LOCK_MOVIECLIP);
|
|
|
|
|
|
|
|
|
|
/* try to obtain cached postprocessed frame first */
|
|
|
|
|
if (need_postprocessed_frame(user, flag, postprocess_flag)) {
|
|
|
|
|
ibuf = get_postprocessed_cached_frame(clip, user, flag, postprocess_flag);
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!ibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
need_postprocess = true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!ibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
ibuf = get_imbuf_cache(clip, user, flag);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
if (!ibuf) {
|
|
|
|
|
bool use_sequence = false;
|
|
|
|
|
|
|
|
|
|
/* undistorted proxies for movies should be read as image sequence */
|
|
|
|
|
use_sequence = (user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT) &&
|
|
|
|
|
(user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL);
|
|
|
|
|
|
|
|
|
|
if (clip->source == MCLIP_SRC_SEQUENCE || use_sequence) {
|
|
|
|
|
ibuf = movieclip_load_sequence_file(clip, user, framenr, flag);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ibuf = movieclip_load_movie_file(clip, user, framenr, flag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ibuf && (cache_flag & MOVIECLIP_CACHE_SKIP) == 0) {
|
|
|
|
|
put_imbuf_cache(clip, user, ibuf, flag, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ibuf) {
|
|
|
|
|
clip->lastframe = framenr;
|
|
|
|
|
real_ibuf_size(clip, user, ibuf, &clip->lastsize[0], &clip->lastsize[1]);
|
|
|
|
|
|
|
|
|
|
/* postprocess frame and put to cache if needed*/
|
|
|
|
|
if (need_postprocess) {
|
|
|
|
|
ImBuf *tmpibuf = ibuf;
|
|
|
|
|
ibuf = postprocess_frame(clip, user, tmpibuf, flag, postprocess_flag);
|
|
|
|
|
IMB_freeImBuf(tmpibuf);
|
|
|
|
|
if (ibuf && (cache_flag & MOVIECLIP_CACHE_SKIP) == 0) {
|
|
|
|
|
put_postprocessed_frame_to_cache(clip, user, ibuf, flag, postprocess_flag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_thread_unlock(LOCK_MOVIECLIP);
|
|
|
|
|
|
|
|
|
|
/* Fallback render in case proxies are not enabled or built */
|
|
|
|
|
if (!ibuf && user->render_flag & MCLIP_PROXY_RENDER_USE_FALLBACK_RENDER &&
|
|
|
|
|
user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL) {
|
|
|
|
|
MovieClipUser user_fallback = *user;
|
|
|
|
|
user_fallback.render_size = MCLIP_PROXY_RENDER_SIZE_FULL;
|
|
|
|
|
|
|
|
|
|
ibuf = movieclip_get_postprocessed_ibuf(
|
|
|
|
|
clip, &user_fallback, flag, postprocess_flag, cache_flag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
ImBuf *BKE_movieclip_get_ibuf(MovieClip *clip, MovieClipUser *user)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return BKE_movieclip_get_ibuf_flag(clip, user, clip->flag, 0);
|
2012-01-15 13:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-01 19:06:21 +00:00
|
|
|
ImBuf *BKE_movieclip_get_ibuf_flag(MovieClip *clip, MovieClipUser *user, int flag, int cache_flag)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return movieclip_get_postprocessed_ibuf(clip, user, flag, 0, cache_flag);
|
2012-01-15 13:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ImBuf *BKE_movieclip_get_postprocessed_ibuf(MovieClip *clip,
|
|
|
|
|
MovieClipUser *user,
|
|
|
|
|
int postprocess_flag)
|
2012-01-15 13:31:58 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return movieclip_get_postprocessed_ibuf(clip, user, clip->flag, postprocess_flag, 0);
|
2012-01-15 13:31:25 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static ImBuf *get_stable_cached_frame(
|
|
|
|
|
MovieClip *clip, MovieClipUser *user, ImBuf *reference_ibuf, int framenr, int postprocess_flag)
|
2012-01-15 13:31:25 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MovieClipCache *cache = clip->cache;
|
|
|
|
|
MovieTracking *tracking = &clip->tracking;
|
|
|
|
|
ImBuf *stableibuf;
|
|
|
|
|
float tloc[2], tscale, tangle;
|
|
|
|
|
short proxy = IMB_PROXY_NONE;
|
|
|
|
|
int render_flag = 0;
|
|
|
|
|
int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, framenr);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->flag & MCLIP_USE_PROXY) {
|
|
|
|
|
proxy = rendersize_to_proxy(user, clip->flag);
|
|
|
|
|
render_flag = user->render_flag;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* there's no cached frame or it was calculated for another frame */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!cache->stabilized.ibuf || cache->stabilized.framenr != framenr) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cache->stabilized.reference_ibuf != reference_ibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-07-09 10:26:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* cached ibuf used different proxy settings */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cache->stabilized.render_flag != render_flag || cache->stabilized.proxy != proxy) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cache->stabilized.postprocess_flag != postprocess_flag) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-02-16 07:45:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* stabilization also depends on pixel aspect ratio */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cache->stabilized.aspect != tracking->camera.pixel_aspect) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-02-16 15:03:37 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cache->stabilized.filter != tracking->stabilization.filter) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-02-16 15:03:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
stableibuf = cache->stabilized.ibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_tracking_stabilization_data_get(
|
|
|
|
|
clip, clip_framenr, stableibuf->x, stableibuf->y, tloc, &tscale, &tangle);
|
2012-01-15 13:31:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* check for stabilization parameters */
|
|
|
|
|
if (tscale != cache->stabilized.scale || tangle != cache->stabilized.angle ||
|
|
|
|
|
!equals_v2v2(tloc, cache->stabilized.loc)) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_refImBuf(stableibuf);
|
2012-01-15 13:31:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return stableibuf;
|
2012-01-15 13:31:25 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static ImBuf *put_stabilized_frame_to_cache(
|
|
|
|
|
MovieClip *clip, MovieClipUser *user, ImBuf *ibuf, int framenr, int postprocess_flag)
|
2012-01-15 13:31:25 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MovieClipCache *cache = clip->cache;
|
|
|
|
|
MovieTracking *tracking = &clip->tracking;
|
|
|
|
|
ImBuf *stableibuf;
|
|
|
|
|
float tloc[2], tscale, tangle;
|
|
|
|
|
int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, framenr);
|
2012-01-15 13:31:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
stableibuf = BKE_tracking_stabilize_frame(clip, clip_framenr, ibuf, tloc, &tscale, &tangle);
|
2012-01-15 13:31:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
copy_v2_v2(cache->stabilized.loc, tloc);
|
2012-01-15 13:31:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
cache->stabilized.reference_ibuf = ibuf;
|
|
|
|
|
cache->stabilized.scale = tscale;
|
|
|
|
|
cache->stabilized.angle = tangle;
|
|
|
|
|
cache->stabilized.framenr = framenr;
|
|
|
|
|
cache->stabilized.aspect = tracking->camera.pixel_aspect;
|
|
|
|
|
cache->stabilized.filter = tracking->stabilization.filter;
|
2012-01-15 13:31:25 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->flag & MCLIP_USE_PROXY) {
|
|
|
|
|
cache->stabilized.proxy = rendersize_to_proxy(user, clip->flag);
|
|
|
|
|
cache->stabilized.render_flag = user->render_flag;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
cache->stabilized.proxy = IMB_PROXY_NONE;
|
|
|
|
|
cache->stabilized.render_flag = 0;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
cache->stabilized.postprocess_flag = postprocess_flag;
|
2012-02-16 07:45:01 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cache->stabilized.ibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_freeImBuf(cache->stabilized.ibuf);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-07-09 10:26:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
cache->stabilized.ibuf = stableibuf;
|
2012-07-09 10:26:01 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_refImBuf(stableibuf);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return stableibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ImBuf *BKE_movieclip_get_stable_ibuf(MovieClip *clip,
|
|
|
|
|
MovieClipUser *user,
|
|
|
|
|
float loc[2],
|
|
|
|
|
float *scale,
|
|
|
|
|
float *angle,
|
2012-05-07 08:53:59 +00:00
|
|
|
int postprocess_flag)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ImBuf *ibuf, *stableibuf = NULL;
|
|
|
|
|
int framenr = user->framenr;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ibuf = BKE_movieclip_get_postprocessed_ibuf(clip, user, postprocess_flag);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!ibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
|
|
|
|
|
MovieClipCache *cache = clip->cache;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
stableibuf = get_stable_cached_frame(clip, user, ibuf, framenr, postprocess_flag);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!stableibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
stableibuf = put_stabilized_frame_to_cache(clip, user, ibuf, framenr, postprocess_flag);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (loc) {
|
2019-04-17 06:17:24 +02:00
|
|
|
copy_v2_v2(loc, cache->stabilized.loc);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (scale) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*scale = cache->stabilized.scale;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (angle) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*angle = cache->stabilized.angle;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (loc) {
|
2019-04-17 06:17:24 +02:00
|
|
|
zero_v2(loc);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (scale) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*scale = 1.0f;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (angle) {
|
2019-04-17 06:17:24 +02:00
|
|
|
*angle = 0.0f;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
stableibuf = ibuf;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (stableibuf != ibuf) {
|
|
|
|
|
IMB_freeImBuf(ibuf);
|
|
|
|
|
ibuf = stableibuf;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-03 18:55:59 +11:00
|
|
|
bool BKE_movieclip_has_frame(MovieClip *clip, MovieClipUser *user)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, user);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ibuf) {
|
|
|
|
|
IMB_freeImBuf(ibuf);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return false;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_movieclip_get_size(MovieClip *clip, MovieClipUser *user, int *width, int *height)
|
|
|
|
|
{
|
2018-10-19 10:51:18 +02:00
|
|
|
#if 0
|
2019-04-17 06:17:24 +02:00
|
|
|
/* originally was needed to support image sequences with different image dimensions,
|
|
|
|
|
* which might be useful for such things as reconstruction of unordered image sequence,
|
|
|
|
|
* or painting/rotoscoping of non-equal-sized images, but this ended up in unneeded
|
|
|
|
|
* cache lookups and even unwanted non-proxied files loading when doing mask parenting,
|
|
|
|
|
* so let's disable this for now and assume image sequence consists of images with
|
|
|
|
|
* equal sizes (sergey)
|
|
|
|
|
* TODO(sergey): Support reading sequences of different resolution.
|
|
|
|
|
*/
|
|
|
|
|
if (user->framenr == clip->lastframe) {
|
2018-10-19 10:51:18 +02:00
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->lastsize[0] != 0 && clip->lastsize[1] != 0) {
|
|
|
|
|
*width = clip->lastsize[0];
|
|
|
|
|
*height = clip->lastsize[1];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, user);
|
|
|
|
|
|
|
|
|
|
if (ibuf && ibuf->x && ibuf->y) {
|
|
|
|
|
real_ibuf_size(clip, user, ibuf, width, height);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
*width = clip->lastsize[0];
|
|
|
|
|
*height = clip->lastsize[1];
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_freeImBuf(ibuf);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
2012-09-13 05:29:38 +00:00
|
|
|
void BKE_movieclip_get_size_fl(MovieClip *clip, MovieClipUser *user, float size[2])
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
int width, height;
|
|
|
|
|
BKE_movieclip_get_size(clip, user, &width, &height);
|
2012-09-13 05:29:38 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
size[0] = (float)width;
|
|
|
|
|
size[1] = (float)height;
|
2012-09-13 05:29:38 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-26 13:30:53 +00:00
|
|
|
int BKE_movieclip_get_duration(MovieClip *clip)
|
2012-03-21 18:02:29 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (!clip->len) {
|
|
|
|
|
movieclip_calc_length(clip);
|
|
|
|
|
}
|
2012-03-26 13:30:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return clip->len;
|
2012-03-21 18:02:29 +00:00
|
|
|
}
|
|
|
|
|
|
2018-03-05 15:00:04 +01:00
|
|
|
float BKE_movieclip_get_fps(MovieClip *clip)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->source != MCLIP_SRC_MOVIE) {
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
movieclip_open_anim_file(clip);
|
|
|
|
|
if (clip->anim == NULL) {
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
short frs_sec;
|
|
|
|
|
float frs_sec_base;
|
|
|
|
|
if (IMB_anim_get_fps(clip->anim, &frs_sec, &frs_sec_base, true)) {
|
|
|
|
|
return (float)frs_sec / frs_sec_base;
|
|
|
|
|
}
|
|
|
|
|
return 0.0f;
|
2018-03-05 15:00:04 +01:00
|
|
|
}
|
|
|
|
|
|
2012-09-13 05:29:38 +00:00
|
|
|
void BKE_movieclip_get_aspect(MovieClip *clip, float *aspx, float *aspy)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
*aspx = 1.0;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* x is always 1 */
|
|
|
|
|
*aspy = clip->aspy / clip->aspx / clip->tracking.camera.pixel_aspect;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get segments of cached frames. useful for debugging cache policies */
|
2019-04-17 06:17:24 +02:00
|
|
|
void BKE_movieclip_get_cache_segments(MovieClip *clip,
|
|
|
|
|
MovieClipUser *user,
|
|
|
|
|
int *r_totseg,
|
|
|
|
|
int **r_points)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
*r_totseg = 0;
|
|
|
|
|
*r_points = NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->cache) {
|
|
|
|
|
int proxy = rendersize_to_proxy(user, clip->flag);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_moviecache_get_cache_segments(
|
|
|
|
|
clip->cache->moviecache, proxy, user->render_flag, r_totseg, r_points);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_movieclip_user_set_frame(MovieClipUser *iuser, int framenr)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* TODO: clamp framenr here? */
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
iuser->framenr = framenr;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void free_buffers(MovieClip *clip)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->cache) {
|
|
|
|
|
IMB_moviecache_free(clip->cache->moviecache);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (clip->cache->postprocessed.ibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_freeImBuf(clip->cache->postprocessed.ibuf);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (clip->cache->stabilized.ibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_freeImBuf(clip->cache->stabilized.ibuf);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MEM_freeN(clip->cache);
|
|
|
|
|
clip->cache = NULL;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->anim) {
|
|
|
|
|
IMB_free_anim(clip->anim);
|
|
|
|
|
clip->anim = NULL;
|
|
|
|
|
}
|
2019-04-02 16:05:22 +02:00
|
|
|
|
|
|
|
|
MovieClip_RuntimeGPUTexture *tex;
|
|
|
|
|
for (tex = clip->runtime.gputextures.first; tex; tex = tex->next) {
|
|
|
|
|
for (int i = 0; i < TEXTARGET_COUNT; i++) {
|
|
|
|
|
if (tex->gputexture[i] != NULL) {
|
|
|
|
|
GPU_texture_free(tex->gputexture[i]);
|
|
|
|
|
tex->gputexture[i] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BLI_freelistN(&clip->runtime.gputextures);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-04 09:50:51 +00:00
|
|
|
void BKE_movieclip_clear_cache(MovieClip *clip)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
free_buffers(clip);
|
2013-04-04 09:50:51 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-15 22:20:06 +05:00
|
|
|
void BKE_movieclip_clear_proxy_cache(MovieClip *clip)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->cache && clip->cache->moviecache) {
|
|
|
|
|
IMB_moviecache_cleanup(clip->cache->moviecache, moviecache_check_free_proxy, NULL);
|
|
|
|
|
}
|
2014-12-15 22:20:06 +05:00
|
|
|
}
|
|
|
|
|
|
2018-06-05 15:10:33 +02:00
|
|
|
void BKE_movieclip_reload(Main *bmain, MovieClip *clip)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* clear cache */
|
|
|
|
|
free_buffers(clip);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* update clip source */
|
|
|
|
|
detect_clip_source(bmain, clip);
|
2012-03-26 13:30:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
clip->lastsize[0] = clip->lastsize[1] = 0;
|
|
|
|
|
movieclip_load_get_size(clip);
|
2012-06-17 16:40:16 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
movieclip_calc_length(clip);
|
2012-10-18 09:48:51 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* same as for image update -- don't use notifiers because they are not 100% sure to succeeded
|
|
|
|
|
* (node trees which are not currently visible wouldn't be refreshed)
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
Scene *scene;
|
|
|
|
|
for (scene = bmain->scenes.first; scene; scene = scene->id.next) {
|
|
|
|
|
if (scene->nodetree) {
|
|
|
|
|
nodeUpdateID(scene->nodetree, &clip->id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_movieclip_update_scopes(MovieClip *clip, MovieClipUser *user, MovieClipScopes *scopes)
|
|
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (scopes->ok) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (scopes->track_preview) {
|
|
|
|
|
IMB_freeImBuf(scopes->track_preview);
|
|
|
|
|
scopes->track_preview = NULL;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (scopes->track_search) {
|
|
|
|
|
IMB_freeImBuf(scopes->track_search);
|
|
|
|
|
scopes->track_search = NULL;
|
|
|
|
|
}
|
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
scopes->marker = NULL;
|
|
|
|
|
scopes->track = NULL;
|
|
|
|
|
scopes->track_locked = true;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip) {
|
|
|
|
|
MovieTrackingTrack *act_track = BKE_tracking_track_get_active(&clip->tracking);
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (act_track) {
|
|
|
|
|
MovieTrackingTrack *track = act_track;
|
|
|
|
|
int framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, user->framenr);
|
|
|
|
|
MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
scopes->marker = marker;
|
|
|
|
|
scopes->track = track;
|
2012-06-24 14:16:40 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (marker->flag & MARKER_DISABLED) {
|
|
|
|
|
scopes->track_disabled = true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, user);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
scopes->track_disabled = false;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ibuf && (ibuf->rect || ibuf->rect_float)) {
|
|
|
|
|
MovieTrackingMarker undist_marker = *marker;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT) {
|
|
|
|
|
int width, height;
|
|
|
|
|
float aspy = 1.0f / clip->tracking.camera.pixel_aspect;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_movieclip_get_size(clip, user, &width, &height);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
undist_marker.pos[0] *= width;
|
|
|
|
|
undist_marker.pos[1] *= height * aspy;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_tracking_undistort_v2(&clip->tracking, undist_marker.pos, undist_marker.pos);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
undist_marker.pos[0] /= width;
|
|
|
|
|
undist_marker.pos[1] /= height * aspy;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
scopes->track_search = BKE_tracking_get_search_imbuf(
|
|
|
|
|
ibuf, track, &undist_marker, true, true);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
scopes->undist_marker = undist_marker;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
scopes->frame_width = ibuf->x;
|
|
|
|
|
scopes->frame_height = ibuf->y;
|
2012-06-12 11:13:53 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
scopes->use_track_mask = (track->flag & TRACK_PREVIEW_ALPHA) != 0;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_freeImBuf(ibuf);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if ((track->flag & TRACK_LOCKED) == 0) {
|
|
|
|
|
float pat_min[2], pat_max[2];
|
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
scopes->track_locked = false;
|
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* XXX: would work fine with non-transformed patterns, but would likely fail
|
|
|
|
|
* with transformed patterns, but that would be easier to debug when
|
|
|
|
|
* we'll have real pattern sampling (at least to test) */
|
|
|
|
|
BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
|
Planar tracking support for motion tracking
===========================================
Major list of changes done in tomato branch:
- Add a planar tracking implementation to libmv
This adds a new planar tracking implementation to libmv. The
tracker is based on Ceres[1], the new nonlinear minimizer that
myself and Sameer released from Google as open source. Since
the motion model is more involved, the interface is
different than the RegionTracker interface used previously
in Blender.
The start of a C API in libmv-capi.{cpp,h} is also included.
- Migrate from pat_{min,max} for markers to 4 corners representation
Convert markers in the movie clip editor / 2D tracker from using
pat_min and pat_max notation to using the a more general, 4-corner
representation.
There is still considerable porting work to do; in particular
sliding from preview widget does not work correct for rotated
markers.
All other areas should be ported to new representation:
* Added support of sliding individual corners. LMB slide + Ctrl
would scale the whole pattern
* S would scale the whole marker, S-S would scale pattern only
* Added support of marker's rotation which is currently rotates
only patterns around their centers or all markers around median,
Rotation or other non-translation/scaling transformation of search
area doesn't make sense.
* Track Preview widget would display transformed pattern which
libmv actually operates with.
- "Efficient Second-order Minimization" for the planar tracker
This implements the "Efficient Second-order Minimization"
scheme, as supported by the existing translation tracker.
This increases the amount of per-iteration work, but
decreases the number of iterations required to converge and
also increases the size of the basin of attraction for the
optimization.
- Remove the use of the legacy RegionTracker API from Blender,
and replaces it with the new TrackRegion API. This also
adds several features to the planar tracker in libmv:
* Do a brute-force initialization of tracking similar to "Hybrid"
mode in the stable release, but using all floats. This is slower
but more accurate. It is still necessary to evaluate if the
performance loss is worth it. In particular, this change is
necessary to support high bit depth imagery.
* Add support for masks over the search window. This is a step
towards supporting user-defined tracker masks. The tracker masks
will make it easy for users to make a mask for e.g. a ball.
Not exposed into interface yet/
* Add Pearson product moment correlation coefficient checking (aka
"Correlation" in the UI. This causes tracking failure if the
tracked patch is not linearly related to the template.
* Add support for warping a few points in addition to the supplied
points. This is useful because the tracking code deliberately
does not expose the underlying warp representation. Instead,
warps are specified in an aparametric way via the correspondences.
- Replace the old style tracker configuration panel with the
new planar tracking panel. From a users perspective, this means:
* The old "tracking algorithm" picker is gone. There is only 1
algorithm now. We may revisit this later, but I would much
prefer to have only 1 algorithm. So far no optimization work
has been done so the speed is not there yet.
* There is now a dropdown to select the motion model. Choices:
* Translation
* Translation, rotation
* Translation, scale
* Translation, rotation, scale
* Affine
* Perspective
* The old "Hybrid" mode is gone; instead there is a toggle to
enable or disable translation-only tracker initialization. This
is the equivalent of the hyrbid mode before, but rewritten to work
with the new planar tracking modes.
* The pyramid levels setting is gone. At a future date, the planar
tracker will decide to use pyramids or not automatically. The
pyramid setting was ultimately a mistake; with the brute force
initialization it is unnecessary.
- Add light-normalized tracking
Added the ability to normalize patterns by their average value while
tracking, to make them invariant to global illumination changes.
Additional details could be found at wiki page [2]
[1] http://code.google.com/p/ceres-solver
[2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
scopes->slide_scale[0] = pat_max[0] - pat_min[0];
|
|
|
|
|
scopes->slide_scale[1] = pat_max[1] - pat_min[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
scopes->framenr = user->framenr;
|
|
|
|
|
scopes->ok = true;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void movieclip_build_proxy_ibuf(
|
|
|
|
|
MovieClip *clip, ImBuf *ibuf, int cfra, int proxy_render_size, bool undistorted, bool threaded)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
char name[FILE_MAX];
|
|
|
|
|
int quality, rectx, recty;
|
|
|
|
|
int size = rendersize_to_number(proxy_render_size);
|
|
|
|
|
ImBuf *scaleibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
get_proxy_fname(clip, proxy_render_size, undistorted, cfra, name);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
rectx = ibuf->x * size / 100.0f;
|
|
|
|
|
recty = ibuf->y * size / 100.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
scaleibuf = IMB_dupImBuf(ibuf);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (threaded) {
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_scaleImBuf_threaded(scaleibuf, (short)rectx, (short)recty);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_scaleImBuf(scaleibuf, (short)rectx, (short)recty);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
quality = clip->proxy.quality;
|
|
|
|
|
scaleibuf->ftype = IMB_FTYPE_JPG;
|
|
|
|
|
scaleibuf->foptions.quality = quality;
|
|
|
|
|
/* unsupported feature only confuses other s/w */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (scaleibuf->planes == 32) {
|
2019-04-17 06:17:24 +02:00
|
|
|
scaleibuf->planes = 24;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-06-12 09:04:10 +10:00
|
|
|
/* TODO: currently the most weak part of multi-threaded proxies,
|
2019-04-17 06:17:24 +02:00
|
|
|
* could be solved in a way that thread only prepares memory
|
|
|
|
|
* buffer and write to disk happens separately
|
|
|
|
|
*/
|
|
|
|
|
BLI_thread_lock(LOCK_MOVIECLIP);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_make_existing_file(name);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (IMB_saveiff(scaleibuf, name, IB_rect) == 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
perror(name);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_thread_unlock(LOCK_MOVIECLIP);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_freeImBuf(scaleibuf);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-15 16:57:19 +00:00
|
|
|
/* note: currently used by proxy job for movies, threading happens within single frame
|
|
|
|
|
* (meaning scaling shall be threaded)
|
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
void BKE_movieclip_build_proxy_frame(MovieClip *clip,
|
|
|
|
|
int clip_flag,
|
|
|
|
|
struct MovieDistortion *distortion,
|
|
|
|
|
int cfra,
|
|
|
|
|
int *build_sizes,
|
|
|
|
|
int build_count,
|
|
|
|
|
bool undistorted)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ImBuf *ibuf;
|
|
|
|
|
MovieClipUser user;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!build_count) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-15 09:32:59 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
user.framenr = cfra;
|
|
|
|
|
user.render_flag = 0;
|
|
|
|
|
user.render_size = MCLIP_PROXY_RENDER_SIZE_FULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
ibuf = BKE_movieclip_get_ibuf_flag(clip, &user, clip_flag, MOVIECLIP_CACHE_SKIP);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ibuf) {
|
|
|
|
|
ImBuf *tmpibuf = ibuf;
|
|
|
|
|
int i;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (undistorted) {
|
2019-04-17 06:17:24 +02:00
|
|
|
tmpibuf = get_undistorted_ibuf(clip, distortion, ibuf);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (i = 0; i < build_count; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
movieclip_build_proxy_ibuf(clip, tmpibuf, cfra, build_sizes[i], undistorted, true);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_freeImBuf(ibuf);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tmpibuf != ibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_freeImBuf(tmpibuf);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-15 16:57:19 +00:00
|
|
|
/* note: currently used by proxy job for sequences, threading happens within sequence
|
|
|
|
|
* (different threads handles different frames, no threading within frame is needed)
|
|
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
void BKE_movieclip_build_proxy_frame_for_ibuf(MovieClip *clip,
|
|
|
|
|
ImBuf *ibuf,
|
|
|
|
|
struct MovieDistortion *distortion,
|
|
|
|
|
int cfra,
|
|
|
|
|
int *build_sizes,
|
|
|
|
|
int build_count,
|
|
|
|
|
bool undistorted)
|
2013-03-15 16:57:19 +00:00
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!build_count) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-15 16:57:19 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (ibuf) {
|
|
|
|
|
ImBuf *tmpibuf = ibuf;
|
|
|
|
|
int i;
|
2013-03-15 16:57:19 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (undistorted) {
|
2019-04-17 06:17:24 +02:00
|
|
|
tmpibuf = get_undistorted_ibuf(clip, distortion, ibuf);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-15 16:57:19 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
for (i = 0; i < build_count; i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
movieclip_build_proxy_ibuf(clip, tmpibuf, cfra, build_sizes[i], undistorted, false);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-15 16:57:19 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tmpibuf != ibuf) {
|
2019-04-17 06:17:24 +02:00
|
|
|
IMB_freeImBuf(tmpibuf);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-15 16:57:19 +00:00
|
|
|
}
|
|
|
|
|
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
/** Free (or release) any data used by this movie clip (does not free the clip itself). */
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_movieclip_free(MovieClip *clip)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* Also frees animdata. */
|
|
|
|
|
free_buffers(clip);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_tracking_free(&clip->tracking);
|
|
|
|
|
BKE_animdata_free((ID *)clip, false);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
/**
|
2019-04-27 12:07:07 +10:00
|
|
|
* Only copy internal data of MovieClip ID from source
|
|
|
|
|
* to already allocated/initialized destination.
|
|
|
|
|
* You probably never want to use that directly,
|
|
|
|
|
* use #BKE_id_copy or #BKE_id_copy_ex for typical needs.
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
*
|
|
|
|
|
* WARNING! This function will not handle ID user count!
|
|
|
|
|
*
|
2018-12-12 12:50:58 +11:00
|
|
|
* \param flag: Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
*/
|
2019-04-17 06:17:24 +02:00
|
|
|
void BKE_movieclip_copy_data(Main *UNUSED(bmain),
|
|
|
|
|
MovieClip *clip_dst,
|
|
|
|
|
const MovieClip *clip_src,
|
|
|
|
|
const int flag)
|
2016-07-29 23:13:31 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* We never handle usercount here for own data. */
|
|
|
|
|
const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
|
2016-07-29 23:13:31 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
clip_dst->anim = NULL;
|
|
|
|
|
clip_dst->cache = NULL;
|
2016-07-29 23:13:31 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_tracking_copy(&clip_dst->tracking, &clip_src->tracking, flag_subdata);
|
|
|
|
|
clip_dst->tracking_context = NULL;
|
2016-07-29 23:13:31 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_color_managed_colorspace_settings_copy(&clip_dst->colorspace_settings,
|
|
|
|
|
&clip_src->colorspace_settings);
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
}
|
2016-07-29 23:13:31 +02:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
MovieClip *BKE_movieclip_copy(Main *bmain, const MovieClip *clip)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
MovieClip *clip_copy;
|
|
|
|
|
BKE_id_copy(bmain, &clip->id, (ID **)&clip_copy);
|
|
|
|
|
return clip_copy;
|
2016-07-29 23:13:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_movieclip_make_local(Main *bmain, MovieClip *clip, const bool lib_local)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_id_make_local_generic(bmain, &clip->id, true, lib_local);
|
2016-07-29 23:13:31 +02:00
|
|
|
}
|
|
|
|
|
|
2017-12-15 12:23:35 +01:00
|
|
|
float BKE_movieclip_remap_scene_to_clip_frame(const MovieClip *clip, float framenr)
|
2012-06-06 18:58:30 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return framenr - (float)clip->start_frame + 1.0f;
|
2012-06-06 18:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
2017-12-15 12:23:35 +01:00
|
|
|
float BKE_movieclip_remap_clip_to_scene_frame(const MovieClip *clip, float framenr)
|
2012-06-06 18:58:30 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return framenr + (float)clip->start_frame - 1.0f;
|
2012-06-06 18:58:30 +00:00
|
|
|
}
|
2013-03-15 16:57:19 +00:00
|
|
|
|
2013-03-20 17:03:20 +00:00
|
|
|
void BKE_movieclip_filename_for_frame(MovieClip *clip, MovieClipUser *user, char *name)
|
2013-03-15 16:57:19 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->source == MCLIP_SRC_SEQUENCE) {
|
|
|
|
|
int use_proxy;
|
2013-03-20 17:03:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
use_proxy = (clip->flag & MCLIP_USE_PROXY) &&
|
|
|
|
|
user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL;
|
2013-03-20 17:03:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (use_proxy) {
|
|
|
|
|
int undistort = user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT;
|
|
|
|
|
get_proxy_fname(clip, user->render_size, undistort, user->framenr, name);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
get_sequence_fname(clip, user->framenr, name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_strncpy(name, clip->name, FILE_MAX);
|
|
|
|
|
BLI_path_abs(name, ID_BLEND_PATH_FROM_GLOBAL(&clip->id));
|
|
|
|
|
}
|
2013-03-15 16:57:19 +00:00
|
|
|
}
|
2013-03-20 17:03:20 +00:00
|
|
|
|
|
|
|
|
ImBuf *BKE_movieclip_anim_ibuf_for_frame(MovieClip *clip, MovieClipUser *user)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ImBuf *ibuf = NULL;
|
2013-03-20 17:03:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
if (clip->source == MCLIP_SRC_MOVIE) {
|
|
|
|
|
BLI_thread_lock(LOCK_MOVIECLIP);
|
|
|
|
|
ibuf = movieclip_load_movie_file(clip, user, user->framenr, clip->flag);
|
|
|
|
|
BLI_thread_unlock(LOCK_MOVIECLIP);
|
|
|
|
|
}
|
2013-03-20 17:03:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return ibuf;
|
2013-03-20 17:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-03 18:55:59 +11:00
|
|
|
bool BKE_movieclip_has_cached_frame(MovieClip *clip, MovieClipUser *user)
|
2013-03-20 17:03:20 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bool has_frame = false;
|
2013-03-20 17:03:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_thread_lock(LOCK_MOVIECLIP);
|
|
|
|
|
has_frame = has_imbuf_cache(clip, user, clip->flag);
|
|
|
|
|
BLI_thread_unlock(LOCK_MOVIECLIP);
|
2013-03-20 17:03:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return has_frame;
|
2013-03-20 17:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bool BKE_movieclip_put_frame_if_possible(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf)
|
2013-03-20 17:03:20 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bool result;
|
2013-03-20 17:03:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_thread_lock(LOCK_MOVIECLIP);
|
|
|
|
|
result = put_imbuf_cache(clip, user, ibuf, clip->flag, false);
|
|
|
|
|
BLI_thread_unlock(LOCK_MOVIECLIP);
|
2013-03-20 17:03:20 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return result;
|
2013-03-20 17:03:20 +00:00
|
|
|
}
|
2017-10-25 11:45:31 +02:00
|
|
|
|
2018-08-15 10:00:38 -03:00
|
|
|
static void movieclip_selection_synchronize(MovieClip *clip_dst, const MovieClip *clip_src)
|
2018-08-13 16:59:42 -03:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_assert(clip_dst != clip_src);
|
|
|
|
|
MovieTracking *tracking_dst = &clip_dst->tracking, tracking_src = clip_src->tracking;
|
|
|
|
|
/* Syncs the active object, track and plane track. */
|
|
|
|
|
tracking_dst->objectnr = tracking_src.objectnr;
|
|
|
|
|
const int active_track_index = BLI_findindex(&tracking_src.tracks, tracking_src.act_track);
|
|
|
|
|
const int active_plane_track_index = BLI_findindex(&tracking_src.plane_tracks,
|
|
|
|
|
tracking_src.act_plane_track);
|
|
|
|
|
tracking_dst->act_track = BLI_findlink(&tracking_dst->tracks, active_track_index);
|
|
|
|
|
tracking_dst->act_plane_track = BLI_findlink(&tracking_dst->plane_tracks,
|
|
|
|
|
active_plane_track_index);
|
|
|
|
|
|
|
|
|
|
/* Syncs the tracking selection flag. */
|
|
|
|
|
MovieTrackingObject *tracking_object_dst, *tracking_object_src;
|
|
|
|
|
tracking_object_src = tracking_src.objects.first;
|
|
|
|
|
|
|
|
|
|
for (tracking_object_dst = tracking_dst->objects.first; tracking_object_dst != NULL;
|
|
|
|
|
tracking_object_dst = tracking_object_dst->next,
|
|
|
|
|
tracking_object_src = tracking_object_src->next) {
|
|
|
|
|
ListBase *tracksbase_dst, *tracksbase_src;
|
|
|
|
|
tracksbase_dst = BKE_tracking_object_get_tracks(tracking_dst, tracking_object_dst);
|
|
|
|
|
tracksbase_src = BKE_tracking_object_get_tracks(&tracking_src, tracking_object_src);
|
|
|
|
|
|
|
|
|
|
MovieTrackingTrack *track_dst, *track_src;
|
|
|
|
|
track_src = tracksbase_src->first;
|
|
|
|
|
for (track_dst = tracksbase_dst->first; track_dst != NULL;
|
|
|
|
|
track_dst = track_dst->next, track_src = track_src->next) {
|
|
|
|
|
track_dst->flag = track_src->flag;
|
|
|
|
|
track_dst->pat_flag = track_src->pat_flag;
|
|
|
|
|
track_dst->search_flag = track_src->search_flag;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-13 16:59:42 -03:00
|
|
|
}
|
|
|
|
|
|
2019-07-28 15:05:10 +02:00
|
|
|
static void movieclip_eval_update_reload(struct Depsgraph *depsgraph, Main *bmain, MovieClip *clip)
|
2019-07-28 13:24:18 +02:00
|
|
|
{
|
|
|
|
|
BKE_movieclip_reload(bmain, clip);
|
|
|
|
|
if (DEG_is_active(depsgraph)) {
|
|
|
|
|
MovieClip *clip_orig = (MovieClip *)DEG_get_original_id(&clip->id);
|
|
|
|
|
BKE_movieclip_reload(bmain, clip_orig);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 15:05:10 +02:00
|
|
|
static void movieclip_eval_update_generic(struct Depsgraph *depsgraph, MovieClip *clip)
|
2017-10-25 11:45:31 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BKE_tracking_dopesheet_tag_update(&clip->tracking);
|
|
|
|
|
if (DEG_is_active(depsgraph)) {
|
|
|
|
|
MovieClip *clip_orig = (MovieClip *)DEG_get_original_id(&clip->id);
|
|
|
|
|
BKE_tracking_dopesheet_tag_update(&clip_orig->tracking);
|
|
|
|
|
}
|
2017-10-25 11:45:31 +02:00
|
|
|
}
|
2018-08-13 16:59:42 -03:00
|
|
|
|
2019-07-28 13:24:18 +02:00
|
|
|
void BKE_movieclip_eval_update(struct Depsgraph *depsgraph, Main *bmain, MovieClip *clip)
|
|
|
|
|
{
|
|
|
|
|
DEG_debug_print_eval(depsgraph, __func__, clip->id.name, clip);
|
|
|
|
|
if (clip->id.recalc & ID_RECALC_SOURCE) {
|
|
|
|
|
movieclip_eval_update_reload(depsgraph, bmain, clip);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
movieclip_eval_update_generic(depsgraph, clip);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 16:59:42 -03:00
|
|
|
void BKE_movieclip_eval_selection_update(struct Depsgraph *depsgraph, MovieClip *clip)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
DEG_debug_print_eval(depsgraph, __func__, clip->id.name, clip);
|
|
|
|
|
movieclip_selection_synchronize(clip, (MovieClip *)clip->id.orig_id);
|
2018-08-13 16:59:42 -03:00
|
|
|
}
|