5#ifndef QBLENDFUNCTIONS_P_H
6#define QBLENDFUNCTIONS_P_H
8#include <QtGui/private/qtguiglobal_p.h>
25template <
typename SRC,
typename T>
26void qt_scale_image_16bit(uchar *destPixels,
int dbpl,
27 const uchar *srcPixels,
int sbpl,
int srch,
28 const QRectF &targetRect,
29 const QRectF &srcRect,
33 qreal sx = srcRect.width() / (qreal) targetRect.width();
34 qreal sy = srcRect.height() / (qreal) targetRect.height();
36 const int ix = 0x00010000 * sx;
37 const int iy = 0x00010000 * sy;
45 QRect tr = targetRect.normalized().toRect();
46 tr = tr.intersected(clip);
49 const int tx1 = tr.left();
50 const int ty1 = tr.top();
58 int dstx = qFloor((tx1 + qreal(0.5) - targetRect.right()) * sx * 65536) + 1;
59 basex = quint32(srcRect.right() * 65536) + dstx;
61 int dstx = qCeil((tx1 + qreal(0.5) - targetRect.left()) * sx * 65536) - 1;
62 basex = quint32(srcRect.left() * 65536) + dstx;
65 int dsty = qFloor((ty1 + qreal(0.5) - targetRect.bottom()) * sy * 65536) + 1;
66 srcy = quint32(srcRect.bottom() * 65536) + dsty;
68 int dsty = qCeil((ty1 + qreal(0.5) - targetRect.top()) * sy * 65536) - 1;
69 srcy = quint32(srcRect.top() * 65536) + dsty;
72 quint16 *dst = ((quint16 *) (destPixels + ty1 * dbpl)) + tx1;
76 const int ystart = srcy >> 16;
77 if (ystart >= srch && iy < 0) {
81 const int xstart = basex >> 16;
82 if (xstart >= (
int)(sbpl/
sizeof(SRC)) && ix < 0) {
86 int yend = (srcy + iy * (h - 1)) >> 16;
87 if (yend < 0 || yend >= srch)
89 int xend = (basex + ix * (w - 1)) >> 16;
90 if (xend < 0 || xend >= (
int)(sbpl/
sizeof(SRC)))
94 const SRC *src = (
const SRC *) (srcPixels + (srcy >> 16) * sbpl);
98 blender.write(&dst[x], src[srcx >> 16]); srcx += ix;
99 blender.write(&dst[x+1], src[srcx >> 16]); srcx += ix;
100 blender.write(&dst[x+2], src[srcx >> 16]); srcx += ix;
101 blender.write(&dst[x+3], src[srcx >> 16]); srcx += ix;
102 blender.write(&dst[x+4], src[srcx >> 16]); srcx += ix;
103 blender.write(&dst[x+5], src[srcx >> 16]); srcx += ix;
104 blender.write(&dst[x+6], src[srcx >> 16]); srcx += ix;
105 blender.write(&dst[x+7], src[srcx >> 16]); srcx += ix;
108 blender.write(&dst[x], src[srcx >> 16]);
111 blender.flush(&dst[x]);
112 dst = (quint16 *)(((uchar *) dst) + dbpl);
118 const uchar *srcPixels,
int sbpl,
int srch,
119 const QRectF &targetRect,
120 const QRectF &srcRect,
124 qreal sx = srcRect.width() / (qreal) targetRect.width();
125 qreal sy = srcRect.height() / (qreal) targetRect.height();
127 const int ix = 0x00010000 * sx;
128 const int iy = 0x00010000 * sy;
136 QRect tr = targetRect.normalized().toRect();
137 tr = tr.intersected(clip);
140 const int tx1 = tr.left();
141 const int ty1 = tr.top();
149 int dstx = qFloor((tx1 + qreal(0.5) - targetRect.right()) * sx * 65536) + 1;
150 basex = quint32(srcRect.right() * 65536) + dstx;
152 int dstx = qCeil((tx1 + qreal(0.5) - targetRect.left()) * sx * 65536) - 1;
153 basex = quint32(srcRect.left() * 65536) + dstx;
156 int dsty = qFloor((ty1 + qreal(0.5) - targetRect.bottom()) * sy * 65536) + 1;
157 srcy = quint32(srcRect.bottom() * 65536) + dsty;
159 int dsty = qCeil((ty1 + qreal(0.5) - targetRect.top()) * sy * 65536) - 1;
160 srcy = quint32(srcRect.top() * 65536) + dsty;
163 quint32 *dst = ((quint32 *) (destPixels + ty1 * dbpl)) + tx1;
167 const int ystart = srcy >> 16;
168 if (ystart >= srch && iy < 0) {
172 const int xstart = basex >> 16;
173 if (xstart >= (
int)(sbpl/
sizeof(quint32)) && ix < 0) {
177 int yend = (srcy + iy * (h - 1)) >> 16;
178 if (yend < 0 || yend >= srch)
180 int xend = (basex + ix * (w - 1)) >> 16;
181 if (xend < 0 || xend >= (
int)(sbpl/
sizeof(quint32)))
185 const uint *src = (
const quint32 *) (srcPixels + (srcy >> 16) * sbpl);
186 quint32 srcx = basex;
189 blender.write(&dst[x], src[srcx >> 16]);
192 blender.flush(&dst[x]);
193 dst = (quint32 *)(((uchar *) dst) + dbpl);
203template <
class SrcT,
class DestT,
class Blender>
205 const SrcT *srcPixels,
int sbpl,
208 const QRect &sourceRect,
210 qreal topY, qreal bottomY,
211 int dudx,
int dvdx,
int dudy,
int dvdy,
int u0,
int v0,
214 qint64 fromY = qMax(qRound(topY), clip.top());
215 qint64 toY = qMin(qRound(bottomY), clip.top() + clip.height());
219 qreal leftSlope = (bottomLeft.x - topLeft.x) / (bottomLeft.y - topLeft.y);
220 qreal rightSlope = (bottomRight.x - topRight.x) / (bottomRight.y - topRight.y);
221 qint64 dx_l = qint64(leftSlope * 0x10000);
222 qint64 dx_r = qint64(rightSlope * 0x10000);
223 qint64 x_l = qint64((topLeft.x + (qreal(0.5) + fromY - topLeft.y) * leftSlope + qreal(0.5)) * 0x10000);
224 qint64 x_r = qint64((topRight.x + (qreal(0.5) + fromY - topRight.y) * rightSlope + qreal(0.5)) * 0x10000);
226 qint64 sourceRectTop = qint64(sourceRect.top());
227 qint64 sourceRectLeft = qint64(sourceRect.left());
228 qint64 sourceRectWidth = qint64(sourceRect.width());
229 qint64 sourceRectHeight = qint64(sourceRect.height());
230 qint64 clipLeft = qint64(clip.left());
231 qint64 clipWidth = qint64(clip.width());
233 qint64 fromX, toX, x1, x2, u, v, i, ii;
235 for (qint64 y = fromY; y < toY; ++y) {
236 line =
reinterpret_cast<DestT *>(
reinterpret_cast<uchar *>(destPixels) + y * dbpl);
238 fromX = qMax(x_l >> 16, clipLeft);
239 toX = qMin(x_r >> 16, clipLeft + clipWidth);
247 u = x1 * dudx + y * dudy + u0;
248 v = x1 * dvdx + y * dvdy + v0;
249 for (; x1 < toX; ++x1) {
252 if (uu >= sourceRectLeft && uu < sourceRectLeft + sourceRectWidth
253 && vv >= sourceRectTop && vv < sourceRectTop + sourceRectHeight) {
262 u = (x2 - 1) * dudx + y * dudy + u0;
263 v = (x2 - 1) * dvdx + y * dvdy + v0;
264 for (; x2 > x1; --x2) {
267 if (uu >= sourceRectLeft && uu < sourceRectLeft + sourceRectWidth
268 && vv >= sourceRectTop && vv < sourceRectTop + sourceRectHeight) {
276 u = fromX * dudx + y * dudy + u0;
277 v = fromX * dvdx + y * dvdy + v0;
283 qint64 uu = qBound(sourceRectLeft, u >> 16, sourceRectLeft + sourceRectWidth - 1);
284 qint64 vv = qBound(sourceRectTop, v >> 16, sourceRectTop + sourceRectHeight - 1);
285 blender.write(line,
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + vv * sbpl)[uu]);
297 blender.write(&line[0],
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
298 blender.write(&line[1],
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
299 blender.write(&line[2],
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
300 blender.write(&line[3],
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
301 blender.write(&line[4],
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
302 blender.write(&line[5],
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
303 blender.write(&line[6],
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
304 blender.write(&line[7],
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx;
311 case 7: blender.write(line,
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx; ++line; Q_FALLTHROUGH();
312 case 6: blender.write(line,
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx; ++line; Q_FALLTHROUGH();
313 case 5: blender.write(line,
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx; ++line; Q_FALLTHROUGH();
314 case 4: blender.write(line,
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx; ++line; Q_FALLTHROUGH();
315 case 3: blender.write(line,
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx; ++line; Q_FALLTHROUGH();
316 case 2: blender.write(line,
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx; ++line; Q_FALLTHROUGH();
317 case 1: blender.write(line,
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + (v >> 16) * sbpl)[u >> 16]); u += dudx; v += dvdx; ++line;
323 qint64 uu = qBound(sourceRectLeft, u >> 16, sourceRectLeft + sourceRectWidth - 1);
324 qint64 vv = qBound(sourceRectTop, v >> 16, sourceRectTop + sourceRectHeight - 1);
325 blender.write(line,
reinterpret_cast<
const SrcT *>(
reinterpret_cast<
const uchar *>(srcPixels) + vv * sbpl)[uu]);
339template <
class SrcT,
class DestT,
class Blender>
341 const SrcT *srcPixels,
int sbpl,
342 const QRectF &targetRect,
343 const QRectF &sourceRect,
345 const QTransform &targetRectTransform,
358 v[TopLeft].u = v[BottomLeft].u = sourceRect.left();
359 v[TopLeft].v = v[TopRight].v = sourceRect.top();
360 v[TopRight].u = v[BottomRight].u = sourceRect.right();
361 v[BottomLeft].v = v[BottomRight].v = sourceRect.bottom();
362 targetRectTransform.map(targetRect.left(), targetRect.top(), &v[TopLeft].x, &v[TopLeft].y);
363 targetRectTransform.map(targetRect.right(), targetRect.top(), &v[TopRight].x, &v[TopRight].y);
364 targetRectTransform.map(targetRect.left(), targetRect.bottom(), &v[BottomLeft].x, &v[BottomLeft].y);
365 targetRectTransform.map(targetRect.right(), targetRect.bottom(), &v[BottomRight].x, &v[BottomRight].y);
369 for (
int i = 1; i < 4; ++i) {
370 if (v[i].y < v[topmost].y)
378 for (
int i = 0; i < 3; ++i)
390 for (
int i = 3; i > 0; --i)
398 qreal dx1 = v[1].x - v[0].x;
399 qreal dy1 = v[1].y - v[0].y;
400 qreal dx2 = v[3].x - v[0].x;
401 qreal dy2 = v[3].y - v[0].y;
402 if (dx1 * dy2 - dx2 * dy1 > 0)
408 qreal det = u.x * w.y - u.y * w.x;
412 qreal invDet = 1.0 / det;
413 qreal m11, m12, m21, m22, mdx, mdy;
415 m11 = (u.u * w.y - u.y * w.u) * invDet;
416 m12 = (u.x * w.u - u.u * w.x) * invDet;
417 m21 = (u.v * w.y - u.y * w.v) * invDet;
418 m22 = (u.x * w.v - u.v * w.x) * invDet;
419 mdx = v[0].u - m11 * v[0].x - m12 * v[0].y;
420 mdy = v[0].v - m21 * v[0].x - m22 * v[0].y;
422 int dudx =
int(m11 * 0x10000);
423 int dvdx =
int(m21 * 0x10000);
424 int dudy =
int(m12 * 0x10000);
425 int dvdy =
int(m22 * 0x10000);
426 int u0 = qCeil((qreal(0.5) * m11 + qreal(0.5) * m12 + mdx) * 0x10000) - 1;
427 int v0 = qCeil((qreal(0.5) * m21 + qreal(0.5) * m22 + mdy) * 0x10000) - 1;
429 int x1 = qFloor(sourceRect.left());
430 int y1 = qFloor(sourceRect.top());
431 int x2 = qCeil(sourceRect.right());
432 int y2 = qCeil(sourceRect.bottom());
433 QRect sourceRectI(x1, y1, x2 - x1, y2 - y1);
436 if (v[1].y < v[3].y) {
437 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);
438 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);
439 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);
441 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);
442 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);
443 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);
Combined button and popup list for selecting options.
SrcOverScaleFunc qScaleFunctions[QImage::NImageFormats][QImage::NImageFormats]
void qt_scale_image_argb32_on_rgb16(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, int srch, const QRectF &targetRect, const QRectF &sourceRect, const QRect &clip, int const_alpha)
static void qt_blend_argb32_on_argb32(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, int w, int h, int const_alpha)
void qInitBlendFunctions()
void qt_blend_argb32_on_rgb16_const_alpha(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, int w, int h, int const_alpha)
static void qt_blend_rgb32_on_rgb16(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, int w, int h, int const_alpha)
SrcOverTransformFunc qTransformFunctions[QImage::NImageFormats][QImage::NImageFormats]
void qt_transform_image_rgb32_on_rgb32(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, const QRectF &targetRect, const QRectF &sourceRect, const QRect &clip, const QTransform &targetRectTransform, int const_alpha)
void qt_scale_image_argb32_on_argb32(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, int srch, const QRectF &targetRect, const QRectF &sourceRect, const QRect &clip, int const_alpha)
void qt_transform_image_argb32_on_argb32(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, const QRectF &targetRect, const QRectF &sourceRect, const QRect &clip, const QTransform &targetRectTransform, int const_alpha)
void qt_transform_image_rgb16_on_rgb16(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, const QRectF &targetRect, const QRectF &sourceRect, const QRect &clip, const QTransform &targetRectTransform, int const_alpha)
void qt_transform_image_argb32_on_rgb16(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, const QRectF &targetRect, const QRectF &sourceRect, const QRect &clip, const QTransform &targetRectTransform, int const_alpha)
void qt_blend_rgb32_on_rgb32(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, int w, int h, int const_alpha)
void qt_scale_image_rgb16_on_rgb16(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, int srch, const QRectF &targetRect, const QRectF &sourceRect, const QRect &clip, int const_alpha)
void qt_scale_image_rgb32_on_rgb32(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, int srch, const QRectF &targetRect, const QRectF &sourceRect, const QRect &clip, int const_alpha)
SrcOverBlendFunc qBlendFunctions[QImage::NImageFormats][QImage::NImageFormats]
void qt_blend_rgb16_on_rgb16(uchar *dst, int dbpl, const uchar *src, int sbpl, int w, int h, int const_alpha)
static void qt_blend_argb32_on_rgb16(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, int w, int h, int const_alpha)
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)
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)
void qt_scale_image_32bit(uchar *destPixels, int dbpl, const uchar *srcPixels, int sbpl, int srch, const QRectF &targetRect, const QRectF &srcRect, const QRect &clip, T blender)
void(* SrcOverBlendFunc)(uchar *destPixels, int dbpl, const uchar *src, int spbl, int w, int h, int const_alpha)
void(* SrcOverScaleFunc)(uchar *destPixels, int dbpl, const uchar *src, int spbl, int srch, const QRectF &targetRect, const QRectF &sourceRect, const QRect &clipRect, int const_alpha)
void(* SrcOverTransformFunc)(uchar *destPixels, int dbpl, const uchar *src, int spbl, const QRectF &targetRect, const QRectF &sourceRect, const QRect &clipRect, const QTransform &targetRectTransform, int const_alpha)
void write(quint32 *dst, quint32 src)
Blend_ARGB32_on_ARGB32_SourceAndConstAlpha(quint32 alpha)
void write(quint32 *dst, quint32 src)
void write(quint16 *dst, quint32 src)
Blend_ARGB32_on_RGB16_SourceAndConstAlpha(quint32 alpha)
void write(quint16 *dst, quint32 src)
void write(quint16 *dst, quint16 src)
Blend_RGB16_on_RGB16_ConstAlpha(quint32 alpha)
void write(quint16 *dst, quint16 src)
Blend_RGB32_on_RGB32_ConstAlpha(quint32 alpha)
void write(quint32 *dst, quint32 src)
void write(quint32 *dst, quint32 src)
quint16 bytemul(quint16 x) const
uchar alpha(uchar src) const
SourceAndConstAlpha(int a)
quint16 bytemul(quint16 spix) const
uchar alpha(uchar src) const