Skip to content

Commit

Permalink
Added gaussian blur, some refactor, fast gaussian
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Apr 20, 2024
1 parent 92ddbd3 commit 184cc92
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/TypeSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,64 +21,64 @@
#include <algorithm>

#if defined(__GNUC__) || defined(__clang__)
#define TYPE_INLINE __attribute__((flatten)) inline
#define TYPE_INLINE static __attribute__((flatten)) inline
#else
#define SPARKYUV_INLINE inline
#define SPARKYUV_INLINE static inline
#endif

namespace {
template<typename T, typename std::enable_if<std::is_same<T, hwy::float16_t>::value, int>::type = 0>
#define ENABLE_TYPE_IS_F16(T) typename std::enable_if<std::is_same<T, hwy::float16_t>::value, int>::type = 0
#define ENABLE_TYPE_IS_NOT_F16(T) typename std::enable_if<!std::is_same<T, hwy::float16_t>::value, int>::type = 0

template<typename T, ENABLE_TYPE_IS_F16(T)>
TYPE_INLINE float LoadFloat(const T *src) {
auto uSource = reinterpret_cast<const uint16_t *>(src);
return hwy::F32FromF16(hwy::float16_t::FromBits(uSource[0]));
}

template<typename T, typename std::enable_if<!std::is_same<T, hwy::float16_t>::value, int>::type = 0>
template<typename T, ENABLE_TYPE_IS_NOT_F16(T)>
TYPE_INLINE float LoadFloat(const T *src) {
return static_cast<float>(src[0]);
}

template<typename V, typename T, typename std::enable_if<std::is_same<T, hwy::float16_t>::value, int>::type = 0>
template<typename V, typename T, ENABLE_TYPE_IS_F16(T)>
TYPE_INLINE V LoadPixel(const T *src) {
auto uSource = reinterpret_cast<const uint16_t *>(src);
return static_cast<V>(hwy::F32FromF16(hwy::float16_t::FromBits(uSource[0])));
}

template<typename V, typename T, typename std::enable_if<!std::is_same<T, hwy::float16_t>::value, int>::type = 0>
template<typename V, typename T, ENABLE_TYPE_IS_NOT_F16(T)>
TYPE_INLINE V LoadPixel(const T *src) {
return static_cast<V>(src[0]);
}

template<typename V, typename T, typename std::enable_if<!std::is_same<V, hwy::float16_t>::value, int>::type = 0>
template<typename V, typename T, ENABLE_TYPE_IS_NOT_F16(V)>
TYPE_INLINE V TransformCast(T t) {
return static_cast<V>(t);
}

template<typename V, typename T, typename std::enable_if<std::is_same<V, hwy::float16_t>::value, int>::type = 0>
template<typename V, typename T, ENABLE_TYPE_IS_F16(V)>
TYPE_INLINE V TransformCast(T t) {
return hwy::F16FromF32(t);
}

template<typename T, typename V, typename std::enable_if<!std::is_same<V, hwy::float16_t>::value, int>::type = 0>
TYPE_INLINE void StoreRoundedFloat(V* v, T t) {
template<typename T, typename V, ENABLE_TYPE_IS_NOT_F16(V)>
TYPE_INLINE void StoreRoundedFloat(V *v, T t) {
v[0] = ::roundf(t);
}

template<typename T, typename V, typename std::enable_if<std::is_same<V, hwy::float16_t>::value, int>::type = 0>
TYPE_INLINE void StoreRoundedFloat(V* v, T t) {
template<typename T, typename V, ENABLE_TYPE_IS_F16(V)>
TYPE_INLINE void StoreRoundedFloat(V *v, T t) {
reinterpret_cast<uint16_t *>(v)[0] = hwy::F16FromF32(::roundf(t)).bits;
}

template<typename T, typename V, typename std::enable_if<!std::is_same<V, hwy::float16_t>::value, int>::type = 0>
TYPE_INLINE void StoreFloat(V* v, T t) {
template<typename T, typename V, ENABLE_TYPE_IS_NOT_F16(V)>
TYPE_INLINE void StoreFloat(V *v, T t) {
v[0] = roundf(t);
}

template<typename T, typename V, typename std::enable_if<std::is_same<V, hwy::float16_t>::value, int>::type = 0>
TYPE_INLINE void StoreFloat(V* v, T t) {
template<typename T, typename V, ENABLE_TYPE_IS_F16(V)>
TYPE_INLINE void StoreFloat(V *v, T t) {
reinterpret_cast<uint16_t *>(v)[0] = hwy::F16FromF32(t).bits;
}

}

#endif //YUV_SRC_TYPESUPPORT_H_

0 comments on commit 184cc92

Please sign in to comment.