diff options
Diffstat (limited to 'src/gui/image/qimage.cpp')
-rw-r--r-- | src/gui/image/qimage.cpp | 108 |
1 files changed, 63 insertions, 45 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 17d3c02e36..64673d44b8 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -1,31 +1,37 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtGui module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -190,74 +196,81 @@ bool QImageData::checkForAlphaPixels() const break; case QImage::Format_ARGB32: case QImage::Format_ARGB32_Premultiplied: { - uchar *bits = data; + const uchar *bits = data; for (int y=0; y<height && !has_alpha_pixels; ++y) { + uint alphaAnd = 0xff000000; for (int x=0; x<width; ++x) - has_alpha_pixels |= (((uint *)bits)[x] & 0xff000000) != 0xff000000; + alphaAnd &= reinterpret_cast<const uint*>(bits)[x]; + has_alpha_pixels = (alphaAnd != 0xff000000); bits += bytes_per_line; } } break; case QImage::Format_RGBA8888: case QImage::Format_RGBA8888_Premultiplied: { - uchar *bits = data; + const uchar *bits = data; for (int y=0; y<height && !has_alpha_pixels; ++y) { + uchar alphaAnd = 0xff; for (int x=0; x<width; ++x) - has_alpha_pixels |= bits[x*4+3] != 0xff; + alphaAnd &= bits[x * 4+ 3]; + has_alpha_pixels = (alphaAnd != 0xff); bits += bytes_per_line; } } break; case QImage::Format_A2BGR30_Premultiplied: case QImage::Format_A2RGB30_Premultiplied: { - uchar *bits = data; + const uchar *bits = data; for (int y=0; y<height && !has_alpha_pixels; ++y) { + uint alphaAnd = 0xc0000000; for (int x=0; x<width; ++x) - has_alpha_pixels |= (((uint *)bits)[x] & 0xc0000000) != 0xc0000000; + alphaAnd &= reinterpret_cast<const uint*>(bits)[x]; + has_alpha_pixels = (alphaAnd != 0xc0000000); bits += bytes_per_line; } } break; case QImage::Format_ARGB8555_Premultiplied: case QImage::Format_ARGB8565_Premultiplied: { - uchar *bits = data; - uchar *end_bits = data + bytes_per_line; + const uchar *bits = data; + const uchar *end_bits = data + bytes_per_line; for (int y=0; y<height && !has_alpha_pixels; ++y) { + uchar alphaAnd = 0xff; while (bits < end_bits) { - has_alpha_pixels |= bits[0] != 0; + alphaAnd &= bits[0]; bits += 3; } + has_alpha_pixels = (alphaAnd != 0xff); bits = end_bits; end_bits += bytes_per_line; } } break; case QImage::Format_ARGB6666_Premultiplied: { - uchar *bits = data; - uchar *end_bits = data + bytes_per_line; + const uchar *bits = data; + const uchar *end_bits = data + bytes_per_line; for (int y=0; y<height && !has_alpha_pixels; ++y) { + uchar alphaAnd = 0xfc; while (bits < end_bits) { - has_alpha_pixels |= (bits[0] & 0xfc) != 0; + alphaAnd &= bits[0]; bits += 3; } + has_alpha_pixels = (alphaAnd != 0xfc); bits = end_bits; end_bits += bytes_per_line; } } break; case QImage::Format_ARGB4444_Premultiplied: { - uchar *bits = data; - uchar *end_bits = data + bytes_per_line; - + const uchar *bits = data; for (int y=0; y<height && !has_alpha_pixels; ++y) { - while (bits < end_bits) { - has_alpha_pixels |= (bits[0] & 0xf0) != 0; - bits += 2; - } - bits = end_bits; - end_bits += bytes_per_line; + ushort alphaAnd = 0xf000; + for (int x=0; x<width; ++x) + alphaAnd &= reinterpret_cast<const ushort*>(bits)[x]; + has_alpha_pixels = (alphaAnd != 0xf000); + bits += bytes_per_line; } } break; @@ -2060,10 +2073,10 @@ static QImage convertWithPalette(const QImage &src, QImage::Format format, dest.setColorTable(clut); QString textsKeys = src.text(); - QStringList textKeyList = textsKeys.split(QLatin1Char('\n'), QString::SkipEmptyParts); - foreach (const QString &textKey, textKeyList) { - QStringList textKeySplitted = textKey.split(QLatin1String(": ")); - dest.setText(textKeySplitted[0], textKeySplitted[1]); + const auto textKeyList = textsKeys.splitRef(QLatin1Char('\n'), QString::SkipEmptyParts); + for (const auto &textKey : textKeyList) { + const auto textKeySplitted = textKey.split(QLatin1String(": ")); + dest.setText(textKeySplitted[0].toString(), textKeySplitted[1].toString()); } int h = src.height(); @@ -2453,10 +2466,16 @@ QColor QImage::pixelColor(int x, int y) const */ void QImage::setPixelColor(int x, int y, const QColor &color) { - if (!d || x < 0 || x >= width() || y < 0 || y >= height() || !color.isValid()) { + if (!d || x < 0 || x >= width() || y < 0 || y >= height()) { qWarning("QImage::setPixelColor: coordinate (%d,%d) out of range", x, y); return; } + + if (!color.isValid()) { + qWarning("QImage::setPixelColor: color is invalid"); + return; + } + // QColor is always unpremultiplied QRgba64 c = color.rgba64(); if (!hasAlphaChannel()) @@ -3763,11 +3782,10 @@ QString QImage::text(const QString &key) const return d->text.value(key); QString tmp; - foreach (const QString &key, d->text.keys()) { - if (!tmp.isEmpty()) - tmp += QLatin1String("\n\n"); - tmp += key + QLatin1String(": ") + d->text.value(key).simplified(); - } + for (auto it = d->text.begin(), end = d->text.end(); it != end; ++it) + tmp += it.key() + QLatin1String(": ") + it.value().simplified() + QLatin1String("\n\n"); + if (!tmp.isEmpty()) + tmp.chop(2); // remove final \n\n return tmp; } |