7#ifndef KIS_LOD_TRANSFORM_BASE_H
8#define KIS_LOD_TRANSFORM_BASE_H
11#include <QtCore/qmath.h>
15#include <kritaglobal_export.h>
20 qreal scale = lodToScale(levelOfDetail);
21 m_transform = QTransform::fromScale(scale, scale);
22 m_levelOfDetail = levelOfDetail;
28 return qMin(maxLod, qMax(0, qFloor(std::log2(1.0 / scale))));
32 return levelOfDetail > 0 ? 1.0 / (1 << qMax(0, levelOfDetail)) : 1.0;
36 return 1 << qMax(0, levelOfDetail);
39 template <
class Pa
intDeviceTypeSP>
41 return lodToScale(device->defaultBounds()->currentLevelOfDetail());
44 QRectF
map(
const QRectF &rc)
const {
45 return m_transform.mapRect(rc);
48 QRect
map(
const QRect &rc)
const {
49 return m_transform.mapRect(rc);
53 return m_transform.inverted().mapRect(rc);
57 return m_transform.inverted().mapRect(rc);
63 T
map(
const T &
object)
const {
64 return m_transform.map(
object);
67 static inline QRect
alignedRect(
const QRect &srcRect,
int lod)
69 qint32 alignment = 1 << lod;
71 qint32 x1, y1, x2, y2;
72 srcRect.getCoords(&x1, &y1, &x2, &y2);
86 rect.setCoords(x1, y1, x2, y2);
91 static inline QRect
scaledRect(
const QRect &srcRect,
int lod) {
92 qint32 x1, y1, x2, y2;
93 srcRect.getCoords(&x1, &y1, &x2, &y2);
100 x1 = divideSafe(x1, lod);
101 y1 = divideSafe(y1, lod);
102 x2 = divideSafe(x2 + 1, lod) - 1;
103 y2 = divideSafe(y2 + 1, lod) - 1;
106 rect.setCoords(x1, y1, x2, y2);
112 qint32 x1, y1, x2, y2;
113 srcRect.getCoords(&x1, &y1, &x2, &y2);
127 rect.setCoords(x1, y1, x2, y2);
133 return divideSafe(x, lod);
148 qint32 mask = alignment - 1;
158 qint32 mask = alignment - 1;
163 return x > 0 ? x >> lod : -( -x >> lod);
177 template <
class Pa
intDeviceTypeSP>
float value(const T *src, size_t ch)
A utility class to maintain a sparse grid of loaded/unloaded rects.
#define KIS_ASSERT_RECOVER_NOOP(cond)
void alignByPow2Lo(qint32 &value, qint32 alignment)
void alignByPow2ButOneHi(qint32 &value, qint32 alignment)