2015-12-10 05:06:13 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
**
|
2019-06-03 13:38:02 +00:00
|
|
|
** This file is part of the QtGui module of the Katie Toolkit.
|
2015-12-10 05:06:13 +02:00
|
|
|
**
|
|
|
|
** $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
|
|
|
|
|
2019-05-30 14:47:21 +00:00
|
|
|
#if QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDREAD
|
2015-12-10 05:06:13 +02:00
|
|
|
template <class DST, class SRC>
|
2016-09-28 23:03:03 +00:00
|
|
|
static inline void qt_memrotate90_cachedRead(const SRC *src, int w, int h,
|
2015-12-10 05:06:13 +02:00
|
|
|
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);
|
2019-05-31 17:24:18 +00:00
|
|
|
destline[y] = src[x];
|
2015-12-10 05:06:13 +02:00
|
|
|
}
|
|
|
|
s += sstride;
|
|
|
|
src = reinterpret_cast<const SRC*>(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class DST, class SRC>
|
2016-09-28 23:03:03 +00:00
|
|
|
static inline void qt_memrotate270_cachedRead(const SRC *src, int w, int h,
|
2015-12-10 05:06:13 +02:00
|
|
|
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);
|
2019-05-31 17:24:18 +00:00
|
|
|
destline[h - y - 1] = src[x];
|
2015-12-10 05:06:13 +02:00
|
|
|
}
|
|
|
|
s -= sstride;
|
|
|
|
}
|
|
|
|
}
|
2019-05-31 17:24:18 +00:00
|
|
|
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
|
2015-12-10 05:06:13 +02:00
|
|
|
template <class DST, class SRC>
|
2016-09-28 23:03:03 +00:00
|
|
|
static inline void qt_memrotate90_cachedWrite(const SRC *src, int w, int h,
|
2015-12-10 05:06:13 +02:00
|
|
|
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) {
|
2019-05-31 17:24:18 +00:00
|
|
|
*d++ = src[y * sstride + x];
|
2015-12-10 05:06:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class DST, class SRC>
|
2016-09-28 23:03:03 +00:00
|
|
|
static inline void qt_memrotate270_cachedWrite(const SRC *src, int w, int h,
|
2015-12-10 05:06:13 +02:00
|
|
|
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) {
|
2019-05-31 17:24:18 +00:00
|
|
|
*d++ = src[y * sstride + x];
|
2015-12-10 05:06:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-31 17:24:18 +00:00
|
|
|
#endif // QT_ROTATION_ALGORITHM
|
2015-12-10 05:06:13 +02:00
|
|
|
|
|
|
|
template <class DST, class SRC>
|
2016-09-28 23:03:03 +00:00
|
|
|
static inline void qt_memrotate90_template(const SRC *src,
|
2015-12-10 05:06:13 +02:00
|
|
|
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>
|
2016-09-28 23:03:03 +00:00
|
|
|
static inline void qt_memrotate180_template(const SRC *src,
|
2015-12-10 05:06:13 +02:00
|
|
|
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) {
|
2019-05-31 17:24:18 +00:00
|
|
|
d[w - x - 1] = src[x];
|
2015-12-10 05:06:13 +02:00
|
|
|
}
|
|
|
|
s -= sstride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class DST, class SRC>
|
2016-09-28 23:03:03 +00:00
|
|
|
static inline void qt_memrotate270_template(const SRC *src,
|
2015-12-10 05:06:13 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
#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); \
|
|
|
|
}
|
|
|
|
|
2019-06-01 12:08:35 +00:00
|
|
|
QT_IMPL_MEMROTATE(quint8, quint8)
|
2015-12-10 05:06:13 +02:00
|
|
|
QT_IMPL_MEMROTATE(quint16, quint16)
|
|
|
|
QT_IMPL_MEMROTATE(quint24, quint24)
|
2019-06-01 12:08:35 +00:00
|
|
|
QT_IMPL_MEMROTATE(quint32, quint32)
|
2015-12-10 05:06:13 +02:00
|
|
|
|
2019-05-30 14:47:21 +00:00
|
|
|
#undef QT_IMPL_MEMROTATE
|
2015-12-10 05:06:13 +02:00
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|