Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-04-16 17:25:10 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-04-16 17:25:10 +0400
commitd1b1d194dc9cc741d87dc63e701402de0776c694 (patch)
tree344bde4783c61c65412fa1fd2435e705ead26965
parentb3972aeea05bc6c60d7b7da4e6b59a64b822448a (diff)
Fix for half pixel offset rasterizing masks
-rw-r--r--source/blender/blenkernel/intern/mask_rasterize.c8
-rw-r--r--source/blender/compositor/operations/COM_MaskOperation.cpp5
-rw-r--r--source/blender/compositor/operations/COM_MaskOperation.h3
-rw-r--r--source/blender/editors/mask/mask_draw.c12
4 files changed, 21 insertions, 7 deletions
diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c
index 92628387dc6..ea039dabce4 100644
--- a/source/blender/blenkernel/intern/mask_rasterize.c
+++ b/source/blender/blenkernel/intern/mask_rasterize.c
@@ -1434,6 +1434,10 @@ void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle,
const unsigned int width, const unsigned int height,
float *buffer)
{
+ const float x_inv = 1.0f / (float)width;
+ const float y_inv = 1.0f / (float)height;
+ const float x_px_ofs = x_inv * 0.5f;
+ const float y_px_ofs = y_inv * 0.5f;
#ifdef _MSC_VER
int y; /* msvc requires signed for some reason */
@@ -1449,9 +1453,9 @@ void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle,
unsigned int i = y * width;
unsigned int x;
float xy[2];
- xy[1] = (float)y / (float)height;
+ xy[1] = ((float)y * y_inv) + y_px_ofs;
for (x = 0; x < width; x++, i++) {
- xy[0] = (float)x / (float)width;
+ xy[0] = ((float)x * x_inv) + x_px_ofs;
buffer[i] = BKE_maskrasterize_handle_sample(mr_handle, xy);
}
diff --git a/source/blender/compositor/operations/COM_MaskOperation.cpp b/source/blender/compositor/operations/COM_MaskOperation.cpp
index 112b5912ad3..8c8ba93327d 100644
--- a/source/blender/compositor/operations/COM_MaskOperation.cpp
+++ b/source/blender/compositor/operations/COM_MaskOperation.cpp
@@ -129,8 +129,9 @@ void MaskOperation::determineResolution(unsigned int resolution[2], unsigned int
void MaskOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
- const float xy[2] = {x * this->m_maskWidthInv,
- y * this->m_maskHeightInv};
+ const float xy[2] = {
+ (x * this->m_maskWidthInv) + this->m_mask_px_ofs[0],
+ (y * this->m_maskHeightInv) + this->m_mask_px_ofs[1]};
if (this->m_rasterMaskHandleTot == 1) {
if (this->m_rasterMaskHandles[0]) {
diff --git a/source/blender/compositor/operations/COM_MaskOperation.h b/source/blender/compositor/operations/COM_MaskOperation.h
index 18d7e594104..522b873e167 100644
--- a/source/blender/compositor/operations/COM_MaskOperation.h
+++ b/source/blender/compositor/operations/COM_MaskOperation.h
@@ -43,6 +43,7 @@ protected:
int m_maskHeight;
float m_maskWidthInv; /* 1 / m_maskWidth */
float m_maskHeightInv; /* 1 / m_maskHeight */
+ float m_mask_px_ofs[2];
float m_frame_shutter;
int m_frame_number;
@@ -70,11 +71,13 @@ public:
{
this->m_maskWidth = width;
this->m_maskWidthInv = 1.0f / (float)width;
+ this->m_mask_px_ofs[0] = this->m_maskWidthInv * 0.5f;
}
void setMaskHeight(int height)
{
this->m_maskHeight = height;
this->m_maskHeightInv = 1.0f / (float)height;
+ this->m_mask_px_ofs[1] = this->m_maskHeightInv * 0.5f;
}
void setFramenumber(int frame_number) { this->m_frame_number = frame_number; }
void setSmooth(bool smooth) { this->m_do_smooth = smooth; }
diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c
index e84bdf12067..08896b39682 100644
--- a/source/blender/editors/mask/mask_draw.c
+++ b/source/blender/editors/mask/mask_draw.c
@@ -643,15 +643,21 @@ static void mask_rasterize_func(TaskPool *pool, void *taskdata, int UNUSED(threa
ThreadedMaskRasterizeState *state = (ThreadedMaskRasterizeState *) BLI_task_pool_userdata(pool);
ThreadedMaskRasterizeData *data = (ThreadedMaskRasterizeData *) taskdata;
int scanline;
+ const float x_inv = 1.0f / (float)state->width;
+ const float y_inv = 1.0f / (float)state->height;
+ const float x_px_ofs = x_inv * 0.5f;
+ const float y_px_ofs = y_inv * 0.5f;
for (scanline = 0; scanline < data->num_scanlines; scanline++) {
+ float xy[2];
int x, y = data->start_scanline + scanline;
+
+ xy[1] = ((float)y * y_inv) + y_px_ofs;
+
for (x = 0; x < state->width; x++) {
int index = y * state->width + x;
- float xy[2];
- xy[0] = (float) x / state->width;
- xy[1] = (float) y / state->height;
+ xy[0] = ((float)x * x_inv) + x_px_ofs;
state->buffer[index] = BKE_maskrasterize_handle_sample(state->handle, xy);
}