Camera tracking integration
=========================== Added compositor node "Movie Clip" There could be some problems due to bug #27997, but heneral workflow works fine here.
This commit is contained in:
@@ -387,6 +387,7 @@ void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat);
|
||||
#define CMP_NODE_COLOR_MATTE 259
|
||||
#define CMP_NODE_COLORBALANCE 260
|
||||
#define CMP_NODE_HUECORRECT 261
|
||||
#define CMP_NODE_MOVIECLIP 262
|
||||
|
||||
#define CMP_NODE_GLARE 301
|
||||
#define CMP_NODE_TONEMAP 302
|
||||
|
||||
@@ -55,11 +55,13 @@
|
||||
#include "DNA_movieclip_types.h"
|
||||
#include "DNA_object_types.h" /* SELECT */
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_ghash.h"
|
||||
#include "BLI_mempool.h"
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_mempool.h"
|
||||
#include "BLI_threads.h"
|
||||
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_global.h"
|
||||
@@ -288,14 +290,21 @@ ImBuf *BKE_movieclip_acquire_ibuf(MovieClip *clip, MovieClipUser *user)
|
||||
ImBuf *ibuf= NULL;
|
||||
int framenr= user?user->framenr:clip->lastframe;
|
||||
|
||||
/* cache is supposed to be threadsafe */
|
||||
ibuf= get_imbuf_cache(clip, user);
|
||||
|
||||
if(!ibuf) {
|
||||
if(clip->source==MCLIP_SRC_SEQUENCE)
|
||||
ibuf= movieclip_load_sequence_file(clip, framenr);
|
||||
else
|
||||
else {
|
||||
/* loading of movies can't happen from concurent threads */
|
||||
BLI_lock_thread(LOCK_MOVIECLIP);
|
||||
|
||||
ibuf= movieclip_load_movie_file(clip, framenr);
|
||||
|
||||
BLI_unlock_thread(LOCK_MOVIECLIP);
|
||||
}
|
||||
|
||||
if(ibuf)
|
||||
put_imbuf_cache(clip, user, ibuf);
|
||||
}
|
||||
|
||||
@@ -3305,6 +3305,10 @@ int ntreeCompositTagAnimated(bNodeTree *ntree)
|
||||
NodeTagChanged(ntree, node);
|
||||
}
|
||||
}
|
||||
else if(node->type==CMP_NODE_MOVIECLIP) {
|
||||
NodeTagChanged(ntree, node);
|
||||
tagged= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return tagged;
|
||||
@@ -3451,6 +3455,7 @@ static void registerCompositNodes(ListBase *ntypelist)
|
||||
register_node_type_cmp_value(ntypelist);
|
||||
register_node_type_cmp_rgb(ntypelist);
|
||||
register_node_type_cmp_curve_time(ntypelist);
|
||||
register_node_type_cmp_movieclip(ntypelist);
|
||||
|
||||
register_node_type_cmp_composite(ntypelist);
|
||||
register_node_type_cmp_viewer(ntypelist);
|
||||
|
||||
@@ -71,6 +71,7 @@ int BLI_system_thread_count(void); /* gets the number of threads the system can
|
||||
#define LOCK_CUSTOM1 3
|
||||
#define LOCK_RCACHE 4
|
||||
#define LOCK_OPENGL 5
|
||||
#define LOCK_MOVIECLIP 6
|
||||
|
||||
void BLI_lock_thread(int type);
|
||||
void BLI_unlock_thread(int type);
|
||||
|
||||
@@ -114,6 +114,7 @@ static pthread_mutex_t _viewer_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t _custom1_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t _rcache_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t _opengl_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t _movieclip_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_t mainid;
|
||||
static int thread_levels= 0; /* threads can be invoked inside threads */
|
||||
|
||||
@@ -349,6 +350,8 @@ void BLI_lock_thread(int type)
|
||||
pthread_mutex_lock(&_rcache_lock);
|
||||
else if (type==LOCK_OPENGL)
|
||||
pthread_mutex_lock(&_opengl_lock);
|
||||
else if (type==LOCK_MOVIECLIP)
|
||||
pthread_mutex_lock(&_movieclip_lock);
|
||||
}
|
||||
|
||||
void BLI_unlock_thread(int type)
|
||||
@@ -365,6 +368,8 @@ void BLI_unlock_thread(int type)
|
||||
pthread_mutex_unlock(&_rcache_lock);
|
||||
else if(type==LOCK_OPENGL)
|
||||
pthread_mutex_unlock(&_opengl_lock);
|
||||
else if(type==LOCK_MOVIECLIP)
|
||||
pthread_mutex_unlock(&_movieclip_lock);
|
||||
}
|
||||
|
||||
/* Mutex Locks */
|
||||
|
||||
@@ -155,8 +155,9 @@ static void draw_movieclip_buffer(SpaceClip *sc, ARegion *ar, ImBuf *ibuf, float
|
||||
glColor3f(0.0f, 0.0f, 0.0f);
|
||||
glRectf(x, y, x+ibuf->x*sc->zoom, y+ibuf->y*sc->zoom);
|
||||
} else {
|
||||
if(ibuf->rect_float)
|
||||
if(ibuf->rect_float && !ibuf->rect) {
|
||||
IMB_rect_from_float(ibuf);
|
||||
}
|
||||
|
||||
if(ibuf->rect)
|
||||
glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
|
||||
|
||||
@@ -1075,6 +1075,11 @@ static void node_composit_buts_ycc(uiLayout *layout, bContext *UNUSED(C), Pointe
|
||||
uiItemR(layout, ptr, "mode", 0, "", ICON_NONE);
|
||||
}
|
||||
|
||||
static void node_composit_buts_movieclip(uiLayout *layout, bContext *C, PointerRNA *ptr)
|
||||
{
|
||||
uiTemplateID(layout, C, ptr, "clip", NULL, "CLIP_OT_open", NULL);
|
||||
}
|
||||
|
||||
/* only once called */
|
||||
static void node_composit_set_butfunc(bNodeType *ntype)
|
||||
{
|
||||
@@ -1225,6 +1230,9 @@ static void node_composit_set_butfunc(bNodeType *ntype)
|
||||
case CMP_NODE_SEPYCCA:
|
||||
ntype->uifunc=node_composit_buts_ycc;
|
||||
break;
|
||||
case CMP_NODE_MOVIECLIP:
|
||||
ntype->uifunc= node_composit_buts_movieclip;
|
||||
break;
|
||||
default:
|
||||
ntype->uifunc= NULL;
|
||||
}
|
||||
|
||||
@@ -2268,6 +2268,20 @@ static void def_cmp_ycc(StructRNA *srna)
|
||||
RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
|
||||
}
|
||||
|
||||
static void def_cmp_movieclip(StructRNA *srna)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
prop = RNA_def_property(srna, "clip", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_pointer_sdna(prop, NULL, "id");
|
||||
RNA_def_property_struct_type(prop, "MovieClip");
|
||||
RNA_def_property_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_ui_text(prop, "Movie Clip", "");
|
||||
RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
|
||||
|
||||
RNA_def_struct_sdna_from(srna, "MovieClipUser", "storage");
|
||||
}
|
||||
|
||||
|
||||
/* -- Texture Nodes --------------------------------------------------------- */
|
||||
|
||||
|
||||
@@ -114,6 +114,7 @@ DefNode( CompositorNode, CMP_NODE_COLOR_MATTE, def_cmp_color_matte, "COLOR
|
||||
DefNode( CompositorNode, CMP_NODE_DIST_MATTE, def_cmp_distance_matte, "DISTANCE_MATTE", DistanceMatte, "Distance Matte", "" )
|
||||
DefNode( CompositorNode, CMP_NODE_COLORBALANCE, def_cmp_colorbalance, "COLORBALANCE", ColorBalance, "Color Balance", "" )
|
||||
DefNode( CompositorNode, CMP_NODE_HUECORRECT, def_cmp_huecorrect, "HUECORRECT", HueCorrect, "Hue Correct", "" )
|
||||
DefNode( CompositorNode, CMP_NODE_MOVIECLIP, def_cmp_movieclip, "MOVIECLIP", MovieClip, "MovieClip", "" )
|
||||
|
||||
DefNode( TextureNode, TEX_NODE_OUTPUT, def_tex_output, "OUTPUT", Output, "Output", "" )
|
||||
DefNode( TextureNode, TEX_NODE_CHECKER, 0, "CHECKER", Checker, "Checker", "" )
|
||||
|
||||
@@ -48,6 +48,7 @@ void register_node_type_cmp_texture(ListBase *lb);
|
||||
void register_node_type_cmp_value(ListBase *lb);
|
||||
void register_node_type_cmp_rgb(ListBase *lb);
|
||||
void register_node_type_cmp_curve_time(ListBase *lb);
|
||||
void register_node_type_cmp_movieclip(ListBase *lb);
|
||||
|
||||
void register_node_type_cmp_composite(ListBase *lb);
|
||||
void register_node_type_cmp_viewer(ListBase *lb);
|
||||
|
||||
@@ -75,6 +75,7 @@ set(SRC
|
||||
intern/CMP_nodes/CMP_mapValue.c
|
||||
intern/CMP_nodes/CMP_math.c
|
||||
intern/CMP_nodes/CMP_mixrgb.c
|
||||
intern/CMP_nodes/CMP_movieclip.c
|
||||
intern/CMP_nodes/CMP_normal.c
|
||||
intern/CMP_nodes/CMP_normalize.c
|
||||
intern/CMP_nodes/CMP_outputFile.c
|
||||
|
||||
157
source/blender/nodes/intern/CMP_nodes/CMP_movieclip.c
Normal file
157
source/blender/nodes/intern/CMP_nodes/CMP_movieclip.c
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): Blender Foundation,
|
||||
* Sergey Sharybin
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/** \file blender/nodes/intern/CMP_nodes/CMP_movieclip.c
|
||||
* \ingroup cmpnodes
|
||||
*/
|
||||
|
||||
|
||||
#include "../CMP_util.h"
|
||||
|
||||
|
||||
static bNodeSocketType cmp_node_rlayers_out[]= {
|
||||
{ SOCK_RGBA, 0, "Image", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
|
||||
{ -1, 0, "" }
|
||||
};
|
||||
|
||||
static CompBuf *node_composit_get_movieclip(RenderData *rd, MovieClip *clip, MovieClipUser *user)
|
||||
{
|
||||
ImBuf *ibuf;
|
||||
CompBuf *stackbuf;
|
||||
int type;
|
||||
|
||||
float *rect;
|
||||
int alloc= FALSE;
|
||||
|
||||
ibuf= BKE_movieclip_acquire_ibuf(clip, user);
|
||||
if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL)) {
|
||||
IMB_freeImBuf(ibuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ibuf->rect_float == NULL) {
|
||||
IMB_float_from_rect(ibuf);
|
||||
}
|
||||
|
||||
/* now we need a float buffer from the image with matching color management */
|
||||
if(ibuf->channels == 4) {
|
||||
if(rd->color_mgt_flag & R_COLOR_MANAGEMENT) {
|
||||
if(ibuf->profile != IB_PROFILE_NONE) {
|
||||
rect= ibuf->rect_float;
|
||||
}
|
||||
else {
|
||||
rect= MEM_mapallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, "node_composit_get_image");
|
||||
srgb_to_linearrgb_rgba_rgba_buf(rect, ibuf->rect_float, ibuf->x * ibuf->y);
|
||||
alloc= TRUE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(ibuf->profile == IB_PROFILE_NONE) {
|
||||
rect= ibuf->rect_float;
|
||||
}
|
||||
else {
|
||||
rect= MEM_mapallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, "node_composit_get_image");
|
||||
linearrgb_to_srgb_rgba_rgba_buf(rect, ibuf->rect_float, ibuf->x * ibuf->y);
|
||||
alloc= TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* non-rgba passes can't use color profiles */
|
||||
rect= ibuf->rect_float;
|
||||
}
|
||||
/* done coercing into the correct color management */
|
||||
|
||||
if(!alloc) {
|
||||
rect= MEM_dupallocN(rect);
|
||||
alloc= 1;
|
||||
}
|
||||
|
||||
type= ibuf->channels;
|
||||
|
||||
if(rd->scemode & R_COMP_CROP) {
|
||||
stackbuf= get_cropped_compbuf(&rd->disprect, rect, ibuf->x, ibuf->y, type);
|
||||
if(alloc)
|
||||
MEM_freeN(rect);
|
||||
}
|
||||
else {
|
||||
/* we put imbuf copy on stack, cbuf knows rect is from other ibuf when freed! */
|
||||
stackbuf= alloc_compbuf(ibuf->x, ibuf->y, type, FALSE);
|
||||
stackbuf->rect= rect;
|
||||
stackbuf->malloc= alloc;
|
||||
}
|
||||
|
||||
IMB_freeImBuf(ibuf);
|
||||
|
||||
return stackbuf;
|
||||
}
|
||||
|
||||
static void node_composit_exec_movieclip(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out)
|
||||
{
|
||||
if(node->id) {
|
||||
RenderData *rd= data;
|
||||
MovieClip *clip= (MovieClip *)node->id;
|
||||
MovieClipUser *user= (MovieClipUser *)node->storage;
|
||||
CompBuf *stackbuf= NULL;
|
||||
|
||||
BKE_movieclip_user_set_frame(user, rd->cfra);
|
||||
|
||||
stackbuf= node_composit_get_movieclip(rd, clip, user);
|
||||
|
||||
if (stackbuf) {
|
||||
/* put image on stack */
|
||||
out[0]->data= stackbuf;
|
||||
|
||||
/* generate preview */
|
||||
generate_preview(data, node, stackbuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void node_composit_init_movieclip(bNode* node)
|
||||
{
|
||||
MovieClipUser *user= MEM_callocN(sizeof(MovieClipUser), "node movie clip user");
|
||||
node->storage= user;
|
||||
user->framenr= 1;
|
||||
}
|
||||
|
||||
void register_node_type_cmp_movieclip(ListBase *lb)
|
||||
{
|
||||
static bNodeType ntype;
|
||||
|
||||
node_type_base(&ntype, CMP_NODE_MOVIECLIP, "Movie Clip", NODE_CLASS_INPUT, NODE_PREVIEW|NODE_OPTIONS,
|
||||
NULL, cmp_node_rlayers_out);
|
||||
node_type_size(&ntype, 120, 80, 300);
|
||||
node_type_init(&ntype, node_composit_init_movieclip);
|
||||
node_type_storage(&ntype, "MovieClipUser", node_free_standard_storage, node_copy_standard_storage);
|
||||
node_type_exec(&ntype, node_composit_exec_movieclip);
|
||||
|
||||
nodeRegisterType(lb, &ntype);
|
||||
}
|
||||
@@ -46,6 +46,7 @@
|
||||
#include "DNA_ID.h"
|
||||
#include "DNA_image_types.h"
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_movieclip_types.h"
|
||||
#include "DNA_node_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
@@ -64,6 +65,7 @@
|
||||
#include "BKE_image.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_movieclip.h"
|
||||
#include "BKE_node.h"
|
||||
#include "BKE_texture.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user