Compare commits
1 Commits
v6.4.0-rc1
...
work/fuf/r
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
485e084fa9 |
@@ -2,9 +2,7 @@
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
include:
|
||||
- project: sysadmin/ci-utilities
|
||||
file:
|
||||
- /gitlab-templates/linux-qt6.yml
|
||||
- /gitlab-templates/android-qt6.yml
|
||||
- /gitlab-templates/freebsd-qt6.yml
|
||||
- /gitlab-templates/windows-qt6.yml
|
||||
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/linux-qt6.yml
|
||||
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/android-qt6.yml
|
||||
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/freebsd-qt6.yml
|
||||
- https://invent.kde.org/sysadmin/ci-utilities/raw/master/gitlab-templates/windows-qt6.yml
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Dependencies:
|
||||
- 'on': ['Linux', 'FreeBSD', 'macOS', 'Windows', 'Android']
|
||||
- 'on': ['Linux', 'FreeBSD', 'macOS', 'Windows']
|
||||
'require':
|
||||
'frameworks/extra-cmake-modules': '@same'
|
||||
'frameworks/karchive' : '@same'
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(KF_VERSION "6.4.0") # handled by release scripts
|
||||
set(KF_DEP_VERSION "6.4.0") # handled by release scripts
|
||||
project(KImageFormats VERSION ${KF_VERSION})
|
||||
project(KImageFormats)
|
||||
|
||||
include(FeatureSummary)
|
||||
find_package(ECM 6.4.0 NO_MODULE)
|
||||
find_package(ECM 5.240.0 NO_MODULE)
|
||||
set_package_properties(ECM PROPERTIES TYPE REQUIRED DESCRIPTION "Extra CMake Modules." URL "https://commits.kde.org/extra-cmake-modules")
|
||||
feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
||||
|
||||
@@ -24,7 +22,7 @@ include(FindPkgConfig)
|
||||
set(REQUIRED_QT_VERSION 6.5.0)
|
||||
find_package(Qt6Gui ${REQUIRED_QT_VERSION} REQUIRED NO_MODULE)
|
||||
|
||||
find_package(KF6Archive ${KF_DEP_VERSION})
|
||||
find_package(KF6Archive)
|
||||
set_package_properties(KF6Archive PROPERTIES
|
||||
TYPE OPTIONAL
|
||||
PURPOSE "Required for the QImage plugin for Krita and OpenRaster images"
|
||||
@@ -75,20 +73,15 @@ if(KIMAGEFORMATS_JXL)
|
||||
endif()
|
||||
add_feature_info(LibJXL LibJXL_FOUND "required for the QImage plugin for JPEG XL images")
|
||||
|
||||
# note: module FindLibRaw missing from https://invent.kde.org/frameworks/extra-cmake-modules
|
||||
find_package(LibRaw 0.20.2)
|
||||
set_package_properties(LibRaw PROPERTIES
|
||||
TYPE OPTIONAL
|
||||
PURPOSE "Required for the QImage plugin for RAW images"
|
||||
)
|
||||
|
||||
option(KIMAGEFORMATS_JXR "Enable plugin for JPEG XR format" OFF)
|
||||
if(KIMAGEFORMATS_JXR)
|
||||
find_package(LibJXR)
|
||||
endif()
|
||||
add_feature_info(LibJXR LibJXR_FOUND "required for the QImage plugin for JPEG XR images")
|
||||
|
||||
ecm_set_disabled_deprecation_versions(
|
||||
QT 6.5
|
||||
QT 6.4
|
||||
KF 5.102
|
||||
)
|
||||
|
||||
@@ -98,7 +91,6 @@ if (BUILD_TESTING)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
include(ECMFeatureSummary)
|
||||
ecm_feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
||||
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
||||
|
||||
kde_configure_git_pre_commit_hook(CHECKS CLANG_FORMAT)
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
Copyright (c) <year> <owner>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -1,11 +0,0 @@
|
||||
Copyright (c) <year> <owner>.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
11
README.md
@@ -17,21 +17,18 @@ The following image formats have read-only support:
|
||||
- Camera RAW images (arw, cr2, cr3, dcs, dng, ...)
|
||||
- Gimp (xcf)
|
||||
- Krita (kra)
|
||||
- OpenEXR (exr)
|
||||
- OpenRaster (ora)
|
||||
- Pixar raster (pxr)
|
||||
- Portable FloatMap (pfm)
|
||||
- Photoshop documents (psd, psb, pdd, psdt)
|
||||
- Radiance HDR (hdr)
|
||||
- Sun Raster (im1, im8, im24, im32, ras, sun)
|
||||
|
||||
The following image formats have read and write support:
|
||||
|
||||
- AV1 Image File Format (avif)
|
||||
- AV1 Image File Format (AVIF)
|
||||
- Encapsulated PostScript (eps)
|
||||
- High Efficiency Image File Format (heif). Can be enabled with the KIMAGEFORMATS_HEIF build option.
|
||||
- JPEG XL (jxl)
|
||||
- JPEG XR (jxr). Can be enabled with the KIMAGEFORMATS_JXR build option.
|
||||
- OpenEXR (exr)
|
||||
- Personal Computer Exchange (pcx)
|
||||
- Quite OK Image format (qoi)
|
||||
- SGI images (rgb, rgba, sgi, bw)
|
||||
@@ -48,6 +45,10 @@ of Qt is the license. As such, if you write an imageformat plugin and
|
||||
you are willing to sign the Qt Project contributor agreement, it may be
|
||||
better to submit the plugin directly to the Qt Project.
|
||||
|
||||
Note that the imageformat plugins provided by this module also provide a
|
||||
desktop file. This is for the benefit of KImageIO in the KDE4 Support
|
||||
framework.
|
||||
|
||||
## Duplicated Plugins
|
||||
|
||||
The TGA plugin supports more formats than Qt's own TGA plugin;
|
||||
|
||||
@@ -11,7 +11,7 @@ macro(kimageformats_read_tests)
|
||||
endif()
|
||||
|
||||
if (NOT TARGET readtest)
|
||||
add_executable(readtest readtest.cpp templateimage.cpp)
|
||||
add_executable(readtest readtest.cpp)
|
||||
target_link_libraries(readtest Qt6::Gui)
|
||||
target_compile_definitions(readtest
|
||||
PRIVATE IMAGEDIR="${CMAKE_CURRENT_SOURCE_DIR}/read")
|
||||
@@ -66,9 +66,7 @@ endmacro()
|
||||
kimageformats_read_tests(
|
||||
hdr
|
||||
pcx
|
||||
pfm
|
||||
psd
|
||||
pxr
|
||||
qoi
|
||||
ras
|
||||
rgb
|
||||
@@ -99,12 +97,6 @@ if (LibHeif_FOUND)
|
||||
kimageformats_write_tests(FUZZ 1
|
||||
heif-nodatacheck-lossless
|
||||
)
|
||||
|
||||
if (LibHeif_VERSION VERSION_GREATER_EQUAL "1.17.0")
|
||||
kimageformats_read_tests(FUZZ 1
|
||||
hej2
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (LibJXL_FOUND AND LibJXLThreads_FOUND)
|
||||
@@ -116,15 +108,6 @@ if (LibJXL_FOUND AND LibJXLThreads_FOUND)
|
||||
)
|
||||
endif()
|
||||
|
||||
if (LibJXR_FOUND)
|
||||
kimageformats_read_tests(
|
||||
jxr
|
||||
)
|
||||
kimageformats_write_tests(
|
||||
jxr-nodatacheck
|
||||
)
|
||||
endif()
|
||||
|
||||
# Allow some fuzziness when reading this formats, to allow for
|
||||
# rounding errors (eg: in alpha blending).
|
||||
kimageformats_read_tests(FUZZ 1
|
||||
@@ -155,11 +138,6 @@ if (OpenEXR_FOUND)
|
||||
kimageformats_read_tests(
|
||||
exr
|
||||
)
|
||||
# Color space conversions from sRGB to linear on saving and
|
||||
# from linear to sRGB on loading result in some rounding errors.
|
||||
kimageformats_write_tests(FUZZ 5
|
||||
exr-nodatacheck-lossless
|
||||
)
|
||||
endif()
|
||||
|
||||
if (LibRaw_FOUND)
|
||||
|
||||
|
Before Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 206 KiB |
|
Before Width: | Height: | Size: 16 KiB |
@@ -1,11 +0,0 @@
|
||||
[
|
||||
{
|
||||
"minQtVersion" : "6.8.0",
|
||||
"fileName" : "testcard_cmyk8.tif"
|
||||
},
|
||||
{
|
||||
"maxQtVersion" : "6.7.99",
|
||||
"unsupportedFormat" : true,
|
||||
"comment" : "Qt versions lower than 6.8 do not support CMYK format so this test should be skipped."
|
||||
}
|
||||
]
|
||||
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 8.2 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 26 KiB |
@@ -1,11 +0,0 @@
|
||||
[
|
||||
{
|
||||
"minQtVersion" : "6.8.0",
|
||||
"fileName" : "cmyk16_testcard_qt6_8.tif"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.0.0",
|
||||
"maxQtVersion" : "6.7.99",
|
||||
"fileName" : "cmyk16_testcard.png"
|
||||
}
|
||||
]
|
||||
|
Before Width: | Height: | Size: 13 KiB |
@@ -1,11 +0,0 @@
|
||||
[
|
||||
{
|
||||
"minQtVersion" : "6.8.0",
|
||||
"fileName" : "cmyk8_testcard_qt6_8.tif"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.0.0",
|
||||
"maxQtVersion" : "6.7.99",
|
||||
"fileName" : "cmyk8_testcard.png"
|
||||
}
|
||||
]
|
||||
@@ -1,11 +0,0 @@
|
||||
[
|
||||
{
|
||||
"minQtVersion" : "6.8.0",
|
||||
"fileName" : "cmyka-16bits_qt6_8.png"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.0.0",
|
||||
"maxQtVersion" : "6.7.99",
|
||||
"fileName" : "cmyka-16bits.png"
|
||||
}
|
||||
]
|
||||
|
Before Width: | Height: | Size: 111 KiB |
@@ -1,11 +0,0 @@
|
||||
[
|
||||
{
|
||||
"minQtVersion" : "6.8.0",
|
||||
"fileName" : "cmyka-8bits_qt6_8.png"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.0.0",
|
||||
"maxQtVersion" : "6.7.99",
|
||||
"fileName" : "cmyka-8bits.png"
|
||||
}
|
||||
]
|
||||
|
Before Width: | Height: | Size: 77 KiB |
@@ -1,11 +0,0 @@
|
||||
[
|
||||
{
|
||||
"minQtVersion" : "6.8.0",
|
||||
"fileName" : "mch-16bits_qt_6_8.tif"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.0.0",
|
||||
"maxQtVersion" : "6.7.99",
|
||||
"fileName" : "mch-16bits.png"
|
||||
}
|
||||
]
|
||||
@@ -1,11 +0,0 @@
|
||||
[
|
||||
{
|
||||
"minQtVersion" : "6.8.0",
|
||||
"fileName" : "mch-8bits_qt_6.8.tif"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.0.0",
|
||||
"maxQtVersion" : "6.7.99",
|
||||
"fileName" : "mch-8bits.png"
|
||||
}
|
||||
]
|
||||
|
Before Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 91 KiB |
@@ -1,32 +0,0 @@
|
||||
[
|
||||
{
|
||||
"minQtVersion" : "6.7.0",
|
||||
"fileName" : "birthday16.png",
|
||||
"seeAlso" : "https://bugreports.qt.io/browse/QTBUG-120614"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.0.0",
|
||||
"maxQtVersion" : "6.2.10",
|
||||
"fileName" : "birthday16_alphabug.png"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.3.0",
|
||||
"maxQtVersion" : "6.3.2",
|
||||
"fileName" : "birthday32_alphabug.png"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.4.0",
|
||||
"maxQtVersion" : "6.4.3",
|
||||
"fileName" : "birthday32_alphabug.png"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.5.0",
|
||||
"maxQtVersion" : "6.5.4",
|
||||
"fileName" : "birthday16_alphabug.png"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.6.0",
|
||||
"maxQtVersion" : "6.6.1",
|
||||
"fileName" : "birthday16_alphabug.png"
|
||||
}
|
||||
]
|
||||
|
Before Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 91 KiB |
@@ -1,32 +0,0 @@
|
||||
[
|
||||
{
|
||||
"minQtVersion" : "6.7.0",
|
||||
"fileName" : "birthday32.png",
|
||||
"seeAlso" : "https://bugreports.qt.io/browse/QTBUG-120614"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.0.0",
|
||||
"maxQtVersion" : "6.2.10",
|
||||
"fileName" : "birthday32_alphabug.png"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.3.0",
|
||||
"maxQtVersion" : "6.3.2",
|
||||
"fileName" : "birthday32_alphabug.png"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.4.0",
|
||||
"maxQtVersion" : "6.4.3",
|
||||
"fileName" : "birthday32_alphabug.png"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.5.0",
|
||||
"maxQtVersion" : "6.5.4",
|
||||
"fileName" : "birthday32_alphabug.png"
|
||||
},
|
||||
{
|
||||
"minQtVersion" : "6.6.0",
|
||||
"maxQtVersion" : "6.6.1",
|
||||
"fileName" : "birthday32_alphabug.png"
|
||||
}
|
||||
]
|
||||
|
Before Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 234 KiB |
|
Before Width: | Height: | Size: 234 KiB |
@@ -16,7 +16,6 @@
|
||||
#include <QTextStream>
|
||||
|
||||
#include "../tests/format-enum.h"
|
||||
#include "templateimage.h"
|
||||
|
||||
#include "fuzzyeq.cpp"
|
||||
|
||||
@@ -90,114 +89,13 @@ static QImage::Format preferredFormat(QImage::Format fmt)
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief The OptionTest class
|
||||
* Class for testing image options.
|
||||
* Supports the most common options:
|
||||
* - Size
|
||||
* - ImageFormat
|
||||
* - ImageTransformation (rotations)
|
||||
* \todo Add missing options if needed.
|
||||
*/
|
||||
class OptionTest
|
||||
{
|
||||
public:
|
||||
OptionTest()
|
||||
: m_size(QSize())
|
||||
, m_format(QImage::Format_Invalid)
|
||||
, m_transformations(QImageIOHandler::TransformationNone)
|
||||
{
|
||||
}
|
||||
|
||||
OptionTest(const OptionTest&) = default;
|
||||
OptionTest& operator =(const OptionTest&) = default;
|
||||
|
||||
/*!
|
||||
* \brief store
|
||||
* Stores the supported options of the reader.
|
||||
* \param reader
|
||||
* \return True on success, otherwise false.
|
||||
*/
|
||||
bool store(const QImageReader *reader = nullptr)
|
||||
{
|
||||
if (reader == nullptr) {
|
||||
return false;
|
||||
}
|
||||
bool ok = true;
|
||||
if (reader->supportsOption(QImageIOHandler::Size)) {
|
||||
m_size = reader->size();
|
||||
if (m_size.isEmpty())
|
||||
ok = false;
|
||||
}
|
||||
if (reader->supportsOption(QImageIOHandler::ImageFormat)) {
|
||||
m_format = reader->imageFormat();
|
||||
if (m_format == QImage::Format_Invalid)
|
||||
ok = false;
|
||||
}
|
||||
if (reader->supportsOption(QImageIOHandler::ImageTransformation)) {
|
||||
m_transformations = reader->transformation();
|
||||
if (m_transformations < 0 || m_transformations > 7)
|
||||
ok = false;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief compare
|
||||
* Compare the stored values with the ones read from the image reader.
|
||||
* \param reader
|
||||
* \return True on success, otherwise false.
|
||||
*/
|
||||
bool compare(const QImageReader *reader)
|
||||
{
|
||||
if (reader == nullptr) {
|
||||
return false;
|
||||
}
|
||||
bool ok = true;
|
||||
if (reader->supportsOption(QImageIOHandler::Size)) {
|
||||
ok = ok && (m_size == reader->size());
|
||||
}
|
||||
if (reader->supportsOption(QImageIOHandler::ImageFormat)) {
|
||||
ok = ok && (m_format == reader->imageFormat());
|
||||
}
|
||||
if (reader->supportsOption(QImageIOHandler::ImageTransformation)) {
|
||||
ok = ok && (m_transformations == reader->transformation());
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief compare
|
||||
* Compare the image properties with the ones stored.
|
||||
* \param image
|
||||
* \return True on success, otherwise false.
|
||||
*/
|
||||
bool compare(const QImage& image)
|
||||
{
|
||||
bool ok = true;
|
||||
if (!m_size.isEmpty()) {
|
||||
ok = ok && (m_size == image.size());
|
||||
}
|
||||
if (m_format != QImage::Format_Invalid) {
|
||||
ok = ok && (m_format == image.format());
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
private:
|
||||
QSize m_size;
|
||||
QImage::Format m_format;
|
||||
QImageIOHandler::Transformations m_transformations;
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
QCoreApplication::removeLibraryPath(QStringLiteral(PLUGIN_DIR));
|
||||
QCoreApplication::addLibraryPath(QStringLiteral(PLUGIN_DIR));
|
||||
QCoreApplication::setApplicationName(QStringLiteral("readtest"));
|
||||
QCoreApplication::setApplicationVersion(QStringLiteral("1.2.0"));
|
||||
QCoreApplication::setApplicationVersion(QStringLiteral("1.1.0"));
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(QStringLiteral("Performs basic image conversion checking."));
|
||||
@@ -261,30 +159,22 @@ int main(int argc, char **argv)
|
||||
QTextStream(stdout) << "* Run on RANDOM ACCESS device\n";
|
||||
}
|
||||
for (const QFileInfo &fi : lstImgDir) {
|
||||
TemplateImage timg(fi);
|
||||
if (timg.isTemplate()) {
|
||||
if (!fi.suffix().compare("png", Qt::CaseInsensitive) || !fi.suffix().compare("tif", Qt::CaseInsensitive)) {
|
||||
continue;
|
||||
}
|
||||
int suffixPos = fi.filePath().size() - suffix.size();
|
||||
QString inputfile = fi.filePath();
|
||||
QString fmt = QStringLiteral("png");
|
||||
QString expfile = fi.filePath().replace(suffixPos, suffix.size(), fmt);
|
||||
if (!QFile::exists(expfile)) { // try with tiff
|
||||
fmt = QStringLiteral("tif");
|
||||
expfile = fi.filePath().replace(suffixPos, suffix.size(), fmt);
|
||||
}
|
||||
QString expfilename = QFileInfo(expfile).fileName();
|
||||
|
||||
bool skipTest = false;
|
||||
QFileInfo expFileInfo = timg.compareImage(skipTest);
|
||||
if (skipTest) {
|
||||
QTextStream(stdout) << "SKIP : " << fi.fileName() << ": image format not supported by current Qt version!\n";
|
||||
++skipped;
|
||||
continue;
|
||||
}
|
||||
if (!formatStrings.contains(expFileInfo.suffix(), Qt::CaseInsensitive)) {
|
||||
// Work Around for CCBUG: 468288
|
||||
QTextStream(stdout) << "SKIP : " << fi.fileName() << ": comparison image " << expFileInfo.fileName() << " cannot be loaded due to the lack of "
|
||||
<< expFileInfo.suffix().toUpper() << " plugin!\n";
|
||||
++skipped;
|
||||
continue;
|
||||
}
|
||||
QString expfilename = expFileInfo.fileName();
|
||||
|
||||
std::unique_ptr<QIODevice> inputDevice(seq ? new SequentialFile(fi.filePath()) : new QFile(fi.filePath()));
|
||||
std::unique_ptr<QIODevice> inputDevice(seq ? new SequentialFile(inputfile) : new QFile(inputfile));
|
||||
QImageReader inputReader(inputDevice.get(), format);
|
||||
QImageReader expReader(expFileInfo.filePath());
|
||||
QImageReader expReader(expfile, fmt.toLatin1());
|
||||
|
||||
QImage inputImage;
|
||||
QImage expImage;
|
||||
@@ -309,32 +199,11 @@ int main(int argc, char **argv)
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
OptionTest optionTest;
|
||||
if (!optionTest.store(&inputReader)) {
|
||||
QTextStream(stdout) << "FAIL : " << fi.fileName() << ": error while reading options\n";
|
||||
++failed;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!inputReader.read(&inputImage)) {
|
||||
QTextStream(stdout) << "FAIL : " << fi.fileName() << ": failed to load: " << inputReader.errorString() << "\n";
|
||||
++failed;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!optionTest.compare(&inputReader)) {
|
||||
QTextStream(stdout) << "FAIL : " << fi.fileName() << ": error while comparing options\n";
|
||||
++failed;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!optionTest.compare(inputImage)) {
|
||||
QTextStream(stdout) << "FAIL : " << fi.fileName() << ": error while comparing the image properties with options\n";
|
||||
++failed;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (expImage.width() != inputImage.width()) {
|
||||
QTextStream(stdout) << "FAIL : " << fi.fileName() << ": width was " << inputImage.width() << " but " << expfilename << " width was "
|
||||
<< expImage.width() << "\n";
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2024 Mirco Miranda <mircomir@outlook.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||
*/
|
||||
|
||||
#include "templateimage.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QVersionNumber>
|
||||
|
||||
TemplateImage::TemplateImage(const QFileInfo &fi) :
|
||||
m_fi(fi)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool TemplateImage::isTemplate() const
|
||||
{
|
||||
auto list = suffixes();
|
||||
for (auto&& suffix : list) {
|
||||
if (!m_fi.suffix().compare(suffix, Qt::CaseInsensitive))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QFileInfo TemplateImage::compareImage(bool &skipTest) const
|
||||
{
|
||||
auto fi = jsonImage(skipTest);
|
||||
if (skipTest) {
|
||||
return {};
|
||||
}
|
||||
if (fi.exists()) {
|
||||
return fi;
|
||||
}
|
||||
return legacyImage();
|
||||
}
|
||||
|
||||
|
||||
QStringList TemplateImage::suffixes()
|
||||
{
|
||||
return QStringList({"png", "tif", "tiff", "json"});
|
||||
}
|
||||
|
||||
QFileInfo TemplateImage::legacyImage() const
|
||||
{
|
||||
auto list = suffixes();
|
||||
for (auto&& suffix : list) {
|
||||
auto fi = QFileInfo(QStringLiteral("%1/%2.%3").arg(m_fi.path(), m_fi.completeBaseName(), suffix));
|
||||
if (fi.exists()) {
|
||||
return fi;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
QFileInfo TemplateImage::jsonImage(bool &skipTest) const
|
||||
{
|
||||
auto fi = QFileInfo(QStringLiteral("%1.json").arg(m_fi.filePath()));
|
||||
if (!fi.exists()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
QFile f(fi.filePath());
|
||||
if (!f.open(QFile::ReadOnly)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
QJsonParseError err;
|
||||
auto doc = QJsonDocument::fromJson(f.readAll(), &err);
|
||||
if (err.error != QJsonParseError::NoError || !doc.isArray()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto currentQt = QVersionNumber::fromString(qVersion());
|
||||
auto arr = doc.array();
|
||||
for (auto val : arr) {
|
||||
if (!val.isObject())
|
||||
continue;
|
||||
auto obj = val.toObject();
|
||||
auto minQt = QVersionNumber::fromString(obj.value("minQtVersion").toString());
|
||||
auto maxQt = QVersionNumber::fromString(obj.value("maxQtVersion").toString());
|
||||
auto name = obj.value("fileName").toString();
|
||||
auto unsupportedFormat = obj.value("unsupportedFormat").toBool();
|
||||
|
||||
// filter
|
||||
if (name.isEmpty() && !unsupportedFormat)
|
||||
continue;
|
||||
if (!minQt.isNull() && currentQt < minQt)
|
||||
continue;
|
||||
if (!maxQt.isNull() && currentQt > maxQt)
|
||||
continue;
|
||||
if (unsupportedFormat) {
|
||||
skipTest = true;
|
||||
break;
|
||||
}
|
||||
return QFileInfo(QStringLiteral("%1/%2").arg(fi.path(), name));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
SPDX-FileCopyrightText: 2024 Mirco Miranda <mircomir@outlook.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
||||
*/
|
||||
|
||||
#ifndef TEMPLATEIMAGE_H
|
||||
#define TEMPLATEIMAGE_H
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
/*!
|
||||
* \brief The TemplateImage class
|
||||
* Given an image name, it decides the template image to compare it with.
|
||||
*/
|
||||
class TemplateImage
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* \brief TemplateImage
|
||||
* \param fi The image to test.
|
||||
*/
|
||||
TemplateImage(const QFileInfo& fi);
|
||||
|
||||
/*!
|
||||
* \brief TemplateImage
|
||||
* Default copy constructor.
|
||||
*/
|
||||
TemplateImage(const TemplateImage& other) = default;
|
||||
/*!
|
||||
* \brief operator =
|
||||
* Default copy operator
|
||||
*/
|
||||
TemplateImage& operator=(const TemplateImage& other) = default;
|
||||
|
||||
/*!
|
||||
* \brief isTemplate
|
||||
* \return True if the image is a template, false otherwise.
|
||||
* \sa suffixes
|
||||
*/
|
||||
bool isTemplate() const;
|
||||
|
||||
/*!
|
||||
* \brief compareImage
|
||||
* \param skipTest True if the test should be skipped (e.g. image format not supported by current Qt version).
|
||||
* \return The template image to use for the comparison.
|
||||
*/
|
||||
QFileInfo compareImage(bool &skipTest) const;
|
||||
|
||||
/*!
|
||||
* \brief suffixes
|
||||
* \return The list of suffixes considered templates.
|
||||
*/
|
||||
static QStringList suffixes();
|
||||
|
||||
private:
|
||||
/*!
|
||||
* \brief legacyImage
|
||||
* \return The template image calculated from the source image name.
|
||||
*/
|
||||
QFileInfo legacyImage() const;
|
||||
|
||||
/*!
|
||||
* \brief jsonImage
|
||||
* \param skipTest True if the test should be skipped (not supported).
|
||||
* \return The template image read from the corresponding JSON.
|
||||
*/
|
||||
QFileInfo jsonImage(bool &skipTest) const;
|
||||
|
||||
private:
|
||||
QFileInfo m_fi;
|
||||
};
|
||||
|
||||
#endif // TEMPLATEIMAGE_H
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QColorSpace>
|
||||
#include <QCommandLineParser>
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
@@ -24,8 +23,8 @@ int main(int argc, char **argv)
|
||||
QCoreApplication app(argc, argv);
|
||||
QCoreApplication::removeLibraryPath(QStringLiteral(PLUGIN_DIR));
|
||||
QCoreApplication::addLibraryPath(QStringLiteral(PLUGIN_DIR));
|
||||
QCoreApplication::setApplicationName(QStringLiteral("writetest"));
|
||||
QCoreApplication::setApplicationVersion(QStringLiteral("1.1.0"));
|
||||
QCoreApplication::setApplicationName(QStringLiteral("readtest"));
|
||||
QCoreApplication::setApplicationVersion(QStringLiteral("1.0.0"));
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(QStringLiteral("Performs basic image conversion checking."));
|
||||
@@ -149,14 +148,6 @@ int main(int argc, char **argv)
|
||||
++failed;
|
||||
continue;
|
||||
}
|
||||
if (reReadImage.colorSpace().isValid()) {
|
||||
QColorSpace toColorSpace;
|
||||
if (pngImage.colorSpace().isValid()) {
|
||||
reReadImage.convertToColorSpace(pngImage.colorSpace());
|
||||
} else {
|
||||
reReadImage.convertToColorSpace(QColorSpace(QColorSpace::SRgb));
|
||||
}
|
||||
}
|
||||
reReadImage = reReadImage.convertToFormat(pngImage.format());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
# - Find LibJXR
|
||||
# Find the JXR library
|
||||
# This module defines
|
||||
# LIBJXR_INCLUDE_DIRS, where to find jxrlib/JXRGlue.h
|
||||
# LIBJXR_LIBRARIES, the libraries needed to use JXR
|
||||
#
|
||||
# Based on cmake code found at https://github.com/microsoft/vcpkg/blob/master/ports/jxrlib/FindJXR.cmake
|
||||
|
||||
find_path(LIBJXR_INCLUDE_DIRS
|
||||
NAMES JXRGlue.h
|
||||
PATH_SUFFIXES jxrlib
|
||||
)
|
||||
mark_as_advanced(LIBJXR_INCLUDE_DIRS)
|
||||
|
||||
include(SelectLibraryConfigurations)
|
||||
|
||||
find_library(LIBJPEGXR_LIBRARY NAMES jpegxr)
|
||||
find_library(LIBJXRGLUE_LIBRARY NAMES jxrglue)
|
||||
|
||||
set(LIBJXR_LIBRARIES ${LIBJPEGXR_LIBRARY} ${LIBJXRGLUE_LIBRARY})
|
||||
mark_as_advanced(LIBJXR_LIBRARIES)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibJXR DEFAULT_MSG LIBJXR_INCLUDE_DIRS LIBJXR_LIBRARIES)
|
||||
@@ -1,3 +1,4 @@
|
||||
maintainer: alexmerry
|
||||
description: Image format plugins for Qt
|
||||
tier: 2
|
||||
type: functional
|
||||
|
||||
@@ -41,7 +41,7 @@ endif()
|
||||
##################################
|
||||
|
||||
if(OpenEXR_FOUND)
|
||||
kimageformats_add_plugin(kimg_exr SOURCES exr.cpp scanlineconverter.cpp)
|
||||
kimageformats_add_plugin(kimg_exr SOURCES exr.cpp)
|
||||
if(TARGET OpenEXR::OpenEXR)
|
||||
target_link_libraries(kimg_exr PRIVATE OpenEXR::OpenEXR)
|
||||
else()
|
||||
@@ -83,15 +83,7 @@ kimageformats_add_plugin(kimg_pic SOURCES pic.cpp)
|
||||
|
||||
##################################
|
||||
|
||||
kimageformats_add_plugin(kimg_pfm SOURCES pfm.cpp)
|
||||
|
||||
##################################
|
||||
|
||||
kimageformats_add_plugin(kimg_psd SOURCES psd.cpp scanlineconverter.cpp)
|
||||
|
||||
##################################
|
||||
|
||||
kimageformats_add_plugin(kimg_pxr SOURCES pxr.cpp)
|
||||
kimageformats_add_plugin(kimg_psd SOURCES psd.cpp)
|
||||
|
||||
##################################
|
||||
|
||||
@@ -123,20 +115,6 @@ endif()
|
||||
|
||||
##################################
|
||||
|
||||
if (LibJXR_FOUND)
|
||||
kimageformats_add_plugin(kimg_jxr SOURCES jxr.cpp)
|
||||
kde_enable_exceptions()
|
||||
target_include_directories(kimg_jxr PRIVATE ${LIBJXR_INCLUDE_DIRS})
|
||||
target_link_libraries(kimg_jxr PRIVATE jpegxr jxrglue)
|
||||
target_compile_definitions(kimg_jxr PRIVATE INITGUID)
|
||||
if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=undef")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=undef")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
##################################
|
||||
|
||||
if (KF6Archive_FOUND)
|
||||
|
||||
kimageformats_add_plugin(kimg_kra SOURCES kra.cpp)
|
||||
|
||||
@@ -383,7 +383,7 @@ bool ANIHandler::ensureScanned() const
|
||||
|
||||
// TODO should we check that the number of rate entries matches nSteps?
|
||||
auto *dataPtr = data.data();
|
||||
QList<int> list;
|
||||
QVector<int> list;
|
||||
for (int i = 0; i < data.size(); i += sizeof(quint32_le)) {
|
||||
const auto entry = *(reinterpret_cast<const quint32_le *>(dataPtr + i));
|
||||
list.append(entry);
|
||||
|
||||
@@ -41,14 +41,14 @@ private:
|
||||
int m_frameCount = 0; // "physical" frames
|
||||
int m_imageCount = 0; // logical images
|
||||
// Stores a custom sequence of images
|
||||
QList<int> m_imageSequence;
|
||||
QVector<int> m_imageSequence;
|
||||
// and the corresponding offsets where they are
|
||||
// since we can't read the image data sequentally in this case then
|
||||
QList<qint64> m_frameOffsets;
|
||||
QVector<qint64> m_frameOffsets;
|
||||
qint64 m_firstFrameOffset = 0;
|
||||
|
||||
int m_displayRate = 0;
|
||||
QList<int> m_displayRates;
|
||||
QVector<int> m_displayRates;
|
||||
|
||||
QString m_name;
|
||||
QString m_artist;
|
||||
|
||||
@@ -16,34 +16,9 @@
|
||||
|
||||
#include <cfloat>
|
||||
|
||||
/*
|
||||
Quality range - compression/subsampling
|
||||
100 - lossless RGB compression
|
||||
< KIMG_AVIF_QUALITY_BEST, 100 ) - YUV444 color subsampling
|
||||
< KIMG_AVIF_QUALITY_HIGH, KIMG_AVIF_QUALITY_BEST ) - YUV422 color subsampling
|
||||
< 0, KIMG_AVIF_QUALITY_HIGH ) - YUV420 color subsampling
|
||||
< 0, KIMG_AVIF_QUALITY_LOW ) - lossy compression of alpha channel
|
||||
*/
|
||||
|
||||
#ifndef KIMG_AVIF_DEFAULT_QUALITY
|
||||
#define KIMG_AVIF_DEFAULT_QUALITY 68
|
||||
#endif
|
||||
|
||||
#ifndef KIMG_AVIF_QUALITY_BEST
|
||||
#define KIMG_AVIF_QUALITY_BEST 90
|
||||
#endif
|
||||
|
||||
#ifndef KIMG_AVIF_QUALITY_HIGH
|
||||
#define KIMG_AVIF_QUALITY_HIGH 80
|
||||
#endif
|
||||
|
||||
#ifndef KIMG_AVIF_QUALITY_LOW
|
||||
#define KIMG_AVIF_QUALITY_LOW 51
|
||||
#endif
|
||||
|
||||
QAVIFHandler::QAVIFHandler()
|
||||
: m_parseState(ParseAvifNotParsed)
|
||||
, m_quality(KIMG_AVIF_DEFAULT_QUALITY)
|
||||
, m_quality(52)
|
||||
, m_container_width(0)
|
||||
, m_container_height(0)
|
||||
, m_rawAvifData(AVIF_DATA_EMPTY)
|
||||
@@ -355,10 +330,6 @@ bool QAVIFHandler::decode_one_frame()
|
||||
avifRGBImage rgb;
|
||||
avifRGBImageSetDefaults(&rgb, m_decoder->image);
|
||||
|
||||
#if AVIF_VERSION >= 1000000
|
||||
rgb.maxThreads = m_decoder->maxThreads;
|
||||
#endif
|
||||
|
||||
if (m_decoder->image->depth > 8) {
|
||||
rgb.depth = 16;
|
||||
rgb.format = AVIF_RGB_FORMAT_RGBA;
|
||||
@@ -544,17 +515,9 @@ bool QAVIFHandler::write(const QImage &image)
|
||||
}
|
||||
}
|
||||
|
||||
if (m_quality > 100) {
|
||||
m_quality = 100;
|
||||
} else if (m_quality < 0) {
|
||||
m_quality = KIMG_AVIF_DEFAULT_QUALITY;
|
||||
}
|
||||
|
||||
#if AVIF_VERSION < 1000000
|
||||
int maxQuantizer = AVIF_QUANTIZER_WORST_QUALITY * (100 - qBound(0, m_quality, 100)) / 100;
|
||||
int minQuantizer = 0;
|
||||
int maxQuantizerAlpha = 0;
|
||||
#endif
|
||||
avifResult res;
|
||||
|
||||
bool save_grayscale; // true - monochrome, false - colors
|
||||
@@ -600,15 +563,13 @@ bool QAVIFHandler::write(const QImage &image)
|
||||
break;
|
||||
}
|
||||
|
||||
#if AVIF_VERSION < 1000000
|
||||
// deprecated quality settings
|
||||
// quality settings
|
||||
if (maxQuantizer > 20) {
|
||||
minQuantizer = maxQuantizer - 20;
|
||||
if (maxQuantizer > 40) { // we decrease quality of alpha channel here
|
||||
maxQuantizerAlpha = maxQuantizer - 40;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (save_grayscale && !image.hasAlphaChannel()) { // we are going to save grayscale image without alpha channel
|
||||
if (save_depth > 8) {
|
||||
@@ -681,8 +642,8 @@ bool QAVIFHandler::write(const QImage &image)
|
||||
QImage tmpcolorimage = image.convertToFormat(tmpformat);
|
||||
|
||||
avifPixelFormat pixel_format = AVIF_PIXEL_FORMAT_YUV420;
|
||||
if (m_quality >= KIMG_AVIF_QUALITY_HIGH) {
|
||||
if (m_quality >= KIMG_AVIF_QUALITY_BEST) {
|
||||
if (maxQuantizer < 20) {
|
||||
if (maxQuantizer < 10) {
|
||||
pixel_format = AVIF_PIXEL_FORMAT_YUV444; // best quality
|
||||
} else {
|
||||
pixel_format = AVIF_PIXEL_FORMAT_YUV422; // high quality
|
||||
@@ -842,8 +803,6 @@ bool QAVIFHandler::write(const QImage &image)
|
||||
avifRWData raw = AVIF_DATA_EMPTY;
|
||||
avifEncoder *encoder = avifEncoderCreate();
|
||||
encoder->maxThreads = qBound(1, QThread::idealThreadCount(), 64);
|
||||
|
||||
#if AVIF_VERSION < 1000000
|
||||
encoder->minQuantizer = minQuantizer;
|
||||
encoder->maxQuantizer = maxQuantizer;
|
||||
|
||||
@@ -851,17 +810,6 @@ bool QAVIFHandler::write(const QImage &image)
|
||||
encoder->minQuantizerAlpha = AVIF_QUANTIZER_LOSSLESS;
|
||||
encoder->maxQuantizerAlpha = maxQuantizerAlpha;
|
||||
}
|
||||
#else
|
||||
encoder->quality = m_quality;
|
||||
|
||||
if (image.hasAlphaChannel()) {
|
||||
if (m_quality >= KIMG_AVIF_QUALITY_LOW) {
|
||||
encoder->qualityAlpha = 100;
|
||||
} else {
|
||||
encoder->qualityAlpha = 100 - (KIMG_AVIF_QUALITY_LOW - m_quality) / 2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
encoder->speed = 6;
|
||||
|
||||
@@ -918,7 +866,7 @@ void QAVIFHandler::setOption(ImageOption option, const QVariant &value)
|
||||
if (m_quality > 100) {
|
||||
m_quality = 100;
|
||||
} else if (m_quality < 0) {
|
||||
m_quality = KIMG_AVIF_DEFAULT_QUALITY;
|
||||
m_quality = 52;
|
||||
}
|
||||
return;
|
||||
default:
|
||||
@@ -1091,11 +1039,6 @@ int QAVIFHandler::loopCount() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if AVIF_VERSION >= 1000000
|
||||
if (m_decoder->repetitionCount >= 0) {
|
||||
return m_decoder->repetitionCount;
|
||||
}
|
||||
#endif
|
||||
// Endless loop to work around https://github.com/AOMediaCodec/libavif/issues/347
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
The high dynamic range EXR format support for QImage.
|
||||
KImageIO Routines to read (and perhaps in the future, write) images
|
||||
in the high dynamic range EXR format.
|
||||
|
||||
SPDX-FileCopyrightText: 2003 Brad Hards <bradh@frogmouth.net>
|
||||
SPDX-FileCopyrightText: 2023 Mirco Miranda <mircomir@outlook.com>
|
||||
@@ -15,52 +16,15 @@
|
||||
*/
|
||||
//#define EXR_USE_LEGACY_CONVERSIONS // default commented -> you should define it in your cmake file
|
||||
|
||||
/* *** EXR_CONVERT_TO_SRGB ***
|
||||
* If defined, the linear data is converted to sRGB on read to accommodate
|
||||
* programs that do not support color profiles.
|
||||
* Otherwise the data are kept as is and it is the display program that
|
||||
* must convert to the monitor profile.
|
||||
/* *** EXR_ALLOW_LINEAR_COLORSPACE ***
|
||||
* If defined, the linear data is kept and it is the display program that
|
||||
* must convert to the monitor profile. Otherwise the data is converted to sRGB
|
||||
* to accommodate programs that do not support color profiles.
|
||||
* NOTE: If EXR_USE_LEGACY_CONVERSIONS is active, this is ignored.
|
||||
*/
|
||||
//#define EXR_CONVERT_TO_SRGB // default: commented -> you should define it in your cmake file
|
||||
|
||||
/* *** EXR_STORE_XMP_ATTRIBUTE ***
|
||||
* If defined, disables the stores XMP values in a non-standard attribute named "xmp".
|
||||
* The QImage metadata used is "XML:com.adobe.xmp".
|
||||
* NOTE: The use of non-standard attributes is possible but discouraged by the specification. However,
|
||||
* metadata is essential for good image management and programs like darktable also set this
|
||||
* attribute. Gimp reads the "xmp" attribute and Darktable writes it as well.
|
||||
*/
|
||||
//#define EXR_DISABLE_XMP_ATTRIBUTE // default: commented -> you should define it in your cmake file
|
||||
|
||||
/* *** EXR_MAX_IMAGE_WIDTH and EXR_MAX_IMAGE_HEIGHT ***
|
||||
* The maximum size in pixel allowed by the plugin.
|
||||
*/
|
||||
#ifndef EXR_MAX_IMAGE_WIDTH
|
||||
#define EXR_MAX_IMAGE_WIDTH 300000
|
||||
#endif
|
||||
#ifndef EXR_MAX_IMAGE_HEIGHT
|
||||
#define EXR_MAX_IMAGE_HEIGHT EXR_MAX_IMAGE_WIDTH
|
||||
#endif
|
||||
|
||||
/* *** EXR_LINES_PER_BLOCK ***
|
||||
* Allows certain compression schemes to work in multithreading
|
||||
* Requires up to "LINES_PER_BLOCK * MAX_IMAGE_WIDTH * 8"
|
||||
* additional RAM (e.g. if 128, up to 307MiB of RAM).
|
||||
* There is a performance gain with the following parameters (based on empirical tests):
|
||||
* - PIZ compression needs 64+ lines
|
||||
* - ZIPS compression needs 8+ lines
|
||||
* - ZIP compression needs 32+ lines
|
||||
* - Others not tested
|
||||
*
|
||||
* NOTE: The OpenEXR documentation states that the higher the better :)
|
||||
*/
|
||||
#ifndef EXR_LINES_PER_BLOCK
|
||||
#define EXR_LINES_PER_BLOCK 128
|
||||
#endif
|
||||
//#define EXR_ALLOW_LINEAR_COLORSPACE // default: commented -> you should define it in your cmake file
|
||||
|
||||
#include "exr_p.h"
|
||||
#include "scanlineconverter_p.h"
|
||||
#include "util_p.h"
|
||||
|
||||
#include <IexThrowErrnoExc.h>
|
||||
@@ -75,9 +39,10 @@
|
||||
#include <ImfInt64.h>
|
||||
#include <ImfIntAttribute.h>
|
||||
#include <ImfLineOrderAttribute.h>
|
||||
#include <ImfPreviewImage.h>
|
||||
#include <ImfRgbaFile.h>
|
||||
#include <ImfStandardAttributes.h>
|
||||
#include <ImfStringAttribute.h>
|
||||
#include <ImfVecAttribute.h>
|
||||
#include <ImfVersion.h>
|
||||
|
||||
#include <iostream>
|
||||
@@ -88,22 +53,16 @@
|
||||
#include <QFloat16>
|
||||
#include <QImage>
|
||||
#include <QImageIOPlugin>
|
||||
#include <QLocale>
|
||||
#include <QThread>
|
||||
|
||||
#include <QTimeZone>
|
||||
|
||||
// Allow the code to works on all QT versions supported by KDE
|
||||
// project (Qt 5.15 and Qt 6.x) to easy backports fixes.
|
||||
#if !defined(EXR_USE_LEGACY_CONVERSIONS)
|
||||
#if (QT_VERSION_MAJOR >= 6) && !defined(EXR_USE_LEGACY_CONVERSIONS)
|
||||
// If uncommented, the image is rendered in a float16 format, the result is very precise
|
||||
#define EXR_USE_QT6_FLOAT_IMAGE // default uncommented
|
||||
#endif
|
||||
|
||||
// Qt 6.8 allow to create and use Gray profile, so we can load a Gray image as Grayscale format instead RGB one.
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
||||
#define EXR_GRAY_SUPPORT_ENABLED
|
||||
#endif
|
||||
|
||||
class K_IStream : public Imf::IStream
|
||||
{
|
||||
public:
|
||||
@@ -163,57 +122,6 @@ void K_IStream::clear()
|
||||
// TODO
|
||||
}
|
||||
|
||||
class K_OStream : public Imf::OStream
|
||||
{
|
||||
public:
|
||||
K_OStream(QIODevice *dev, const QByteArray &fileName)
|
||||
: OStream(fileName.data())
|
||||
, m_dev(dev)
|
||||
{
|
||||
}
|
||||
|
||||
void write(const char c[/*n*/], int n) override;
|
||||
#if OPENEXR_VERSION_MAJOR > 2
|
||||
uint64_t tellp() override;
|
||||
void seekp(uint64_t pos) override;
|
||||
#else
|
||||
Imf::Int64 tellp() override;
|
||||
void seekp(Imf::Int64 pos) override;
|
||||
#endif
|
||||
|
||||
private:
|
||||
QIODevice *m_dev;
|
||||
};
|
||||
|
||||
void K_OStream::write(const char c[], int n)
|
||||
{
|
||||
qint64 result = m_dev->write(c, n);
|
||||
if (result > 0) {
|
||||
return;
|
||||
} else { // negative value {
|
||||
Iex::throwErrnoExc("Error in write", result);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
#if OPENEXR_VERSION_MAJOR > 2
|
||||
uint64_t K_OStream::tellp()
|
||||
#else
|
||||
Imf::Int64 K_OStream::tellg()
|
||||
#endif
|
||||
{
|
||||
return m_dev->pos();
|
||||
}
|
||||
|
||||
#if OPENEXR_VERSION_MAJOR > 2
|
||||
void K_OStream::seekp(uint64_t pos)
|
||||
#else
|
||||
void K_OStream::seekg(Imf::Int64 pos)
|
||||
#endif
|
||||
{
|
||||
m_dev->seek(pos);
|
||||
}
|
||||
|
||||
#ifdef EXR_USE_LEGACY_CONVERSIONS
|
||||
// source: https://openexr.com/en/latest/ReadingAndWritingImageFiles.html
|
||||
inline unsigned char gamma(float x)
|
||||
@@ -231,14 +139,7 @@ inline QRgb RgbaToQrgba(struct Imf::Rgba &imagePixel)
|
||||
#endif
|
||||
|
||||
EXRHandler::EXRHandler()
|
||||
: m_compressionRatio(-1)
|
||||
, m_quality(-1)
|
||||
, m_imageNumber(0)
|
||||
, m_imageCount(0)
|
||||
, m_startPos(-1)
|
||||
{
|
||||
// Set the number of threads to use (0 is allowed)
|
||||
Imf::setGlobalThreadCount(QThread::idealThreadCount() / 2);
|
||||
}
|
||||
|
||||
bool EXRHandler::canRead() const
|
||||
@@ -250,612 +151,113 @@ bool EXRHandler::canRead() const
|
||||
return false;
|
||||
}
|
||||
|
||||
static QImage::Format imageFormat(const Imf::RgbaInputFile &file)
|
||||
{
|
||||
auto isRgba = file.channels() & Imf::RgbaChannels::WRITE_A;
|
||||
#ifdef EXR_GRAY_SUPPORT_ENABLED
|
||||
auto isGray = file.channels() & Imf::RgbaChannels::WRITE_Y;
|
||||
#else
|
||||
auto isGray = false;
|
||||
#endif
|
||||
#if defined(EXR_USE_LEGACY_CONVERSIONS)
|
||||
return (isRgba ? QImage::Format_ARGB32 : QImage::Format_RGB32);
|
||||
#elif defined(EXR_USE_QT6_FLOAT_IMAGE)
|
||||
return (isRgba ? QImage::Format_RGBA16FPx4 : isGray ? QImage::Format_Grayscale16 : QImage::Format_RGBX16FPx4);
|
||||
#else
|
||||
return (isRgba ? QImage::Format_RGBA64 : QImage::Format_RGBX64);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief viewList
|
||||
* \param header
|
||||
* \return The list of available views.
|
||||
*/
|
||||
static QStringList viewList(const Imf::Header &h)
|
||||
{
|
||||
QStringList l;
|
||||
if (auto views = h.findTypedAttribute<Imf::StringVectorAttribute>("multiView")) {
|
||||
for (auto &&v : views->value()) {
|
||||
l << QString::fromStdString(v);
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
#ifdef QT_DEBUG
|
||||
void printAttributes(const Imf::Header &h)
|
||||
{
|
||||
for (auto i = h.begin(); i != h.end(); ++i) {
|
||||
qDebug() << i.name();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \brief readMetadata
|
||||
* Reads EXR attributes from the \a header and set its as metadata in the \a image.
|
||||
*/
|
||||
static void readMetadata(const Imf::Header &header, QImage &image)
|
||||
{
|
||||
// set some useful metadata
|
||||
if (auto comments = header.findTypedAttribute<Imf::StringAttribute>("comments")) {
|
||||
image.setText(QStringLiteral(META_KEY_COMMENT), QString::fromStdString(comments->value()));
|
||||
}
|
||||
|
||||
if (auto owner = header.findTypedAttribute<Imf::StringAttribute>("owner")) {
|
||||
image.setText(QStringLiteral(META_KEY_OWNER), QString::fromStdString(owner->value()));
|
||||
}
|
||||
|
||||
if (auto lat = header.findTypedAttribute<Imf::FloatAttribute>("latitude")) {
|
||||
image.setText(QStringLiteral(META_KEY_LATITUDE), QLocale::c().toString(lat->value()));
|
||||
}
|
||||
|
||||
if (auto lon = header.findTypedAttribute<Imf::FloatAttribute>("longitude")) {
|
||||
image.setText(QStringLiteral(META_KEY_LONGITUDE), QLocale::c().toString(lon->value()));
|
||||
}
|
||||
|
||||
if (auto alt = header.findTypedAttribute<Imf::FloatAttribute>("altitude")) {
|
||||
image.setText(QStringLiteral(META_KEY_ALTITUDE), QLocale::c().toString(alt->value()));
|
||||
}
|
||||
|
||||
if (auto capDate = header.findTypedAttribute<Imf::StringAttribute>("capDate")) {
|
||||
float off = 0;
|
||||
if (auto utcOffset = header.findTypedAttribute<Imf::FloatAttribute>("utcOffset")) {
|
||||
off = utcOffset->value();
|
||||
}
|
||||
auto dateTime = QDateTime::fromString(QString::fromStdString(capDate->value()), QStringLiteral("yyyy:MM:dd HH:mm:ss"));
|
||||
if (dateTime.isValid()) {
|
||||
dateTime.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(off));
|
||||
image.setText(QStringLiteral(META_KEY_CREATIONDATE), dateTime.toString(Qt::ISODate));
|
||||
}
|
||||
}
|
||||
|
||||
if (auto xDensity = header.findTypedAttribute<Imf::FloatAttribute>("xDensity")) {
|
||||
float par = 1;
|
||||
if (auto pixelAspectRatio = header.findTypedAttribute<Imf::FloatAttribute>("pixelAspectRatio")) {
|
||||
par = pixelAspectRatio->value();
|
||||
}
|
||||
image.setDotsPerMeterX(qRound(xDensity->value() * 100.0 / 2.54));
|
||||
image.setDotsPerMeterY(qRound(xDensity->value() * par * 100.0 / 2.54));
|
||||
}
|
||||
|
||||
// Non-standard attribute
|
||||
if (auto xmp = header.findTypedAttribute<Imf::StringAttribute>("xmp")) {
|
||||
image.setText(QStringLiteral(META_KEY_XMP_ADOBE), QString::fromStdString(xmp->value()));
|
||||
}
|
||||
|
||||
/* TODO: OpenEXR 3.2 metadata
|
||||
*
|
||||
* New Optional Standard Attributes:
|
||||
* - Support automated editorial workflow:
|
||||
* reelName, imageCounter, ascFramingDecisionList
|
||||
*
|
||||
* - Support forensics (“which other shots used that camera and lens before the camera firmware was updated?”):
|
||||
* cameraMake, cameraModel, cameraSerialNumber, cameraFirmware, cameraUuid, cameraLabel, lensMake, lensModel,
|
||||
* lensSerialNumber, lensFirmware, cameraColorBalance
|
||||
*
|
||||
* -Support pickup shots (reproduce critical camera settings):
|
||||
* shutterAngle, cameraCCTSetting, cameraTintSetting
|
||||
*
|
||||
* - Support metadata-driven match move:
|
||||
* sensorCenterOffset, sensorOverallDimensions, sensorPhotositePitch, sensorAcquisitionRectanglenominalFocalLength,
|
||||
* effectiveFocalLength, pinholeFocalLength, entrancePupilOffset, tStop(complementing existing 'aperture')
|
||||
*/
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief readColorSpace
|
||||
* Reads EXR chromaticities from the \a header and set its as color profile in the \a image.
|
||||
*/
|
||||
static void readColorSpace(const Imf::Header &header, QImage &image)
|
||||
{
|
||||
// final color operations
|
||||
#ifndef EXR_USE_LEGACY_CONVERSIONS
|
||||
|
||||
QColorSpace cs;
|
||||
if (auto chroma = header.findTypedAttribute<Imf::ChromaticitiesAttribute>("chromaticities")) {
|
||||
auto &&v = chroma->value();
|
||||
cs = QColorSpace(QPointF(v.white.x, v.white.y),
|
||||
QPointF(v.red.x, v.red.y),
|
||||
QPointF(v.green.x, v.green.y),
|
||||
QPointF(v.blue.x, v.blue.y),
|
||||
QColorSpace::TransferFunction::Linear);
|
||||
}
|
||||
if (!cs.isValid()) {
|
||||
#ifdef EXR_GRAY_SUPPORT_ENABLED
|
||||
if (image.format() == QImage::Format_Grayscale16 || image.format() == QImage::Format_Grayscale8) {
|
||||
cs = QColorSpace(QPointF(0.31271, 0.32902), QColorSpace::TransferFunction::Linear);
|
||||
cs.setDescription(QStringLiteral("Gray Linear build-in"));
|
||||
} else {
|
||||
cs = QColorSpace(QColorSpace::SRgbLinear);
|
||||
}
|
||||
#else
|
||||
cs = QColorSpace(QColorSpace::SRgbLinear);
|
||||
#endif
|
||||
}
|
||||
image.setColorSpace(cs);
|
||||
|
||||
#ifdef EXR_CONVERT_TO_SRGB
|
||||
image.convertToColorSpace(QColorSpace(QColorSpace::SRgb));
|
||||
#endif
|
||||
|
||||
#endif // !EXR_USE_LEGACY_CONVERSIONS
|
||||
}
|
||||
|
||||
bool EXRHandler::read(QImage *outImage)
|
||||
{
|
||||
try {
|
||||
auto d = device();
|
||||
int width;
|
||||
int height;
|
||||
|
||||
// set the image position after the first run.
|
||||
if (!d->isSequential()) {
|
||||
if (m_startPos < 0) {
|
||||
m_startPos = d->pos();
|
||||
} else {
|
||||
d->seek(m_startPos);
|
||||
}
|
||||
}
|
||||
|
||||
K_IStream istr(d, QByteArray());
|
||||
K_IStream istr(device(), QByteArray());
|
||||
Imf::RgbaInputFile file(istr);
|
||||
auto &&header = file.header();
|
||||
|
||||
// set the image to load
|
||||
if (m_imageNumber > -1) {
|
||||
auto views = viewList(header);
|
||||
if (m_imageNumber < views.count()) {
|
||||
file.setLayerName(views.at(m_imageNumber).toStdString());
|
||||
}
|
||||
}
|
||||
|
||||
// get image info
|
||||
Imath::Box2i dw = file.dataWindow();
|
||||
qint32 width = dw.max.x - dw.min.x + 1;
|
||||
qint32 height = dw.max.y - dw.min.y + 1;
|
||||
bool isRgba = file.channels() & Imf::RgbaChannels::WRITE_A;
|
||||
|
||||
// limiting the maximum image size on a reasonable size (as done in other plugins)
|
||||
if (width > EXR_MAX_IMAGE_WIDTH || height > EXR_MAX_IMAGE_HEIGHT) {
|
||||
qWarning() << "The maximum image size is limited to" << EXR_MAX_IMAGE_WIDTH << "x" << EXR_MAX_IMAGE_HEIGHT << "px";
|
||||
return false;
|
||||
}
|
||||
width = dw.max.x - dw.min.x + 1;
|
||||
height = dw.max.y - dw.min.y + 1;
|
||||
|
||||
// creating the image
|
||||
QImage image = imageAlloc(width, height, imageFormat(file));
|
||||
#if defined(EXR_USE_LEGACY_CONVERSIONS)
|
||||
QImage image = imageAlloc(width, height, isRgba ? QImage::Format_ARGB32 : QImage::Format_RGB32);
|
||||
#elif defined(EXR_USE_QT6_FLOAT_IMAGE)
|
||||
QImage image = imageAlloc(width, height, isRgba ? QImage::Format_RGBA16FPx4 : QImage::Format_RGBX16FPx4);
|
||||
#else
|
||||
QImage image = imageAlloc(width, height, isRgba ? QImage::Format_RGBA64 : QImage::Format_RGBX64);
|
||||
#endif
|
||||
if (image.isNull()) {
|
||||
qWarning() << "Failed to allocate image, invalid size?" << QSize(width, height);
|
||||
return false;
|
||||
}
|
||||
|
||||
Imf::Array2D<Imf::Rgba> pixels;
|
||||
pixels.resizeErase(EXR_LINES_PER_BLOCK, width);
|
||||
bool isRgba = image.hasAlphaChannel();
|
||||
// set some useful metadata
|
||||
auto &&h = file.header();
|
||||
if (auto comments = h.findTypedAttribute<Imf::StringAttribute>("comments")) {
|
||||
image.setText(QStringLiteral("Comment"), QString::fromStdString(comments->value()));
|
||||
}
|
||||
if (auto owner = h.findTypedAttribute<Imf::StringAttribute>("owner")) {
|
||||
image.setText(QStringLiteral("Owner"), QString::fromStdString(owner->value()));
|
||||
}
|
||||
if (auto capDate = h.findTypedAttribute<Imf::StringAttribute>("capDate")) {
|
||||
float off = 0;
|
||||
if (auto utcOffset = h.findTypedAttribute<Imf::FloatAttribute>("utcOffset")) {
|
||||
off = utcOffset->value();
|
||||
}
|
||||
auto dateTime = QDateTime::fromString(QString::fromStdString(capDate->value()), QStringLiteral("yyyy:MM:dd HH:mm:ss"));
|
||||
if (dateTime.isValid()) {
|
||||
dateTime.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(off));
|
||||
image.setText(QStringLiteral("Date"), dateTime.toString(Qt::ISODate));
|
||||
}
|
||||
}
|
||||
if (auto xDensity = h.findTypedAttribute<Imf::FloatAttribute>("xDensity")) {
|
||||
float par = 1;
|
||||
if (auto pixelAspectRatio = h.findTypedAttribute<Imf::FloatAttribute>("pixelAspectRatio")) {
|
||||
par = pixelAspectRatio->value();
|
||||
}
|
||||
image.setDotsPerMeterX(qRound(xDensity->value() * 100.0 / 2.54));
|
||||
image.setDotsPerMeterY(qRound(xDensity->value() * par * 100.0 / 2.54));
|
||||
}
|
||||
|
||||
Imf::Array<Imf::Rgba> pixels;
|
||||
pixels.resizeErase(width);
|
||||
|
||||
// somehow copy pixels into image
|
||||
for (int y = 0, n = 0; y < height; y += n) {
|
||||
for (int y = 0; y < height; ++y) {
|
||||
auto my = dw.min.y + y;
|
||||
if (my > dw.max.y) { // paranoia check
|
||||
break;
|
||||
}
|
||||
if (my <= dw.max.y) { // paranoia check
|
||||
file.setFrameBuffer(&pixels[0] - dw.min.x - qint64(my) * width, 1, width);
|
||||
file.readPixels(my, my);
|
||||
|
||||
file.setFrameBuffer(&pixels[0][0] - dw.min.x - qint64(my) * width, 1, width);
|
||||
file.readPixels(my, std::min(my + EXR_LINES_PER_BLOCK - 1, dw.max.y));
|
||||
|
||||
for (n = 0; n < std::min(EXR_LINES_PER_BLOCK, height - y); ++n) {
|
||||
if (image.format() == QImage::Format_Grayscale16) { // grayscale image
|
||||
auto scanLine = reinterpret_cast<quint16 *>(image.scanLine(y + n));
|
||||
for (int x = 0; x < width; ++x) {
|
||||
*(scanLine + x) = quint16(qBound(0.f, float(pixels[n][x].r) * 65535.f + 0.5f, 65535.f));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
#if defined(EXR_USE_LEGACY_CONVERSIONS)
|
||||
Q_UNUSED(isRgba)
|
||||
auto scanLine = reinterpret_cast<QRgb *>(image.scanLine(y + n));
|
||||
auto scanLine = reinterpret_cast<QRgb *>(image.scanLine(y));
|
||||
for (int x = 0; x < width; ++x) {
|
||||
*(scanLine + x) = RgbaToQrgba(pixels[n][x]);
|
||||
*(scanLine + x) = RgbaToQrgba(pixels[x]);
|
||||
}
|
||||
#elif defined(EXR_USE_QT6_FLOAT_IMAGE)
|
||||
auto scanLine = reinterpret_cast<qfloat16 *>(image.scanLine(y + n));
|
||||
auto scanLine = reinterpret_cast<qfloat16 *>(image.scanLine(y));
|
||||
for (int x = 0; x < width; ++x) {
|
||||
auto xcs = x * 4;
|
||||
*(scanLine + xcs) = qfloat16(qBound(0.f, float(pixels[n][x].r), 1.f));
|
||||
*(scanLine + xcs + 1) = qfloat16(qBound(0.f, float(pixels[n][x].g), 1.f));
|
||||
*(scanLine + xcs + 2) = qfloat16(qBound(0.f, float(pixels[n][x].b), 1.f));
|
||||
*(scanLine + xcs + 3) = qfloat16(isRgba ? qBound(0.f, float(pixels[n][x].a), 1.f) : 1.f);
|
||||
*(scanLine + xcs) = qfloat16(qBound(0.f, float(pixels[x].r), 1.f));
|
||||
*(scanLine + xcs + 1) = qfloat16(qBound(0.f, float(pixels[x].g), 1.f));
|
||||
*(scanLine + xcs + 2) = qfloat16(qBound(0.f, float(pixels[x].b), 1.f));
|
||||
*(scanLine + xcs + 3) = qfloat16(isRgba ? qBound(0.f, float(pixels[x].a), 1.f) : 1.f);
|
||||
}
|
||||
#else
|
||||
auto scanLine = reinterpret_cast<QRgba64 *>(image.scanLine(y + n));
|
||||
auto scanLine = reinterpret_cast<QRgba64 *>(image.scanLine(y));
|
||||
for (int x = 0; x < width; ++x) {
|
||||
*(scanLine + x) = QRgba64::fromRgba64(quint16(qBound(0.f, float(pixels[n][x].r) * 65535.f + 0.5f, 65535.f)),
|
||||
quint16(qBound(0.f, float(pixels[n][x].g) * 65535.f + 0.5f, 65535.f)),
|
||||
quint16(qBound(0.f, float(pixels[n][x].b) * 65535.f + 0.5f, 65535.f)),
|
||||
isRgba ? quint16(qBound(0.f, float(pixels[n][x].a) * 65535.f + 0.5f, 65535.f)) : quint16(65535));
|
||||
*(scanLine + x) = QRgba64::fromRgba64(quint16(qBound(0.f, float(pixels[x].r) * 65535.f + 0.5f, 65535.f)),
|
||||
quint16(qBound(0.f, float(pixels[x].g) * 65535.f + 0.5f, 65535.f)),
|
||||
quint16(qBound(0.f, float(pixels[x].b) * 65535.f + 0.5f, 65535.f)),
|
||||
isRgba ? quint16(qBound(0.f, float(pixels[x].a) * 65535.f + 0.5f, 65535.f)) : quint16(65535));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// set some useful metadata
|
||||
readMetadata(header, image);
|
||||
// final color operations
|
||||
readColorSpace(header, image);
|
||||
#ifndef EXR_USE_LEGACY_CONVERSIONS
|
||||
image.setColorSpace(QColorSpace(QColorSpace::SRgbLinear));
|
||||
#ifndef EXR_ALLOW_LINEAR_COLORSPACE
|
||||
image.convertToColorSpace(QColorSpace(QColorSpace::SRgb));
|
||||
#endif // !EXR_ALLOW_LINEAR_COLORSPACE
|
||||
#endif // !EXR_USE_LEGACY_CONVERSIONS
|
||||
|
||||
*outImage = image;
|
||||
*outImage = std::move(image);
|
||||
|
||||
return true;
|
||||
} catch (const std::exception &) {
|
||||
} catch (const std::exception &exc) {
|
||||
// qDebug() << exc.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief makePreview
|
||||
* Creates a preview of maximum 256 x 256 pixels from the \a image.
|
||||
*/
|
||||
bool makePreview(const QImage &image, Imf::Array2D<Imf::PreviewRgba> &pixels)
|
||||
{
|
||||
auto w = image.width();
|
||||
auto h = image.height();
|
||||
|
||||
QImage preview;
|
||||
if (w > h) {
|
||||
preview = image.scaledToWidth(256).convertToFormat(QImage::Format_ARGB32);
|
||||
} else {
|
||||
preview = image.scaledToHeight(256).convertToFormat(QImage::Format_ARGB32);
|
||||
}
|
||||
if (preview.isNull()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
w = preview.width();
|
||||
h = preview.height();
|
||||
pixels.resizeErase(h, w);
|
||||
preview.convertToColorSpace(QColorSpace(QColorSpace::SRgb));
|
||||
|
||||
for (int y = 0; y < h; ++y) {
|
||||
auto scanLine = reinterpret_cast<const QRgb *>(preview.constScanLine(y));
|
||||
for (int x = 0; x < w; ++x) {
|
||||
auto &&out = pixels[y][x];
|
||||
out.r = qRed(*(scanLine + x));
|
||||
out.g = qGreen(*(scanLine + x));
|
||||
out.b = qBlue(*(scanLine + x));
|
||||
out.a = qAlpha(*(scanLine + x));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief setMetadata
|
||||
* Reades the metadata from \a image and set its as attributes in the \a header.
|
||||
*/
|
||||
static void setMetadata(const QImage &image, Imf::Header &header)
|
||||
{
|
||||
auto dateTime = QDateTime::currentDateTime();
|
||||
for (auto &&key : image.textKeys()) {
|
||||
auto text = image.text(key);
|
||||
if (!key.compare(QStringLiteral(META_KEY_COMMENT), Qt::CaseInsensitive)) {
|
||||
header.insert("comments", Imf::StringAttribute(text.toStdString()));
|
||||
}
|
||||
|
||||
if (!key.compare(QStringLiteral(META_KEY_OWNER), Qt::CaseInsensitive)) {
|
||||
header.insert("owner", Imf::StringAttribute(text.toStdString()));
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
if (!key.compare(QStringLiteral(META_KEY_LATITUDE), Qt::CaseInsensitive) ||
|
||||
!key.compare(QStringLiteral(META_KEY_LONGITUDE), Qt::CaseInsensitive) ||
|
||||
!key.compare(QStringLiteral(META_KEY_ALTITUDE), Qt::CaseInsensitive)) {
|
||||
// clang-format on
|
||||
auto ok = false;
|
||||
auto value = QLocale::c().toFloat(text, &ok);
|
||||
if (ok) {
|
||||
header.insert(qPrintable(key.toLower()), Imf::FloatAttribute(value));
|
||||
}
|
||||
}
|
||||
|
||||
if (!key.compare(QStringLiteral(META_KEY_CREATIONDATE), Qt::CaseInsensitive)) {
|
||||
auto dt = QDateTime::fromString(text, Qt::ISODate);
|
||||
if (dt.isValid()) {
|
||||
dateTime = dt;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef EXR_DISABLE_XMP_ATTRIBUTE // warning: Non-standard attribute!
|
||||
if (!key.compare(QStringLiteral(META_KEY_XMP_ADOBE), Qt::CaseInsensitive)) {
|
||||
header.insert("xmp", Imf::StringAttribute(text.toStdString()));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (dateTime.isValid()) {
|
||||
header.insert("capDate", Imf::StringAttribute(dateTime.toString(QStringLiteral("yyyy:MM:dd HH:mm:ss")).toStdString()));
|
||||
header.insert("utcOffset", Imf::FloatAttribute(dateTime.offsetFromUtc()));
|
||||
}
|
||||
|
||||
if (image.dotsPerMeterX() && image.dotsPerMeterY()) {
|
||||
header.insert("xDensity", Imf::FloatAttribute(image.dotsPerMeterX() * 2.54f / 100.f));
|
||||
header.insert("pixelAspectRatio", Imf::FloatAttribute(float(image.dotsPerMeterX()) / float(image.dotsPerMeterY())));
|
||||
}
|
||||
|
||||
// set default chroma (default constructor ITU-R BT.709-3 -> sRGB)
|
||||
// The image is converted to Linear sRGB so, the chroma is the default EXR value.
|
||||
// If a file doesn’t have a chromaticities attribute, display software should assume that the
|
||||
// file’s primaries and the white point match Rec. ITU-R BT.709-3.
|
||||
// header.insert("chromaticities", Imf::ChromaticitiesAttribute(Imf::Chromaticities()));
|
||||
|
||||
// TODO: EXR 3.2 attributes (see readMetadata())
|
||||
}
|
||||
|
||||
bool EXRHandler::write(const QImage &image)
|
||||
{
|
||||
try {
|
||||
// create EXR header
|
||||
qint32 width = image.width();
|
||||
qint32 height = image.height();
|
||||
|
||||
// limiting the maximum image size on a reasonable size (as done in other plugins)
|
||||
if (width > EXR_MAX_IMAGE_WIDTH || height > EXR_MAX_IMAGE_HEIGHT) {
|
||||
qWarning() << "The maximum image size is limited to" << EXR_MAX_IMAGE_WIDTH << "x" << EXR_MAX_IMAGE_HEIGHT << "px";
|
||||
return false;
|
||||
}
|
||||
|
||||
Imf::Header header(width, height);
|
||||
// set compression scheme (forcing PIZ as default)
|
||||
header.compression() = Imf::Compression::PIZ_COMPRESSION;
|
||||
if (m_compressionRatio >= qint32(Imf::Compression::NO_COMPRESSION) && m_compressionRatio < qint32(Imf::Compression::NUM_COMPRESSION_METHODS)) {
|
||||
header.compression() = Imf::Compression(m_compressionRatio);
|
||||
}
|
||||
// set the DCT quality (used by DCT compressions only)
|
||||
if (m_quality > -1 && m_quality <= 100) {
|
||||
header.dwaCompressionLevel() = float(m_quality);
|
||||
}
|
||||
// make ZIP compression fast (used by ZIP compressions)
|
||||
header.zipCompressionLevel() = 1;
|
||||
|
||||
// set preview (don't set it for small images)
|
||||
if (width > 1024 || height > 1024) {
|
||||
Imf::Array2D<Imf::PreviewRgba> previewPixels;
|
||||
if (makePreview(image, previewPixels)) {
|
||||
header.setPreviewImage(Imf::PreviewImage(previewPixels.width(), previewPixels.height(), &previewPixels[0][0]));
|
||||
}
|
||||
}
|
||||
|
||||
// set metadata (EXR attributes)
|
||||
setMetadata(image, header);
|
||||
|
||||
// write the EXR
|
||||
K_OStream ostr(device(), QByteArray());
|
||||
auto channelsType = image.hasAlphaChannel() ? Imf::RgbaChannels::WRITE_RGBA : Imf::RgbaChannels::WRITE_RGB;
|
||||
if (image.format() == QImage::Format_Mono ||
|
||||
image.format() == QImage::Format_MonoLSB ||
|
||||
image.format() == QImage::Format_Grayscale16 ||
|
||||
image.format() == QImage::Format_Grayscale8) {
|
||||
channelsType = Imf::RgbaChannels::WRITE_Y;
|
||||
}
|
||||
Imf::RgbaOutputFile file(ostr, header, channelsType);
|
||||
Imf::Array2D<Imf::Rgba> pixels;
|
||||
pixels.resizeErase(EXR_LINES_PER_BLOCK, width);
|
||||
|
||||
// convert the image and write into the stream
|
||||
#if defined(EXR_USE_QT6_FLOAT_IMAGE)
|
||||
auto convFormat = image.hasAlphaChannel() ? QImage::Format_RGBA16FPx4 : QImage::Format_RGBX16FPx4;
|
||||
#else
|
||||
auto convFormat = image.hasAlphaChannel() ? QImage::Format_RGBA64 : QImage::Format_RGBX64;
|
||||
#endif
|
||||
ScanLineConverter slc(convFormat);
|
||||
#ifdef EXR_GRAY_SUPPORT_ENABLED
|
||||
if (channelsType == Imf::RgbaChannels::WRITE_Y) {
|
||||
slc.setDefaultSourceColorSpace(QColorSpace(QColorSpace(QColorSpace::SRgb).whitePoint(), QColorSpace::TransferFunction::SRgb)); // Creates a custom grayscale color space
|
||||
} else {
|
||||
slc.setDefaultSourceColorSpace(QColorSpace(QColorSpace::SRgb));
|
||||
}
|
||||
#else
|
||||
slc.setDefaultSourceColorSpace(QColorSpace(QColorSpace::SRgb));
|
||||
#endif
|
||||
|
||||
slc.setTargetColorSpace(QColorSpace(QColorSpace::SRgbLinear));
|
||||
for (int y = 0, n = 0; y < height; y += n) {
|
||||
for (n = 0; n < std::min(EXR_LINES_PER_BLOCK, height - y); ++n) {
|
||||
#if defined(EXR_USE_QT6_FLOAT_IMAGE)
|
||||
auto scanLine = reinterpret_cast<const qfloat16 *>(slc.convertedScanLine(image, y + n));
|
||||
if (scanLine == nullptr) {
|
||||
return false;
|
||||
}
|
||||
for (int x = 0; x < width; ++x) {
|
||||
auto xcs = x * 4;
|
||||
pixels[n][x].r = float(*(scanLine + xcs));
|
||||
pixels[n][x].g = float(*(scanLine + xcs + 1));
|
||||
pixels[n][x].b = float(*(scanLine + xcs + 2));
|
||||
pixels[n][x].a = float(*(scanLine + xcs + 3));
|
||||
}
|
||||
#else
|
||||
auto scanLine = reinterpret_cast<const QRgba64 *>(slc.convertedScanLine(image, y + n));
|
||||
if (scanLine == nullptr) {
|
||||
return false;
|
||||
}
|
||||
for (int x = 0; x < width; ++x) {
|
||||
pixels[n][x].r = float((scanLine + x)->red() / 65535.f);
|
||||
pixels[n][x].g = float((scanLine + x)->green() / 65535.f);
|
||||
pixels[n][x].b = float((scanLine + x)->blue() / 65535.f);
|
||||
pixels[n][x].a = float((scanLine + x)->alpha() / 65535.f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
file.setFrameBuffer(&pixels[0][0] - qint64(y) * width, 1, width);
|
||||
file.writePixels(n);
|
||||
}
|
||||
} catch (const std::exception &) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void EXRHandler::setOption(ImageOption option, const QVariant &value)
|
||||
{
|
||||
if (option == QImageIOHandler::CompressionRatio) {
|
||||
auto ok = false;
|
||||
auto cr = value.toInt(&ok);
|
||||
if (ok) {
|
||||
m_compressionRatio = cr;
|
||||
}
|
||||
}
|
||||
if (option == QImageIOHandler::Quality) {
|
||||
auto ok = false;
|
||||
auto q = value.toInt(&ok);
|
||||
if (ok) {
|
||||
m_quality = q;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool EXRHandler::supportsOption(ImageOption option) const
|
||||
{
|
||||
if (option == QImageIOHandler::Size) {
|
||||
if (auto d = device())
|
||||
return !d->isSequential();
|
||||
}
|
||||
if (option == QImageIOHandler::ImageFormat) {
|
||||
if (auto d = device())
|
||||
return !d->isSequential();
|
||||
}
|
||||
if (option == QImageIOHandler::CompressionRatio) {
|
||||
return true;
|
||||
}
|
||||
if (option == QImageIOHandler::Quality) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant EXRHandler::option(ImageOption option) const
|
||||
{
|
||||
QVariant v;
|
||||
|
||||
if (option == QImageIOHandler::Size) {
|
||||
if (auto d = device()) {
|
||||
// transactions works on both random and sequential devices
|
||||
d->startTransaction();
|
||||
if (m_startPos > -1) {
|
||||
d->seek(m_startPos);
|
||||
}
|
||||
try {
|
||||
K_IStream istr(d, QByteArray());
|
||||
Imf::RgbaInputFile file(istr);
|
||||
if (m_imageNumber > -1) { // set the image to read
|
||||
auto views = viewList(file.header());
|
||||
if (m_imageNumber < views.count()) {
|
||||
file.setLayerName(views.at(m_imageNumber).toStdString());
|
||||
}
|
||||
}
|
||||
Imath::Box2i dw = file.dataWindow();
|
||||
v = QVariant(QSize(dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1));
|
||||
} catch (const std::exception &) {
|
||||
// broken file or unsupported version
|
||||
}
|
||||
d->rollbackTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
if (option == QImageIOHandler::ImageFormat) {
|
||||
if (auto d = device()) {
|
||||
// transactions works on both random and sequential devices
|
||||
d->startTransaction();
|
||||
if (m_startPos > -1) {
|
||||
d->seek(m_startPos);
|
||||
}
|
||||
try {
|
||||
K_IStream istr(d, QByteArray());
|
||||
Imf::RgbaInputFile file(istr);
|
||||
v = QVariant::fromValue(imageFormat(file));
|
||||
} catch (const std::exception &) {
|
||||
// broken file or unsupported version
|
||||
}
|
||||
d->rollbackTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
if (option == QImageIOHandler::CompressionRatio) {
|
||||
v = QVariant(m_compressionRatio);
|
||||
}
|
||||
|
||||
if (option == QImageIOHandler::Quality) {
|
||||
v = QVariant(m_quality);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
bool EXRHandler::jumpToNextImage()
|
||||
{
|
||||
return jumpToImage(m_imageNumber + 1);
|
||||
}
|
||||
|
||||
bool EXRHandler::jumpToImage(int imageNumber)
|
||||
{
|
||||
if (imageNumber < 0 || imageNumber >= imageCount()) {
|
||||
return false;
|
||||
}
|
||||
m_imageNumber = imageNumber;
|
||||
return true;
|
||||
}
|
||||
|
||||
int EXRHandler::imageCount() const
|
||||
{
|
||||
// NOTE: image count is cached for performance reason
|
||||
auto &&count = m_imageCount;
|
||||
if (count > 0) {
|
||||
return count;
|
||||
}
|
||||
|
||||
count = QImageIOHandler::imageCount();
|
||||
|
||||
auto d = device();
|
||||
d->startTransaction();
|
||||
|
||||
try {
|
||||
K_IStream istr(d, QByteArray());
|
||||
Imf::RgbaInputFile file(istr);
|
||||
auto views = viewList(file.header());
|
||||
if (!views.isEmpty()) {
|
||||
count = views.size();
|
||||
}
|
||||
} catch (const std::exception &) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
d->rollbackTransaction();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int EXRHandler::currentImageNumber() const
|
||||
{
|
||||
return m_imageNumber;
|
||||
}
|
||||
|
||||
bool EXRHandler::canRead(QIODevice *device)
|
||||
{
|
||||
if (!device) {
|
||||
@@ -871,7 +273,7 @@ bool EXRHandler::canRead(QIODevice *device)
|
||||
QImageIOPlugin::Capabilities EXRPlugin::capabilities(QIODevice *device, const QByteArray &format) const
|
||||
{
|
||||
if (format == "exr") {
|
||||
return Capabilities(CanRead | CanWrite);
|
||||
return Capabilities(CanRead);
|
||||
}
|
||||
if (!format.isEmpty()) {
|
||||
return {};
|
||||
@@ -884,9 +286,6 @@ QImageIOPlugin::Capabilities EXRPlugin::capabilities(QIODevice *device, const QB
|
||||
if (device->isReadable() && EXRHandler::canRead(device)) {
|
||||
cap |= CanRead;
|
||||
}
|
||||
if (device->isWritable()) {
|
||||
cap |= CanWrite;
|
||||
}
|
||||
return cap;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
The high dynamic range EXR format support for QImage.
|
||||
QImageIO Routines to read (and perhaps in the future, write) images
|
||||
in the high definition EXR format.
|
||||
|
||||
SPDX-FileCopyrightText: 2003 Brad Hards <bradh@frogmouth.net>
|
||||
SPDX-FileCopyrightText: 2023 Mirco Miranda <mircomir@outlook.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
@@ -12,44 +12,6 @@
|
||||
|
||||
#include <QImageIOPlugin>
|
||||
|
||||
/*!
|
||||
* \brief The EXRHandler class
|
||||
* The handler uses the OpenEXR reference implementation of the EXR file format.
|
||||
*
|
||||
* The purpose of EXR format is to accurately and efficiently represent high-dynamic-range scene-linear
|
||||
* image data and associated metadata.
|
||||
*
|
||||
* Both reading and writing of EXR files is supported. When saving, the image is converted to 16-bit
|
||||
* and sRGB Linear color space (if not already so). If no color space is set in the image, sRGB is assumed.
|
||||
* When the handler is compiled with the default compile options, the loaded image is a 16-bit image
|
||||
* with linear color space.
|
||||
* Multiview images are also supported (read only) via imageCount(), jumpToImage(), etc....
|
||||
*
|
||||
* The following QImageIOHandler options are supported:
|
||||
* - ImageFormat: The image's data format returned by the handler.
|
||||
* - Size: The size of the image.
|
||||
* - CompressionRatio: The compression ratio of the image data (see OpenEXR compression schemes).
|
||||
* - Quality: The quality level of the image (see OpenEXR compression level of lossy codecs).
|
||||
*
|
||||
* The following metadata are set/get via QImage::setText()/QImage::text() in both read/write (if any):
|
||||
* - Latitude, Longitude, Altitude: Geographic coordinates (Float converted to string).
|
||||
* - CreationDate: Date the image was captured/created (QDateTime converted to string using Qt::ISODate).
|
||||
* - Comment: Additional image information in human-readable form, for example a verbal description of the image (QString).
|
||||
* - Owner: Name of the owner of the image (QString).
|
||||
*
|
||||
* In addition, information about image resolution is preserved and the preview is written for images larger
|
||||
* than 1024px.
|
||||
*
|
||||
* The following compile options are supported (defines):
|
||||
* - EXR_MAX_IMAGE_WIDTH: Maximum image width supported (read/write, default: 300000 px).
|
||||
* - EXR_MAX_IMAGE_HEIGHT: Maximum image height supported (read/write, default: 300000 px).
|
||||
* - EXR_LINES_PER_BLOCK: The number of scanlines buffered on both read and write operations.\n
|
||||
* The higher the value, the greater the parallelization but the RAM consumption increases (default: 128)
|
||||
* - EXR_USE_LEGACY_CONVERSIONS: The result image is an 8-bit RGB(A) converted without icc profiles (read, default: undefined).
|
||||
* - EXR_CONVERT_TO_SRGB: The resulting image is convertef in the sRGB color space (read, default: undefined).
|
||||
* - EXR_DISABLE_XMP_ATTRIBUTE: Disable the stores of XMP values in a non-standard attribute named "xmp".\n
|
||||
* The QImage metadata used is "XML:com.adobe.xmp" (write, default: undefined).
|
||||
*/
|
||||
class EXRHandler : public QImageIOHandler
|
||||
{
|
||||
public:
|
||||
@@ -57,65 +19,8 @@ public:
|
||||
|
||||
bool canRead() const override;
|
||||
bool read(QImage *outImage) override;
|
||||
bool write(const QImage &image) override;
|
||||
|
||||
void setOption(ImageOption option, const QVariant &value) override;
|
||||
bool supportsOption(QImageIOHandler::ImageOption option) const override;
|
||||
QVariant option(QImageIOHandler::ImageOption option) const override;
|
||||
|
||||
bool jumpToNextImage() override;
|
||||
bool jumpToImage(int imageNumber) override;
|
||||
int imageCount() const override;
|
||||
int currentImageNumber() const override;
|
||||
|
||||
static bool canRead(QIODevice *device);
|
||||
|
||||
private:
|
||||
/*!
|
||||
* \brief m_compressionRatio
|
||||
* Value set by QImageWriter::setCompression().
|
||||
*
|
||||
* The compression scheme is the same as defined by OpenEXR library:
|
||||
* - 0: no compression
|
||||
* - 1: run length encoding
|
||||
* - 2: zlib compression, one scan line at a time
|
||||
* - 3: zlib compression, in blocks of 16 scan lines
|
||||
* - 4: piz-based wavelet compression (default)
|
||||
* - 5: lossy 24-bit float compression
|
||||
* - 6: lossy 4-by-4 pixel block compression, fixed compression rate
|
||||
* - 7: lossy 4-by-4 pixel block compression, fields are compressed more
|
||||
* - 8: lossy DCT based compression, in blocks of 32 scanlines. More efficient for partial buffer access.
|
||||
* - 9: lossy DCT based compression, in blocks of 256 scanlines. More efficient space wise and faster to decode full frames than DWAA_COMPRESSION.
|
||||
*/
|
||||
qint32 m_compressionRatio;
|
||||
|
||||
/*!
|
||||
* \brief m_quality
|
||||
* Value set by QImageWriter::setQuality().
|
||||
*
|
||||
* The quality is used on DCT compression schemes only with a
|
||||
* supposed value between 0 and 100 (default: 45).
|
||||
*/
|
||||
qint32 m_quality;
|
||||
|
||||
/*!
|
||||
* \brief m_imageNumber
|
||||
* Value set by QImageReader::jumpToImage() or QImageReader::jumpToNextImage().
|
||||
* The number of view selected in a multiview image.
|
||||
*/
|
||||
qint32 m_imageNumber;
|
||||
|
||||
/*!
|
||||
* \brief m_imageCount
|
||||
* The total number of views (cache value)
|
||||
*/
|
||||
mutable qint32 m_imageCount;
|
||||
|
||||
/*!
|
||||
* \brief m_startPos
|
||||
* The initial device position to allow multi image load (cache value).
|
||||
*/
|
||||
qint64 m_startPos;
|
||||
};
|
||||
|
||||
class EXRPlugin : public QImageIOPlugin
|
||||
|
||||
@@ -269,13 +269,13 @@ bool HDRHandler::read(QImage *outImage)
|
||||
{
|
||||
QDataStream s(device());
|
||||
|
||||
m_imageSize = readHeaderSize(s.device());
|
||||
if (!m_imageSize.isValid()) {
|
||||
QSize size = readHeaderSize(s.device());
|
||||
if (!size.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QImage img;
|
||||
if (!LoadHDR(s, m_imageSize.width(), m_imageSize.height(), img)) {
|
||||
if (!LoadHDR(s, size.width(), size.height(), img)) {
|
||||
// qDebug() << "Error loading HDR file.";
|
||||
return false;
|
||||
}
|
||||
@@ -283,7 +283,7 @@ bool HDRHandler::read(QImage *outImage)
|
||||
// By setting the linear color space, programs that support profiles display HDR files as in GIMP and Photoshop.
|
||||
img.setColorSpace(QColorSpace(QColorSpace::SRgbLinear));
|
||||
|
||||
*outImage = img;
|
||||
*outImage = std::move(img);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -303,9 +303,7 @@ QVariant HDRHandler::option(ImageOption option) const
|
||||
QVariant v;
|
||||
|
||||
if (option == QImageIOHandler::Size) {
|
||||
if (!m_imageSize.isEmpty()) {
|
||||
v = QVariant::fromValue(m_imageSize);
|
||||
} else if (auto d = device()) {
|
||||
if (auto d = device()) {
|
||||
// transactions works on both random and sequential devices
|
||||
d->startTransaction();
|
||||
auto size = readHeaderSize(d);
|
||||
|
||||
@@ -22,13 +22,6 @@ public:
|
||||
QVariant option(QImageIOHandler::ImageOption option) const override;
|
||||
|
||||
static bool canRead(QIODevice *device);
|
||||
|
||||
private:
|
||||
/*!
|
||||
* \brief m_imageSize
|
||||
* Image size cache used by option()
|
||||
*/
|
||||
QSize m_imageSize;
|
||||
};
|
||||
|
||||
class HDRPlugin : public QImageIOPlugin
|
||||
|
||||
@@ -22,7 +22,6 @@ size_t HEIFHandler::m_initialized_count = 0;
|
||||
bool HEIFHandler::m_plugins_queried = false;
|
||||
bool HEIFHandler::m_heif_decoder_available = false;
|
||||
bool HEIFHandler::m_heif_encoder_available = false;
|
||||
bool HEIFHandler::m_hej2_decoder_available = false;
|
||||
|
||||
extern "C" {
|
||||
static struct heif_error heifhandler_write_callback(struct heif_context * /* ctx */, const void *data, size_t size, void *userdata)
|
||||
@@ -60,25 +59,12 @@ HEIFHandler::HEIFHandler()
|
||||
|
||||
bool HEIFHandler::canRead() const
|
||||
{
|
||||
if (m_parseState == ParseHeicNotParsed) {
|
||||
QIODevice *dev = device();
|
||||
if (dev) {
|
||||
const QByteArray header = dev->peek(28);
|
||||
|
||||
if (HEIFHandler::isSupportedBMFFType(header)) {
|
||||
setFormat("heif");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (HEIFHandler::isSupportedHEJ2(header)) {
|
||||
setFormat("hej2");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (m_parseState == ParseHeicNotParsed && !canRead(device())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_parseState != ParseHeicError) {
|
||||
setFormat("heif");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -314,6 +300,17 @@ bool HEIFHandler::write_helper(const QImage &image)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HEIFHandler::canRead(QIODevice *device)
|
||||
{
|
||||
if (!device) {
|
||||
qWarning("HEIFHandler::canRead() called with no device");
|
||||
return false;
|
||||
}
|
||||
|
||||
const QByteArray header = device->peek(28);
|
||||
return HEIFHandler::isSupportedBMFFType(header);
|
||||
}
|
||||
|
||||
bool HEIFHandler::isSupportedBMFFType(const QByteArray &header)
|
||||
{
|
||||
if (header.size() < 28) {
|
||||
@@ -353,22 +350,6 @@ bool HEIFHandler::isSupportedBMFFType(const QByteArray &header)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HEIFHandler::isSupportedHEJ2(const QByteArray &header)
|
||||
{
|
||||
if (header.size() < 28) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *buffer = header.constData();
|
||||
if (qstrncmp(buffer + 4, "ftyp", 4) == 0) {
|
||||
if (qstrncmp(buffer + 8, "j2ki", 4) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant HEIFHandler::option(ImageOption option) const
|
||||
{
|
||||
if (option == Quality) {
|
||||
@@ -444,7 +425,7 @@ bool HEIFHandler::ensureDecoder()
|
||||
}
|
||||
|
||||
const QByteArray buffer = device()->readAll();
|
||||
if (!HEIFHandler::isSupportedBMFFType(buffer) && !HEIFHandler::isSupportedHEJ2(buffer)) {
|
||||
if (!HEIFHandler::isSupportedBMFFType(buffer)) {
|
||||
m_parseState = ParseHeicError;
|
||||
return false;
|
||||
}
|
||||
@@ -833,9 +814,6 @@ bool HEIFHandler::isHeifDecoderAvailable()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIBHEIF_HAVE_VERSION(1, 13, 0)
|
||||
m_hej2_decoder_available = heif_have_decoder_for_format(heif_compression_JPEG2000);
|
||||
#endif
|
||||
m_heif_encoder_available = heif_have_encoder_for_format(heif_compression_HEVC);
|
||||
m_heif_decoder_available = heif_have_decoder_for_format(heif_compression_HEVC);
|
||||
m_plugins_queried = true;
|
||||
@@ -861,9 +839,6 @@ bool HEIFHandler::isHeifEncoderAvailable()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIBHEIF_HAVE_VERSION(1, 13, 0)
|
||||
m_hej2_decoder_available = heif_have_decoder_for_format(heif_compression_JPEG2000);
|
||||
#endif
|
||||
m_heif_decoder_available = heif_have_decoder_for_format(heif_compression_HEVC);
|
||||
m_heif_encoder_available = heif_have_encoder_for_format(heif_compression_HEVC);
|
||||
m_plugins_queried = true;
|
||||
@@ -878,34 +853,6 @@ bool HEIFHandler::isHeifEncoderAvailable()
|
||||
return m_heif_encoder_available;
|
||||
}
|
||||
|
||||
bool HEIFHandler::isHej2DecoderAvailable()
|
||||
{
|
||||
QMutexLocker locker(&getHEIFHandlerMutex());
|
||||
|
||||
if (!m_plugins_queried) {
|
||||
#if LIBHEIF_HAVE_VERSION(1, 13, 0)
|
||||
if (m_initialized_count == 0) {
|
||||
heif_init(nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
m_heif_encoder_available = heif_have_encoder_for_format(heif_compression_HEVC);
|
||||
m_heif_decoder_available = heif_have_decoder_for_format(heif_compression_HEVC);
|
||||
#if LIBHEIF_HAVE_VERSION(1, 13, 0)
|
||||
m_hej2_decoder_available = heif_have_decoder_for_format(heif_compression_JPEG2000);
|
||||
#endif
|
||||
m_plugins_queried = true;
|
||||
|
||||
#if LIBHEIF_HAVE_VERSION(1, 13, 0)
|
||||
if (m_initialized_count == 0) {
|
||||
heif_deinit();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return m_hej2_decoder_available;
|
||||
}
|
||||
|
||||
void HEIFHandler::startHeifLib()
|
||||
{
|
||||
#if LIBHEIF_HAVE_VERSION(1, 13, 0)
|
||||
@@ -954,15 +901,6 @@ QImageIOPlugin::Capabilities HEIFPlugin::capabilities(QIODevice *device, const Q
|
||||
}
|
||||
return format_cap;
|
||||
}
|
||||
|
||||
if (format == "hej2") {
|
||||
Capabilities format_cap;
|
||||
if (HEIFHandler::isHej2DecoderAvailable()) {
|
||||
format_cap |= CanRead;
|
||||
}
|
||||
return format_cap;
|
||||
}
|
||||
|
||||
if (!format.isEmpty()) {
|
||||
return {};
|
||||
}
|
||||
@@ -971,16 +909,8 @@ QImageIOPlugin::Capabilities HEIFPlugin::capabilities(QIODevice *device, const Q
|
||||
}
|
||||
|
||||
Capabilities cap;
|
||||
if (device->isReadable()) {
|
||||
const QByteArray header = device->peek(28);
|
||||
|
||||
if (HEIFHandler::isSupportedBMFFType(header) && HEIFHandler::isHeifDecoderAvailable()) {
|
||||
cap |= CanRead;
|
||||
}
|
||||
|
||||
if (HEIFHandler::isSupportedHEJ2(header) && HEIFHandler::isHej2DecoderAvailable()) {
|
||||
cap |= CanRead;
|
||||
}
|
||||
if (device->isReadable() && HEIFHandler::canRead(device) && HEIFHandler::isHeifDecoderAvailable()) {
|
||||
cap |= CanRead;
|
||||
}
|
||||
|
||||
if (device->isWritable() && HEIFHandler::isHeifEncoderAvailable()) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"Keys": [ "heif", "heic", "hej2" ],
|
||||
"MimeTypes": [ "image/heif", "image/heif", "image/hej2k" ]
|
||||
"Keys": [ "heif", "heic" ],
|
||||
"MimeTypes": [ "image/heif", "image/heif" ]
|
||||
}
|
||||
|
||||
@@ -24,18 +24,17 @@ public:
|
||||
bool read(QImage *image) override;
|
||||
bool write(const QImage &image) override;
|
||||
|
||||
static bool canRead(QIODevice *device);
|
||||
|
||||
QVariant option(ImageOption option) const override;
|
||||
void setOption(ImageOption option, const QVariant &value) override;
|
||||
bool supportsOption(ImageOption option) const override;
|
||||
|
||||
static bool isHeifDecoderAvailable();
|
||||
static bool isHeifEncoderAvailable();
|
||||
static bool isHej2DecoderAvailable();
|
||||
|
||||
static bool isSupportedBMFFType(const QByteArray &header);
|
||||
static bool isSupportedHEJ2(const QByteArray &header);
|
||||
|
||||
private:
|
||||
static bool isSupportedBMFFType(const QByteArray &header);
|
||||
bool ensureParsed() const;
|
||||
bool ensureDecoder();
|
||||
|
||||
@@ -58,7 +57,6 @@ private:
|
||||
static bool m_plugins_queried;
|
||||
static bool m_heif_decoder_available;
|
||||
static bool m_heif_encoder_available;
|
||||
static bool m_hej2_decoder_available;
|
||||
|
||||
static QMutex &getHEIFHandlerMutex();
|
||||
};
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
#include <QImage>
|
||||
#include <QImageIOHandler>
|
||||
#include <QImageIOPlugin>
|
||||
#include <QList>
|
||||
#include <QVariant>
|
||||
#include <QVector>
|
||||
|
||||
#include <jxl/decode.h>
|
||||
|
||||
@@ -71,7 +71,7 @@ private:
|
||||
void *m_runner;
|
||||
JxlBasicInfo m_basicinfo;
|
||||
|
||||
QList<int> m_framedelays;
|
||||
QVector<int> m_framedelays;
|
||||
int m_next_image_delay;
|
||||
|
||||
QImage m_current_image;
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"Keys": [ "jxr", "wdp", "hdp" ],
|
||||
"MimeTypes": [ "image/jxr", "image/vnd.ms-photo", "image/vnd.ms-photo" ]
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
This file is part of the KDE project
|
||||
SPDX-FileCopyrightText: 2024 Mirco Miranda <mircomir@outlook.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef KIMG_JXR_P_H
|
||||
#define KIMG_JXR_P_H
|
||||
|
||||
#include <QImageIOPlugin>
|
||||
#include <QSharedDataPointer>
|
||||
|
||||
class JXRHandlerPrivate;
|
||||
|
||||
class JXRHandler : public QImageIOHandler
|
||||
{
|
||||
public:
|
||||
JXRHandler();
|
||||
|
||||
bool canRead() const override;
|
||||
bool read(QImage *outImage) override;
|
||||
bool write(const QImage &image) override;
|
||||
|
||||
void setOption(ImageOption option, const QVariant &value) override;
|
||||
bool supportsOption(QImageIOHandler::ImageOption option) const override;
|
||||
QVariant option(QImageIOHandler::ImageOption option) const override;
|
||||
|
||||
static bool canRead(QIODevice *device);
|
||||
|
||||
private:
|
||||
mutable QSharedDataPointer<JXRHandlerPrivate> d;
|
||||
|
||||
qint32 m_quality;
|
||||
};
|
||||
|
||||
class JXRPlugin : public QImageIOPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface" FILE "jxr.json")
|
||||
|
||||
public:
|
||||
Capabilities capabilities(QIODevice *device, const QByteArray &format) const override;
|
||||
QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const override;
|
||||
};
|
||||
|
||||
#endif // KIMG_JXR_P_H
|
||||
@@ -383,8 +383,7 @@ static bool readImage8(QImage &img, QDataStream &s, const PCXHEADER &header)
|
||||
while (flag != 12 && s.status() == QDataStream::Ok) {
|
||||
s >> flag;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
device->seek(device->size() - 769);
|
||||
s >> flag;
|
||||
}
|
||||
@@ -613,7 +612,7 @@ static bool writeImage24(QImage &img, QDataStream &s, PCXHEADER &header)
|
||||
QByteArray b_buf(header.width(), 0);
|
||||
|
||||
for (int y = 0; y < header.height(); ++y) {
|
||||
auto p = (QRgb*)img.scanLine(y);
|
||||
auto p = (QRgb *)img.scanLine(y);
|
||||
|
||||
for (int x = 0; x < header.width(); ++x) {
|
||||
QRgb rgb = *p++;
|
||||
@@ -684,7 +683,7 @@ bool PCXHandler::read(QImage *outImage)
|
||||
|
||||
img.setDotsPerMeterX(qRound(header.HDpi / 25.4 * 1000));
|
||||
img.setDotsPerMeterY(qRound(header.YDpi / 25.4 * 1000));
|
||||
*outImage = img;
|
||||
*outImage = std::move(img);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,340 +0,0 @@
|
||||
/*
|
||||
This file is part of the KDE project
|
||||
SPDX-FileCopyrightText: 2024 Mirco Miranda <mircomir@outlook.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
/*
|
||||
* See also: https://www.pauldebevec.com/Research/HDR/PFM/
|
||||
*/
|
||||
|
||||
#include "pfm_p.h"
|
||||
#include "util_p.h"
|
||||
|
||||
#include <QColorSpace>
|
||||
#include <QDataStream>
|
||||
#include <QIODevice>
|
||||
#include <QImage>
|
||||
#include <QLoggingCategory>
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_PFMPLUGIN)
|
||||
Q_LOGGING_CATEGORY(LOG_PFMPLUGIN, "kf.imageformats.plugins.pfm", QtWarningMsg)
|
||||
|
||||
class PFMHeader
|
||||
{
|
||||
private:
|
||||
/*!
|
||||
* \brief m_bw True if grayscale.
|
||||
*/
|
||||
bool m_bw;
|
||||
|
||||
/*!
|
||||
* \brief m_ps True if saved by Photoshop (Photoshop variant).
|
||||
*
|
||||
* When \a false the format of the header is the following (GIMP):
|
||||
* [type]
|
||||
* [xres] [yres]
|
||||
* [byte_order]
|
||||
*
|
||||
* When \a true the format of the header is the following (Photoshop):
|
||||
* [type]
|
||||
* [xres]
|
||||
* [yres]
|
||||
* [byte_order]
|
||||
*/
|
||||
bool m_ps;
|
||||
|
||||
/*!
|
||||
* \brief m_width The image width.
|
||||
*/
|
||||
qint32 m_width;
|
||||
|
||||
/*!
|
||||
* \brief m_height The image height.
|
||||
*/
|
||||
qint32 m_height;
|
||||
|
||||
/*!
|
||||
* \brief m_byteOrder The image byte orger.
|
||||
*/
|
||||
QDataStream::ByteOrder m_byteOrder;
|
||||
|
||||
public:
|
||||
PFMHeader() :
|
||||
m_bw(false),
|
||||
m_ps(false),
|
||||
m_width(0),
|
||||
m_height(0),
|
||||
m_byteOrder(QDataStream::BigEndian)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return (m_width > 0 && m_height > 0);
|
||||
}
|
||||
|
||||
bool isBlackAndWhite() const
|
||||
{
|
||||
return m_bw;
|
||||
}
|
||||
|
||||
bool isPhotoshop() const
|
||||
{
|
||||
return m_ps;
|
||||
}
|
||||
|
||||
qint32 width() const
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
qint32 height() const
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
QSize size() const
|
||||
{
|
||||
return QSize(m_width, m_height);
|
||||
}
|
||||
|
||||
QDataStream::ByteOrder byteOrder() const
|
||||
{
|
||||
return m_byteOrder;
|
||||
}
|
||||
|
||||
QImage::Format format() const
|
||||
{
|
||||
if (isValid()) {
|
||||
return isBlackAndWhite() ? QImage::Format_Grayscale16 : QImage::Format_RGBX32FPx4;
|
||||
}
|
||||
return QImage::Format_Invalid;
|
||||
}
|
||||
|
||||
bool read(QIODevice *d)
|
||||
{
|
||||
auto pf = d->read(3);
|
||||
if (pf == QByteArray("PF\n")) {
|
||||
m_bw = false;
|
||||
} else if (pf == QByteArray("Pf\n")) {
|
||||
m_bw = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
auto wh = QString::fromLatin1(d->readLine(128));
|
||||
auto list = wh.split(QStringLiteral(" "));
|
||||
if (list.size() == 1) {
|
||||
m_ps = true; // try for Photoshop version
|
||||
list << QString::fromLatin1(d->readLine(128));
|
||||
}
|
||||
if (list.size() != 2) {
|
||||
return false;
|
||||
}
|
||||
auto ok_o = false;
|
||||
auto ok_w = false;
|
||||
auto ok_h = false;
|
||||
auto o = QString::fromLatin1(d->readLine(128)).toDouble(&ok_o);
|
||||
auto w = list.first().toInt(&ok_w);
|
||||
auto h = list.last().toInt(&ok_h);
|
||||
if (!ok_o || !ok_w || !ok_h || o == 0) {
|
||||
return false;
|
||||
}
|
||||
m_width = w;
|
||||
m_height = h;
|
||||
m_byteOrder = o > 0 ? QDataStream::BigEndian : QDataStream::LittleEndian;
|
||||
return isValid();
|
||||
}
|
||||
|
||||
bool peek(QIODevice *d)
|
||||
{
|
||||
d->startTransaction();
|
||||
auto ok = read(d);
|
||||
d->rollbackTransaction();
|
||||
return ok;
|
||||
}
|
||||
} ;
|
||||
|
||||
class PFMHandlerPrivate
|
||||
{
|
||||
public:
|
||||
PFMHandlerPrivate() {}
|
||||
~PFMHandlerPrivate() {}
|
||||
|
||||
PFMHeader m_header;
|
||||
};
|
||||
|
||||
PFMHandler::PFMHandler()
|
||||
: QImageIOHandler()
|
||||
, d(new PFMHandlerPrivate)
|
||||
{
|
||||
}
|
||||
|
||||
bool PFMHandler::canRead() const
|
||||
{
|
||||
if (canRead(device())) {
|
||||
setFormat("pfm");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PFMHandler::canRead(QIODevice *device)
|
||||
{
|
||||
if (!device) {
|
||||
qCWarning(LOG_PFMPLUGIN) << "PFMHandler::canRead() called with no device";
|
||||
return false;
|
||||
}
|
||||
|
||||
PFMHeader h;
|
||||
if (!h.peek(device)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return h.isValid();
|
||||
}
|
||||
|
||||
bool PFMHandler::read(QImage *image)
|
||||
{
|
||||
auto&& header = d->m_header;
|
||||
if (!header.read(device())) {
|
||||
qCWarning(LOG_PFMPLUGIN) << "PFMHandler::read() invalid header";
|
||||
return false;
|
||||
}
|
||||
|
||||
QDataStream s(device());
|
||||
s.setFloatingPointPrecision(QDataStream::SinglePrecision);
|
||||
s.setByteOrder(header.byteOrder());
|
||||
|
||||
auto img = imageAlloc(header.size(), header.format());
|
||||
if (img.isNull()) {
|
||||
qCWarning(LOG_PFMPLUGIN) << "PFMHandler::read() error while allocating the image";
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto y = 0, h = img.height(); y < h; ++y) {
|
||||
float f;
|
||||
if (header.isBlackAndWhite()) {
|
||||
auto line = reinterpret_cast<quint16*>(img.scanLine(header.isPhotoshop() ? y : h - y - 1));
|
||||
for (auto x = 0, w = img.width(); x < w; ++x) {
|
||||
s >> f;
|
||||
// QColorSpace does not handle gray linear profile, so I have to convert to non-linear
|
||||
f = f < 0.0031308f ? (f * 12.92f) : (1.055 * std::pow(f, 1.0 / 2.4) - 0.055);
|
||||
line[x] = quint16(std::clamp(f, float(0), float(1)) * std::numeric_limits<quint16>::max() + float(0.5));
|
||||
|
||||
if (s.status() != QDataStream::Ok) {
|
||||
qCWarning(LOG_PFMPLUGIN) << "PFMHandler::read() detected corrupted data";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
auto line = reinterpret_cast<float*>(img.scanLine(header.isPhotoshop() ? y : h - y - 1));
|
||||
for (auto x = 0, n = img.width() * 4; x < n; x += 4) {
|
||||
s >> f;
|
||||
line[x] = std::clamp(f, float(0), float(1));
|
||||
s >> f;
|
||||
line[x + 1] = std::clamp(f, float(0), float(1));
|
||||
s >> f;
|
||||
line[x + 2] = std::clamp(f, float(0), float(1));
|
||||
line[x + 3] = float(1);
|
||||
|
||||
if (s.status() != QDataStream::Ok) {
|
||||
qCWarning(LOG_PFMPLUGIN) << "PFMHandler::read() detected corrupted data";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!header.isBlackAndWhite()) {
|
||||
img.setColorSpace(QColorSpace(QColorSpace::SRgbLinear));
|
||||
}
|
||||
|
||||
*image = img;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PFMHandler::supportsOption(ImageOption option) const
|
||||
{
|
||||
if (option == QImageIOHandler::Size) {
|
||||
return true;
|
||||
}
|
||||
if (option == QImageIOHandler::ImageFormat) {
|
||||
return true;
|
||||
}
|
||||
if (option == QImageIOHandler::Endianness) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant PFMHandler::option(ImageOption option) const
|
||||
{
|
||||
QVariant v;
|
||||
|
||||
if (option == QImageIOHandler::Size) {
|
||||
auto&& h = d->m_header;
|
||||
if (h.isValid()) {
|
||||
v = QVariant::fromValue(h.size());
|
||||
} else if (auto dev = device()) {
|
||||
if (h.peek(dev)) {
|
||||
v = QVariant::fromValue(h.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (option == QImageIOHandler::ImageFormat) {
|
||||
auto&& h = d->m_header;
|
||||
if (h.isValid()) {
|
||||
v = QVariant::fromValue(h.format());
|
||||
} else if (auto dev = device()) {
|
||||
if (h.peek(dev)) {
|
||||
v = QVariant::fromValue(h.format());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (option == QImageIOHandler::Endianness) {
|
||||
auto&& h = d->m_header;
|
||||
if (h.isValid()) {
|
||||
v = QVariant::fromValue(h.byteOrder());
|
||||
} else if (auto dev = device()) {
|
||||
if (h.peek(dev)) {
|
||||
v = QVariant::fromValue(h.byteOrder());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
QImageIOPlugin::Capabilities PFMPlugin::capabilities(QIODevice *device, const QByteArray &format) const
|
||||
{
|
||||
if (format == "pfm") {
|
||||
return Capabilities(CanRead);
|
||||
}
|
||||
if (!format.isEmpty()) {
|
||||
return {};
|
||||
}
|
||||
if (!device->isOpen()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
Capabilities cap;
|
||||
if (device->isReadable() && PFMHandler::canRead(device)) {
|
||||
cap |= CanRead;
|
||||
}
|
||||
return cap;
|
||||
}
|
||||
|
||||
QImageIOHandler *PFMPlugin::create(QIODevice *device, const QByteArray &format) const
|
||||
{
|
||||
QImageIOHandler *handler = new PFMHandler;
|
||||
handler->setDevice(device);
|
||||
handler->setFormat(format);
|
||||
return handler;
|
||||
}
|
||||
|
||||
#include "moc_pfm_p.cpp"
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"Keys": [ "pfm" ],
|
||||
"MimeTypes": [ "image/x-pfm" ]
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
This file is part of the KDE project
|
||||
SPDX-FileCopyrightText: 2024 Mirco Miranda <mircomir@outlook.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef KIMG_PFM_P_H
|
||||
#define KIMG_PFM_P_H
|
||||
|
||||
#include <QImageIOPlugin>
|
||||
#include <QScopedPointer>
|
||||
|
||||
class PFMHandlerPrivate;
|
||||
class PFMHandler : public QImageIOHandler
|
||||
{
|
||||
public:
|
||||
PFMHandler();
|
||||
|
||||
bool canRead() const override;
|
||||
bool read(QImage *image) override;
|
||||
|
||||
bool supportsOption(QImageIOHandler::ImageOption option) const override;
|
||||
QVariant option(QImageIOHandler::ImageOption option) const override;
|
||||
|
||||
static bool canRead(QIODevice *device);
|
||||
|
||||
private:
|
||||
const QScopedPointer<PFMHandlerPrivate> d;
|
||||
};
|
||||
|
||||
class PFMPlugin : public QImageIOPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface" FILE "pfm.json")
|
||||
|
||||
public:
|
||||
Capabilities capabilities(QIODevice *device, const QByteArray &format) const override;
|
||||
QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const override;
|
||||
};
|
||||
|
||||
#endif // KIMG_PFM_P_H
|
||||
@@ -255,7 +255,7 @@ bool SoftimagePICHandler::read(QImage *image)
|
||||
}
|
||||
}
|
||||
|
||||
*image = img;
|
||||
*image = std::move(img);
|
||||
m_state = Ready;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
* - Color spaces other than RGB/Grayscale cannot be read due to lack of QImage
|
||||
* support. Where possible, a conversion to RGB is done:
|
||||
* - CMYK images are converted using an approximated way that ignores the color
|
||||
* information (ICC profile) with Qt less than 6.8.
|
||||
* information (ICC profile).
|
||||
* - LAB images are converted to sRGB using literature formulas.
|
||||
* - MULICHANNEL images more than 3 channels are converted as CMYK images.
|
||||
* - DUOTONE images are considered as Grayscale images.
|
||||
@@ -34,7 +34,6 @@
|
||||
|
||||
#include "fastmath_p.h"
|
||||
#include "psd_p.h"
|
||||
#include "scanlineconverter_p.h"
|
||||
#include "util_p.h"
|
||||
|
||||
#include <QDataStream>
|
||||
@@ -61,24 +60,9 @@ typedef quint8 uchar;
|
||||
*/
|
||||
//#define PSD_FAST_LAB_CONVERSION
|
||||
|
||||
/*
|
||||
* Since Qt version 6.8, the 8-bit CMYK format is natively supported.
|
||||
* If you encounter problems with native CMYK support you can continue to force the plugin to convert
|
||||
* to RGB as in previous versions by defining PSD_NATIVE_CMYK_SUPPORT_DISABLED.
|
||||
*/
|
||||
//#define PSD_NATIVE_CMYK_SUPPORT_DISABLED
|
||||
|
||||
namespace // Private.
|
||||
{
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) || defined(PSD_NATIVE_CMYK_SUPPORT_DISABLED)
|
||||
# define CMYK_FORMAT QImage::Format_Invalid
|
||||
#else
|
||||
# define CMYK_FORMAT QImage::Format_CMYK8888
|
||||
#endif
|
||||
|
||||
#define NATIVE_CMYK (CMYK_FORMAT != QImage::Format_Invalid)
|
||||
|
||||
enum Signature : quint32 {
|
||||
S_8BIM = 0x3842494D, // '8BIM'
|
||||
S_8B64 = 0x38423634, // '8B64'
|
||||
@@ -112,10 +96,6 @@ enum LayerId : quint32 {
|
||||
};
|
||||
|
||||
struct PSDHeader {
|
||||
PSDHeader() {
|
||||
memset(this, 0, sizeof(PSDHeader));
|
||||
}
|
||||
|
||||
uint signature;
|
||||
ushort version;
|
||||
uchar reserved[6];
|
||||
@@ -146,7 +126,7 @@ struct PSDDuotoneOptions {
|
||||
*/
|
||||
struct PSDColorModeDataSection {
|
||||
PSDDuotoneOptions duotone;
|
||||
QList<QRgb> palette;
|
||||
QVector<QRgb> palette;
|
||||
};
|
||||
|
||||
using PSDImageResourceSection = QHash<quint16, PSDImageResourceBlock>;
|
||||
@@ -478,7 +458,7 @@ PSDColorModeDataSection readColorModeDataSection(QDataStream &s, bool *ok = null
|
||||
}
|
||||
else { // read the palette (768 bytes)
|
||||
auto&& palette = cms.palette;
|
||||
QList<quint8> vect(size);
|
||||
QVector<quint8> vect(size);
|
||||
for (auto&& v : vect)
|
||||
s >> v;
|
||||
for (qsizetype i = 0, n = vect.size()/3; i < n; ++i)
|
||||
@@ -497,7 +477,7 @@ PSDColorModeDataSection readColorModeDataSection(QDataStream &s, bool *ok = null
|
||||
*/
|
||||
static bool setColorSpace(QImage& img, const PSDImageResourceSection& irs)
|
||||
{
|
||||
if (!irs.contains(IRI_ICCPROFILE) || img.isNull())
|
||||
if (!irs.contains(IRI_ICCPROFILE))
|
||||
return false;
|
||||
auto irb = irs.value(IRI_ICCPROFILE);
|
||||
auto cs = QColorSpace::fromIccProfile(irb.data);
|
||||
@@ -525,7 +505,7 @@ static bool setXmpData(QImage& img, const PSDImageResourceSection& irs)
|
||||
// NOTE: "XML:com.adobe.xmp" is the meta set by Qt reader when an
|
||||
// XMP packet is found (e.g. when reading a PNG saved by Photoshop).
|
||||
// I'm reusing the same key because a programs could search for it.
|
||||
img.setText(QStringLiteral(META_KEY_XMP_ADOBE), xmp);
|
||||
img.setText(QStringLiteral("XML:com.adobe.xmp"), xmp);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -651,7 +631,7 @@ static bool IsValid(const PSDHeader &header)
|
||||
qDebug() << "PSD header: invalid color mode" << header.color_mode;
|
||||
return false;
|
||||
}
|
||||
// Specs tells: "Supported range is 1 to 56" but when the alpha channel is present the limit is 57:
|
||||
// Specs tells: "Supported range is 1 to 56" but the limit is 57:
|
||||
// Photoshop does not make you add more (see also 53alphas.psd test case).
|
||||
if (header.channel_count < 1 || header.channel_count > 57) {
|
||||
qDebug() << "PSD header: invalid number of channels" << header.channel_count;
|
||||
@@ -762,9 +742,7 @@ static QImage::Format imageFormat(const PSDHeader &header, bool alpha)
|
||||
break;
|
||||
case CM_MULTICHANNEL: // Treat MCH as CMYK (number of channel check is done in IsSupported())
|
||||
case CM_CMYK: // Photoshop supports CMYK/MCH 8-bits and 16-bits only
|
||||
if (NATIVE_CMYK && header.channel_count == 4 && (header.depth == 16 || header.depth == 8))
|
||||
format = CMYK_FORMAT;
|
||||
else if (header.depth == 16)
|
||||
if (header.depth == 16)
|
||||
format = header.channel_count < 5 || !alpha ? QImage::Format_RGBX64 : QImage::Format_RGBA64;
|
||||
else if (header.depth == 8)
|
||||
format = header.channel_count < 5 || !alpha ? QImage::Format_RGB888 : QImage::Format_RGBA8888;
|
||||
@@ -866,18 +844,6 @@ inline void planarToChunchy(uchar *target, const char *source, qint32 width, qin
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void planarToChunchyCMYK(uchar *target, const char *source, qint32 width, qint32 c, qint32 cn)
|
||||
{
|
||||
auto s = reinterpret_cast<const T*>(source);
|
||||
auto t = reinterpret_cast<quint8*>(target);
|
||||
const T d = std::numeric_limits<T>::max() / std::numeric_limits<quint8>::max();
|
||||
for (qint32 x = 0; x < width; ++x) {
|
||||
t[x * cn + c] = quint8((std::numeric_limits<T>::max() - xchg(s[x])) / d);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void planarToChunchyFloatToUInt16(uchar *target, const char *source, qint32 width, qint32 c, qint32 cn)
|
||||
{
|
||||
@@ -937,19 +903,6 @@ inline void monoInvert(uchar *target, const char* source, qint32 bytes)
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void rawChannelsCopyToCMYK(uchar *target, qint32 targetChannels, const char *source, qint32 sourceChannels, qint32 width)
|
||||
{
|
||||
auto s = reinterpret_cast<const T*>(source);
|
||||
auto t = reinterpret_cast<quint8*>(target);
|
||||
const T d = std::numeric_limits<T>::max() / std::numeric_limits<quint8>::max();
|
||||
for (qint32 c = 0, cs = std::min(targetChannels, sourceChannels); c < cs; ++c) {
|
||||
for (qint32 x = 0; x < width; ++x) {
|
||||
t[x * targetChannels + c] = (std::numeric_limits<T>::max() - s[x * sourceChannels + c]) / d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void rawChannelsCopy(uchar *target, qint32 targetChannels, const char *source, qint32 sourceChannels, qint32 width)
|
||||
{
|
||||
@@ -962,17 +915,6 @@ inline void rawChannelsCopy(uchar *target, qint32 targetChannels, const char *so
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void rawChannelCopy(uchar *target, qint32 targetChannels, qint32 targetChannel, const char *source, qint32 sourceChannels, qint32 sourceChannel, qint32 width)
|
||||
{
|
||||
auto s = reinterpret_cast<const T*>(source);
|
||||
auto t = reinterpret_cast<T*>(target);
|
||||
for (qint32 x = 0; x < width; ++x) {
|
||||
t[x * targetChannels + targetChannel] = s[x * sourceChannels + sourceChannel];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void cmykToRgb(uchar *target, qint32 targetChannels, const char *source, qint32 sourceChannels, qint32 width, bool alpha = false)
|
||||
{
|
||||
@@ -1161,14 +1103,13 @@ static bool LoadPSD(QDataStream &stream, const PSDHeader &header, QImage &img)
|
||||
auto imgChannels = imageChannels(img.format());
|
||||
auto channel_num = std::min(qint32(header.channel_count), imgChannels);
|
||||
auto raw_count = qsizetype(header.width * header.depth + 7) / 8;
|
||||
auto native_cmyk = img.format() == CMYK_FORMAT;
|
||||
|
||||
if (header.height > kMaxQVectorSize / header.channel_count / sizeof(quint32)) {
|
||||
qWarning() << "LoadPSD() header height/channel_count too big" << header.height << header.channel_count;
|
||||
return false;
|
||||
}
|
||||
|
||||
QList<quint32> strides(header.height * header.channel_count, raw_count);
|
||||
QVector<quint32> strides(header.height * header.channel_count, raw_count);
|
||||
// Read the compressed stride sizes
|
||||
if (compression) {
|
||||
for (auto&& v : strides) {
|
||||
@@ -1183,7 +1124,7 @@ static bool LoadPSD(QDataStream &stream, const PSDHeader &header, QImage &img)
|
||||
}
|
||||
// calculate the absolute file positions of each stride (required when a colorspace conversion should be done)
|
||||
auto device = stream.device();
|
||||
QList<quint64> stridePositions(strides.size());
|
||||
QVector<quint64> stridePositions(strides.size());
|
||||
if (!stridePositions.isEmpty()) {
|
||||
stridePositions[0] = device->pos();
|
||||
}
|
||||
@@ -1197,25 +1138,13 @@ static bool LoadPSD(QDataStream &stream, const PSDHeader &header, QImage &img)
|
||||
|
||||
// clang-format off
|
||||
// checks the need of color conversion (that requires random access to the image)
|
||||
auto randomAccess = (header.color_mode == CM_CMYK && !native_cmyk) ||
|
||||
(header.color_mode == CM_MULTICHANNEL && !native_cmyk) ||
|
||||
auto randomAccess = (header.color_mode == CM_CMYK) ||
|
||||
(header.color_mode == CM_LABCOLOR) ||
|
||||
(header.color_mode == CM_MULTICHANNEL) ||
|
||||
(header.color_mode != CM_INDEXED && img.hasAlphaChannel());
|
||||
// clang-format on
|
||||
|
||||
if (randomAccess) {
|
||||
// CMYK with spots (e.g. CMYKA) ICC conversion to RGBA/RGBX
|
||||
QImage tmpCmyk;
|
||||
ScanLineConverter iccConv(img.format());
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) && !defined(PSD_NATIVE_CMYK_SUPPORT_DISABLED)
|
||||
if (header.color_mode == CM_CMYK && img.format() != QImage::Format_CMYK8888) {
|
||||
auto tmpi = QImage(header.width, 1, QImage::Format_CMYK8888);
|
||||
if (setColorSpace(tmpi, irs))
|
||||
tmpCmyk = tmpi;
|
||||
iccConv.setTargetColorSpace(QColorSpace(QColorSpace::SRgb));
|
||||
}
|
||||
#endif
|
||||
|
||||
// In order to make a colorspace transformation, we need all channels of a scanline
|
||||
QByteArray psdScanline;
|
||||
psdScanline.resize(qsizetype(header.width * header.depth * header.channel_count + 7) / 8);
|
||||
@@ -1271,26 +1200,10 @@ static bool LoadPSD(QDataStream &stream, const PSDHeader &header, QImage &img)
|
||||
|
||||
// Conversion to RGB
|
||||
if (header.color_mode == CM_CMYK || header.color_mode == CM_MULTICHANNEL) {
|
||||
if (tmpCmyk.isNull()) {
|
||||
if (header.depth == 8)
|
||||
cmykToRgb<quint8>(img.scanLine(y), imgChannels, psdScanline.data(), header.channel_count, header.width, alpha);
|
||||
else if (header.depth == 16)
|
||||
cmykToRgb<quint16>(img.scanLine(y), imgChannels, psdScanline.data(), header.channel_count, header.width, alpha);
|
||||
}
|
||||
else if (header.depth == 8) {
|
||||
rawChannelsCopyToCMYK<quint8>(tmpCmyk.bits(), 4, psdScanline.data(), header.channel_count, header.width);
|
||||
if (auto rgbPtr = iccConv.convertedScanLine(tmpCmyk, 0))
|
||||
std::memcpy(img.scanLine(y), rgbPtr, img.bytesPerLine());
|
||||
if (imgChannels == 4 && header.channel_count >= 5)
|
||||
rawChannelCopy<quint8>(img.scanLine(y), imgChannels, 3, psdScanline.data(), header.channel_count, 4, header.width);
|
||||
}
|
||||
else if (header.depth == 16) {
|
||||
rawChannelsCopyToCMYK<quint16>(tmpCmyk.bits(), 4, psdScanline.data(), header.channel_count, header.width);
|
||||
if (auto rgbPtr = iccConv.convertedScanLine(tmpCmyk, 0))
|
||||
std::memcpy(img.scanLine(y), rgbPtr, img.bytesPerLine());
|
||||
if (imgChannels == 4 && header.channel_count >= 5)
|
||||
rawChannelCopy<quint16>(img.scanLine(y), imgChannels, 3, psdScanline.data(), header.channel_count, 4, header.width);
|
||||
}
|
||||
if (header.depth == 8)
|
||||
cmykToRgb<quint8>(img.scanLine(y), imgChannels, psdScanline.data(), header.channel_count, header.width, alpha);
|
||||
else if (header.depth == 16)
|
||||
cmykToRgb<quint16>(img.scanLine(y), imgChannels, psdScanline.data(), header.channel_count, header.width, alpha);
|
||||
}
|
||||
if (header.color_mode == CM_LABCOLOR) {
|
||||
if (header.depth == 8)
|
||||
@@ -1322,17 +1235,11 @@ static bool LoadPSD(QDataStream &stream, const PSDHeader &header, QImage &img)
|
||||
if (header.depth == 1) { // Bitmap
|
||||
monoInvert(scanLine, rawStride.data(), std::min(rawStride.size(), img.bytesPerLine()));
|
||||
}
|
||||
else if (header.depth == 8) { // 8-bits images: Indexed, Grayscale, RGB/RGBA, CMYK, MCH4
|
||||
if (native_cmyk)
|
||||
planarToChunchyCMYK<quint8>(scanLine, rawStride.data(), header.width, c, imgChannels);
|
||||
else
|
||||
planarToChunchy<quint8>(scanLine, rawStride.data(), header.width, c, imgChannels);
|
||||
else if (header.depth == 8) { // 8-bits images: Indexed, Grayscale, RGB/RGBA
|
||||
planarToChunchy<quint8>(scanLine, rawStride.data(), header.width, c, imgChannels);
|
||||
}
|
||||
else if (header.depth == 16) { // 16-bits integer images: Grayscale, RGB/RGBA, CMYK, MCH4
|
||||
if (native_cmyk)
|
||||
planarToChunchyCMYK<quint16>(scanLine, rawStride.data(), header.width, c, imgChannels);
|
||||
else
|
||||
planarToChunchy<quint16>(scanLine, rawStride.data(), header.width, c, imgChannels);
|
||||
else if (header.depth == 16) { // 16-bits integer images: Grayscale, RGB/RGBA
|
||||
planarToChunchy<quint16>(scanLine, rawStride.data(), header.width, c, imgChannels);
|
||||
}
|
||||
else if (header.depth == 32 && header.color_mode == CM_RGB) { // 32-bits float images: RGB/RGBA
|
||||
planarToChunchy<float>(scanLine, rawStride.data(), header.width, c, imgChannels);
|
||||
@@ -1344,6 +1251,7 @@ static bool LoadPSD(QDataStream &stream, const PSDHeader &header, QImage &img)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Resolution info
|
||||
if (!setResolution(img, irs)) {
|
||||
// qDebug() << "No resolution info found!";
|
||||
@@ -1379,17 +1287,7 @@ static bool LoadPSD(QDataStream &stream, const PSDHeader &header, QImage &img)
|
||||
|
||||
} // Private
|
||||
|
||||
class PSDHandlerPrivate
|
||||
{
|
||||
public:
|
||||
PSDHandlerPrivate() {}
|
||||
~PSDHandlerPrivate() {}
|
||||
PSDHeader m_header;
|
||||
};
|
||||
|
||||
PSDHandler::PSDHandler()
|
||||
: QImageIOHandler()
|
||||
, d(new PSDHandlerPrivate)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1407,7 +1305,7 @@ bool PSDHandler::read(QImage *image)
|
||||
QDataStream s(device());
|
||||
s.setByteOrder(QDataStream::BigEndian);
|
||||
|
||||
auto&& header = d->m_header;
|
||||
PSDHeader header;
|
||||
s >> header;
|
||||
|
||||
// Check image file format.
|
||||
@@ -1428,7 +1326,7 @@ bool PSDHandler::read(QImage *image)
|
||||
return false;
|
||||
}
|
||||
|
||||
*image = img;
|
||||
*image = std::move(img);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1444,20 +1342,18 @@ QVariant PSDHandler::option(ImageOption option) const
|
||||
QVariant v;
|
||||
|
||||
if (option == QImageIOHandler::Size) {
|
||||
auto&& header = d->m_header;
|
||||
if (IsValid(header)) {
|
||||
v = QVariant::fromValue(QSize(header.width, header.height));
|
||||
}
|
||||
else if (auto dev = device()) {
|
||||
if (auto d = device()) {
|
||||
// transactions works on both random and sequential devices
|
||||
dev->startTransaction();
|
||||
auto ba = dev->read(sizeof(PSDHeader));
|
||||
dev->rollbackTransaction();
|
||||
d->startTransaction();
|
||||
auto ba = d->read(sizeof(PSDHeader));
|
||||
d->rollbackTransaction();
|
||||
|
||||
QDataStream s(ba);
|
||||
s.setByteOrder(QDataStream::BigEndian);
|
||||
|
||||
PSDHeader header;
|
||||
s >> header;
|
||||
|
||||
if (s.status() == QDataStream::Ok && IsValid(header))
|
||||
v = QVariant::fromValue(QSize(header.width, header.height));
|
||||
}
|
||||
@@ -1488,11 +1384,7 @@ bool PSDHandler::canRead(QIODevice *device)
|
||||
}
|
||||
|
||||
if (device->isSequential()) {
|
||||
if (header.color_mode == CM_CMYK || header.color_mode == CM_MULTICHANNEL) {
|
||||
if (header.channel_count != 4 || !NATIVE_CMYK)
|
||||
return false;
|
||||
}
|
||||
if (header.color_mode == CM_LABCOLOR) {
|
||||
if (header.color_mode == CM_CMYK || header.color_mode == CM_LABCOLOR || header.color_mode == CM_MULTICHANNEL) {
|
||||
return false;
|
||||
}
|
||||
if (header.color_mode == CM_RGB && header.channel_count > 3) {
|
||||
|
||||
@@ -9,9 +9,7 @@
|
||||
#define KIMG_PSD_P_H
|
||||
|
||||
#include <QImageIOPlugin>
|
||||
#include <QScopedPointer>
|
||||
|
||||
class PSDHandlerPrivate;
|
||||
class PSDHandler : public QImageIOHandler
|
||||
{
|
||||
public:
|
||||
@@ -24,9 +22,6 @@ public:
|
||||
QVariant option(QImageIOHandler::ImageOption option) const override;
|
||||
|
||||
static bool canRead(QIODevice *device);
|
||||
|
||||
private:
|
||||
const QScopedPointer<PSDHandlerPrivate> d;
|
||||
};
|
||||
|
||||
class PSDPlugin : public QImageIOPlugin
|
||||
|
||||
@@ -1,282 +0,0 @@
|
||||
/*
|
||||
This file is part of the KDE project
|
||||
SPDX-FileCopyrightText: 2024 Mirco Miranda <mircomir@outlook.com>
|
||||
|
||||
SPDX-License-Identifier: LGPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "pxr_p.h"
|
||||
#include "util_p.h"
|
||||
|
||||
#include <QIODevice>
|
||||
#include <QImage>
|
||||
#include <QLoggingCategory>
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(LOG_PXRPLUGIN)
|
||||
Q_LOGGING_CATEGORY(LOG_PXRPLUGIN, "kf.imageformats.plugins.pxr", QtWarningMsg)
|
||||
|
||||
class PXRHeader
|
||||
{
|
||||
private:
|
||||
QByteArray m_rawHeader;
|
||||
|
||||
quint16 ui16(quint8 c1, quint8 c2) const {
|
||||
return (quint16(c2) << 8) | quint16(c1);
|
||||
}
|
||||
|
||||
quint32 ui32(quint8 c1, quint8 c2, quint8 c3, quint8 c4) const {
|
||||
return (quint32(c4) << 24) | (quint32(c3) << 16) | (quint32(c2) << 8) | quint32(c1);
|
||||
}
|
||||
|
||||
public:
|
||||
PXRHeader()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool isValid() const
|
||||
{
|
||||
return (m_rawHeader.size() == 512 &&
|
||||
m_rawHeader.startsWith(QByteArray::fromRawData("\x80\xE8\x00\x00", 4)));
|
||||
}
|
||||
|
||||
bool isSupported() const
|
||||
{
|
||||
return format() != QImage::Format_Invalid;
|
||||
}
|
||||
|
||||
qint32 width() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
return 0;
|
||||
}
|
||||
return qint32(ui16(m_rawHeader.at(418), m_rawHeader.at(419)));
|
||||
}
|
||||
|
||||
qint32 height() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
return 0;
|
||||
}
|
||||
return qint32(ui16(m_rawHeader.at(416), m_rawHeader.at(417)));
|
||||
}
|
||||
|
||||
QSize size() const
|
||||
{
|
||||
return QSize(width(), height());
|
||||
}
|
||||
|
||||
qint32 channel() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
return 0;
|
||||
}
|
||||
return qint32(ui16(m_rawHeader.at(424), m_rawHeader.at(425)));
|
||||
}
|
||||
|
||||
qint32 depth() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
return 0;
|
||||
}
|
||||
return qint32(ui16(m_rawHeader.at(426), m_rawHeader.at(427)));
|
||||
}
|
||||
|
||||
// supposing the image offset (always 1024 on sample files)
|
||||
qint32 offset() const
|
||||
{
|
||||
if (!isValid()) {
|
||||
return 0;
|
||||
}
|
||||
return qint32(ui16(m_rawHeader.at(428), m_rawHeader.at(429)));
|
||||
}
|
||||
|
||||
QImage::Format format() const
|
||||
{
|
||||
if (channel() == 14 && depth() == 2) {
|
||||
return QImage::Format_RGB888;
|
||||
}
|
||||
if (channel() == 8 && depth() == 2) {
|
||||
return QImage::Format_Grayscale8;
|
||||
}
|
||||
return QImage::Format_Invalid;
|
||||
}
|
||||
|
||||
qsizetype strideSize() const
|
||||
{
|
||||
if (format() == QImage::Format_RGB888) {
|
||||
return width() * 3;
|
||||
}
|
||||
if (format() == QImage::Format_Grayscale8) {
|
||||
return width();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool read(QIODevice *d)
|
||||
{
|
||||
m_rawHeader = d->read(512);
|
||||
return isValid();
|
||||
}
|
||||
|
||||
bool peek(QIODevice *d)
|
||||
{
|
||||
d->startTransaction();
|
||||
auto ok = read(d);
|
||||
d->rollbackTransaction();
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool jumpToImageData(QIODevice *d) const
|
||||
{
|
||||
if (d->isSequential()) {
|
||||
if (auto sz = std::max(offset() - qint32(m_rawHeader.size()), 0)) {
|
||||
return d->read(sz).size() == sz;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return d->seek(offset());
|
||||
}
|
||||
};
|
||||
|
||||
class PXRHandlerPrivate
|
||||
{
|
||||
public:
|
||||
PXRHandlerPrivate() {}
|
||||
~PXRHandlerPrivate() {}
|
||||
|
||||
PXRHeader m_header;
|
||||
};
|
||||
|
||||
PXRHandler::PXRHandler()
|
||||
: QImageIOHandler()
|
||||
, d(new PXRHandlerPrivate)
|
||||
{
|
||||
}
|
||||
|
||||
bool PXRHandler::canRead() const
|
||||
{
|
||||
if (canRead(device())) {
|
||||
setFormat("pxr");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool PXRHandler::canRead(QIODevice *device)
|
||||
{
|
||||
if (!device) {
|
||||
qCWarning(LOG_PXRPLUGIN) << "PXRHandler::canRead() called with no device";
|
||||
return false;
|
||||
}
|
||||
|
||||
PXRHeader h;
|
||||
if (!h.peek(device)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return h.isSupported();
|
||||
}
|
||||
|
||||
bool PXRHandler::read(QImage *image)
|
||||
{
|
||||
auto&& header = d->m_header;
|
||||
|
||||
if (!header.read(device())) {
|
||||
qCWarning(LOG_PXRPLUGIN) << "PXRHandler::read() invalid header";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto img = imageAlloc(header.size(), header.format());
|
||||
if (img.isNull()) {
|
||||
qCWarning(LOG_PXRPLUGIN) << "PXRHandler::read() error while allocating the image";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto d = device();
|
||||
if (!header.jumpToImageData(d)) {
|
||||
qCWarning(LOG_PXRPLUGIN) << "PXRHandler::read() error while seeking image data";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto size = std::min(img.bytesPerLine(), header.strideSize());
|
||||
for (auto y = 0, h = img.height(); y < h; ++y) {
|
||||
auto line = reinterpret_cast<char*>(img.scanLine(y));
|
||||
if (d->read(line, size) != size) {
|
||||
qCWarning(LOG_PXRPLUGIN) << "PXRHandler::read() error while reading image scanline";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
*image = img;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PXRHandler::supportsOption(ImageOption option) const
|
||||
{
|
||||
if (option == QImageIOHandler::Size) {
|
||||
return true;
|
||||
}
|
||||
if (option == QImageIOHandler::ImageFormat) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant PXRHandler::option(ImageOption option) const
|
||||
{
|
||||
QVariant v;
|
||||
|
||||
if (option == QImageIOHandler::Size) {
|
||||
auto&& h = d->m_header;
|
||||
if (h.isValid()) {
|
||||
v = QVariant::fromValue(h.size());
|
||||
} else if (auto d = device()) {
|
||||
if (h.peek(d)) {
|
||||
v = QVariant::fromValue(h.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (option == QImageIOHandler::ImageFormat) {
|
||||
auto&& h = d->m_header;
|
||||
if (h.isValid()) {
|
||||
v = QVariant::fromValue(h.format());
|
||||
} else if (auto d = device()) {
|
||||
if (h.peek(d)) {
|
||||
v = QVariant::fromValue(h.format());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
QImageIOPlugin::Capabilities PXRPlugin::capabilities(QIODevice *device, const QByteArray &format) const
|
||||
{
|
||||
if (format == "pxr") {
|
||||
return Capabilities(CanRead);
|
||||
}
|
||||
if (!format.isEmpty()) {
|
||||
return {};
|
||||
}
|
||||
if (!device->isOpen()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
Capabilities cap;
|
||||
if (device->isReadable() && PXRHandler::canRead(device)) {
|
||||
cap |= CanRead;
|
||||
}
|
||||
return cap;
|
||||
}
|
||||
|
||||
QImageIOHandler *PXRPlugin::create(QIODevice *device, const QByteArray &format) const
|
||||
{
|
||||
QImageIOHandler *handler = new PXRHandler;
|
||||
handler->setDevice(device);
|
||||
handler->setFormat(format);
|
||||
return handler;
|
||||
}
|
||||
|
||||
#include "moc_pxr_p.cpp"
|
||||