diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-05-22 13:15:01 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-05-22 13:15:01 +0400 |
commit | 1ae392913833edd2b11cef5b682f04ac8e70c4c4 (patch) | |
tree | 0f8f991eaa527cada11ddae00ebb381e8a2c46b2 /source/blender/compositor/operations | |
parent | 40b7b9655afca32bf3fdae9bd6f58e7b377ddade (diff) |
Fix for movie distoriton node in tiles
Now it works in the same way as non-tiles node in cases when image's
resolution is not equal to resolution used for calibration.
Also add some additional checks for distortion cache, so now it should
be updating properly when camera intrinsics are changing.
Potentially added support of overscan, but currently all needed computation
is commented out.
Diffstat (limited to 'source/blender/compositor/operations')
-rw-r--r-- | source/blender/compositor/operations/COM_MovieDistortionOperation.cpp | 17 | ||||
-rw-r--r-- | source/blender/compositor/operations/COM_MovieDistortionOperation.h | 44 |
2 files changed, 48 insertions, 13 deletions
diff --git a/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp b/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp index 1699707ab3a..ebea9e8b4a2 100644 --- a/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp +++ b/source/blender/compositor/operations/COM_MovieDistortionOperation.cpp @@ -24,8 +24,8 @@ extern "C" { #include "BKE_tracking.h" - -#include "BLI_linklist.h" + #include "BKE_movieclip.h" + #include "BLI_linklist.h" } @@ -46,14 +46,23 @@ void MovieDistortionOperation::initExecution() { this->inputOperation = this->getInputSocketReader(0); if (this->movieClip) { + MovieClipUser clipUser = {0}; + int calibration_width, calibration_height; + + BKE_movieclip_user_set_frame(&clipUser, this->framenumber); + BKE_movieclip_get_size(this->movieClip, &clipUser, &calibration_width, &calibration_height); + for (int i = 0 ; i < s_cache.size() ; i ++) { DistortionCache *c = (DistortionCache*)s_cache[i]; - if (c->isCacheFor(this->movieClip, this->width, this->height, this->distortion)) { + if (c->isCacheFor(this->movieClip, this->width, this->height, + calibration_width, calibration_height, this->distortion)) + { this->cache = c; return; } } - DistortionCache *newC = new DistortionCache(this->movieClip, this->width, this->height, this->distortion); + DistortionCache *newC = new DistortionCache(this->movieClip, this->width, this->height, + calibration_width, calibration_height, this->distortion); s_cache.push_back(newC); this->cache = newC; } diff --git a/source/blender/compositor/operations/COM_MovieDistortionOperation.h b/source/blender/compositor/operations/COM_MovieDistortionOperation.h index fcdf7090566..f583493340b 100644 --- a/source/blender/compositor/operations/COM_MovieDistortionOperation.h +++ b/source/blender/compositor/operations/COM_MovieDistortionOperation.h @@ -34,18 +34,28 @@ private: float k1; float k2; float k3; + float principal_x; + float principal_y; + float pixel_aspect; int width; int height; + int calibration_width; + int calibration_height; bool inverted; float *buffer; int *bufferCalculated; public: - DistortionCache(MovieClip *movieclip, int width, int height, bool inverted) { + DistortionCache(MovieClip *movieclip, int width, int height, int calibration_width, int calibration_height, bool inverted) { this->k1 = movieclip->tracking.camera.k1; this->k2 = movieclip->tracking.camera.k2; this->k3 = movieclip->tracking.camera.k3; + this->principal_x = movieclip->tracking.camera.principal[0]; + this->principal_y = movieclip->tracking.camera.principal[1]; + this->pixel_aspect = movieclip->tracking.camera.pixel_aspect; this->width = width; this->height = height; + this->calibration_width = calibration_width; + this->calibration_height = calibration_height; this->inverted = inverted; this->bufferCalculated = new int[this->width*this->height]; this->buffer = new float[this->width*this->height*2]; @@ -53,13 +63,18 @@ public: this->bufferCalculated[i] = 0; } } - bool isCacheFor(MovieClip *movieclip, int width, int height, bool inverted) { + bool isCacheFor(MovieClip *movieclip, int width, int height, int calibration_width, int claibration_height, bool inverted) { return this->k1 == movieclip->tracking.camera.k1 && this->k2 == movieclip->tracking.camera.k2 && this->k3 == movieclip->tracking.camera.k3 && + this->principal_x == movieclip->tracking.camera.principal[0] && + this->principal_y == movieclip->tracking.camera.principal[1] && + this->pixel_aspect == movieclip->tracking.camera.pixel_aspect && this->inverted == inverted && - this->width == width && - this->height == height; + this->width == width && + this->height == height && + this->calibration_width == calibration_width && + this->calibration_height == calibration_height; } void getUV(MovieTracking *trackingData, int x, int y, float *u, float*v) { @@ -67,20 +82,30 @@ public: *u = x; *v = y; } else { + int offset = y * this->width + x; int offset2 = offset*2; if (!bufferCalculated[offset]) { + //float overscan = 0.0f; + float w = (float)this->width/* / (1 + overscan) */; + float h = (float)this->height/* / (1 + overscan) */; + float aspx = (float)w / this->calibration_width; + float aspy = (float)h / this->calibration_height; float in[2]; float out[2]; - in[0] = x; - in[1] = y; + + in[0] = (x /* - 0.5 * overscan * w */) / aspx; + in[1] = (y /* - 0.5 * overscan * h */) / aspy / this->pixel_aspect; + if (inverted) { BKE_tracking_invert_intrinsics(trackingData, in, out); } else { BKE_tracking_apply_intrinsics(trackingData, in, out); } - buffer[offset2] = out[0]; - buffer[offset2+1] = out[1]; + + buffer[offset2] = out[0] * aspx /* + 0.5 * overscan * w */; + buffer[offset2+1] = (out[1] * aspy /* + 0.5 * overscan * h */) * this->pixel_aspect; + bufferCalculated[offset] = 1; } *u = buffer[offset2]; @@ -97,6 +122,7 @@ private: protected: bool distortion; + int framenumber; public: MovieDistortionOperation(bool distortion); @@ -107,7 +133,7 @@ public: void deinitExecution(); void setMovieClip(MovieClip *clip) {this->movieClip = clip;} - + void setFramenumber(int framenumber) {this->framenumber = framenumber;} }; #endif |