simplify memory rotation templates

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-03-14 09:24:33 +02:00
parent 5b05fc946e
commit f4bbfdc17a

View file

@ -43,25 +43,25 @@ QT_BEGIN_NAMESPACE
#define QT_ROTATION_ALGORITHM QT_ROTATION_CACHEDREAD
template <class DST, class SRC>
static inline void qt_memrotate90_template(const SRC *src,
template <class T>
static inline void qt_memrotate90_template(const T *src,
int srcWidth, int srcHeight, int srcStride,
DST *dest, int dstStride)
T *dest, int dstStride)
{
#if QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDREAD
const char *s = reinterpret_cast<const char*>(src);
char *d = reinterpret_cast<char*>(dest);
for (int y = 0; y < srcHeight; ++y) {
for (int x = srcWidth - 1; x >= 0; --x) {
DST *destline = reinterpret_cast<DST*>(d + (srcWidth - x - 1) * dstStride);
T *destline = reinterpret_cast<T*>(d + (srcWidth - x - 1) * dstStride);
destline[y] = src[x];
}
s += srcStride;
src = reinterpret_cast<const SRC*>(s);
src = reinterpret_cast<const T*>(s);
}
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
for (int x = srcWidth - 1; x >= 0; --x) {
DST *d = dest + (srcWidth - x - 1) * dstStride;
T *d = dest + (srcWidth - x - 1) * dstStride;
for (int y = 0; y < srcHeight; ++y) {
*d++ = src[y * srcStride + x];
}
@ -69,26 +69,26 @@ static inline void qt_memrotate90_template(const SRC *src,
#endif
}
template <class DST, class SRC>
static inline void qt_memrotate270_template(const SRC *src,
template <class T>
static inline void qt_memrotate270_template(const T *src,
int srcWidth, int srcHeight, int srcStride,
DST *dest, int dstStride)
T *dest, int dstStride)
{
#if QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDREAD
const char *s = reinterpret_cast<const char*>(src);
char *d = reinterpret_cast<char*>(dest);
s += (srcHeight - 1) * srcStride;
for (int y = srcHeight - 1; y >= 0; --y) {
src = reinterpret_cast<const SRC*>(s);
src = reinterpret_cast<const T*>(s);
for (int x = 0; x < srcWidth; ++x) {
DST *destline = reinterpret_cast<DST*>(d + x * dstStride);
T *destline = reinterpret_cast<T*>(d + x * dstStride);
destline[srcHeight - y - 1] = src[x];
}
s -= srcStride;
}
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
for (int x = 0; x < srcWidth; ++x) {
DST *d = dest + x * dstStride;
T *d = dest + x * dstStride;
for (int y = srcHeight - 1; y >= 0; --y) {
*d++ = src[y * srcStride + x];
}
@ -96,20 +96,20 @@ static inline void qt_memrotate270_template(const SRC *src,
#endif
}
#define QT_IMPL_MEMROTATE(srctype, desttype) \
static inline void qt_memrotate90(const srctype *src, int w, int h, int sstride, \
desttype *dest, int dstride) \
#define QT_IMPL_MEMROTATE(TYPE) \
static inline void qt_memrotate90(const TYPE *src, int w, int h, int sstride, \
TYPE *dest, int dstride) \
{ \
qt_memrotate90_template(src, w, h, sstride, dest, dstride); \
} \
static inline void qt_memrotate270(const srctype *src, int w, int h, int sstride, \
desttype *dest, int dstride) \
static inline void qt_memrotate270(const TYPE *src, int w, int h, int sstride, \
TYPE *dest, int dstride) \
{ \
qt_memrotate270_template(src, w, h, sstride, dest, dstride); \
}
QT_IMPL_MEMROTATE(quint16, quint16)
QT_IMPL_MEMROTATE(quint32, quint32)
QT_IMPL_MEMROTATE(quint16)
QT_IMPL_MEMROTATE(quint32)
#undef QT_IMPL_MEMROTATE