diff options
Diffstat (limited to 'source/blender/compositor')
12 files changed, 318 insertions, 5 deletions
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index 653e11c80a7..30cea825281 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -338,6 +338,11 @@ set(SRC operations/COM_KeyingScreenOperation.cpp operations/COM_KeyingScreenOperation.h + nodes/COM_TrackPositionNode.cpp + nodes/COM_TrackPositionNode.h + operations/COM_TrackPositionOperation.cpp + operations/COM_TrackPositionOperation.h + nodes/COM_KeyingNode.cpp nodes/COM_KeyingNode.h operations/COM_KeyingOperation.cpp diff --git a/source/blender/compositor/intern/COM_Converter.cpp b/source/blender/compositor/intern/COM_Converter.cpp index 05fcfb33c51..4f7b7c233f9 100644 --- a/source/blender/compositor/intern/COM_Converter.cpp +++ b/source/blender/compositor/intern/COM_Converter.cpp @@ -110,6 +110,7 @@ #include "COM_TransformNode.h" #include "COM_TranslateNode.h" #include "COM_TranslateOperation.h" +#include "COM_TrackPositionNode.h" #include "COM_ValueNode.h" #include "COM_VectorBlurNode.h" #include "COM_VectorCurveNode.h" @@ -377,6 +378,9 @@ Node *Converter::convert(bNode *b_node, bool fast) case CMP_NODE_KEYING: node = new KeyingNode(b_node); break; + case CMP_NODE_TRACKPOS: + node = new TrackPositionNode(b_node); + break; /* not inplemented yet */ default: node = new MuteNode(b_node); diff --git a/source/blender/compositor/nodes/COM_MovieClipNode.cpp b/source/blender/compositor/nodes/COM_MovieClipNode.cpp index 89bd0e8549e..a250841b160 100644 --- a/source/blender/compositor/nodes/COM_MovieClipNode.cpp +++ b/source/blender/compositor/nodes/COM_MovieClipNode.cpp @@ -81,6 +81,7 @@ void MovieClipNode::convertToOperations(ExecutionSystem *graph, CompositorContex operation->setMovieClip(movieClip); operation->setMovieClipUser(movieClipUser); operation->setFramenumber(context->getFramenumber()); + operation->setCacheFrame(!context->isRendering()); graph->addOperation(operation); MovieTrackingStabilization *stab = &movieClip->tracking.stabilization; diff --git a/source/blender/compositor/nodes/COM_TrackPositionNode.cpp b/source/blender/compositor/nodes/COM_TrackPositionNode.cpp new file mode 100644 index 00000000000..243f63a0149 --- /dev/null +++ b/source/blender/compositor/nodes/COM_TrackPositionNode.cpp @@ -0,0 +1,68 @@ +/* + * Copyright 2012, Blender Foundation. + * + * 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. + * + * Contributor: + * Jeroen Bakker + * Monique Dewanchand + * Sergey Sharybin + */ + +#include "COM_TrackPositionNode.h" +#include "COM_ExecutionSystem.h" +#include "COM_TrackPositionOperation.h" + +extern "C" { + #include "DNA_movieclip_types.h" +} + +TrackPositionNode::TrackPositionNode(bNode *editorNode) : Node(editorNode) +{ + /* pass */ +} + +void TrackPositionNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) +{ + OutputSocket *outputX = this->getOutputSocket(0); + OutputSocket *outputY = this->getOutputSocket(1); + + bNode *editorNode = this->getbNode(); + MovieClip *clip = (MovieClip *) editorNode->id; + + NodeTrackPosData *trackpos_data = (NodeTrackPosData *) editorNode->storage; + + TrackPositionOperation *operationX = new TrackPositionOperation(); + TrackPositionOperation *operationY = new TrackPositionOperation(); + + operationX->setMovieClip(clip); + operationX->setTrackingObject(trackpos_data->tracking_object); + operationX->setTrackName(trackpos_data->track_name); + operationX->setFramenumber(context->getFramenumber()); + operationX->setAxis(0); + operationX->setRelative(editorNode->custom1); + + operationY->setMovieClip(clip); + operationY->setTrackingObject(trackpos_data->tracking_object); + operationY->setTrackName(trackpos_data->track_name); + operationY->setFramenumber(context->getFramenumber()); + operationY->setAxis(1); + operationY->setRelative(editorNode->custom1); + + outputX->relinkConnections(operationX->getOutputSocket()); + outputY->relinkConnections(operationY->getOutputSocket()); + + graph->addOperation(operationX); +} diff --git a/source/blender/compositor/nodes/COM_TrackPositionNode.h b/source/blender/compositor/nodes/COM_TrackPositionNode.h new file mode 100644 index 00000000000..3d92ec3978c --- /dev/null +++ b/source/blender/compositor/nodes/COM_TrackPositionNode.h @@ -0,0 +1,36 @@ +/* + * Copyright 2012, Blender Foundation. + * + * 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. + * + * Contributor: + * Jeroen Bakker + * Monique Dewanchand + * Sergey Sharybin + */ + +#include "COM_Node.h" +#include "DNA_node_types.h" + +/** + * @brief TrackPositionNode + * @ingroup Node + */ +class TrackPositionNode : public Node { +public: + TrackPositionNode(bNode *editorNode); + void convertToOperations(ExecutionSystem *graph, CompositorContext *context); + +}; diff --git a/source/blender/compositor/operations/COM_MaskOperation.cpp b/source/blender/compositor/operations/COM_MaskOperation.cpp index 2b45cd53fd5..0d57be84720 100644 --- a/source/blender/compositor/operations/COM_MaskOperation.cpp +++ b/source/blender/compositor/operations/COM_MaskOperation.cpp @@ -84,7 +84,7 @@ void *MaskOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers buffer = (float *)MEM_callocN(sizeof(float) * width * height, "rasterized mask"); - BKE_mask_rasterize_layers(&this->m_maskLayers, width, height, buffer, TRUE, + BKE_mask_rasterize_layers(this->m_mask, &this->m_maskLayers, width, height, buffer, TRUE, this->m_do_smooth, this->m_do_feather); if (this->m_do_smooth) { diff --git a/source/blender/compositor/operations/COM_MovieClipOperation.cpp b/source/blender/compositor/operations/COM_MovieClipOperation.cpp index f53bb66d478..a5cc7196f62 100644 --- a/source/blender/compositor/operations/COM_MovieClipOperation.cpp +++ b/source/blender/compositor/operations/COM_MovieClipOperation.cpp @@ -48,7 +48,16 @@ void MovieClipOperation::initExecution() if (this->m_movieClip) { BKE_movieclip_user_set_frame(this->m_movieClipUser, this->m_framenumber); ImBuf *ibuf; - ibuf = BKE_movieclip_get_ibuf(this->m_movieClip, this->m_movieClipUser); + + if (this->m_cacheFrame) { + ibuf = BKE_movieclip_get_ibuf(this->m_movieClip, this->m_movieClipUser); + } + else { + int flag = this->m_movieClip->flag & MCLIP_TIMECODE_FLAGS; + + ibuf = BKE_movieclip_get_ibuf_flag(this->m_movieClip, this->m_movieClipUser, flag, MOVIECLIP_CACHE_SKIP); + } + if (ibuf) { this->m_movieClipBuffer = ibuf; if (ibuf->rect_float == NULL || ibuf->userflags & IB_RECT_INVALID) { diff --git a/source/blender/compositor/operations/COM_MovieClipOperation.h b/source/blender/compositor/operations/COM_MovieClipOperation.h index 2e824009ab6..50d79213428 100644 --- a/source/blender/compositor/operations/COM_MovieClipOperation.h +++ b/source/blender/compositor/operations/COM_MovieClipOperation.h @@ -43,6 +43,7 @@ protected: int m_movieClipheight; int m_movieClipwidth; int m_framenumber; + bool m_cacheFrame; /** * Determine the output resolution. The resolution is retrieved from the Renderer @@ -56,6 +57,7 @@ public: void deinitExecution(); void setMovieClip(MovieClip *image) { this->m_movieClip = image; } void setMovieClipUser(MovieClipUser *imageuser) { this->m_movieClipUser = imageuser; } + void setCacheFrame(bool value) { this->m_cacheFrame = value; } void setFramenumber(int framenumber) { this->m_framenumber = framenumber; } void executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer * inputBuffers[]); diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.cpp b/source/blender/compositor/operations/COM_TrackPositionOperation.cpp new file mode 100644 index 00000000000..cf516401a3c --- /dev/null +++ b/source/blender/compositor/operations/COM_TrackPositionOperation.cpp @@ -0,0 +1,100 @@ +/* + * Copyright 2012, Blender Foundation. + * + * 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. + * + * Contributor: + * Jeroen Bakker + * Monique Dewanchand + * Sergey Sharybin + */ + +#include "COM_TrackPositionOperation.h" + +#include "MEM_guardedalloc.h" + +#include "BLI_listbase.h" +#include "BLI_math.h" +#include "BLI_math_color.h" + +#include "DNA_scene_types.h" + +extern "C" { + #include "BKE_movieclip.h" + #include "BKE_tracking.h" +} + +TrackPositionOperation::TrackPositionOperation() : NodeOperation() +{ + this->addOutputSocket(COM_DT_VALUE); + this->movieClip = NULL; + this->framenumber = 0; + this->trackingObject[0] = 0; + this->trackName[0] = 0; + this->axis = 0; + this->relative = false; +} + +void TrackPositionOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) +{ + MovieClipUser user = {0}; + MovieTracking *tracking = &movieClip->tracking; + MovieTrackingObject *object = BKE_tracking_object_get_named(tracking, this->trackingObject); + MovieTrackingTrack *track; + MovieTrackingMarker *marker; + int width, height; + + outputValue[0] = 0.0f; + + if (!object) + return; + + track = BKE_tracking_track_get_named(tracking, object, this->trackName); + + if (!track) + return; + + BKE_movieclip_user_set_frame(&user, this->framenumber); + BKE_movieclip_get_size(this->movieClip, &user, &width, &height); + + marker = BKE_tracking_marker_get(track, this->framenumber); + + outputValue[0] = marker->pos[this->axis]; + + if (this->relative) { + int i; + + for (i = 0; i < track->markersnr; i++) { + marker = &track->markers[i]; + + if ((marker->flag & MARKER_DISABLED) == 0) { + outputValue[0] -= marker->pos[this->axis]; + + break; + } + } + } + + if (this->axis == 0) + outputValue[0] *= width; + else + outputValue[0] *= height; +} + +void TrackPositionOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +{ + resolution[0] = preferredResolution[0]; + resolution[1] = preferredResolution[1]; +} diff --git a/source/blender/compositor/operations/COM_TrackPositionOperation.h b/source/blender/compositor/operations/COM_TrackPositionOperation.h new file mode 100644 index 00000000000..caf444db0d5 --- /dev/null +++ b/source/blender/compositor/operations/COM_TrackPositionOperation.h @@ -0,0 +1,69 @@ +/* + * Copyright 2012, Blender Foundation. + * + * 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. + * + * Contributor: + * Jeroen Bakker + * Monique Dewanchand + * Sergey Sharybin + */ + + +#ifndef _COM_TrackPositionOperation_h +#define _COM_TrackPositionOperation_h + +#include <string.h> + +#include "COM_NodeOperation.h" + +#include "DNA_scene_types.h" +#include "DNA_movieclip_types.h" + +#include "BLI_listbase.h" + +/** + * Class with implementation of green screen gradient rasterization + */ +class TrackPositionOperation : public NodeOperation { +protected: + MovieClip *movieClip; + int framenumber; + char trackingObject[64]; + char trackName[64]; + int axis; + bool relative; + + /** + * Determine the output resolution. The resolution is retrieved from the Renderer + */ + void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + +public: + TrackPositionOperation(); + + void setMovieClip(MovieClip *clip) {this->movieClip = clip;} + void setTrackingObject(char *object) {strncpy(this->trackingObject, object, sizeof(this->trackingObject));} + void setTrackName(char *track) {strncpy(this->trackName, track, sizeof(this->trackName));} + void setFramenumber(int framenumber) {this->framenumber = framenumber;} + void setAxis(int value) {this->axis = value;} + void setRelative(bool value) {this->relative = value;} + + void executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer * inputBuffers[]); + + const bool isSetOperation() const { return true; } +}; + +#endif diff --git a/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp b/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp index 446b169763c..f229c6cf365 100644 --- a/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp @@ -35,6 +35,7 @@ extern "C" { #include "MEM_guardedalloc.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" + #include "IMB_colormanagement.h" } @@ -46,10 +47,13 @@ ViewerBaseOperation::ViewerBaseOperation() : NodeOperation() this->m_outputBufferDisplay = NULL; this->m_active = false; this->m_doColorManagement = true; + this->m_partialBufferUpdate = NULL; } void ViewerBaseOperation::initExecution() { + this->m_partialBufferUpdate = NULL; + if (isActiveViewerOutput()) { initImage(); } @@ -59,7 +63,7 @@ void ViewerBaseOperation::initImage() { Image *anImage = this->m_image; ImBuf *ibuf = BKE_image_acquire_ibuf(anImage, this->m_imageUser, &this->m_lock); - + if (!ibuf) return; if (ibuf->x != (int)getWidth() || ibuf->y != (int)getHeight()) { imb_freerectImBuf(ibuf); @@ -71,20 +75,34 @@ void ViewerBaseOperation::initImage() imb_addrectfloatImBuf(ibuf); anImage->ok = IMA_OK_LOADED; } - + + this->m_partialBufferUpdate = IMB_partial_buffer_update_context_new(ibuf); + /* now we combine the input with ibuf */ this->m_outputBuffer = ibuf->rect_float; this->m_outputBufferDisplay = (unsigned char *)ibuf->rect; - + BKE_image_release_ibuf(this->m_image, this->m_lock); } void ViewerBaseOperation:: updateImage(rcti *rect) { + IMB_partial_buffer_update_rect(this->m_partialBufferUpdate, this->m_outputBuffer, rect); + WM_main_add_notifier(NC_WINDOW | ND_DRAW, NULL); } void ViewerBaseOperation::deinitExecution() { + if (this->m_partialBufferUpdate) { + /* partial buffer context could be NULL if it's not active viewer node */ + + ImBuf *ibuf = BKE_image_acquire_ibuf(this->m_image, this->m_imageUser, &this->m_lock); + + IMB_partial_buffer_update_free(this->m_partialBufferUpdate, ibuf); + + BKE_image_release_ibuf(this->m_image, this->m_lock); + } + this->m_outputBuffer = NULL; } diff --git a/source/blender/compositor/operations/COM_ViewerBaseOperation.h b/source/blender/compositor/operations/COM_ViewerBaseOperation.h index f3fd1e9c9df..4052c49ebbc 100644 --- a/source/blender/compositor/operations/COM_ViewerBaseOperation.h +++ b/source/blender/compositor/operations/COM_ViewerBaseOperation.h @@ -40,6 +40,7 @@ protected: bool m_doColorManagement; bool m_doColorPredivide; + struct PartialBufferUpdateContext *m_partialBufferUpdate; public: bool isOutputOperation(bool rendering) const { return isActiveViewerOutput(); } void initExecution(); |