diff options
Diffstat (limited to 'src/gui/image/qxbmhandler.cpp')
-rw-r--r-- | src/gui/image/qxbmhandler.cpp | 64 |
1 files changed, 14 insertions, 50 deletions
diff --git a/src/gui/image/qxbmhandler.cpp b/src/gui/image/qxbmhandler.cpp index 9c324aeeb9..8206fe3b29 100644 --- a/src/gui/image/qxbmhandler.cpp +++ b/src/gui/image/qxbmhandler.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** 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: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 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 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. -** -** 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include <qplatformdefs.h> #include "private/qxbmhandler_p.h" @@ -46,12 +10,14 @@ #include <qiodevice.h> #include <qloggingcategory.h> #include <qvariant.h> +#include <private/qtools_p.h> #include <stdio.h> -#include <ctype.h> QT_BEGIN_NAMESPACE +using namespace QtMiscUtils; + Q_DECLARE_LOGGING_CATEGORY(lcImageIo) /***************************************************************************** @@ -60,8 +26,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcImageIo) static inline int hex2byte(char *p) { - return ((isdigit((uchar) *p) ? *p - '0' : toupper((uchar) *p) - 'A' + 10) << 4) | - (isdigit((uchar) *(p+1)) ? *(p+1) - '0' : toupper((uchar) *(p+1)) - 'A' + 10); + return QtMiscUtils::fromHex(p[0]) * 16 | QtMiscUtils::fromHex(p[1]); } static bool read_xbm_header(QIODevice *device, int& w, int& h) @@ -91,11 +56,9 @@ static bool read_xbm_header(QIODevice *device, int& w, int& h) } auto parseDefine = [] (const char *buf, int len) -> int { - auto isAsciiLetterOrNumber = [] (char ch) -> bool { - return (ch >= '0' && ch <= '9') || - (ch >= 'A' && ch <= 'Z') || - (ch >= 'a' && ch <= 'z') || - ch == '_' || ch == '.'; + auto checkChar = [] (char ch) -> bool { + return isAsciiLetterOrNumber(ch) + || ch == '_' || ch == '.'; }; auto isAsciiSpace = [] (char ch) -> bool { return ch == ' ' || ch == '\t'; @@ -107,7 +70,7 @@ static bool read_xbm_header(QIODevice *device, int& w, int& h) int index = defineLen; while (buf[index] && isAsciiSpace(buf[index])) ++index; - while (buf[index] && isAsciiLetterOrNumber(buf[index])) + while (buf[index] && checkChar(buf[index])) ++index; while (buf[index] && isAsciiSpace(buf[index])) ++index; @@ -165,9 +128,10 @@ static bool read_xbm_body(QIODevice *device, int w, int h, QImage *outImage) while (y < h) { // for all encoded bytes... if (p && p < (buf + readBytes - 3)) { // p = "0x.." - if (!isxdigit(p[2]) || !isxdigit(p[3])) + const int byte = hex2byte(p + 2); + if (byte < 0) // non-hex char encountered return false; - *b++ = hex2byte(p+2); + *b++ = byte; p += 2; if (++x == w && ++y < h) { b = outImage->scanLine(y); @@ -200,7 +164,7 @@ static bool write_xbm_image(const QImage &sourceImage, QIODevice *device, const int h = image.height(); int i; QString s = fileName; // get file base name - int msize = s.length() + 100; + int msize = s.size() + 100; char *buf = new char[msize]; qsnprintf(buf, msize, "#define %s_width %d\n", s.toUtf8().data(), w); |