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
|
|
|
*/
|
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include <fcntl.h>
|
2011-11-07 12:55:18 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.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"
|
|
|
|
|
|
2020-09-10 14:53:11 +02:00
|
|
|
/* Allow using deprecated functionality for .blend file I/O. */
|
|
|
|
|
#define DNA_DEPRECATED_ALLOW
|
|
|
|
|
|
2020-10-08 17:18:15 +02:00
|
|
|
#include "DNA_defaults.h"
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
#include "DNA_constraint_types.h"
|
2020-05-15 18:29:50 +02:00
|
|
|
#include "DNA_gpencil_types.h"
|
2011-11-07 12:55:18 +00:00
|
|
|
#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"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
#include "DNA_space_types.h"
|
2011-11-07 12:55:18 +00:00
|
|
|
#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"
|
|
|
|
|
|
2020-03-09 16:24:23 +01:00
|
|
|
#include "BLT_translation.h"
|
|
|
|
|
|
2020-09-10 14:53:11 +02:00
|
|
|
#include "BKE_anim_data.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"
|
2020-03-09 16:24:23 +01:00
|
|
|
#include "BKE_idtype.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_image.h" /* openanim */
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2020-05-15 18:29:50 +02:00
|
|
|
#include "BKE_lib_query.h"
|
2011-11-07 12:55:18 +00:00
|
|
|
#include "BKE_main.h"
|
|
|
|
|
#include "BKE_movieclip.h"
|
2012-10-01 07:54:37 +00:00
|
|
|
#include "BKE_node.h"
|
2011-11-07 12:55:18 +00:00
|
|
|
#include "BKE_tracking.h"
|
|
|
|
|
|
|
|
|
|
#include "IMB_imbuf.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "IMB_imbuf_types.h"
|
2011-11-07 12:55:18 +00:00
|
|
|
#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"
|
|
|
|
|
|
2020-09-10 14:53:11 +02:00
|
|
|
#include "BLO_read_write.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
|
|
|
|
|
|
2020-03-09 16:24:23 +01:00
|
|
|
static void free_buffers(MovieClip *clip);
|
|
|
|
|
|
2020-10-08 17:18:15 +02:00
|
|
|
static void movie_clip_init_data(ID *id)
|
|
|
|
|
{
|
|
|
|
|
MovieClip *movie_clip = (MovieClip *)id;
|
|
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(movie_clip, id));
|
|
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(movie_clip, DNA_struct_default_get(MovieClip), id);
|
|
|
|
|
|
|
|
|
|
BKE_tracking_settings_init(&movie_clip->tracking);
|
|
|
|
|
BKE_color_managed_colorspace_settings_init(&movie_clip->colorspace_settings);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-09 16:24:23 +01:00
|
|
|
static void movie_clip_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag)
|
|
|
|
|
{
|
|
|
|
|
MovieClip *movie_clip_dst = (MovieClip *)id_dst;
|
|
|
|
|
const MovieClip *movie_clip_src = (const MovieClip *)id_src;
|
|
|
|
|
|
|
|
|
|
/* We never handle usercount here for own data. */
|
|
|
|
|
const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
|
|
|
|
|
|
|
|
|
|
movie_clip_dst->anim = NULL;
|
|
|
|
|
movie_clip_dst->cache = NULL;
|
|
|
|
|
|
|
|
|
|
BKE_tracking_copy(&movie_clip_dst->tracking, &movie_clip_src->tracking, flag_subdata);
|
|
|
|
|
movie_clip_dst->tracking_context = NULL;
|
|
|
|
|
|
|
|
|
|
BKE_color_managed_colorspace_settings_copy(&movie_clip_dst->colorspace_settings,
|
|
|
|
|
&movie_clip_src->colorspace_settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void movie_clip_free_data(ID *id)
|
|
|
|
|
{
|
|
|
|
|
MovieClip *movie_clip = (MovieClip *)id;
|
|
|
|
|
|
|
|
|
|
/* Also frees animdata. */
|
|
|
|
|
free_buffers(movie_clip);
|
|
|
|
|
|
|
|
|
|
BKE_tracking_free(&movie_clip->tracking);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 18:29:50 +02:00
|
|
|
static void movie_clip_foreach_id(ID *id, LibraryForeachIDData *data)
|
|
|
|
|
{
|
|
|
|
|
MovieClip *movie_clip = (MovieClip *)id;
|
|
|
|
|
MovieTracking *tracking = &movie_clip->tracking;
|
|
|
|
|
|
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, movie_clip->gpd, IDWALK_CB_USER);
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking->tracks) {
|
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, track->gpd, IDWALK_CB_USER);
|
|
|
|
|
}
|
|
|
|
|
LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) {
|
|
|
|
|
LISTBASE_FOREACH (MovieTrackingTrack *, track, &object->tracks) {
|
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, track->gpd, IDWALK_CB_USER);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, &tracking->plane_tracks) {
|
|
|
|
|
BKE_LIB_FOREACHID_PROCESS(data, plane_track->image, IDWALK_CB_USER);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-03 16:55:13 +02:00
|
|
|
static void movie_clip_foreach_cache(ID *id,
|
|
|
|
|
IDTypeForeachCacheFunctionCallback function_callback,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
|
|
|
|
MovieClip *movie_clip = (MovieClip *)id;
|
|
|
|
|
IDCacheKey key = {
|
|
|
|
|
.id_session_uuid = id->session_uuid,
|
|
|
|
|
.offset_in_ID = offsetof(MovieClip, cache),
|
|
|
|
|
.cache_v = movie_clip->cache,
|
|
|
|
|
};
|
2020-07-06 15:07:12 +02:00
|
|
|
function_callback(id, &key, (void **)&movie_clip->cache, 0, user_data);
|
2020-07-03 16:55:13 +02:00
|
|
|
|
|
|
|
|
key.offset_in_ID = offsetof(MovieClip, tracking.camera.intrinsics);
|
|
|
|
|
key.cache_v = movie_clip->tracking.camera.intrinsics;
|
2020-07-06 15:07:12 +02:00
|
|
|
function_callback(id, &key, (void **)&movie_clip->tracking.camera.intrinsics, 0, user_data);
|
2020-07-03 16:55:13 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-10 14:53:11 +02:00
|
|
|
static void write_movieTracks(BlendWriter *writer, ListBase *tracks)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingTrack *track;
|
|
|
|
|
|
|
|
|
|
track = tracks->first;
|
|
|
|
|
while (track) {
|
|
|
|
|
BLO_write_struct(writer, MovieTrackingTrack, track);
|
|
|
|
|
|
|
|
|
|
if (track->markers) {
|
|
|
|
|
BLO_write_struct_array(writer, MovieTrackingMarker, track->markersnr, track->markers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
track = track->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void write_moviePlaneTracks(BlendWriter *writer, ListBase *plane_tracks_base)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingPlaneTrack *plane_track;
|
|
|
|
|
|
|
|
|
|
for (plane_track = plane_tracks_base->first; plane_track; plane_track = plane_track->next) {
|
|
|
|
|
BLO_write_struct(writer, MovieTrackingPlaneTrack, plane_track);
|
|
|
|
|
|
|
|
|
|
BLO_write_pointer_array(writer, plane_track->point_tracksnr, plane_track->point_tracks);
|
|
|
|
|
BLO_write_struct_array(
|
|
|
|
|
writer, MovieTrackingPlaneMarker, plane_track->markersnr, plane_track->markers);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void write_movieReconstruction(BlendWriter *writer,
|
|
|
|
|
MovieTrackingReconstruction *reconstruction)
|
|
|
|
|
{
|
|
|
|
|
if (reconstruction->camnr) {
|
|
|
|
|
BLO_write_struct_array(
|
|
|
|
|
writer, MovieReconstructedCamera, reconstruction->camnr, reconstruction->cameras);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void movieclip_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
|
|
|
|
{
|
|
|
|
|
MovieClip *clip = (MovieClip *)id;
|
|
|
|
|
if (clip->id.us > 0 || BLO_write_is_undo(writer)) {
|
|
|
|
|
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
|
|
|
|
clip->anim = NULL;
|
|
|
|
|
clip->tracking_context = NULL;
|
|
|
|
|
clip->tracking.stats = NULL;
|
|
|
|
|
|
|
|
|
|
MovieTracking *tracking = &clip->tracking;
|
|
|
|
|
MovieTrackingObject *object;
|
|
|
|
|
|
|
|
|
|
BLO_write_id_struct(writer, MovieClip, id_address, &clip->id);
|
|
|
|
|
BKE_id_blend_write(writer, &clip->id);
|
|
|
|
|
|
|
|
|
|
if (clip->adt) {
|
|
|
|
|
BKE_animdata_blend_write(writer, clip->adt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
write_movieTracks(writer, &tracking->tracks);
|
|
|
|
|
write_moviePlaneTracks(writer, &tracking->plane_tracks);
|
|
|
|
|
write_movieReconstruction(writer, &tracking->reconstruction);
|
|
|
|
|
|
|
|
|
|
object = tracking->objects.first;
|
|
|
|
|
while (object) {
|
|
|
|
|
BLO_write_struct(writer, MovieTrackingObject, object);
|
|
|
|
|
|
|
|
|
|
write_movieTracks(writer, &object->tracks);
|
|
|
|
|
write_moviePlaneTracks(writer, &object->plane_tracks);
|
|
|
|
|
write_movieReconstruction(writer, &object->reconstruction);
|
|
|
|
|
|
|
|
|
|
object = object->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void direct_link_movieReconstruction(BlendDataReader *reader,
|
|
|
|
|
MovieTrackingReconstruction *reconstruction)
|
|
|
|
|
{
|
|
|
|
|
BLO_read_data_address(reader, &reconstruction->cameras);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void direct_link_movieTracks(BlendDataReader *reader, ListBase *tracksbase)
|
|
|
|
|
{
|
|
|
|
|
BLO_read_list(reader, tracksbase);
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) {
|
|
|
|
|
BLO_read_data_address(reader, &track->markers);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void direct_link_moviePlaneTracks(BlendDataReader *reader, ListBase *plane_tracks_base)
|
|
|
|
|
{
|
|
|
|
|
BLO_read_list(reader, plane_tracks_base);
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, plane_tracks_base) {
|
|
|
|
|
BLO_read_pointer_array(reader, (void **)&plane_track->point_tracks);
|
|
|
|
|
for (int i = 0; i < plane_track->point_tracksnr; i++) {
|
|
|
|
|
BLO_read_data_address(reader, &plane_track->point_tracks[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLO_read_data_address(reader, &plane_track->markers);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void movieclip_blend_read_data(BlendDataReader *reader, ID *id)
|
|
|
|
|
{
|
|
|
|
|
MovieClip *clip = (MovieClip *)id;
|
|
|
|
|
MovieTracking *tracking = &clip->tracking;
|
|
|
|
|
|
|
|
|
|
BLO_read_data_address(reader, &clip->adt);
|
2020-11-16 12:11:09 +01:00
|
|
|
BKE_animdata_blend_read_data(reader, clip->adt);
|
2020-09-10 14:53:11 +02:00
|
|
|
|
|
|
|
|
direct_link_movieTracks(reader, &tracking->tracks);
|
|
|
|
|
direct_link_moviePlaneTracks(reader, &tracking->plane_tracks);
|
|
|
|
|
direct_link_movieReconstruction(reader, &tracking->reconstruction);
|
|
|
|
|
|
|
|
|
|
BLO_read_data_address(reader, &clip->tracking.act_track);
|
|
|
|
|
BLO_read_data_address(reader, &clip->tracking.act_plane_track);
|
|
|
|
|
|
|
|
|
|
clip->anim = NULL;
|
|
|
|
|
clip->tracking_context = NULL;
|
|
|
|
|
clip->tracking.stats = NULL;
|
|
|
|
|
|
|
|
|
|
/* TODO we could store those in undo cache storage as well, and preserve them instead of
|
|
|
|
|
* re-creating them... */
|
|
|
|
|
BLI_listbase_clear(&clip->runtime.gputextures);
|
|
|
|
|
|
|
|
|
|
/* Needed for proper versioning, will be NULL for all newer files anyway. */
|
|
|
|
|
BLO_read_data_address(reader, &clip->tracking.stabilization.rot_track);
|
|
|
|
|
|
|
|
|
|
clip->tracking.dopesheet.ok = 0;
|
|
|
|
|
BLI_listbase_clear(&clip->tracking.dopesheet.channels);
|
|
|
|
|
BLI_listbase_clear(&clip->tracking.dopesheet.coverage_segments);
|
|
|
|
|
|
|
|
|
|
BLO_read_list(reader, &tracking->objects);
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) {
|
|
|
|
|
direct_link_movieTracks(reader, &object->tracks);
|
|
|
|
|
direct_link_moviePlaneTracks(reader, &object->plane_tracks);
|
|
|
|
|
direct_link_movieReconstruction(reader, &object->reconstruction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lib_link_movieTracks(BlendLibReader *reader, MovieClip *clip, ListBase *tracksbase)
|
|
|
|
|
{
|
|
|
|
|
LISTBASE_FOREACH (MovieTrackingTrack *, track, tracksbase) {
|
|
|
|
|
BLO_read_id_address(reader, clip->id.lib, &track->gpd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lib_link_moviePlaneTracks(BlendLibReader *reader,
|
|
|
|
|
MovieClip *clip,
|
|
|
|
|
ListBase *tracksbase)
|
|
|
|
|
{
|
|
|
|
|
LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track, tracksbase) {
|
|
|
|
|
BLO_read_id_address(reader, clip->id.lib, &plane_track->image);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void movieclip_blend_read_lib(BlendLibReader *reader, ID *id)
|
|
|
|
|
{
|
|
|
|
|
MovieClip *clip = (MovieClip *)id;
|
|
|
|
|
MovieTracking *tracking = &clip->tracking;
|
|
|
|
|
|
|
|
|
|
BLO_read_id_address(reader, clip->id.lib, &clip->gpd);
|
|
|
|
|
|
|
|
|
|
lib_link_movieTracks(reader, clip, &tracking->tracks);
|
|
|
|
|
lib_link_moviePlaneTracks(reader, clip, &tracking->plane_tracks);
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (MovieTrackingObject *, object, &tracking->objects) {
|
|
|
|
|
lib_link_movieTracks(reader, clip, &object->tracks);
|
|
|
|
|
lib_link_moviePlaneTracks(reader, clip, &object->plane_tracks);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-09 16:24:23 +01:00
|
|
|
IDTypeInfo IDType_ID_MC = {
|
|
|
|
|
.id_code = ID_MC,
|
|
|
|
|
.id_filter = FILTER_ID_MC,
|
|
|
|
|
.main_listbase_index = INDEX_ID_MC,
|
|
|
|
|
.struct_size = sizeof(MovieClip),
|
|
|
|
|
.name = "MovieClip",
|
|
|
|
|
.name_plural = "movieclips",
|
|
|
|
|
.translation_context = BLT_I18NCONTEXT_ID_MOVIECLIP,
|
|
|
|
|
.flags = 0,
|
|
|
|
|
|
2020-10-08 17:18:15 +02:00
|
|
|
.init_data = movie_clip_init_data,
|
2020-03-09 16:24:23 +01:00
|
|
|
.copy_data = movie_clip_copy_data,
|
|
|
|
|
.free_data = movie_clip_free_data,
|
|
|
|
|
.make_local = NULL,
|
2020-05-15 18:29:50 +02:00
|
|
|
.foreach_id = movie_clip_foreach_id,
|
2020-07-03 16:55:13 +02:00
|
|
|
.foreach_cache = movie_clip_foreach_cache,
|
2020-08-28 13:05:48 +02:00
|
|
|
|
2020-09-10 14:53:11 +02:00
|
|
|
.blend_write = movieclip_blend_write,
|
|
|
|
|
.blend_read_data = movieclip_blend_read_data,
|
|
|
|
|
.blend_read_lib = movieclip_blend_read_lib,
|
2020-08-28 13:05:48 +02:00
|
|
|
.blend_read_expand = NULL,
|
2020-11-03 11:39:36 +01:00
|
|
|
|
|
|
|
|
.blend_read_undo_preserve = NULL,
|
2020-03-09 16:24:23 +01:00
|
|
|
};
|
|
|
|
|
|
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
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
char num[FILE_MAX] = {0};
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
BLI_strncpy(num, full_name + head_len, numlen + 1);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return atoi(num);
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2011-11-07 12:55:18 +00:00
|
|
|
return IMB_PROXY_NONE;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
switch (user->render_size) {
|
2011-11-07 12:55:18 +00:00
|
|
|
case MCLIP_PROXY_RENDER_SIZE_25:
|
|
|
|
|
return IMB_PROXY_25;
|
|
|
|
|
|
|
|
|
|
case MCLIP_PROXY_RENDER_SIZE_50:
|
|
|
|
|
return IMB_PROXY_50;
|
|
|
|
|
|
|
|
|
|
case MCLIP_PROXY_RENDER_SIZE_75:
|
|
|
|
|
return IMB_PROXY_75;
|
|
|
|
|
|
|
|
|
|
case MCLIP_PROXY_RENDER_SIZE_100:
|
|
|
|
|
return IMB_PROXY_100;
|
|
|
|
|
|
|
|
|
|
case MCLIP_PROXY_RENDER_SIZE_FULL:
|
|
|
|
|
return IMB_PROXY_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return IMB_PROXY_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int rendersize_to_number(int render_size)
|
|
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
switch (render_size) {
|
2011-11-07 12:55:18 +00:00
|
|
|
case MCLIP_PROXY_RENDER_SIZE_25:
|
|
|
|
|
return 25;
|
|
|
|
|
|
|
|
|
|
case MCLIP_PROXY_RENDER_SIZE_50:
|
|
|
|
|
return 50;
|
|
|
|
|
|
|
|
|
|
case MCLIP_PROXY_RENDER_SIZE_75:
|
|
|
|
|
return 75;
|
|
|
|
|
|
|
|
|
|
case MCLIP_PROXY_RENDER_SIZE_100:
|
|
|
|
|
return 100;
|
|
|
|
|
|
|
|
|
|
case MCLIP_PROXY_RENDER_SIZE_FULL:
|
|
|
|
|
return 100;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 100;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int get_timecode(MovieClip *clip, int flag)
|
|
|
|
|
{
|
2019-04-22 09:39:35 +10:00
|
|
|
if ((flag & MCLIP_USE_PROXY) == 0) {
|
2011-11-07 12:55:18 +00:00
|
|
|
return IMB_TC_NONE;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return clip->proxy.tc;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
static void get_sequence_fname(const MovieClip *clip, const int framenr, char *name)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
unsigned short numlen;
|
|
|
|
|
char head[FILE_MAX], tail[FILE_MAX];
|
|
|
|
|
int offset;
|
|
|
|
|
|
2020-06-23 09:54:14 +10:00
|
|
|
BLI_strncpy(name, clip->filepath, sizeof(clip->filepath));
|
2020-04-07 12:02:21 +10:00
|
|
|
BLI_path_sequence_decode(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. */
|
2020-06-23 09:54:14 +10:00
|
|
|
offset = sequence_guess_offset(clip->filepath, strlen(head), numlen);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
if (numlen) {
|
2020-04-07 12:02:21 +10:00
|
|
|
BLI_path_sequence_encode(
|
2016-03-15 14:59:59 +05:00
|
|
|
name, head, tail, numlen, offset + framenr - clip->start_frame + clip->frame_offset);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2020-06-23 09:54:14 +10:00
|
|
|
BLI_strncpy(name, clip->filepath, sizeof(clip->filepath));
|
2016-03-15 14:59:59 +05:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2018-06-12 11:21:54 +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 */
|
2016-03-15 14:59:59 +05: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
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
int size = rendersize_to_number(proxy_render_size);
|
2011-11-07 12:55:18 +00:00
|
|
|
char dir[FILE_MAX], clipdir[FILE_MAX], clipfile[FILE_MAX];
|
2012-06-12 21:25:23 +00:00
|
|
|
int proxynr = framenr - clip->start_frame + 1 + clip->frame_offset;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2020-06-23 09:54:14 +10:00
|
|
|
BLI_split_dirfile(clip->filepath, clipdir, clipfile, FILE_MAX, FILE_MAX);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (clip->flag & MCLIP_USE_PROXY_CUSTOM_DIR) {
|
2011-11-07 15:19:26 +00:00
|
|
|
BLI_strncpy(dir, clip->proxy.dir, sizeof(dir));
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-11-07 12:55:18 +00:00
|
|
|
BLI_snprintf(dir, FILE_MAX, "%s/BL_proxy", clipdir);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (undistorted) {
|
2012-06-06 18:58:30 +00: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 {
|
2012-06-06 18:58:30 +00: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
|
|
|
|
2018-06-05 15:10:33 +02:00
|
|
|
BLI_path_abs(name, BKE_main_blendfile_path_from_global());
|
2011-11-07 12:55:18 +00:00
|
|
|
BLI_path_frame(name, 1, 0);
|
|
|
|
|
|
|
|
|
|
strcat(name, ".jpg");
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-05 16:50:57 +01:00
|
|
|
#ifdef WITH_OPENEXR
|
|
|
|
|
|
2019-02-05 16:23:53 +01:00
|
|
|
typedef struct MultilayerConvertContext {
|
|
|
|
|
float *combined_pass;
|
|
|
|
|
int num_combined_channels;
|
|
|
|
|
} MultilayerConvertContext;
|
|
|
|
|
|
|
|
|
|
static void *movieclip_convert_multilayer_add_view(void *UNUSED(ctx_v),
|
|
|
|
|
const char *UNUSED(view_name))
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-05 16:23:53 +01:00
|
|
|
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;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-05 16:23:53 +01:00
|
|
|
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;
|
|
|
|
|
}
|
2020-11-06 15:29:25 +11:00
|
|
|
if (STREQ(pass_name, RE_PASSNAME_COMBINED) || STR_ELEM(chan_id, "RGBA", "RGB")) {
|
2019-02-05 16:23:53 +01:00
|
|
|
ctx->combined_pass = rect;
|
|
|
|
|
ctx->num_combined_channels = num_channels;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
MEM_freeN(rect);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-05 16:50:57 +01:00
|
|
|
#endif /* WITH_OPENEXR */
|
|
|
|
|
|
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-02-05 16:50:57 +01:00
|
|
|
if (ibuf == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#ifdef WITH_OPENEXR
|
|
|
|
|
if (ibuf->ftype != IMB_FTYPE_OPENEXR || ibuf->userdata == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-02-05 16:23:53 +01:00
|
|
|
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
|
|
|
{
|
|
|
|
|
struct ImBuf *ibuf;
|
|
|
|
|
char name[FILE_MAX];
|
2014-03-31 17:59:50 +06:00
|
|
|
int loadflag;
|
|
|
|
|
bool use_proxy = false;
|
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
|
|
|
char *colorspace;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
use_proxy = (flag & MCLIP_USE_PROXY) && user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (use_proxy) {
|
2012-03-25 23:19:21 +00:00
|
|
|
int undistort = user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT;
|
2011-11-07 12:55:18 +00:00
|
|
|
get_proxy_fname(clip, user->render_size, undistort, framenr, name);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-06 17:27:16 +06:00
|
|
|
/* 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;
|
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
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
|
|
|
else {
|
2011-11-07 12:55:18 +00:00
|
|
|
get_sequence_fname(clip, framenr, name);
|
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
|
|
|
colorspace = clip->colorspace_settings.name;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-06-12 15:25:46 +02:00
|
|
|
loadflag = IB_rect | IB_multilayer | IB_alphamode_detect | IB_metadata;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
/* read ibuf */
|
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
|
|
|
ibuf = IMB_loadiffname(name, loadflag, colorspace);
|
2019-02-05 16:50:57 +01:00
|
|
|
BKE_movieclip_convert_multilayer_ibuf(ibuf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
return ibuf;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-26 15:57:00 +00:00
|
|
|
static void movieclip_open_anim_file(MovieClip *clip)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
char str[FILE_MAX];
|
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!clip->anim) {
|
2020-06-23 09:54:14 +10:00
|
|
|
BLI_strncpy(str, clip->filepath, FILE_MAX);
|
2018-06-12 11:21:54 +02:00
|
|
|
BLI_path_abs(str, ID_BLEND_PATH_FROM_GLOBAL(&clip->id));
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* FIXME: make several stream accessible in image editor, too */
|
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
|
|
|
clip->anim = openanim(str, IB_rect, 0, clip->colorspace_settings.name);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (clip->anim) {
|
2012-03-25 23:19:21 +00:00
|
|
|
if (clip->flag & MCLIP_USE_PROXY_CUSTOM_DIR) {
|
2011-11-07 12:55:18 +00:00
|
|
|
char dir[FILE_MAX];
|
2011-11-07 15:19:26 +00:00
|
|
|
BLI_strncpy(dir, clip->proxy.dir, sizeof(dir));
|
2018-06-05 15:10:33 +02:00
|
|
|
BLI_path_abs(dir, BKE_main_blendfile_path_from_global());
|
2011-11-07 12:55:18 +00:00
|
|
|
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
|
|
|
{
|
|
|
|
|
ImBuf *ibuf = NULL;
|
|
|
|
|
int tc = get_timecode(clip, flag);
|
|
|
|
|
int proxy = rendersize_to_proxy(user, flag);
|
|
|
|
|
|
|
|
|
|
movieclip_open_anim_file(clip);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (clip->anim) {
|
2014-04-02 14:07:44 +06:00
|
|
|
int fra = framenr - clip->start_frame + clip->frame_offset;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
ibuf = IMB_anim_absolute(clip->anim, fra, tc, proxy);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ibuf;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-26 13:30:53 +00:00
|
|
|
static void movieclip_calc_length(MovieClip *clip)
|
|
|
|
|
{
|
2012-03-26 15:57:00 +00:00
|
|
|
if (clip->source == MCLIP_SRC_MOVIE) {
|
|
|
|
|
movieclip_open_anim_file(clip);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-26 15:57:00 +00:00
|
|
|
if (clip->anim) {
|
|
|
|
|
clip->len = IMB_anim_get_duration(clip->anim, clip->proxy.tc);
|
|
|
|
|
}
|
2012-03-26 13:30:53 +00:00
|
|
|
}
|
|
|
|
|
else if (clip->source == MCLIP_SRC_SEQUENCE) {
|
2012-04-08 07:34:09 +00:00
|
|
|
unsigned short numlen;
|
2012-04-07 16:37:55 +00:00
|
|
|
char name[FILE_MAX], head[FILE_MAX], tail[FILE_MAX];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-06-23 09:54:14 +10:00
|
|
|
BLI_path_sequence_decode(clip->filepath, head, tail, &numlen);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-07 16:37:55 +00:00
|
|
|
if (numlen == 0) {
|
|
|
|
|
/* there's no number group in file name, assume it's single framed sequence */
|
2013-05-09 14:57:20 +00:00
|
|
|
clip->len = 1;
|
2012-04-07 16:37:55 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2013-05-09 14:57:20 +00:00
|
|
|
clip->len = 0;
|
2012-09-24 15:27:04 +00:00
|
|
|
for (;;) {
|
2016-03-15 14:59:59 +05:00
|
|
|
get_sequence_fname(clip, clip->len + clip->start_frame, name);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (BLI_exists(name)) {
|
2013-05-09 14:57:20 +00:00
|
|
|
clip->len++;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2012-04-07 16:37:55 +00:00
|
|
|
break;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-04-07 16:37:55 +00:00
|
|
|
}
|
2012-03-26 13:30:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
/*********************** image buffer cache *************************/
|
|
|
|
|
|
|
|
|
|
typedef struct MovieClipCache {
|
|
|
|
|
/* regular movie cache */
|
|
|
|
|
struct MovieCache *moviecache;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
/* cached postprocessed shot */
|
|
|
|
|
struct {
|
|
|
|
|
ImBuf *ibuf;
|
|
|
|
|
int framenr;
|
2012-01-15 13:31:58 +00:00
|
|
|
int flag;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
/* cache for undistorted shot */
|
2020-04-08 17:19:02 +02:00
|
|
|
float focal_length;
|
2012-01-15 13:31:25 +00:00
|
|
|
float principal[2];
|
2020-04-06 12:15:14 +02:00
|
|
|
float polynomial_k[3];
|
|
|
|
|
float division_k[2];
|
2020-04-20 17:33:03 +02:00
|
|
|
float nuke_k[2];
|
2020-09-30 15:12:14 +02:00
|
|
|
float brown_k[4];
|
|
|
|
|
float brown_p[2];
|
2014-02-20 19:41:05 +06:00
|
|
|
short distortion_model;
|
2014-03-31 17:59:50 +06:00
|
|
|
bool undistortion_used;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
int proxy;
|
|
|
|
|
short render_flag;
|
|
|
|
|
} postprocessed;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
/* cache for stable shot */
|
|
|
|
|
struct {
|
2012-07-09 10:26:01 +00:00
|
|
|
ImBuf *reference_ibuf;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
ImBuf *ibuf;
|
|
|
|
|
int framenr;
|
2012-02-16 07:45:01 +00:00
|
|
|
int postprocess_flag;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-02-16 15:03:18 +00:00
|
|
|
float loc[2], scale, angle, aspect;
|
2012-02-16 15:03:37 +00:00
|
|
|
int proxy, filter;
|
2012-01-15 13:31:25 +00:00
|
|
|
short render_flag;
|
|
|
|
|
} stabilized;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-25 15:32:11 +00:00
|
|
|
int sequence_offset;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-03-15 15:07:18 +05:00
|
|
|
bool is_still_sequence;
|
2011-11-07 12:55:18 +00:00
|
|
|
} MovieClipCache;
|
|
|
|
|
|
|
|
|
|
typedef struct MovieClipImBufCacheKey {
|
|
|
|
|
int framenr;
|
|
|
|
|
int proxy;
|
|
|
|
|
short render_flag;
|
|
|
|
|
} MovieClipImBufCacheKey;
|
|
|
|
|
|
2012-07-10 14:43:50 +00:00
|
|
|
typedef struct MovieClipCachePriorityData {
|
|
|
|
|
int framenr;
|
|
|
|
|
} MovieClipCachePriorityData;
|
|
|
|
|
|
2013-03-25 15:32:11 +00:00
|
|
|
static int user_frame_to_cache_frame(MovieClip *clip, int framenr)
|
|
|
|
|
{
|
|
|
|
|
int index;
|
|
|
|
|
|
|
|
|
|
index = framenr - clip->start_frame + clip->frame_offset;
|
|
|
|
|
|
|
|
|
|
if (clip->source == MCLIP_SRC_SEQUENCE) {
|
|
|
|
|
if (clip->cache->sequence_offset == -1) {
|
|
|
|
|
unsigned short numlen;
|
|
|
|
|
char head[FILE_MAX], tail[FILE_MAX];
|
|
|
|
|
|
2020-06-23 09:54:14 +10:00
|
|
|
BLI_path_sequence_decode(clip->filepath, head, tail, &numlen);
|
2013-03-25 15:32:11 +00:00
|
|
|
|
|
|
|
|
/* see comment in get_sequence_fname */
|
2020-06-23 09:54:14 +10:00
|
|
|
clip->cache->sequence_offset = sequence_guess_offset(clip->filepath, strlen(head), numlen);
|
2013-03-25 15:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
index += clip->cache->sequence_offset;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (index < 0) {
|
2013-03-25 15:32:11 +00:00
|
|
|
return framenr - index;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-25 15:32:11 +00:00
|
|
|
|
|
|
|
|
return framenr;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
static void moviecache_keydata(void *userkey, int *framenr, int *proxy, int *render_flags)
|
|
|
|
|
{
|
2015-01-01 23:26:03 +11:00
|
|
|
const MovieClipImBufCacheKey *key = userkey;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00: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)
|
|
|
|
|
{
|
2015-01-01 23:26:03 +11:00
|
|
|
const MovieClipImBufCacheKey *key = keyv;
|
2012-03-25 23:19:21 +00:00
|
|
|
int rval = key->framenr;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return rval;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2015-01-01 23:26:03 +11:00
|
|
|
const MovieClipImBufCacheKey *a = av;
|
|
|
|
|
const MovieClipImBufCacheKey *b = bv;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2014-09-25 06:15:52 +10: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
|
|
|
{
|
|
|
|
|
MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey *)key_v;
|
|
|
|
|
MovieClipCachePriorityData *priority_data;
|
|
|
|
|
|
2013-07-13 05:43:35 +00:00
|
|
|
priority_data = MEM_callocN(sizeof(*priority_data), "movie cache clip priority data");
|
2012-07-10 14:43:50 +00:00
|
|
|
priority_data->framenr = key->framenr;
|
|
|
|
|
|
|
|
|
|
return priority_data;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
MovieClipImBufCacheKey *last_userkey = (MovieClipImBufCacheKey *)last_userkey_v;
|
|
|
|
|
MovieClipCachePriorityData *priority_data = (MovieClipCachePriorityData *)priority_data_v;
|
|
|
|
|
|
|
|
|
|
return -abs(last_userkey->framenr - priority_data->framenr);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-15 01:52:28 +00:00
|
|
|
static void moviecache_prioritydeleter(void *priority_data_v)
|
2012-07-10 14:43:50 +00:00
|
|
|
{
|
|
|
|
|
MovieClipCachePriorityData *priority_data = (MovieClipCachePriorityData *)priority_data_v;
|
|
|
|
|
|
|
|
|
|
MEM_freeN(priority_data);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
static ImBuf *get_imbuf_cache(MovieClip *clip, const MovieClipUser *user, int flag)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (clip->cache) {
|
2011-11-07 12:55:18 +00:00
|
|
|
MovieClipImBufCacheKey key;
|
|
|
|
|
|
2016-03-15 15:07:18 +05: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
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (flag & MCLIP_USE_PROXY) {
|
|
|
|
|
key.proxy = rendersize_to_proxy(user, flag);
|
|
|
|
|
key.render_flag = user->render_flag;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-03-25 23:19:21 +00:00
|
|
|
key.proxy = IMB_PROXY_NONE;
|
|
|
|
|
key.render_flag = 0;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return IMB_moviecache_get(clip->cache->moviecache, &key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
if (clip->cache) {
|
|
|
|
|
MovieClipImBufCacheKey key;
|
|
|
|
|
|
2013-03-25 15:32:11 +00:00
|
|
|
key.framenr = user_frame_to_cache_frame(clip, user->framenr);
|
2013-03-20 17:03:20 +00: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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return IMB_moviecache_has_frame(clip->cache->moviecache, &key);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-31 17:59:50 +06:00
|
|
|
return false;
|
2013-03-20 17:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-15 14:59:59 +05: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
|
|
|
{
|
|
|
|
|
MovieClipImBufCacheKey key;
|
|
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
if (clip->cache == NULL) {
|
2012-07-10 14:43:50 +00:00
|
|
|
struct MovieCache *moviecache;
|
|
|
|
|
|
|
|
|
|
// char cache_name[64];
|
|
|
|
|
// BLI_snprintf(cache_name, sizeof(cache_name), "movie %s", clip->id.name);
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
clip->cache = MEM_callocN(sizeof(MovieClipCache), "movieClipCache");
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
moviecache = IMB_moviecache_create(
|
|
|
|
|
"movieclip", sizeof(MovieClipImBufCacheKey), moviecache_hashhash, moviecache_hashcmp);
|
2012-07-10 14:43:50 +00:00
|
|
|
|
|
|
|
|
IMB_moviecache_set_getdata_callback(moviecache, moviecache_keydata);
|
2016-03-15 14:59:59 +05:00
|
|
|
IMB_moviecache_set_priority_callback(moviecache,
|
|
|
|
|
moviecache_getprioritydata,
|
|
|
|
|
moviecache_getitempriority,
|
2012-07-10 14:43:50 +00:00
|
|
|
moviecache_prioritydeleter);
|
|
|
|
|
|
|
|
|
|
clip->cache->moviecache = moviecache;
|
2013-03-25 15:32:11 +00:00
|
|
|
clip->cache->sequence_offset = -1;
|
2016-03-15 15:07:18 +05:00
|
|
|
if (clip->source == MCLIP_SRC_SEQUENCE) {
|
|
|
|
|
unsigned short numlen;
|
2020-06-23 09:54:14 +10:00
|
|
|
BLI_path_sequence_decode(clip->filepath, NULL, NULL, &numlen);
|
2016-03-15 15:07:18 +05:00
|
|
|
clip->cache->is_still_sequence = (numlen == 0);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-15 15:07:18 +05: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
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (flag & MCLIP_USE_PROXY) {
|
|
|
|
|
key.proxy = rendersize_to_proxy(user, flag);
|
|
|
|
|
key.render_flag = user->render_flag;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-03-25 23:19:21 +00:00
|
|
|
key.proxy = IMB_PROXY_NONE;
|
|
|
|
|
key.render_flag = 0;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-20 17:03:20 +00:00
|
|
|
if (destructive) {
|
|
|
|
|
IMB_moviecache_put(clip->cache->moviecache, &key, ibuf);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-08-07 12:30:43 +02:00
|
|
|
|
|
|
|
|
return IMB_moviecache_put_if_possible(clip->cache->moviecache, &key, ibuf);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-15 22:20:06 +05:00
|
|
|
static bool moviecache_check_free_proxy(ImBuf *UNUSED(ibuf), void *userkey, void *UNUSED(userdata))
|
|
|
|
|
{
|
|
|
|
|
MovieClipImBufCacheKey *key = (MovieClipImBufCacheKey *)userkey;
|
|
|
|
|
|
|
|
|
|
return !(key->proxy == IMB_PROXY_NONE && key->render_flag == 0);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
MovieClip *clip;
|
|
|
|
|
|
2020-10-08 12:50:04 +02:00
|
|
|
clip = BKE_id_new(bmain, ID_MC, name);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return clip;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-08 22:25:23 +10:00
|
|
|
static void movieclip_load_get_size(MovieClip *clip)
|
2012-06-17 16:40:16 +00:00
|
|
|
{
|
|
|
|
|
int width, height;
|
|
|
|
|
MovieClipUser user = {0};
|
|
|
|
|
|
|
|
|
|
user.framenr = 1;
|
|
|
|
|
BKE_movieclip_get_size(clip, &user, &width, &height);
|
|
|
|
|
|
|
|
|
|
if (width && height) {
|
|
|
|
|
clip->tracking.camera.principal[0] = ((float)width) / 2.0f;
|
|
|
|
|
clip->tracking.camera.principal[1] = ((float)height) / 2.0f;
|
2012-07-28 18:14:44 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
ImBuf *ibuf;
|
|
|
|
|
char name[FILE_MAX];
|
|
|
|
|
|
2020-06-23 09:54:14 +10:00
|
|
|
BLI_strncpy(name, clip->filepath, sizeof(name));
|
2018-06-05 15:10:33 +02:00
|
|
|
BLI_path_abs(name, BKE_main_blendfile_path(bmain));
|
2012-11-05 10:32:47 +00: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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
MovieClip *clip;
|
2015-10-06 19:49:58 +11:00
|
|
|
int file;
|
2015-10-06 19:40:15 +11:00
|
|
|
char str[FILE_MAX];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
BLI_strncpy(str, name, sizeof(str));
|
2018-06-05 15:10:33 +02:00
|
|
|
BLI_path_abs(str, BKE_main_blendfile_path(bmain));
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* exists? */
|
2012-04-29 15:47:02 +00:00
|
|
|
file = BLI_open(str, O_BINARY | O_RDONLY, 0);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (file == -1) {
|
2012-03-25 23:19:21 +00:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
close(file);
|
|
|
|
|
|
|
|
|
|
/* ** add new movieclip ** */
|
|
|
|
|
|
|
|
|
|
/* create a short library name */
|
2015-10-06 19:49:58 +11:00
|
|
|
clip = movieclip_alloc(bmain, BLI_path_basename(name));
|
2020-06-23 09:54:14 +10:00
|
|
|
BLI_strncpy(clip->filepath, name, sizeof(clip->filepath));
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2018-06-05 15:10:33 +02:00
|
|
|
detect_clip_source(bmain, clip);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2016-06-08 22:25:23 +10:00
|
|
|
movieclip_load_get_size(clip);
|
2012-06-18 18:22:49 +00:00
|
|
|
if (clip->lastsize[0]) {
|
|
|
|
|
int width = clip->lastsize[0];
|
|
|
|
|
|
|
|
|
|
clip->tracking.camera.focal = 24.0f * width / clip->tracking.camera.sensor_width;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-26 13:30:53 +00:00
|
|
|
movieclip_calc_length(clip);
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
return clip;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-06 19:40:15 +11:00
|
|
|
MovieClip *BKE_movieclip_file_add_exists_ex(Main *bmain, const char *filepath, bool *r_exists)
|
|
|
|
|
{
|
|
|
|
|
MovieClip *clip;
|
|
|
|
|
char str[FILE_MAX], strtest[FILE_MAX];
|
|
|
|
|
|
|
|
|
|
BLI_strncpy(str, filepath, sizeof(str));
|
2018-06-05 15:10:33 +02:00
|
|
|
BLI_path_abs(str, BKE_main_blendfile_path(bmain));
|
2015-10-06 19:40:15 +11:00
|
|
|
|
|
|
|
|
/* first search an identical filepath */
|
2019-03-08 09:29:17 +11:00
|
|
|
for (clip = bmain->movieclips.first; clip; clip = clip->id.next) {
|
2020-06-23 09:54:14 +10:00
|
|
|
BLI_strncpy(strtest, clip->filepath, sizeof(clip->filepath));
|
2015-10-06 19:40:15 +11:00
|
|
|
BLI_path_abs(strtest, ID_BLEND_PATH(bmain, &clip->id));
|
|
|
|
|
|
|
|
|
|
if (BLI_path_cmp(strtest, str) == 0) {
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_plus(&clip->id); /* officially should not, it doesn't link here! */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (r_exists) {
|
2015-10-06 19:40:15 +11:00
|
|
|
*r_exists = true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2015-10-06 19:40:15 +11:00
|
|
|
return clip;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (r_exists) {
|
2015-10-06 19:40:15 +11:00
|
|
|
*r_exists = false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2015-10-06 19:40:15 +11:00
|
|
|
return BKE_movieclip_file_add(bmain, filepath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MovieClip *BKE_movieclip_file_add_exists(Main *bmain, const char *filepath)
|
|
|
|
|
{
|
|
|
|
|
return BKE_movieclip_file_add_exists_ex(bmain, filepath, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-15 14:59:59 +05: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
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
*width = ibuf->x;
|
|
|
|
|
*height = ibuf->y;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (clip->flag & MCLIP_USE_PROXY) {
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (user->render_size) {
|
2011-11-07 12:55:18 +00:00
|
|
|
case MCLIP_PROXY_RENDER_SIZE_25:
|
2012-03-25 23:19:21 +00:00
|
|
|
(*width) *= 4;
|
|
|
|
|
(*height) *= 4;
|
2011-11-07 12:55:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MCLIP_PROXY_RENDER_SIZE_50:
|
2012-03-25 23:19:21 +00:00
|
|
|
(*width) *= 2.0f;
|
|
|
|
|
(*height) *= 2.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MCLIP_PROXY_RENDER_SIZE_75:
|
2012-05-06 15:15:33 +00:00
|
|
|
*width = ((float)*width) * 4.0f / 3.0f;
|
|
|
|
|
*height = ((float)*height) * 4.0f / 3.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2012-01-15 13:31:25 +00:00
|
|
|
ImBuf *undistibuf;
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (distortion) {
|
2012-03-25 23:19:21 +00: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 {
|
2012-06-15 11:03:23 +00: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
|
|
|
|
|
|
|
|
IMB_scaleImBuf(undistibuf, ibuf->x, ibuf->y);
|
|
|
|
|
|
|
|
|
|
return undistibuf;
|
|
|
|
|
}
|
|
|
|
|
|
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-03-18 12:01:40 -07: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. */
|
2012-10-01 11:26:52 +00:00
|
|
|
result |= uses_full_frame && (user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT) != 0;
|
2012-01-15 13:31:25 +00:00
|
|
|
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-03-18 12:01:40 -07:00
|
|
|
bool result = (postprocess_flag != 0);
|
|
|
|
|
result |= need_undistortion_postprocess(user, clip_flag);
|
2012-01-15 13:31:25 +00:00
|
|
|
return result;
|
|
|
|
|
}
|
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
|
|
|
{
|
2016-03-15 14:59:59 +05:00
|
|
|
const MovieClipCache *cache = clip->cache;
|
|
|
|
|
const MovieTrackingCamera *camera = &clip->tracking.camera;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2020-04-08 17:19:02 +02:00
|
|
|
if (camera->focal != cache->postprocessed.focal_length) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
/* check for distortion model changes */
|
2014-02-20 19:41:05 +06:00
|
|
|
if (!equals_v2v2(camera->principal, cache->postprocessed.principal)) {
|
2014-03-31 17:59:50 +06:00
|
|
|
return false;
|
2014-02-20 19:41:05 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (camera->distortion_model != cache->postprocessed.distortion_model) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2020-04-06 12:15:14 +02:00
|
|
|
if (!equals_v3v3(&camera->k1, cache->postprocessed.polynomial_k)) {
|
2014-03-31 17:59:50 +06:00
|
|
|
return false;
|
2014-02-20 19:41:05 +06:00
|
|
|
}
|
|
|
|
|
|
2020-04-06 12:15:14 +02:00
|
|
|
if (!equals_v2v2(&camera->division_k1, cache->postprocessed.division_k)) {
|
2014-02-20 19:41:05 +06:00
|
|
|
return false;
|
|
|
|
|
}
|
2020-09-30 15:12:14 +02:00
|
|
|
|
2020-04-20 17:33:03 +02:00
|
|
|
if (!equals_v2v2(&camera->nuke_k1, cache->postprocessed.nuke_k)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2020-09-30 15:12:14 +02:00
|
|
|
if (!equals_v4v4(&camera->brown_k1, cache->postprocessed.brown_k)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!equals_v2v2(&camera->brown_p1, cache->postprocessed.brown_p)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-31 17:59:50 +06: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
|
|
|
{
|
2016-03-15 14:59:59 +05:00
|
|
|
const MovieClipCache *cache = clip->cache;
|
2012-03-25 23:19:21 +00:00
|
|
|
int framenr = user->framenr;
|
|
|
|
|
short proxy = IMB_PROXY_NONE;
|
|
|
|
|
int render_flag = 0;
|
|
|
|
|
|
|
|
|
|
if (flag & MCLIP_USE_PROXY) {
|
|
|
|
|
proxy = rendersize_to_proxy(user, flag);
|
|
|
|
|
render_flag = user->render_flag;
|
2012-01-15 13:31:25 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
/* no cache or no cached postprocessed image */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!clip->cache || !clip->cache->postprocessed.ibuf) {
|
2012-01-15 13:31:25 +00:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
/* postprocessing happened for other frame */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cache->postprocessed.framenr != framenr) {
|
2012-01-15 13:31:25 +00:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-01-15 13:31:25 +00: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) {
|
2012-01-15 13:31:58 +00: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) {
|
2012-01-15 13:31:25 +00:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-01-15 13:31:25 +00:00
|
|
|
|
2019-03-18 12:01:40 -07:00
|
|
|
if (need_undistortion_postprocess(user, flag)) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!check_undistortion_cache_flags(clip)) {
|
2012-01-15 13:31:25 +00: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
|
|
|
else if (cache->postprocessed.undistortion_used) {
|
2012-01-15 13:31:58 +00:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
IMB_refImBuf(cache->postprocessed.ibuf);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
return cache->postprocessed.ibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-15 14:59:59 +05: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
|
|
|
{
|
|
|
|
|
ImBuf *postproc_ibuf = NULL;
|
|
|
|
|
|
2019-03-18 12:01:40 -07:00
|
|
|
if (need_undistortion_postprocess(user, flag)) {
|
2014-02-04 15:16:21 +06:00
|
|
|
postproc_ibuf = get_undistorted_ibuf(clip, NULL, ibuf);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
postproc_ibuf = IMB_dupImBuf(ibuf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (postprocess_flag) {
|
2015-02-11 18:38:41 +11:00
|
|
|
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) {
|
2014-02-04 15:16:21 +06:00
|
|
|
BKE_tracking_disable_channels(postproc_ibuf, disable_red, disable_green, disable_blue, 1);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2014-02-04 15:16:21 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return postproc_ibuf;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
static void put_postprocessed_frame_to_cache(
|
|
|
|
|
MovieClip *clip, const MovieClipUser *user, ImBuf *ibuf, int flag, int postprocess_flag)
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
MovieClipCache *cache = clip->cache;
|
|
|
|
|
MovieTrackingCamera *camera = &clip->tracking.camera;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
cache->postprocessed.framenr = user->framenr;
|
2012-01-15 13:31:58 +00:00
|
|
|
cache->postprocessed.flag = postprocess_flag;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (flag & MCLIP_USE_PROXY) {
|
|
|
|
|
cache->postprocessed.proxy = rendersize_to_proxy(user, flag);
|
|
|
|
|
cache->postprocessed.render_flag = user->render_flag;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2012-01-15 13:31:25 +00:00
|
|
|
cache->postprocessed.proxy = IMB_PROXY_NONE;
|
|
|
|
|
cache->postprocessed.render_flag = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
if (need_undistortion_postprocess(user, flag)) {
|
2014-02-20 19:41:05 +06:00
|
|
|
cache->postprocessed.distortion_model = camera->distortion_model;
|
2020-04-08 17:19:02 +02:00
|
|
|
cache->postprocessed.focal_length = camera->focal;
|
2012-01-15 13:31:25 +00:00
|
|
|
copy_v2_v2(cache->postprocessed.principal, camera->principal);
|
2020-04-06 12:15:14 +02:00
|
|
|
copy_v3_v3(cache->postprocessed.polynomial_k, &camera->k1);
|
|
|
|
|
copy_v2_v2(cache->postprocessed.division_k, &camera->division_k1);
|
2020-04-20 17:33:03 +02:00
|
|
|
copy_v2_v2(cache->postprocessed.nuke_k, &camera->nuke_k1);
|
2020-09-30 15:12:14 +02:00
|
|
|
copy_v4_v4(cache->postprocessed.brown_k, &camera->brown_k1);
|
|
|
|
|
copy_v2_v2(cache->postprocessed.brown_p, &camera->brown_p1);
|
2014-03-31 17:59:50 +06:00
|
|
|
cache->postprocessed.undistortion_used = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2014-03-31 17:59:50 +06:00
|
|
|
cache->postprocessed.undistortion_used = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-04 15:16:21 +06:00
|
|
|
IMB_refImBuf(ibuf);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cache->postprocessed.ibuf) {
|
2012-07-09 10:26:01 +00:00
|
|
|
IMB_freeImBuf(cache->postprocessed.ibuf);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-04 15:16:21 +06:00
|
|
|
cache->postprocessed.ibuf = ibuf;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
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
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
ImBuf *ibuf = NULL;
|
|
|
|
|
int framenr = user->framenr;
|
2012-01-15 13:31:58 +00:00
|
|
|
bool need_postprocess = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-01-15 13:31:58 +00:00
|
|
|
/* cache isn't threadsafe itself and also loading of movies
|
2012-03-25 23:19:21 +00:00
|
|
|
* can't happen from concurrent threads that's why we use lock here */
|
|
|
|
|
BLI_thread_lock(LOCK_MOVIECLIP);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
/* try to obtain cached postprocessed frame first */
|
2019-03-18 12:01:40 -07:00
|
|
|
if (need_postprocessed_frame(user, flag, postprocess_flag)) {
|
2012-01-15 13:31:25 +00:00
|
|
|
ibuf = get_postprocessed_cached_frame(clip, user, flag, postprocess_flag);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!ibuf) {
|
2014-03-31 17:59:50 +06:00
|
|
|
need_postprocess = true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!ibuf) {
|
2016-03-15 14:59:59 +05:00
|
|
|
ibuf = get_imbuf_cache(clip, user, flag);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (!ibuf) {
|
2014-03-31 17:59:50 +06:00
|
|
|
bool use_sequence = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
/* undistorted proxies for movies should be read as image sequence */
|
2015-10-08 11:11:31 +11:00
|
|
|
use_sequence = (user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT) &&
|
2018-02-16 01:13:46 +11:00
|
|
|
(user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-18 12:01:40 -07:00
|
|
|
if (clip->source == MCLIP_SRC_SEQUENCE || use_sequence) {
|
2012-05-03 23:47:39 +00:00
|
|
|
ibuf = movieclip_load_sequence_file(clip, user, framenr, flag);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-03 23:47:39 +00:00
|
|
|
ibuf = movieclip_load_movie_file(clip, user, framenr, flag);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2012-05-03 23:47:39 +00:00
|
|
|
if (ibuf && (cache_flag & MOVIECLIP_CACHE_SKIP) == 0) {
|
|
|
|
|
put_imbuf_cache(clip, user, ibuf, flag, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ibuf) {
|
2014-03-31 17:59:50 +06:00
|
|
|
clip->lastframe = framenr;
|
2011-11-07 12:55:18 +00:00
|
|
|
real_ibuf_size(clip, user, ibuf, &clip->lastsize[0], &clip->lastsize[1]);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
/* postprocess frame and put to cache if needed*/
|
2012-03-25 23:19:21 +00:00
|
|
|
if (need_postprocess) {
|
|
|
|
|
ImBuf *tmpibuf = ibuf;
|
2019-02-21 11:08:33 +01:00
|
|
|
ibuf = postprocess_frame(clip, user, tmpibuf, flag, postprocess_flag);
|
2012-03-25 23:19:21 +00:00
|
|
|
IMB_freeImBuf(tmpibuf);
|
2016-03-15 14:59:59 +05:00
|
|
|
if (ibuf && (cache_flag & MOVIECLIP_CACHE_SKIP) == 0) {
|
2014-02-04 15:16:21 +06:00
|
|
|
put_postprocessed_frame_to_cache(clip, user, ibuf, flag, postprocess_flag);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-02-04 15:16:21 +06:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-16 01:13:46 +11:00
|
|
|
BLI_thread_unlock(LOCK_MOVIECLIP);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-18 12:01:40 -07:00
|
|
|
/* Fallback render in case proxies are not enabled or built */
|
2019-03-21 00:58:01 +11:00
|
|
|
if (!ibuf && user->render_flag & MCLIP_PROXY_RENDER_USE_FALLBACK_RENDER &&
|
|
|
|
|
user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL) {
|
2019-03-18 12:01:40 -07:00
|
|
|
MovieClipUser user_fallback = *user;
|
|
|
|
|
user_fallback.render_size = MCLIP_PROXY_RENDER_SIZE_FULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-18 12:01:40 -07:00
|
|
|
ibuf = movieclip_get_postprocessed_ibuf(
|
|
|
|
|
clip, &user_fallback, flag, postprocess_flag, cache_flag);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
return ibuf;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
ImBuf *BKE_movieclip_get_ibuf(MovieClip *clip, MovieClipUser *user)
|
|
|
|
|
{
|
2012-02-01 19:06:21 +00: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
|
|
|
{
|
2012-02-01 19:06:21 +00:00
|
|
|
return movieclip_get_postprocessed_ibuf(clip, user, flag, 0, cache_flag);
|
2012-01-15 13:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImBuf *BKE_movieclip_get_postprocessed_ibuf(MovieClip *clip,
|
|
|
|
|
MovieClipUser *user,
|
|
|
|
|
int postprocess_flag)
|
|
|
|
|
{
|
2012-02-01 19:06:21 +00: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
|
|
|
|
2012-07-09 10:26:01 +00: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
|
|
|
{
|
|
|
|
|
MovieClipCache *cache = clip->cache;
|
2012-02-16 15:03:37 +00:00
|
|
|
MovieTracking *tracking = &clip->tracking;
|
2012-01-15 13:31:25 +00:00
|
|
|
ImBuf *stableibuf;
|
|
|
|
|
float tloc[2], tscale, tangle;
|
|
|
|
|
short proxy = IMB_PROXY_NONE;
|
|
|
|
|
int render_flag = 0;
|
2012-06-15 11:15:48 +00:00
|
|
|
int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, framenr);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (clip->flag & MCLIP_USE_PROXY) {
|
2012-01-15 13:31:25 +00:00
|
|
|
proxy = rendersize_to_proxy(user, clip->flag);
|
|
|
|
|
render_flag = user->render_flag;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-15 13:31:25 +00: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) {
|
2012-01-15 13:31:25 +00: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) {
|
2012-07-09 10:26:01 +00:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-07-09 10:26:01 +00:00
|
|
|
|
2012-01-15 13:31:25 +00: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) {
|
2012-01-15 13:31:25 +00: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) {
|
2012-02-16 07:45:01 +00:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-02-16 07:45:01 +00:00
|
|
|
|
2012-02-16 15:03:18 +00:00
|
|
|
/* stabilization also depends on pixel aspect ratio */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cache->stabilized.aspect != tracking->camera.pixel_aspect) {
|
2012-02-16 15:03:37 +00: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) {
|
2012-02-16 15:03:18 +00:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-02-16 15:03:18 +00:00
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
stableibuf = cache->stabilized.ibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
Rework 2D stabilizator
See this page for motivation and description of concepts:
https://github.com/Ichthyostega/blender/wiki
See this video for UI explanation and demonstration of usage
http://vimeo.com/blenderHack/stabilizerdemo
This proposal attempts to improve usability of Blender's image stabilization
feature for real-world footage esp. with moving and panning camera. It builds
upon the feature tracking to get a measurement of 2D image movement.
- Use a weighted average of movement contributions (instead of a median).
- Allow for rotation compensation and zoom (image scale) compensation.
- Allow to pick a different set of tracks for translation and for
rotation/zoom.
- Treat translation / rotation / zoom contributions systematically in a
similar way.
- Improve handling of partial tracking data with gaps and varying
start / end points.
- Have a user definable anchor frame and interpolate / extrapolate data to
avoid jumping back to "neutral" position when no tracking data is available.
- Support for travelling and panning shots by including an //intended//
position/rotation/zoom ("target position"). The idea is for these parameters
to be //animated// by the user, in order to supply an smooth, intended
camera movement. This way, we can keep the image content roughly in frame
even when moving completely away from the initial view.
A known shortcoming is that the pivot point for rotation compensation is set to
the translation compensated image center. This can produce spurious rotation on
travelling shots, which needs to be compensated manually (by animating the
target rotation parameter). There are several possible ways to address that
problem, yet all of them are considered beyond the scope of this improvement
proposal for now.
Own modifications:
- Restrict line length, it's really handy for split-view editing
- In motion tracking we prefer fully human-readable comments, meaning we
don't use doxygen with it's weird markup and comments are supposed to
start with capital and end with a full stop,
- Add explicit comparison of pointer to NULL.
Reviewers: sergey
Subscribers: kusi, kdawg, forest-house, mardy, Samoth, plasmasolutions, willolis, sebastian_k, hype, enetheru, sunboy, jta, leon_cheung
Maniphest Tasks: T49036
Differential Revision: https://developer.blender.org/D583
2016-08-16 10:32:55 +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
|
|
|
|
|
|
|
|
/* check for stabilization parameters */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (tscale != cache->stabilized.scale || tangle != cache->stabilized.angle ||
|
2012-05-06 15:15:33 +00:00
|
|
|
!equals_v2v2(tloc, cache->stabilized.loc)) {
|
2012-01-15 13:31:25 +00:00
|
|
|
return NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
IMB_refImBuf(stableibuf);
|
|
|
|
|
|
|
|
|
|
return stableibuf;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-16 07:45:01 +00: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
|
|
|
{
|
|
|
|
|
MovieClipCache *cache = clip->cache;
|
2012-02-16 15:03:37 +00:00
|
|
|
MovieTracking *tracking = &clip->tracking;
|
2012-01-15 13:31:25 +00:00
|
|
|
ImBuf *stableibuf;
|
|
|
|
|
float tloc[2], tscale, tangle;
|
2012-06-15 11:15:48 +00:00
|
|
|
int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, framenr);
|
2012-01-15 13:31:25 +00:00
|
|
|
|
Rework 2D stabilizator
See this page for motivation and description of concepts:
https://github.com/Ichthyostega/blender/wiki
See this video for UI explanation and demonstration of usage
http://vimeo.com/blenderHack/stabilizerdemo
This proposal attempts to improve usability of Blender's image stabilization
feature for real-world footage esp. with moving and panning camera. It builds
upon the feature tracking to get a measurement of 2D image movement.
- Use a weighted average of movement contributions (instead of a median).
- Allow for rotation compensation and zoom (image scale) compensation.
- Allow to pick a different set of tracks for translation and for
rotation/zoom.
- Treat translation / rotation / zoom contributions systematically in a
similar way.
- Improve handling of partial tracking data with gaps and varying
start / end points.
- Have a user definable anchor frame and interpolate / extrapolate data to
avoid jumping back to "neutral" position when no tracking data is available.
- Support for travelling and panning shots by including an //intended//
position/rotation/zoom ("target position"). The idea is for these parameters
to be //animated// by the user, in order to supply an smooth, intended
camera movement. This way, we can keep the image content roughly in frame
even when moving completely away from the initial view.
A known shortcoming is that the pivot point for rotation compensation is set to
the translation compensated image center. This can produce spurious rotation on
travelling shots, which needs to be compensated manually (by animating the
target rotation parameter). There are several possible ways to address that
problem, yet all of them are considered beyond the scope of this improvement
proposal for now.
Own modifications:
- Restrict line length, it's really handy for split-view editing
- In motion tracking we prefer fully human-readable comments, meaning we
don't use doxygen with it's weird markup and comments are supposed to
start with capital and end with a full stop,
- Add explicit comparison of pointer to NULL.
Reviewers: sergey
Subscribers: kusi, kdawg, forest-house, mardy, Samoth, plasmasolutions, willolis, sebastian_k, hype, enetheru, sunboy, jta, leon_cheung
Maniphest Tasks: T49036
Differential Revision: https://developer.blender.org/D583
2016-08-16 10:32:55 +02:00
|
|
|
stableibuf = BKE_tracking_stabilize_frame(clip, clip_framenr, ibuf, tloc, &tscale, &tangle);
|
2012-01-15 13:31:25 +00:00
|
|
|
|
|
|
|
|
copy_v2_v2(cache->stabilized.loc, tloc);
|
|
|
|
|
|
2013-04-08 10:56:50 +00:00
|
|
|
cache->stabilized.reference_ibuf = ibuf;
|
2012-01-15 13:31:25 +00:00
|
|
|
cache->stabilized.scale = tscale;
|
|
|
|
|
cache->stabilized.angle = tangle;
|
|
|
|
|
cache->stabilized.framenr = framenr;
|
2012-02-16 15:03:37 +00:00
|
|
|
cache->stabilized.aspect = tracking->camera.pixel_aspect;
|
|
|
|
|
cache->stabilized.filter = tracking->stabilization.filter;
|
2012-01-15 13:31:25 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (clip->flag & MCLIP_USE_PROXY) {
|
|
|
|
|
cache->stabilized.proxy = rendersize_to_proxy(user, clip->flag);
|
|
|
|
|
cache->stabilized.render_flag = user->render_flag;
|
2012-01-15 13:31:25 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
cache->stabilized.proxy = IMB_PROXY_NONE;
|
|
|
|
|
cache->stabilized.render_flag = 0;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-16 07:45:01 +00:00
|
|
|
cache->stabilized.postprocess_flag = postprocess_flag;
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (cache->stabilized.ibuf) {
|
2012-07-09 10:26:01 +00:00
|
|
|
IMB_freeImBuf(cache->stabilized.ibuf);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-07-09 10:26:01 +00:00
|
|
|
|
|
|
|
|
cache->stabilized.ibuf = stableibuf;
|
|
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
IMB_refImBuf(stableibuf);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-01-15 13:31:25 +00:00
|
|
|
return stableibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
ImBuf *BKE_movieclip_get_stable_ibuf(MovieClip *clip,
|
|
|
|
|
MovieClipUser *user,
|
|
|
|
|
float loc[2],
|
|
|
|
|
float *scale,
|
|
|
|
|
float *angle,
|
|
|
|
|
int postprocess_flag)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
ImBuf *ibuf, *stableibuf = NULL;
|
|
|
|
|
int framenr = user->framenr;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00: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) {
|
2011-11-07 12:55:18 +00:00
|
|
|
return NULL;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
|
2012-05-03 23:47:39 +00:00
|
|
|
MovieClipCache *cache = clip->cache;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-07-09 10:26:01 +00: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) {
|
2012-03-25 23:19:21 +00: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) {
|
2012-03-25 23:19:21 +00: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) {
|
2012-05-03 23:47:39 +00: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) {
|
2012-05-03 23:47:39 +00:00
|
|
|
*angle = cache->stabilized.angle;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (loc) {
|
2012-03-25 23:19:21 +00: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) {
|
2012-05-03 23:47:39 +00: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) {
|
2012-05-03 23:47:39 +00:00
|
|
|
*angle = 0.0f;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
stableibuf = ibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (stableibuf != ibuf) {
|
2011-11-07 12:55:18 +00:00
|
|
|
IMB_freeImBuf(ibuf);
|
2012-03-25 23:19:21 +00:00
|
|
|
ibuf = stableibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ibuf;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, user);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ibuf) {
|
2011-11-07 12:55:18 +00:00
|
|
|
IMB_freeImBuf(ibuf);
|
2014-03-31 17:59:50 +06:00
|
|
|
return true;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-31 17:59:50 +06: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
|
|
|
|
|
/* 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) {
|
|
|
|
|
#endif
|
2012-06-07 16:15:24 +00:00
|
|
|
if (clip->lastsize[0] != 0 && clip->lastsize[1] != 0) {
|
2012-03-25 23:19:21 +00:00
|
|
|
*width = clip->lastsize[0];
|
|
|
|
|
*height = clip->lastsize[1];
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-03-25 23:19:21 +00:00
|
|
|
ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, user);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ibuf && ibuf->x && ibuf->y) {
|
2011-11-07 12:55:18 +00:00
|
|
|
real_ibuf_size(clip, user, ibuf, width, height);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-04-28 10:09:58 +00:00
|
|
|
*width = clip->lastsize[0];
|
|
|
|
|
*height = clip->lastsize[1];
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ibuf) {
|
2011-11-07 12:55:18 +00:00
|
|
|
IMB_freeImBuf(ibuf);
|
2019-04-22 09:39:35 +10: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])
|
|
|
|
|
{
|
|
|
|
|
int width, height;
|
|
|
|
|
BKE_movieclip_get_size(clip, user, &width, &height);
|
|
|
|
|
|
|
|
|
|
size[0] = (float)width;
|
|
|
|
|
size[1] = (float)height;
|
|
|
|
|
}
|
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
|
|
|
{
|
2012-03-26 13:36:22 +00:00
|
|
|
if (!clip->len) {
|
|
|
|
|
movieclip_calc_length(clip);
|
2012-03-26 13:30:53 +00: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)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2012-09-13 05:29:38 +00:00
|
|
|
*aspx = 1.0;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* x is always 1 */
|
2012-03-25 23:19:21 +00:00
|
|
|
*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 */
|
2015-05-08 07:25:39 +10: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
|
|
|
{
|
2015-05-08 07:25:39 +10:00
|
|
|
*r_totseg = 0;
|
|
|
|
|
*r_points = NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (clip->cache) {
|
2012-03-25 23:19:21 +00:00
|
|
|
int proxy = rendersize_to_proxy(user, clip->flag);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2015-05-08 07:25:39 +10: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)
|
|
|
|
|
{
|
|
|
|
|
/* TODO: clamp framenr here? */
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
iuser->framenr = framenr;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void free_buffers(MovieClip *clip)
|
|
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (clip->cache) {
|
2011-11-07 12:55:18 +00:00
|
|
|
IMB_moviecache_free(clip->cache->moviecache);
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (clip->cache->postprocessed.ibuf) {
|
2012-01-15 13:31:25 +00: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) {
|
2012-01-15 13:31:25 +00:00
|
|
|
IMB_freeImBuf(clip->cache->stabilized.ibuf);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(clip->cache);
|
2012-03-25 23:19:21 +00:00
|
|
|
clip->cache = NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (clip->anim) {
|
2011-11-07 12:55:18 +00:00
|
|
|
IMB_free_anim(clip->anim);
|
2012-03-25 23:19:21 +00:00
|
|
|
clip->anim = NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
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)
|
|
|
|
|
{
|
|
|
|
|
free_buffers(clip);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-15 22:20:06 +05:00
|
|
|
void BKE_movieclip_clear_proxy_cache(MovieClip *clip)
|
|
|
|
|
{
|
|
|
|
|
if (clip->cache && clip->cache->moviecache) {
|
|
|
|
|
IMB_moviecache_cleanup(clip->cache->moviecache, moviecache_check_free_proxy, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-05 15:10:33 +02:00
|
|
|
void BKE_movieclip_reload(Main *bmain, MovieClip *clip)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
/* clear cache */
|
|
|
|
|
free_buffers(clip);
|
|
|
|
|
|
|
|
|
|
/* update clip source */
|
2018-06-05 15:10:33 +02:00
|
|
|
detect_clip_source(bmain, clip);
|
2012-03-26 13:30:53 +00:00
|
|
|
|
2012-07-28 18:14:44 +00:00
|
|
|
clip->lastsize[0] = clip->lastsize[1] = 0;
|
2016-06-08 22:25:23 +10:00
|
|
|
movieclip_load_get_size(clip);
|
2012-06-17 16:40:16 +00:00
|
|
|
|
2012-03-26 13:30:53 +00:00
|
|
|
movieclip_calc_length(clip);
|
2012-10-18 09:48:51 +00: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;
|
2019-03-08 09:29:17 +11:00
|
|
|
for (scene = bmain->scenes.first; scene; scene = scene->id.next) {
|
2012-10-18 09:48:51 +00:00
|
|
|
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) {
|
2011-12-05 18:57:17 +00:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (scopes->track_preview) {
|
2011-11-07 12:55:18 +00:00
|
|
|
IMB_freeImBuf(scopes->track_preview);
|
2012-03-25 23:19:21 +00:00
|
|
|
scopes->track_preview = NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
if (scopes->track_search) {
|
|
|
|
|
IMB_freeImBuf(scopes->track_search);
|
|
|
|
|
scopes->track_search = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
scopes->marker = NULL;
|
|
|
|
|
scopes->track = NULL;
|
2014-04-01 11:34:00 +11:00
|
|
|
scopes->track_locked = true;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (clip) {
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingTrack *act_track = BKE_tracking_track_get_active(&clip->tracking);
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (act_track) {
|
2012-03-25 23:19:21 +00:00
|
|
|
MovieTrackingTrack *track = act_track;
|
2012-06-06 18:58:30 +00:00
|
|
|
int framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, user->framenr);
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-24 14:16:40 +00:00
|
|
|
scopes->marker = marker;
|
|
|
|
|
scopes->track = track;
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (marker->flag & MARKER_DISABLED) {
|
2014-04-01 11:34:00 +11:00
|
|
|
scopes->track_disabled = true;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-03-25 23:19:21 +00:00
|
|
|
ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, user);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
scopes->track_disabled = false;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-05-09 08:33:11 +00:00
|
|
|
if (ibuf && (ibuf->rect || ibuf->rect_float)) {
|
2012-03-25 23:19:21 +00:00
|
|
|
MovieTrackingMarker undist_marker = *marker;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT) {
|
2011-11-07 12:55:18 +00:00
|
|
|
int width, height;
|
2012-05-03 23:47:39 +00:00
|
|
|
float aspy = 1.0f / clip->tracking.camera.pixel_aspect;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
BKE_movieclip_get_size(clip, user, &width, &height);
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
undist_marker.pos[0] *= width;
|
2012-05-06 15:15:33 +00:00
|
|
|
undist_marker.pos[1] *= height * aspy;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2020-04-17 16:51:00 +02:00
|
|
|
BKE_tracking_undistort_v2(
|
|
|
|
|
&clip->tracking, width, height, undist_marker.pos, undist_marker.pos);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
undist_marker.pos[0] /= width;
|
2012-05-06 15:15:33 +00:00
|
|
|
undist_marker.pos[1] /= height * aspy;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2014-04-10 21:14:36 +06:00
|
|
|
scopes->track_search = BKE_tracking_get_search_imbuf(
|
|
|
|
|
ibuf, track, &undist_marker, true, true);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
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
|
|
|
scopes->undist_marker = undist_marker;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
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
|
|
|
scopes->frame_width = ibuf->x;
|
|
|
|
|
scopes->frame_height = ibuf->y;
|
2012-06-12 11:13:53 +00:00
|
|
|
|
2014-10-31 12:59:55 +01:00
|
|
|
scopes->use_track_mask = (track->flag & TRACK_PREVIEW_ALPHA) != 0;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IMB_freeImBuf(ibuf);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if ((track->flag & TRACK_LOCKED) == 0) {
|
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
|
|
|
float pat_min[2], pat_max[2];
|
|
|
|
|
|
2014-04-01 11:34:00 +11: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
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
scopes->framenr = user->framenr;
|
2014-04-01 11:34:00 +11:00
|
|
|
scopes->ok = true;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-03 18:55:59 +11: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
|
|
|
{
|
2011-11-26 04:07:38 +00:00
|
|
|
char name[FILE_MAX];
|
2011-11-07 12:55:18 +00:00
|
|
|
int quality, rectx, recty;
|
2012-03-25 23:19:21 +00:00
|
|
|
int size = rendersize_to_number(proxy_render_size);
|
2011-11-07 12:55:18 +00:00
|
|
|
ImBuf *scaleibuf;
|
|
|
|
|
|
|
|
|
|
get_proxy_fname(clip, proxy_render_size, undistorted, cfra, name);
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
rectx = ibuf->x * size / 100.0f;
|
|
|
|
|
recty = ibuf->y * size / 100.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
scaleibuf = IMB_dupImBuf(ibuf);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (threaded) {
|
2013-03-15 16:57:19 +00:00
|
|
|
IMB_scaleImBuf_threaded(scaleibuf, (short)rectx, (short)recty);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2013-03-15 16:57:19 +00:00
|
|
|
IMB_scaleImBuf(scaleibuf, (short)rectx, (short)recty);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
quality = clip->proxy.quality;
|
2015-07-13 13:58:17 +02:00
|
|
|
scaleibuf->ftype = IMB_FTYPE_JPG;
|
|
|
|
|
scaleibuf->foptions.quality = quality;
|
2011-11-07 12:55:18 +00:00
|
|
|
/* unsupported feature only confuses other s/w */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (scaleibuf->planes == 32) {
|
2012-03-25 23:19:21 +00: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,
|
2013-03-15 16:57:19 +00:00
|
|
|
* could be solved in a way that thread only prepares memory
|
|
|
|
|
* buffer and write to disk happens separately
|
|
|
|
|
*/
|
2018-02-16 01:13:46 +11:00
|
|
|
BLI_thread_lock(LOCK_MOVIECLIP);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
BLI_make_existing_file(name);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (IMB_saveiff(scaleibuf, name, IB_rect) == 0) {
|
2011-11-07 12:55:18 +00:00
|
|
|
perror(name);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2018-02-16 01:13:46 +11:00
|
|
|
BLI_thread_unlock(LOCK_MOVIECLIP);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
IMB_freeImBuf(scaleibuf);
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
*/
|
2011-12-27 11:09:06 +00:00
|
|
|
void BKE_movieclip_build_proxy_frame(MovieClip *clip,
|
|
|
|
|
int clip_flag,
|
|
|
|
|
struct MovieDistortion *distortion,
|
2014-02-03 18:55:59 +11:00
|
|
|
int cfra,
|
|
|
|
|
int *build_sizes,
|
|
|
|
|
int build_count,
|
|
|
|
|
bool undistorted)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
ImBuf *ibuf;
|
|
|
|
|
MovieClipUser user;
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!build_count) {
|
2013-03-15 09:32:59 +00:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-15 09:32:59 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
user.framenr = cfra;
|
|
|
|
|
user.render_flag = 0;
|
|
|
|
|
user.render_size = MCLIP_PROXY_RENDER_SIZE_FULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
ibuf = BKE_movieclip_get_ibuf_flag(clip, &user, clip_flag, MOVIECLIP_CACHE_SKIP);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ibuf) {
|
2012-03-25 23:19:21 +00:00
|
|
|
ImBuf *tmpibuf = ibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
int i;
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (undistorted) {
|
2012-03-25 23:19:21 +00: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++) {
|
2013-03-15 16:57:19 +00: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
|
|
|
|
|
|
|
|
IMB_freeImBuf(ibuf);
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tmpibuf != ibuf) {
|
2011-11-07 12:55:18 +00:00
|
|
|
IMB_freeImBuf(tmpibuf);
|
2019-04-22 09:39:35 +10: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)
|
|
|
|
|
*/
|
|
|
|
|
void BKE_movieclip_build_proxy_frame_for_ibuf(MovieClip *clip,
|
|
|
|
|
ImBuf *ibuf,
|
|
|
|
|
struct MovieDistortion *distortion,
|
2014-02-03 18:55:59 +11:00
|
|
|
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) {
|
2013-03-15 16:57:19 +00:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-15 16:57:19 +00:00
|
|
|
|
|
|
|
|
if (ibuf) {
|
|
|
|
|
ImBuf *tmpibuf = ibuf;
|
|
|
|
|
int i;
|
|
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (undistorted) {
|
2013-03-15 16:57:19 +00: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++) {
|
2013-03-15 16:57:19 +00: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) {
|
2013-03-15 16:57:19 +00:00
|
|
|
IMB_freeImBuf(tmpibuf);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2013-03-15 16:57:19 +00: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
|
|
|
{
|
2012-06-20 10:54:56 +00: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
|
|
|
{
|
2012-06-20 10:54:56 +00: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
|
|
|
{
|
2013-03-20 17:03:20 +00:00
|
|
|
if (clip->source == MCLIP_SRC_SEQUENCE) {
|
|
|
|
|
int use_proxy;
|
|
|
|
|
|
|
|
|
|
use_proxy = (clip->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, user->framenr, name);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
get_sequence_fname(clip, user->framenr, name);
|
|
|
|
|
}
|
2013-03-15 16:57:19 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2020-06-23 09:54:14 +10:00
|
|
|
BLI_strncpy(name, clip->filepath, FILE_MAX);
|
2018-06-12 11:21:54 +02:00
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
ImBuf *ibuf = NULL;
|
|
|
|
|
|
|
|
|
|
if (clip->source == MCLIP_SRC_MOVIE) {
|
2018-02-16 01:13:46 +11:00
|
|
|
BLI_thread_lock(LOCK_MOVIECLIP);
|
2013-03-20 17:03:20 +00:00
|
|
|
ibuf = movieclip_load_movie_file(clip, user, user->framenr, clip->flag);
|
2018-02-16 01:13:46 +11:00
|
|
|
BLI_thread_unlock(LOCK_MOVIECLIP);
|
2013-03-20 17:03:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ibuf;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2014-02-03 18:55:59 +11:00
|
|
|
bool has_frame = false;
|
2013-03-20 17:03:20 +00:00
|
|
|
|
2018-02-16 01:13:46 +11:00
|
|
|
BLI_thread_lock(LOCK_MOVIECLIP);
|
2013-03-20 17:03:20 +00:00
|
|
|
has_frame = has_imbuf_cache(clip, user, clip->flag);
|
2018-02-16 01:13:46 +11:00
|
|
|
BLI_thread_unlock(LOCK_MOVIECLIP);
|
2013-03-20 17:03:20 +00:00
|
|
|
|
|
|
|
|
return has_frame;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-15 14:59:59 +05:00
|
|
|
bool BKE_movieclip_put_frame_if_possible(MovieClip *clip, MovieClipUser *user, ImBuf *ibuf)
|
2013-03-20 17:03:20 +00:00
|
|
|
{
|
|
|
|
|
bool result;
|
|
|
|
|
|
2018-02-16 01:13:46 +11:00
|
|
|
BLI_thread_lock(LOCK_MOVIECLIP);
|
2013-03-20 17:03:20 +00:00
|
|
|
result = put_imbuf_cache(clip, user, ibuf, clip->flag, false);
|
2018-02-16 01:13:46 +11:00
|
|
|
BLI_thread_unlock(LOCK_MOVIECLIP);
|
2013-03-20 17:03:20 +00:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2017-10-25 11:45:31 +02:00
|
|
|
|
2020-04-03 16:46:34 +11:00
|
|
|
static void movieclip_selection_sync(MovieClip *clip_dst, const MovieClip *clip_src)
|
2018-08-13 16:59:42 -03:00
|
|
|
{
|
|
|
|
|
BLI_assert(clip_dst != clip_src);
|
2018-08-15 10:00:38 -03:00
|
|
|
MovieTracking *tracking_dst = &clip_dst->tracking, tracking_src = clip_src->tracking;
|
2018-08-13 16:59:42 -03:00
|
|
|
/* Syncs the active object, track and plane track. */
|
2018-08-15 10:00:38 -03:00
|
|
|
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);
|
2018-08-13 16:59:42 -03:00
|
|
|
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);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-13 16:59:42 -03:00
|
|
|
/* Syncs the tracking selection flag. */
|
|
|
|
|
MovieTrackingObject *tracking_object_dst, *tracking_object_src;
|
2018-08-15 10:00:38 -03:00
|
|
|
tracking_object_src = tracking_src.objects.first;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-13 16:59:42 -03:00
|
|
|
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);
|
2018-08-15 10:00:38 -03:00
|
|
|
tracksbase_src = BKE_tracking_object_get_tracks(&tracking_src, tracking_object_src);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-08-13 16:59:42 -03:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
BKE_tracking_dopesheet_tag_update(&clip->tracking);
|
2019-03-14 15:16:56 +01:00
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
DEG_debug_print_eval(depsgraph, __func__, clip->id.name, clip);
|
2020-04-03 16:46:34 +11:00
|
|
|
movieclip_selection_sync(clip, (MovieClip *)clip->id.orig_id);
|
2018-08-13 16:59:42 -03:00
|
|
|
}
|
2020-07-29 18:13:19 +02:00
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name GPU textures
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
static GPUTexture **movieclip_get_gputexture_ptr(MovieClip *clip,
|
|
|
|
|
MovieClipUser *cuser,
|
|
|
|
|
eGPUTextureTarget textarget)
|
|
|
|
|
{
|
2020-08-05 02:20:59 +02:00
|
|
|
/* Check if we have an existing entry for that clip user. */
|
|
|
|
|
MovieClip_RuntimeGPUTexture *tex;
|
|
|
|
|
for (tex = clip->runtime.gputextures.first; tex; tex = tex->next) {
|
2020-07-29 18:13:19 +02:00
|
|
|
if (memcmp(&tex->user, cuser, sizeof(MovieClipUser)) == 0) {
|
2020-08-05 02:20:59 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-29 18:13:19 +02:00
|
|
|
|
2020-08-05 02:20:59 +02:00
|
|
|
/* If not, allocate a new one. */
|
|
|
|
|
if (tex == NULL) {
|
|
|
|
|
tex = (MovieClip_RuntimeGPUTexture *)MEM_mallocN(sizeof(MovieClip_RuntimeGPUTexture),
|
|
|
|
|
__func__);
|
2020-07-29 18:13:19 +02:00
|
|
|
|
2020-08-05 02:20:59 +02:00
|
|
|
for (int i = 0; i < TEXTARGET_COUNT; i++) {
|
|
|
|
|
tex->gputexture[i] = NULL;
|
2020-07-29 18:13:19 +02:00
|
|
|
}
|
2020-08-05 02:20:59 +02:00
|
|
|
|
|
|
|
|
memcpy(&tex->user, cuser, sizeof(MovieClipUser));
|
|
|
|
|
BLI_addtail(&clip->runtime.gputextures, tex);
|
2020-07-29 18:13:19 +02:00
|
|
|
}
|
2020-08-05 02:20:59 +02:00
|
|
|
|
|
|
|
|
return &tex->gputexture[textarget];
|
2020-07-29 18:13:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GPUTexture *BKE_movieclip_get_gpu_texture(MovieClip *clip, MovieClipUser *cuser)
|
|
|
|
|
{
|
|
|
|
|
if (clip == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GPUTexture **tex = movieclip_get_gputexture_ptr(clip, cuser, TEXTARGET_2D);
|
|
|
|
|
if (*tex) {
|
|
|
|
|
return *tex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* check if we have a valid image buffer */
|
|
|
|
|
ImBuf *ibuf = BKE_movieclip_get_ibuf(clip, cuser);
|
|
|
|
|
if (ibuf == NULL) {
|
2020-09-05 02:55:22 +02:00
|
|
|
fprintf(stderr, "GPUTexture: Blender Texture Not Loaded!\n");
|
2020-07-29 18:13:19 +02:00
|
|
|
*tex = GPU_texture_create_error(2, false);
|
|
|
|
|
return *tex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This only means RGBA16F instead of RGBA32F. */
|
|
|
|
|
const bool high_bitdepth = false;
|
|
|
|
|
const bool store_premultiplied = ibuf->rect_float ? false : true;
|
2020-09-05 17:33:56 +02:00
|
|
|
*tex = IMB_create_gpu_texture(clip->id.name + 2, ibuf, high_bitdepth, store_premultiplied);
|
2020-07-29 18:13:19 +02:00
|
|
|
|
|
|
|
|
/* Do not generate mips for movieclips... too slow. */
|
|
|
|
|
GPU_texture_mipmap_mode(*tex, false, true);
|
|
|
|
|
|
|
|
|
|
IMB_freeImBuf(ibuf);
|
|
|
|
|
|
|
|
|
|
return *tex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_movieclip_free_gputexture(struct MovieClip *clip)
|
|
|
|
|
{
|
|
|
|
|
/* number of gpu textures to keep around as cache
|
|
|
|
|
* We don't want to keep too many GPU textures for
|
|
|
|
|
* movie clips around, as they can be large.*/
|
|
|
|
|
const int MOVIECLIP_NUM_GPUTEXTURES = 1;
|
|
|
|
|
|
|
|
|
|
while (BLI_listbase_count(&clip->runtime.gputextures) > MOVIECLIP_NUM_GPUTEXTURES) {
|
|
|
|
|
MovieClip_RuntimeGPUTexture *tex = (MovieClip_RuntimeGPUTexture *)BLI_pophead(
|
|
|
|
|
&clip->runtime.gputextures);
|
|
|
|
|
for (int i = 0; i < TEXTARGET_COUNT; i++) {
|
|
|
|
|
/* free glsl image binding */
|
|
|
|
|
if (tex->gputexture[i]) {
|
|
|
|
|
GPU_texture_free(tex->gputexture[i]);
|
|
|
|
|
tex->gputexture[i] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MEM_freeN(tex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-02 18:43:17 +10:00
|
|
|
/** \} */
|