Commit: d1b1d194dc9cc741d87dc63e701402de0776c694
Author: Campbell Barton
Date:   Wed Apr 16 23:25:10 2014 +1000
https://developer.blender.org/rBd1b1d194dc9cc741d87dc63e701402de0776c694

Fix for half pixel offset rasterizing masks

===================================================================

M       source/blender/blenkernel/intern/mask_rasterize.c
M       source/blender/compositor/operations/COM_MaskOperation.cpp
M       source/blender/compositor/operations/COM_MaskOperation.h
M       source/blender/editors/mask/mask_draw.c

===================================================================

diff --git a/source/blender/blenkernel/intern/mask_rasterize.c 
b/source/blender/blenkernel/intern/mask_rasterize.c
index 9262838..ea039da 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 112b591..8c8ba93 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 18d7e59..522b873 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 e84bdf1..08896b3 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);
                }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to