| 1 |
// Copyright (C) 2019 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 |
|
| 4 |
#include <cstdlib> |
| 5 |
|
| 6 |
#include <QGuiApplication> |
| 7 |
#include <QColor> |
| 8 |
#include <QColorSpace> |
| 9 |
#include <QImage> |
| 10 |
|
| 11 |
static QImage::Format toFormat(QColorSpace::ColorModel model) |
| 12 |
{ |
| 13 |
switch (model) { |
| 14 |
case QColorSpace::ColorModel::Rgb: |
| 15 |
return QImage::Format_RGB32; |
| 16 |
case QColorSpace::ColorModel::Gray: |
| 17 |
return QImage::Format_Grayscale16; |
| 18 |
case QColorSpace::ColorModel::Cmyk: |
| 19 |
return QImage::Format_CMYK8888; |
| 20 |
case QColorSpace::ColorModel::Undefined: |
| 21 |
break; |
| 22 |
} |
| 23 |
return QImage::Format_Invalid; |
| 24 |
} |
| 25 |
|
| 26 |
extern "C" int LLVMFuzzerTestOneInput(const char *data, size_t size) { |
| 27 |
// to reduce noise and increase speed |
| 28 |
static char quiet[] = "QT_LOGGING_RULES=qt.gui.icc=false"; |
| 29 |
static int pe = putenv(quiet); |
| 30 |
Q_UNUSED(pe); |
| 31 |
static int argc = 3; |
| 32 |
static char arg1[] = "fuzzer"; |
| 33 |
static char arg2[] = "-platform"; |
| 34 |
static char arg3[] = "minimal"; |
| 35 |
static char *argv[] = {arg1, arg2, arg3, nullptr}; |
| 36 |
static QGuiApplication qga(argc, argv); |
| 37 |
QColorSpace cs = QColorSpace::fromIccProfile(QByteArray::fromRawData(data, size)); |
| 38 |
if (cs.isValid()) { |
| 39 |
cs.description(); |
| 40 |
QColorTransform trans1 = cs.transformationToColorSpace(QColorSpace::SRgb); |
| 41 |
trans1.isIdentity(); |
| 42 |
QColorSpace cs2 = cs; |
| 43 |
cs2.setDescription("Hello"); |
| 44 |
Q_ASSERT(cs == cs2); |
| 45 |
QByteArray profileData = cs2.iccProfile(); |
| 46 |
QColorSpace cs3 = QColorSpace::fromIccProfile(profileData); |
| 47 |
Q_ASSERT(cs == cs3); |
| 48 |
QColor color(0xfaf8fa00); |
| 49 |
color = trans1.map(color); |
| 50 |
QImage img(16, 2, toFormat(cs.colorModel())); |
| 51 |
img.setColorSpace(cs); |
| 52 |
QImage img2 = img.convertedToColorSpace(QColorSpace::SRgb); |
| 53 |
if (cs.isValidTarget()) { |
| 54 |
QImage img3 = img2.convertedToColorSpace(cs); |
| 55 |
|
| 56 |
QColorTransform trans2 = QColorSpace(QColorSpace::SRgb).transformationToColorSpace(cs); |
| 57 |
bool a = (trans1 == trans2); |
| 58 |
Q_UNUSED(a); |
| 59 |
color = trans2.map(color); |
| 60 |
} |
| 61 |
} |
| 62 |
return 0; |
| 63 |
} |