| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/image/qimage.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||||||||
| 5 | - | |||||||||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||||||||
| 7 | - | |||||||||||||||||||||||||||||||
| 8 | - | |||||||||||||||||||||||||||||||
| 9 | static inline bool isLocked(QImageData *data) | - | ||||||||||||||||||||||||||||||
| 10 | { | - | ||||||||||||||||||||||||||||||
| 11 | return data != 0 && data->is_locked; | - | ||||||||||||||||||||||||||||||
| 12 | } | - | ||||||||||||||||||||||||||||||
| 13 | static QImage rotated90(const QImage &src); | - | ||||||||||||||||||||||||||||||
| 14 | static QImage rotated180(const QImage &src); | - | ||||||||||||||||||||||||||||||
| 15 | static QImage rotated270(const QImage &src); | - | ||||||||||||||||||||||||||||||
| 16 | - | |||||||||||||||||||||||||||||||
| 17 | QBasicAtomicInt qimage_serial_number = { 1 }; | - | ||||||||||||||||||||||||||||||
| 18 | - | |||||||||||||||||||||||||||||||
| 19 | QImageData::QImageData() | - | ||||||||||||||||||||||||||||||
| 20 | : ref(0), width(0), height(0), depth(0), nbytes(0), devicePixelRatio(1.0), data(0), | - | ||||||||||||||||||||||||||||||
| 21 | format(QImage::Format_ARGB32), bytes_per_line(0), | - | ||||||||||||||||||||||||||||||
| 22 | ser_no(qimage_serial_number.fetchAndAddRelaxed(1)), | - | ||||||||||||||||||||||||||||||
| 23 | detach_no(0), | - | ||||||||||||||||||||||||||||||
| 24 | dpmx(qt_defaultDpiX() * 100 / qreal(2.54)), | - | ||||||||||||||||||||||||||||||
| 25 | dpmy(qt_defaultDpiY() * 100 / qreal(2.54)), | - | ||||||||||||||||||||||||||||||
| 26 | offset(0, 0), own_data(true), ro_data(false), has_alpha_clut(false), | - | ||||||||||||||||||||||||||||||
| 27 | is_cached(false), is_locked(false), cleanupFunction(0), cleanupInfo(0), | - | ||||||||||||||||||||||||||||||
| 28 | paintEngine(0) | - | ||||||||||||||||||||||||||||||
| 29 | { | - | ||||||||||||||||||||||||||||||
| 30 | } | - | ||||||||||||||||||||||||||||||
| 31 | QImageData * QImageData::create(const QSize &size, QImage::Format format) | - | ||||||||||||||||||||||||||||||
| 32 | { | - | ||||||||||||||||||||||||||||||
| 33 | if (!size.isValid() || format == QImage::Format_Invalid) | - | ||||||||||||||||||||||||||||||
| 34 | return 0; | - | ||||||||||||||||||||||||||||||
| 35 | - | |||||||||||||||||||||||||||||||
| 36 | uint width = size.width(); | - | ||||||||||||||||||||||||||||||
| 37 | uint height = size.height(); | - | ||||||||||||||||||||||||||||||
| 38 | uint depth = qt_depthForFormat(format); | - | ||||||||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||||||||
| 40 | const int bytes_per_line = ((width * depth + 31) >> 5) << 2; | - | ||||||||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||||||||
| 42 | - | |||||||||||||||||||||||||||||||
| 43 | if (2147483647/depth < width | - | ||||||||||||||||||||||||||||||
| 44 | || bytes_per_line <= 0 | - | ||||||||||||||||||||||||||||||
| 45 | || height <= 0 | - | ||||||||||||||||||||||||||||||
| 46 | || 2147483647/uint(bytes_per_line) < height | - | ||||||||||||||||||||||||||||||
| 47 | || 2147483647/sizeof(uchar *) < uint(height)) | - | ||||||||||||||||||||||||||||||
| 48 | return 0; | - | ||||||||||||||||||||||||||||||
| 49 | - | |||||||||||||||||||||||||||||||
| 50 | QScopedPointer<QImageData> d(new QImageData); | - | ||||||||||||||||||||||||||||||
| 51 | - | |||||||||||||||||||||||||||||||
| 52 | switch (format) { | - | ||||||||||||||||||||||||||||||
| 53 | case QImage::Format_Mono: | - | ||||||||||||||||||||||||||||||
| 54 | case QImage::Format_MonoLSB: | - | ||||||||||||||||||||||||||||||
| 55 | d->colortable.resize(2); | - | ||||||||||||||||||||||||||||||
| 56 | d->colortable[0] = QColor(Qt::black).rgba(); | - | ||||||||||||||||||||||||||||||
| 57 | d->colortable[1] = QColor(Qt::white).rgba(); | - | ||||||||||||||||||||||||||||||
| 58 | break; | - | ||||||||||||||||||||||||||||||
| 59 | default: | - | ||||||||||||||||||||||||||||||
| 60 | break; | - | ||||||||||||||||||||||||||||||
| 61 | } | - | ||||||||||||||||||||||||||||||
| 62 | - | |||||||||||||||||||||||||||||||
| 63 | d->width = width; | - | ||||||||||||||||||||||||||||||
| 64 | d->height = height; | - | ||||||||||||||||||||||||||||||
| 65 | d->depth = depth; | - | ||||||||||||||||||||||||||||||
| 66 | d->format = format; | - | ||||||||||||||||||||||||||||||
| 67 | d->has_alpha_clut = false; | - | ||||||||||||||||||||||||||||||
| 68 | d->is_cached = false; | - | ||||||||||||||||||||||||||||||
| 69 | - | |||||||||||||||||||||||||||||||
| 70 | d->bytes_per_line = bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||||||||
| 72 | d->nbytes = d->bytes_per_line*height; | - | ||||||||||||||||||||||||||||||
| 73 | d->data = (uchar *)malloc(d->nbytes); | - | ||||||||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||||||||
| 75 | if (!d->data) { | - | ||||||||||||||||||||||||||||||
| 76 | return 0; | - | ||||||||||||||||||||||||||||||
| 77 | } | - | ||||||||||||||||||||||||||||||
| 78 | - | |||||||||||||||||||||||||||||||
| 79 | d->ref.ref(); | - | ||||||||||||||||||||||||||||||
| 80 | return d.take(); | - | ||||||||||||||||||||||||||||||
| 81 | - | |||||||||||||||||||||||||||||||
| 82 | } | - | ||||||||||||||||||||||||||||||
| 83 | - | |||||||||||||||||||||||||||||||
| 84 | QImageData::~QImageData() | - | ||||||||||||||||||||||||||||||
| 85 | { | - | ||||||||||||||||||||||||||||||
| 86 | if (cleanupFunction) | - | ||||||||||||||||||||||||||||||
| 87 | cleanupFunction(cleanupInfo); | - | ||||||||||||||||||||||||||||||
| 88 | if (is_cached) | - | ||||||||||||||||||||||||||||||
| 89 | QImagePixmapCleanupHooks::executeImageHooks((((qint64) ser_no) << 32) | ((qint64) detach_no)); | - | ||||||||||||||||||||||||||||||
| 90 | delete paintEngine; | - | ||||||||||||||||||||||||||||||
| 91 | if (data && own_data) | - | ||||||||||||||||||||||||||||||
| 92 | free(data); | - | ||||||||||||||||||||||||||||||
| 93 | data = 0; | - | ||||||||||||||||||||||||||||||
| 94 | } | - | ||||||||||||||||||||||||||||||
| 95 | - | |||||||||||||||||||||||||||||||
| 96 | - | |||||||||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||||||||
| 99 | - | |||||||||||||||||||||||||||||||
| 100 | bool QImageData::checkForAlphaPixels() const | - | ||||||||||||||||||||||||||||||
| 101 | { | - | ||||||||||||||||||||||||||||||
| 102 | bool has_alpha_pixels = false; | - | ||||||||||||||||||||||||||||||
| 103 | - | |||||||||||||||||||||||||||||||
| 104 | switch (format) { | - | ||||||||||||||||||||||||||||||
| 105 | - | |||||||||||||||||||||||||||||||
| 106 | case never executed: QImage::Format_Mono:case QImage::Format_Mono:never executed: case QImage::Format_Mono: | 0 | ||||||||||||||||||||||||||||||
| 107 | case never executed: QImage::Format_MonoLSB:case QImage::Format_MonoLSB:never executed: case QImage::Format_MonoLSB: | 0 | ||||||||||||||||||||||||||||||
| 108 | case never executed: QImage::Format_Indexed8:case QImage::Format_Indexed8:never executed: case QImage::Format_Indexed8: | 0 | ||||||||||||||||||||||||||||||
| 109 | has_alpha_pixels = has_alpha_clut; | - | ||||||||||||||||||||||||||||||
| 110 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 111 | case never executed: QImage::Format_Alpha8:case QImage::Format_Alpha8:never executed: case QImage::Format_Alpha8: | 0 | ||||||||||||||||||||||||||||||
| 112 | has_alpha_pixels = true; | - | ||||||||||||||||||||||||||||||
| 113 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 114 | case never executed: QImage::Format_ARGB32:case QImage::Format_ARGB32:never executed: case QImage::Format_ARGB32: | 0 | ||||||||||||||||||||||||||||||
| 115 | case never executed: QImage::Format_ARGB32_Premultiplied:case QImage::Format_ARGB32_Premultiplied:never executed: {case QImage::Format_ARGB32_Premultiplied: | 0 | ||||||||||||||||||||||||||||||
| 116 | const uchar *bits = data; | - | ||||||||||||||||||||||||||||||
| 117 | for (int y=0; y<height
| 0 | ||||||||||||||||||||||||||||||
| 118 | uint alphaAnd = 0xff000000; | - | ||||||||||||||||||||||||||||||
| 119 | for (int x=0; x<width
| 0 | ||||||||||||||||||||||||||||||
| 120 | has_alpha_pixels |alphaAnd & never executed: = (((reinterpret_cast<const uint*)*>(bits)[x] & 0xff000000)];alphaAnd &= reinterpret_cast<const uint*>(bits)[x];never executed: alphaAnd &= reinterpret_cast<const uint*>(bits)[x]; | 0 | ||||||||||||||||||||||||||||||
| 121 | has_alpha_pixels = (alphaAnd != 0xff000000;); | - | ||||||||||||||||||||||||||||||
| 122 | bits += bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 123 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 124 | } break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 125 | - | |||||||||||||||||||||||||||||||
| 126 | case never executed: QImage::Format_RGBA8888:case QImage::Format_RGBA8888:never executed: case QImage::Format_RGBA8888: | 0 | ||||||||||||||||||||||||||||||
| 127 | case never executed: QImage::Format_RGBA8888_Premultiplied:case QImage::Format_RGBA8888_Premultiplied:never executed: {case QImage::Format_RGBA8888_Premultiplied: | 0 | ||||||||||||||||||||||||||||||
| 128 | const uchar *bits = data; | - | ||||||||||||||||||||||||||||||
| 129 | for (int y=0; y<height
| 0 | ||||||||||||||||||||||||||||||
| 130 | uchar alphaAnd = 0xff; | - | ||||||||||||||||||||||||||||||
| 131 | for (int x=0; x<width
| 0 | ||||||||||||||||||||||||||||||
| 132 | has_alpha_pixels |alphaAnd & never executed: = bits[x * 4+ 3]];alphaAnd &= bits[x * 4+ 3];never executed: alphaAnd &= bits[x * 4+ 3]; | 0 | ||||||||||||||||||||||||||||||
| 133 | has_alpha_pixels = (alphaAnd != 0xff;); | - | ||||||||||||||||||||||||||||||
| 134 | bits += bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 135 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 136 | } break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 137 | - | |||||||||||||||||||||||||||||||
| 138 | case never executed: QImage::Format_A2BGR30_Premultiplied:case QImage::Format_A2BGR30_Premultiplied:never executed: case QImage::Format_A2BGR30_Premultiplied: | 0 | ||||||||||||||||||||||||||||||
| 139 | case never executed: QImage::Format_A2RGB30_Premultiplied:case QImage::Format_A2RGB30_Premultiplied:never executed: {case QImage::Format_A2RGB30_Premultiplied: | 0 | ||||||||||||||||||||||||||||||
| 140 | const uchar *bits = data; | - | ||||||||||||||||||||||||||||||
| 141 | for (int y=0; y<height
| 0 | ||||||||||||||||||||||||||||||
| 142 | uint alphaAnd = 0xc0000000; | - | ||||||||||||||||||||||||||||||
| 143 | for (int x=0; x<width
| 0 | ||||||||||||||||||||||||||||||
| 144 | has_alpha_pixels |alphaAnd & never executed: = (((reinterpret_cast<const uint*)*>(bits)[x] & 0xc0000000)];alphaAnd &= reinterpret_cast<const uint*>(bits)[x];never executed: alphaAnd &= reinterpret_cast<const uint*>(bits)[x]; | 0 | ||||||||||||||||||||||||||||||
| 145 | has_alpha_pixels = (alphaAnd != 0xc0000000;); | - | ||||||||||||||||||||||||||||||
| 146 | bits += bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 147 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 148 | } break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 149 | - | |||||||||||||||||||||||||||||||
| 150 | case never executed: QImage::Format_ARGB8555_Premultiplied:case QImage::Format_ARGB8555_Premultiplied:never executed: case QImage::Format_ARGB8555_Premultiplied: | 0 | ||||||||||||||||||||||||||||||
| 151 | case never executed: QImage::Format_ARGB8565_Premultiplied:case QImage::Format_ARGB8565_Premultiplied:never executed: {case QImage::Format_ARGB8565_Premultiplied: | 0 | ||||||||||||||||||||||||||||||
| 152 | const uchar *bits = data; | - | ||||||||||||||||||||||||||||||
| 153 | const uchar *end_bits = data + bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 154 | - | |||||||||||||||||||||||||||||||
| 155 | for (int y=0; y<height
| 0 | ||||||||||||||||||||||||||||||
| 156 | uchar alphaAnd = 0xff; | - | ||||||||||||||||||||||||||||||
| 157 | while (bits < end_bits
| 0 | ||||||||||||||||||||||||||||||
| 158 | has_alpha_pixels |alphaAnd &= bits[0] !=0;]; | - | ||||||||||||||||||||||||||||||
| 159 | bits += 3; | - | ||||||||||||||||||||||||||||||
| 160 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 161 | has_alpha_pixels = (alphaAnd != 0xff); | - | ||||||||||||||||||||||||||||||
| 162 | bits = end_bits; | - | ||||||||||||||||||||||||||||||
| 163 | end_bits += bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 164 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 165 | } break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 166 | - | |||||||||||||||||||||||||||||||
| 167 | case never executed: QImage::Format_ARGB6666_Premultiplied:case QImage::Format_ARGB6666_Premultiplied:never executed: {case QImage::Format_ARGB6666_Premultiplied: | 0 | ||||||||||||||||||||||||||||||
| 168 | const uchar *bits = data; | - | ||||||||||||||||||||||||||||||
| 169 | const uchar *end_bits = data + bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 170 | - | |||||||||||||||||||||||||||||||
| 171 | for (int y=0; y<height
| 0 | ||||||||||||||||||||||||||||||
| 172 | uchar alphaAnd = 0xfc; | - | ||||||||||||||||||||||||||||||
| 173 | while (bits < end_bits
| 0 | ||||||||||||||||||||||||||||||
| 174 | has_alpha_pixels |alphaAnd &= (bits[0] & 0xfc) !=0;]; | - | ||||||||||||||||||||||||||||||
| 175 | bits += 3; | - | ||||||||||||||||||||||||||||||
| 176 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 177 | has_alpha_pixels = (alphaAnd != 0xfc); | - | ||||||||||||||||||||||||||||||
| 178 | bits = end_bits; | - | ||||||||||||||||||||||||||||||
| 179 | end_bits += bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 180 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 181 | } break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 182 | - | |||||||||||||||||||||||||||||||
| 183 | case never executed: QImage::Format_ARGB4444_Premultiplied:case QImage::Format_ARGB4444_Premultiplied:never executed: {case QImage::Format_ARGB4444_Premultiplied: | 0 | ||||||||||||||||||||||||||||||
| 184 | const uchar *bits = data; | - | ||||||||||||||||||||||||||||||
| uchar *end_bits= data+ bytes_per_line; | ||||||||||||||||||||||||||||||||
| 185 | for (int y=0; y<height
| 0 | ||||||||||||||||||||||||||||||
| 186 | whileushort alphaAnd = 0xf000; | - | ||||||||||||||||||||||||||||||
| 187 | for (bitsint x=0; x
| 0 | ||||||||||||||||||||||||||||||
| 188 | {alphaAnd &= reinterpret_cast<const ushort*>(bits)[x]; never executed: alphaAnd &= reinterpret_cast<const ushort*>(bits)[x]; | 0 | ||||||||||||||||||||||||||||||
| 189 | has_alpha_pixels |= (bits[0] & 0xf0)alphaAnd != 0; | - | ||||||||||||||||||||||||||||||
| bits += 2; | ||||||||||||||||||||||||||||||||
| }0xf000); | ||||||||||||||||||||||||||||||||
| 190 | bits = end_bits; | - | ||||||||||||||||||||||||||||||
| end_bits+= bytes_per_line; | ||||||||||||||||||||||||||||||||
| 191 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 192 | } break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 193 | - | |||||||||||||||||||||||||||||||
| 194 | case never executed: QImage::Format_RGB32:case QImage::Format_RGB32:never executed: case QImage::Format_RGB32: | 0 | ||||||||||||||||||||||||||||||
| 195 | case never executed: QImage::Format_RGB16:case QImage::Format_RGB16:never executed: case QImage::Format_RGB16: | 0 | ||||||||||||||||||||||||||||||
| 196 | case never executed: QImage::Format_RGB444:case QImage::Format_RGB444:never executed: case QImage::Format_RGB444: | 0 | ||||||||||||||||||||||||||||||
| 197 | case never executed: QImage::Format_RGB555:case QImage::Format_RGB555:never executed: case QImage::Format_RGB555: | 0 | ||||||||||||||||||||||||||||||
| 198 | case never executed: QImage::Format_RGB666:case QImage::Format_RGB666:never executed: case QImage::Format_RGB666: | 0 | ||||||||||||||||||||||||||||||
| 199 | case never executed: QImage::Format_RGB888:case QImage::Format_RGB888:never executed: case QImage::Format_RGB888: | 0 | ||||||||||||||||||||||||||||||
| 200 | case never executed: QImage::Format_RGBX8888:case QImage::Format_RGBX8888:never executed: case QImage::Format_RGBX8888: | 0 | ||||||||||||||||||||||||||||||
| 201 | case never executed: QImage::Format_BGR30:case QImage::Format_BGR30:never executed: case QImage::Format_BGR30: | 0 | ||||||||||||||||||||||||||||||
| 202 | case never executed: QImage::Format_RGB30:case QImage::Format_RGB30:never executed: case QImage::Format_RGB30: | 0 | ||||||||||||||||||||||||||||||
| 203 | case never executed: QImage::Format_Grayscale8:case QImage::Format_Grayscale8:never executed: case QImage::Format_Grayscale8: | 0 | ||||||||||||||||||||||||||||||
| 204 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 205 | case never executed: QImage::Format_Invalid:case QImage::Format_Invalid:never executed: case QImage::Format_Invalid: | 0 | ||||||||||||||||||||||||||||||
| 206 | case never executed: QImage::NImageFormats:case QImage::NImageFormats:never executed: case QImage::NImageFormats: | 0 | ||||||||||||||||||||||||||||||
| 207 | do { ((!(false)) ? qt_assert_x("Q_UNREACHABLE()", "Q_UNREACHABLE was reached",__FILE__,277290) : qt_noop()); __builtin_unreachable(); } while (0); | - | ||||||||||||||||||||||||||||||
| 208 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 209 | } | - | ||||||||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||||||||
| 211 | return never executed: has_alpha_pixels;return has_alpha_pixels;never executed: return has_alpha_pixels; | 0 | ||||||||||||||||||||||||||||||
| 212 | } | - | ||||||||||||||||||||||||||||||
| 213 | QImage::QImage() noexcept | - | ||||||||||||||||||||||||||||||
| 214 | : QPaintDevice() | - | ||||||||||||||||||||||||||||||
| 215 | { | - | ||||||||||||||||||||||||||||||
| 216 | d = 0; | - | ||||||||||||||||||||||||||||||
| 217 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 218 | QImage::QImage(int width, int height, Format format) | - | ||||||||||||||||||||||||||||||
| 219 | : QPaintDevice() | - | ||||||||||||||||||||||||||||||
| 220 | { | - | ||||||||||||||||||||||||||||||
| 221 | d = QImageData::create(QSize(width, height), format); | - | ||||||||||||||||||||||||||||||
| 222 | } | - | ||||||||||||||||||||||||||||||
| 223 | QImage::QImage(const QSize &size, Format format) | - | ||||||||||||||||||||||||||||||
| 224 | : QPaintDevice() | - | ||||||||||||||||||||||||||||||
| 225 | { | - | ||||||||||||||||||||||||||||||
| 226 | d = QImageData::create(size, format); | - | ||||||||||||||||||||||||||||||
| 227 | } | - | ||||||||||||||||||||||||||||||
| 228 | - | |||||||||||||||||||||||||||||||
| 229 | - | |||||||||||||||||||||||||||||||
| 230 | - | |||||||||||||||||||||||||||||||
| 231 | QImageData *QImageData::create(uchar *data, int width, int height, int bpl, QImage::Format format, bool readOnly, QImageCleanupFunction cleanupFunction, void *cleanupInfo) | - | ||||||||||||||||||||||||||||||
| 232 | { | - | ||||||||||||||||||||||||||||||
| 233 | QImageData *d = 0; | - | ||||||||||||||||||||||||||||||
| 234 | - | |||||||||||||||||||||||||||||||
| 235 | if (format == QImage::Format_Invalid) | - | ||||||||||||||||||||||||||||||
| 236 | return d; | - | ||||||||||||||||||||||||||||||
| 237 | - | |||||||||||||||||||||||||||||||
| 238 | const int depth = qt_depthForFormat(format); | - | ||||||||||||||||||||||||||||||
| 239 | const int calc_bytes_per_line = ((width * depth + 31)/32) * 4; | - | ||||||||||||||||||||||||||||||
| 240 | const int min_bytes_per_line = (width * depth + 7)/8; | - | ||||||||||||||||||||||||||||||
| 241 | - | |||||||||||||||||||||||||||||||
| 242 | if (bpl <= 0) | - | ||||||||||||||||||||||||||||||
| 243 | bpl = calc_bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 244 | - | |||||||||||||||||||||||||||||||
| 245 | if (width <= 0 || height <= 0 || !data | - | ||||||||||||||||||||||||||||||
| 246 | || 2147483647/sizeof(uchar *) < uint(height) | - | ||||||||||||||||||||||||||||||
| 247 | || 2147483647/uint(depth) < uint(width) | - | ||||||||||||||||||||||||||||||
| 248 | || bpl <= 0 | - | ||||||||||||||||||||||||||||||
| 249 | || bpl < min_bytes_per_line | - | ||||||||||||||||||||||||||||||
| 250 | || 2147483647/uint(bpl) < uint(height)) | - | ||||||||||||||||||||||||||||||
| 251 | return d; | - | ||||||||||||||||||||||||||||||
| 252 | - | |||||||||||||||||||||||||||||||
| 253 | d = new QImageData; | - | ||||||||||||||||||||||||||||||
| 254 | d->ref.ref(); | - | ||||||||||||||||||||||||||||||
| 255 | - | |||||||||||||||||||||||||||||||
| 256 | d->own_data = false; | - | ||||||||||||||||||||||||||||||
| 257 | d->ro_data = readOnly; | - | ||||||||||||||||||||||||||||||
| 258 | d->data = data; | - | ||||||||||||||||||||||||||||||
| 259 | d->width = width; | - | ||||||||||||||||||||||||||||||
| 260 | d->height = height; | - | ||||||||||||||||||||||||||||||
| 261 | d->depth = depth; | - | ||||||||||||||||||||||||||||||
| 262 | d->format = format; | - | ||||||||||||||||||||||||||||||
| 263 | - | |||||||||||||||||||||||||||||||
| 264 | d->bytes_per_line = bpl; | - | ||||||||||||||||||||||||||||||
| 265 | d->nbytes = d->bytes_per_line * height; | - | ||||||||||||||||||||||||||||||
| 266 | - | |||||||||||||||||||||||||||||||
| 267 | d->cleanupFunction = cleanupFunction; | - | ||||||||||||||||||||||||||||||
| 268 | d->cleanupInfo = cleanupInfo; | - | ||||||||||||||||||||||||||||||
| 269 | - | |||||||||||||||||||||||||||||||
| 270 | return d; | - | ||||||||||||||||||||||||||||||
| 271 | } | - | ||||||||||||||||||||||||||||||
| 272 | QImage::QImage(uchar* data, int width, int height, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) | - | ||||||||||||||||||||||||||||||
| 273 | : QPaintDevice() | - | ||||||||||||||||||||||||||||||
| 274 | { | - | ||||||||||||||||||||||||||||||
| 275 | d = QImageData::create(data, width, height, 0, format, false, cleanupFunction, cleanupInfo); | - | ||||||||||||||||||||||||||||||
| 276 | } | - | ||||||||||||||||||||||||||||||
| 277 | QImage::QImage(const uchar* data, int width, int height, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) | - | ||||||||||||||||||||||||||||||
| 278 | : QPaintDevice() | - | ||||||||||||||||||||||||||||||
| 279 | { | - | ||||||||||||||||||||||||||||||
| 280 | d = QImageData::create(const_cast<uchar*>(data), width, height, 0, format, true, cleanupFunction, cleanupInfo); | - | ||||||||||||||||||||||||||||||
| 281 | } | - | ||||||||||||||||||||||||||||||
| 282 | QImage::QImage(uchar *data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) | - | ||||||||||||||||||||||||||||||
| 283 | :QPaintDevice() | - | ||||||||||||||||||||||||||||||
| 284 | { | - | ||||||||||||||||||||||||||||||
| 285 | d = QImageData::create(data, width, height, bytesPerLine, format, false, cleanupFunction, cleanupInfo); | - | ||||||||||||||||||||||||||||||
| 286 | } | - | ||||||||||||||||||||||||||||||
| 287 | QImage::QImage(const uchar *data, int width, int height, int bytesPerLine, Format format, QImageCleanupFunction cleanupFunction, void *cleanupInfo) | - | ||||||||||||||||||||||||||||||
| 288 | :QPaintDevice() | - | ||||||||||||||||||||||||||||||
| 289 | { | - | ||||||||||||||||||||||||||||||
| 290 | d = QImageData::create(const_cast<uchar*>(data), width, height, bytesPerLine, format, true, cleanupFunction, cleanupInfo); | - | ||||||||||||||||||||||||||||||
| 291 | } | - | ||||||||||||||||||||||||||||||
| 292 | QImage::QImage(const QString &fileName, const char *format) | - | ||||||||||||||||||||||||||||||
| 293 | : QPaintDevice() | - | ||||||||||||||||||||||||||||||
| 294 | { | - | ||||||||||||||||||||||||||||||
| 295 | d = 0; | - | ||||||||||||||||||||||||||||||
| 296 | load(fileName, format); | - | ||||||||||||||||||||||||||||||
| 297 | } | - | ||||||||||||||||||||||||||||||
| 298 | - | |||||||||||||||||||||||||||||||
| 299 | - | |||||||||||||||||||||||||||||||
| 300 | extern bool qt_read_xpm_image_or_array(QIODevice *device, const char * const *source, QImage &image); | - | ||||||||||||||||||||||||||||||
| 301 | QImage::QImage(const char * const xpm[]) | - | ||||||||||||||||||||||||||||||
| 302 | : QPaintDevice() | - | ||||||||||||||||||||||||||||||
| 303 | { | - | ||||||||||||||||||||||||||||||
| 304 | d = 0; | - | ||||||||||||||||||||||||||||||
| 305 | if (!xpm) | - | ||||||||||||||||||||||||||||||
| 306 | return; | - | ||||||||||||||||||||||||||||||
| 307 | if (!qt_read_xpm_image_or_array(0, xpm, *this)) | - | ||||||||||||||||||||||||||||||
| 308 | - | |||||||||||||||||||||||||||||||
| 309 | QMessageLogger(__FILE__, 9961009, __PRETTY_FUNCTION__).warning("QImage::QImage(), XPM is not supported"); | - | ||||||||||||||||||||||||||||||
| 310 | } | - | ||||||||||||||||||||||||||||||
| 311 | QImage::QImage(const QImage &image) | - | ||||||||||||||||||||||||||||||
| 312 | : QPaintDevice() | - | ||||||||||||||||||||||||||||||
| 313 | { | - | ||||||||||||||||||||||||||||||
| 314 | if (image.paintingActive() || isLocked(image.d)) { | - | ||||||||||||||||||||||||||||||
| 315 | d = 0; | - | ||||||||||||||||||||||||||||||
| 316 | image.copy().swap(*this); | - | ||||||||||||||||||||||||||||||
| 317 | } else { | - | ||||||||||||||||||||||||||||||
| 318 | d = image.d; | - | ||||||||||||||||||||||||||||||
| 319 | if (d) | - | ||||||||||||||||||||||||||||||
| 320 | d->ref.ref(); | - | ||||||||||||||||||||||||||||||
| 321 | } | - | ||||||||||||||||||||||||||||||
| 322 | } | - | ||||||||||||||||||||||||||||||
| 323 | - | |||||||||||||||||||||||||||||||
| 324 | - | |||||||||||||||||||||||||||||||
| 325 | - | |||||||||||||||||||||||||||||||
| 326 | - | |||||||||||||||||||||||||||||||
| 327 | - | |||||||||||||||||||||||||||||||
| 328 | QImage::~QImage() | - | ||||||||||||||||||||||||||||||
| 329 | { | - | ||||||||||||||||||||||||||||||
| 330 | if (d && !d->ref.deref()) | - | ||||||||||||||||||||||||||||||
| 331 | delete d; | - | ||||||||||||||||||||||||||||||
| 332 | } | - | ||||||||||||||||||||||||||||||
| 333 | QImage &QImage::operator=(const QImage &image) | - | ||||||||||||||||||||||||||||||
| 334 | { | - | ||||||||||||||||||||||||||||||
| 335 | if (image.paintingActive() || isLocked(image.d)) { | - | ||||||||||||||||||||||||||||||
| 336 | operator=(image.copy()); | - | ||||||||||||||||||||||||||||||
| 337 | } else { | - | ||||||||||||||||||||||||||||||
| 338 | if (image.d) | - | ||||||||||||||||||||||||||||||
| 339 | image.d->ref.ref(); | - | ||||||||||||||||||||||||||||||
| 340 | if (d && !d->ref.deref()) | - | ||||||||||||||||||||||||||||||
| 341 | delete d; | - | ||||||||||||||||||||||||||||||
| 342 | d = image.d; | - | ||||||||||||||||||||||||||||||
| 343 | } | - | ||||||||||||||||||||||||||||||
| 344 | return *this; | - | ||||||||||||||||||||||||||||||
| 345 | } | - | ||||||||||||||||||||||||||||||
| 346 | int QImage::devType() const | - | ||||||||||||||||||||||||||||||
| 347 | { | - | ||||||||||||||||||||||||||||||
| 348 | return QInternal::Image; | - | ||||||||||||||||||||||||||||||
| 349 | } | - | ||||||||||||||||||||||||||||||
| 350 | - | |||||||||||||||||||||||||||||||
| 351 | - | |||||||||||||||||||||||||||||||
| 352 | - | |||||||||||||||||||||||||||||||
| 353 | - | |||||||||||||||||||||||||||||||
| 354 | QImage::operator QVariant() const | - | ||||||||||||||||||||||||||||||
| 355 | { | - | ||||||||||||||||||||||||||||||
| 356 | return QVariant(QVariant::Image, this); | - | ||||||||||||||||||||||||||||||
| 357 | } | - | ||||||||||||||||||||||||||||||
| 358 | void QImage::detach() | - | ||||||||||||||||||||||||||||||
| 359 | { | - | ||||||||||||||||||||||||||||||
| 360 | if (d) { | - | ||||||||||||||||||||||||||||||
| 361 | if (d->is_cached && d->ref.load() == 1) | - | ||||||||||||||||||||||||||||||
| 362 | QImagePixmapCleanupHooks::executeImageHooks(cacheKey()); | - | ||||||||||||||||||||||||||||||
| 363 | - | |||||||||||||||||||||||||||||||
| 364 | if (d->ref.load() != 1 || d->ro_data) | - | ||||||||||||||||||||||||||||||
| 365 | *this = copy(); | - | ||||||||||||||||||||||||||||||
| 366 | - | |||||||||||||||||||||||||||||||
| 367 | if (d) | - | ||||||||||||||||||||||||||||||
| 368 | ++d->detach_no; | - | ||||||||||||||||||||||||||||||
| 369 | } | - | ||||||||||||||||||||||||||||||
| 370 | } | - | ||||||||||||||||||||||||||||||
| 371 | - | |||||||||||||||||||||||||||||||
| 372 | - | |||||||||||||||||||||||||||||||
| 373 | static void copyMetadata(QImageData *dst, const QImageData *src) | - | ||||||||||||||||||||||||||||||
| 374 | { | - | ||||||||||||||||||||||||||||||
| 375 | - | |||||||||||||||||||||||||||||||
| 376 | dst->dpmx = src->dpmx; | - | ||||||||||||||||||||||||||||||
| 377 | dst->dpmy = src->dpmy; | - | ||||||||||||||||||||||||||||||
| 378 | dst->devicePixelRatio = src->devicePixelRatio; | - | ||||||||||||||||||||||||||||||
| 379 | dst->text = src->text; | - | ||||||||||||||||||||||||||||||
| 380 | } | - | ||||||||||||||||||||||||||||||
| 381 | QImage QImage::copy(const QRect& r) const | - | ||||||||||||||||||||||||||||||
| 382 | { | - | ||||||||||||||||||||||||||||||
| 383 | if (!d) | - | ||||||||||||||||||||||||||||||
| 384 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 385 | - | |||||||||||||||||||||||||||||||
| 386 | if (r.isNull()) { | - | ||||||||||||||||||||||||||||||
| 387 | QImage image(d->width, d->height, d->format); | - | ||||||||||||||||||||||||||||||
| 388 | if (image.isNull()) | - | ||||||||||||||||||||||||||||||
| 389 | return image; | - | ||||||||||||||||||||||||||||||
| 390 | - | |||||||||||||||||||||||||||||||
| 391 | - | |||||||||||||||||||||||||||||||
| 392 | - | |||||||||||||||||||||||||||||||
| 393 | if (image.d->nbytes != d->nbytes) { | - | ||||||||||||||||||||||||||||||
| 394 | int bpl = qMin(bytesPerLine(), image.bytesPerLine()); | - | ||||||||||||||||||||||||||||||
| 395 | for (int i = 0; i < height(); i++) | - | ||||||||||||||||||||||||||||||
| 396 | memcpy(image.scanLine(i), scanLine(i), bpl); | - | ||||||||||||||||||||||||||||||
| 397 | } else | - | ||||||||||||||||||||||||||||||
| 398 | memcpy(image.bits(), bits(), d->nbytes); | - | ||||||||||||||||||||||||||||||
| 399 | image.d->colortable = d->colortable; | - | ||||||||||||||||||||||||||||||
| 400 | image.d->offset = d->offset; | - | ||||||||||||||||||||||||||||||
| 401 | image.d->has_alpha_clut = d->has_alpha_clut; | - | ||||||||||||||||||||||||||||||
| 402 | copyMetadata(image.d, d); | - | ||||||||||||||||||||||||||||||
| 403 | return image; | - | ||||||||||||||||||||||||||||||
| 404 | } | - | ||||||||||||||||||||||||||||||
| 405 | - | |||||||||||||||||||||||||||||||
| 406 | int x = r.x(); | - | ||||||||||||||||||||||||||||||
| 407 | int y = r.y(); | - | ||||||||||||||||||||||||||||||
| 408 | int w = r.width(); | - | ||||||||||||||||||||||||||||||
| 409 | int h = r.height(); | - | ||||||||||||||||||||||||||||||
| 410 | - | |||||||||||||||||||||||||||||||
| 411 | int dx = 0; | - | ||||||||||||||||||||||||||||||
| 412 | int dy = 0; | - | ||||||||||||||||||||||||||||||
| 413 | if (w <= 0 || h <= 0) | - | ||||||||||||||||||||||||||||||
| 414 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 415 | - | |||||||||||||||||||||||||||||||
| 416 | QImage image(w, h, d->format); | - | ||||||||||||||||||||||||||||||
| 417 | if (image.isNull()) | - | ||||||||||||||||||||||||||||||
| 418 | return image; | - | ||||||||||||||||||||||||||||||
| 419 | - | |||||||||||||||||||||||||||||||
| 420 | if (x < 0 || y < 0 || x + w > d->width || y + h > d->height) { | - | ||||||||||||||||||||||||||||||
| 421 | - | |||||||||||||||||||||||||||||||
| 422 | image.fill(0); | - | ||||||||||||||||||||||||||||||
| 423 | if (x < 0) { | - | ||||||||||||||||||||||||||||||
| 424 | dx = -x; | - | ||||||||||||||||||||||||||||||
| 425 | x = 0; | - | ||||||||||||||||||||||||||||||
| 426 | } | - | ||||||||||||||||||||||||||||||
| 427 | if (y < 0) { | - | ||||||||||||||||||||||||||||||
| 428 | dy = -y; | - | ||||||||||||||||||||||||||||||
| 429 | y = 0; | - | ||||||||||||||||||||||||||||||
| 430 | } | - | ||||||||||||||||||||||||||||||
| 431 | } | - | ||||||||||||||||||||||||||||||
| 432 | - | |||||||||||||||||||||||||||||||
| 433 | image.d->colortable = d->colortable; | - | ||||||||||||||||||||||||||||||
| 434 | - | |||||||||||||||||||||||||||||||
| 435 | int pixels_to_copy = qMax(w - dx, 0); | - | ||||||||||||||||||||||||||||||
| 436 | if (x > d->width) | - | ||||||||||||||||||||||||||||||
| 437 | pixels_to_copy = 0; | - | ||||||||||||||||||||||||||||||
| 438 | else if (pixels_to_copy > d->width - x) | - | ||||||||||||||||||||||||||||||
| 439 | pixels_to_copy = d->width - x; | - | ||||||||||||||||||||||||||||||
| 440 | int lines_to_copy = qMax(h - dy, 0); | - | ||||||||||||||||||||||||||||||
| 441 | if (y > d->height) | - | ||||||||||||||||||||||||||||||
| 442 | lines_to_copy = 0; | - | ||||||||||||||||||||||||||||||
| 443 | else if (lines_to_copy > d->height - y) | - | ||||||||||||||||||||||||||||||
| 444 | lines_to_copy = d->height - y; | - | ||||||||||||||||||||||||||||||
| 445 | - | |||||||||||||||||||||||||||||||
| 446 | bool byteAligned = true; | - | ||||||||||||||||||||||||||||||
| 447 | if (d->format == Format_Mono || d->format == Format_MonoLSB) | - | ||||||||||||||||||||||||||||||
| 448 | byteAligned = !(dx & 7) && !(x & 7) && !(pixels_to_copy & 7); | - | ||||||||||||||||||||||||||||||
| 449 | - | |||||||||||||||||||||||||||||||
| 450 | if (byteAligned) { | - | ||||||||||||||||||||||||||||||
| 451 | const uchar *src = d->data + ((x * d->depth) >> 3) + y * d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 452 | uchar *dest = image.d->data + ((dx * d->depth) >> 3) + dy * image.d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 453 | const int bytes_to_copy = (pixels_to_copy * d->depth) >> 3; | - | ||||||||||||||||||||||||||||||
| 454 | for (int i = 0; i < lines_to_copy; ++i) { | - | ||||||||||||||||||||||||||||||
| 455 | memcpy(dest, src, bytes_to_copy); | - | ||||||||||||||||||||||||||||||
| 456 | src += d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 457 | dest += image.d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 458 | } | - | ||||||||||||||||||||||||||||||
| 459 | } else if (d->format == Format_Mono) { | - | ||||||||||||||||||||||||||||||
| 460 | const uchar *src = d->data + y * d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 461 | uchar *dest = image.d->data + dy * image.d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 462 | for (int i = 0; i < lines_to_copy; ++i) { | - | ||||||||||||||||||||||||||||||
| 463 | for (int j = 0; j < pixels_to_copy; ++j) { | - | ||||||||||||||||||||||||||||||
| 464 | if (src[(x + j) >> 3] & (0x80 >> ((x + j) & 7))) | - | ||||||||||||||||||||||||||||||
| 465 | dest[(dx + j) >> 3] |= (0x80 >> ((dx + j) & 7)); | - | ||||||||||||||||||||||||||||||
| 466 | else | - | ||||||||||||||||||||||||||||||
| 467 | dest[(dx + j) >> 3] &= ~(0x80 >> ((dx + j) & 7)); | - | ||||||||||||||||||||||||||||||
| 468 | } | - | ||||||||||||||||||||||||||||||
| 469 | src += d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 470 | dest += image.d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 471 | } | - | ||||||||||||||||||||||||||||||
| 472 | } else { | - | ||||||||||||||||||||||||||||||
| 473 | ((!(d->format == Format_MonoLSB)) ? qt_assert("d->format == Format_MonoLSB",__FILE__,12371250) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 474 | const uchar *src = d->data + y * d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 475 | uchar *dest = image.d->data + dy * image.d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 476 | for (int i = 0; i < lines_to_copy; ++i) { | - | ||||||||||||||||||||||||||||||
| 477 | for (int j = 0; j < pixels_to_copy; ++j) { | - | ||||||||||||||||||||||||||||||
| 478 | if (src[(x + j) >> 3] & (0x1 << ((x + j) & 7))) | - | ||||||||||||||||||||||||||||||
| 479 | dest[(dx + j) >> 3] |= (0x1 << ((dx + j) & 7)); | - | ||||||||||||||||||||||||||||||
| 480 | else | - | ||||||||||||||||||||||||||||||
| 481 | dest[(dx + j) >> 3] &= ~(0x1 << ((dx + j) & 7)); | - | ||||||||||||||||||||||||||||||
| 482 | } | - | ||||||||||||||||||||||||||||||
| 483 | src += d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 484 | dest += image.d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 485 | } | - | ||||||||||||||||||||||||||||||
| 486 | } | - | ||||||||||||||||||||||||||||||
| 487 | - | |||||||||||||||||||||||||||||||
| 488 | copyMetadata(image.d, d); | - | ||||||||||||||||||||||||||||||
| 489 | image.d->offset = offset(); | - | ||||||||||||||||||||||||||||||
| 490 | image.d->has_alpha_clut = d->has_alpha_clut; | - | ||||||||||||||||||||||||||||||
| 491 | return image; | - | ||||||||||||||||||||||||||||||
| 492 | } | - | ||||||||||||||||||||||||||||||
| 493 | bool QImage::isNull() const | - | ||||||||||||||||||||||||||||||
| 494 | { | - | ||||||||||||||||||||||||||||||
| 495 | return !d; | - | ||||||||||||||||||||||||||||||
| 496 | } | - | ||||||||||||||||||||||||||||||
| 497 | int QImage::width() const | - | ||||||||||||||||||||||||||||||
| 498 | { | - | ||||||||||||||||||||||||||||||
| 499 | return d ? d->width : 0; | - | ||||||||||||||||||||||||||||||
| 500 | } | - | ||||||||||||||||||||||||||||||
| 501 | int QImage::height() const | - | ||||||||||||||||||||||||||||||
| 502 | { | - | ||||||||||||||||||||||||||||||
| 503 | return d ? d->height : 0; | - | ||||||||||||||||||||||||||||||
| 504 | } | - | ||||||||||||||||||||||||||||||
| 505 | QSize QImage::size() const | - | ||||||||||||||||||||||||||||||
| 506 | { | - | ||||||||||||||||||||||||||||||
| 507 | return d ? QSize(d->width, d->height) : QSize(0, 0); | - | ||||||||||||||||||||||||||||||
| 508 | } | - | ||||||||||||||||||||||||||||||
| 509 | QRect QImage::rect() const | - | ||||||||||||||||||||||||||||||
| 510 | { | - | ||||||||||||||||||||||||||||||
| 511 | return d ? QRect(0, 0, d->width, d->height) : QRect(); | - | ||||||||||||||||||||||||||||||
| 512 | } | - | ||||||||||||||||||||||||||||||
| 513 | int QImage::depth() const | - | ||||||||||||||||||||||||||||||
| 514 | { | - | ||||||||||||||||||||||||||||||
| 515 | return d ? d->depth : 0; | - | ||||||||||||||||||||||||||||||
| 516 | } | - | ||||||||||||||||||||||||||||||
| 517 | int QImage::colorCount() const | - | ||||||||||||||||||||||||||||||
| 518 | { | - | ||||||||||||||||||||||||||||||
| 519 | return d ? d->colortable.size() : 0; | - | ||||||||||||||||||||||||||||||
| 520 | } | - | ||||||||||||||||||||||||||||||
| 521 | void QImage::setColorTable(const QVector<QRgb> colors) | - | ||||||||||||||||||||||||||||||
| 522 | - | |||||||||||||||||||||||||||||||
| 523 | { | - | ||||||||||||||||||||||||||||||
| 524 | if (!d) | - | ||||||||||||||||||||||||||||||
| 525 | return; | - | ||||||||||||||||||||||||||||||
| 526 | detach(); | - | ||||||||||||||||||||||||||||||
| 527 | - | |||||||||||||||||||||||||||||||
| 528 | - | |||||||||||||||||||||||||||||||
| 529 | if (!d) | - | ||||||||||||||||||||||||||||||
| 530 | return; | - | ||||||||||||||||||||||||||||||
| 531 | - | |||||||||||||||||||||||||||||||
| 532 | - | |||||||||||||||||||||||||||||||
| 533 | - | |||||||||||||||||||||||||||||||
| 534 | - | |||||||||||||||||||||||||||||||
| 535 | d->colortable = std::move(const_cast<QVector<QRgb>&>(colors)); | - | ||||||||||||||||||||||||||||||
| 536 | - | |||||||||||||||||||||||||||||||
| 537 | d->has_alpha_clut = false; | - | ||||||||||||||||||||||||||||||
| 538 | for (int i = 0; i < d->colortable.size(); ++i) { | - | ||||||||||||||||||||||||||||||
| 539 | if (qAlpha(d->colortable.at(i)) != 255) { | - | ||||||||||||||||||||||||||||||
| 540 | d->has_alpha_clut = true; | - | ||||||||||||||||||||||||||||||
| 541 | break; | - | ||||||||||||||||||||||||||||||
| 542 | } | - | ||||||||||||||||||||||||||||||
| 543 | } | - | ||||||||||||||||||||||||||||||
| 544 | } | - | ||||||||||||||||||||||||||||||
| 545 | - | |||||||||||||||||||||||||||||||
| 546 | - | |||||||||||||||||||||||||||||||
| 547 | - | |||||||||||||||||||||||||||||||
| 548 | - | |||||||||||||||||||||||||||||||
| 549 | - | |||||||||||||||||||||||||||||||
| 550 | - | |||||||||||||||||||||||||||||||
| 551 | - | |||||||||||||||||||||||||||||||
| 552 | QVector<QRgb> QImage::colorTable() const | - | ||||||||||||||||||||||||||||||
| 553 | { | - | ||||||||||||||||||||||||||||||
| 554 | return d ? d->colortable : QVector<QRgb>(); | - | ||||||||||||||||||||||||||||||
| 555 | } | - | ||||||||||||||||||||||||||||||
| 556 | qreal QImage::devicePixelRatio() const | - | ||||||||||||||||||||||||||||||
| 557 | { | - | ||||||||||||||||||||||||||||||
| 558 | if (!d) | - | ||||||||||||||||||||||||||||||
| 559 | return 1.0; | - | ||||||||||||||||||||||||||||||
| 560 | return d->devicePixelRatio; | - | ||||||||||||||||||||||||||||||
| 561 | } | - | ||||||||||||||||||||||||||||||
| 562 | void QImage::setDevicePixelRatio(qreal scaleFactor) | - | ||||||||||||||||||||||||||||||
| 563 | { | - | ||||||||||||||||||||||||||||||
| 564 | if (!d) | - | ||||||||||||||||||||||||||||||
| 565 | return; | - | ||||||||||||||||||||||||||||||
| 566 | - | |||||||||||||||||||||||||||||||
| 567 | if (scaleFactor == d->devicePixelRatio) | - | ||||||||||||||||||||||||||||||
| 568 | return; | - | ||||||||||||||||||||||||||||||
| 569 | - | |||||||||||||||||||||||||||||||
| 570 | detach(); | - | ||||||||||||||||||||||||||||||
| 571 | d->devicePixelRatio = scaleFactor; | - | ||||||||||||||||||||||||||||||
| 572 | } | - | ||||||||||||||||||||||||||||||
| 573 | int QImage::byteCount() const | - | ||||||||||||||||||||||||||||||
| 574 | { | - | ||||||||||||||||||||||||||||||
| 575 | return d ? d->nbytes : 0; | - | ||||||||||||||||||||||||||||||
| 576 | } | - | ||||||||||||||||||||||||||||||
| 577 | int QImage::bytesPerLine() const | - | ||||||||||||||||||||||||||||||
| 578 | { | - | ||||||||||||||||||||||||||||||
| 579 | return (d && d->height) ? d->nbytes / d->height : 0; | - | ||||||||||||||||||||||||||||||
| 580 | } | - | ||||||||||||||||||||||||||||||
| 581 | QRgb QImage::color(int i) const | - | ||||||||||||||||||||||||||||||
| 582 | { | - | ||||||||||||||||||||||||||||||
| 583 | ((!(i < colorCount())) ? qt_assert("i < colorCount()",__FILE__,15021515) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 584 | return d ? d->colortable.at(i) : QRgb(uint(-1)); | - | ||||||||||||||||||||||||||||||
| 585 | } | - | ||||||||||||||||||||||||||||||
| 586 | void QImage::setColor(int i, QRgb c) | - | ||||||||||||||||||||||||||||||
| 587 | { | - | ||||||||||||||||||||||||||||||
| 588 | if (!d) | - | ||||||||||||||||||||||||||||||
| 589 | return; | - | ||||||||||||||||||||||||||||||
| 590 | if (i < 0 || d->depth > 8 || i >= 1<<d->depth) { | - | ||||||||||||||||||||||||||||||
| 591 | QMessageLogger(__FILE__, 15231536, __PRETTY_FUNCTION__).warning("QImage::setColor: Index out of bound %d", i); | - | ||||||||||||||||||||||||||||||
| 592 | return; | - | ||||||||||||||||||||||||||||||
| 593 | } | - | ||||||||||||||||||||||||||||||
| 594 | detach(); | - | ||||||||||||||||||||||||||||||
| 595 | - | |||||||||||||||||||||||||||||||
| 596 | - | |||||||||||||||||||||||||||||||
| 597 | if (!d) | - | ||||||||||||||||||||||||||||||
| 598 | return; | - | ||||||||||||||||||||||||||||||
| 599 | - | |||||||||||||||||||||||||||||||
| 600 | if (i >= d->colortable.size()) | - | ||||||||||||||||||||||||||||||
| 601 | setColorCount(i+1); | - | ||||||||||||||||||||||||||||||
| 602 | d->colortable[i] = c; | - | ||||||||||||||||||||||||||||||
| 603 | d->has_alpha_clut |= (qAlpha(c) != 255); | - | ||||||||||||||||||||||||||||||
| 604 | } | - | ||||||||||||||||||||||||||||||
| 605 | uchar *QImage::scanLine(int i) | - | ||||||||||||||||||||||||||||||
| 606 | { | - | ||||||||||||||||||||||||||||||
| 607 | if (!d) | - | ||||||||||||||||||||||||||||||
| 608 | return 0; | - | ||||||||||||||||||||||||||||||
| 609 | - | |||||||||||||||||||||||||||||||
| 610 | detach(); | - | ||||||||||||||||||||||||||||||
| 611 | - | |||||||||||||||||||||||||||||||
| 612 | - | |||||||||||||||||||||||||||||||
| 613 | if (!d) | - | ||||||||||||||||||||||||||||||
| 614 | return 0; | - | ||||||||||||||||||||||||||||||
| 615 | - | |||||||||||||||||||||||||||||||
| 616 | return d->data + i * d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 617 | } | - | ||||||||||||||||||||||||||||||
| 618 | - | |||||||||||||||||||||||||||||||
| 619 | - | |||||||||||||||||||||||||||||||
| 620 | - | |||||||||||||||||||||||||||||||
| 621 | - | |||||||||||||||||||||||||||||||
| 622 | const uchar *QImage::scanLine(int i) const | - | ||||||||||||||||||||||||||||||
| 623 | { | - | ||||||||||||||||||||||||||||||
| 624 | if (!d) | - | ||||||||||||||||||||||||||||||
| 625 | return 0; | - | ||||||||||||||||||||||||||||||
| 626 | - | |||||||||||||||||||||||||||||||
| 627 | ((!(i >= 0 && i < height())) ? qt_assert("i >= 0 && i < height()",__FILE__,15761589) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 628 | return d->data + i * d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 629 | } | - | ||||||||||||||||||||||||||||||
| 630 | const uchar *QImage::constScanLine(int i) const | - | ||||||||||||||||||||||||||||||
| 631 | { | - | ||||||||||||||||||||||||||||||
| 632 | if (!d) | - | ||||||||||||||||||||||||||||||
| 633 | return 0; | - | ||||||||||||||||||||||||||||||
| 634 | - | |||||||||||||||||||||||||||||||
| 635 | ((!(i >= 0 && i < height())) ? qt_assert("i >= 0 && i < height()",__FILE__,15991612) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 636 | return d->data + i * d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 637 | } | - | ||||||||||||||||||||||||||||||
| 638 | uchar *QImage::bits() | - | ||||||||||||||||||||||||||||||
| 639 | { | - | ||||||||||||||||||||||||||||||
| 640 | if (!d) | - | ||||||||||||||||||||||||||||||
| 641 | return 0; | - | ||||||||||||||||||||||||||||||
| 642 | detach(); | - | ||||||||||||||||||||||||||||||
| 643 | - | |||||||||||||||||||||||||||||||
| 644 | - | |||||||||||||||||||||||||||||||
| 645 | if (!d) | - | ||||||||||||||||||||||||||||||
| 646 | return 0; | - | ||||||||||||||||||||||||||||||
| 647 | - | |||||||||||||||||||||||||||||||
| 648 | return d->data; | - | ||||||||||||||||||||||||||||||
| 649 | } | - | ||||||||||||||||||||||||||||||
| 650 | const uchar *QImage::bits() const | - | ||||||||||||||||||||||||||||||
| 651 | { | - | ||||||||||||||||||||||||||||||
| 652 | return d ? d->data : 0; | - | ||||||||||||||||||||||||||||||
| 653 | } | - | ||||||||||||||||||||||||||||||
| 654 | const uchar *QImage::constBits() const | - | ||||||||||||||||||||||||||||||
| 655 | { | - | ||||||||||||||||||||||||||||||
| 656 | return d ? d->data : 0; | - | ||||||||||||||||||||||||||||||
| 657 | } | - | ||||||||||||||||||||||||||||||
| 658 | void QImage::fill(uint pixel) | - | ||||||||||||||||||||||||||||||
| 659 | { | - | ||||||||||||||||||||||||||||||
| 660 | if (!d) | - | ||||||||||||||||||||||||||||||
| 661 | return; | - | ||||||||||||||||||||||||||||||
| 662 | - | |||||||||||||||||||||||||||||||
| 663 | detach(); | - | ||||||||||||||||||||||||||||||
| 664 | - | |||||||||||||||||||||||||||||||
| 665 | - | |||||||||||||||||||||||||||||||
| 666 | if (!d) | - | ||||||||||||||||||||||||||||||
| 667 | return; | - | ||||||||||||||||||||||||||||||
| 668 | - | |||||||||||||||||||||||||||||||
| 669 | if (d->depth == 1 || d->depth == 8) { | - | ||||||||||||||||||||||||||||||
| 670 | int w = d->width; | - | ||||||||||||||||||||||||||||||
| 671 | if (d->depth == 1) { | - | ||||||||||||||||||||||||||||||
| 672 | if (pixel & 1) | - | ||||||||||||||||||||||||||||||
| 673 | pixel = 0xffffffff; | - | ||||||||||||||||||||||||||||||
| 674 | else | - | ||||||||||||||||||||||||||||||
| 675 | pixel = 0; | - | ||||||||||||||||||||||||||||||
| 676 | w = (w + 7) / 8; | - | ||||||||||||||||||||||||||||||
| 677 | } else { | - | ||||||||||||||||||||||||||||||
| 678 | pixel &= 0xff; | - | ||||||||||||||||||||||||||||||
| 679 | } | - | ||||||||||||||||||||||||||||||
| 680 | qt_rectfill<quint8>(d->data, pixel, 0, 0, | - | ||||||||||||||||||||||||||||||
| 681 | w, d->height, d->bytes_per_line); | - | ||||||||||||||||||||||||||||||
| 682 | return; | - | ||||||||||||||||||||||||||||||
| 683 | } else if (d->depth == 16) { | - | ||||||||||||||||||||||||||||||
| 684 | qt_rectfill<quint16>(reinterpret_cast<quint16*>(d->data), pixel, | - | ||||||||||||||||||||||||||||||
| 685 | 0, 0, d->width, d->height, d->bytes_per_line); | - | ||||||||||||||||||||||||||||||
| 686 | return; | - | ||||||||||||||||||||||||||||||
| 687 | } else if (d->depth == 24) { | - | ||||||||||||||||||||||||||||||
| 688 | qt_rectfill<quint24>(reinterpret_cast<quint24*>(d->data), pixel, | - | ||||||||||||||||||||||||||||||
| 689 | 0, 0, d->width, d->height, d->bytes_per_line); | - | ||||||||||||||||||||||||||||||
| 690 | return; | - | ||||||||||||||||||||||||||||||
| 691 | } | - | ||||||||||||||||||||||||||||||
| 692 | - | |||||||||||||||||||||||||||||||
| 693 | if (d->format == Format_RGB32) | - | ||||||||||||||||||||||||||||||
| 694 | pixel |= 0xff000000; | - | ||||||||||||||||||||||||||||||
| 695 | if (d->format == Format_RGBX8888) | - | ||||||||||||||||||||||||||||||
| 696 | - | |||||||||||||||||||||||||||||||
| 697 | pixel |= 0xff000000; | - | ||||||||||||||||||||||||||||||
| 698 | - | |||||||||||||||||||||||||||||||
| 699 | - | |||||||||||||||||||||||||||||||
| 700 | - | |||||||||||||||||||||||||||||||
| 701 | if (d->format == Format_BGR30 || d->format == Format_RGB30) | - | ||||||||||||||||||||||||||||||
| 702 | pixel |= 0xc0000000; | - | ||||||||||||||||||||||||||||||
| 703 | - | |||||||||||||||||||||||||||||||
| 704 | qt_rectfill<uint>(reinterpret_cast<uint*>(d->data), pixel, | - | ||||||||||||||||||||||||||||||
| 705 | 0, 0, d->width, d->height, d->bytes_per_line); | - | ||||||||||||||||||||||||||||||
| 706 | } | - | ||||||||||||||||||||||||||||||
| 707 | void QImage::fill(Qt::GlobalColor color) | - | ||||||||||||||||||||||||||||||
| 708 | { | - | ||||||||||||||||||||||||||||||
| 709 | fill(QColor(color)); | - | ||||||||||||||||||||||||||||||
| 710 | } | - | ||||||||||||||||||||||||||||||
| 711 | void QImage::fill(const QColor &color) | - | ||||||||||||||||||||||||||||||
| 712 | { | - | ||||||||||||||||||||||||||||||
| 713 | if (!d) | - | ||||||||||||||||||||||||||||||
| 714 | return; | - | ||||||||||||||||||||||||||||||
| 715 | detach(); | - | ||||||||||||||||||||||||||||||
| 716 | - | |||||||||||||||||||||||||||||||
| 717 | - | |||||||||||||||||||||||||||||||
| 718 | if (!d) | - | ||||||||||||||||||||||||||||||
| 719 | return; | - | ||||||||||||||||||||||||||||||
| 720 | - | |||||||||||||||||||||||||||||||
| 721 | switch (d->format) { | - | ||||||||||||||||||||||||||||||
| 722 | case QImage::Format_RGB32: | - | ||||||||||||||||||||||||||||||
| 723 | case QImage::Format_ARGB32: | - | ||||||||||||||||||||||||||||||
| 724 | fill(color.rgba()); | - | ||||||||||||||||||||||||||||||
| 725 | break; | - | ||||||||||||||||||||||||||||||
| 726 | case QImage::Format_ARGB32_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 727 | fill(qPremultiply(color.rgba())); | - | ||||||||||||||||||||||||||||||
| 728 | break; | - | ||||||||||||||||||||||||||||||
| 729 | case QImage::Format_RGBX8888: | - | ||||||||||||||||||||||||||||||
| 730 | fill(ARGB2RGBA(color.rgba() | 0xff000000)); | - | ||||||||||||||||||||||||||||||
| 731 | break; | - | ||||||||||||||||||||||||||||||
| 732 | case QImage::Format_RGBA8888: | - | ||||||||||||||||||||||||||||||
| 733 | fill(ARGB2RGBA(color.rgba())); | - | ||||||||||||||||||||||||||||||
| 734 | break; | - | ||||||||||||||||||||||||||||||
| 735 | case QImage::Format_RGBA8888_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 736 | fill(ARGB2RGBA(qPremultiply(color.rgba()))); | - | ||||||||||||||||||||||||||||||
| 737 | break; | - | ||||||||||||||||||||||||||||||
| 738 | case QImage::Format_BGR30: | - | ||||||||||||||||||||||||||||||
| 739 | case QImage::Format_A2BGR30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 740 | fill(qConvertRgb64ToRgb30<PixelOrderBGR>(color.rgba64())); | - | ||||||||||||||||||||||||||||||
| 741 | break; | - | ||||||||||||||||||||||||||||||
| 742 | case QImage::Format_RGB30: | - | ||||||||||||||||||||||||||||||
| 743 | case QImage::Format_A2RGB30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 744 | fill(qConvertRgb64ToRgb30<PixelOrderRGB>(color.rgba64())); | - | ||||||||||||||||||||||||||||||
| 745 | break; | - | ||||||||||||||||||||||||||||||
| 746 | case QImage::Format_RGB16: | - | ||||||||||||||||||||||||||||||
| 747 | fill((uint) qConvertRgb32To16(color.rgba())); | - | ||||||||||||||||||||||||||||||
| 748 | break; | - | ||||||||||||||||||||||||||||||
| 749 | case QImage::Format_Indexed8: { | - | ||||||||||||||||||||||||||||||
| 750 | uint pixel = 0; | - | ||||||||||||||||||||||||||||||
| 751 | for (int i=0; i<d->colortable.size(); ++i) { | - | ||||||||||||||||||||||||||||||
| 752 | if (color.rgba() == d->colortable.at(i)) { | - | ||||||||||||||||||||||||||||||
| 753 | pixel = i; | - | ||||||||||||||||||||||||||||||
| 754 | break; | - | ||||||||||||||||||||||||||||||
| 755 | } | - | ||||||||||||||||||||||||||||||
| 756 | } | - | ||||||||||||||||||||||||||||||
| 757 | fill(pixel); | - | ||||||||||||||||||||||||||||||
| 758 | break; | - | ||||||||||||||||||||||||||||||
| 759 | } | - | ||||||||||||||||||||||||||||||
| 760 | case QImage::Format_Mono: | - | ||||||||||||||||||||||||||||||
| 761 | case QImage::Format_MonoLSB: | - | ||||||||||||||||||||||||||||||
| 762 | if (color == Qt::color1) | - | ||||||||||||||||||||||||||||||
| 763 | fill((uint) 1); | - | ||||||||||||||||||||||||||||||
| 764 | else | - | ||||||||||||||||||||||||||||||
| 765 | fill((uint) 0); | - | ||||||||||||||||||||||||||||||
| 766 | break; | - | ||||||||||||||||||||||||||||||
| 767 | default: { | - | ||||||||||||||||||||||||||||||
| 768 | QPainter p(this); | - | ||||||||||||||||||||||||||||||
| 769 | p.setCompositionMode(QPainter::CompositionMode_Source); | - | ||||||||||||||||||||||||||||||
| 770 | p.fillRect(rect(), color); | - | ||||||||||||||||||||||||||||||
| 771 | }} | - | ||||||||||||||||||||||||||||||
| 772 | } | - | ||||||||||||||||||||||||||||||
| 773 | void QImage::invertPixels(InvertMode mode) | - | ||||||||||||||||||||||||||||||
| 774 | { | - | ||||||||||||||||||||||||||||||
| 775 | if (!d) | - | ||||||||||||||||||||||||||||||
| 776 | return; | - | ||||||||||||||||||||||||||||||
| 777 | - | |||||||||||||||||||||||||||||||
| 778 | detach(); | - | ||||||||||||||||||||||||||||||
| 779 | - | |||||||||||||||||||||||||||||||
| 780 | - | |||||||||||||||||||||||||||||||
| 781 | if (!d) | - | ||||||||||||||||||||||||||||||
| 782 | return; | - | ||||||||||||||||||||||||||||||
| 783 | - | |||||||||||||||||||||||||||||||
| 784 | QImage::Format originalFormat = d->format; | - | ||||||||||||||||||||||||||||||
| 785 | - | |||||||||||||||||||||||||||||||
| 786 | if (hasAlphaChannel() && qPixelLayouts[d->format].premultiplied) { | - | ||||||||||||||||||||||||||||||
| 787 | if (!d->convertInPlace(QImage::Format_ARGB32, 0)) | - | ||||||||||||||||||||||||||||||
| 788 | *this = convertToFormat(QImage::Format_ARGB32); | - | ||||||||||||||||||||||||||||||
| 789 | } | - | ||||||||||||||||||||||||||||||
| 790 | - | |||||||||||||||||||||||||||||||
| 791 | if (depth() < 32) { | - | ||||||||||||||||||||||||||||||
| 792 | - | |||||||||||||||||||||||||||||||
| 793 | int bpl = (d->width * d->depth + 7) / 8; | - | ||||||||||||||||||||||||||||||
| 794 | int pad = d->bytes_per_line - bpl; | - | ||||||||||||||||||||||||||||||
| 795 | uchar *sl = d->data; | - | ||||||||||||||||||||||||||||||
| 796 | for (int y=0; y<d->height; ++y) { | - | ||||||||||||||||||||||||||||||
| 797 | for (int x=0; x<bpl; ++x) | - | ||||||||||||||||||||||||||||||
| 798 | *sl++ ^= 0xff; | - | ||||||||||||||||||||||||||||||
| 799 | sl += pad; | - | ||||||||||||||||||||||||||||||
| 800 | } | - | ||||||||||||||||||||||||||||||
| 801 | } else { | - | ||||||||||||||||||||||||||||||
| 802 | quint32 *p = (quint32*)d->data; | - | ||||||||||||||||||||||||||||||
| 803 | quint32 *end = (quint32*)(d->data + d->nbytes); | - | ||||||||||||||||||||||||||||||
| 804 | quint32 xorbits = 0xffffffff; | - | ||||||||||||||||||||||||||||||
| 805 | switch (d->format) { | - | ||||||||||||||||||||||||||||||
| 806 | case QImage::Format_RGBA8888: | - | ||||||||||||||||||||||||||||||
| 807 | if (mode == InvertRgba) | - | ||||||||||||||||||||||||||||||
| 808 | break; | - | ||||||||||||||||||||||||||||||
| 809 | - | |||||||||||||||||||||||||||||||
| 810 | case QImage::Format_RGBX8888: | - | ||||||||||||||||||||||||||||||
| 811 | - | |||||||||||||||||||||||||||||||
| 812 | - | |||||||||||||||||||||||||||||||
| 813 | - | |||||||||||||||||||||||||||||||
| 814 | - | |||||||||||||||||||||||||||||||
| 815 | xorbits = 0x00ffffff; | - | ||||||||||||||||||||||||||||||
| 816 | break; | - | ||||||||||||||||||||||||||||||
| 817 | - | |||||||||||||||||||||||||||||||
| 818 | case QImage::Format_ARGB32: | - | ||||||||||||||||||||||||||||||
| 819 | if (mode == InvertRgba) | - | ||||||||||||||||||||||||||||||
| 820 | break; | - | ||||||||||||||||||||||||||||||
| 821 | - | |||||||||||||||||||||||||||||||
| 822 | case QImage::Format_RGB32: | - | ||||||||||||||||||||||||||||||
| 823 | xorbits = 0x00ffffff; | - | ||||||||||||||||||||||||||||||
| 824 | break; | - | ||||||||||||||||||||||||||||||
| 825 | case QImage::Format_BGR30: | - | ||||||||||||||||||||||||||||||
| 826 | case QImage::Format_RGB30: | - | ||||||||||||||||||||||||||||||
| 827 | xorbits = 0x3fffffff; | - | ||||||||||||||||||||||||||||||
| 828 | break; | - | ||||||||||||||||||||||||||||||
| 829 | default: | - | ||||||||||||||||||||||||||||||
| 830 | do { ((!(false)) ? qt_assert_x("Q_UNREACHABLE()", "Q_UNREACHABLE was reached",__FILE__,19001913) : qt_noop()); __builtin_unreachable(); } while (0); | - | ||||||||||||||||||||||||||||||
| 831 | xorbits = 0; | - | ||||||||||||||||||||||||||||||
| 832 | break; | - | ||||||||||||||||||||||||||||||
| 833 | } | - | ||||||||||||||||||||||||||||||
| 834 | while (p < end) | - | ||||||||||||||||||||||||||||||
| 835 | *p++ ^= xorbits; | - | ||||||||||||||||||||||||||||||
| 836 | } | - | ||||||||||||||||||||||||||||||
| 837 | - | |||||||||||||||||||||||||||||||
| 838 | if (originalFormat != d->format) { | - | ||||||||||||||||||||||||||||||
| 839 | if (!d->convertInPlace(originalFormat, 0)) | - | ||||||||||||||||||||||||||||||
| 840 | *this = convertToFormat(originalFormat); | - | ||||||||||||||||||||||||||||||
| 841 | } | - | ||||||||||||||||||||||||||||||
| 842 | } | - | ||||||||||||||||||||||||||||||
| 843 | void QImage::setColorCount(int colorCount) | - | ||||||||||||||||||||||||||||||
| 844 | { | - | ||||||||||||||||||||||||||||||
| 845 | if (!d) { | - | ||||||||||||||||||||||||||||||
| 846 | QMessageLogger(__FILE__, 19431956, __PRETTY_FUNCTION__).warning("QImage::setColorCount: null image"); | - | ||||||||||||||||||||||||||||||
| 847 | return; | - | ||||||||||||||||||||||||||||||
| 848 | } | - | ||||||||||||||||||||||||||||||
| 849 | - | |||||||||||||||||||||||||||||||
| 850 | detach(); | - | ||||||||||||||||||||||||||||||
| 851 | - | |||||||||||||||||||||||||||||||
| 852 | - | |||||||||||||||||||||||||||||||
| 853 | if (!d) | - | ||||||||||||||||||||||||||||||
| 854 | return; | - | ||||||||||||||||||||||||||||||
| 855 | - | |||||||||||||||||||||||||||||||
| 856 | if (colorCount == d->colortable.size()) | - | ||||||||||||||||||||||||||||||
| 857 | return; | - | ||||||||||||||||||||||||||||||
| 858 | if (colorCount <= 0) { | - | ||||||||||||||||||||||||||||||
| 859 | d->colortable = QVector<QRgb>(); | - | ||||||||||||||||||||||||||||||
| 860 | return; | - | ||||||||||||||||||||||||||||||
| 861 | } | - | ||||||||||||||||||||||||||||||
| 862 | int nc = d->colortable.size(); | - | ||||||||||||||||||||||||||||||
| 863 | d->colortable.resize(colorCount); | - | ||||||||||||||||||||||||||||||
| 864 | for (int i = nc; i < colorCount; ++i) | - | ||||||||||||||||||||||||||||||
| 865 | d->colortable[i] = 0; | - | ||||||||||||||||||||||||||||||
| 866 | } | - | ||||||||||||||||||||||||||||||
| 867 | - | |||||||||||||||||||||||||||||||
| 868 | - | |||||||||||||||||||||||||||||||
| 869 | - | |||||||||||||||||||||||||||||||
| 870 | - | |||||||||||||||||||||||||||||||
| 871 | - | |||||||||||||||||||||||||||||||
| 872 | - | |||||||||||||||||||||||||||||||
| 873 | QImage::Format QImage::format() const | - | ||||||||||||||||||||||||||||||
| 874 | { | - | ||||||||||||||||||||||||||||||
| 875 | return d ? d->format : Format_Invalid; | - | ||||||||||||||||||||||||||||||
| 876 | } | - | ||||||||||||||||||||||||||||||
| 877 | QImage QImage::convertToFormat_helper(Format format, Qt::ImageConversionFlags flags) const | - | ||||||||||||||||||||||||||||||
| 878 | { | - | ||||||||||||||||||||||||||||||
| 879 | if (!d || d->format == format) | - | ||||||||||||||||||||||||||||||
| 880 | return *this; | - | ||||||||||||||||||||||||||||||
| 881 | - | |||||||||||||||||||||||||||||||
| 882 | if (format == Format_Invalid || d->format == Format_Invalid) | - | ||||||||||||||||||||||||||||||
| 883 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 884 | - | |||||||||||||||||||||||||||||||
| 885 | Image_Converter converter = qimage_converter_map[d->format][format]; | - | ||||||||||||||||||||||||||||||
| 886 | if (!converter && format > QImage::Format_Indexed8 && d->format > QImage::Format_Indexed8) | - | ||||||||||||||||||||||||||||||
| 887 | converter = convert_generic; | - | ||||||||||||||||||||||||||||||
| 888 | if (converter) { | - | ||||||||||||||||||||||||||||||
| 889 | QImage image(d->width, d->height, format); | - | ||||||||||||||||||||||||||||||
| 890 | - | |||||||||||||||||||||||||||||||
| 891 | if ((image).isNull()) { QMessageLogger(__FILE__, 20032016, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - | ||||||||||||||||||||||||||||||
| 892 | - | |||||||||||||||||||||||||||||||
| 893 | image.d->offset = offset(); | - | ||||||||||||||||||||||||||||||
| 894 | copyMetadata(image.d, d); | - | ||||||||||||||||||||||||||||||
| 895 | - | |||||||||||||||||||||||||||||||
| 896 | converter(image.d, d, flags); | - | ||||||||||||||||||||||||||||||
| 897 | return image; | - | ||||||||||||||||||||||||||||||
| 898 | } | - | ||||||||||||||||||||||||||||||
| 899 | - | |||||||||||||||||||||||||||||||
| 900 | - | |||||||||||||||||||||||||||||||
| 901 | ((!(format != QImage::Format_ARGB32 && format != QImage::Format_RGB32)) ? qt_assert("format != QImage::Format_ARGB32 && format != QImage::Format_RGB32",__FILE__,20132026) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 902 | ((!(d->format != QImage::Format_ARGB32 && d->format != QImage::Format_RGB32)) ? qt_assert("d->format != QImage::Format_ARGB32 && d->format != QImage::Format_RGB32",__FILE__,20142027) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 903 | - | |||||||||||||||||||||||||||||||
| 904 | if (!hasAlphaChannel()) | - | ||||||||||||||||||||||||||||||
| 905 | return convertToFormat(Format_RGB32, flags).convertToFormat(format, flags); | - | ||||||||||||||||||||||||||||||
| 906 | - | |||||||||||||||||||||||||||||||
| 907 | return convertToFormat(Format_ARGB32, flags).convertToFormat(format, flags); | - | ||||||||||||||||||||||||||||||
| 908 | } | - | ||||||||||||||||||||||||||||||
| 909 | - | |||||||||||||||||||||||||||||||
| 910 | - | |||||||||||||||||||||||||||||||
| 911 | - | |||||||||||||||||||||||||||||||
| 912 | - | |||||||||||||||||||||||||||||||
| 913 | bool QImage::convertToFormat_inplace(Format format, Qt::ImageConversionFlags flags) | - | ||||||||||||||||||||||||||||||
| 914 | { | - | ||||||||||||||||||||||||||||||
| 915 | return d && d->convertInPlace(format, flags); | - | ||||||||||||||||||||||||||||||
| 916 | } | - | ||||||||||||||||||||||||||||||
| 917 | - | |||||||||||||||||||||||||||||||
| 918 | static inline int pixel_distance(QRgb p1, QRgb p2) { | - | ||||||||||||||||||||||||||||||
| 919 | int r1 = qRed(p1); | - | ||||||||||||||||||||||||||||||
| 920 | int g1 = qGreen(p1); | - | ||||||||||||||||||||||||||||||
| 921 | int b1 = qBlue(p1); | - | ||||||||||||||||||||||||||||||
| 922 | int a1 = qAlpha(p1); | - | ||||||||||||||||||||||||||||||
| 923 | - | |||||||||||||||||||||||||||||||
| 924 | int r2 = qRed(p2); | - | ||||||||||||||||||||||||||||||
| 925 | int g2 = qGreen(p2); | - | ||||||||||||||||||||||||||||||
| 926 | int b2 = qBlue(p2); | - | ||||||||||||||||||||||||||||||
| 927 | int a2 = qAlpha(p2); | - | ||||||||||||||||||||||||||||||
| 928 | - | |||||||||||||||||||||||||||||||
| 929 | return abs(r1 - r2) + abs(g1 - g2) + abs(b1 - b2) + abs(a1 - a2); | - | ||||||||||||||||||||||||||||||
| 930 | } | - | ||||||||||||||||||||||||||||||
| 931 | - | |||||||||||||||||||||||||||||||
| 932 | static inline int closestMatch(QRgb pixel, const QVector<QRgb> &clut) { | - | ||||||||||||||||||||||||||||||
| 933 | int idx = 0; | - | ||||||||||||||||||||||||||||||
| 934 | int current_distance = 2147483647; | - | ||||||||||||||||||||||||||||||
| 935 | for (int i=0; i<clut.size(); ++i) { | - | ||||||||||||||||||||||||||||||
| 936 | int dist = pixel_distance(pixel, clut.at(i)); | - | ||||||||||||||||||||||||||||||
| 937 | if (dist < current_distance) { | - | ||||||||||||||||||||||||||||||
| 938 | current_distance = dist; | - | ||||||||||||||||||||||||||||||
| 939 | idx = i; | - | ||||||||||||||||||||||||||||||
| 940 | } | - | ||||||||||||||||||||||||||||||
| 941 | } | - | ||||||||||||||||||||||||||||||
| 942 | return idx; | - | ||||||||||||||||||||||||||||||
| 943 | } | - | ||||||||||||||||||||||||||||||
| 944 | - | |||||||||||||||||||||||||||||||
| 945 | static QImage convertWithPalette(const QImage &src, QImage::Format format, | - | ||||||||||||||||||||||||||||||
| 946 | const QVector<QRgb> &clut) { | - | ||||||||||||||||||||||||||||||
| 947 | QImage dest(src.size(), format); | - | ||||||||||||||||||||||||||||||
| 948 | dest.setColorTable(clut); | - | ||||||||||||||||||||||||||||||
| 949 | - | |||||||||||||||||||||||||||||||
| 950 | QString textsKeys = src.text(); | - | ||||||||||||||||||||||||||||||
| 951 | QStringListconst auto textKeyList = textsKeys.splitsplitRef(QLatin1Char('\n'), QString::SkipEmptyParts); | - | ||||||||||||||||||||||||||||||
| 952 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(textKeyList)>::type> _container_((textKeyList)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QStringauto &textKey = *_container_.i; _container_.control; _container_.control = 0: textKeyList) { | - | ||||||||||||||||||||||||||||||
| 953 | QStringListconst auto textKeySplitted = textKey.split(QLatin1String(": ")); | - | ||||||||||||||||||||||||||||||
| 954 | dest.setText(textKeySplitted[0],].toString(), textKeySplitted[1]);].toString()); | - | ||||||||||||||||||||||||||||||
| 955 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 956 | - | |||||||||||||||||||||||||||||||
| 957 | int h = src.height(); | - | ||||||||||||||||||||||||||||||
| 958 | int w = src.width(); | - | ||||||||||||||||||||||||||||||
| 959 | - | |||||||||||||||||||||||||||||||
| 960 | QHash<QRgb, int> cache; | - | ||||||||||||||||||||||||||||||
| 961 | - | |||||||||||||||||||||||||||||||
| 962 | if (format == QImage::Format_Indexed8
| 0 | ||||||||||||||||||||||||||||||
| 963 | for (int y=0; y<h
| 0 | ||||||||||||||||||||||||||||||
| 964 | const QRgb *src_pixels = (const QRgb *) src.scanLine(y); | - | ||||||||||||||||||||||||||||||
| 965 | uchar *dest_pixels = (uchar *) dest.scanLine(y); | - | ||||||||||||||||||||||||||||||
| 966 | for (int x=0; x<w
| 0 | ||||||||||||||||||||||||||||||
| 967 | int src_pixel = src_pixels[x]; | - | ||||||||||||||||||||||||||||||
| 968 | int value = cache.value(src_pixel, -1); | - | ||||||||||||||||||||||||||||||
| 969 | if (value == -1
| 0 | ||||||||||||||||||||||||||||||
| 970 | value = closestMatch(src_pixel, clut); | - | ||||||||||||||||||||||||||||||
| 971 | cache.insert(src_pixel, value); | - | ||||||||||||||||||||||||||||||
| 972 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 973 | dest_pixels[x] = (uchar) value; | - | ||||||||||||||||||||||||||||||
| 974 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 975 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 976 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||||||||
| 977 | QVector<QRgb> table = clut; | - | ||||||||||||||||||||||||||||||
| 978 | table.resize(2); | - | ||||||||||||||||||||||||||||||
| 979 | for (int y=0; y<h
| 0 | ||||||||||||||||||||||||||||||
| 980 | const QRgb *src_pixels = (const QRgb *) src.scanLine(y); | - | ||||||||||||||||||||||||||||||
| 981 | for (int x=0; x<w
| 0 | ||||||||||||||||||||||||||||||
| 982 | int src_pixel = src_pixels[x]; | - | ||||||||||||||||||||||||||||||
| 983 | int value = cache.value(src_pixel, -1); | - | ||||||||||||||||||||||||||||||
| 984 | if (value == -1
| 0 | ||||||||||||||||||||||||||||||
| 985 | value = closestMatch(src_pixel, table); | - | ||||||||||||||||||||||||||||||
| 986 | cache.insert(src_pixel, value); | - | ||||||||||||||||||||||||||||||
| 987 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 988 | dest.setPixel(x, y, value); | - | ||||||||||||||||||||||||||||||
| 989 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 990 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 991 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 992 | - | |||||||||||||||||||||||||||||||
| 993 | return never executed: dest;return dest;never executed: return dest; | 0 | ||||||||||||||||||||||||||||||
| 994 | } | - | ||||||||||||||||||||||||||||||
| 995 | QImage QImage::convertToFormat(Format format, const QVector<QRgb> &colorTable, Qt::ImageConversionFlags flags) const | - | ||||||||||||||||||||||||||||||
| 996 | { | - | ||||||||||||||||||||||||||||||
| 997 | if (!d || d->format == format) | - | ||||||||||||||||||||||||||||||
| 998 | return *this; | - | ||||||||||||||||||||||||||||||
| 999 | - | |||||||||||||||||||||||||||||||
| 1000 | if (format <= QImage::Format_Indexed8 && depth() == 32) { | - | ||||||||||||||||||||||||||||||
| 1001 | return convertWithPalette(*this, format, colorTable); | - | ||||||||||||||||||||||||||||||
| 1002 | } | - | ||||||||||||||||||||||||||||||
| 1003 | - | |||||||||||||||||||||||||||||||
| 1004 | const Image_Converter *converterPtr = &qimage_converter_map[d->format][format]; | - | ||||||||||||||||||||||||||||||
| 1005 | Image_Converter converter = *converterPtr; | - | ||||||||||||||||||||||||||||||
| 1006 | if (!converter) | - | ||||||||||||||||||||||||||||||
| 1007 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 1008 | - | |||||||||||||||||||||||||||||||
| 1009 | QImage image(d->width, d->height, format); | - | ||||||||||||||||||||||||||||||
| 1010 | if ((image).isNull()) { QMessageLogger(__FILE__, 21332146, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - | ||||||||||||||||||||||||||||||
| 1011 | - | |||||||||||||||||||||||||||||||
| 1012 | image.d->offset = offset(); | - | ||||||||||||||||||||||||||||||
| 1013 | copyMetadata(image.d, d); | - | ||||||||||||||||||||||||||||||
| 1014 | - | |||||||||||||||||||||||||||||||
| 1015 | converter(image.d, d, flags); | - | ||||||||||||||||||||||||||||||
| 1016 | return image; | - | ||||||||||||||||||||||||||||||
| 1017 | } | - | ||||||||||||||||||||||||||||||
| 1018 | bool QImage::valid(int x, int y) const | - | ||||||||||||||||||||||||||||||
| 1019 | { | - | ||||||||||||||||||||||||||||||
| 1020 | return d | - | ||||||||||||||||||||||||||||||
| 1021 | && x >= 0 && x < d->width | - | ||||||||||||||||||||||||||||||
| 1022 | && y >= 0 && y < d->height; | - | ||||||||||||||||||||||||||||||
| 1023 | } | - | ||||||||||||||||||||||||||||||
| 1024 | int QImage::pixelIndex(int x, int y) const | - | ||||||||||||||||||||||||||||||
| 1025 | { | - | ||||||||||||||||||||||||||||||
| 1026 | if (!d || x < 0 || x >= d->width || y < 0 || y >= height()) { | - | ||||||||||||||||||||||||||||||
| 1027 | QMessageLogger(__FILE__, 21832196, __PRETTY_FUNCTION__).warning("QImage::pixelIndex: coordinate (%d,%d) out of range", x, y); | - | ||||||||||||||||||||||||||||||
| 1028 | return -12345; | - | ||||||||||||||||||||||||||||||
| 1029 | } | - | ||||||||||||||||||||||||||||||
| 1030 | const uchar * s = scanLine(y); | - | ||||||||||||||||||||||||||||||
| 1031 | switch(d->format) { | - | ||||||||||||||||||||||||||||||
| 1032 | case Format_Mono: | - | ||||||||||||||||||||||||||||||
| 1033 | return (*(s + (x >> 3)) >> (7- (x & 7))) & 1; | - | ||||||||||||||||||||||||||||||
| 1034 | case Format_MonoLSB: | - | ||||||||||||||||||||||||||||||
| 1035 | return (*(s + (x >> 3)) >> (x & 7)) & 1; | - | ||||||||||||||||||||||||||||||
| 1036 | case Format_Indexed8: | - | ||||||||||||||||||||||||||||||
| 1037 | return (int)s[x]; | - | ||||||||||||||||||||||||||||||
| 1038 | default: | - | ||||||||||||||||||||||||||||||
| 1039 | QMessageLogger(__FILE__, 21952208, __PRETTY_FUNCTION__).warning("QImage::pixelIndex: Not applicable for %d-bpp images (no palette)", d->depth); | - | ||||||||||||||||||||||||||||||
| 1040 | } | - | ||||||||||||||||||||||||||||||
| 1041 | return 0; | - | ||||||||||||||||||||||||||||||
| 1042 | } | - | ||||||||||||||||||||||||||||||
| 1043 | QRgb QImage::pixel(int x, int y) const | - | ||||||||||||||||||||||||||||||
| 1044 | { | - | ||||||||||||||||||||||||||||||
| 1045 | if (!d || x < 0 || x >= d->width || y < 0 || y >= d->height) { | - | ||||||||||||||||||||||||||||||
| 1046 | QMessageLogger(__FILE__, 22242237, __PRETTY_FUNCTION__).warning("QImage::pixel: coordinate (%d,%d) out of range", x, y); | - | ||||||||||||||||||||||||||||||
| 1047 | return 12345; | - | ||||||||||||||||||||||||||||||
| 1048 | } | - | ||||||||||||||||||||||||||||||
| 1049 | - | |||||||||||||||||||||||||||||||
| 1050 | const uchar *s = d->data + y * d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 1051 | - | |||||||||||||||||||||||||||||||
| 1052 | int index = -1; | - | ||||||||||||||||||||||||||||||
| 1053 | switch (d->format) { | - | ||||||||||||||||||||||||||||||
| 1054 | case Format_Mono: | - | ||||||||||||||||||||||||||||||
| 1055 | index = (*(s + (x >> 3)) >> (~x & 7)) & 1; | - | ||||||||||||||||||||||||||||||
| 1056 | break; | - | ||||||||||||||||||||||||||||||
| 1057 | case Format_MonoLSB: | - | ||||||||||||||||||||||||||||||
| 1058 | index = (*(s + (x >> 3)) >> (x & 7)) & 1; | - | ||||||||||||||||||||||||||||||
| 1059 | break; | - | ||||||||||||||||||||||||||||||
| 1060 | case Format_Indexed8: | - | ||||||||||||||||||||||||||||||
| 1061 | index = s[x]; | - | ||||||||||||||||||||||||||||||
| 1062 | break; | - | ||||||||||||||||||||||||||||||
| 1063 | default: | - | ||||||||||||||||||||||||||||||
| 1064 | break; | - | ||||||||||||||||||||||||||||||
| 1065 | } | - | ||||||||||||||||||||||||||||||
| 1066 | if (index >= 0) { | - | ||||||||||||||||||||||||||||||
| 1067 | if (index >= d->colortable.size()) { | - | ||||||||||||||||||||||||||||||
| 1068 | QMessageLogger(__FILE__, 22462259, __PRETTY_FUNCTION__).warning("QImage::pixel: color table index %d out of range.", index); | - | ||||||||||||||||||||||||||||||
| 1069 | return 0; | - | ||||||||||||||||||||||||||||||
| 1070 | } | - | ||||||||||||||||||||||||||||||
| 1071 | return d->colortable.at(index); | - | ||||||||||||||||||||||||||||||
| 1072 | } | - | ||||||||||||||||||||||||||||||
| 1073 | - | |||||||||||||||||||||||||||||||
| 1074 | switch (d->format) { | - | ||||||||||||||||||||||||||||||
| 1075 | case Format_RGB32: | - | ||||||||||||||||||||||||||||||
| 1076 | return 0xff000000 | reinterpret_cast<const QRgb *>(s)[x]; | - | ||||||||||||||||||||||||||||||
| 1077 | case Format_ARGB32: | - | ||||||||||||||||||||||||||||||
| 1078 | case Format_ARGB32_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1079 | return reinterpret_cast<const QRgb *>(s)[x]; | - | ||||||||||||||||||||||||||||||
| 1080 | case Format_RGBX8888: | - | ||||||||||||||||||||||||||||||
| 1081 | case Format_RGBA8888: | - | ||||||||||||||||||||||||||||||
| 1082 | case Format_RGBA8888_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1083 | return RGBA2ARGB(reinterpret_cast<const quint32 *>(s)[x]); | - | ||||||||||||||||||||||||||||||
| 1084 | case Format_BGR30: | - | ||||||||||||||||||||||||||||||
| 1085 | case Format_A2BGR30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1086 | return qConvertA2rgb30ToArgb32<PixelOrderBGR>(reinterpret_cast<const quint32 *>(s)[x]); | - | ||||||||||||||||||||||||||||||
| 1087 | case Format_RGB30: | - | ||||||||||||||||||||||||||||||
| 1088 | case Format_A2RGB30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1089 | return qConvertA2rgb30ToArgb32<PixelOrderRGB>(reinterpret_cast<const quint32 *>(s)[x]); | - | ||||||||||||||||||||||||||||||
| 1090 | case Format_RGB16: | - | ||||||||||||||||||||||||||||||
| 1091 | return qConvertRgb16To32(reinterpret_cast<const quint16 *>(s)[x]); | - | ||||||||||||||||||||||||||||||
| 1092 | default: | - | ||||||||||||||||||||||||||||||
| 1093 | break; | - | ||||||||||||||||||||||||||||||
| 1094 | } | - | ||||||||||||||||||||||||||||||
| 1095 | const QPixelLayout *layout = &qPixelLayouts[d->format]; | - | ||||||||||||||||||||||||||||||
| 1096 | uint result; | - | ||||||||||||||||||||||||||||||
| 1097 | const uint *ptr = qFetchPixels[layout->bpp](&result, s, x, 1); | - | ||||||||||||||||||||||||||||||
| 1098 | return *layout->convertToARGB32PM(&result, ptr, 1, layout, 0); | - | ||||||||||||||||||||||||||||||
| 1099 | } | - | ||||||||||||||||||||||||||||||
| 1100 | void QImage::setPixel(int x, int y, uint index_or_rgb) | - | ||||||||||||||||||||||||||||||
| 1101 | { | - | ||||||||||||||||||||||||||||||
| 1102 | if (!d || x < 0 || x >= width() || y < 0 || y >= height()) { | - | ||||||||||||||||||||||||||||||
| 1103 | QMessageLogger(__FILE__, 23082321, __PRETTY_FUNCTION__).warning("QImage::setPixel: coordinate (%d,%d) out of range", x, y); | - | ||||||||||||||||||||||||||||||
| 1104 | return; | - | ||||||||||||||||||||||||||||||
| 1105 | } | - | ||||||||||||||||||||||||||||||
| 1106 | - | |||||||||||||||||||||||||||||||
| 1107 | uchar * s = scanLine(y); | - | ||||||||||||||||||||||||||||||
| 1108 | switch(d->format) { | - | ||||||||||||||||||||||||||||||
| 1109 | case Format_Mono: | - | ||||||||||||||||||||||||||||||
| 1110 | case Format_MonoLSB: | - | ||||||||||||||||||||||||||||||
| 1111 | if (index_or_rgb > 1) { | - | ||||||||||||||||||||||||||||||
| 1112 | QMessageLogger(__FILE__, 23172330, __PRETTY_FUNCTION__).warning("QImage::setPixel: Index %d out of range", index_or_rgb); | - | ||||||||||||||||||||||||||||||
| 1113 | } else if (format() == Format_MonoLSB) { | - | ||||||||||||||||||||||||||||||
| 1114 | if (index_or_rgb==0) | - | ||||||||||||||||||||||||||||||
| 1115 | *(s + (x >> 3)) &= ~(1 << (x & 7)); | - | ||||||||||||||||||||||||||||||
| 1116 | else | - | ||||||||||||||||||||||||||||||
| 1117 | *(s + (x >> 3)) |= (1 << (x & 7)); | - | ||||||||||||||||||||||||||||||
| 1118 | } else { | - | ||||||||||||||||||||||||||||||
| 1119 | if (index_or_rgb==0) | - | ||||||||||||||||||||||||||||||
| 1120 | *(s + (x >> 3)) &= ~(1 << (7-(x & 7))); | - | ||||||||||||||||||||||||||||||
| 1121 | else | - | ||||||||||||||||||||||||||||||
| 1122 | *(s + (x >> 3)) |= (1 << (7-(x & 7))); | - | ||||||||||||||||||||||||||||||
| 1123 | } | - | ||||||||||||||||||||||||||||||
| 1124 | return; | - | ||||||||||||||||||||||||||||||
| 1125 | case Format_Indexed8: | - | ||||||||||||||||||||||||||||||
| 1126 | if (index_or_rgb >= (uint)d->colortable.size()) { | - | ||||||||||||||||||||||||||||||
| 1127 | QMessageLogger(__FILE__, 23322345, __PRETTY_FUNCTION__).warning("QImage::setPixel: Index %d out of range", index_or_rgb); | - | ||||||||||||||||||||||||||||||
| 1128 | return; | - | ||||||||||||||||||||||||||||||
| 1129 | } | - | ||||||||||||||||||||||||||||||
| 1130 | s[x] = index_or_rgb; | - | ||||||||||||||||||||||||||||||
| 1131 | return; | - | ||||||||||||||||||||||||||||||
| 1132 | case Format_RGB32: | - | ||||||||||||||||||||||||||||||
| 1133 | - | |||||||||||||||||||||||||||||||
| 1134 | - | |||||||||||||||||||||||||||||||
| 1135 | ((uint *)s)[x] = 0xff000000 | index_or_rgb; | - | ||||||||||||||||||||||||||||||
| 1136 | return; | - | ||||||||||||||||||||||||||||||
| 1137 | case Format_ARGB32: | - | ||||||||||||||||||||||||||||||
| 1138 | case Format_ARGB32_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1139 | ((uint *)s)[x] = index_or_rgb; | - | ||||||||||||||||||||||||||||||
| 1140 | return; | - | ||||||||||||||||||||||||||||||
| 1141 | case Format_RGB16: | - | ||||||||||||||||||||||||||||||
| 1142 | ((quint16 *)s)[x] = qConvertRgb32To16(qUnpremultiply(index_or_rgb)); | - | ||||||||||||||||||||||||||||||
| 1143 | return; | - | ||||||||||||||||||||||||||||||
| 1144 | case Format_RGBX8888: | - | ||||||||||||||||||||||||||||||
| 1145 | ((uint *)s)[x] = ARGB2RGBA(0xff000000 | index_or_rgb); | - | ||||||||||||||||||||||||||||||
| 1146 | return; | - | ||||||||||||||||||||||||||||||
| 1147 | case Format_RGBA8888: | - | ||||||||||||||||||||||||||||||
| 1148 | case Format_RGBA8888_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1149 | ((uint *)s)[x] = ARGB2RGBA(index_or_rgb); | - | ||||||||||||||||||||||||||||||
| 1150 | return; | - | ||||||||||||||||||||||||||||||
| 1151 | case Format_BGR30: | - | ||||||||||||||||||||||||||||||
| 1152 | ((uint *)s)[x] = qConvertRgb32ToRgb30<PixelOrderBGR>(index_or_rgb); | - | ||||||||||||||||||||||||||||||
| 1153 | return; | - | ||||||||||||||||||||||||||||||
| 1154 | case Format_A2BGR30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1155 | ((uint *)s)[x] = qConvertArgb32ToA2rgb30<PixelOrderBGR>(index_or_rgb); | - | ||||||||||||||||||||||||||||||
| 1156 | return; | - | ||||||||||||||||||||||||||||||
| 1157 | case Format_RGB30: | - | ||||||||||||||||||||||||||||||
| 1158 | ((uint *)s)[x] = qConvertRgb32ToRgb30<PixelOrderRGB>(index_or_rgb); | - | ||||||||||||||||||||||||||||||
| 1159 | return; | - | ||||||||||||||||||||||||||||||
| 1160 | case Format_A2RGB30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1161 | ((uint *)s)[x] = qConvertArgb32ToA2rgb30<PixelOrderRGB>(index_or_rgb); | - | ||||||||||||||||||||||||||||||
| 1162 | return; | - | ||||||||||||||||||||||||||||||
| 1163 | case Format_Invalid: | - | ||||||||||||||||||||||||||||||
| 1164 | case NImageFormats: | - | ||||||||||||||||||||||||||||||
| 1165 | ((!(false)) ? qt_assert("false",__FILE__,23702383) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 1166 | return; | - | ||||||||||||||||||||||||||||||
| 1167 | default: | - | ||||||||||||||||||||||||||||||
| 1168 | break; | - | ||||||||||||||||||||||||||||||
| 1169 | } | - | ||||||||||||||||||||||||||||||
| 1170 | - | |||||||||||||||||||||||||||||||
| 1171 | const QPixelLayout *layout = &qPixelLayouts[d->format]; | - | ||||||||||||||||||||||||||||||
| 1172 | uint result; | - | ||||||||||||||||||||||||||||||
| 1173 | const uint *ptr = layout->convertFromARGB32PM(&result, &index_or_rgb, 1, layout, 0); | - | ||||||||||||||||||||||||||||||
| 1174 | qStorePixels[layout->bpp](s, ptr, x, 1); | - | ||||||||||||||||||||||||||||||
| 1175 | } | - | ||||||||||||||||||||||||||||||
| 1176 | QColor QImage::pixelColor(int x, int y) const | - | ||||||||||||||||||||||||||||||
| 1177 | { | - | ||||||||||||||||||||||||||||||
| 1178 | if (!d || x < 0 || x >= d->width || y < 0 || y >= height()) { | - | ||||||||||||||||||||||||||||||
| 1179 | QMessageLogger(__FILE__, 24072420, __PRETTY_FUNCTION__).warning("QImage::pixelColor: coordinate (%d,%d) out of range", x, y); | - | ||||||||||||||||||||||||||||||
| 1180 | return QColor(); | - | ||||||||||||||||||||||||||||||
| 1181 | } | - | ||||||||||||||||||||||||||||||
| 1182 | - | |||||||||||||||||||||||||||||||
| 1183 | QRgba64 c; | - | ||||||||||||||||||||||||||||||
| 1184 | const uchar * s = constScanLine(y); | - | ||||||||||||||||||||||||||||||
| 1185 | switch (d->format) { | - | ||||||||||||||||||||||||||||||
| 1186 | case Format_BGR30: | - | ||||||||||||||||||||||||||||||
| 1187 | case Format_A2BGR30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1188 | c = qConvertA2rgb30ToRgb64<PixelOrderBGR>(reinterpret_cast<const quint32 *>(s)[x]); | - | ||||||||||||||||||||||||||||||
| 1189 | break; | - | ||||||||||||||||||||||||||||||
| 1190 | case Format_RGB30: | - | ||||||||||||||||||||||||||||||
| 1191 | case Format_A2RGB30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1192 | c = qConvertA2rgb30ToRgb64<PixelOrderRGB>(reinterpret_cast<const quint32 *>(s)[x]); | - | ||||||||||||||||||||||||||||||
| 1193 | break; | - | ||||||||||||||||||||||||||||||
| 1194 | default: | - | ||||||||||||||||||||||||||||||
| 1195 | c = QRgba64::fromArgb32(pixel(x, y)); | - | ||||||||||||||||||||||||||||||
| 1196 | break; | - | ||||||||||||||||||||||||||||||
| 1197 | } | - | ||||||||||||||||||||||||||||||
| 1198 | - | |||||||||||||||||||||||||||||||
| 1199 | if (hasAlphaChannel() && qPixelLayouts[d->format].premultiplied) | - | ||||||||||||||||||||||||||||||
| 1200 | c = c.unpremultiplied(); | - | ||||||||||||||||||||||||||||||
| 1201 | return QColor(c); | - | ||||||||||||||||||||||||||||||
| 1202 | } | - | ||||||||||||||||||||||||||||||
| 1203 | void QImage::setPixelColor(int x, int y, const QColor &color) | - | ||||||||||||||||||||||||||||||
| 1204 | { | - | ||||||||||||||||||||||||||||||
| 1205 | if (!d
| 0 | ||||||||||||||||||||||||||||||
| 1206 | QMessageLogger(__FILE__, 24572470, __PRETTY_FUNCTION__).warning("QImage::setPixelColor: coordinate (%d,%d) out of range", x, y); | - | ||||||||||||||||||||||||||||||
| 1207 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 1208 | } | - | ||||||||||||||||||||||||||||||
| 1209 | - | |||||||||||||||||||||||||||||||
| 1210 | if (!color.isValid()
| 0 | ||||||||||||||||||||||||||||||
| 1211 | QMessageLogger(__FILE__, 2475, __PRETTY_FUNCTION__).warning("QImage::setPixelColor: color is invalid"); | - | ||||||||||||||||||||||||||||||
| 1212 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 1213 | } | - | ||||||||||||||||||||||||||||||
| 1214 | - | |||||||||||||||||||||||||||||||
| 1215 | - | |||||||||||||||||||||||||||||||
| 1216 | QRgba64 c = color.rgba64(); | - | ||||||||||||||||||||||||||||||
| 1217 | if (!hasAlphaChannel()
| 0 | ||||||||||||||||||||||||||||||
| 1218 | c.setAlpha(65535); never executed: c.setAlpha(65535); | 0 | ||||||||||||||||||||||||||||||
| 1219 | else if (qPixelLayouts[d->format].premultiplied
| 0 | ||||||||||||||||||||||||||||||
| 1220 | c = c.premultiplied(); never executed: c = c.premultiplied(); | 0 | ||||||||||||||||||||||||||||||
| 1221 | - | |||||||||||||||||||||||||||||||
| 1222 | uchar * s = scanLine(y); | - | ||||||||||||||||||||||||||||||
| 1223 | switch (d->format) { | - | ||||||||||||||||||||||||||||||
| 1224 | case never executed: Format_Mono:case Format_Mono:never executed: case Format_Mono: | 0 | ||||||||||||||||||||||||||||||
| 1225 | case never executed: Format_MonoLSB:case Format_MonoLSB:never executed: case Format_MonoLSB: | 0 | ||||||||||||||||||||||||||||||
| 1226 | case never executed: Format_Indexed8:case Format_Indexed8:never executed: case Format_Indexed8: | 0 | ||||||||||||||||||||||||||||||
| 1227 | QMessageLogger(__FILE__, 24722491, __PRETTY_FUNCTION__).warning("QImage::setPixelColor: called on monochrome or indexed format"); | - | ||||||||||||||||||||||||||||||
| 1228 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 1229 | case never executed: Format_BGR30:case Format_BGR30:never executed: case Format_BGR30: | 0 | ||||||||||||||||||||||||||||||
| 1230 | ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderBGR>(c) | 0xc0000000; | - | ||||||||||||||||||||||||||||||
| 1231 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 1232 | case never executed: Format_A2BGR30_Premultiplied:case Format_A2BGR30_Premultiplied:never executed: case Format_A2BGR30_Premultiplied: | 0 | ||||||||||||||||||||||||||||||
| 1233 | ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderBGR>(c); | - | ||||||||||||||||||||||||||||||
| 1234 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 1235 | case never executed: Format_RGB30:case Format_RGB30:never executed: case Format_RGB30: | 0 | ||||||||||||||||||||||||||||||
| 1236 | ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderRGB>(c) | 0xc0000000; | - | ||||||||||||||||||||||||||||||
| 1237 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 1238 | case never executed: Format_A2RGB30_Premultiplied:case Format_A2RGB30_Premultiplied:never executed: case Format_A2RGB30_Premultiplied: | 0 | ||||||||||||||||||||||||||||||
| 1239 | ((uint *)s)[x] = qConvertRgb64ToRgb30<PixelOrderRGB>(c); | - | ||||||||||||||||||||||||||||||
| 1240 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 1241 | default never executed: :default:never executed: default: | 0 | ||||||||||||||||||||||||||||||
| 1242 | setPixel(x, y, c.toArgb32()); | - | ||||||||||||||||||||||||||||||
| 1243 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 1244 | } | - | ||||||||||||||||||||||||||||||
| 1245 | } | - | ||||||||||||||||||||||||||||||
| 1246 | bool QImage::allGray() const | - | ||||||||||||||||||||||||||||||
| 1247 | { | - | ||||||||||||||||||||||||||||||
| 1248 | if (!d) | - | ||||||||||||||||||||||||||||||
| 1249 | return true; | - | ||||||||||||||||||||||||||||||
| 1250 | - | |||||||||||||||||||||||||||||||
| 1251 | switch (d->format) { | - | ||||||||||||||||||||||||||||||
| 1252 | case Format_Mono: | - | ||||||||||||||||||||||||||||||
| 1253 | case Format_MonoLSB: | - | ||||||||||||||||||||||||||||||
| 1254 | case Format_Indexed8: | - | ||||||||||||||||||||||||||||||
| 1255 | for (int i = 0; i < d->colortable.size(); ++i) { | - | ||||||||||||||||||||||||||||||
| 1256 | if (!qIsGray(d->colortable.at(i))) | - | ||||||||||||||||||||||||||||||
| 1257 | return false; | - | ||||||||||||||||||||||||||||||
| 1258 | } | - | ||||||||||||||||||||||||||||||
| 1259 | return true; | - | ||||||||||||||||||||||||||||||
| 1260 | case Format_Alpha8: | - | ||||||||||||||||||||||||||||||
| 1261 | return false; | - | ||||||||||||||||||||||||||||||
| 1262 | case Format_Grayscale8: | - | ||||||||||||||||||||||||||||||
| 1263 | return true; | - | ||||||||||||||||||||||||||||||
| 1264 | case Format_RGB32: | - | ||||||||||||||||||||||||||||||
| 1265 | case Format_ARGB32: | - | ||||||||||||||||||||||||||||||
| 1266 | case Format_ARGB32_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1267 | - | |||||||||||||||||||||||||||||||
| 1268 | case Format_RGBX8888: | - | ||||||||||||||||||||||||||||||
| 1269 | case Format_RGBA8888: | - | ||||||||||||||||||||||||||||||
| 1270 | case Format_RGBA8888_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1271 | - | |||||||||||||||||||||||||||||||
| 1272 | for (int j = 0; j < d->height; ++j) { | - | ||||||||||||||||||||||||||||||
| 1273 | const QRgb *b = (const QRgb *)constScanLine(j); | - | ||||||||||||||||||||||||||||||
| 1274 | for (int i = 0; i < d->width; ++i) { | - | ||||||||||||||||||||||||||||||
| 1275 | if (!qIsGray(b[i])) | - | ||||||||||||||||||||||||||||||
| 1276 | return false; | - | ||||||||||||||||||||||||||||||
| 1277 | } | - | ||||||||||||||||||||||||||||||
| 1278 | } | - | ||||||||||||||||||||||||||||||
| 1279 | return true; | - | ||||||||||||||||||||||||||||||
| 1280 | case Format_RGB16: | - | ||||||||||||||||||||||||||||||
| 1281 | for (int j = 0; j < d->height; ++j) { | - | ||||||||||||||||||||||||||||||
| 1282 | const quint16 *b = (const quint16 *)constScanLine(j); | - | ||||||||||||||||||||||||||||||
| 1283 | for (int i = 0; i < d->width; ++i) { | - | ||||||||||||||||||||||||||||||
| 1284 | if (!qIsGray(qConvertRgb16To32(b[i]))) | - | ||||||||||||||||||||||||||||||
| 1285 | return false; | - | ||||||||||||||||||||||||||||||
| 1286 | } | - | ||||||||||||||||||||||||||||||
| 1287 | } | - | ||||||||||||||||||||||||||||||
| 1288 | return true; | - | ||||||||||||||||||||||||||||||
| 1289 | default: | - | ||||||||||||||||||||||||||||||
| 1290 | break; | - | ||||||||||||||||||||||||||||||
| 1291 | } | - | ||||||||||||||||||||||||||||||
| 1292 | - | |||||||||||||||||||||||||||||||
| 1293 | const int buffer_size = 2048; | - | ||||||||||||||||||||||||||||||
| 1294 | uint buffer[buffer_size]; | - | ||||||||||||||||||||||||||||||
| 1295 | const QPixelLayout *layout = &qPixelLayouts[d->format]; | - | ||||||||||||||||||||||||||||||
| 1296 | FetchPixelsFunc fetch = qFetchPixels[layout->bpp]; | - | ||||||||||||||||||||||||||||||
| 1297 | for (int j = 0; j < d->height; ++j) { | - | ||||||||||||||||||||||||||||||
| 1298 | const uchar *b = constScanLine(j); | - | ||||||||||||||||||||||||||||||
| 1299 | int x = 0; | - | ||||||||||||||||||||||||||||||
| 1300 | while (x < d->width) { | - | ||||||||||||||||||||||||||||||
| 1301 | int l = qMin(d->width - x, buffer_size); | - | ||||||||||||||||||||||||||||||
| 1302 | const uint *ptr = fetch(buffer, b, x, l); | - | ||||||||||||||||||||||||||||||
| 1303 | ptr = layout->convertToARGB32PM(buffer, ptr, l, layout, 0); | - | ||||||||||||||||||||||||||||||
| 1304 | for (int i = 0; i < l; ++i) { | - | ||||||||||||||||||||||||||||||
| 1305 | if (!qIsGray(ptr[i])) | - | ||||||||||||||||||||||||||||||
| 1306 | return false; | - | ||||||||||||||||||||||||||||||
| 1307 | } | - | ||||||||||||||||||||||||||||||
| 1308 | x += l; | - | ||||||||||||||||||||||||||||||
| 1309 | } | - | ||||||||||||||||||||||||||||||
| 1310 | } | - | ||||||||||||||||||||||||||||||
| 1311 | return true; | - | ||||||||||||||||||||||||||||||
| 1312 | } | - | ||||||||||||||||||||||||||||||
| 1313 | bool QImage::isGrayscale() const | - | ||||||||||||||||||||||||||||||
| 1314 | { | - | ||||||||||||||||||||||||||||||
| 1315 | if (!d) | - | ||||||||||||||||||||||||||||||
| 1316 | return false; | - | ||||||||||||||||||||||||||||||
| 1317 | - | |||||||||||||||||||||||||||||||
| 1318 | if (d->format == QImage::Format_Alpha8) | - | ||||||||||||||||||||||||||||||
| 1319 | return false; | - | ||||||||||||||||||||||||||||||
| 1320 | - | |||||||||||||||||||||||||||||||
| 1321 | if (d->format == QImage::Format_Grayscale8) | - | ||||||||||||||||||||||||||||||
| 1322 | return true; | - | ||||||||||||||||||||||||||||||
| 1323 | - | |||||||||||||||||||||||||||||||
| 1324 | switch (depth()) { | - | ||||||||||||||||||||||||||||||
| 1325 | case 32: | - | ||||||||||||||||||||||||||||||
| 1326 | case 24: | - | ||||||||||||||||||||||||||||||
| 1327 | case 16: | - | ||||||||||||||||||||||||||||||
| 1328 | return allGray(); | - | ||||||||||||||||||||||||||||||
| 1329 | case 8: { | - | ||||||||||||||||||||||||||||||
| 1330 | ((!(d->format == QImage::Format_Indexed8)) ? qt_assert("d->format == QImage::Format_Indexed8",__FILE__,25952614) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 1331 | for (int i = 0; i < colorCount(); i++) | - | ||||||||||||||||||||||||||||||
| 1332 | if (d->colortable.at(i) != qRgb(i,i,i)) | - | ||||||||||||||||||||||||||||||
| 1333 | return false; | - | ||||||||||||||||||||||||||||||
| 1334 | return true; | - | ||||||||||||||||||||||||||||||
| 1335 | } | - | ||||||||||||||||||||||||||||||
| 1336 | } | - | ||||||||||||||||||||||||||||||
| 1337 | return false; | - | ||||||||||||||||||||||||||||||
| 1338 | } | - | ||||||||||||||||||||||||||||||
| 1339 | QImage QImage::scaled(const QSize& s, Qt::AspectRatioMode aspectMode, Qt::TransformationMode mode) const | - | ||||||||||||||||||||||||||||||
| 1340 | { | - | ||||||||||||||||||||||||||||||
| 1341 | if (!d) { | - | ||||||||||||||||||||||||||||||
| 1342 | QMessageLogger(__FILE__, 26462665, __PRETTY_FUNCTION__).warning("QImage::scaled: Image is a null image"); | - | ||||||||||||||||||||||||||||||
| 1343 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 1344 | } | - | ||||||||||||||||||||||||||||||
| 1345 | if (s.isEmpty()) | - | ||||||||||||||||||||||||||||||
| 1346 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 1347 | - | |||||||||||||||||||||||||||||||
| 1348 | QSize newSize = size(); | - | ||||||||||||||||||||||||||||||
| 1349 | newSize.scale(s, aspectMode); | - | ||||||||||||||||||||||||||||||
| 1350 | newSize.rwidth() = qMax(newSize.width(), 1); | - | ||||||||||||||||||||||||||||||
| 1351 | newSize.rheight() = qMax(newSize.height(), 1); | - | ||||||||||||||||||||||||||||||
| 1352 | if (newSize == size()) | - | ||||||||||||||||||||||||||||||
| 1353 | return *this; | - | ||||||||||||||||||||||||||||||
| 1354 | - | |||||||||||||||||||||||||||||||
| 1355 | QTransform wm = QTransform::fromScale((qreal)newSize.width() / width(), (qreal)newSize.height() / height()); | - | ||||||||||||||||||||||||||||||
| 1356 | QImage img = transformed(wm, mode); | - | ||||||||||||||||||||||||||||||
| 1357 | return img; | - | ||||||||||||||||||||||||||||||
| 1358 | } | - | ||||||||||||||||||||||||||||||
| 1359 | QImage QImage::scaledToWidth(int w, Qt::TransformationMode mode) const | - | ||||||||||||||||||||||||||||||
| 1360 | { | - | ||||||||||||||||||||||||||||||
| 1361 | if (!d) { | - | ||||||||||||||||||||||||||||||
| 1362 | QMessageLogger(__FILE__, 26812700, __PRETTY_FUNCTION__).warning("QImage::scaleWidth: Image is a null image"); | - | ||||||||||||||||||||||||||||||
| 1363 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 1364 | } | - | ||||||||||||||||||||||||||||||
| 1365 | if (w <= 0) | - | ||||||||||||||||||||||||||||||
| 1366 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 1367 | - | |||||||||||||||||||||||||||||||
| 1368 | qreal factor = (qreal) w / width(); | - | ||||||||||||||||||||||||||||||
| 1369 | QTransform wm = QTransform::fromScale(factor, factor); | - | ||||||||||||||||||||||||||||||
| 1370 | return transformed(wm, mode); | - | ||||||||||||||||||||||||||||||
| 1371 | } | - | ||||||||||||||||||||||||||||||
| 1372 | QImage QImage::scaledToHeight(int h, Qt::TransformationMode mode) const | - | ||||||||||||||||||||||||||||||
| 1373 | { | - | ||||||||||||||||||||||||||||||
| 1374 | if (!d) { | - | ||||||||||||||||||||||||||||||
| 1375 | QMessageLogger(__FILE__, 27092728, __PRETTY_FUNCTION__).warning("QImage::scaleHeight: Image is a null image"); | - | ||||||||||||||||||||||||||||||
| 1376 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 1377 | } | - | ||||||||||||||||||||||||||||||
| 1378 | if (h <= 0) | - | ||||||||||||||||||||||||||||||
| 1379 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 1380 | - | |||||||||||||||||||||||||||||||
| 1381 | qreal factor = (qreal) h / height(); | - | ||||||||||||||||||||||||||||||
| 1382 | QTransform wm = QTransform::fromScale(factor, factor); | - | ||||||||||||||||||||||||||||||
| 1383 | return transformed(wm, mode); | - | ||||||||||||||||||||||||||||||
| 1384 | } | - | ||||||||||||||||||||||||||||||
| 1385 | QMatrix QImage::trueMatrix(const QMatrix &matrix, int w, int h) | - | ||||||||||||||||||||||||||||||
| 1386 | { | - | ||||||||||||||||||||||||||||||
| 1387 | return trueMatrix(QTransform(matrix), w, h).toAffine(); | - | ||||||||||||||||||||||||||||||
| 1388 | } | - | ||||||||||||||||||||||||||||||
| 1389 | QImage QImage::transformed(const QMatrix &matrix, Qt::TransformationMode mode) const | - | ||||||||||||||||||||||||||||||
| 1390 | { | - | ||||||||||||||||||||||||||||||
| 1391 | return transformed(QTransform(matrix), mode); | - | ||||||||||||||||||||||||||||||
| 1392 | } | - | ||||||||||||||||||||||||||||||
| 1393 | QImage QImage::createAlphaMask(Qt::ImageConversionFlags flags) const | - | ||||||||||||||||||||||||||||||
| 1394 | { | - | ||||||||||||||||||||||||||||||
| 1395 | if (!d || d->format == QImage::Format_RGB32) | - | ||||||||||||||||||||||||||||||
| 1396 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 1397 | - | |||||||||||||||||||||||||||||||
| 1398 | if (d->depth == 1) { | - | ||||||||||||||||||||||||||||||
| 1399 | - | |||||||||||||||||||||||||||||||
| 1400 | - | |||||||||||||||||||||||||||||||
| 1401 | return convertToFormat(Format_Indexed8, flags).createAlphaMask(flags); | - | ||||||||||||||||||||||||||||||
| 1402 | } | - | ||||||||||||||||||||||||||||||
| 1403 | - | |||||||||||||||||||||||||||||||
| 1404 | QImage mask(d->width, d->height, Format_MonoLSB); | - | ||||||||||||||||||||||||||||||
| 1405 | if (!mask.isNull()) | - | ||||||||||||||||||||||||||||||
| 1406 | dither_to_Mono(mask.d, d, flags, true); | - | ||||||||||||||||||||||||||||||
| 1407 | return mask; | - | ||||||||||||||||||||||||||||||
| 1408 | } | - | ||||||||||||||||||||||||||||||
| 1409 | QImage QImage::createHeuristicMask(bool clipTight) const | - | ||||||||||||||||||||||||||||||
| 1410 | { | - | ||||||||||||||||||||||||||||||
| 1411 | if (!d) | - | ||||||||||||||||||||||||||||||
| 1412 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 1413 | - | |||||||||||||||||||||||||||||||
| 1414 | if (d->depth != 32) { | - | ||||||||||||||||||||||||||||||
| 1415 | QImage img32 = convertToFormat(Format_RGB32); | - | ||||||||||||||||||||||||||||||
| 1416 | return img32.createHeuristicMask(clipTight); | - | ||||||||||||||||||||||||||||||
| 1417 | } | - | ||||||||||||||||||||||||||||||
| 1418 | - | |||||||||||||||||||||||||||||||
| 1419 | - | |||||||||||||||||||||||||||||||
| 1420 | - | |||||||||||||||||||||||||||||||
| 1421 | int w = width(); | - | ||||||||||||||||||||||||||||||
| 1422 | int h = height(); | - | ||||||||||||||||||||||||||||||
| 1423 | QImage m(w, h, Format_MonoLSB); | - | ||||||||||||||||||||||||||||||
| 1424 | if ((m).isNull()) { QMessageLogger(__FILE__, 28342853, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - | ||||||||||||||||||||||||||||||
| 1425 | m.setColorCount(2); | - | ||||||||||||||||||||||||||||||
| 1426 | m.setColor(0, QColor(Qt::color0).rgba()); | - | ||||||||||||||||||||||||||||||
| 1427 | m.setColor(1, QColor(Qt::color1).rgba()); | - | ||||||||||||||||||||||||||||||
| 1428 | m.fill(0xff); | - | ||||||||||||||||||||||||||||||
| 1429 | - | |||||||||||||||||||||||||||||||
| 1430 | QRgb background = (*((const QRgb*)scanLine(0)+0) & 0x00ffffff); | - | ||||||||||||||||||||||||||||||
| 1431 | if (background != (*((const QRgb*)scanLine(0)+w-1) & 0x00ffffff) && | - | ||||||||||||||||||||||||||||||
| 1432 | background != (*((const QRgb*)scanLine(h-1)+0) & 0x00ffffff) && | - | ||||||||||||||||||||||||||||||
| 1433 | background != (*((const QRgb*)scanLine(h-1)+w-1) & 0x00ffffff)) { | - | ||||||||||||||||||||||||||||||
| 1434 | background = (*((const QRgb*)scanLine(0)+w-1) & 0x00ffffff); | - | ||||||||||||||||||||||||||||||
| 1435 | if (background != (*((const QRgb*)scanLine(h-1)+w-1) & 0x00ffffff) && | - | ||||||||||||||||||||||||||||||
| 1436 | background != (*((const QRgb*)scanLine(h-1)+0) & 0x00ffffff) && | - | ||||||||||||||||||||||||||||||
| 1437 | (*((const QRgb*)scanLine(h-1)+0) & 0x00ffffff) == (*((const QRgb*)scanLine(h-1)+w-1) & 0x00ffffff)) { | - | ||||||||||||||||||||||||||||||
| 1438 | background = (*((const QRgb*)scanLine(h-1)+w-1) & 0x00ffffff); | - | ||||||||||||||||||||||||||||||
| 1439 | } | - | ||||||||||||||||||||||||||||||
| 1440 | } | - | ||||||||||||||||||||||||||||||
| 1441 | - | |||||||||||||||||||||||||||||||
| 1442 | int x,y; | - | ||||||||||||||||||||||||||||||
| 1443 | bool done = false; | - | ||||||||||||||||||||||||||||||
| 1444 | uchar *ypp, *ypc, *ypn; | - | ||||||||||||||||||||||||||||||
| 1445 | while(!done) { | - | ||||||||||||||||||||||||||||||
| 1446 | done = true; | - | ||||||||||||||||||||||||||||||
| 1447 | ypn = m.scanLine(0); | - | ||||||||||||||||||||||||||||||
| 1448 | ypc = 0; | - | ||||||||||||||||||||||||||||||
| 1449 | for (y = 0; y < h; y++) { | - | ||||||||||||||||||||||||||||||
| 1450 | ypp = ypc; | - | ||||||||||||||||||||||||||||||
| 1451 | ypc = ypn; | - | ||||||||||||||||||||||||||||||
| 1452 | ypn = (y == h-1) ? 0 : m.scanLine(y+1); | - | ||||||||||||||||||||||||||||||
| 1453 | const QRgb *p = (const QRgb *)scanLine(y); | - | ||||||||||||||||||||||||||||||
| 1454 | for (x = 0; x < w; x++) { | - | ||||||||||||||||||||||||||||||
| 1455 | - | |||||||||||||||||||||||||||||||
| 1456 | - | |||||||||||||||||||||||||||||||
| 1457 | if ((x == 0 || y == 0 || x == w-1 || y == h-1 || | - | ||||||||||||||||||||||||||||||
| 1458 | !(*(ypc + ((x-1) >> 3)) & (1 << ((x-1) & 7))) || | - | ||||||||||||||||||||||||||||||
| 1459 | !(*(ypc + ((x+1) >> 3)) & (1 << ((x+1) & 7))) || | - | ||||||||||||||||||||||||||||||
| 1460 | !(*(ypp + (x >> 3)) & (1 << (x & 7))) || | - | ||||||||||||||||||||||||||||||
| 1461 | !(*(ypn + (x >> 3)) & (1 << (x & 7)))) && | - | ||||||||||||||||||||||||||||||
| 1462 | ( (*(ypc + (x >> 3)) & (1 << (x & 7)))) && | - | ||||||||||||||||||||||||||||||
| 1463 | ((*p & 0x00ffffff) == background)) { | - | ||||||||||||||||||||||||||||||
| 1464 | done = false; | - | ||||||||||||||||||||||||||||||
| 1465 | *(ypc + (x >> 3)) &= ~(1 << (x & 7)); | - | ||||||||||||||||||||||||||||||
| 1466 | } | - | ||||||||||||||||||||||||||||||
| 1467 | p++; | - | ||||||||||||||||||||||||||||||
| 1468 | } | - | ||||||||||||||||||||||||||||||
| 1469 | } | - | ||||||||||||||||||||||||||||||
| 1470 | } | - | ||||||||||||||||||||||||||||||
| 1471 | - | |||||||||||||||||||||||||||||||
| 1472 | if (!clipTight) { | - | ||||||||||||||||||||||||||||||
| 1473 | ypn = m.scanLine(0); | - | ||||||||||||||||||||||||||||||
| 1474 | ypc = 0; | - | ||||||||||||||||||||||||||||||
| 1475 | for (y = 0; y < h; y++) { | - | ||||||||||||||||||||||||||||||
| 1476 | ypp = ypc; | - | ||||||||||||||||||||||||||||||
| 1477 | ypc = ypn; | - | ||||||||||||||||||||||||||||||
| 1478 | ypn = (y == h-1) ? 0 : m.scanLine(y+1); | - | ||||||||||||||||||||||||||||||
| 1479 | const QRgb *p = (const QRgb *)scanLine(y); | - | ||||||||||||||||||||||||||||||
| 1480 | for (x = 0; x < w; x++) { | - | ||||||||||||||||||||||||||||||
| 1481 | if ((*p & 0x00ffffff) != background) { | - | ||||||||||||||||||||||||||||||
| 1482 | if (x > 0) | - | ||||||||||||||||||||||||||||||
| 1483 | *(ypc + ((x-1) >> 3)) |= (1 << ((x-1) & 7)); | - | ||||||||||||||||||||||||||||||
| 1484 | if (x < w-1) | - | ||||||||||||||||||||||||||||||
| 1485 | *(ypc + ((x+1) >> 3)) |= (1 << ((x+1) & 7)); | - | ||||||||||||||||||||||||||||||
| 1486 | if (y > 0) | - | ||||||||||||||||||||||||||||||
| 1487 | *(ypp + (x >> 3)) |= (1 << (x & 7)); | - | ||||||||||||||||||||||||||||||
| 1488 | if (y < h-1) | - | ||||||||||||||||||||||||||||||
| 1489 | *(ypn + (x >> 3)) |= (1 << (x & 7)); | - | ||||||||||||||||||||||||||||||
| 1490 | } | - | ||||||||||||||||||||||||||||||
| 1491 | p++; | - | ||||||||||||||||||||||||||||||
| 1492 | } | - | ||||||||||||||||||||||||||||||
| 1493 | } | - | ||||||||||||||||||||||||||||||
| 1494 | } | - | ||||||||||||||||||||||||||||||
| 1495 | - | |||||||||||||||||||||||||||||||
| 1496 | - | |||||||||||||||||||||||||||||||
| 1497 | - | |||||||||||||||||||||||||||||||
| 1498 | return m; | - | ||||||||||||||||||||||||||||||
| 1499 | } | - | ||||||||||||||||||||||||||||||
| 1500 | QImage QImage::createMaskFromColor(QRgb color, Qt::MaskMode mode) const | - | ||||||||||||||||||||||||||||||
| 1501 | { | - | ||||||||||||||||||||||||||||||
| 1502 | if (!d) | - | ||||||||||||||||||||||||||||||
| 1503 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 1504 | QImage maskImage(size(), QImage::Format_MonoLSB); | - | ||||||||||||||||||||||||||||||
| 1505 | if ((maskImage).isNull()) { QMessageLogger(__FILE__, 29272946, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - | ||||||||||||||||||||||||||||||
| 1506 | maskImage.fill(0); | - | ||||||||||||||||||||||||||||||
| 1507 | uchar *s = maskImage.bits(); | - | ||||||||||||||||||||||||||||||
| 1508 | - | |||||||||||||||||||||||||||||||
| 1509 | if (depth() == 32) { | - | ||||||||||||||||||||||||||||||
| 1510 | for (int h = 0; h < d->height; h++) { | - | ||||||||||||||||||||||||||||||
| 1511 | const uint *sl = (const uint *) scanLine(h); | - | ||||||||||||||||||||||||||||||
| 1512 | for (int w = 0; w < d->width; w++) { | - | ||||||||||||||||||||||||||||||
| 1513 | if (sl[w] == color) | - | ||||||||||||||||||||||||||||||
| 1514 | *(s + (w >> 3)) |= (1 << (w & 7)); | - | ||||||||||||||||||||||||||||||
| 1515 | } | - | ||||||||||||||||||||||||||||||
| 1516 | s += maskImage.bytesPerLine(); | - | ||||||||||||||||||||||||||||||
| 1517 | } | - | ||||||||||||||||||||||||||||||
| 1518 | } else { | - | ||||||||||||||||||||||||||||||
| 1519 | for (int h = 0; h < d->height; h++) { | - | ||||||||||||||||||||||||||||||
| 1520 | for (int w = 0; w < d->width; w++) { | - | ||||||||||||||||||||||||||||||
| 1521 | if ((uint) pixel(w, h) == color) | - | ||||||||||||||||||||||||||||||
| 1522 | *(s + (w >> 3)) |= (1 << (w & 7)); | - | ||||||||||||||||||||||||||||||
| 1523 | } | - | ||||||||||||||||||||||||||||||
| 1524 | s += maskImage.bytesPerLine(); | - | ||||||||||||||||||||||||||||||
| 1525 | } | - | ||||||||||||||||||||||||||||||
| 1526 | } | - | ||||||||||||||||||||||||||||||
| 1527 | if (mode == Qt::MaskOutColor) | - | ||||||||||||||||||||||||||||||
| 1528 | maskImage.invertPixels(); | - | ||||||||||||||||||||||||||||||
| 1529 | return maskImage; | - | ||||||||||||||||||||||||||||||
| 1530 | } | - | ||||||||||||||||||||||||||||||
| 1531 | template<class T> inline void do_mirror_data(QImageData *dst, QImageData *src, | - | ||||||||||||||||||||||||||||||
| 1532 | int dstX0, int dstY0, | - | ||||||||||||||||||||||||||||||
| 1533 | int dstXIncr, int dstYIncr, | - | ||||||||||||||||||||||||||||||
| 1534 | int w, int h) | - | ||||||||||||||||||||||||||||||
| 1535 | { | - | ||||||||||||||||||||||||||||||
| 1536 | if (dst == src) { | - | ||||||||||||||||||||||||||||||
| 1537 | - | |||||||||||||||||||||||||||||||
| 1538 | - | |||||||||||||||||||||||||||||||
| 1539 | const int srcXEnd = (dstX0 && !dstY0) ? w / 2 : w; | - | ||||||||||||||||||||||||||||||
| 1540 | const int srcYEnd = dstY0 ? h / 2 : h; | - | ||||||||||||||||||||||||||||||
| 1541 | for (int srcY = 0, dstY = dstY0; srcY < srcYEnd; ++srcY, dstY += dstYIncr) { | - | ||||||||||||||||||||||||||||||
| 1542 | T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line); | - | ||||||||||||||||||||||||||||||
| 1543 | T *dstPtr = (T *) (dst->data + dstY * dst->bytes_per_line); | - | ||||||||||||||||||||||||||||||
| 1544 | for (int srcX = 0, dstX = dstX0; srcX < srcXEnd; ++srcX, dstX += dstXIncr) | - | ||||||||||||||||||||||||||||||
| 1545 | std::swap(srcPtr[srcX], dstPtr[dstX]); | - | ||||||||||||||||||||||||||||||
| 1546 | } | - | ||||||||||||||||||||||||||||||
| 1547 | - | |||||||||||||||||||||||||||||||
| 1548 | if (dstX0 && dstY0 && (h & 1)) { | - | ||||||||||||||||||||||||||||||
| 1549 | int srcY = h / 2; | - | ||||||||||||||||||||||||||||||
| 1550 | int srcXEnd2 = w / 2; | - | ||||||||||||||||||||||||||||||
| 1551 | T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line); | - | ||||||||||||||||||||||||||||||
| 1552 | for (int srcX = 0, dstX = dstX0; srcX < srcXEnd2; ++srcX, dstX += dstXIncr) | - | ||||||||||||||||||||||||||||||
| 1553 | std::swap(srcPtr[srcX], srcPtr[dstX]); | - | ||||||||||||||||||||||||||||||
| 1554 | } | - | ||||||||||||||||||||||||||||||
| 1555 | } else { | - | ||||||||||||||||||||||||||||||
| 1556 | for (int srcY = 0, dstY = dstY0; srcY < h; ++srcY, dstY += dstYIncr) { | - | ||||||||||||||||||||||||||||||
| 1557 | T *srcPtr = (T *) (src->data + srcY * src->bytes_per_line); | - | ||||||||||||||||||||||||||||||
| 1558 | T *dstPtr = (T *) (dst->data + dstY * dst->bytes_per_line); | - | ||||||||||||||||||||||||||||||
| 1559 | for (int srcX = 0, dstX = dstX0; srcX < w; ++srcX, dstX += dstXIncr) | - | ||||||||||||||||||||||||||||||
| 1560 | dstPtr[dstX] = srcPtr[srcX]; | - | ||||||||||||||||||||||||||||||
| 1561 | } | - | ||||||||||||||||||||||||||||||
| 1562 | } | - | ||||||||||||||||||||||||||||||
| 1563 | } | - | ||||||||||||||||||||||||||||||
| 1564 | - | |||||||||||||||||||||||||||||||
| 1565 | inline void do_mirror(QImageData *dst, QImageData *src, bool horizontal, bool vertical) | - | ||||||||||||||||||||||||||||||
| 1566 | { | - | ||||||||||||||||||||||||||||||
| 1567 | ((!(src->width == dst->width && src->height == dst->height && src->depth == dst->depth)) ? qt_assert("src->width == dst->width && src->height == dst->height && src->depth == dst->depth",__FILE__,30013020) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 1568 | int w = src->width; | - | ||||||||||||||||||||||||||||||
| 1569 | int h = src->height; | - | ||||||||||||||||||||||||||||||
| 1570 | int depth = src->depth; | - | ||||||||||||||||||||||||||||||
| 1571 | - | |||||||||||||||||||||||||||||||
| 1572 | if (src->depth == 1) { | - | ||||||||||||||||||||||||||||||
| 1573 | w = (w + 7) / 8; | - | ||||||||||||||||||||||||||||||
| 1574 | depth = 8; | - | ||||||||||||||||||||||||||||||
| 1575 | } | - | ||||||||||||||||||||||||||||||
| 1576 | - | |||||||||||||||||||||||||||||||
| 1577 | int dstX0 = 0, dstXIncr = 1; | - | ||||||||||||||||||||||||||||||
| 1578 | int dstY0 = 0, dstYIncr = 1; | - | ||||||||||||||||||||||||||||||
| 1579 | if (horizontal) { | - | ||||||||||||||||||||||||||||||
| 1580 | - | |||||||||||||||||||||||||||||||
| 1581 | dstX0 = w - 1; | - | ||||||||||||||||||||||||||||||
| 1582 | dstXIncr = -1; | - | ||||||||||||||||||||||||||||||
| 1583 | } | - | ||||||||||||||||||||||||||||||
| 1584 | if (vertical) { | - | ||||||||||||||||||||||||||||||
| 1585 | - | |||||||||||||||||||||||||||||||
| 1586 | dstY0 = h - 1; | - | ||||||||||||||||||||||||||||||
| 1587 | dstYIncr = -1; | - | ||||||||||||||||||||||||||||||
| 1588 | } | - | ||||||||||||||||||||||||||||||
| 1589 | - | |||||||||||||||||||||||||||||||
| 1590 | switch (depth) { | - | ||||||||||||||||||||||||||||||
| 1591 | case 32: | - | ||||||||||||||||||||||||||||||
| 1592 | do_mirror_data<quint32>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h); | - | ||||||||||||||||||||||||||||||
| 1593 | break; | - | ||||||||||||||||||||||||||||||
| 1594 | case 24: | - | ||||||||||||||||||||||||||||||
| 1595 | do_mirror_data<quint24>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h); | - | ||||||||||||||||||||||||||||||
| 1596 | break; | - | ||||||||||||||||||||||||||||||
| 1597 | case 16: | - | ||||||||||||||||||||||||||||||
| 1598 | do_mirror_data<quint16>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h); | - | ||||||||||||||||||||||||||||||
| 1599 | break; | - | ||||||||||||||||||||||||||||||
| 1600 | case 8: | - | ||||||||||||||||||||||||||||||
| 1601 | do_mirror_data<quint8>(dst, src, dstX0, dstY0, dstXIncr, dstYIncr, w, h); | - | ||||||||||||||||||||||||||||||
| 1602 | break; | - | ||||||||||||||||||||||||||||||
| 1603 | default: | - | ||||||||||||||||||||||||||||||
| 1604 | ((!(false)) ? qt_assert("false",__FILE__,30383057) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 1605 | break; | - | ||||||||||||||||||||||||||||||
| 1606 | } | - | ||||||||||||||||||||||||||||||
| 1607 | - | |||||||||||||||||||||||||||||||
| 1608 | - | |||||||||||||||||||||||||||||||
| 1609 | - | |||||||||||||||||||||||||||||||
| 1610 | if (horizontal && dst->depth == 1) { | - | ||||||||||||||||||||||||||||||
| 1611 | ((!(dst->format == QImage::Format_Mono || dst->format == QImage::Format_MonoLSB)) ? qt_assert("dst->format == QImage::Format_Mono || dst->format == QImage::Format_MonoLSB",__FILE__,30453064) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 1612 | const int shift = 8 - (dst->width % 8); | - | ||||||||||||||||||||||||||||||
| 1613 | const uchar *bitflip = qt_get_bitflip_array(); | - | ||||||||||||||||||||||||||||||
| 1614 | for (int y = 0; y < h; ++y) { | - | ||||||||||||||||||||||||||||||
| 1615 | uchar *begin = dst->data + y * dst->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 1616 | uchar *end = begin + dst->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 1617 | for (uchar *p = begin; p < end; ++p) { | - | ||||||||||||||||||||||||||||||
| 1618 | *p = bitflip[*p]; | - | ||||||||||||||||||||||||||||||
| 1619 | - | |||||||||||||||||||||||||||||||
| 1620 | - | |||||||||||||||||||||||||||||||
| 1621 | if (shift != 8 && p != begin) { | - | ||||||||||||||||||||||||||||||
| 1622 | if (dst->format == QImage::Format_Mono) { | - | ||||||||||||||||||||||||||||||
| 1623 | for (int i = 0; i < shift; ++i) { | - | ||||||||||||||||||||||||||||||
| 1624 | p[-1] <<= 1; | - | ||||||||||||||||||||||||||||||
| 1625 | p[-1] |= (*p & (128 >> i)) >> (7 - i); | - | ||||||||||||||||||||||||||||||
| 1626 | } | - | ||||||||||||||||||||||||||||||
| 1627 | } else { | - | ||||||||||||||||||||||||||||||
| 1628 | for (int i = 0; i < shift; ++i) { | - | ||||||||||||||||||||||||||||||
| 1629 | p[-1] >>= 1; | - | ||||||||||||||||||||||||||||||
| 1630 | p[-1] |= (*p & (1 << i)) << (7 - i); | - | ||||||||||||||||||||||||||||||
| 1631 | } | - | ||||||||||||||||||||||||||||||
| 1632 | } | - | ||||||||||||||||||||||||||||||
| 1633 | } | - | ||||||||||||||||||||||||||||||
| 1634 | } | - | ||||||||||||||||||||||||||||||
| 1635 | if (shift != 8) { | - | ||||||||||||||||||||||||||||||
| 1636 | if (dst->format == QImage::Format_Mono) | - | ||||||||||||||||||||||||||||||
| 1637 | end[-1] <<= shift; | - | ||||||||||||||||||||||||||||||
| 1638 | else | - | ||||||||||||||||||||||||||||||
| 1639 | end[-1] >>= shift; | - | ||||||||||||||||||||||||||||||
| 1640 | } | - | ||||||||||||||||||||||||||||||
| 1641 | } | - | ||||||||||||||||||||||||||||||
| 1642 | } | - | ||||||||||||||||||||||||||||||
| 1643 | } | - | ||||||||||||||||||||||||||||||
| 1644 | - | |||||||||||||||||||||||||||||||
| 1645 | - | |||||||||||||||||||||||||||||||
| 1646 | - | |||||||||||||||||||||||||||||||
| 1647 | - | |||||||||||||||||||||||||||||||
| 1648 | QImage QImage::mirrored_helper(bool horizontal, bool vertical) const | - | ||||||||||||||||||||||||||||||
| 1649 | { | - | ||||||||||||||||||||||||||||||
| 1650 | if (!d) | - | ||||||||||||||||||||||||||||||
| 1651 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 1652 | - | |||||||||||||||||||||||||||||||
| 1653 | if ((d->width <= 1 && d->height <= 1) || (!horizontal && !vertical)) | - | ||||||||||||||||||||||||||||||
| 1654 | return *this; | - | ||||||||||||||||||||||||||||||
| 1655 | - | |||||||||||||||||||||||||||||||
| 1656 | - | |||||||||||||||||||||||||||||||
| 1657 | QImage result(d->width, d->height, d->format); | - | ||||||||||||||||||||||||||||||
| 1658 | if ((result).isNull()) { QMessageLogger(__FILE__, 30923111, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - | ||||||||||||||||||||||||||||||
| 1659 | - | |||||||||||||||||||||||||||||||
| 1660 | - | |||||||||||||||||||||||||||||||
| 1661 | if (!result.d) | - | ||||||||||||||||||||||||||||||
| 1662 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 1663 | - | |||||||||||||||||||||||||||||||
| 1664 | result.d->colortable = d->colortable; | - | ||||||||||||||||||||||||||||||
| 1665 | result.d->has_alpha_clut = d->has_alpha_clut; | - | ||||||||||||||||||||||||||||||
| 1666 | copyMetadata(result.d, d); | - | ||||||||||||||||||||||||||||||
| 1667 | - | |||||||||||||||||||||||||||||||
| 1668 | do_mirror(result.d, d, horizontal, vertical); | - | ||||||||||||||||||||||||||||||
| 1669 | - | |||||||||||||||||||||||||||||||
| 1670 | return result; | - | ||||||||||||||||||||||||||||||
| 1671 | } | - | ||||||||||||||||||||||||||||||
| 1672 | - | |||||||||||||||||||||||||||||||
| 1673 | - | |||||||||||||||||||||||||||||||
| 1674 | - | |||||||||||||||||||||||||||||||
| 1675 | - | |||||||||||||||||||||||||||||||
| 1676 | void QImage::mirrored_inplace(bool horizontal, bool vertical) | - | ||||||||||||||||||||||||||||||
| 1677 | { | - | ||||||||||||||||||||||||||||||
| 1678 | if (!d || (d->width <= 1 && d->height <= 1) || (!horizontal && !vertical)) | - | ||||||||||||||||||||||||||||||
| 1679 | return; | - | ||||||||||||||||||||||||||||||
| 1680 | - | |||||||||||||||||||||||||||||||
| 1681 | detach(); | - | ||||||||||||||||||||||||||||||
| 1682 | if (!d->own_data) | - | ||||||||||||||||||||||||||||||
| 1683 | *this = copy(); | - | ||||||||||||||||||||||||||||||
| 1684 | - | |||||||||||||||||||||||||||||||
| 1685 | do_mirror(d, d, horizontal, vertical); | - | ||||||||||||||||||||||||||||||
| 1686 | } | - | ||||||||||||||||||||||||||||||
| 1687 | inline void rgbSwapped_generic(int width, int height, const QImage *src, QImage *dst, const QPixelLayout* layout) | - | ||||||||||||||||||||||||||||||
| 1688 | { | - | ||||||||||||||||||||||||||||||
| 1689 | ((!(layout->redWidth == layout->blueWidth)) ? qt_assert("layout->redWidth == layout->blueWidth",__FILE__,31353154) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 1690 | FetchPixelsFunc fetch = qFetchPixels[layout->bpp]; | - | ||||||||||||||||||||||||||||||
| 1691 | StorePixelsFunc store = qStorePixels[layout->bpp]; | - | ||||||||||||||||||||||||||||||
| 1692 | - | |||||||||||||||||||||||||||||||
| 1693 | const uint redBlueMask = (1 << layout->redWidth) - 1; | - | ||||||||||||||||||||||||||||||
| 1694 | const uint alphaGreenMask = (((1 << layout->alphaWidth) - 1) << layout->alphaShift) | - | ||||||||||||||||||||||||||||||
| 1695 | | (((1 << layout->greenWidth) - 1) << layout->greenShift); | - | ||||||||||||||||||||||||||||||
| 1696 | - | |||||||||||||||||||||||||||||||
| 1697 | const int buffer_size = 2048; | - | ||||||||||||||||||||||||||||||
| 1698 | uint buffer[buffer_size]; | - | ||||||||||||||||||||||||||||||
| 1699 | for (int i = 0; i < height; ++i) { | - | ||||||||||||||||||||||||||||||
| 1700 | uchar *q = dst->scanLine(i); | - | ||||||||||||||||||||||||||||||
| 1701 | const uchar *p = src->constScanLine(i); | - | ||||||||||||||||||||||||||||||
| 1702 | int x = 0; | - | ||||||||||||||||||||||||||||||
| 1703 | while (x < width) { | - | ||||||||||||||||||||||||||||||
| 1704 | int l = qMin(width - x, buffer_size); | - | ||||||||||||||||||||||||||||||
| 1705 | const uint *ptr = fetch(buffer, p, x, l); | - | ||||||||||||||||||||||||||||||
| 1706 | for (int j = 0; j < l; ++j) { | - | ||||||||||||||||||||||||||||||
| 1707 | uint red = (ptr[j] >> layout->redShift) & redBlueMask; | - | ||||||||||||||||||||||||||||||
| 1708 | uint blue = (ptr[j] >> layout->blueShift) & redBlueMask; | - | ||||||||||||||||||||||||||||||
| 1709 | buffer[j] = (ptr[j] & alphaGreenMask) | - | ||||||||||||||||||||||||||||||
| 1710 | | (red << layout->blueShift) | - | ||||||||||||||||||||||||||||||
| 1711 | | (blue << layout->redShift); | - | ||||||||||||||||||||||||||||||
| 1712 | } | - | ||||||||||||||||||||||||||||||
| 1713 | store(q, buffer, x, l); | - | ||||||||||||||||||||||||||||||
| 1714 | x += l; | - | ||||||||||||||||||||||||||||||
| 1715 | } | - | ||||||||||||||||||||||||||||||
| 1716 | } | - | ||||||||||||||||||||||||||||||
| 1717 | } | - | ||||||||||||||||||||||||||||||
| 1718 | - | |||||||||||||||||||||||||||||||
| 1719 | - | |||||||||||||||||||||||||||||||
| 1720 | - | |||||||||||||||||||||||||||||||
| 1721 | - | |||||||||||||||||||||||||||||||
| 1722 | QImage QImage::rgbSwapped_helper() const | - | ||||||||||||||||||||||||||||||
| 1723 | { | - | ||||||||||||||||||||||||||||||
| 1724 | if (isNull()) | - | ||||||||||||||||||||||||||||||
| 1725 | return *this; | - | ||||||||||||||||||||||||||||||
| 1726 | - | |||||||||||||||||||||||||||||||
| 1727 | QImage res; | - | ||||||||||||||||||||||||||||||
| 1728 | - | |||||||||||||||||||||||||||||||
| 1729 | switch (d->format) { | - | ||||||||||||||||||||||||||||||
| 1730 | case Format_Invalid: | - | ||||||||||||||||||||||||||||||
| 1731 | case NImageFormats: | - | ||||||||||||||||||||||||||||||
| 1732 | ((!(false)) ? qt_assert("false",__FILE__,31783197) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 1733 | break; | - | ||||||||||||||||||||||||||||||
| 1734 | case Format_Alpha8: | - | ||||||||||||||||||||||||||||||
| 1735 | case Format_Grayscale8: | - | ||||||||||||||||||||||||||||||
| 1736 | return *this; | - | ||||||||||||||||||||||||||||||
| 1737 | case Format_Mono: | - | ||||||||||||||||||||||||||||||
| 1738 | case Format_MonoLSB: | - | ||||||||||||||||||||||||||||||
| 1739 | case Format_Indexed8: | - | ||||||||||||||||||||||||||||||
| 1740 | res = copy(); | - | ||||||||||||||||||||||||||||||
| 1741 | for (int i = 0; i < res.d->colortable.size(); i++) { | - | ||||||||||||||||||||||||||||||
| 1742 | QRgb c = res.d->colortable.at(i); | - | ||||||||||||||||||||||||||||||
| 1743 | res.d->colortable[i] = QRgb(((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00)); | - | ||||||||||||||||||||||||||||||
| 1744 | } | - | ||||||||||||||||||||||||||||||
| 1745 | break; | - | ||||||||||||||||||||||||||||||
| 1746 | case Format_RGB32: | - | ||||||||||||||||||||||||||||||
| 1747 | case Format_ARGB32: | - | ||||||||||||||||||||||||||||||
| 1748 | case Format_ARGB32_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1749 | - | |||||||||||||||||||||||||||||||
| 1750 | case Format_RGBX8888: | - | ||||||||||||||||||||||||||||||
| 1751 | case Format_RGBA8888: | - | ||||||||||||||||||||||||||||||
| 1752 | case Format_RGBA8888_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1753 | - | |||||||||||||||||||||||||||||||
| 1754 | res = QImage(d->width, d->height, d->format); | - | ||||||||||||||||||||||||||||||
| 1755 | if ((res).isNull()) { QMessageLogger(__FILE__, 32013220, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - | ||||||||||||||||||||||||||||||
| 1756 | for (int i = 0; i < d->height; i++) { | - | ||||||||||||||||||||||||||||||
| 1757 | uint *q = (uint*)res.scanLine(i); | - | ||||||||||||||||||||||||||||||
| 1758 | const uint *p = (const uint*)constScanLine(i); | - | ||||||||||||||||||||||||||||||
| 1759 | const uint *end = p + d->width; | - | ||||||||||||||||||||||||||||||
| 1760 | while (p < end) { | - | ||||||||||||||||||||||||||||||
| 1761 | uint c = *p; | - | ||||||||||||||||||||||||||||||
| 1762 | *q = ((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00); | - | ||||||||||||||||||||||||||||||
| 1763 | p++; | - | ||||||||||||||||||||||||||||||
| 1764 | q++; | - | ||||||||||||||||||||||||||||||
| 1765 | } | - | ||||||||||||||||||||||||||||||
| 1766 | } | - | ||||||||||||||||||||||||||||||
| 1767 | break; | - | ||||||||||||||||||||||||||||||
| 1768 | case Format_RGB16: | - | ||||||||||||||||||||||||||||||
| 1769 | res = QImage(d->width, d->height, d->format); | - | ||||||||||||||||||||||||||||||
| 1770 | if ((res).isNull()) { QMessageLogger(__FILE__, 32163235, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - | ||||||||||||||||||||||||||||||
| 1771 | for (int i = 0; i < d->height; i++) { | - | ||||||||||||||||||||||||||||||
| 1772 | ushort *q = (ushort*)res.scanLine(i); | - | ||||||||||||||||||||||||||||||
| 1773 | const ushort *p = (const ushort*)constScanLine(i); | - | ||||||||||||||||||||||||||||||
| 1774 | const ushort *end = p + d->width; | - | ||||||||||||||||||||||||||||||
| 1775 | while (p < end) { | - | ||||||||||||||||||||||||||||||
| 1776 | ushort c = *p; | - | ||||||||||||||||||||||||||||||
| 1777 | *q = ((c << 11) & 0xf800) | ((c >> 11) & 0x1f) | (c & 0x07e0); | - | ||||||||||||||||||||||||||||||
| 1778 | p++; | - | ||||||||||||||||||||||||||||||
| 1779 | q++; | - | ||||||||||||||||||||||||||||||
| 1780 | } | - | ||||||||||||||||||||||||||||||
| 1781 | } | - | ||||||||||||||||||||||||||||||
| 1782 | break; | - | ||||||||||||||||||||||||||||||
| 1783 | case Format_BGR30: | - | ||||||||||||||||||||||||||||||
| 1784 | case Format_A2BGR30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1785 | case Format_RGB30: | - | ||||||||||||||||||||||||||||||
| 1786 | case Format_A2RGB30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1787 | res = QImage(d->width, d->height, d->format); | - | ||||||||||||||||||||||||||||||
| 1788 | if ((res).isNull()) { QMessageLogger(__FILE__, 32343253, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - | ||||||||||||||||||||||||||||||
| 1789 | for (int i = 0; i < d->height; i++) { | - | ||||||||||||||||||||||||||||||
| 1790 | uint *q = (uint*)res.scanLine(i); | - | ||||||||||||||||||||||||||||||
| 1791 | const uint *p = (const uint*)constScanLine(i); | - | ||||||||||||||||||||||||||||||
| 1792 | const uint *end = p + d->width; | - | ||||||||||||||||||||||||||||||
| 1793 | while (p < end) { | - | ||||||||||||||||||||||||||||||
| 1794 | *q = qRgbSwapRgb30(*p); | - | ||||||||||||||||||||||||||||||
| 1795 | p++; | - | ||||||||||||||||||||||||||||||
| 1796 | q++; | - | ||||||||||||||||||||||||||||||
| 1797 | } | - | ||||||||||||||||||||||||||||||
| 1798 | } | - | ||||||||||||||||||||||||||||||
| 1799 | break; | - | ||||||||||||||||||||||||||||||
| 1800 | default: | - | ||||||||||||||||||||||||||||||
| 1801 | res = QImage(d->width, d->height, d->format); | - | ||||||||||||||||||||||||||||||
| 1802 | rgbSwapped_generic(d->width, d->height, this, &res, &qPixelLayouts[d->format]); | - | ||||||||||||||||||||||||||||||
| 1803 | break; | - | ||||||||||||||||||||||||||||||
| 1804 | } | - | ||||||||||||||||||||||||||||||
| 1805 | copyMetadata(res.d, d); | - | ||||||||||||||||||||||||||||||
| 1806 | return res; | - | ||||||||||||||||||||||||||||||
| 1807 | } | - | ||||||||||||||||||||||||||||||
| 1808 | - | |||||||||||||||||||||||||||||||
| 1809 | - | |||||||||||||||||||||||||||||||
| 1810 | - | |||||||||||||||||||||||||||||||
| 1811 | - | |||||||||||||||||||||||||||||||
| 1812 | void QImage::rgbSwapped_inplace() | - | ||||||||||||||||||||||||||||||
| 1813 | { | - | ||||||||||||||||||||||||||||||
| 1814 | if (isNull()) | - | ||||||||||||||||||||||||||||||
| 1815 | return; | - | ||||||||||||||||||||||||||||||
| 1816 | - | |||||||||||||||||||||||||||||||
| 1817 | detach(); | - | ||||||||||||||||||||||||||||||
| 1818 | if (!d->own_data) | - | ||||||||||||||||||||||||||||||
| 1819 | *this = copy(); | - | ||||||||||||||||||||||||||||||
| 1820 | - | |||||||||||||||||||||||||||||||
| 1821 | switch (d->format) { | - | ||||||||||||||||||||||||||||||
| 1822 | case Format_Invalid: | - | ||||||||||||||||||||||||||||||
| 1823 | case NImageFormats: | - | ||||||||||||||||||||||||||||||
| 1824 | ((!(false)) ? qt_assert("false",__FILE__,32703289) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 1825 | break; | - | ||||||||||||||||||||||||||||||
| 1826 | case Format_Alpha8: | - | ||||||||||||||||||||||||||||||
| 1827 | case Format_Grayscale8: | - | ||||||||||||||||||||||||||||||
| 1828 | return; | - | ||||||||||||||||||||||||||||||
| 1829 | case Format_Mono: | - | ||||||||||||||||||||||||||||||
| 1830 | case Format_MonoLSB: | - | ||||||||||||||||||||||||||||||
| 1831 | case Format_Indexed8: | - | ||||||||||||||||||||||||||||||
| 1832 | for (int i = 0; i < d->colortable.size(); i++) { | - | ||||||||||||||||||||||||||||||
| 1833 | QRgb c = d->colortable.at(i); | - | ||||||||||||||||||||||||||||||
| 1834 | d->colortable[i] = QRgb(((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00)); | - | ||||||||||||||||||||||||||||||
| 1835 | } | - | ||||||||||||||||||||||||||||||
| 1836 | break; | - | ||||||||||||||||||||||||||||||
| 1837 | case Format_RGB32: | - | ||||||||||||||||||||||||||||||
| 1838 | case Format_ARGB32: | - | ||||||||||||||||||||||||||||||
| 1839 | case Format_ARGB32_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1840 | - | |||||||||||||||||||||||||||||||
| 1841 | case Format_RGBX8888: | - | ||||||||||||||||||||||||||||||
| 1842 | case Format_RGBA8888: | - | ||||||||||||||||||||||||||||||
| 1843 | case Format_RGBA8888_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1844 | - | |||||||||||||||||||||||||||||||
| 1845 | for (int i = 0; i < d->height; i++) { | - | ||||||||||||||||||||||||||||||
| 1846 | uint *p = (uint*)scanLine(i); | - | ||||||||||||||||||||||||||||||
| 1847 | uint *end = p + d->width; | - | ||||||||||||||||||||||||||||||
| 1848 | while (p < end) { | - | ||||||||||||||||||||||||||||||
| 1849 | uint c = *p; | - | ||||||||||||||||||||||||||||||
| 1850 | *p = ((c << 16) & 0xff0000) | ((c >> 16) & 0xff) | (c & 0xff00ff00); | - | ||||||||||||||||||||||||||||||
| 1851 | p++; | - | ||||||||||||||||||||||||||||||
| 1852 | } | - | ||||||||||||||||||||||||||||||
| 1853 | } | - | ||||||||||||||||||||||||||||||
| 1854 | break; | - | ||||||||||||||||||||||||||||||
| 1855 | case Format_RGB16: | - | ||||||||||||||||||||||||||||||
| 1856 | for (int i = 0; i < d->height; i++) { | - | ||||||||||||||||||||||||||||||
| 1857 | ushort *p = (ushort*)scanLine(i); | - | ||||||||||||||||||||||||||||||
| 1858 | ushort *end = p + d->width; | - | ||||||||||||||||||||||||||||||
| 1859 | while (p < end) { | - | ||||||||||||||||||||||||||||||
| 1860 | ushort c = *p; | - | ||||||||||||||||||||||||||||||
| 1861 | *p = ((c << 11) & 0xf800) | ((c >> 11) & 0x1f) | (c & 0x07e0); | - | ||||||||||||||||||||||||||||||
| 1862 | p++; | - | ||||||||||||||||||||||||||||||
| 1863 | } | - | ||||||||||||||||||||||||||||||
| 1864 | } | - | ||||||||||||||||||||||||||||||
| 1865 | break; | - | ||||||||||||||||||||||||||||||
| 1866 | case Format_BGR30: | - | ||||||||||||||||||||||||||||||
| 1867 | case Format_A2BGR30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1868 | case Format_RGB30: | - | ||||||||||||||||||||||||||||||
| 1869 | case Format_A2RGB30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 1870 | for (int i = 0; i < d->height; i++) { | - | ||||||||||||||||||||||||||||||
| 1871 | uint *p = (uint*)scanLine(i); | - | ||||||||||||||||||||||||||||||
| 1872 | uint *end = p + d->width; | - | ||||||||||||||||||||||||||||||
| 1873 | while (p < end) { | - | ||||||||||||||||||||||||||||||
| 1874 | *p = qRgbSwapRgb30(*p); | - | ||||||||||||||||||||||||||||||
| 1875 | p++; | - | ||||||||||||||||||||||||||||||
| 1876 | } | - | ||||||||||||||||||||||||||||||
| 1877 | } | - | ||||||||||||||||||||||||||||||
| 1878 | break; | - | ||||||||||||||||||||||||||||||
| 1879 | default: | - | ||||||||||||||||||||||||||||||
| 1880 | rgbSwapped_generic(d->width, d->height, this, this, &qPixelLayouts[d->format]); | - | ||||||||||||||||||||||||||||||
| 1881 | break; | - | ||||||||||||||||||||||||||||||
| 1882 | } | - | ||||||||||||||||||||||||||||||
| 1883 | } | - | ||||||||||||||||||||||||||||||
| 1884 | bool QImage::load(const QString &fileName, const char* format) | - | ||||||||||||||||||||||||||||||
| 1885 | { | - | ||||||||||||||||||||||||||||||
| 1886 | QImage image = QImageReader(fileName, format).read(); | - | ||||||||||||||||||||||||||||||
| 1887 | operator=(image); | - | ||||||||||||||||||||||||||||||
| 1888 | return !isNull(); | - | ||||||||||||||||||||||||||||||
| 1889 | } | - | ||||||||||||||||||||||||||||||
| 1890 | bool QImage::load(QIODevice* device, const char* format) | - | ||||||||||||||||||||||||||||||
| 1891 | { | - | ||||||||||||||||||||||||||||||
| 1892 | QImage image = QImageReader(device, format).read(); | - | ||||||||||||||||||||||||||||||
| 1893 | operator=(image); | - | ||||||||||||||||||||||||||||||
| 1894 | return !isNull(); | - | ||||||||||||||||||||||||||||||
| 1895 | } | - | ||||||||||||||||||||||||||||||
| 1896 | bool QImage::loadFromData(const uchar *data, int len, const char *format) | - | ||||||||||||||||||||||||||||||
| 1897 | { | - | ||||||||||||||||||||||||||||||
| 1898 | QImage image = fromData(data, len, format); | - | ||||||||||||||||||||||||||||||
| 1899 | operator=(image); | - | ||||||||||||||||||||||||||||||
| 1900 | return !isNull(); | - | ||||||||||||||||||||||||||||||
| 1901 | } | - | ||||||||||||||||||||||||||||||
| 1902 | QImage QImage::fromData(const uchar *data, int size, const char *format) | - | ||||||||||||||||||||||||||||||
| 1903 | { | - | ||||||||||||||||||||||||||||||
| 1904 | QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(data), size); | - | ||||||||||||||||||||||||||||||
| 1905 | QBuffer b; | - | ||||||||||||||||||||||||||||||
| 1906 | b.setData(a); | - | ||||||||||||||||||||||||||||||
| 1907 | b.open(QIODevice::ReadOnly); | - | ||||||||||||||||||||||||||||||
| 1908 | return QImageReader(&b, format).read(); | - | ||||||||||||||||||||||||||||||
| 1909 | } | - | ||||||||||||||||||||||||||||||
| 1910 | bool QImage::save(const QString &fileName, const char *format, int quality) const | - | ||||||||||||||||||||||||||||||
| 1911 | { | - | ||||||||||||||||||||||||||||||
| 1912 | if (isNull()) | - | ||||||||||||||||||||||||||||||
| 1913 | return false; | - | ||||||||||||||||||||||||||||||
| 1914 | QImageWriter writer(fileName, format); | - | ||||||||||||||||||||||||||||||
| 1915 | return d->doImageIO(this, &writer, quality); | - | ||||||||||||||||||||||||||||||
| 1916 | } | - | ||||||||||||||||||||||||||||||
| 1917 | bool QImage::save(QIODevice* device, const char* format, int quality) const | - | ||||||||||||||||||||||||||||||
| 1918 | { | - | ||||||||||||||||||||||||||||||
| 1919 | if (isNull()) | - | ||||||||||||||||||||||||||||||
| 1920 | return false; | - | ||||||||||||||||||||||||||||||
| 1921 | QImageWriter writer(device, format); | - | ||||||||||||||||||||||||||||||
| 1922 | return d->doImageIO(this, &writer, quality); | - | ||||||||||||||||||||||||||||||
| 1923 | } | - | ||||||||||||||||||||||||||||||
| 1924 | - | |||||||||||||||||||||||||||||||
| 1925 | - | |||||||||||||||||||||||||||||||
| 1926 | - | |||||||||||||||||||||||||||||||
| 1927 | - | |||||||||||||||||||||||||||||||
| 1928 | bool QImageData::doImageIO(const QImage *image, QImageWriter *writer, int quality) const | - | ||||||||||||||||||||||||||||||
| 1929 | { | - | ||||||||||||||||||||||||||||||
| 1930 | if (quality > 100 || quality < -1) | - | ||||||||||||||||||||||||||||||
| 1931 | QMessageLogger(__FILE__, 34853504, __PRETTY_FUNCTION__).warning("QPixmap::save: Quality out of range [-1, 100]"); | - | ||||||||||||||||||||||||||||||
| 1932 | if (quality >= 0) | - | ||||||||||||||||||||||||||||||
| 1933 | writer->setQuality(qMin(quality,100)); | - | ||||||||||||||||||||||||||||||
| 1934 | return writer->write(*image); | - | ||||||||||||||||||||||||||||||
| 1935 | } | - | ||||||||||||||||||||||||||||||
| 1936 | QDataStream &operator<<(QDataStream &s, const QImage &image) | - | ||||||||||||||||||||||||||||||
| 1937 | { | - | ||||||||||||||||||||||||||||||
| 1938 | if (s.version() >= 5) { | - | ||||||||||||||||||||||||||||||
| 1939 | if (image.isNull()) { | - | ||||||||||||||||||||||||||||||
| 1940 | s << (qint32) 0; | - | ||||||||||||||||||||||||||||||
| 1941 | return s; | - | ||||||||||||||||||||||||||||||
| 1942 | } else { | - | ||||||||||||||||||||||||||||||
| 1943 | s << (qint32) 1; | - | ||||||||||||||||||||||||||||||
| 1944 | - | |||||||||||||||||||||||||||||||
| 1945 | } | - | ||||||||||||||||||||||||||||||
| 1946 | } | - | ||||||||||||||||||||||||||||||
| 1947 | QImageWriter writer(s.device(), s.version() == 1 ? "bmp" : "png"); | - | ||||||||||||||||||||||||||||||
| 1948 | writer.write(image); | - | ||||||||||||||||||||||||||||||
| 1949 | return s; | - | ||||||||||||||||||||||||||||||
| 1950 | } | - | ||||||||||||||||||||||||||||||
| 1951 | QDataStream &operator>>(QDataStream &s, QImage &image) | - | ||||||||||||||||||||||||||||||
| 1952 | { | - | ||||||||||||||||||||||||||||||
| 1953 | if (s.version() >= 5) { | - | ||||||||||||||||||||||||||||||
| 1954 | qint32 nullMarker; | - | ||||||||||||||||||||||||||||||
| 1955 | s >> nullMarker; | - | ||||||||||||||||||||||||||||||
| 1956 | if (!nullMarker) { | - | ||||||||||||||||||||||||||||||
| 1957 | image = QImage(); | - | ||||||||||||||||||||||||||||||
| 1958 | return s; | - | ||||||||||||||||||||||||||||||
| 1959 | } | - | ||||||||||||||||||||||||||||||
| 1960 | } | - | ||||||||||||||||||||||||||||||
| 1961 | image = QImageReader(s.device(), 0).read(); | - | ||||||||||||||||||||||||||||||
| 1962 | return s; | - | ||||||||||||||||||||||||||||||
| 1963 | } | - | ||||||||||||||||||||||||||||||
| 1964 | bool QImage::operator==(const QImage & i) const | - | ||||||||||||||||||||||||||||||
| 1965 | { | - | ||||||||||||||||||||||||||||||
| 1966 | - | |||||||||||||||||||||||||||||||
| 1967 | if (i.d == d) | - | ||||||||||||||||||||||||||||||
| 1968 | return true; | - | ||||||||||||||||||||||||||||||
| 1969 | if (!i.d || !d) | - | ||||||||||||||||||||||||||||||
| 1970 | return false; | - | ||||||||||||||||||||||||||||||
| 1971 | - | |||||||||||||||||||||||||||||||
| 1972 | - | |||||||||||||||||||||||||||||||
| 1973 | if (i.d->height != d->height || i.d->width != d->width || i.d->format != d->format) | - | ||||||||||||||||||||||||||||||
| 1974 | return false; | - | ||||||||||||||||||||||||||||||
| 1975 | - | |||||||||||||||||||||||||||||||
| 1976 | if (d->format != Format_RGB32) { | - | ||||||||||||||||||||||||||||||
| 1977 | if (d->format >= Format_ARGB32) { | - | ||||||||||||||||||||||||||||||
| 1978 | const int n = d->width * d->depth / 8; | - | ||||||||||||||||||||||||||||||
| 1979 | if (n == d->bytes_per_line && n == i.d->bytes_per_line) { | - | ||||||||||||||||||||||||||||||
| 1980 | if (memcmp(bits(), i.bits(), d->nbytes)) | - | ||||||||||||||||||||||||||||||
| 1981 | return false; | - | ||||||||||||||||||||||||||||||
| 1982 | } else { | - | ||||||||||||||||||||||||||||||
| 1983 | for (int y = 0; y < d->height; ++y) { | - | ||||||||||||||||||||||||||||||
| 1984 | if (memcmp(scanLine(y), i.scanLine(y), n)) | - | ||||||||||||||||||||||||||||||
| 1985 | return false; | - | ||||||||||||||||||||||||||||||
| 1986 | } | - | ||||||||||||||||||||||||||||||
| 1987 | } | - | ||||||||||||||||||||||||||||||
| 1988 | } else { | - | ||||||||||||||||||||||||||||||
| 1989 | const int w = width(); | - | ||||||||||||||||||||||||||||||
| 1990 | const int h = height(); | - | ||||||||||||||||||||||||||||||
| 1991 | const QVector<QRgb> &colortable = d->colortable; | - | ||||||||||||||||||||||||||||||
| 1992 | const QVector<QRgb> &icolortable = i.d->colortable; | - | ||||||||||||||||||||||||||||||
| 1993 | for (int y=0; y<h; ++y) { | - | ||||||||||||||||||||||||||||||
| 1994 | for (int x=0; x<w; ++x) { | - | ||||||||||||||||||||||||||||||
| 1995 | if (colortable[pixelIndex(x, y)] != icolortable[i.pixelIndex(x, y)]) | - | ||||||||||||||||||||||||||||||
| 1996 | return false; | - | ||||||||||||||||||||||||||||||
| 1997 | } | - | ||||||||||||||||||||||||||||||
| 1998 | } | - | ||||||||||||||||||||||||||||||
| 1999 | } | - | ||||||||||||||||||||||||||||||
| 2000 | } else { | - | ||||||||||||||||||||||||||||||
| 2001 | - | |||||||||||||||||||||||||||||||
| 2002 | for(int l = 0; l < d->height; l++) { | - | ||||||||||||||||||||||||||||||
| 2003 | int w = d->width; | - | ||||||||||||||||||||||||||||||
| 2004 | const uint *p1 = reinterpret_cast<const uint*>(scanLine(l)); | - | ||||||||||||||||||||||||||||||
| 2005 | const uint *p2 = reinterpret_cast<const uint*>(i.scanLine(l)); | - | ||||||||||||||||||||||||||||||
| 2006 | while (w--) { | - | ||||||||||||||||||||||||||||||
| 2007 | if ((*p1++ & 0x00ffffff) != (*p2++ & 0x00ffffff)) | - | ||||||||||||||||||||||||||||||
| 2008 | return false; | - | ||||||||||||||||||||||||||||||
| 2009 | } | - | ||||||||||||||||||||||||||||||
| 2010 | } | - | ||||||||||||||||||||||||||||||
| 2011 | } | - | ||||||||||||||||||||||||||||||
| 2012 | return true; | - | ||||||||||||||||||||||||||||||
| 2013 | } | - | ||||||||||||||||||||||||||||||
| 2014 | bool QImage::operator!=(const QImage & i) const | - | ||||||||||||||||||||||||||||||
| 2015 | { | - | ||||||||||||||||||||||||||||||
| 2016 | return !(*this == i); | - | ||||||||||||||||||||||||||||||
| 2017 | } | - | ||||||||||||||||||||||||||||||
| 2018 | int QImage::dotsPerMeterX() const | - | ||||||||||||||||||||||||||||||
| 2019 | { | - | ||||||||||||||||||||||||||||||
| 2020 | return d ? qRound(d->dpmx) : 0; | - | ||||||||||||||||||||||||||||||
| 2021 | } | - | ||||||||||||||||||||||||||||||
| 2022 | int QImage::dotsPerMeterY() const | - | ||||||||||||||||||||||||||||||
| 2023 | { | - | ||||||||||||||||||||||||||||||
| 2024 | return d ? qRound(d->dpmy) : 0; | - | ||||||||||||||||||||||||||||||
| 2025 | } | - | ||||||||||||||||||||||||||||||
| 2026 | void QImage::setDotsPerMeterX(int x) | - | ||||||||||||||||||||||||||||||
| 2027 | { | - | ||||||||||||||||||||||||||||||
| 2028 | if (!d || !x) | - | ||||||||||||||||||||||||||||||
| 2029 | return; | - | ||||||||||||||||||||||||||||||
| 2030 | detach(); | - | ||||||||||||||||||||||||||||||
| 2031 | - | |||||||||||||||||||||||||||||||
| 2032 | if (d) | - | ||||||||||||||||||||||||||||||
| 2033 | d->dpmx = x; | - | ||||||||||||||||||||||||||||||
| 2034 | } | - | ||||||||||||||||||||||||||||||
| 2035 | void QImage::setDotsPerMeterY(int y) | - | ||||||||||||||||||||||||||||||
| 2036 | { | - | ||||||||||||||||||||||||||||||
| 2037 | if (!d || !y) | - | ||||||||||||||||||||||||||||||
| 2038 | return; | - | ||||||||||||||||||||||||||||||
| 2039 | detach(); | - | ||||||||||||||||||||||||||||||
| 2040 | - | |||||||||||||||||||||||||||||||
| 2041 | if (d) | - | ||||||||||||||||||||||||||||||
| 2042 | d->dpmy = y; | - | ||||||||||||||||||||||||||||||
| 2043 | } | - | ||||||||||||||||||||||||||||||
| 2044 | QPoint QImage::offset() const | - | ||||||||||||||||||||||||||||||
| 2045 | { | - | ||||||||||||||||||||||||||||||
| 2046 | return d ? d->offset : QPoint(); | - | ||||||||||||||||||||||||||||||
| 2047 | } | - | ||||||||||||||||||||||||||||||
| 2048 | void QImage::setOffset(const QPoint& p) | - | ||||||||||||||||||||||||||||||
| 2049 | { | - | ||||||||||||||||||||||||||||||
| 2050 | if (!d) | - | ||||||||||||||||||||||||||||||
| 2051 | return; | - | ||||||||||||||||||||||||||||||
| 2052 | detach(); | - | ||||||||||||||||||||||||||||||
| 2053 | - | |||||||||||||||||||||||||||||||
| 2054 | if (d) | - | ||||||||||||||||||||||||||||||
| 2055 | d->offset = p; | - | ||||||||||||||||||||||||||||||
| 2056 | } | - | ||||||||||||||||||||||||||||||
| 2057 | QStringList QImage::textKeys() const | - | ||||||||||||||||||||||||||||||
| 2058 | { | - | ||||||||||||||||||||||||||||||
| 2059 | return d ? QStringList(d->text.keys()) : QStringList(); | - | ||||||||||||||||||||||||||||||
| 2060 | } | - | ||||||||||||||||||||||||||||||
| 2061 | QString QImage::text(const QString &key) const | - | ||||||||||||||||||||||||||||||
| 2062 | { | - | ||||||||||||||||||||||||||||||
| 2063 | if (!d
| 0 | ||||||||||||||||||||||||||||||
| 2064 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||||||||||||||
| 2065 | - | |||||||||||||||||||||||||||||||
| 2066 | if (!key.isEmpty()
| 0 | ||||||||||||||||||||||||||||||
| 2067 | return never executed: d->text.value(key);return d->text.value(key);never executed: return d->text.value(key); | 0 | ||||||||||||||||||||||||||||||
| 2068 | - | |||||||||||||||||||||||||||||||
| 2069 | QString tmp; | - | ||||||||||||||||||||||||||||||
| 2070 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(auto it = d->text.keys())>::type> _container_((begin(), end = d->text.keys())); _container_.control && _container_.iend(); it
| 0 | ||||||||||||||||||||||||||||||
| 2071 | { | 0 | ||||||||||||||||||||||||||||||
| if (!tmp.isEmpty()) | ||||||||||||||||||||||||||||||||
| tmp += QLatin1String("\n\n");tmp += it.key() + QLatin1String(": ") + d->textit.value(key).().simplified(); never executed: tmp += it.key() + QLatin1String(": ") + it.value().simplified() + QLatin1String("\n\n"); | ||||||||||||||||||||||||||||||||
| } never executed: tmp += it.key() + QLatin1String(": ") + it.value().simplified() + QLatin1String("\n\n");never executed: () + QLatin1String("\n\n");tmp += it.key() + QLatin1String(": ") + it.value().simplified() + QLatin1String("\n\n");never executed: tmp += it.key() + QLatin1String(": ") + it.value().simplified() + QLatin1String("\n\n"); | ||||||||||||||||||||||||||||||||
| 2072 | if (!tmp.isEmpty()
| 0 | ||||||||||||||||||||||||||||||
| 2073 | tmp.chop(2); never executed: tmp.chop(2); | 0 | ||||||||||||||||||||||||||||||
| 2074 | return never executed: tmp;return tmp;never executed: return tmp; | 0 | ||||||||||||||||||||||||||||||
| 2075 | } | - | ||||||||||||||||||||||||||||||
| 2076 | void QImage::setText(const QString &key, const QString &value) | - | ||||||||||||||||||||||||||||||
| 2077 | { | - | ||||||||||||||||||||||||||||||
| 2078 | if (!d) | - | ||||||||||||||||||||||||||||||
| 2079 | return; | - | ||||||||||||||||||||||||||||||
| 2080 | detach(); | - | ||||||||||||||||||||||||||||||
| 2081 | - | |||||||||||||||||||||||||||||||
| 2082 | if (d) | - | ||||||||||||||||||||||||||||||
| 2083 | d->text.insert(key, value); | - | ||||||||||||||||||||||||||||||
| 2084 | } | - | ||||||||||||||||||||||||||||||
| 2085 | QPaintEngine *QImage::paintEngine() const | - | ||||||||||||||||||||||||||||||
| 2086 | { | - | ||||||||||||||||||||||||||||||
| 2087 | if (!d) | - | ||||||||||||||||||||||||||||||
| 2088 | return 0; | - | ||||||||||||||||||||||||||||||
| 2089 | - | |||||||||||||||||||||||||||||||
| 2090 | if (!d->paintEngine) { | - | ||||||||||||||||||||||||||||||
| 2091 | QPaintDevice *paintDevice = const_cast<QImage *>(this); | - | ||||||||||||||||||||||||||||||
| 2092 | QPaintEngine *paintEngine = 0; | - | ||||||||||||||||||||||||||||||
| 2093 | QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration(); | - | ||||||||||||||||||||||||||||||
| 2094 | if (platformIntegration) | - | ||||||||||||||||||||||||||||||
| 2095 | paintEngine = platformIntegration->createImagePaintEngine(paintDevice); | - | ||||||||||||||||||||||||||||||
| 2096 | d->paintEngine = paintEngine ? paintEngine : new QRasterPaintEngine(paintDevice); | - | ||||||||||||||||||||||||||||||
| 2097 | } | - | ||||||||||||||||||||||||||||||
| 2098 | - | |||||||||||||||||||||||||||||||
| 2099 | return d->paintEngine; | - | ||||||||||||||||||||||||||||||
| 2100 | } | - | ||||||||||||||||||||||||||||||
| 2101 | - | |||||||||||||||||||||||||||||||
| 2102 | - | |||||||||||||||||||||||||||||||
| 2103 | - | |||||||||||||||||||||||||||||||
| 2104 | - | |||||||||||||||||||||||||||||||
| 2105 | - | |||||||||||||||||||||||||||||||
| 2106 | - | |||||||||||||||||||||||||||||||
| 2107 | - | |||||||||||||||||||||||||||||||
| 2108 | int QImage::metric(PaintDeviceMetric metric) const | - | ||||||||||||||||||||||||||||||
| 2109 | { | - | ||||||||||||||||||||||||||||||
| 2110 | if (!d) | - | ||||||||||||||||||||||||||||||
| 2111 | return 0; | - | ||||||||||||||||||||||||||||||
| 2112 | - | |||||||||||||||||||||||||||||||
| 2113 | switch (metric) { | - | ||||||||||||||||||||||||||||||
| 2114 | case PdmWidth: | - | ||||||||||||||||||||||||||||||
| 2115 | return d->width; | - | ||||||||||||||||||||||||||||||
| 2116 | - | |||||||||||||||||||||||||||||||
| 2117 | case PdmHeight: | - | ||||||||||||||||||||||||||||||
| 2118 | return d->height; | - | ||||||||||||||||||||||||||||||
| 2119 | - | |||||||||||||||||||||||||||||||
| 2120 | case PdmWidthMM: | - | ||||||||||||||||||||||||||||||
| 2121 | return qRound(d->width * 1000 / d->dpmx); | - | ||||||||||||||||||||||||||||||
| 2122 | - | |||||||||||||||||||||||||||||||
| 2123 | case PdmHeightMM: | - | ||||||||||||||||||||||||||||||
| 2124 | return qRound(d->height * 1000 / d->dpmy); | - | ||||||||||||||||||||||||||||||
| 2125 | - | |||||||||||||||||||||||||||||||
| 2126 | case PdmNumColors: | - | ||||||||||||||||||||||||||||||
| 2127 | return d->colortable.size(); | - | ||||||||||||||||||||||||||||||
| 2128 | - | |||||||||||||||||||||||||||||||
| 2129 | case PdmDepth: | - | ||||||||||||||||||||||||||||||
| 2130 | return d->depth; | - | ||||||||||||||||||||||||||||||
| 2131 | - | |||||||||||||||||||||||||||||||
| 2132 | case PdmDpiX: | - | ||||||||||||||||||||||||||||||
| 2133 | return qRound(d->dpmx * 0.0254); | - | ||||||||||||||||||||||||||||||
| 2134 | break; dead code: break; | - | ||||||||||||||||||||||||||||||
| 2135 | - | |||||||||||||||||||||||||||||||
| 2136 | case PdmDpiY: | - | ||||||||||||||||||||||||||||||
| 2137 | return qRound(d->dpmy * 0.0254); | - | ||||||||||||||||||||||||||||||
| 2138 | break; dead code: break; | - | ||||||||||||||||||||||||||||||
| 2139 | - | |||||||||||||||||||||||||||||||
| 2140 | case PdmPhysicalDpiX: | - | ||||||||||||||||||||||||||||||
| 2141 | return qRound(d->dpmx * 0.0254); | - | ||||||||||||||||||||||||||||||
| 2142 | break; dead code: break; | - | ||||||||||||||||||||||||||||||
| 2143 | - | |||||||||||||||||||||||||||||||
| 2144 | case PdmPhysicalDpiY: | - | ||||||||||||||||||||||||||||||
| 2145 | return qRound(d->dpmy * 0.0254); | - | ||||||||||||||||||||||||||||||
| 2146 | break; dead code: break; | - | ||||||||||||||||||||||||||||||
| 2147 | - | |||||||||||||||||||||||||||||||
| 2148 | case PdmDevicePixelRatio: | - | ||||||||||||||||||||||||||||||
| 2149 | return d->devicePixelRatio; | - | ||||||||||||||||||||||||||||||
| 2150 | break; dead code: break; | - | ||||||||||||||||||||||||||||||
| 2151 | - | |||||||||||||||||||||||||||||||
| 2152 | case PdmDevicePixelRatioScaled: | - | ||||||||||||||||||||||||||||||
| 2153 | return d->devicePixelRatio * QPaintDevice::devicePixelRatioFScale(); | - | ||||||||||||||||||||||||||||||
| 2154 | break; dead code: break; | - | ||||||||||||||||||||||||||||||
| 2155 | - | |||||||||||||||||||||||||||||||
| 2156 | default: | - | ||||||||||||||||||||||||||||||
| 2157 | QMessageLogger(__FILE__, 39463964, __PRETTY_FUNCTION__).warning("QImage::metric(): Unhandled metric type %d", metric); | - | ||||||||||||||||||||||||||||||
| 2158 | break; | - | ||||||||||||||||||||||||||||||
| 2159 | } | - | ||||||||||||||||||||||||||||||
| 2160 | return 0; | - | ||||||||||||||||||||||||||||||
| 2161 | } | - | ||||||||||||||||||||||||||||||
| 2162 | bool qt_xForm_helper(const QTransform &trueMat, int xoffset, int type, int depth, | - | ||||||||||||||||||||||||||||||
| 2163 | uchar *dptr, int dbpl, int p_inc, int dHeight, | - | ||||||||||||||||||||||||||||||
| 2164 | const uchar *sptr, int sbpl, int sWidth, int sHeight) | - | ||||||||||||||||||||||||||||||
| 2165 | { | - | ||||||||||||||||||||||||||||||
| 2166 | int m11 = int(trueMat.m11()*4096.0); | - | ||||||||||||||||||||||||||||||
| 2167 | int m12 = int(trueMat.m12()*4096.0); | - | ||||||||||||||||||||||||||||||
| 2168 | int m21 = int(trueMat.m21()*4096.0); | - | ||||||||||||||||||||||||||||||
| 2169 | int m22 = int(trueMat.m22()*4096.0); | - | ||||||||||||||||||||||||||||||
| 2170 | int dx = qRound(trueMat.dx()*4096.0); | - | ||||||||||||||||||||||||||||||
| 2171 | int dy = qRound(trueMat.dy()*4096.0); | - | ||||||||||||||||||||||||||||||
| 2172 | - | |||||||||||||||||||||||||||||||
| 2173 | int m21ydx = dx + (xoffset<<16) + (m11 + m21) / 2; | - | ||||||||||||||||||||||||||||||
| 2174 | int m22ydy = dy + (m12 + m22) / 2; | - | ||||||||||||||||||||||||||||||
| 2175 | uint trigx; | - | ||||||||||||||||||||||||||||||
| 2176 | uint trigy; | - | ||||||||||||||||||||||||||||||
| 2177 | uint maxws = sWidth<<12; | - | ||||||||||||||||||||||||||||||
| 2178 | uint maxhs = sHeight<<12; | - | ||||||||||||||||||||||||||||||
| 2179 | - | |||||||||||||||||||||||||||||||
| 2180 | for (int y=0; y<dHeight; y++) { | - | ||||||||||||||||||||||||||||||
| 2181 | trigx = m21ydx; | - | ||||||||||||||||||||||||||||||
| 2182 | trigy = m22ydy; | - | ||||||||||||||||||||||||||||||
| 2183 | uchar *maxp = dptr + dbpl; | - | ||||||||||||||||||||||||||||||
| 2184 | if (depth != 1) { | - | ||||||||||||||||||||||||||||||
| 2185 | switch (depth) { | - | ||||||||||||||||||||||||||||||
| 2186 | case 8: | - | ||||||||||||||||||||||||||||||
| 2187 | while (dptr < maxp) { | - | ||||||||||||||||||||||||||||||
| 2188 | if (trigx < maxws && trigy < maxhs) | - | ||||||||||||||||||||||||||||||
| 2189 | *dptr = *(sptr+sbpl*(trigy>>12)+(trigx>>12)); | - | ||||||||||||||||||||||||||||||
| 2190 | trigx += m11; | - | ||||||||||||||||||||||||||||||
| 2191 | trigy += m12; | - | ||||||||||||||||||||||||||||||
| 2192 | dptr++; | - | ||||||||||||||||||||||||||||||
| 2193 | } | - | ||||||||||||||||||||||||||||||
| 2194 | break; | - | ||||||||||||||||||||||||||||||
| 2195 | - | |||||||||||||||||||||||||||||||
| 2196 | case 16: | - | ||||||||||||||||||||||||||||||
| 2197 | while (dptr < maxp) { | - | ||||||||||||||||||||||||||||||
| 2198 | if (trigx < maxws && trigy < maxhs) | - | ||||||||||||||||||||||||||||||
| 2199 | *((ushort*)dptr) = *((const ushort *)(sptr+sbpl*(trigy>>12) + | - | ||||||||||||||||||||||||||||||
| 2200 | ((trigx>>12)<<1))); | - | ||||||||||||||||||||||||||||||
| 2201 | trigx += m11; | - | ||||||||||||||||||||||||||||||
| 2202 | trigy += m12; | - | ||||||||||||||||||||||||||||||
| 2203 | dptr++; | - | ||||||||||||||||||||||||||||||
| 2204 | dptr++; | - | ||||||||||||||||||||||||||||||
| 2205 | } | - | ||||||||||||||||||||||||||||||
| 2206 | break; | - | ||||||||||||||||||||||||||||||
| 2207 | - | |||||||||||||||||||||||||||||||
| 2208 | case 24: | - | ||||||||||||||||||||||||||||||
| 2209 | while (dptr < maxp) { | - | ||||||||||||||||||||||||||||||
| 2210 | if (trigx < maxws && trigy < maxhs) { | - | ||||||||||||||||||||||||||||||
| 2211 | const uchar *p2 = sptr+sbpl*(trigy>>12) + ((trigx>>12)*3); | - | ||||||||||||||||||||||||||||||
| 2212 | dptr[0] = p2[0]; | - | ||||||||||||||||||||||||||||||
| 2213 | dptr[1] = p2[1]; | - | ||||||||||||||||||||||||||||||
| 2214 | dptr[2] = p2[2]; | - | ||||||||||||||||||||||||||||||
| 2215 | } | - | ||||||||||||||||||||||||||||||
| 2216 | trigx += m11; | - | ||||||||||||||||||||||||||||||
| 2217 | trigy += m12; | - | ||||||||||||||||||||||||||||||
| 2218 | dptr += 3; | - | ||||||||||||||||||||||||||||||
| 2219 | } | - | ||||||||||||||||||||||||||||||
| 2220 | break; | - | ||||||||||||||||||||||||||||||
| 2221 | - | |||||||||||||||||||||||||||||||
| 2222 | case 32: | - | ||||||||||||||||||||||||||||||
| 2223 | while (dptr < maxp) { | - | ||||||||||||||||||||||||||||||
| 2224 | if (trigx < maxws && trigy < maxhs) | - | ||||||||||||||||||||||||||||||
| 2225 | *((uint*)dptr) = *((const uint *)(sptr+sbpl*(trigy>>12) + | - | ||||||||||||||||||||||||||||||
| 2226 | ((trigx>>12)<<2))); | - | ||||||||||||||||||||||||||||||
| 2227 | trigx += m11; | - | ||||||||||||||||||||||||||||||
| 2228 | trigy += m12; | - | ||||||||||||||||||||||||||||||
| 2229 | dptr += 4; | - | ||||||||||||||||||||||||||||||
| 2230 | } | - | ||||||||||||||||||||||||||||||
| 2231 | break; | - | ||||||||||||||||||||||||||||||
| 2232 | - | |||||||||||||||||||||||||||||||
| 2233 | default: { | - | ||||||||||||||||||||||||||||||
| 2234 | return false; | - | ||||||||||||||||||||||||||||||
| 2235 | } | - | ||||||||||||||||||||||||||||||
| 2236 | } | - | ||||||||||||||||||||||||||||||
| 2237 | } else { | - | ||||||||||||||||||||||||||||||
| 2238 | switch (type) { | - | ||||||||||||||||||||||||||||||
| 2239 | case 0: | - | ||||||||||||||||||||||||||||||
| 2240 | while (dptr < maxp) { | - | ||||||||||||||||||||||||||||||
| 2241 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 128; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2242 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 64; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2243 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 32; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2244 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 16; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2245 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 8; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2246 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 4; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2247 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 2; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2248 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << (7-((trigx>>12)&7)))) *dptr |= 1; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2249 | dptr++; | - | ||||||||||||||||||||||||||||||
| 2250 | } | - | ||||||||||||||||||||||||||||||
| 2251 | break; | - | ||||||||||||||||||||||||||||||
| 2252 | case 1: | - | ||||||||||||||||||||||||||||||
| 2253 | while (dptr < maxp) { | - | ||||||||||||||||||||||||||||||
| 2254 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 1; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2255 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 2; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2256 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 4; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2257 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 8; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2258 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 16; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2259 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 32; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2260 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 64; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2261 | if (trigx < maxws && trigy < maxhs) { if (*(sptr+sbpl*(trigy>>12)+(trigx>>15)) & (1 << ((trigx>>12)&7))) *dptr |= 128; } trigx += m11; trigy += m12;; | - | ||||||||||||||||||||||||||||||
| 2262 | dptr++; | - | ||||||||||||||||||||||||||||||
| 2263 | } | - | ||||||||||||||||||||||||||||||
| 2264 | break; | - | ||||||||||||||||||||||||||||||
| 2265 | } | - | ||||||||||||||||||||||||||||||
| 2266 | } | - | ||||||||||||||||||||||||||||||
| 2267 | m21ydx += m21; | - | ||||||||||||||||||||||||||||||
| 2268 | m22ydy += m22; | - | ||||||||||||||||||||||||||||||
| 2269 | dptr += p_inc; | - | ||||||||||||||||||||||||||||||
| 2270 | } | - | ||||||||||||||||||||||||||||||
| 2271 | return true; | - | ||||||||||||||||||||||||||||||
| 2272 | } | - | ||||||||||||||||||||||||||||||
| 2273 | qint64 QImage::cacheKey() const | - | ||||||||||||||||||||||||||||||
| 2274 | { | - | ||||||||||||||||||||||||||||||
| 2275 | if (!d) | - | ||||||||||||||||||||||||||||||
| 2276 | return 0; | - | ||||||||||||||||||||||||||||||
| 2277 | else | - | ||||||||||||||||||||||||||||||
| 2278 | return (((qint64) d->ser_no) << 32) | ((qint64) d->detach_no); | - | ||||||||||||||||||||||||||||||
| 2279 | } | - | ||||||||||||||||||||||||||||||
| 2280 | bool QImage::isDetached() const | - | ||||||||||||||||||||||||||||||
| 2281 | { | - | ||||||||||||||||||||||||||||||
| 2282 | return d && d->ref.load() == 1; | - | ||||||||||||||||||||||||||||||
| 2283 | } | - | ||||||||||||||||||||||||||||||
| 2284 | void QImage::setAlphaChannel(const QImage &alphaChannel) | - | ||||||||||||||||||||||||||||||
| 2285 | { | - | ||||||||||||||||||||||||||||||
| 2286 | if (!d) | - | ||||||||||||||||||||||||||||||
| 2287 | return; | - | ||||||||||||||||||||||||||||||
| 2288 | - | |||||||||||||||||||||||||||||||
| 2289 | int w = d->width; | - | ||||||||||||||||||||||||||||||
| 2290 | int h = d->height; | - | ||||||||||||||||||||||||||||||
| 2291 | - | |||||||||||||||||||||||||||||||
| 2292 | if (w != alphaChannel.d->width || h != alphaChannel.d->height) { | - | ||||||||||||||||||||||||||||||
| 2293 | QMessageLogger(__FILE__, 41924210, __PRETTY_FUNCTION__).warning("QImage::setAlphaChannel: " | - | ||||||||||||||||||||||||||||||
| 2294 | "Alpha channel must have same dimensions as the target image"); | - | ||||||||||||||||||||||||||||||
| 2295 | return; | - | ||||||||||||||||||||||||||||||
| 2296 | } | - | ||||||||||||||||||||||||||||||
| 2297 | - | |||||||||||||||||||||||||||||||
| 2298 | if (d->paintEngine && d->paintEngine->isActive()) { | - | ||||||||||||||||||||||||||||||
| 2299 | QMessageLogger(__FILE__, 41984216, __PRETTY_FUNCTION__).warning("QImage::setAlphaChannel: " | - | ||||||||||||||||||||||||||||||
| 2300 | "Unable to set alpha channel while image is being painted on"); | - | ||||||||||||||||||||||||||||||
| 2301 | return; | - | ||||||||||||||||||||||||||||||
| 2302 | } | - | ||||||||||||||||||||||||||||||
| 2303 | - | |||||||||||||||||||||||||||||||
| 2304 | if (d->format == QImage::Format_ARGB32_Premultiplied) | - | ||||||||||||||||||||||||||||||
| 2305 | detach(); | - | ||||||||||||||||||||||||||||||
| 2306 | else | - | ||||||||||||||||||||||||||||||
| 2307 | *this = convertToFormat(QImage::Format_ARGB32_Premultiplied); | - | ||||||||||||||||||||||||||||||
| 2308 | - | |||||||||||||||||||||||||||||||
| 2309 | if (isNull()) | - | ||||||||||||||||||||||||||||||
| 2310 | return; | - | ||||||||||||||||||||||||||||||
| 2311 | - | |||||||||||||||||||||||||||||||
| 2312 | - | |||||||||||||||||||||||||||||||
| 2313 | if (alphaChannel.format() == QImage::Format_Alpha8 ||( alphaChannel.d->depth == 8 && alphaChannel.isGrayscale())) { | - | ||||||||||||||||||||||||||||||
| 2314 | const uchar *src_data = alphaChannel.d->data; | - | ||||||||||||||||||||||||||||||
| 2315 | uchar *dest_data = d->data; | - | ||||||||||||||||||||||||||||||
| 2316 | for (int y=0; y<h; ++y) { | - | ||||||||||||||||||||||||||||||
| 2317 | const uchar *src = src_data; | - | ||||||||||||||||||||||||||||||
| 2318 | QRgb *dest = (QRgb *)dest_data; | - | ||||||||||||||||||||||||||||||
| 2319 | for (int x=0; x<w; ++x) { | - | ||||||||||||||||||||||||||||||
| 2320 | int alpha = *src; | - | ||||||||||||||||||||||||||||||
| 2321 | int destAlpha = qt_div_255(alpha * qAlpha(*dest)); | - | ||||||||||||||||||||||||||||||
| 2322 | *dest = ((destAlpha << 24) | - | ||||||||||||||||||||||||||||||
| 2323 | | (qt_div_255(qRed(*dest) * alpha) << 16) | - | ||||||||||||||||||||||||||||||
| 2324 | | (qt_div_255(qGreen(*dest) * alpha) << 8) | - | ||||||||||||||||||||||||||||||
| 2325 | | (qt_div_255(qBlue(*dest) * alpha))); | - | ||||||||||||||||||||||||||||||
| 2326 | ++dest; | - | ||||||||||||||||||||||||||||||
| 2327 | ++src; | - | ||||||||||||||||||||||||||||||
| 2328 | } | - | ||||||||||||||||||||||||||||||
| 2329 | src_data += alphaChannel.d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 2330 | dest_data += d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 2331 | } | - | ||||||||||||||||||||||||||||||
| 2332 | - | |||||||||||||||||||||||||||||||
| 2333 | } else { | - | ||||||||||||||||||||||||||||||
| 2334 | const QImage sourceImage = alphaChannel.convertToFormat(QImage::Format_RGB32); | - | ||||||||||||||||||||||||||||||
| 2335 | if (sourceImage.isNull()) | - | ||||||||||||||||||||||||||||||
| 2336 | return; | - | ||||||||||||||||||||||||||||||
| 2337 | const uchar *src_data = sourceImage.d->data; | - | ||||||||||||||||||||||||||||||
| 2338 | uchar *dest_data = d->data; | - | ||||||||||||||||||||||||||||||
| 2339 | for (int y=0; y<h; ++y) { | - | ||||||||||||||||||||||||||||||
| 2340 | const QRgb *src = (const QRgb *) src_data; | - | ||||||||||||||||||||||||||||||
| 2341 | QRgb *dest = (QRgb *) dest_data; | - | ||||||||||||||||||||||||||||||
| 2342 | for (int x=0; x<w; ++x) { | - | ||||||||||||||||||||||||||||||
| 2343 | int alpha = qGray(*src); | - | ||||||||||||||||||||||||||||||
| 2344 | int destAlpha = qt_div_255(alpha * qAlpha(*dest)); | - | ||||||||||||||||||||||||||||||
| 2345 | *dest = ((destAlpha << 24) | - | ||||||||||||||||||||||||||||||
| 2346 | | (qt_div_255(qRed(*dest) * alpha) << 16) | - | ||||||||||||||||||||||||||||||
| 2347 | | (qt_div_255(qGreen(*dest) * alpha) << 8) | - | ||||||||||||||||||||||||||||||
| 2348 | | (qt_div_255(qBlue(*dest) * alpha))); | - | ||||||||||||||||||||||||||||||
| 2349 | ++dest; | - | ||||||||||||||||||||||||||||||
| 2350 | ++src; | - | ||||||||||||||||||||||||||||||
| 2351 | } | - | ||||||||||||||||||||||||||||||
| 2352 | src_data += sourceImage.d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 2353 | dest_data += d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 2354 | } | - | ||||||||||||||||||||||||||||||
| 2355 | } | - | ||||||||||||||||||||||||||||||
| 2356 | } | - | ||||||||||||||||||||||||||||||
| 2357 | QImage QImage::alphaChannel() const | - | ||||||||||||||||||||||||||||||
| 2358 | { | - | ||||||||||||||||||||||||||||||
| 2359 | if (!d) | - | ||||||||||||||||||||||||||||||
| 2360 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 2361 | - | |||||||||||||||||||||||||||||||
| 2362 | int w = d->width; | - | ||||||||||||||||||||||||||||||
| 2363 | int h = d->height; | - | ||||||||||||||||||||||||||||||
| 2364 | - | |||||||||||||||||||||||||||||||
| 2365 | QImage image(w, h, Format_Indexed8); | - | ||||||||||||||||||||||||||||||
| 2366 | image.setColorCount(256); | - | ||||||||||||||||||||||||||||||
| 2367 | - | |||||||||||||||||||||||||||||||
| 2368 | - | |||||||||||||||||||||||||||||||
| 2369 | for (int i=0; i<256; ++i) | - | ||||||||||||||||||||||||||||||
| 2370 | image.setColor(i, qRgb(i, i, i)); | - | ||||||||||||||||||||||||||||||
| 2371 | - | |||||||||||||||||||||||||||||||
| 2372 | if (!hasAlphaChannel()) { | - | ||||||||||||||||||||||||||||||
| 2373 | image.fill(255); | - | ||||||||||||||||||||||||||||||
| 2374 | return image; | - | ||||||||||||||||||||||||||||||
| 2375 | } | - | ||||||||||||||||||||||||||||||
| 2376 | - | |||||||||||||||||||||||||||||||
| 2377 | if (d->format == Format_Indexed8) { | - | ||||||||||||||||||||||||||||||
| 2378 | const uchar *src_data = d->data; | - | ||||||||||||||||||||||||||||||
| 2379 | uchar *dest_data = image.d->data; | - | ||||||||||||||||||||||||||||||
| 2380 | for (int y=0; y<h; ++y) { | - | ||||||||||||||||||||||||||||||
| 2381 | const uchar *src = src_data; | - | ||||||||||||||||||||||||||||||
| 2382 | uchar *dest = dest_data; | - | ||||||||||||||||||||||||||||||
| 2383 | for (int x=0; x<w; ++x) { | - | ||||||||||||||||||||||||||||||
| 2384 | *dest = qAlpha(d->colortable.at(*src)); | - | ||||||||||||||||||||||||||||||
| 2385 | ++dest; | - | ||||||||||||||||||||||||||||||
| 2386 | ++src; | - | ||||||||||||||||||||||||||||||
| 2387 | } | - | ||||||||||||||||||||||||||||||
| 2388 | src_data += d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 2389 | dest_data += image.d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 2390 | } | - | ||||||||||||||||||||||||||||||
| 2391 | } else if (d->format == Format_Alpha8) { | - | ||||||||||||||||||||||||||||||
| 2392 | const uchar *src_data = d->data; | - | ||||||||||||||||||||||||||||||
| 2393 | uchar *dest_data = image.d->data; | - | ||||||||||||||||||||||||||||||
| 2394 | memcpy(dest_data, src_data, d->bytes_per_line * h); | - | ||||||||||||||||||||||||||||||
| 2395 | } else { | - | ||||||||||||||||||||||||||||||
| 2396 | QImage alpha32 = *this; | - | ||||||||||||||||||||||||||||||
| 2397 | bool canSkipConversion = (d->format == Format_ARGB32 || d->format == Format_ARGB32_Premultiplied); | - | ||||||||||||||||||||||||||||||
| 2398 | - | |||||||||||||||||||||||||||||||
| 2399 | canSkipConversion = canSkipConversion || (d->format == Format_RGBA8888 || d->format == Format_RGBA8888_Premultiplied); | - | ||||||||||||||||||||||||||||||
| 2400 | - | |||||||||||||||||||||||||||||||
| 2401 | if (!canSkipConversion) | - | ||||||||||||||||||||||||||||||
| 2402 | alpha32 = convertToFormat(Format_ARGB32); | - | ||||||||||||||||||||||||||||||
| 2403 | - | |||||||||||||||||||||||||||||||
| 2404 | const uchar *src_data = alpha32.d->data; | - | ||||||||||||||||||||||||||||||
| 2405 | uchar *dest_data = image.d->data; | - | ||||||||||||||||||||||||||||||
| 2406 | for (int y=0; y<h; ++y) { | - | ||||||||||||||||||||||||||||||
| 2407 | const QRgb *src = (const QRgb *) src_data; | - | ||||||||||||||||||||||||||||||
| 2408 | uchar *dest = dest_data; | - | ||||||||||||||||||||||||||||||
| 2409 | for (int x=0; x<w; ++x) { | - | ||||||||||||||||||||||||||||||
| 2410 | *dest = qAlpha(*src); | - | ||||||||||||||||||||||||||||||
| 2411 | ++dest; | - | ||||||||||||||||||||||||||||||
| 2412 | ++src; | - | ||||||||||||||||||||||||||||||
| 2413 | } | - | ||||||||||||||||||||||||||||||
| 2414 | src_data += alpha32.d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 2415 | dest_data += image.d->bytes_per_line; | - | ||||||||||||||||||||||||||||||
| 2416 | } | - | ||||||||||||||||||||||||||||||
| 2417 | } | - | ||||||||||||||||||||||||||||||
| 2418 | - | |||||||||||||||||||||||||||||||
| 2419 | return image; | - | ||||||||||||||||||||||||||||||
| 2420 | } | - | ||||||||||||||||||||||||||||||
| 2421 | - | |||||||||||||||||||||||||||||||
| 2422 | - | |||||||||||||||||||||||||||||||
| 2423 | - | |||||||||||||||||||||||||||||||
| 2424 | - | |||||||||||||||||||||||||||||||
| 2425 | - | |||||||||||||||||||||||||||||||
| 2426 | - | |||||||||||||||||||||||||||||||
| 2427 | - | |||||||||||||||||||||||||||||||
| 2428 | bool QImage::hasAlphaChannel() const | - | ||||||||||||||||||||||||||||||
| 2429 | { | - | ||||||||||||||||||||||||||||||
| 2430 | if (!d) | - | ||||||||||||||||||||||||||||||
| 2431 | return false; | - | ||||||||||||||||||||||||||||||
| 2432 | const QPixelFormat format = pixelFormat(); | - | ||||||||||||||||||||||||||||||
| 2433 | if (format.alphaUsage() == QPixelFormat::UsesAlpha) | - | ||||||||||||||||||||||||||||||
| 2434 | return true; | - | ||||||||||||||||||||||||||||||
| 2435 | if (format.colorModel() == QPixelFormat::Indexed) | - | ||||||||||||||||||||||||||||||
| 2436 | return d->has_alpha_clut; | - | ||||||||||||||||||||||||||||||
| 2437 | return false; | - | ||||||||||||||||||||||||||||||
| 2438 | } | - | ||||||||||||||||||||||||||||||
| 2439 | int QImage::bitPlaneCount() const | - | ||||||||||||||||||||||||||||||
| 2440 | { | - | ||||||||||||||||||||||||||||||
| 2441 | if (!d) | - | ||||||||||||||||||||||||||||||
| 2442 | return 0; | - | ||||||||||||||||||||||||||||||
| 2443 | int bpc = 0; | - | ||||||||||||||||||||||||||||||
| 2444 | switch (d->format) { | - | ||||||||||||||||||||||||||||||
| 2445 | case QImage::Format_Invalid: | - | ||||||||||||||||||||||||||||||
| 2446 | break; | - | ||||||||||||||||||||||||||||||
| 2447 | case QImage::Format_BGR30: | - | ||||||||||||||||||||||||||||||
| 2448 | case QImage::Format_RGB30: | - | ||||||||||||||||||||||||||||||
| 2449 | bpc = 30; | - | ||||||||||||||||||||||||||||||
| 2450 | break; | - | ||||||||||||||||||||||||||||||
| 2451 | case QImage::Format_RGB32: | - | ||||||||||||||||||||||||||||||
| 2452 | case QImage::Format_RGBX8888: | - | ||||||||||||||||||||||||||||||
| 2453 | bpc = 24; | - | ||||||||||||||||||||||||||||||
| 2454 | break; | - | ||||||||||||||||||||||||||||||
| 2455 | case QImage::Format_RGB666: | - | ||||||||||||||||||||||||||||||
| 2456 | bpc = 18; | - | ||||||||||||||||||||||||||||||
| 2457 | break; | - | ||||||||||||||||||||||||||||||
| 2458 | case QImage::Format_RGB555: | - | ||||||||||||||||||||||||||||||
| 2459 | bpc = 15; | - | ||||||||||||||||||||||||||||||
| 2460 | break; | - | ||||||||||||||||||||||||||||||
| 2461 | case QImage::Format_ARGB8555_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2462 | bpc = 23; | - | ||||||||||||||||||||||||||||||
| 2463 | break; | - | ||||||||||||||||||||||||||||||
| 2464 | case QImage::Format_RGB444: | - | ||||||||||||||||||||||||||||||
| 2465 | bpc = 12; | - | ||||||||||||||||||||||||||||||
| 2466 | break; | - | ||||||||||||||||||||||||||||||
| 2467 | default: | - | ||||||||||||||||||||||||||||||
| 2468 | bpc = qt_depthForFormat(d->format); | - | ||||||||||||||||||||||||||||||
| 2469 | break; | - | ||||||||||||||||||||||||||||||
| 2470 | } | - | ||||||||||||||||||||||||||||||
| 2471 | return bpc; | - | ||||||||||||||||||||||||||||||
| 2472 | } | - | ||||||||||||||||||||||||||||||
| 2473 | - | |||||||||||||||||||||||||||||||
| 2474 | - | |||||||||||||||||||||||||||||||
| 2475 | - | |||||||||||||||||||||||||||||||
| 2476 | - | |||||||||||||||||||||||||||||||
| 2477 | - | |||||||||||||||||||||||||||||||
| 2478 | QImage QImage::smoothScaled(int w, int h) const { | - | ||||||||||||||||||||||||||||||
| 2479 | QImage src = *this; | - | ||||||||||||||||||||||||||||||
| 2480 | switch (src.format()) { | - | ||||||||||||||||||||||||||||||
| 2481 | case QImage::Format_RGB32: | - | ||||||||||||||||||||||||||||||
| 2482 | case QImage::Format_ARGB32_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2483 | - | |||||||||||||||||||||||||||||||
| 2484 | case QImage::Format_RGBX8888: | - | ||||||||||||||||||||||||||||||
| 2485 | - | |||||||||||||||||||||||||||||||
| 2486 | case QImage::Format_RGBA8888_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2487 | break; | - | ||||||||||||||||||||||||||||||
| 2488 | default: | - | ||||||||||||||||||||||||||||||
| 2489 | if (src.hasAlphaChannel()) | - | ||||||||||||||||||||||||||||||
| 2490 | src = src.convertToFormat(QImage::Format_ARGB32_Premultiplied); | - | ||||||||||||||||||||||||||||||
| 2491 | else | - | ||||||||||||||||||||||||||||||
| 2492 | src = src.convertToFormat(QImage::Format_RGB32); | - | ||||||||||||||||||||||||||||||
| 2493 | } | - | ||||||||||||||||||||||||||||||
| 2494 | src = qSmoothScaleImage(src, w, h); | - | ||||||||||||||||||||||||||||||
| 2495 | if (!src.isNull()) | - | ||||||||||||||||||||||||||||||
| 2496 | copyMetadata(src.d, d); | - | ||||||||||||||||||||||||||||||
| 2497 | return src; | - | ||||||||||||||||||||||||||||||
| 2498 | } | - | ||||||||||||||||||||||||||||||
| 2499 | - | |||||||||||||||||||||||||||||||
| 2500 | static QImage rotated90(const QImage &image) { | - | ||||||||||||||||||||||||||||||
| 2501 | QImage out(image.height(), image.width(), image.format()); | - | ||||||||||||||||||||||||||||||
| 2502 | out.setDotsPerMeterX(image.dotsPerMeterY()); | - | ||||||||||||||||||||||||||||||
| 2503 | out.setDotsPerMeterY(image.dotsPerMeterX()); | - | ||||||||||||||||||||||||||||||
| 2504 | if (image.colorCount() > 0) | - | ||||||||||||||||||||||||||||||
| 2505 | out.setColorTable(image.colorTable()); | - | ||||||||||||||||||||||||||||||
| 2506 | int w = image.width(); | - | ||||||||||||||||||||||||||||||
| 2507 | int h = image.height(); | - | ||||||||||||||||||||||||||||||
| 2508 | switch (image.format()) { | - | ||||||||||||||||||||||||||||||
| 2509 | case QImage::Format_RGB32: | - | ||||||||||||||||||||||||||||||
| 2510 | case QImage::Format_ARGB32: | - | ||||||||||||||||||||||||||||||
| 2511 | case QImage::Format_ARGB32_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2512 | case QImage::Format_RGBX8888: | - | ||||||||||||||||||||||||||||||
| 2513 | case QImage::Format_RGBA8888: | - | ||||||||||||||||||||||||||||||
| 2514 | case QImage::Format_RGBA8888_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2515 | case QImage::Format_BGR30: | - | ||||||||||||||||||||||||||||||
| 2516 | case QImage::Format_A2BGR30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2517 | case QImage::Format_RGB30: | - | ||||||||||||||||||||||||||||||
| 2518 | case QImage::Format_A2RGB30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2519 | qt_memrotate270(reinterpret_cast<const quint32*>(image.bits()), | - | ||||||||||||||||||||||||||||||
| 2520 | w, h, image.bytesPerLine(), | - | ||||||||||||||||||||||||||||||
| 2521 | reinterpret_cast<quint32*>(out.bits()), | - | ||||||||||||||||||||||||||||||
| 2522 | out.bytesPerLine()); | - | ||||||||||||||||||||||||||||||
| 2523 | break; | - | ||||||||||||||||||||||||||||||
| 2524 | case QImage::Format_RGB666: | - | ||||||||||||||||||||||||||||||
| 2525 | case QImage::Format_ARGB6666_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2526 | case QImage::Format_ARGB8565_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2527 | case QImage::Format_ARGB8555_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2528 | case QImage::Format_RGB888: | - | ||||||||||||||||||||||||||||||
| 2529 | qt_memrotate270(reinterpret_cast<const quint24*>(image.bits()), | - | ||||||||||||||||||||||||||||||
| 2530 | w, h, image.bytesPerLine(), | - | ||||||||||||||||||||||||||||||
| 2531 | reinterpret_cast<quint24*>(out.bits()), | - | ||||||||||||||||||||||||||||||
| 2532 | out.bytesPerLine()); | - | ||||||||||||||||||||||||||||||
| 2533 | break; | - | ||||||||||||||||||||||||||||||
| 2534 | case QImage::Format_RGB555: | - | ||||||||||||||||||||||||||||||
| 2535 | case QImage::Format_RGB16: | - | ||||||||||||||||||||||||||||||
| 2536 | case QImage::Format_ARGB4444_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2537 | qt_memrotate270(reinterpret_cast<const quint16*>(image.bits()), | - | ||||||||||||||||||||||||||||||
| 2538 | w, h, image.bytesPerLine(), | - | ||||||||||||||||||||||||||||||
| 2539 | reinterpret_cast<quint16*>(out.bits()), | - | ||||||||||||||||||||||||||||||
| 2540 | out.bytesPerLine()); | - | ||||||||||||||||||||||||||||||
| 2541 | break; | - | ||||||||||||||||||||||||||||||
| 2542 | case QImage::Format_Alpha8: | - | ||||||||||||||||||||||||||||||
| 2543 | case QImage::Format_Grayscale8: | - | ||||||||||||||||||||||||||||||
| 2544 | case QImage::Format_Indexed8: | - | ||||||||||||||||||||||||||||||
| 2545 | qt_memrotate270(reinterpret_cast<const quint8*>(image.bits()), | - | ||||||||||||||||||||||||||||||
| 2546 | w, h, image.bytesPerLine(), | - | ||||||||||||||||||||||||||||||
| 2547 | reinterpret_cast<quint8*>(out.bits()), | - | ||||||||||||||||||||||||||||||
| 2548 | out.bytesPerLine()); | - | ||||||||||||||||||||||||||||||
| 2549 | break; | - | ||||||||||||||||||||||||||||||
| 2550 | default: | - | ||||||||||||||||||||||||||||||
| 2551 | for (int y=0; y<h; ++y) { | - | ||||||||||||||||||||||||||||||
| 2552 | if (image.colorCount()) | - | ||||||||||||||||||||||||||||||
| 2553 | for (int x=0; x<w; ++x) | - | ||||||||||||||||||||||||||||||
| 2554 | out.setPixel(h-y-1, x, image.pixelIndex(x, y)); | - | ||||||||||||||||||||||||||||||
| 2555 | else | - | ||||||||||||||||||||||||||||||
| 2556 | for (int x=0; x<w; ++x) | - | ||||||||||||||||||||||||||||||
| 2557 | out.setPixel(h-y-1, x, image.pixel(x, y)); | - | ||||||||||||||||||||||||||||||
| 2558 | } | - | ||||||||||||||||||||||||||||||
| 2559 | break; | - | ||||||||||||||||||||||||||||||
| 2560 | } | - | ||||||||||||||||||||||||||||||
| 2561 | return out; | - | ||||||||||||||||||||||||||||||
| 2562 | } | - | ||||||||||||||||||||||||||||||
| 2563 | - | |||||||||||||||||||||||||||||||
| 2564 | - | |||||||||||||||||||||||||||||||
| 2565 | static QImage rotated180(const QImage &image) { | - | ||||||||||||||||||||||||||||||
| 2566 | return image.mirrored(true, true); | - | ||||||||||||||||||||||||||||||
| 2567 | } | - | ||||||||||||||||||||||||||||||
| 2568 | - | |||||||||||||||||||||||||||||||
| 2569 | - | |||||||||||||||||||||||||||||||
| 2570 | static QImage rotated270(const QImage &image) { | - | ||||||||||||||||||||||||||||||
| 2571 | QImage out(image.height(), image.width(), image.format()); | - | ||||||||||||||||||||||||||||||
| 2572 | out.setDotsPerMeterX(image.dotsPerMeterY()); | - | ||||||||||||||||||||||||||||||
| 2573 | out.setDotsPerMeterY(image.dotsPerMeterX()); | - | ||||||||||||||||||||||||||||||
| 2574 | if (image.colorCount() > 0) | - | ||||||||||||||||||||||||||||||
| 2575 | out.setColorTable(image.colorTable()); | - | ||||||||||||||||||||||||||||||
| 2576 | int w = image.width(); | - | ||||||||||||||||||||||||||||||
| 2577 | int h = image.height(); | - | ||||||||||||||||||||||||||||||
| 2578 | switch (image.format()) { | - | ||||||||||||||||||||||||||||||
| 2579 | case QImage::Format_RGB32: | - | ||||||||||||||||||||||||||||||
| 2580 | case QImage::Format_ARGB32: | - | ||||||||||||||||||||||||||||||
| 2581 | case QImage::Format_ARGB32_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2582 | case QImage::Format_RGBX8888: | - | ||||||||||||||||||||||||||||||
| 2583 | case QImage::Format_RGBA8888: | - | ||||||||||||||||||||||||||||||
| 2584 | case QImage::Format_RGBA8888_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2585 | case QImage::Format_BGR30: | - | ||||||||||||||||||||||||||||||
| 2586 | case QImage::Format_A2BGR30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2587 | case QImage::Format_RGB30: | - | ||||||||||||||||||||||||||||||
| 2588 | case QImage::Format_A2RGB30_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2589 | qt_memrotate90(reinterpret_cast<const quint32*>(image.bits()), | - | ||||||||||||||||||||||||||||||
| 2590 | w, h, image.bytesPerLine(), | - | ||||||||||||||||||||||||||||||
| 2591 | reinterpret_cast<quint32*>(out.bits()), | - | ||||||||||||||||||||||||||||||
| 2592 | out.bytesPerLine()); | - | ||||||||||||||||||||||||||||||
| 2593 | break; | - | ||||||||||||||||||||||||||||||
| 2594 | case QImage::Format_RGB666: | - | ||||||||||||||||||||||||||||||
| 2595 | case QImage::Format_ARGB6666_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2596 | case QImage::Format_ARGB8565_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2597 | case QImage::Format_ARGB8555_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2598 | case QImage::Format_RGB888: | - | ||||||||||||||||||||||||||||||
| 2599 | qt_memrotate90(reinterpret_cast<const quint24*>(image.bits()), | - | ||||||||||||||||||||||||||||||
| 2600 | w, h, image.bytesPerLine(), | - | ||||||||||||||||||||||||||||||
| 2601 | reinterpret_cast<quint24*>(out.bits()), | - | ||||||||||||||||||||||||||||||
| 2602 | out.bytesPerLine()); | - | ||||||||||||||||||||||||||||||
| 2603 | break; | - | ||||||||||||||||||||||||||||||
| 2604 | case QImage::Format_RGB555: | - | ||||||||||||||||||||||||||||||
| 2605 | case QImage::Format_RGB16: | - | ||||||||||||||||||||||||||||||
| 2606 | case QImage::Format_ARGB4444_Premultiplied: | - | ||||||||||||||||||||||||||||||
| 2607 | qt_memrotate90(reinterpret_cast<const quint16*>(image.bits()), | - | ||||||||||||||||||||||||||||||
| 2608 | w, h, image.bytesPerLine(), | - | ||||||||||||||||||||||||||||||
| 2609 | reinterpret_cast<quint16*>(out.bits()), | - | ||||||||||||||||||||||||||||||
| 2610 | out.bytesPerLine()); | - | ||||||||||||||||||||||||||||||
| 2611 | break; | - | ||||||||||||||||||||||||||||||
| 2612 | case QImage::Format_Alpha8: | - | ||||||||||||||||||||||||||||||
| 2613 | case QImage::Format_Grayscale8: | - | ||||||||||||||||||||||||||||||
| 2614 | case QImage::Format_Indexed8: | - | ||||||||||||||||||||||||||||||
| 2615 | qt_memrotate90(reinterpret_cast<const quint8*>(image.bits()), | - | ||||||||||||||||||||||||||||||
| 2616 | w, h, image.bytesPerLine(), | - | ||||||||||||||||||||||||||||||
| 2617 | reinterpret_cast<quint8*>(out.bits()), | - | ||||||||||||||||||||||||||||||
| 2618 | out.bytesPerLine()); | - | ||||||||||||||||||||||||||||||
| 2619 | break; | - | ||||||||||||||||||||||||||||||
| 2620 | default: | - | ||||||||||||||||||||||||||||||
| 2621 | for (int y=0; y<h; ++y) { | - | ||||||||||||||||||||||||||||||
| 2622 | if (image.colorCount()) | - | ||||||||||||||||||||||||||||||
| 2623 | for (int x=0; x<w; ++x) | - | ||||||||||||||||||||||||||||||
| 2624 | out.setPixel(y, w-x-1, image.pixelIndex(x, y)); | - | ||||||||||||||||||||||||||||||
| 2625 | else | - | ||||||||||||||||||||||||||||||
| 2626 | for (int x=0; x<w; ++x) | - | ||||||||||||||||||||||||||||||
| 2627 | out.setPixel(y, w-x-1, image.pixel(x, y)); | - | ||||||||||||||||||||||||||||||
| 2628 | } | - | ||||||||||||||||||||||||||||||
| 2629 | break; | - | ||||||||||||||||||||||||||||||
| 2630 | } | - | ||||||||||||||||||||||||||||||
| 2631 | return out; | - | ||||||||||||||||||||||||||||||
| 2632 | } | - | ||||||||||||||||||||||||||||||
| 2633 | QImage QImage::transformed(const QTransform &matrix, Qt::TransformationMode mode ) const | - | ||||||||||||||||||||||||||||||
| 2634 | { | - | ||||||||||||||||||||||||||||||
| 2635 | if (!d) | - | ||||||||||||||||||||||||||||||
| 2636 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 2637 | - | |||||||||||||||||||||||||||||||
| 2638 | - | |||||||||||||||||||||||||||||||
| 2639 | int ws = width(); | - | ||||||||||||||||||||||||||||||
| 2640 | int hs = height(); | - | ||||||||||||||||||||||||||||||
| 2641 | - | |||||||||||||||||||||||||||||||
| 2642 | - | |||||||||||||||||||||||||||||||
| 2643 | int wd; | - | ||||||||||||||||||||||||||||||
| 2644 | int hd; | - | ||||||||||||||||||||||||||||||
| 2645 | - | |||||||||||||||||||||||||||||||
| 2646 | - | |||||||||||||||||||||||||||||||
| 2647 | QTransform mat = trueMatrix(matrix, ws, hs); | - | ||||||||||||||||||||||||||||||
| 2648 | bool complex_xform = false; | - | ||||||||||||||||||||||||||||||
| 2649 | bool scale_xform = false; | - | ||||||||||||||||||||||||||||||
| 2650 | if (mat.type() <= QTransform::TxScale) { | - | ||||||||||||||||||||||||||||||
| 2651 | if (mat.type() == QTransform::TxNone) | - | ||||||||||||||||||||||||||||||
| 2652 | return *this; | - | ||||||||||||||||||||||||||||||
| 2653 | else if (mat.m11() == -1. && mat.m22() == -1.) | - | ||||||||||||||||||||||||||||||
| 2654 | return rotated180(*this); | - | ||||||||||||||||||||||||||||||
| 2655 | - | |||||||||||||||||||||||||||||||
| 2656 | if (mode == Qt::FastTransformation) { | - | ||||||||||||||||||||||||||||||
| 2657 | hd = qRound(qAbs(mat.m22()) * hs); | - | ||||||||||||||||||||||||||||||
| 2658 | wd = qRound(qAbs(mat.m11()) * ws); | - | ||||||||||||||||||||||||||||||
| 2659 | } else { | - | ||||||||||||||||||||||||||||||
| 2660 | hd = int(qAbs(mat.m22()) * hs + 0.9999); | - | ||||||||||||||||||||||||||||||
| 2661 | wd = int(qAbs(mat.m11()) * ws + 0.9999); | - | ||||||||||||||||||||||||||||||
| 2662 | } | - | ||||||||||||||||||||||||||||||
| 2663 | scale_xform = true; | - | ||||||||||||||||||||||||||||||
| 2664 | } else { | - | ||||||||||||||||||||||||||||||
| 2665 | if (mat.type() <= QTransform::TxRotate && mat.m11() == 0 && mat.m22() == 0) { | - | ||||||||||||||||||||||||||||||
| 2666 | if (mat.m12() == 1. && mat.m21() == -1.) | - | ||||||||||||||||||||||||||||||
| 2667 | return rotated90(*this); | - | ||||||||||||||||||||||||||||||
| 2668 | else if (mat.m12() == -1. && mat.m21() == 1.) | - | ||||||||||||||||||||||||||||||
| 2669 | return rotated270(*this); | - | ||||||||||||||||||||||||||||||
| 2670 | } | - | ||||||||||||||||||||||||||||||
| 2671 | - | |||||||||||||||||||||||||||||||
| 2672 | QPolygonF a(QRectF(0, 0, ws, hs)); | - | ||||||||||||||||||||||||||||||
| 2673 | a = mat.map(a); | - | ||||||||||||||||||||||||||||||
| 2674 | QRect r = a.boundingRect().toAlignedRect(); | - | ||||||||||||||||||||||||||||||
| 2675 | wd = r.width(); | - | ||||||||||||||||||||||||||||||
| 2676 | hd = r.height(); | - | ||||||||||||||||||||||||||||||
| 2677 | complex_xform = true; | - | ||||||||||||||||||||||||||||||
| 2678 | } | - | ||||||||||||||||||||||||||||||
| 2679 | - | |||||||||||||||||||||||||||||||
| 2680 | if (wd == 0 || hd == 0) | - | ||||||||||||||||||||||||||||||
| 2681 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 2682 | - | |||||||||||||||||||||||||||||||
| 2683 | - | |||||||||||||||||||||||||||||||
| 2684 | if (scale_xform && mode == Qt::SmoothTransformation) { | - | ||||||||||||||||||||||||||||||
| 2685 | if (mat.m11() < 0.0F && mat.m22() < 0.0F) { | - | ||||||||||||||||||||||||||||||
| 2686 | return smoothScaled(wd, hd).mirrored(true, true); | - | ||||||||||||||||||||||||||||||
| 2687 | } else if (mat.m11() < 0.0F) { | - | ||||||||||||||||||||||||||||||
| 2688 | return smoothScaled(wd, hd).mirrored(true, false); | - | ||||||||||||||||||||||||||||||
| 2689 | } else if (mat.m22() < 0.0F) { | - | ||||||||||||||||||||||||||||||
| 2690 | return smoothScaled(wd, hd).mirrored(false, true); | - | ||||||||||||||||||||||||||||||
| 2691 | } else { | - | ||||||||||||||||||||||||||||||
| 2692 | return smoothScaled(wd, hd); | - | ||||||||||||||||||||||||||||||
| 2693 | } | - | ||||||||||||||||||||||||||||||
| 2694 | } | - | ||||||||||||||||||||||||||||||
| 2695 | - | |||||||||||||||||||||||||||||||
| 2696 | int bpp = depth(); | - | ||||||||||||||||||||||||||||||
| 2697 | - | |||||||||||||||||||||||||||||||
| 2698 | int sbpl = bytesPerLine(); | - | ||||||||||||||||||||||||||||||
| 2699 | const uchar *sptr = bits(); | - | ||||||||||||||||||||||||||||||
| 2700 | - | |||||||||||||||||||||||||||||||
| 2701 | QImage::Format target_format = d->format; | - | ||||||||||||||||||||||||||||||
| 2702 | - | |||||||||||||||||||||||||||||||
| 2703 | if (complex_xform || mode == Qt::SmoothTransformation) { | - | ||||||||||||||||||||||||||||||
| 2704 | if (d->format < QImage::Format_RGB32 || !hasAlphaChannel()) { | - | ||||||||||||||||||||||||||||||
| 2705 | target_format = qt_alphaVersion(d->format); | - | ||||||||||||||||||||||||||||||
| 2706 | } | - | ||||||||||||||||||||||||||||||
| 2707 | } | - | ||||||||||||||||||||||||||||||
| 2708 | - | |||||||||||||||||||||||||||||||
| 2709 | QImage dImage(wd, hd, target_format); | - | ||||||||||||||||||||||||||||||
| 2710 | if ((dImage).isNull()) { QMessageLogger(__FILE__, 46664684, __PRETTY_FUNCTION__).warning("QImage: out of memory, returning null image"); return QImage(); }; | - | ||||||||||||||||||||||||||||||
| 2711 | - | |||||||||||||||||||||||||||||||
| 2712 | if (target_format == QImage::Format_MonoLSB | - | ||||||||||||||||||||||||||||||
| 2713 | || target_format == QImage::Format_Mono | - | ||||||||||||||||||||||||||||||
| 2714 | || target_format == QImage::Format_Indexed8) { | - | ||||||||||||||||||||||||||||||
| 2715 | dImage.d->colortable = d->colortable; | - | ||||||||||||||||||||||||||||||
| 2716 | dImage.d->has_alpha_clut = d->has_alpha_clut | complex_xform; | - | ||||||||||||||||||||||||||||||
| 2717 | } | - | ||||||||||||||||||||||||||||||
| 2718 | - | |||||||||||||||||||||||||||||||
| 2719 | - | |||||||||||||||||||||||||||||||
| 2720 | if (d->format == QImage::Format_Indexed8) { | - | ||||||||||||||||||||||||||||||
| 2721 | if (dImage.d->colortable.size() < 256) { | - | ||||||||||||||||||||||||||||||
| 2722 | - | |||||||||||||||||||||||||||||||
| 2723 | dImage.d->colortable.append(0x0); | - | ||||||||||||||||||||||||||||||
| 2724 | memset(dImage.bits(), dImage.d->colortable.size() - 1, dImage.byteCount()); | - | ||||||||||||||||||||||||||||||
| 2725 | } else { | - | ||||||||||||||||||||||||||||||
| 2726 | memset(dImage.bits(), 0, dImage.byteCount()); | - | ||||||||||||||||||||||||||||||
| 2727 | } | - | ||||||||||||||||||||||||||||||
| 2728 | } else | - | ||||||||||||||||||||||||||||||
| 2729 | memset(dImage.bits(), 0x00, dImage.byteCount()); | - | ||||||||||||||||||||||||||||||
| 2730 | - | |||||||||||||||||||||||||||||||
| 2731 | if (target_format >= QImage::Format_RGB32) { | - | ||||||||||||||||||||||||||||||
| 2732 | - | |||||||||||||||||||||||||||||||
| 2733 | const QImage sImage = (devicePixelRatio() != 1) ? QImage(constBits(), width(), height(), format()) : *this; | - | ||||||||||||||||||||||||||||||
| 2734 | - | |||||||||||||||||||||||||||||||
| 2735 | ((!(sImage.devicePixelRatio() == 1)) ? qt_assert("sImage.devicePixelRatio() == 1",__FILE__,46914709) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 2736 | ((!(sImage.devicePixelRatio() == dImage.devicePixelRatio())) ? qt_assert("sImage.devicePixelRatio() == dImage.devicePixelRatio()",__FILE__,46924710) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 2737 | - | |||||||||||||||||||||||||||||||
| 2738 | QPainter p(&dImage); | - | ||||||||||||||||||||||||||||||
| 2739 | if (mode == Qt::SmoothTransformation) { | - | ||||||||||||||||||||||||||||||
| 2740 | p.setRenderHint(QPainter::Antialiasing); | - | ||||||||||||||||||||||||||||||
| 2741 | p.setRenderHint(QPainter::SmoothPixmapTransform); | - | ||||||||||||||||||||||||||||||
| 2742 | } | - | ||||||||||||||||||||||||||||||
| 2743 | p.setTransform(mat); | - | ||||||||||||||||||||||||||||||
| 2744 | p.drawImage(QPoint(0, 0), sImage); | - | ||||||||||||||||||||||||||||||
| 2745 | } else { | - | ||||||||||||||||||||||||||||||
| 2746 | bool invertible; | - | ||||||||||||||||||||||||||||||
| 2747 | mat = mat.inverted(&invertible); | - | ||||||||||||||||||||||||||||||
| 2748 | if (!invertible) | - | ||||||||||||||||||||||||||||||
| 2749 | return QImage(); | - | ||||||||||||||||||||||||||||||
| 2750 | - | |||||||||||||||||||||||||||||||
| 2751 | - | |||||||||||||||||||||||||||||||
| 2752 | int type = format() == Format_Mono ? 0 : 1; | - | ||||||||||||||||||||||||||||||
| 2753 | int dbpl = dImage.bytesPerLine(); | - | ||||||||||||||||||||||||||||||
| 2754 | qt_xForm_helper(mat, 0, type, bpp, dImage.bits(), dbpl, 0, hd, sptr, sbpl, ws, hs); | - | ||||||||||||||||||||||||||||||
| 2755 | } | - | ||||||||||||||||||||||||||||||
| 2756 | copyMetadata(dImage.d, d); | - | ||||||||||||||||||||||||||||||
| 2757 | - | |||||||||||||||||||||||||||||||
| 2758 | return dImage; | - | ||||||||||||||||||||||||||||||
| 2759 | } | - | ||||||||||||||||||||||||||||||
| 2760 | QTransform QImage::trueMatrix(const QTransform &matrix, int w, int h) | - | ||||||||||||||||||||||||||||||
| 2761 | { | - | ||||||||||||||||||||||||||||||
| 2762 | const QRectF rect(0, 0, w, h); | - | ||||||||||||||||||||||||||||||
| 2763 | const QRect mapped = matrix.mapRect(rect).toAlignedRect(); | - | ||||||||||||||||||||||||||||||
| 2764 | const QPoint delta = mapped.topLeft(); | - | ||||||||||||||||||||||||||||||
| 2765 | return matrix * QTransform().translate(-delta.x(), -delta.y()); | - | ||||||||||||||||||||||||||||||
| 2766 | } | - | ||||||||||||||||||||||||||||||
| 2767 | - | |||||||||||||||||||||||||||||||
| 2768 | bool QImageData::convertInPlace(QImage::Format newFormat, Qt::ImageConversionFlags flags) | - | ||||||||||||||||||||||||||||||
| 2769 | { | - | ||||||||||||||||||||||||||||||
| 2770 | if (format == newFormat) | - | ||||||||||||||||||||||||||||||
| 2771 | return true; | - | ||||||||||||||||||||||||||||||
| 2772 | - | |||||||||||||||||||||||||||||||
| 2773 | - | |||||||||||||||||||||||||||||||
| 2774 | if (ref.load() > 1 || !own_data) | - | ||||||||||||||||||||||||||||||
| 2775 | return false; | - | ||||||||||||||||||||||||||||||
| 2776 | - | |||||||||||||||||||||||||||||||
| 2777 | InPlace_Image_Converter converter = qimage_inplace_converter_map[format][newFormat]; | - | ||||||||||||||||||||||||||||||
| 2778 | if (converter) | - | ||||||||||||||||||||||||||||||
| 2779 | return converter(this, flags); | - | ||||||||||||||||||||||||||||||
| 2780 | else if (format > QImage::Format_Indexed8 && newFormat > QImage::Format_Indexed8 && !qimage_converter_map[format][newFormat]) | - | ||||||||||||||||||||||||||||||
| 2781 | - | |||||||||||||||||||||||||||||||
| 2782 | - | |||||||||||||||||||||||||||||||
| 2783 | return convert_generic_inplace(this, newFormat, flags); | - | ||||||||||||||||||||||||||||||
| 2784 | else | - | ||||||||||||||||||||||||||||||
| 2785 | return false; | - | ||||||||||||||||||||||||||||||
| 2786 | } | - | ||||||||||||||||||||||||||||||
| 2787 | QDebug operator<<(QDebug dbg, const QImage &i) | - | ||||||||||||||||||||||||||||||
| 2788 | { | - | ||||||||||||||||||||||||||||||
| 2789 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||||||||||||||
| 2790 | dbg.resetFormat(); | - | ||||||||||||||||||||||||||||||
| 2791 | dbg.nospace(); | - | ||||||||||||||||||||||||||||||
| 2792 | dbg << "QImage("; | - | ||||||||||||||||||||||||||||||
| 2793 | if (i.isNull()) { | - | ||||||||||||||||||||||||||||||
| 2794 | dbg << "null"; | - | ||||||||||||||||||||||||||||||
| 2795 | } else { | - | ||||||||||||||||||||||||||||||
| 2796 | dbg << i.size() << ",format=" << i.format() << ",depth=" << i.depth(); | - | ||||||||||||||||||||||||||||||
| 2797 | if (i.colorCount()) | - | ||||||||||||||||||||||||||||||
| 2798 | dbg << ",colorCount=" << i.colorCount(); | - | ||||||||||||||||||||||||||||||
| 2799 | dbg << ",devicePixelRatio=" << i.devicePixelRatio() | - | ||||||||||||||||||||||||||||||
| 2800 | << ",bytesPerLine=" << i.bytesPerLine() << ",byteCount=" << i.byteCount(); | - | ||||||||||||||||||||||||||||||
| 2801 | } | - | ||||||||||||||||||||||||||||||
| 2802 | dbg << ')'; | - | ||||||||||||||||||||||||||||||
| 2803 | return dbg; | - | ||||||||||||||||||||||||||||||
| 2804 | } | - | ||||||||||||||||||||||||||||||
| 2805 | static constexpr QPixelFormat pixelformats[] = { | - | ||||||||||||||||||||||||||||||
| 2806 | - | |||||||||||||||||||||||||||||||
| 2807 | QPixelFormat(), | - | ||||||||||||||||||||||||||||||
| 2808 | - | |||||||||||||||||||||||||||||||
| 2809 | QPixelFormat(QPixelFormat::Indexed, | - | ||||||||||||||||||||||||||||||
| 2810 | 1, | - | ||||||||||||||||||||||||||||||
| 2811 | 0, | - | ||||||||||||||||||||||||||||||
| 2812 | 0, | - | ||||||||||||||||||||||||||||||
| 2813 | 0, | - | ||||||||||||||||||||||||||||||
| 2814 | 0, | - | ||||||||||||||||||||||||||||||
| 2815 | 0, | - | ||||||||||||||||||||||||||||||
| 2816 | QPixelFormat::IgnoresAlpha, | - | ||||||||||||||||||||||||||||||
| 2817 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 2818 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 2819 | QPixelFormat::UnsignedByte, | - | ||||||||||||||||||||||||||||||
| 2820 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 2821 | - | |||||||||||||||||||||||||||||||
| 2822 | QPixelFormat(QPixelFormat::Indexed, | - | ||||||||||||||||||||||||||||||
| 2823 | 1, | - | ||||||||||||||||||||||||||||||
| 2824 | 0, | - | ||||||||||||||||||||||||||||||
| 2825 | 0, | - | ||||||||||||||||||||||||||||||
| 2826 | 0, | - | ||||||||||||||||||||||||||||||
| 2827 | 0, | - | ||||||||||||||||||||||||||||||
| 2828 | 0, | - | ||||||||||||||||||||||||||||||
| 2829 | QPixelFormat::IgnoresAlpha, | - | ||||||||||||||||||||||||||||||
| 2830 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 2831 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 2832 | QPixelFormat::UnsignedByte, | - | ||||||||||||||||||||||||||||||
| 2833 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 2834 | - | |||||||||||||||||||||||||||||||
| 2835 | QPixelFormat(QPixelFormat::Indexed, | - | ||||||||||||||||||||||||||||||
| 2836 | 8, | - | ||||||||||||||||||||||||||||||
| 2837 | 0, | - | ||||||||||||||||||||||||||||||
| 2838 | 0, | - | ||||||||||||||||||||||||||||||
| 2839 | 0, | - | ||||||||||||||||||||||||||||||
| 2840 | 0, | - | ||||||||||||||||||||||||||||||
| 2841 | 0, | - | ||||||||||||||||||||||||||||||
| 2842 | QPixelFormat::IgnoresAlpha, | - | ||||||||||||||||||||||||||||||
| 2843 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 2844 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 2845 | QPixelFormat::UnsignedByte, | - | ||||||||||||||||||||||||||||||
| 2846 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 2847 | - | |||||||||||||||||||||||||||||||
| 2848 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 2849 | 8, | - | ||||||||||||||||||||||||||||||
| 2850 | 8, | - | ||||||||||||||||||||||||||||||
| 2851 | 8, | - | ||||||||||||||||||||||||||||||
| 2852 | 0, | - | ||||||||||||||||||||||||||||||
| 2853 | 0, | - | ||||||||||||||||||||||||||||||
| 2854 | 8, | - | ||||||||||||||||||||||||||||||
| 2855 | QPixelFormat::IgnoresAlpha, | - | ||||||||||||||||||||||||||||||
| 2856 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 2857 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 2858 | QPixelFormat::UnsignedInteger, | - | ||||||||||||||||||||||||||||||
| 2859 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 2860 | - | |||||||||||||||||||||||||||||||
| 2861 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 2862 | 8, | - | ||||||||||||||||||||||||||||||
| 2863 | 8, | - | ||||||||||||||||||||||||||||||
| 2864 | 8, | - | ||||||||||||||||||||||||||||||
| 2865 | 0, | - | ||||||||||||||||||||||||||||||
| 2866 | 0, | - | ||||||||||||||||||||||||||||||
| 2867 | 8, | - | ||||||||||||||||||||||||||||||
| 2868 | QPixelFormat::UsesAlpha, | - | ||||||||||||||||||||||||||||||
| 2869 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 2870 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 2871 | QPixelFormat::UnsignedInteger, | - | ||||||||||||||||||||||||||||||
| 2872 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 2873 | - | |||||||||||||||||||||||||||||||
| 2874 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 2875 | 8, | - | ||||||||||||||||||||||||||||||
| 2876 | 8, | - | ||||||||||||||||||||||||||||||
| 2877 | 8, | - | ||||||||||||||||||||||||||||||
| 2878 | 0, | - | ||||||||||||||||||||||||||||||
| 2879 | 0, | - | ||||||||||||||||||||||||||||||
| 2880 | 8, | - | ||||||||||||||||||||||||||||||
| 2881 | QPixelFormat::UsesAlpha, | - | ||||||||||||||||||||||||||||||
| 2882 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 2883 | QPixelFormat::Premultiplied, | - | ||||||||||||||||||||||||||||||
| 2884 | QPixelFormat::UnsignedInteger, | - | ||||||||||||||||||||||||||||||
| 2885 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 2886 | - | |||||||||||||||||||||||||||||||
| 2887 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 2888 | 5, | - | ||||||||||||||||||||||||||||||
| 2889 | 6, | - | ||||||||||||||||||||||||||||||
| 2890 | 5, | - | ||||||||||||||||||||||||||||||
| 2891 | 0, | - | ||||||||||||||||||||||||||||||
| 2892 | 0, | - | ||||||||||||||||||||||||||||||
| 2893 | 0, | - | ||||||||||||||||||||||||||||||
| 2894 | QPixelFormat::IgnoresAlpha, | - | ||||||||||||||||||||||||||||||
| 2895 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 2896 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 2897 | QPixelFormat::UnsignedShort, | - | ||||||||||||||||||||||||||||||
| 2898 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 2899 | - | |||||||||||||||||||||||||||||||
| 2900 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 2901 | 5, | - | ||||||||||||||||||||||||||||||
| 2902 | 6, | - | ||||||||||||||||||||||||||||||
| 2903 | 5, | - | ||||||||||||||||||||||||||||||
| 2904 | 0, | - | ||||||||||||||||||||||||||||||
| 2905 | 0, | - | ||||||||||||||||||||||||||||||
| 2906 | 8, | - | ||||||||||||||||||||||||||||||
| 2907 | QPixelFormat::UsesAlpha, | - | ||||||||||||||||||||||||||||||
| 2908 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 2909 | QPixelFormat::Premultiplied, | - | ||||||||||||||||||||||||||||||
| 2910 | QPixelFormat::UnsignedInteger, | - | ||||||||||||||||||||||||||||||
| 2911 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 2912 | - | |||||||||||||||||||||||||||||||
| 2913 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 2914 | 6, | - | ||||||||||||||||||||||||||||||
| 2915 | 6, | - | ||||||||||||||||||||||||||||||
| 2916 | 6, | - | ||||||||||||||||||||||||||||||
| 2917 | 0, | - | ||||||||||||||||||||||||||||||
| 2918 | 0, | - | ||||||||||||||||||||||||||||||
| 2919 | 0, | - | ||||||||||||||||||||||||||||||
| 2920 | QPixelFormat::IgnoresAlpha, | - | ||||||||||||||||||||||||||||||
| 2921 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 2922 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 2923 | QPixelFormat::UnsignedInteger, | - | ||||||||||||||||||||||||||||||
| 2924 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 2925 | - | |||||||||||||||||||||||||||||||
| 2926 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 2927 | 6, | - | ||||||||||||||||||||||||||||||
| 2928 | 6, | - | ||||||||||||||||||||||||||||||
| 2929 | 6, | - | ||||||||||||||||||||||||||||||
| 2930 | 0, | - | ||||||||||||||||||||||||||||||
| 2931 | 0, | - | ||||||||||||||||||||||||||||||
| 2932 | 6, | - | ||||||||||||||||||||||||||||||
| 2933 | QPixelFormat::UsesAlpha, | - | ||||||||||||||||||||||||||||||
| 2934 | QPixelFormat::AtEnd, | - | ||||||||||||||||||||||||||||||
| 2935 | QPixelFormat::Premultiplied, | - | ||||||||||||||||||||||||||||||
| 2936 | QPixelFormat::UnsignedInteger, | - | ||||||||||||||||||||||||||||||
| 2937 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 2938 | - | |||||||||||||||||||||||||||||||
| 2939 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 2940 | 5, | - | ||||||||||||||||||||||||||||||
| 2941 | 5, | - | ||||||||||||||||||||||||||||||
| 2942 | 5, | - | ||||||||||||||||||||||||||||||
| 2943 | 0, | - | ||||||||||||||||||||||||||||||
| 2944 | 0, | - | ||||||||||||||||||||||||||||||
| 2945 | 0, | - | ||||||||||||||||||||||||||||||
| 2946 | QPixelFormat::IgnoresAlpha, | - | ||||||||||||||||||||||||||||||
| 2947 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 2948 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 2949 | QPixelFormat::UnsignedShort, | - | ||||||||||||||||||||||||||||||
| 2950 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 2951 | - | |||||||||||||||||||||||||||||||
| 2952 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 2953 | 5, | - | ||||||||||||||||||||||||||||||
| 2954 | 5, | - | ||||||||||||||||||||||||||||||
| 2955 | 5, | - | ||||||||||||||||||||||||||||||
| 2956 | 0, | - | ||||||||||||||||||||||||||||||
| 2957 | 0, | - | ||||||||||||||||||||||||||||||
| 2958 | 8, | - | ||||||||||||||||||||||||||||||
| 2959 | QPixelFormat::UsesAlpha, | - | ||||||||||||||||||||||||||||||
| 2960 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 2961 | QPixelFormat::Premultiplied, | - | ||||||||||||||||||||||||||||||
| 2962 | QPixelFormat::UnsignedInteger, | - | ||||||||||||||||||||||||||||||
| 2963 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 2964 | - | |||||||||||||||||||||||||||||||
| 2965 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 2966 | 8, | - | ||||||||||||||||||||||||||||||
| 2967 | 8, | - | ||||||||||||||||||||||||||||||
| 2968 | 8, | - | ||||||||||||||||||||||||||||||
| 2969 | 0, | - | ||||||||||||||||||||||||||||||
| 2970 | 0, | - | ||||||||||||||||||||||||||||||
| 2971 | 0, | - | ||||||||||||||||||||||||||||||
| 2972 | QPixelFormat::IgnoresAlpha, | - | ||||||||||||||||||||||||||||||
| 2973 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 2974 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 2975 | QPixelFormat::UnsignedByte, | - | ||||||||||||||||||||||||||||||
| 2976 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 2977 | - | |||||||||||||||||||||||||||||||
| 2978 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 2979 | 4, | - | ||||||||||||||||||||||||||||||
| 2980 | 4, | - | ||||||||||||||||||||||||||||||
| 2981 | 4, | - | ||||||||||||||||||||||||||||||
| 2982 | 0, | - | ||||||||||||||||||||||||||||||
| 2983 | 0, | - | ||||||||||||||||||||||||||||||
| 2984 | 0, | - | ||||||||||||||||||||||||||||||
| 2985 | QPixelFormat::IgnoresAlpha, | - | ||||||||||||||||||||||||||||||
| 2986 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 2987 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 2988 | QPixelFormat::UnsignedShort, | - | ||||||||||||||||||||||||||||||
| 2989 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 2990 | - | |||||||||||||||||||||||||||||||
| 2991 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 2992 | 4, | - | ||||||||||||||||||||||||||||||
| 2993 | 4, | - | ||||||||||||||||||||||||||||||
| 2994 | 4, | - | ||||||||||||||||||||||||||||||
| 2995 | 0, | - | ||||||||||||||||||||||||||||||
| 2996 | 0, | - | ||||||||||||||||||||||||||||||
| 2997 | 4, | - | ||||||||||||||||||||||||||||||
| 2998 | QPixelFormat::UsesAlpha, | - | ||||||||||||||||||||||||||||||
| 2999 | QPixelFormat::AtEnd, | - | ||||||||||||||||||||||||||||||
| 3000 | QPixelFormat::Premultiplied, | - | ||||||||||||||||||||||||||||||
| 3001 | QPixelFormat::UnsignedShort, | - | ||||||||||||||||||||||||||||||
| 3002 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 3003 | - | |||||||||||||||||||||||||||||||
| 3004 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 3005 | 8, | - | ||||||||||||||||||||||||||||||
| 3006 | 8, | - | ||||||||||||||||||||||||||||||
| 3007 | 8, | - | ||||||||||||||||||||||||||||||
| 3008 | 0, | - | ||||||||||||||||||||||||||||||
| 3009 | 0, | - | ||||||||||||||||||||||||||||||
| 3010 | 8, | - | ||||||||||||||||||||||||||||||
| 3011 | QPixelFormat::IgnoresAlpha, | - | ||||||||||||||||||||||||||||||
| 3012 | QPixelFormat::AtEnd, | - | ||||||||||||||||||||||||||||||
| 3013 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 3014 | QPixelFormat::UnsignedByte, | - | ||||||||||||||||||||||||||||||
| 3015 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 3016 | - | |||||||||||||||||||||||||||||||
| 3017 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 3018 | 8, | - | ||||||||||||||||||||||||||||||
| 3019 | 8, | - | ||||||||||||||||||||||||||||||
| 3020 | 8, | - | ||||||||||||||||||||||||||||||
| 3021 | 0, | - | ||||||||||||||||||||||||||||||
| 3022 | 0, | - | ||||||||||||||||||||||||||||||
| 3023 | 8, | - | ||||||||||||||||||||||||||||||
| 3024 | QPixelFormat::UsesAlpha, | - | ||||||||||||||||||||||||||||||
| 3025 | QPixelFormat::AtEnd, | - | ||||||||||||||||||||||||||||||
| 3026 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 3027 | QPixelFormat::UnsignedByte, | - | ||||||||||||||||||||||||||||||
| 3028 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 3029 | - | |||||||||||||||||||||||||||||||
| 3030 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 3031 | 8, | - | ||||||||||||||||||||||||||||||
| 3032 | 8, | - | ||||||||||||||||||||||||||||||
| 3033 | 8, | - | ||||||||||||||||||||||||||||||
| 3034 | 0, | - | ||||||||||||||||||||||||||||||
| 3035 | 0, | - | ||||||||||||||||||||||||||||||
| 3036 | 8, | - | ||||||||||||||||||||||||||||||
| 3037 | QPixelFormat::UsesAlpha, | - | ||||||||||||||||||||||||||||||
| 3038 | QPixelFormat::AtEnd, | - | ||||||||||||||||||||||||||||||
| 3039 | QPixelFormat::Premultiplied, | - | ||||||||||||||||||||||||||||||
| 3040 | QPixelFormat::UnsignedByte, | - | ||||||||||||||||||||||||||||||
| 3041 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 3042 | - | |||||||||||||||||||||||||||||||
| 3043 | QPixelFormat(QPixelFormat::BGR, | - | ||||||||||||||||||||||||||||||
| 3044 | 10, | - | ||||||||||||||||||||||||||||||
| 3045 | 10, | - | ||||||||||||||||||||||||||||||
| 3046 | 10, | - | ||||||||||||||||||||||||||||||
| 3047 | 0, | - | ||||||||||||||||||||||||||||||
| 3048 | 0, | - | ||||||||||||||||||||||||||||||
| 3049 | 2, | - | ||||||||||||||||||||||||||||||
| 3050 | QPixelFormat::IgnoresAlpha, | - | ||||||||||||||||||||||||||||||
| 3051 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 3052 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 3053 | QPixelFormat::UnsignedInteger, | - | ||||||||||||||||||||||||||||||
| 3054 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 3055 | - | |||||||||||||||||||||||||||||||
| 3056 | QPixelFormat(QPixelFormat::BGR, | - | ||||||||||||||||||||||||||||||
| 3057 | 10, | - | ||||||||||||||||||||||||||||||
| 3058 | 10, | - | ||||||||||||||||||||||||||||||
| 3059 | 10, | - | ||||||||||||||||||||||||||||||
| 3060 | 0, | - | ||||||||||||||||||||||||||||||
| 3061 | 0, | - | ||||||||||||||||||||||||||||||
| 3062 | 2, | - | ||||||||||||||||||||||||||||||
| 3063 | QPixelFormat::UsesAlpha, | - | ||||||||||||||||||||||||||||||
| 3064 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 3065 | QPixelFormat::Premultiplied, | - | ||||||||||||||||||||||||||||||
| 3066 | QPixelFormat::UnsignedInteger, | - | ||||||||||||||||||||||||||||||
| 3067 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 3068 | - | |||||||||||||||||||||||||||||||
| 3069 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 3070 | 10, | - | ||||||||||||||||||||||||||||||
| 3071 | 10, | - | ||||||||||||||||||||||||||||||
| 3072 | 10, | - | ||||||||||||||||||||||||||||||
| 3073 | 0, | - | ||||||||||||||||||||||||||||||
| 3074 | 0, | - | ||||||||||||||||||||||||||||||
| 3075 | 2, | - | ||||||||||||||||||||||||||||||
| 3076 | QPixelFormat::IgnoresAlpha, | - | ||||||||||||||||||||||||||||||
| 3077 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 3078 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 3079 | QPixelFormat::UnsignedInteger, | - | ||||||||||||||||||||||||||||||
| 3080 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 3081 | - | |||||||||||||||||||||||||||||||
| 3082 | QPixelFormat(QPixelFormat::RGB, | - | ||||||||||||||||||||||||||||||
| 3083 | 10, | - | ||||||||||||||||||||||||||||||
| 3084 | 10, | - | ||||||||||||||||||||||||||||||
| 3085 | 10, | - | ||||||||||||||||||||||||||||||
| 3086 | 0, | - | ||||||||||||||||||||||||||||||
| 3087 | 0, | - | ||||||||||||||||||||||||||||||
| 3088 | 2, | - | ||||||||||||||||||||||||||||||
| 3089 | QPixelFormat::UsesAlpha, | - | ||||||||||||||||||||||||||||||
| 3090 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 3091 | QPixelFormat::Premultiplied, | - | ||||||||||||||||||||||||||||||
| 3092 | QPixelFormat::UnsignedInteger, | - | ||||||||||||||||||||||||||||||
| 3093 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 3094 | - | |||||||||||||||||||||||||||||||
| 3095 | QPixelFormat(QPixelFormat::Alpha, | - | ||||||||||||||||||||||||||||||
| 3096 | 0, | - | ||||||||||||||||||||||||||||||
| 3097 | 0, | - | ||||||||||||||||||||||||||||||
| 3098 | 0, | - | ||||||||||||||||||||||||||||||
| 3099 | 0, | - | ||||||||||||||||||||||||||||||
| 3100 | 0, | - | ||||||||||||||||||||||||||||||
| 3101 | 8, | - | ||||||||||||||||||||||||||||||
| 3102 | QPixelFormat::UsesAlpha, | - | ||||||||||||||||||||||||||||||
| 3103 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 3104 | QPixelFormat::Premultiplied, | - | ||||||||||||||||||||||||||||||
| 3105 | QPixelFormat::UnsignedByte, | - | ||||||||||||||||||||||||||||||
| 3106 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 3107 | - | |||||||||||||||||||||||||||||||
| 3108 | QPixelFormat(QPixelFormat::Grayscale, | - | ||||||||||||||||||||||||||||||
| 3109 | 8, | - | ||||||||||||||||||||||||||||||
| 3110 | 0, | - | ||||||||||||||||||||||||||||||
| 3111 | 0, | - | ||||||||||||||||||||||||||||||
| 3112 | 0, | - | ||||||||||||||||||||||||||||||
| 3113 | 0, | - | ||||||||||||||||||||||||||||||
| 3114 | 0, | - | ||||||||||||||||||||||||||||||
| 3115 | QPixelFormat::IgnoresAlpha, | - | ||||||||||||||||||||||||||||||
| 3116 | QPixelFormat::AtBeginning, | - | ||||||||||||||||||||||||||||||
| 3117 | QPixelFormat::NotPremultiplied, | - | ||||||||||||||||||||||||||||||
| 3118 | QPixelFormat::UnsignedByte, | - | ||||||||||||||||||||||||||||||
| 3119 | QPixelFormat::CurrentSystemEndian), | - | ||||||||||||||||||||||||||||||
| 3120 | }; | - | ||||||||||||||||||||||||||||||
| 3121 | static_assert(bool(sizeof(pixelformats) / sizeof(*pixelformats) == QImage::NImageFormats), "sizeof(pixelformats) / sizeof(*pixelformats) == QImage::NImageFormats"); | - | ||||||||||||||||||||||||||||||
| 3122 | - | |||||||||||||||||||||||||||||||
| 3123 | - | |||||||||||||||||||||||||||||||
| 3124 | - | |||||||||||||||||||||||||||||||
| 3125 | - | |||||||||||||||||||||||||||||||
| 3126 | QPixelFormat QImage::pixelFormat() const noexcept | - | ||||||||||||||||||||||||||||||
| 3127 | { | - | ||||||||||||||||||||||||||||||
| 3128 | return never executed: toPixelFormat(format());return toPixelFormat(format());never executed: return toPixelFormat(format()); | 0 | ||||||||||||||||||||||||||||||
| 3129 | } | - | ||||||||||||||||||||||||||||||
| 3130 | - | |||||||||||||||||||||||||||||||
| 3131 | - | |||||||||||||||||||||||||||||||
| 3132 | - | |||||||||||||||||||||||||||||||
| 3133 | - | |||||||||||||||||||||||||||||||
| 3134 | QPixelFormat QImage::toPixelFormat(QImage::Format format) noexcept | - | ||||||||||||||||||||||||||||||
| 3135 | { | - | ||||||||||||||||||||||||||||||
| 3136 | ((!(static_cast<int>(format) < NImageFormats)) ? qt_assert("static_cast<int>(format) < NImageFormats",__FILE__,51725190) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 3137 | return never executed: pixelformats[format];return pixelformats[format];never executed: return pixelformats[format]; | 0 | ||||||||||||||||||||||||||||||
| 3138 | } | - | ||||||||||||||||||||||||||||||
| 3139 | - | |||||||||||||||||||||||||||||||
| 3140 | - | |||||||||||||||||||||||||||||||
| 3141 | - | |||||||||||||||||||||||||||||||
| 3142 | - | |||||||||||||||||||||||||||||||
| 3143 | QImage::Format QImage::toImageFormat(QPixelFormat format) noexcept | - | ||||||||||||||||||||||||||||||
| 3144 | { | - | ||||||||||||||||||||||||||||||
| 3145 | for (int i = 0; i < NImageFormats
| 0 | ||||||||||||||||||||||||||||||
| 3146 | if (format == pixelformats[i]
| 0 | ||||||||||||||||||||||||||||||
| 3147 | return never executed: Format(i);return Format(i);never executed: return Format(i); | 0 | ||||||||||||||||||||||||||||||
| 3148 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 3149 | return never executed: Format_Invalid;return Format_Invalid;never executed: return Format_Invalid; | 0 | ||||||||||||||||||||||||||||||
| 3150 | } | - | ||||||||||||||||||||||||||||||
| 3151 | - | |||||||||||||||||||||||||||||||
| 3152 | __attribute__((visibility("default"))) void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient) | - | ||||||||||||||||||||||||||||||
| 3153 | { | - | ||||||||||||||||||||||||||||||
| 3154 | if (orient == QImageIOHandler::TransformationNone) | - | ||||||||||||||||||||||||||||||
| 3155 | return; | - | ||||||||||||||||||||||||||||||
| 3156 | if (orient == QImageIOHandler::TransformationRotate270) { | - | ||||||||||||||||||||||||||||||
| 3157 | src = rotated270(src); | - | ||||||||||||||||||||||||||||||
| 3158 | } else { | - | ||||||||||||||||||||||||||||||
| 3159 | src = std::move(src).mirrored(orient & QImageIOHandler::TransformationMirror, | - | ||||||||||||||||||||||||||||||
| 3160 | orient & QImageIOHandler::TransformationFlip); | - | ||||||||||||||||||||||||||||||
| 3161 | if (orient & QImageIOHandler::TransformationRotate90) | - | ||||||||||||||||||||||||||||||
| 3162 | src = rotated90(src); | - | ||||||||||||||||||||||||||||||
| 3163 | } | - | ||||||||||||||||||||||||||||||
| 3164 | } | - | ||||||||||||||||||||||||||||||
| 3165 | - | |||||||||||||||||||||||||||||||
| 3166 | - | |||||||||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |