katie/src/gui/painting/qmemrotate.cpp
Ivailo Monev da4b533485 memory rotation cleanup
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
2019-05-30 14:47:21 +00:00

233 lines
9.7 KiB
C++

/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qmemrotate_p.h"
QT_BEGIN_NAMESPACE
#if QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDREAD
template <class DST, class SRC>
static inline void qt_memrotate90_cachedRead(const SRC *src, int w, int h,
int sstride,
DST *dest, int dstride)
{
const char *s = reinterpret_cast<const char*>(src);
char *d = reinterpret_cast<char*>(dest);
for (int y = 0; y < h; ++y) {
for (int x = w - 1; x >= 0; --x) {
DST *destline = reinterpret_cast<DST*>(d + (w - x - 1) * dstride);
destline[y] = qt_colorConvert<DST,SRC>(src[x], 0);
}
s += sstride;
src = reinterpret_cast<const SRC*>(s);
}
}
template <class DST, class SRC>
static inline void qt_memrotate270_cachedRead(const SRC *src, int w, int h,
int sstride,
DST *dest, int dstride)
{
const char *s = reinterpret_cast<const char*>(src);
char *d = reinterpret_cast<char*>(dest);
s += (h - 1) * sstride;
for (int y = h - 1; y >= 0; --y) {
src = reinterpret_cast<const SRC*>(s);
for (int x = 0; x < w; ++x) {
DST *destline = reinterpret_cast<DST*>(d + x * dstride);
destline[h - y - 1] = qt_colorConvert<DST,SRC>(src[x], 0);
}
s -= sstride;
}
}
#endif // QT_ROTATION_CACHEDREAD
#if QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
template <class DST, class SRC>
static inline void qt_memrotate90_cachedWrite(const SRC *src, int w, int h,
int sstride,
DST *dest, int dstride)
{
for (int x = w - 1; x >= 0; --x) {
DST *d = dest + (w - x - 1) * dstride;
for (int y = 0; y < h; ++y) {
*d++ = qt_colorConvert<DST,SRC>(src[y * sstride + x], 0);
}
}
}
template <class DST, class SRC>
static inline void qt_memrotate270_cachedWrite(const SRC *src, int w, int h,
int sstride,
DST *dest, int dstride)
{
for (int x = 0; x < w; ++x) {
DST *d = dest + x * dstride;
for (int y = h - 1; y >= 0; --y) {
*d++ = qt_colorConvert<DST,SRC>(src[y * sstride + x], 0);
}
}
}
#endif // QT_ROTATION_CACHEDWRITE
template <class DST, class SRC>
static inline void qt_memrotate90_template(const SRC *src,
int srcWidth, int srcHeight, int srcStride,
DST *dest, int dstStride)
{
#if QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDREAD
qt_memrotate90_cachedRead<DST,SRC>(src, srcWidth, srcHeight, srcStride,
dest, dstStride);
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
qt_memrotate90_cachedWrite<DST,SRC>(src, srcWidth, srcHeight, srcStride,
dest, dstStride);
#endif
}
template <class DST, class SRC>
static inline void qt_memrotate180_template(const SRC *src,
int w, int h, int sstride,
DST *dest, int dstride)
{
const char *s = (const char*)(src) + (h - 1) * sstride;
for (int y = h - 1; y >= 0; --y) {
DST *d = reinterpret_cast<DST*>((char *)(dest) + (h - y - 1) * dstride);
src = reinterpret_cast<const SRC*>(s);
for (int x = w - 1; x >= 0; --x) {
d[w - x - 1] = qt_colorConvert<DST,SRC>(src[x], 0);
}
s -= sstride;
}
}
template <class DST, class SRC>
static inline void qt_memrotate270_template(const SRC *src,
int srcWidth, int srcHeight, int srcStride,
DST *dest, int dstStride)
{
#if QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDREAD
qt_memrotate270_cachedRead<DST,SRC>(src, srcWidth, srcHeight, srcStride,
dest, dstStride);
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
qt_memrotate270_cachedWrite<DST,SRC>(src, srcWidth, srcHeight, srcStride,
dest, dstStride);
#endif
}
template <>
inline void qt_memrotate90_template<quint24, quint24>(const quint24 *src,
int srcWidth, int srcHeight, int srcStride,
quint24 *dest, int dstStride)
{
#if QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDREAD
qt_memrotate90_cachedRead<quint24,quint24>(src, srcWidth, srcHeight,
srcStride, dest, dstStride);
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
qt_memrotate90_cachedWrite<quint24,quint24>(src, srcWidth, srcHeight,
srcStride, dest, dstStride);
#endif
}
template <>
inline void qt_memrotate90_template<quint24, quint32>(const quint32 *src,
int srcWidth, int srcHeight, int srcStride,
quint24 *dest, int dstStride)
{
#if QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDREAD
qt_memrotate90_cachedRead<quint24,quint32>(src, srcWidth, srcHeight,
srcStride, dest, dstStride);
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
qt_memrotate90_cachedWrite<quint24,quint32>(src, srcWidth, srcHeight,
srcStride, dest, dstStride);
#endif
}
template <>
inline void qt_memrotate90_template<quint18, quint32>(const quint32 *src,
int srcWidth, int srcHeight, int srcStride,
quint18 *dest, int dstStride)
{
#if QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDREAD
qt_memrotate90_cachedRead<quint18,quint32>(src, srcWidth, srcHeight,
srcStride, dest, dstStride);
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
qt_memrotate90_cachedWrite<quint18,quint32>(src, srcWidth, srcHeight,
srcStride, dest, dstStride);
#endif
}
#define QT_IMPL_MEMROTATE(srctype, desttype) \
void qt_memrotate90(const srctype *src, int w, int h, int sstride, \
desttype *dest, int dstride) \
{ \
qt_memrotate90_template(src, w, h, sstride, dest, dstride); \
} \
void qt_memrotate180(const srctype *src, int w, int h, int sstride, \
desttype *dest, int dstride) \
{ \
qt_memrotate180_template(src, w, h, sstride, dest, dstride); \
} \
void qt_memrotate270(const srctype *src, int w, int h, int sstride, \
desttype *dest, int dstride) \
{ \
qt_memrotate270_template(src, w, h, sstride, dest, dstride); \
}
QT_IMPL_MEMROTATE(quint32, quint32)
QT_IMPL_MEMROTATE(quint32, quint16)
QT_IMPL_MEMROTATE(quint16, quint32)
QT_IMPL_MEMROTATE(quint16, quint16)
QT_IMPL_MEMROTATE(quint24, quint24)
QT_IMPL_MEMROTATE(quint32, quint24)
QT_IMPL_MEMROTATE(quint32, quint18)
QT_IMPL_MEMROTATE(quint32, quint8)
QT_IMPL_MEMROTATE(quint16, quint8)
QT_IMPL_MEMROTATE(qrgb444, quint8)
QT_IMPL_MEMROTATE(quint8, quint8)
#undef QT_IMPL_MEMROTATE
QT_END_NAMESPACE