Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qimagescale_neon.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qimagescale_p.h"
5#include "qimage.h"
6#include <private/qsimd_p.h>
7
8#if QT_CONFIG(thread) && !defined(Q_OS_WASM)
9#include <qsemaphore.h>
10#include <qthreadpool.h>
11#include <private/qthreadpool_p.h>
12#endif
13
14#if defined(__ARM_NEON__)
15
17
18using namespace QImageScale;
19
20template<typename T>
21static inline void multithread_pixels_function(QImageScaleInfo *isi, int dh, const T &scaleSection)
22{
23#if QT_CONFIG(thread) && !defined(Q_OS_WASM)
24 int segments = (qsizetype(isi->sh) * isi->sw) / (1<<16);
25 segments = std::min(segments, dh);
27 if (segments > 1 && threadPool && !threadPool->contains(QThread::currentThread())) {
28 QSemaphore semaphore;
29 int y = 0;
30 for (int i = 0; i < segments; ++i) {
31 int yn = (dh - y) / (segments - i);
32 threadPool->start([&, y, yn]() {
33 scaleSection(y, y + yn);
34 semaphore.release(1);
35 });
36 y += yn;
37 }
38 semaphore.acquire(segments);
39 return;
40 }
41#endif
42 scaleSection(0, dh);
43}
44
45inline static uint32x4_t qt_qimageScaleAARGBA_helper(const unsigned int *pix, int xyap, int Cxy, int step)
46{
47 uint32x2_t vpix32 = vmov_n_u32(*pix);
48 uint16x4_t vpix16 = vget_low_u16(vmovl_u8(vreinterpret_u8_u32(vpix32)));
49 uint32x4_t vx = vmull_n_u16(vpix16, xyap);
50 int i;
51 for (i = (1 << 14) - xyap; i > Cxy; i -= Cxy) {
52 pix += step;
53 vpix32 = vmov_n_u32(*pix);
54 vpix16 = vget_low_u16(vmovl_u8(vreinterpret_u8_u32(vpix32)));
55 vx = vaddq_u32(vx, vmull_n_u16(vpix16, Cxy));
56 }
57 pix += step;
58 vpix32 = vmov_n_u32(*pix);
59 vpix16 = vget_low_u16(vmovl_u8(vreinterpret_u8_u32(vpix32)));
60 vx = vaddq_u32(vx, vmull_n_u16(vpix16, i));
61 return vx;
62}
63
64template<bool RGB>
65void qt_qimageScaleAARGBA_up_x_down_y_neon(QImageScaleInfo *isi, unsigned int *dest,
66 int dw, int dh, int dow, int sow)
67{
68 const unsigned int **ypoints = isi->ypoints;
69 int *xpoints = isi->xpoints;
70 int *xapoints = isi->xapoints;
71 int *yapoints = isi->yapoints;
72
73 /* go through every scanline in the output buffer */
74 auto scaleSection = [&] (int yStart, int yEnd) {
75 for (int y = yStart; y < yEnd; ++y) {
76 int Cy = yapoints[y] >> 16;
77 int yap = yapoints[y] & 0xffff;
78
79 unsigned int *dptr = dest + (y * dow);
80 for (int x = 0; x < dw; x++) {
81 const unsigned int *sptr = ypoints[y] + xpoints[x];
82 uint32x4_t vx = qt_qimageScaleAARGBA_helper(sptr, yap, Cy, sow);
83
84 int xap = xapoints[x];
85 if (xap > 0) {
86 uint32x4_t vr = qt_qimageScaleAARGBA_helper(sptr + 1, yap, Cy, sow);
87
88 vx = vmulq_n_u32(vx, 256 - xap);
89 vr = vmulq_n_u32(vr, xap);
90 vx = vaddq_u32(vx, vr);
91 vx = vshrq_n_u32(vx, 8);
92 }
93 vx = vshrq_n_u32(vx, 14);
94 const uint16x4_t vx16 = vmovn_u32(vx);
95 const uint8x8_t vx8 = vmovn_u16(vcombine_u16(vx16, vx16));
96 *dptr = vget_lane_u32(vreinterpret_u32_u8(vx8), 0);
97 if (RGB)
98 *dptr |= 0xff000000;
99 dptr++;
100 }
101 }
102 };
103 multithread_pixels_function(isi, dh, scaleSection);
104}
105
106template<bool RGB>
107void qt_qimageScaleAARGBA_down_x_up_y_neon(QImageScaleInfo *isi, unsigned int *dest,
108 int dw, int dh, int dow, int sow)
109{
110 const unsigned int **ypoints = isi->ypoints;
111 int *xpoints = isi->xpoints;
112 int *xapoints = isi->xapoints;
113 int *yapoints = isi->yapoints;
114
115 /* go through every scanline in the output buffer */
116 auto scaleSection = [&] (int yStart, int yEnd) {
117 for (int y = yStart; y < yEnd; ++y) {
118 unsigned int *dptr = dest + (y * dow);
119 for (int x = 0; x < dw; x++) {
120 int Cx = xapoints[x] >> 16;
121 int xap = xapoints[x] & 0xffff;
122
123 const unsigned int *sptr = ypoints[y] + xpoints[x];
124 uint32x4_t vx = qt_qimageScaleAARGBA_helper(sptr, xap, Cx, 1);
125
126 int yap = yapoints[y];
127 if (yap > 0) {
128 uint32x4_t vr = qt_qimageScaleAARGBA_helper(sptr + sow, xap, Cx, 1);
129
130 vx = vmulq_n_u32(vx, 256 - yap);
131 vr = vmulq_n_u32(vr, yap);
132 vx = vaddq_u32(vx, vr);
133 vx = vshrq_n_u32(vx, 8);
134 }
135 vx = vshrq_n_u32(vx, 14);
136 const uint16x4_t vx16 = vmovn_u32(vx);
137 const uint8x8_t vx8 = vmovn_u16(vcombine_u16(vx16, vx16));
138 *dptr = vget_lane_u32(vreinterpret_u32_u8(vx8), 0);
139 if (RGB)
140 *dptr |= 0xff000000;
141 dptr++;
142 }
143 }
144 };
145 multithread_pixels_function(isi, dh, scaleSection);
146}
147
148template<bool RGB>
149void qt_qimageScaleAARGBA_down_xy_neon(QImageScaleInfo *isi, unsigned int *dest,
150 int dw, int dh, int dow, int sow)
151{
152 const unsigned int **ypoints = isi->ypoints;
153 int *xpoints = isi->xpoints;
154 int *xapoints = isi->xapoints;
155 int *yapoints = isi->yapoints;
156
157 auto scaleSection = [&] (int yStart, int yEnd) {
158 for (int y = yStart; y < yEnd; ++y) {
159 int Cy = yapoints[y] >> 16;
160 int yap = yapoints[y] & 0xffff;
161
162 unsigned int *dptr = dest + (y * dow);
163 for (int x = 0; x < dw; x++) {
164 const int Cx = xapoints[x] >> 16;
165 const int xap = xapoints[x] & 0xffff;
166
167 const unsigned int *sptr = ypoints[y] + xpoints[x];
168 uint32x4_t vx = qt_qimageScaleAARGBA_helper(sptr, xap, Cx, 1);
169 vx = vshrq_n_u32(vx, 4);
170 uint32x4_t vr = vmulq_n_u32(vx, yap);
171
172 int j;
173 for (j = (1 << 14) - yap; j > Cy; j -= Cy) {
174 sptr += sow;
175 vx = qt_qimageScaleAARGBA_helper(sptr, xap, Cx, 1);
176 vx = vshrq_n_u32(vx, 4);
177 vx = vmulq_n_u32(vx, Cy);
178 vr = vaddq_u32(vr, vx);
179 }
180 sptr += sow;
181 vx = qt_qimageScaleAARGBA_helper(sptr, xap, Cx, 1);
182 vx = vshrq_n_u32(vx, 4);
183 vx = vmulq_n_u32(vx, j);
184 vr = vaddq_u32(vr, vx);
185
186 vx = vshrq_n_u32(vr, 24);
187 const uint16x4_t vx16 = vmovn_u32(vx);
188 const uint8x8_t vx8 = vmovn_u16(vcombine_u16(vx16, vx16));
189 *dptr = vget_lane_u32(vreinterpret_u32_u8(vx8), 0);
190 if (RGB)
191 *dptr |= 0xff000000;
192 dptr++;
193 }
194 }
195 };
196 multithread_pixels_function(isi, dh, scaleSection);
197}
198
199template void qt_qimageScaleAARGBA_up_x_down_y_neon<false>(QImageScaleInfo *isi, unsigned int *dest,
200 int dw, int dh, int dow, int sow);
201
202template void qt_qimageScaleAARGBA_up_x_down_y_neon<true>(QImageScaleInfo *isi, unsigned int *dest,
203 int dw, int dh, int dow, int sow);
204
205template void qt_qimageScaleAARGBA_down_x_up_y_neon<false>(QImageScaleInfo *isi, unsigned int *dest,
206 int dw, int dh, int dow, int sow);
207
208template void qt_qimageScaleAARGBA_down_x_up_y_neon<true>(QImageScaleInfo *isi, unsigned int *dest,
209 int dw, int dh, int dow, int sow);
210
211template void qt_qimageScaleAARGBA_down_xy_neon<false>(QImageScaleInfo *isi, unsigned int *dest,
212 int dw, int dh, int dow, int sow);
213
214template void qt_qimageScaleAARGBA_down_xy_neon<true>(QImageScaleInfo *isi, unsigned int *dest,
215 int dw, int dh, int dow, int sow);
216
218
219#endif
\inmodule QtCore
Definition qsemaphore.h:18
void acquire(int n=1)
Tries to acquire n resources guarded by the semaphore.
void release(int n=1)
Releases n resources guarded by the semaphore.
static QThreadPool * qtGuiInstance()
Returns the QThreadPool instance for Qt Gui.
\inmodule QtCore
Definition qthreadpool.h:22
void start(QRunnable *runnable, int priority=0)
Reserves a thread and uses it to run runnable, unless this thread will make the current thread count ...
bool contains(const QThread *thread) const
static QThread * currentThread()
Definition qthread.cpp:1039
QPixmap pix
Combined button and popup list for selecting options.
static void multithread_pixels_function(QImageScaleInfo *isi, int dh, const T &scaleSection)
static void qt_qimageScaleAARGBA_helper(const unsigned int *pix, int xyap, int Cxy, int step, int &r, int &g, int &b, int &a)
GLint GLint GLint GLint GLint x
[0]
GLint y
GLuint segments
ptrdiff_t qsizetype
Definition qtypes.h:165