From 2467b357cec75c77833c1e9f562c9855a271b58e Mon Sep 17 00:00:00 2001 From: sekrit-twc Date: Thu, 21 Jul 2022 22:37:51 -0700 Subject: [PATCH] graph: introduce base class for filters --- Makefile.am | 2 + _msvc/zimg/zimg.vcxproj | 2 + _msvc/zimg/zimg.vcxproj.filters | 18 ++++--- src/zimg/colorspace/colorspace.cpp | 22 ++------- src/zimg/depth/depth_convert.cpp | 36 ++------------ src/zimg/depth/dither.cpp | 27 ++-------- src/zimg/depth/x86/error_diffusion_avx2.cpp | 11 +---- src/zimg/depth/x86/error_diffusion_sse2.cpp | 11 +---- src/zimg/graph/filter_base.cpp | 14 ++++++ src/zimg/graph/filter_base.h | 38 ++++++++++++++ src/zimg/graph/simple_filters.cpp | 14 ++---- src/zimg/graph/simple_filters.h | 49 ++----------------- src/zimg/resize/arm/resize_impl_neon.cpp | 6 +-- src/zimg/resize/resize_impl.cpp | 2 - src/zimg/resize/resize_impl.h | 16 ++---- src/zimg/resize/x86/resize_impl_avx.cpp | 5 +- src/zimg/resize/x86/resize_impl_avx2.cpp | 30 +++--------- src/zimg/resize/x86/resize_impl_avx512.cpp | 16 ++---- .../resize/x86/resize_impl_avx512_common.h | 16 ++---- src/zimg/resize/x86/resize_impl_sse.cpp | 5 +- src/zimg/resize/x86/resize_impl_sse2.cpp | 5 +- src/zimg/unresize/unresize_impl.cpp | 2 - src/zimg/unresize/unresize_impl.h | 20 ++------ src/zimg/unresize/x86/unresize_impl_sse.cpp | 1 - 24 files changed, 125 insertions(+), 243 deletions(-) create mode 100644 src/zimg/graph/filter_base.cpp create mode 100644 src/zimg/graph/filter_base.h diff --git a/Makefile.am b/Makefile.am index e8f6acde..c85c6734 100644 --- a/Makefile.am +++ b/Makefile.am @@ -108,6 +108,8 @@ libzimg_internal_la_SOURCES = \ src/zimg/depth/dither.h \ src/zimg/depth/quantize.h \ src/zimg/depth/quantize.cpp \ + src/zimg/graph/filter_base.cpp \ + src/zimg/graph/filter_base.h \ src/zimg/graph/filtergraph.cpp \ src/zimg/graph/filtergraph.h \ src/zimg/graph/graphbuilder.cpp \ diff --git a/_msvc/zimg/zimg.vcxproj b/_msvc/zimg/zimg.vcxproj index cd186eae..5b6a5737 100644 --- a/_msvc/zimg/zimg.vcxproj +++ b/_msvc/zimg/zimg.vcxproj @@ -335,6 +335,7 @@ + @@ -461,6 +462,7 @@ StreamingSIMDExtensions2 StreamingSIMDExtensions2 + diff --git a/_msvc/zimg/zimg.vcxproj.filters b/_msvc/zimg/zimg.vcxproj.filters index 75d98ccd..2819bb59 100644 --- a/_msvc/zimg/zimg.vcxproj.filters +++ b/_msvc/zimg/zimg.vcxproj.filters @@ -279,15 +279,18 @@ Header Files\graph - - Header Files\graph - Header Files\graph Header Files\graph + + Header Files\graph + + + Header Files\graph + @@ -482,14 +485,17 @@ Source Files\graph - - Source Files\graph - Source Files\graph Source Files\graph + + Source Files\graph + + + Source Files\graph + \ No newline at end of file diff --git a/src/zimg/colorspace/colorspace.cpp b/src/zimg/colorspace/colorspace.cpp index 1edde7f8..b34bcc1c 100644 --- a/src/zimg/colorspace/colorspace.cpp +++ b/src/zimg/colorspace/colorspace.cpp @@ -4,7 +4,7 @@ #include "common/except.h" #include "common/pixel.h" #include "common/zassert.h" -#include "graphengine/filter.h" +#include "graph/filter_base.h" #include "colorspace.h" #include "graph.h" #include "operation.h" @@ -14,8 +14,7 @@ namespace colorspace { namespace { -class ColorspaceConversionImpl : public graphengine::Filter { - graphengine::FilterDescriptor m_desc; +class ColorspaceConversionImpl : public graph::PointFilter { std::array, 6> m_operations; void build_graph(const ColorspaceDefinition &in, const ColorspaceDefinition &out, const OperationParams ¶ms, CPUClass cpu) @@ -39,31 +38,20 @@ class ColorspaceConversionImpl : public graphengine::Filter { } } public: - ColorspaceConversionImpl(unsigned width, unsigned height, const ColorspaceDefinition &in, const ColorspaceDefinition &out, + ColorspaceConversionImpl(unsigned width, unsigned height, + const ColorspaceDefinition &in, const ColorspaceDefinition &out, const OperationParams ¶ms, CPUClass cpu) : - m_desc{} + PointFilter(width, height, PixelType::FLOAT) { zassert_d(width <= pixel_max_width(PixelType::FLOAT), "overflow"); - m_desc.format = { width, height, sizeof(float) }; m_desc.num_deps = 3; m_desc.num_planes = 3; - m_desc.step = 1; m_desc.flags.in_place = 1; build_graph(in, out, params, cpu); } - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - - pair_unsigned get_row_deps(unsigned i) const noexcept override { return{ i, i + 1 }; } - - pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override { return{ left, right }; } - - void init_context(void *) const noexcept override {} - void process(const graphengine::BufferDescriptor in[3], const graphengine::BufferDescriptor out[3], unsigned i, unsigned left, unsigned right, void *, void *) const noexcept override { diff --git a/src/zimg/depth/depth_convert.cpp b/src/zimg/depth/depth_convert.cpp index 9ebf3949..f434ba56 100644 --- a/src/zimg/depth/depth_convert.cpp +++ b/src/zimg/depth/depth_convert.cpp @@ -6,7 +6,7 @@ #include "common/except.h" #include "common/pixel.h" #include "common/zassert.h" -#include "graphengine/filter.h" +#include "graph/filter_base.h" #include "depth_convert.h" #include "quantize.h" @@ -88,8 +88,7 @@ depth_convert_func select_depth_convert_func(PixelType type_in, PixelType type_o } -class IntegerLeftShift : public graphengine::Filter { - graphengine::FilterDescriptor m_desc; +class IntegerLeftShift : public graph::PointFilter { left_shift_func m_func; unsigned m_shift; @@ -111,31 +110,19 @@ class IntegerLeftShift : public graphengine::Filter { } public: IntegerLeftShift(left_shift_func func, unsigned width, unsigned height, const PixelFormat &pixel_in, const PixelFormat &pixel_out) : - m_desc{}, + PointFilter(width, height, pixel_out.type), m_func{ func }, m_shift{} { check_preconditions(width, pixel_in, pixel_out); - m_desc.format = { width, height, pixel_size(pixel_out.type) }; m_desc.num_deps = 1; m_desc.num_planes = 1; - m_desc.step = 1; m_desc.flags.in_place = pixel_size(pixel_in.type) == pixel_size(pixel_out.type); m_shift = pixel_out.depth - pixel_in.depth; } - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - - pair_unsigned get_row_deps(unsigned i) const noexcept override { return{ i, i + 1 }; } - - pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override { return{ left, right }; } - - void init_context(void *) const noexcept override {} - void process(const graphengine::BufferDescriptor *in, const graphengine::BufferDescriptor *out, unsigned i, unsigned left, unsigned right, void *, void *) const noexcept override { @@ -144,8 +131,7 @@ class IntegerLeftShift : public graphengine::Filter { }; -class ConvertToFloat : public graphengine::Filter { - graphengine::FilterDescriptor m_desc; +class ConvertToFloat : public graph::PointFilter { depth_convert_func m_func; depth_f16c_func m_f16c; float m_scale; @@ -166,7 +152,7 @@ class ConvertToFloat : public graphengine::Filter { public: ConvertToFloat(depth_convert_func func, depth_f16c_func f16c, unsigned width, unsigned height, const PixelFormat &pixel_in, const PixelFormat &pixel_out) : - m_desc{}, + PointFilter(width, height, pixel_out.type), m_func{ func }, m_f16c{ f16c }, m_scale{}, @@ -174,26 +160,14 @@ class ConvertToFloat : public graphengine::Filter { { check_preconditions(width, pixel_in, pixel_out, !!f16c); - m_desc.format = { width, height, pixel_size(pixel_out.type) }; m_desc.num_deps = 1; m_desc.num_planes = 1; - m_desc.step = 1; m_desc.scratchpad_size = m_f16c ? (static_cast(width) * sizeof(float)).get() : 0; m_desc.flags.in_place = pixel_size(pixel_in.type) == pixel_size(pixel_out.type); std::tie(m_scale, m_offset) = get_scale_offset(pixel_in, pixel_out); } - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - - pair_unsigned get_row_deps(unsigned i) const noexcept override { return{ i, i + 1 }; } - - pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override { return{ left, right }; } - - void init_context(void *) const noexcept override {} - void process(const graphengine::BufferDescriptor *in, const graphengine::BufferDescriptor *out, unsigned i, unsigned left, unsigned right, void *, void *tmp) const noexcept override { diff --git a/src/zimg/depth/dither.cpp b/src/zimg/depth/dither.cpp index f1cac9c1..b6d1e77f 100644 --- a/src/zimg/depth/dither.cpp +++ b/src/zimg/depth/dither.cpp @@ -9,7 +9,7 @@ #include "common/except.h" #include "common/pixel.h" #include "common/zassert.h" -#include "graphengine/filter.h" +#include "graph/filter_base.h" #include "blue.h" #include "depth.h" #include "dither.h" @@ -227,8 +227,7 @@ class RandomDitherTable final : public OrderedDitherTable { }; -class OrderedDither : public graphengine::Filter { - graphengine::FilterDescriptor m_desc; +class OrderedDither : public graph::PointFilter { std::shared_ptr m_dither_table; dither_convert_func m_func; dither_f16c_func m_f16c; @@ -248,7 +247,7 @@ class OrderedDither : public graphengine::Filter { public: OrderedDither(std::shared_ptr table, dither_convert_func func, dither_f16c_func f16c, unsigned width, unsigned height, const PixelFormat &pixel_in, const PixelFormat &pixel_out, unsigned plane) : - m_desc{}, + PointFilter(width, height, pixel_out.type), m_dither_table{ std::move(table) }, m_func{ func }, m_f16c{ f16c }, @@ -259,26 +258,14 @@ class OrderedDither : public graphengine::Filter { { check_preconditions(width, pixel_in, pixel_out); - m_desc.format = { width, height, pixel_size(pixel_out.type) }; m_desc.num_deps = 1; m_desc.num_planes = 1; - m_desc.step = 1; m_desc.scratchpad_size = m_f16c ? (static_cast(width) * sizeof(float)).get() : 0; m_desc.flags.in_place = pixel_size(pixel_in.type) == pixel_size(pixel_out.type); std::tie(m_scale, m_offset) = get_scale_offset(pixel_in, pixel_out); } - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - - pair_unsigned get_row_deps(unsigned i) const noexcept override { return{ i, i + 1 }; } - - pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override { return{ left, right }; } - - void init_context(void *) const noexcept override {} - void process(const graphengine::BufferDescriptor *in, const graphengine::BufferDescriptor *out, unsigned i, unsigned left, unsigned right, void *, void *tmp) const noexcept override { @@ -297,11 +284,10 @@ class OrderedDither : public graphengine::Filter { }; -class ErrorDiffusion : public graphengine::Filter { +class ErrorDiffusion : public graph::FilterBase { public: typedef void (*ed_func)(const void *src, void *dst, void *error_top, void *error_cur, float scale, float offset, unsigned bits, unsigned width); private: - graphengine::FilterDescriptor m_desc; ed_func m_func; dither_f16c_func m_f16c; float m_scale; @@ -318,7 +304,6 @@ class ErrorDiffusion : public graphengine::Filter { } public: ErrorDiffusion(ed_func func, dither_f16c_func f16c, unsigned width, unsigned height, const PixelFormat &pixel_in, const PixelFormat &pixel_out) : - m_desc{}, m_func{ func }, m_f16c{ f16c }, m_scale{}, @@ -342,10 +327,6 @@ class ErrorDiffusion : public graphengine::Filter { std::tie(m_scale, m_offset) = get_scale_offset(pixel_in, pixel_out); } - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - pair_unsigned get_row_deps(unsigned i) const noexcept override { return{ i, i + 1 }; } pair_unsigned get_col_deps(unsigned, unsigned) const noexcept override { return{ 0, m_desc.format.width }; } diff --git a/src/zimg/depth/x86/error_diffusion_avx2.cpp b/src/zimg/depth/x86/error_diffusion_avx2.cpp index 19dc52f0..2163075d 100644 --- a/src/zimg/depth/x86/error_diffusion_avx2.cpp +++ b/src/zimg/depth/x86/error_diffusion_avx2.cpp @@ -13,7 +13,7 @@ #include "common/pixel.h" #include "common/zassert.h" #include "depth/quantize.h" -#include "graphengine/filter.h" +#include "graph/filter_base.h" #include "dither_x86.h" #include "common/x86/avx_util.h" @@ -447,9 +447,7 @@ auto select_error_diffusion_avx2_func(PixelType pixel_in, PixelType pixel_out) } -class ErrorDiffusionAVX2 final : public graphengine::Filter { - graphengine::FilterDescriptor m_desc; - +class ErrorDiffusionAVX2 : public graph::FilterBase { decltype(select_error_diffusion_scalar_func({}, {})) m_scalar_func; decltype(select_error_diffusion_avx2_func({}, {})) m_avx2_func; @@ -480,7 +478,6 @@ class ErrorDiffusionAVX2 final : public graphengine::Filter { } public: ErrorDiffusionAVX2(unsigned width, unsigned height, const PixelFormat &pixel_in, const PixelFormat &pixel_out) try : - m_desc{}, m_scalar_func{ select_error_diffusion_scalar_func(pixel_in.type, pixel_out.type) }, m_avx2_func{ select_error_diffusion_avx2_func(pixel_in.type, pixel_out.type) }, m_scale{}, @@ -508,10 +505,6 @@ class ErrorDiffusionAVX2 final : public graphengine::Filter { error::throw_(); } - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - pair_unsigned get_row_deps(unsigned i) const noexcept override { unsigned last = std::min(i, UINT_MAX - 8) + 8; diff --git a/src/zimg/depth/x86/error_diffusion_sse2.cpp b/src/zimg/depth/x86/error_diffusion_sse2.cpp index 29aec96b..9fc1a718 100644 --- a/src/zimg/depth/x86/error_diffusion_sse2.cpp +++ b/src/zimg/depth/x86/error_diffusion_sse2.cpp @@ -13,7 +13,7 @@ #include "common/pixel.h" #include "common/zassert.h" #include "depth/quantize.h" -#include "graphengine/filter.h" +#include "graph/filter_base.h" #include "dither_x86.h" #include "common/x86/sse2_util.h" @@ -350,9 +350,7 @@ auto select_error_diffusion_sse2_func(PixelType pixel_in, PixelType pixel_out) } -class ErrorDiffusionSSE2 : public graphengine::Filter { - graphengine::FilterDescriptor m_desc; - +class ErrorDiffusionSSE2 : public graph::FilterBase { decltype(select_error_diffusion_scalar_func({}, {})) m_scalar_func; decltype(select_error_diffusion_sse2_func({}, {})) m_sse2_func; dither_f16c_func m_f16c; @@ -388,7 +386,6 @@ class ErrorDiffusionSSE2 : public graphengine::Filter { } public: ErrorDiffusionSSE2(unsigned width, unsigned height, const PixelFormat &pixel_in, const PixelFormat &pixel_out, CPUClass cpu) try : - m_desc{}, m_scalar_func{ select_error_diffusion_scalar_func(pixel_in.type, pixel_out.type) }, m_sse2_func{ select_error_diffusion_sse2_func(pixel_in.type, pixel_out.type) }, m_f16c{}, @@ -422,10 +419,6 @@ class ErrorDiffusionSSE2 : public graphengine::Filter { error::throw_(); } - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - pair_unsigned get_row_deps(unsigned i) const noexcept override { unsigned last = std::min(i, UINT_MAX - 4) + 4; diff --git a/src/zimg/graph/filter_base.cpp b/src/zimg/graph/filter_base.cpp new file mode 100644 index 00000000..9cb035af --- /dev/null +++ b/src/zimg/graph/filter_base.cpp @@ -0,0 +1,14 @@ +#include "common/pixel.h" +#include "filter_base.h" + +namespace zimg { +namespace graph { + +PointFilter::PointFilter(unsigned width, unsigned height, PixelType type) +{ + m_desc.format = { width, height, pixel_size(type) }; + m_desc.step = 1; +} + +} // namespace graph +} // namespace zimg diff --git a/src/zimg/graph/filter_base.h b/src/zimg/graph/filter_base.h new file mode 100644 index 00000000..1f15e696 --- /dev/null +++ b/src/zimg/graph/filter_base.h @@ -0,0 +1,38 @@ +#pragma once + +#ifndef ZIMG_GRAPH_FILTER_BASE_H_ +#define ZIMG_GRAPH_FILTER_BASE_H_ + +#include "graphengine/filter.h" + +namespace zimg { + +enum class PixelType; + +namespace graph { + +class FilterBase : public graphengine::Filter { +protected: + graphengine::FilterDescriptor m_desc{}; +public: + int version() const noexcept override final { return VERSION; } + + const graphengine::FilterDescriptor &descriptor() const noexcept override final { return m_desc; } + + void init_context(void *) const noexcept override {} +}; + +class PointFilter : public FilterBase { +protected: + // Initializes |format| and |step| fields of descriptor. + PointFilter(unsigned width, unsigned height, PixelType type); + + pair_unsigned get_row_deps(unsigned i) const noexcept override final { return{ i, i + 1 }; } + + pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override final { return{ left, right }; } +}; + +} // namespace graph +} // namespace zimg + +#endif // ZIMG_GRAPH_FILTER_BASE_H_ diff --git a/src/zimg/graph/simple_filters.cpp b/src/zimg/graph/simple_filters.cpp index ff529e37..d679a991 100644 --- a/src/zimg/graph/simple_filters.cpp +++ b/src/zimg/graph/simple_filters.cpp @@ -7,7 +7,6 @@ namespace zimg { namespace graph { CopyRectFilter::CopyRectFilter(unsigned left, unsigned top, unsigned width, unsigned height, PixelType type) : - m_desc{}, m_left{ left }, m_top{ top } { @@ -25,14 +24,13 @@ void CopyRectFilter::process(const graphengine::BufferDescriptor *in, const grap std::copy_n(src_p, static_cast(right - left) * m_desc.format.bytes_per_sample, dst_p); } + ValueInitializeFilter::ValueInitializeFilter(unsigned width, unsigned height, PixelType type, value_type val) : - m_desc{}, + PointFilter(width, height, type), m_value(val) { - m_desc.format = { width, height, pixel_size(type) }; m_desc.num_deps = 0; m_desc.num_planes = 1; - m_desc.step = 1; } void ValueInitializeFilter::fill_b(void *ptr, size_t n) const @@ -69,12 +67,10 @@ void ValueInitializeFilter::process(const graphengine::BufferDescriptor *in, con } -PremultiplyFilter::PremultiplyFilter(unsigned width, unsigned height) : m_desc{} +PremultiplyFilter::PremultiplyFilter(unsigned width, unsigned height) : PointFilter(width, height, PixelType::FLOAT) { - m_desc.format = { width, height, pixel_size(PixelType::FLOAT) }; m_desc.num_deps = 2; m_desc.num_planes = 1; - m_desc.step = 1; m_desc.flags.in_place = 1; } @@ -93,12 +89,10 @@ void PremultiplyFilter::process(const graphengine::BufferDescriptor in[2], const } -UnpremultiplyFilter::UnpremultiplyFilter(unsigned width, unsigned height) : m_desc{} +UnpremultiplyFilter::UnpremultiplyFilter(unsigned width, unsigned height) : PointFilter(width, height, PixelType::FLOAT) { - m_desc.format = { width, height, pixel_size(PixelType::FLOAT) }; m_desc.num_deps = 2; m_desc.num_planes = 1; - m_desc.step = 1; m_desc.flags.in_place = 1; } diff --git a/src/zimg/graph/simple_filters.h b/src/zimg/graph/simple_filters.h index 698df4da..0fade689 100644 --- a/src/zimg/graph/simple_filters.h +++ b/src/zimg/graph/simple_filters.h @@ -5,6 +5,7 @@ #include #include "graphengine/filter.h" +#include "filter_base.h" namespace zimg { @@ -12,29 +13,22 @@ enum class PixelType; namespace graph { -class CopyRectFilter : public graphengine::Filter { - graphengine::FilterDescriptor m_desc; +class CopyRectFilter : public FilterBase { unsigned m_left; unsigned m_top; public: CopyRectFilter(unsigned left, unsigned top, unsigned width, unsigned height, PixelType type); - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - pair_unsigned get_row_deps(unsigned i) const noexcept override { return{ m_top + i, m_top + i + 1 }; } pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override { return{ m_left + left, m_left + right }; } - void init_context(void *) const noexcept override {} - void process(const graphengine::BufferDescriptor *in, const graphengine::BufferDescriptor *out, unsigned i, unsigned left, unsigned right, void *, void *) const noexcept override; }; // Initializes a plane to a constant value. -class ValueInitializeFilter : public graphengine::Filter { +class ValueInitializeFilter : public PointFilter { public: union value_type { uint8_t b; @@ -42,7 +36,6 @@ class ValueInitializeFilter : public graphengine::Filter { float f; }; private: - graphengine::FilterDescriptor m_desc; value_type m_value; void fill_b(void *ptr, size_t n) const; @@ -51,56 +44,24 @@ class ValueInitializeFilter : public graphengine::Filter { public: ValueInitializeFilter(unsigned width, unsigned height, PixelType type, value_type val); - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - - pair_unsigned get_row_deps(unsigned i) const noexcept override { return{ i, i + 1 }; } - - pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override { return{ left, right }; } - - void init_context(void *) const noexcept override {} - void process(const graphengine::BufferDescriptor *in, const graphengine::BufferDescriptor *out, unsigned i, unsigned left, unsigned right, void *, void *) const noexcept override; }; // Premultiplies an image. -class PremultiplyFilter : public graphengine::Filter { - graphengine::FilterDescriptor m_desc; +class PremultiplyFilter : public PointFilter { public: PremultiplyFilter(unsigned width, unsigned height); - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - - pair_unsigned get_row_deps(unsigned i) const noexcept override { return{ i, i + 1 }; } - - pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override { return{ left, right }; } - - void init_context(void *) const noexcept override {} - void process(const graphengine::BufferDescriptor in[2], const graphengine::BufferDescriptor *out, unsigned i, unsigned left, unsigned right, void *, void *) const noexcept override; }; // Unpremultiplies an image. -class UnpremultiplyFilter : public graphengine::Filter { - graphengine::FilterDescriptor m_desc; +class UnpremultiplyFilter : public PointFilter { public: UnpremultiplyFilter(unsigned width, unsigned height); - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - - pair_unsigned get_row_deps(unsigned i) const noexcept override { return{ i, i + 1 }; } - - pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override { return{ left, right }; } - - void init_context(void *) const noexcept override {} - void process(const graphengine::BufferDescriptor in[2], const graphengine::BufferDescriptor *out, unsigned i, unsigned left, unsigned right, void *, void *) const noexcept override; }; diff --git a/src/zimg/resize/arm/resize_impl_neon.cpp b/src/zimg/resize/arm/resize_impl_neon.cpp index b015443c..5fbca672 100644 --- a/src/zimg/resize/arm/resize_impl_neon.cpp +++ b/src/zimg/resize/arm/resize_impl_neon.cpp @@ -803,7 +803,7 @@ class ResizeImplH_F32_Neon final : public ResizeImplH { }; -class ResizeImplV_U16_Neon final : public ResizeImplV { +class ResizeImplV_U16_Neon : public ResizeImplV { uint16_t m_pixel_max; public: ResizeImplV_U16_Neon(const FilterContext &filter, unsigned width, unsigned depth) try : @@ -859,14 +859,14 @@ class ResizeImplV_U16_Neon final : public ResizeImplV { }; -class ResizeImplV_F32_Neon final : public ResizeImplV { +class ResizeImplV_F32_Neon : public ResizeImplV { public: ResizeImplV_F32_Neon(const FilterContext &filter, unsigned width) : ResizeImplV(filter, width, PixelType::FLOAT) {} void process(const graphengine::BufferDescriptor *in, const graphengine::BufferDescriptor *out, - unsigned i, unsigned left, unsigned right, void *, void *) const noexcept override + unsigned i, unsigned left, unsigned right, void *, void *) const noexcept override { const float *filter_data = m_filter.data.data() + i * m_filter.stride; unsigned filter_width = m_filter.filter_width; diff --git a/src/zimg/resize/resize_impl.cpp b/src/zimg/resize/resize_impl.cpp index d31e1333..516a7562 100644 --- a/src/zimg/resize/resize_impl.cpp +++ b/src/zimg/resize/resize_impl.cpp @@ -165,7 +165,6 @@ class ResizeImplV_C : public ResizeImplV { ResizeImplH::ResizeImplH(const FilterContext &filter, unsigned height, PixelType type) : - m_desc{}, m_filter(filter) { zassert_d(m_filter.input_width <= pixel_max_width(type), "overflow"); @@ -198,7 +197,6 @@ auto ResizeImplH::get_col_deps(unsigned left, unsigned right) const noexcept -> ResizeImplV::ResizeImplV(const FilterContext &filter, unsigned width, PixelType type) : - m_desc{}, m_filter(filter), m_unsorted{} { diff --git a/src/zimg/resize/resize_impl.h b/src/zimg/resize/resize_impl.h index 6b8ae090..6992cb63 100644 --- a/src/zimg/resize/resize_impl.h +++ b/src/zimg/resize/resize_impl.h @@ -5,7 +5,7 @@ #include #include -#include "graphengine/filter.h" +#include "graph/filter_base.h" #include "filter.h" namespace zimg { @@ -15,17 +15,12 @@ enum class PixelType; namespace resize { -class ResizeImplH : public graphengine::Filter { +class ResizeImplH : public graph::FilterBase { protected: - graphengine::FilterDescriptor m_desc; FilterContext m_filter; ResizeImplH(const FilterContext &filter, unsigned height, PixelType type); public: - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - pair_unsigned get_row_deps(unsigned i) const noexcept override; pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override; @@ -33,18 +28,13 @@ class ResizeImplH : public graphengine::Filter { void init_context(void *) const noexcept override {} }; -class ResizeImplV : public graphengine::Filter { +class ResizeImplV : public graph::FilterBase { protected: - graphengine::FilterDescriptor m_desc; FilterContext m_filter; bool m_unsorted; ResizeImplV(const FilterContext &filter, unsigned width, PixelType type); public: - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - pair_unsigned get_row_deps(unsigned i) const noexcept override; pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override; diff --git a/src/zimg/resize/x86/resize_impl_avx.cpp b/src/zimg/resize/x86/resize_impl_avx.cpp index eaf47426..b2aeb47b 100644 --- a/src/zimg/resize/x86/resize_impl_avx.cpp +++ b/src/zimg/resize/x86/resize_impl_avx.cpp @@ -9,7 +9,6 @@ #include "common/except.h" #include "common/make_array.h" #include "common/pixel.h" -#include "graphengine/filter.h" #include "resize/filter.h" #include "resize/resize_impl.h" #include "resize_impl_x86.h" @@ -334,7 +333,7 @@ constexpr auto resize_line_v_f32_avx_jt_cont = make_array( resize_line_v_f32_avx<8, true>); -class ResizeImplH_F32_AVX final : public ResizeImplH { +class ResizeImplH_F32_AVX : public ResizeImplH { decltype(resize_line8_h_f32_avx_jt_small)::value_type m_func; public: ResizeImplH_F32_AVX(const FilterContext &filter, unsigned height) try : @@ -388,7 +387,7 @@ class ResizeImplH_F32_AVX final : public ResizeImplH { }; -class ResizeImplV_F32_AVX final : public ResizeImplV { +class ResizeImplV_F32_AVX : public ResizeImplV { public: ResizeImplV_F32_AVX(const FilterContext &filter, unsigned width) : ResizeImplV(filter, width, zimg::PixelType::FLOAT) diff --git a/src/zimg/resize/x86/resize_impl_avx2.cpp b/src/zimg/resize/x86/resize_impl_avx2.cpp index 546dc59a..eb8f4051 100644 --- a/src/zimg/resize/x86/resize_impl_avx2.cpp +++ b/src/zimg/resize/x86/resize_impl_avx2.cpp @@ -13,7 +13,7 @@ #include "common/make_array.h" #include "common/pixel.h" #include "common/x86/cpuinfo_x86.h" -#include "graphengine/filter.h" +#include "graph/filter_base.h" #include "resize/filter.h" #include "resize/resize_impl.h" #include "resize_impl_x86.h" @@ -1153,7 +1153,7 @@ constexpr auto resize_line_v_fp_avx2_jt_cont = make_array( resize_line_v_fp_avx2); -class ResizeImplH_U16_AVX2 final : public ResizeImplH { +class ResizeImplH_U16_AVX2 : public ResizeImplH { decltype(resize_line8_h_u16_avx2_jt_small)::value_type m_func; uint16_t m_pixel_max; public: @@ -1200,7 +1200,7 @@ class ResizeImplH_U16_AVX2 final : public ResizeImplH { template -class ResizeImplH_FP_AVX2 final : public ResizeImplH { +class ResizeImplH_FP_AVX2 : public ResizeImplH { typedef typename Traits::pixel_type pixel_type; typedef typename decltype(resize_line8_h_fp_avx2_jt_small)::value_type func_type; @@ -1257,7 +1257,7 @@ class ResizeImplH_FP_AVX2 final : public ResizeImplH { }; -class ResizeImplH_Permute_U16_AVX2 final : public graphengine::Filter { +class ResizeImplH_Permute_U16_AVX2 : public graph::FilterBase { typedef decltype(resize_line_h_perm_u16_avx2_jt)::value_type func_type; struct PermuteContext { @@ -1269,13 +1269,11 @@ class ResizeImplH_Permute_U16_AVX2 final : public graphengine::Filter { unsigned input_width; }; - graphengine::FilterDescriptor m_desc; PermuteContext m_context; uint16_t m_pixel_max; func_type m_func; ResizeImplH_Permute_U16_AVX2(PermuteContext context, unsigned height, unsigned depth) : - m_desc{}, m_context(std::move(context)), m_pixel_max{ static_cast((1UL << depth) - 1) }, m_func{ resize_line_h_perm_u16_avx2_jt[(m_context.filter_width - 1) / 2] } @@ -1341,10 +1339,6 @@ class ResizeImplH_Permute_U16_AVX2 final : public graphengine::Filter { return ret; } - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - pair_unsigned get_row_deps(unsigned i) const noexcept override { return{ i, i + 1 }; } pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override @@ -1358,8 +1352,6 @@ class ResizeImplH_Permute_U16_AVX2 final : public graphengine::Filter { return{ m_context.left[left / 8], right_base + std::min(input_width - right_base, iter_width) }; } - void init_context(void *) const noexcept override {} - void process(const graphengine::BufferDescriptor *in, const graphengine::BufferDescriptor *out, unsigned i, unsigned left, unsigned right, void *, void *) const noexcept override { @@ -1369,7 +1361,7 @@ class ResizeImplH_Permute_U16_AVX2 final : public graphengine::Filter { template -class ResizeImplH_Permute_FP_AVX2 final : public graphengine::Filter { +class ResizeImplH_Permute_FP_AVX2 : public graph::FilterBase { typedef typename Traits::pixel_type pixel_type; typedef typename decltype(resize_line_h_perm_fp_avx2_jt)::value_type func_type; @@ -1382,12 +1374,10 @@ class ResizeImplH_Permute_FP_AVX2 final : public graphengine::Filter { unsigned input_width; }; - graphengine::FilterDescriptor m_desc; PermuteContext m_context; func_type m_func; ResizeImplH_Permute_FP_AVX2(PermuteContext context, unsigned height) : - m_desc{}, m_context(std::move(context)), m_func{ resize_line_h_perm_fp_avx2_jt[m_context.filter_width - 1] } { @@ -1442,10 +1432,6 @@ class ResizeImplH_Permute_FP_AVX2 final : public graphengine::Filter { return ret; } - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - pair_unsigned get_row_deps(unsigned i) const noexcept override { return{ i, i + 1 }; } pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override @@ -1459,8 +1445,6 @@ class ResizeImplH_Permute_FP_AVX2 final : public graphengine::Filter { return{ m_context.left[left / 8], right_base + std::min(input_width - right_base, iter_width) }; } - void init_context(void *) const noexcept override {} - void process(const graphengine::BufferDescriptor *in, const graphengine::BufferDescriptor *out, unsigned i, unsigned left, unsigned right, void *, void *) const noexcept override { @@ -1469,7 +1453,7 @@ class ResizeImplH_Permute_FP_AVX2 final : public graphengine::Filter { }; -class ResizeImplV_U16_AVX2 final : public ResizeImplV { +class ResizeImplV_U16_AVX2 : public ResizeImplV { uint16_t m_pixel_max; public: ResizeImplV_U16_AVX2(const FilterContext &filter, unsigned width, unsigned depth) try : @@ -1524,7 +1508,7 @@ class ResizeImplV_U16_AVX2 final : public ResizeImplV { template -class ResizeImplV_FP_AVX2 final : public ResizeImplV { +class ResizeImplV_FP_AVX2 : public ResizeImplV { typedef typename Traits::pixel_type pixel_type; public: ResizeImplV_FP_AVX2(const FilterContext &filter, unsigned width) : diff --git a/src/zimg/resize/x86/resize_impl_avx512.cpp b/src/zimg/resize/x86/resize_impl_avx512.cpp index 709ba2b9..800b62da 100644 --- a/src/zimg/resize/x86/resize_impl_avx512.cpp +++ b/src/zimg/resize/x86/resize_impl_avx512.cpp @@ -12,7 +12,7 @@ #include "common/except.h" #include "common/make_array.h" #include "common/pixel.h" -#include "graphengine/filter.h" +#include "graph/filter_base.h" #include "resize/resize_impl.h" #include "resize_impl_x86.h" @@ -657,7 +657,7 @@ constexpr auto resize_line_v_fp_avx512_jt_cont = make_array( template -class ResizeImplH_FP_AVX512 final : public ResizeImplH { +class ResizeImplH_FP_AVX512 : public ResizeImplH { typedef typename Traits::pixel_type pixel_type; typedef typename decltype(resize_line16_h_fp_avx512_jt_small)::value_type func_type; @@ -703,7 +703,7 @@ class ResizeImplH_FP_AVX512 final : public ResizeImplH { template -class ResizeImplH_Permute_FP_AVX512 final : public graphengine::Filter { +class ResizeImplH_Permute_FP_AVX512 : public graph::FilterBase { typedef typename Traits::pixel_type pixel_type; typedef typename decltype(resize_line_h_perm_fp_avx512_jt)::value_type func_type; @@ -716,12 +716,10 @@ class ResizeImplH_Permute_FP_AVX512 final : public graphengine::Filter { unsigned input_width; }; - graphengine::FilterDescriptor m_desc; PermuteContext m_context; func_type m_func; ResizeImplH_Permute_FP_AVX512(PermuteContext context, unsigned height) : - m_desc{}, m_context(std::move(context)), m_func{ resize_line_h_perm_fp_avx512_jt[m_context.filter_width - 1] } { @@ -776,10 +774,6 @@ class ResizeImplH_Permute_FP_AVX512 final : public graphengine::Filter { return ret; } - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - pair_unsigned get_row_deps(unsigned i) const noexcept override { return{ i, i + 1 }; } pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override @@ -793,8 +787,6 @@ class ResizeImplH_Permute_FP_AVX512 final : public graphengine::Filter { return{ m_context.left[left / 16], right_base + std::min(input_width - right_base, iter_width) }; } - void init_context(void *) const noexcept override {} - void process(const graphengine::BufferDescriptor *in, const graphengine::BufferDescriptor *out, unsigned i, unsigned left, unsigned right, void *, void *) const noexcept override { @@ -804,7 +796,7 @@ class ResizeImplH_Permute_FP_AVX512 final : public graphengine::Filter { template -class ResizeImplV_FP_AVX512 final : public ResizeImplV { +class ResizeImplV_FP_AVX512 : public ResizeImplV { typedef typename Traits::pixel_type pixel_type; public: ResizeImplV_FP_AVX512(const FilterContext &filter, unsigned width) : diff --git a/src/zimg/resize/x86/resize_impl_avx512_common.h b/src/zimg/resize/x86/resize_impl_avx512_common.h index c2b47681..baad60d4 100644 --- a/src/zimg/resize/x86/resize_impl_avx512_common.h +++ b/src/zimg/resize/x86/resize_impl_avx512_common.h @@ -11,7 +11,7 @@ #include "common/checked_int.h" #include "common/make_array.h" #include "common/except.h" -#include "graphengine/filter.h" +#include "graph/filter_base.h" #include "resize/resize_impl.h" #include "common/x86/sse2_util.h" @@ -698,7 +698,7 @@ inline FORCE_INLINE void calculate_line_address(void *dst, const void *src, ptrd } -class ResizeImplH_U16_AVX512 final : public ResizeImplH { +class ResizeImplH_U16_AVX512 : public ResizeImplH { decltype(resize_line16_h_u16_avx512_jt_small)::value_type m_func; uint16_t m_pixel_max; public: @@ -746,7 +746,7 @@ class ResizeImplH_U16_AVX512 final : public ResizeImplH { }; -class ResizeImplH_Permute_U16_AVX512 final : public graphengine::Filter { +class ResizeImplH_Permute_U16_AVX512 : public graph::FilterBase { typedef decltype(resize_line_h_perm_u16_avx512_jt)::value_type func_type; struct PermuteContext { @@ -758,13 +758,11 @@ class ResizeImplH_Permute_U16_AVX512 final : public graphengine::Filter { unsigned input_width; }; - graphengine::FilterDescriptor m_desc; PermuteContext m_context; uint16_t m_pixel_max; func_type m_func; ResizeImplH_Permute_U16_AVX512(PermuteContext context, unsigned height, unsigned depth) : - m_desc{}, m_context(std::move(context)), m_pixel_max{ static_cast((1UL << depth) - 1) }, m_func{ resize_line_h_perm_u16_avx512_jt[(m_context.filter_width - 1) / 2] } @@ -824,10 +822,6 @@ class ResizeImplH_Permute_U16_AVX512 final : public graphengine::Filter { return ret; } - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - pair_unsigned get_row_deps(unsigned i) const noexcept override { return{ i, i + 1 }; } pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override @@ -841,8 +835,6 @@ class ResizeImplH_Permute_U16_AVX512 final : public graphengine::Filter { return{ m_context.left[left / 16], right_base + std::min(input_width - right_base, iter_width) }; } - void init_context(void *) const noexcept override {} - void process(const graphengine::BufferDescriptor *in, const graphengine::BufferDescriptor *out, unsigned i, unsigned left, unsigned right, void *, void *) const noexcept override { @@ -851,7 +843,7 @@ class ResizeImplH_Permute_U16_AVX512 final : public graphengine::Filter { }; -class ResizeImplV_U16_AVX512 final : public ResizeImplV { +class ResizeImplV_U16_AVX512 : public ResizeImplV { uint16_t m_pixel_max; public: ResizeImplV_U16_AVX512(const FilterContext &filter, unsigned width, unsigned depth) try : diff --git a/src/zimg/resize/x86/resize_impl_sse.cpp b/src/zimg/resize/x86/resize_impl_sse.cpp index 1f216ba8..86f58ba0 100644 --- a/src/zimg/resize/x86/resize_impl_sse.cpp +++ b/src/zimg/resize/x86/resize_impl_sse.cpp @@ -9,7 +9,6 @@ #include "common/except.h" #include "common/make_array.h" #include "common/pixel.h" -#include "graphengine/filter.h" #include "resize/filter.h" #include "resize/resize_impl.h" #include "resize_impl_x86.h" @@ -267,7 +266,7 @@ constexpr auto resize_line_v_f32_sse_jt_cont = make_array( resize_line_v_f32_sse<4, true>); -class ResizeImplH_F32_SSE final : public ResizeImplH { +class ResizeImplH_F32_SSE : public ResizeImplH { decltype(resize_line4_h_f32_sse_jt_small)::value_type m_func; public: ResizeImplH_F32_SSE(const FilterContext &filter, unsigned height) try : @@ -313,7 +312,7 @@ class ResizeImplH_F32_SSE final : public ResizeImplH { }; -class ResizeImplV_F32_SSE final : public ResizeImplV { +class ResizeImplV_F32_SSE : public ResizeImplV { public: ResizeImplV_F32_SSE(const FilterContext &filter, unsigned width) : ResizeImplV(filter, width, PixelType::FLOAT) diff --git a/src/zimg/resize/x86/resize_impl_sse2.cpp b/src/zimg/resize/x86/resize_impl_sse2.cpp index 392e7029..03fdeb83 100644 --- a/src/zimg/resize/x86/resize_impl_sse2.cpp +++ b/src/zimg/resize/x86/resize_impl_sse2.cpp @@ -10,7 +10,6 @@ #include "common/except.h" #include "common/make_array.h" #include "common/pixel.h" -#include "graphengine/filter.h" #include "resize/resize_impl.h" #include "resize_impl_x86.h" @@ -467,7 +466,7 @@ constexpr auto resize_line_v_u16_sse2_jt_final = make_array( resize_line_v_u16_sse2<8, V_ACCUM_FINAL>); -class ResizeImplH_U16_SSE2 final : public ResizeImplH { +class ResizeImplH_U16_SSE2 : public ResizeImplH { decltype(resize_line8_h_u16_sse2_jt_small)::value_type m_func; uint16_t m_pixel_max; public: @@ -513,7 +512,7 @@ class ResizeImplH_U16_SSE2 final : public ResizeImplH { }; -class ResizeImplV_U16_SSE2 final : public ResizeImplV { +class ResizeImplV_U16_SSE2 : public ResizeImplV { uint16_t m_pixel_max; public: ResizeImplV_U16_SSE2(const FilterContext &filter, unsigned width, unsigned depth) try : diff --git a/src/zimg/unresize/unresize_impl.cpp b/src/zimg/unresize/unresize_impl.cpp index 6d591c21..cc582ebc 100644 --- a/src/zimg/unresize/unresize_impl.cpp +++ b/src/zimg/unresize/unresize_impl.cpp @@ -138,7 +138,6 @@ class UnresizeImplV_C : public UnresizeImplV { UnresizeImplH::UnresizeImplH(const BilinearContext &context, unsigned width, unsigned height, PixelType type) : - m_desc{}, m_context(context) { zassert_d(m_context.input_width <= pixel_max_width(type), "overflow"); @@ -165,7 +164,6 @@ auto UnresizeImplH::get_col_deps(unsigned, unsigned) const noexcept -> pair_unsi UnresizeImplV::UnresizeImplV(const BilinearContext &context, unsigned width, unsigned height, PixelType type) : - m_desc{}, m_context(context) { zassert_d(m_context.input_width <= pixel_max_width(type), "overflow"); diff --git a/src/zimg/unresize/unresize_impl.h b/src/zimg/unresize/unresize_impl.h index b4f9f545..bb174283 100644 --- a/src/zimg/unresize/unresize_impl.h +++ b/src/zimg/unresize/unresize_impl.h @@ -4,7 +4,7 @@ #define ZIMG_UNRESIZE_UNRESIZE_IMPL_H_ #include -#include "graphengine/filter.h" +#include "graph/filter_base.h" #include "bilinear.h" namespace zimg { @@ -14,40 +14,26 @@ enum class PixelType; namespace unresize { -class UnresizeImplH : public graphengine::Filter { +class UnresizeImplH : public graph::FilterBase { protected: - graphengine::FilterDescriptor m_desc; BilinearContext m_context; UnresizeImplH(const BilinearContext &context, unsigned width, unsigned height, PixelType type); public: - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - pair_unsigned get_row_deps(unsigned i) const noexcept override; pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override; - - void init_context(void *) const noexcept override {} }; -class UnresizeImplV : public graphengine::Filter { +class UnresizeImplV : public graph::FilterBase { protected: - graphengine::FilterDescriptor m_desc; BilinearContext m_context; UnresizeImplV(const BilinearContext &context, unsigned width, unsigned height, PixelType type); public: - int version() const noexcept override { return VERSION; } - - const graphengine::FilterDescriptor &descriptor() const noexcept override { return m_desc; } - pair_unsigned get_row_deps(unsigned i) const noexcept override; pair_unsigned get_col_deps(unsigned left, unsigned right) const noexcept override; - - void init_context(void *) const noexcept override {} }; struct UnresizeImplBuilder { diff --git a/src/zimg/unresize/x86/unresize_impl_sse.cpp b/src/zimg/unresize/x86/unresize_impl_sse.cpp index b0b116bd..ecb5bfe1 100644 --- a/src/zimg/unresize/x86/unresize_impl_sse.cpp +++ b/src/zimg/unresize/x86/unresize_impl_sse.cpp @@ -8,7 +8,6 @@ #include "common/except.h" #include "common/pixel.h" #include "common/zassert.h" -#include "graphengine/filter.h" #include "unresize/bilinear.h" #include "unresize/unresize_impl.h" #include "unresize_impl_x86.h"