From 224f73653a2fcb92e6d3dd55803fba03d99c50dd Mon Sep 17 00:00:00 2001 From: sekrit-twc Date: Wed, 14 Jul 2021 20:32:38 -0700 Subject: [PATCH] common: use variable template for AlignmentOf --- src/zimg/common/align.h | 6 ++---- src/zimg/common/pixel.h | 8 ++++---- src/zimg/depth/dither.cpp | 4 ++-- src/zimg/resize/filter.cpp | 8 ++++---- src/zimg/unresize/bilinear.cpp | 4 ++-- test/graph/audit_buffer.cpp | 8 ++++---- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/zimg/common/align.h b/src/zimg/common/align.h index d53bd72..ec524b3 100644 --- a/src/zimg/common/align.h +++ b/src/zimg/common/align.h @@ -34,14 +34,12 @@ template constexpr T floor_n(T x, unsigned n) { return x & ~static_cast(n - 1); } /** - * Helper struct that computes alignment in units of object count. + * Alignment in units of object count. * * @tparam T type of object */ template -struct AlignmentOf { - static constexpr unsigned value = ALIGNMENT / sizeof(T); -}; +constexpr unsigned AlignmentOf = ALIGNMENT / sizeof(T); } // namespace zimg diff --git a/src/zimg/common/pixel.h b/src/zimg/common/pixel.h index 33249e0..76c75a2 100644 --- a/src/zimg/common/pixel.h +++ b/src/zimg/common/pixel.h @@ -40,10 +40,10 @@ struct PixelTraits { * Table used by {@link pixel_get_traits}. */ constexpr PixelTraits pixel_traits_table[] = { - { sizeof(uint8_t), 8, AlignmentOf::value, true }, - { sizeof(uint16_t), 16, AlignmentOf::value, true }, - { sizeof(uint16_t), 16, AlignmentOf::value, false }, - { sizeof(float), 32, AlignmentOf::value, false }, + { sizeof(uint8_t), 8, AlignmentOf, true }, + { sizeof(uint16_t), 16, AlignmentOf, true }, + { sizeof(uint16_t), 16, AlignmentOf, false }, + { sizeof(float), 32, AlignmentOf, false }, }; /** diff --git a/src/zimg/depth/dither.cpp b/src/zimg/depth/dither.cpp index 73a458e..9d782c9 100644 --- a/src/zimg/depth/dither.cpp +++ b/src/zimg/depth/dither.cpp @@ -174,8 +174,8 @@ class NoneDitherTable final : public OrderedDitherTable { public: std::tuple get_dither_coeffs(unsigned i, unsigned seq) const override { - static constexpr float table alignas(ALIGNMENT)[AlignmentOf::value] = {}; - return std::make_tuple(table, 0, AlignmentOf::value - 1); + static constexpr float table alignas(ALIGNMENT)[AlignmentOf] = {}; + return std::make_tuple(table, 0, AlignmentOf - 1); } }; diff --git a/src/zimg/resize/filter.cpp b/src/zimg/resize/filter.cpp index a575164..3609b0d 100644 --- a/src/zimg/resize/filter.cpp +++ b/src/zimg/resize/filter.cpp @@ -50,9 +50,9 @@ FilterContext matrix_to_filter(const RowMatrix &m) } zassert_d(width, "empty matrix"); - if (width > floor_n(UINT_MAX, AlignmentOf::value)) + if (width > floor_n(UINT_MAX, AlignmentOf)) error::throw_(); - if (width > floor_n(UINT_MAX, AlignmentOf::value)) + if (width > floor_n(UINT_MAX, AlignmentOf)) error::throw_(); FilterContext e{}; @@ -61,8 +61,8 @@ FilterContext matrix_to_filter(const RowMatrix &m) e.filter_width = static_cast(width); e.filter_rows = static_cast(m.rows()); e.input_width = static_cast(m.cols()); - e.stride = static_cast(ceil_n(width, AlignmentOf::value)); - e.stride_i16 = static_cast(ceil_n(width, AlignmentOf::value)); + e.stride = static_cast(ceil_n(width, AlignmentOf)); + e.stride_i16 = static_cast(ceil_n(width, AlignmentOf)); if (e.filter_rows > UINT_MAX / e.stride || e.filter_rows > UINT_MAX / e.stride_i16) error::throw_(); diff --git a/src/zimg/unresize/bilinear.cpp b/src/zimg/unresize/bilinear.cpp index 40fcf56..7122718 100644 --- a/src/zimg/unresize/bilinear.cpp +++ b/src/zimg/unresize/bilinear.cpp @@ -131,10 +131,10 @@ BilinearContext create_bilinear_context(unsigned in, unsigned out, double shift) } zassert_d(rowsize, "empty matrix"); - if (rowsize > floor_n(SIZE_MAX, AlignmentOf::value)) + if (rowsize > floor_n(SIZE_MAX, AlignmentOf)) error::throw_(); - size_t rowstride = ceil_n(rowsize, AlignmentOf::value); + size_t rowstride = ceil_n(rowsize, AlignmentOf); if (rows > SIZE_MAX / rowstride) error::throw_(); diff --git a/test/graph/audit_buffer.cpp b/test/graph/audit_buffer.cpp index 166a516..2ecf083 100644 --- a/test/graph/audit_buffer.cpp +++ b/test/graph/audit_buffer.cpp @@ -83,7 +83,7 @@ void AuditBuffer::add_guard_bytes() for (unsigned i = 0; i < m_buffer_height[p]; ++i) { T *line_base = m_buffer[p][i]; - T *line_guard_left = line_base - zimg::AlignmentOf::value; + T *line_guard_left = line_base - zimg::AlignmentOf; T *line_guard_right = line_guard_left + stride_T(p); std::fill(line_guard_left, line_base, m_guard_val); @@ -127,12 +127,12 @@ AuditBuffer::AuditBuffer(AuditBufferType buffer_type, unsigned width, unsigne unsigned mask_plane = p ? (mask == zimg::graph::BUFFER_MAX ? mask : mask >> subsample_h) : mask; unsigned buffer_height = (mask_plane == zimg::graph::BUFFER_MAX) ? height_plane : mask_plane + 1; - size_t guarded_linesize = (zimg::ceil_n(width_plane, zimg::AlignmentOf::value) + 2 * zimg::AlignmentOf::value) * sizeof(T); + size_t guarded_linesize = (zimg::ceil_n(width_plane, zimg::AlignmentOf) + 2 * zimg::AlignmentOf) * sizeof(T); size_t guarded_linecount = buffer_height + 2; m_vector[p].resize(guarded_linesize * guarded_linecount / sizeof(T)); m_buffer[p] = zimg::graph::ImageBuffer{ - m_vector[p].data() + guarded_linesize / sizeof(T) + zimg::AlignmentOf::value, + m_vector[p].data() + guarded_linesize / sizeof(T) + zimg::AlignmentOf, static_cast(guarded_linesize), mask_plane }; @@ -198,7 +198,7 @@ void AuditBuffer::assert_guard_bytes() const for (unsigned i = 0; i < m_buffer_height[p]; ++i) { const T *line_base = m_buffer[p].data() + static_cast(i) * stride_T(p); - const T *line_guard_left = line_base - zimg::AlignmentOf::value; + const T *line_guard_left = line_base - zimg::AlignmentOf; const T *line_guard_right = line_guard_left + stride_T(p); ASSERT_TRUE(contains_only(line_guard_left, line_base, m_guard_val)) << -- 2.32.0