From e6ee2c0db607c09454f630d6f10372b4e12e81db Mon Sep 17 00:00:00 2001 From: "Thouis (Ray) Jones" Date: Tue, 5 Mar 2013 10:37:56 -0500 Subject: [PATCH] BUG: not all histogram memory was aligned correctly --- skimage/filter/_ctmf.pyx | 24 +++++++++++------------- skimage/filter/setup.py | 3 ++- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/skimage/filter/_ctmf.pyx b/skimage/filter/_ctmf.pyx index 1a03ff5a..7cb5251f 100644 --- a/skimage/filter/_ctmf.pyx +++ b/skimage/filter/_ctmf.pyx @@ -20,7 +20,7 @@ from libc.stdlib cimport malloc, free from libc.string cimport memset -cdef extern from "../_shared/vectorized_ops.h": +cdef extern from "vectorized_ops.h": void add16(cnp.uint16_t *dest, cnp.uint16_t *src) void sub16(cnp.uint16_t *dest, cnp.uint16_t *src) @@ -91,8 +91,9 @@ cdef struct SCoord: Py_ssize_t y cdef struct Histograms: - void *memory # pointer to the allocated memory - Histogram *histogram # pointer to the histogram memory + HistogramPiece accumulator # running histogram (32-byte aligned) + void *memory # pointer to the unaligned allocated memory + Histogram *histogram # pointer to the histogram memory (aligned) PixelCount *pixel_count # pointer to the pixel count memory cnp.uint8_t *data # pointer to the image data cnp.uint8_t *mask # pointer to the image mask @@ -142,9 +143,6 @@ cdef struct Histograms: Py_ssize_t row_stride # stride between one row and the next Py_ssize_t col_stride # stride between one column and the next - # The accumulator holds the running histogram - # - HistogramPiece accumulator # # The running count of pixels in the accumulator # @@ -188,10 +186,12 @@ cdef Histograms *allocate_histograms(Py_ssize_t rows, memory_size = (adjusted_stripe_length * (sizeof(Histogram) + sizeof(PixelCount)) + - sizeof(Histograms) + 32) + sizeof(Histograms) + 64) ptr = malloc(memory_size) memset(ptr, 0, memory_size) - ph = ptr + # align ph.accumulator to 32-byte boundary + roundoff = ( ptr + 31) % 32 + ph = (ptr + 31 - roundoff) if not ptr: return ph ph.memory = ptr @@ -201,10 +201,8 @@ cdef Histograms *allocate_histograms(Py_ssize_t rows, # # Align histogram memory to a 32-byte boundary # - roundoff = ptr - roundoff += 31 - roundoff -= roundoff % 32 - ptr = roundoff + roundoff = ( ptr + 31) % 32 + ptr += 31 - roundoff ph.histogram = ptr # # Fill in the statistical things we keep around @@ -696,7 +694,7 @@ cdef int c_median_filter(Py_ssize_t rows, # # Initialize the accumulator (octagon histogram) to zero # - memset(&ph.accumulator, 0, sizeof(ph.accumulator)) + memset(&(ph.accumulator), 0, sizeof(ph.accumulator)) ph.accumulator_count = 0 for i in range(16): ph.last_update_column[i] = -radius-1 diff --git a/skimage/filter/setup.py b/skimage/filter/setup.py index 934d3f2e..dba8172c 100644 --- a/skimage/filter/setup.py +++ b/skimage/filter/setup.py @@ -26,7 +26,8 @@ def configuration(parent_package='', top_path=None): cython(['rank/bilateral_rank.pyx'], working_path=base_path) config.add_extension('_ctmf', sources=['_ctmf.c'], - include_dirs=[get_numpy_include_dirs()]) + depends=['../_shared/vectorized_ops.h'], + include_dirs=[get_numpy_include_dirs(), '../_shared']) config.add_extension('_denoise_cy', sources=['_denoise_cy.c'], include_dirs=[get_numpy_include_dirs(), '../_shared']) config.add_extension('rank._core8', sources=['rank/_core8.c'],