42 #ifndef QBLENDFUNCTIONS_P_H 43 #define QBLENDFUNCTIONS_P_H 61 template <
typename SRC,
typename T>
63 const uchar *srcPixels,
int sbpl,
int sh,
72 int ix = 0x00010000 / sx;
73 int iy = 0x00010000 / sy;
82 int cx2 = clip.
x() + clip.
width();
84 int cy2 = clip.
y() + clip.
height();
126 int dstx =
qCeil((tx1 +
qreal(0.5) - targetRect.
left()) * ix) - 1;
133 int dsty =
qCeil((ty1 +
qreal(0.5) - targetRect.
top()) * iy) - 1;
141 int yend = (srcy + iy * (h - 1)) >> 16;
142 if (yend < 0 || yend >= sh)
144 int xend = (basex + ix * (w - 1)) >> 16;
145 if (xend < 0 || xend >= (
int)(sbpl/
sizeof(
quint32)))
149 const SRC *src = (
const SRC *) (srcPixels + (srcy >> 16) * sbpl);
152 for (; x<w-7; x+=8) {
153 blender.write(&dst[x], src[srcx >> 16]); srcx += ix;
154 blender.write(&dst[x+1], src[srcx >> 16]); srcx += ix;
155 blender.write(&dst[x+2], src[srcx >> 16]); srcx += ix;
156 blender.write(&dst[x+3], src[srcx >> 16]); srcx += ix;
157 blender.write(&dst[x+4], src[srcx >> 16]); srcx += ix;
158 blender.write(&dst[x+5], src[srcx >> 16]); srcx += ix;
159 blender.write(&dst[x+6], src[srcx >> 16]); srcx += ix;
160 blender.write(&dst[x+7], src[srcx >> 16]); srcx += ix;
163 blender.write(&dst[x], src[srcx >> 16]);
166 blender.flush(&dst[x]);
173 const uchar *srcPixels,
int sbpl,
int sh,
182 int ix = 0x00010000 / sx;
183 int iy = 0x00010000 / sy;
192 int cx2 = clip.
x() + clip.
width();
193 int cy1 = clip.
top();
194 int cy2 = clip.
y() + clip.
height();
235 int dstx =
qCeil((tx1 +
qreal(0.5) - targetRect.
left()) * ix) - 1;
242 int dsty =
qCeil((ty1 +
qreal(0.5) - targetRect.
top()) * iy) - 1;
250 int yend = (srcy + iy * (h - 1)) >> 16;
251 if (yend < 0 || yend >= sh)
253 int xend = (basex + ix * (w - 1)) >> 16;
254 if (xend < 0 || xend >= (
int)(sbpl/
sizeof(
quint32)))
258 const uint *src = (
const quint32 *) (srcPixels + (srcy >> 16) * sbpl);
262 blender.write(&dst[x], src[srcx >> 16]);
265 blender.flush(&dst[x]);
276 template <
class SrcT,
class DestT,
class Blender>
278 const SrcT *srcPixels,
int sbpl,
281 const QRect &sourceRect,
284 int dudx,
int dvdx,
int dudy,
int dvdy,
int u0,
int v0,
292 qreal leftSlope = (bottomLeft.
x - topLeft.
x) / (bottomLeft.
y - topLeft.
y);
293 qreal rightSlope = (bottomRight.
x - topRight.
x) / (bottomRight.
y - topRight.
y);
294 int dx_l = int(leftSlope * 0x10000);
295 int dx_r = int(rightSlope * 0x10000);
296 int x_l = int((topLeft.
x + (
qreal(0.5) + fromY - topLeft.
y) * leftSlope +
qreal(0.5)) * 0x10000);
297 int x_r = int((topRight.
x + (
qreal(0.5) + fromY - topRight.
y) * rightSlope +
qreal(0.5)) * 0x10000);
299 int fromX, toX, x1, x2,
u,
v, i, ii;
301 for (
int y = fromY;
y < toY; ++
y) {
302 line =
reinterpret_cast<DestT *
>(
reinterpret_cast<uchar *
>(destPixels) +
y * dbpl);
304 fromX =
qMax(x_l >> 16, clip.
left());
313 u = x1 * dudx +
y * dudy + u0;
314 v = x1 * dvdx +
y * dvdy + v0;
315 for (; x1 < toX; ++x1) {
318 if (uu >= sourceRect.
left() && uu < sourceRect.
left() + sourceRect.
width()
319 && vv >= sourceRect.
top() && vv < sourceRect.
top() + sourceRect.
height()) {
328 u = (x2 - 1) * dudx +
y * dudy + u0;
329 v = (x2 - 1) * dvdx +
y * dvdy + v0;
330 for (; x2 > x1; --x2) {
333 if (uu >= sourceRect.
left() && uu < sourceRect.
left() + sourceRect.
width()
334 && vv >= sourceRect.
top() && vv < sourceRect.
top() + sourceRect.
height()) {
342 u = fromX * dudx +
y * dudy + u0;
343 v = fromX * dvdx +
y * dvdy + v0;
350 int vv =
qBound(sourceRect.
top(), v >> 16, sourceRect.
top() + sourceRect.
height() - 1);
351 blender.write(line, reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + vv * sbpl)[uu]);
363 blender.write(&line[0], reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
364 blender.write(&line[1], reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
365 blender.write(&line[2], reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
366 blender.write(&line[3], reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
367 blender.write(&line[4], reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
368 blender.write(&line[5], reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
369 blender.write(&line[6], reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
370 blender.write(&line[7], reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
377 case 7: blender.write(line, reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx; ++line;
378 case 6: blender.write(line, reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx; ++line;
379 case 5: blender.write(line, reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx; ++line;
380 case 4: blender.write(line, reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx; ++line;
381 case 3: blender.write(line, reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx; ++line;
382 case 2: blender.write(line, reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx; ++line;
383 case 1: blender.write(line, reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx; ++line;
390 int vv =
qBound(sourceRect.
top(), v >> 16, sourceRect.
top() + sourceRect.
height() - 1);
391 blender.write(line, reinterpret_cast<const SrcT *>(reinterpret_cast<const uchar *>(srcPixels) + vv * sbpl)[uu]);
405 template <
class SrcT,
class DestT,
class Blender>
407 const SrcT *srcPixels,
int sbpl,
424 v[TopLeft].
u = v[BottomLeft].
u = sourceRect.
left();
425 v[TopLeft].
v = v[TopRight].
v = sourceRect.
top();
426 v[TopRight].
u = v[BottomRight].
u = sourceRect.
right();
427 v[BottomLeft].
v = v[BottomRight].
v = sourceRect.
bottom();
428 targetRectTransform.
map(targetRect.
left(), targetRect.
top(), &v[TopLeft].
x, &v[TopLeft].
y);
429 targetRectTransform.
map(targetRect.
right(), targetRect.
top(), &v[TopRight].
x, &v[TopRight].
y);
430 targetRectTransform.
map(targetRect.
left(), targetRect.
bottom(), &v[BottomLeft].
x, &v[BottomLeft].
y);
431 targetRectTransform.
map(targetRect.
right(), targetRect.
bottom(), &v[BottomRight].
x, &v[BottomRight].
y);
435 for (
int i = 1; i < 4; ++i) {
436 if (v[i].
y < v[topmost].
y)
444 for (
int i = 0; i < 3; ++i)
456 for (
int i = 3; i > 0; --i)
468 if (dx1 * dy2 - dx2 * dy1 > 0)
478 qreal invDet = 1.0 / det;
479 qreal m11, m12, m21, m22, mdx, mdy;
481 m11 = (u.
u * w.
y - u.
y * w.
u) * invDet;
482 m12 = (u.
x * w.
u - u.
u * w.
x) * invDet;
483 m21 = (u.
v * w.
y - u.
y * w.
v) * invDet;
484 m22 = (u.
x * w.
v - u.
v * w.
x) * invDet;
485 mdx = v[0].
u - m11 * v[0].
x - m12 * v[0].
y;
486 mdy = v[0].
v - m21 * v[0].
x - m22 * v[0].
y;
488 int dudx = int(m11 * 0x10000);
489 int dvdx = int(m21 * 0x10000);
490 int dudy = int(m12 * 0x10000);
491 int dvdy = int(m22 * 0x10000);
492 int u0 =
qCeil((
qreal(0.5) * m11 +
qreal(0.5) * m12 + mdx) * 0x10000) - 1;
493 int v0 =
qCeil((
qreal(0.5) * m21 +
qreal(0.5) * m22 + mdy) * 0x10000) - 1;
499 QRect sourceRectI(x1, y1, x2 - x1, y2 - y1);
502 if (v[1].
y < v[3].
y) {
503 qt_transform_image_rasterize(destPixels, dbpl, srcPixels, sbpl, v[0], v[1], v[0], v[3], sourceRectI, clip, v[0].y, v[1].y, dudx, dvdx, dudy, dvdy, u0, v0, blender);
504 qt_transform_image_rasterize(destPixels, dbpl, srcPixels, sbpl, v[1], v[2], v[0], v[3], sourceRectI, clip, v[1].y, v[3].y, dudx, dvdx, dudy, dvdy, u0, v0, blender);
505 qt_transform_image_rasterize(destPixels, dbpl, srcPixels, sbpl, v[1], v[2], v[3], v[2], sourceRectI, clip, v[3].y, v[2].y, dudx, dvdx, dudy, dvdy, u0, v0, blender);
507 qt_transform_image_rasterize(destPixels, dbpl, srcPixels, sbpl, v[0], v[1], v[0], v[3], sourceRectI, clip, v[0].y, v[3].y, dudx, dvdx, dudy, dvdy, u0, v0, blender);
508 qt_transform_image_rasterize(destPixels, dbpl, srcPixels, sbpl, v[0], v[1], v[3], v[2], sourceRectI, clip, v[3].y, v[1].y, dudx, dvdx, dudy, dvdy, u0, v0, blender);
509 qt_transform_image_rasterize(destPixels, dbpl, srcPixels, sbpl, v[1], v[2], v[3], v[2], sourceRectI, clip, v[1].y, v[2].y, dudx, dvdx, dudy, dvdy, u0, v0, blender);
515 #endif // QBLENDFUNCTIONS_P_H void qt_transform_image_rasterize(DestT *destPixels, int dbpl, const SrcT *srcPixels, int sbpl, const QTransformImageVertex &topLeft, const QTransformImageVertex &bottomLeft, const QTransformImageVertex &topRight, const QTransformImageVertex &bottomRight, const QRect &sourceRect, const QRect &clip, qreal topY, qreal bottomY, int dudx, int dvdx, int dudy, int dvdy, int u0, int v0, Blender blender)
qreal right() const
Returns the x-coordinate of the rectangle's right edge.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
qreal left() const
Returns the x-coordinate of the rectangle's left edge.
int left() const
Returns the x-coordinate of the rectangle's left edge.
int width() const
Returns the width of the rectangle.
void qt_scale_image_32bit(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, int sh, const QRectF &targetRect, const QRectF &srcRect, const QRect &clip, T blender)
int height() const
Returns the height of the rectangle.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
#define QT_BEGIN_NAMESPACE
This macro expands to.
void qt_transform_image(DestT *destPixels, int dbpl, const SrcT *srcPixels, int sbpl, const QRectF &targetRect, const QRectF &sourceRect, const QRect &clip, const QTransform &targetRectTransform, Blender blender)
The QRectF class defines a rectangle in the plane using floating point precision. ...
qreal height() const
Returns the height of the rectangle.
qreal width() const
Returns the width of the rectangle.
void qSwap(T &value1, T &value2)
int top() const
Returns the y-coordinate of the rectangle's top edge.
int y() const
Returns the y-coordinate of the rectangle's top edge.
int x() const
Returns the x-coordinate of the rectangle's left edge.
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
The QRect class defines a rectangle in the plane using integer precision.
qreal top() const
Returns the y-coordinate of the rectangle's top edge.
qreal bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
Q_DECL_CONSTEXPR int qRound(qreal d)
void qt_scale_image_16bit(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, int sh, const QRectF &targetRect, const QRectF &srcRect, const QRect &clip, T blender)