mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 02:42:55 +00:00
memory rotation cleanup
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
c6ff1bc3df
commit
da4b533485
2 changed files with 5 additions and 366 deletions
|
@ -43,16 +43,7 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#if QT_ROTATION_ALGORITHM == QT_ROTATION_TILED
|
||||
static const int tileSize = 32;
|
||||
#endif
|
||||
|
||||
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
|
||||
#if QT_ROTATION_ALGORITHM == QT_ROTATION_PACKED || QT_ROTATION_ALGORITHM == QT_ROTATION_TILED
|
||||
#error Big endian version not implemented for the transformed driver!
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#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,
|
||||
|
@ -87,9 +78,9 @@ static inline void qt_memrotate270_cachedRead(const SRC *src, int w, int h,
|
|||
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,
|
||||
|
@ -116,275 +107,8 @@ static inline void qt_memrotate270_cachedWrite(const SRC *src, int w, int h,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // QT_ROTATION_CACHEDWRITE
|
||||
|
||||
#if QT_ROTATION_ALGORITHM == QT_ROTATION_PACKING
|
||||
|
||||
// TODO: packing algorithms should probably be modified on 64-bit architectures
|
||||
|
||||
template <class DST, class SRC>
|
||||
static inline void qt_memrotate90_packing(const SRC *src, int w, int h,
|
||||
int sstride,
|
||||
DST *dest, int dstride)
|
||||
{
|
||||
sstride /= sizeof(SRC);
|
||||
dstride /= sizeof(DST);
|
||||
|
||||
const int pack = sizeof(quint32) / sizeof(DST);
|
||||
const int unaligned = int((long(dest) & (sizeof(quint32)-1))) / sizeof(DST);
|
||||
|
||||
for (int x = w - 1; x >= 0; --x) {
|
||||
int y = 0;
|
||||
|
||||
for (int i = 0; i < unaligned; ++i) {
|
||||
dest[(w - x - 1) * dstride + y]
|
||||
= qt_colorConvert<DST,SRC>(src[y * sstride + x], 0);
|
||||
++y;
|
||||
}
|
||||
|
||||
quint32 *d = reinterpret_cast<quint32*>(dest + (w - x - 1) * dstride
|
||||
+ unaligned);
|
||||
const int rest = (h - unaligned) % pack;
|
||||
while (y < h - rest) {
|
||||
quint32 c = qt_colorConvert<DST,SRC>(src[y * sstride + x], 0);
|
||||
for (int i = 1; i < pack; ++i) {
|
||||
c |= qt_colorConvert<DST,SRC>(src[(y + i) * sstride + x], 0)
|
||||
<< (sizeof(int) * 8 / pack * i);
|
||||
}
|
||||
*d++ = c;
|
||||
y += pack;
|
||||
}
|
||||
|
||||
while (y < h) {
|
||||
dest[(w - x - 1) * dstride + y]
|
||||
= qt_colorConvert<DST,SRC>(src[y * sstride + x], 0);
|
||||
++y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class DST, class SRC>
|
||||
static inline void qt_memrotate270_packing(const SRC *src, int w, int h,
|
||||
int sstride,
|
||||
DST *dest, int dstride)
|
||||
{
|
||||
sstride /= sizeof(SRC);
|
||||
dstride /= sizeof(DST);
|
||||
|
||||
const int pack = sizeof(quint32) / sizeof(DST);
|
||||
const int unaligned = int((long(dest) & (sizeof(quint32)-1))) / sizeof(DST);
|
||||
|
||||
for (int x = 0; x < w; ++x) {
|
||||
int y = h - 1;
|
||||
|
||||
for (int i = 0; i < unaligned; ++i) {
|
||||
dest[x * dstride + h - y - 1]
|
||||
= qt_colorConvert<DST,SRC>(src[y * sstride + x], 0);
|
||||
--y;
|
||||
}
|
||||
|
||||
quint32 *d = reinterpret_cast<quint32*>(dest + x * dstride
|
||||
+ unaligned);
|
||||
const int rest = (h - unaligned) % pack;
|
||||
while (y > rest) {
|
||||
quint32 c = qt_colorConvert<DST,SRC>(src[y * sstride + x], 0);
|
||||
for (int i = 1; i < pack; ++i) {
|
||||
c |= qt_colorConvert<DST,SRC>(src[(y - i) * sstride + x], 0)
|
||||
<< (sizeof(int) * 8 / pack * i);
|
||||
}
|
||||
*d++ = c;
|
||||
y -= pack;
|
||||
}
|
||||
while (y >= 0) {
|
||||
dest[x * dstride + h - y - 1]
|
||||
= qt_colorConvert<DST,SRC>(src[y * sstride + x], 0);
|
||||
--y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // QT_ROTATION_PACKING
|
||||
|
||||
#if QT_ROTATION_ALGORITHM == QT_ROTATION_TILED
|
||||
template <class DST, class SRC>
|
||||
static inline void qt_memrotate90_tiled(const SRC *src, int w, int h,
|
||||
int sstride,
|
||||
DST *dest, int dstride)
|
||||
{
|
||||
sstride /= sizeof(SRC);
|
||||
dstride /= sizeof(DST);
|
||||
|
||||
const int pack = sizeof(quint32) / sizeof(DST);
|
||||
const int unaligned =
|
||||
qMin(uint((quintptr(dest) & (sizeof(quint32)-1)) / sizeof(DST)), uint(h));
|
||||
const int restX = w % tileSize;
|
||||
const int restY = (h - unaligned) % tileSize;
|
||||
const int unoptimizedY = restY % pack;
|
||||
const int numTilesX = w / tileSize + (restX > 0);
|
||||
const int numTilesY = (h - unaligned) / tileSize + (restY >= pack);
|
||||
|
||||
for (int tx = 0; tx < numTilesX; ++tx) {
|
||||
const int startx = w - tx * tileSize - 1;
|
||||
const int stopx = qMax(startx - tileSize, 0);
|
||||
|
||||
if (unaligned) {
|
||||
for (int x = startx; x >= stopx; --x) {
|
||||
DST *d = dest + (w - x - 1) * dstride;
|
||||
for (int y = 0; y < unaligned; ++y) {
|
||||
*d++ = qt_colorConvert<DST,SRC>(src[y * sstride + x], 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int ty = 0; ty < numTilesY; ++ty) {
|
||||
const int starty = ty * tileSize + unaligned;
|
||||
const int stopy = qMin(starty + tileSize, h - unoptimizedY);
|
||||
|
||||
for (int x = startx; x >= stopx; --x) {
|
||||
quint32 *d = reinterpret_cast<quint32*>(dest + (w - x - 1) * dstride + starty);
|
||||
for (int y = starty; y < stopy; y += pack) {
|
||||
quint32 c = qt_colorConvert<DST,SRC>(src[y * sstride + x], 0);
|
||||
for (int i = 1; i < pack; ++i) {
|
||||
const int shift = (sizeof(int) * 8 / pack * i);
|
||||
const DST color = qt_colorConvert<DST,SRC>(src[(y + i) * sstride + x], 0);
|
||||
c |= color << shift;
|
||||
}
|
||||
*d++ = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (unoptimizedY) {
|
||||
const int starty = h - unoptimizedY;
|
||||
for (int x = startx; x >= stopx; --x) {
|
||||
DST *d = dest + (w - x - 1) * dstride + starty;
|
||||
for (int y = starty; y < h; ++y) {
|
||||
*d++ = qt_colorConvert<DST,SRC>(src[y * sstride + x], 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class DST, class SRC>
|
||||
static inline void qt_memrotate90_tiled_unpacked(const SRC *src, int w, int h,
|
||||
int sstride,
|
||||
DST *dest, int dstride)
|
||||
{
|
||||
const int numTilesX = (w + tileSize - 1) / tileSize;
|
||||
const int numTilesY = (h + tileSize - 1) / tileSize;
|
||||
|
||||
for (int tx = 0; tx < numTilesX; ++tx) {
|
||||
const int startx = w - tx * tileSize - 1;
|
||||
const int stopx = qMax(startx - tileSize, 0);
|
||||
|
||||
for (int ty = 0; ty < numTilesY; ++ty) {
|
||||
const int starty = ty * tileSize;
|
||||
const int stopy = qMin(starty + tileSize, h);
|
||||
|
||||
for (int x = startx; x >= stopx; --x) {
|
||||
DST *d = (DST*)((char*)dest + (w - x - 1) * dstride) + starty;
|
||||
const char *s = (const char*)(src + x) + starty * sstride;
|
||||
for (int y = starty; y < stopy; ++y) {
|
||||
*d++ = qt_colorConvert<DST,SRC>(*(const SRC*)(s), 0);
|
||||
s += sstride;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class DST, class SRC>
|
||||
static inline void qt_memrotate270_tiled(const SRC *src, int w, int h,
|
||||
int sstride,
|
||||
DST *dest, int dstride)
|
||||
{
|
||||
sstride /= sizeof(SRC);
|
||||
dstride /= sizeof(DST);
|
||||
|
||||
const int pack = sizeof(quint32) / sizeof(DST);
|
||||
const int unaligned =
|
||||
qMin(uint((long(dest) & (sizeof(quint32)-1)) / sizeof(DST)), uint(h));
|
||||
const int restX = w % tileSize;
|
||||
const int restY = (h - unaligned) % tileSize;
|
||||
const int unoptimizedY = restY % pack;
|
||||
const int numTilesX = w / tileSize + (restX > 0);
|
||||
const int numTilesY = (h - unaligned) / tileSize + (restY >= pack);
|
||||
|
||||
for (int tx = 0; tx < numTilesX; ++tx) {
|
||||
const int startx = tx * tileSize;
|
||||
const int stopx = qMin(startx + tileSize, w);
|
||||
|
||||
if (unaligned) {
|
||||
for (int x = startx; x < stopx; ++x) {
|
||||
DST *d = dest + x * dstride;
|
||||
for (int y = h - 1; y >= h - unaligned; --y) {
|
||||
*d++ = qt_colorConvert<DST,SRC>(src[y * sstride + x], 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int ty = 0; ty < numTilesY; ++ty) {
|
||||
const int starty = h - 1 - unaligned - ty * tileSize;
|
||||
const int stopy = qMax(starty - tileSize, unoptimizedY);
|
||||
|
||||
for (int x = startx; x < stopx; ++x) {
|
||||
quint32 *d = reinterpret_cast<quint32*>(dest + x * dstride
|
||||
+ h - 1 - starty);
|
||||
for (int y = starty; y > stopy; y -= pack) {
|
||||
quint32 c = qt_colorConvert<DST,SRC>(src[y * sstride + x], 0);
|
||||
for (int i = 1; i < pack; ++i) {
|
||||
const int shift = (sizeof(int) * 8 / pack * i);
|
||||
const DST color = qt_colorConvert<DST,SRC>(src[(y - i) * sstride + x], 0);
|
||||
c |= color << shift;
|
||||
}
|
||||
*d++ = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (unoptimizedY) {
|
||||
const int starty = unoptimizedY - 1;
|
||||
for (int x = startx; x < stopx; ++x) {
|
||||
DST *d = dest + x * dstride + h - 1 - starty;
|
||||
for (int y = starty; y >= 0; --y) {
|
||||
*d++ = qt_colorConvert<DST,SRC>(src[y * sstride + x], 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class DST, class SRC>
|
||||
static inline void qt_memrotate270_tiled_unpacked(const SRC *src, int w, int h,
|
||||
int sstride,
|
||||
DST *dest, int dstride)
|
||||
{
|
||||
const int numTilesX = (w + tileSize - 1) / tileSize;
|
||||
const int numTilesY = (h + tileSize - 1) / tileSize;
|
||||
|
||||
for (int tx = 0; tx < numTilesX; ++tx) {
|
||||
const int startx = tx * tileSize;
|
||||
const int stopx = qMin(startx + tileSize, w);
|
||||
|
||||
for (int ty = 0; ty < numTilesY; ++ty) {
|
||||
const int starty = h - 1 - ty * tileSize;
|
||||
const int stopy = qMax(starty - tileSize, 0);
|
||||
|
||||
for (int x = startx; x < stopx; ++x) {
|
||||
DST *d = (DST*)((char*)dest + x * dstride) + h - 1 - starty;
|
||||
const char *s = (const char*)(src + x) + starty * sstride;
|
||||
for (int y = starty; y >= stopy; --y) {
|
||||
*d++ = qt_colorConvert<DST,SRC>(*(const SRC*)s, 0);
|
||||
s -= sstride;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // QT_ROTATION_ALGORITHM
|
||||
|
||||
template <class DST, class SRC>
|
||||
static inline void qt_memrotate90_template(const SRC *src,
|
||||
int srcWidth, int srcHeight, int srcStride,
|
||||
|
@ -396,12 +120,6 @@ static inline void qt_memrotate90_template(const SRC *src,
|
|||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
|
||||
qt_memrotate90_cachedWrite<DST,SRC>(src, srcWidth, srcHeight, srcStride,
|
||||
dest, dstStride);
|
||||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_PACKING
|
||||
qt_memrotate90_packing<DST,SRC>(src, srcWidth, srcHeight, srcStride,
|
||||
dest, dstStride);
|
||||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_TILED
|
||||
qt_memrotate90_tiled<DST,SRC>(src, srcWidth, srcHeight, srcStride,
|
||||
dest, dstStride);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -432,13 +150,6 @@ static inline void qt_memrotate270_template(const SRC *src,
|
|||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
|
||||
qt_memrotate270_cachedWrite<DST,SRC>(src, srcWidth, srcHeight, srcStride,
|
||||
dest, dstStride);
|
||||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_PACKING
|
||||
qt_memrotate270_packing<DST,SRC>(src, srcWidth, srcHeight, srcStride,
|
||||
dest, dstStride);
|
||||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_TILED
|
||||
qt_memrotate270_tiled_unpacked<DST,SRC>(src, srcWidth, srcHeight,
|
||||
srcStride,
|
||||
dest, dstStride);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -453,14 +164,6 @@ inline void qt_memrotate90_template<quint24, quint24>(const quint24 *src,
|
|||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
|
||||
qt_memrotate90_cachedWrite<quint24,quint24>(src, srcWidth, srcHeight,
|
||||
srcStride, dest, dstStride);
|
||||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_PACKING
|
||||
// packed algorithm not implemented
|
||||
qt_memrotate90_cachedRead<quint24,quint24>(src, srcWidth, srcHeight,
|
||||
srcStride, dest, dstStride);
|
||||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_TILED
|
||||
// packed algorithm not implemented
|
||||
qt_memrotate90_tiled_unpacked<quint24,quint24>(src, srcWidth, srcHeight,
|
||||
srcStride, dest, dstStride);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -475,14 +178,6 @@ inline void qt_memrotate90_template<quint24, quint32>(const quint32 *src,
|
|||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
|
||||
qt_memrotate90_cachedWrite<quint24,quint32>(src, srcWidth, srcHeight,
|
||||
srcStride, dest, dstStride);
|
||||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_PACKING
|
||||
// packed algorithm not implemented
|
||||
qt_memrotate90_cachedRead<quint24,quint32>(src, srcWidth, srcHeight,
|
||||
srcStride, dest, dstStride);
|
||||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_TILED
|
||||
// packed algorithm not implemented
|
||||
qt_memrotate90_tiled_unpacked<quint24,quint32>(src, srcWidth, srcHeight,
|
||||
srcStride, dest, dstStride);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -497,14 +192,6 @@ inline void qt_memrotate90_template<quint18, quint32>(const quint32 *src,
|
|||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_CACHEDWRITE
|
||||
qt_memrotate90_cachedWrite<quint18,quint32>(src, srcWidth, srcHeight,
|
||||
srcStride, dest, dstStride);
|
||||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_PACKING
|
||||
// packed algorithm not implemented
|
||||
qt_memrotate90_cachedRead<quint18,quint32>(src, srcWidth, srcHeight,
|
||||
srcStride, dest, dstStride);
|
||||
#elif QT_ROTATION_ALGORITHM == QT_ROTATION_TILED
|
||||
// packed algorithm not implemented
|
||||
qt_memrotate90_tiled_unpacked<quint18,quint32>(src, srcWidth, srcHeight,
|
||||
srcStride, dest, dstStride);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -525,24 +212,6 @@ void qt_memrotate270(const srctype *src, int w, int h, int sstride, \
|
|||
qt_memrotate270_template(src, w, h, sstride, dest, dstride); \
|
||||
}
|
||||
|
||||
#define QT_IMPL_SIMPLE_MEMROTATE(srctype, desttype) \
|
||||
void qt_memrotate90(const srctype *src, int w, int h, int sstride, \
|
||||
desttype *dest, int dstride) \
|
||||
{ \
|
||||
qt_memrotate90_tiled_unpacked<desttype,srctype>(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_tiled_unpacked<desttype,srctype>(src, w, h, sstride, dest, dstride); \
|
||||
}
|
||||
|
||||
|
||||
QT_IMPL_MEMROTATE(quint32, quint32)
|
||||
QT_IMPL_MEMROTATE(quint32, quint16)
|
||||
QT_IMPL_MEMROTATE(quint16, quint32)
|
||||
|
@ -555,35 +224,7 @@ QT_IMPL_MEMROTATE(quint16, quint8)
|
|||
QT_IMPL_MEMROTATE(qrgb444, quint8)
|
||||
QT_IMPL_MEMROTATE(quint8, quint8)
|
||||
|
||||
void qt_memrotate90_16(const uchar *srcPixels, int w, int h, int sbpl, uchar *destPixels, int dbpl)
|
||||
{
|
||||
qt_memrotate90((const ushort *)srcPixels, w, h, sbpl, (ushort *)destPixels, dbpl);
|
||||
}
|
||||
|
||||
void qt_memrotate180_16(const uchar *srcPixels, int w, int h, int sbpl, uchar *destPixels, int dbpl)
|
||||
{
|
||||
qt_memrotate180((const ushort *)srcPixels, w, h, sbpl, (ushort *)destPixels, dbpl);
|
||||
}
|
||||
|
||||
void qt_memrotate270_16(const uchar *srcPixels, int w, int h, int sbpl, uchar *destPixels, int dbpl)
|
||||
{
|
||||
qt_memrotate270((const ushort *)srcPixels, w, h, sbpl, (ushort *)destPixels, dbpl);
|
||||
}
|
||||
|
||||
void qt_memrotate90_32(const uchar *srcPixels, int w, int h, int sbpl, uchar *destPixels, int dbpl)
|
||||
{
|
||||
qt_memrotate90((const uint *)srcPixels, w, h, sbpl, (uint *)destPixels, dbpl);
|
||||
}
|
||||
|
||||
void qt_memrotate180_32(const uchar *srcPixels, int w, int h, int sbpl, uchar *destPixels, int dbpl)
|
||||
{
|
||||
qt_memrotate180((const uint *)srcPixels, w, h, sbpl, (uint *)destPixels, dbpl);
|
||||
}
|
||||
|
||||
void qt_memrotate270_32(const uchar *srcPixels, int w, int h, int sbpl, uchar *destPixels, int dbpl)
|
||||
{
|
||||
qt_memrotate270((const uint *)srcPixels, w, h, sbpl, (uint *)destPixels, dbpl);
|
||||
}
|
||||
#undef QT_IMPL_MEMROTATE
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
|
|
@ -59,12 +59,10 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
#define QT_ROTATION_CACHEDREAD 1
|
||||
#define QT_ROTATION_CACHEDWRITE 2
|
||||
#define QT_ROTATION_PACKING 3
|
||||
#define QT_ROTATION_TILED 4
|
||||
|
||||
#ifndef QT_ROTATION_ALGORITHM
|
||||
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
|
||||
#define QT_ROTATION_ALGORITHM QT_ROTATION_TILED
|
||||
#define QT_ROTATION_ALGORITHM QT_ROTATION_CACHEDWRITE
|
||||
#else
|
||||
#define QT_ROTATION_ALGORITHM QT_ROTATION_CACHEDREAD
|
||||
#endif
|
||||
|
@ -75,7 +73,7 @@ QT_BEGIN_NAMESPACE
|
|||
void qt_memrotate180(const srctype*, int, int, int, desttype*, int); \
|
||||
void qt_memrotate270(const srctype*, int, int, int, desttype*, int)
|
||||
|
||||
void Q_GUI_EXPORT qt_memrotate90(const quint32*, int, int, int, quint32*, int);
|
||||
void qt_memrotate90(const quint32*, int, int, int, quint32*, int);
|
||||
void qt_memrotate180(const quint32*, int, int, int, quint32*, int);
|
||||
void qt_memrotate270(const quint32*, int, int, int, quint32*, int);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue