From 8e5052e93380c5d0345cab2a7447364073540a95 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 26 Feb 2022 16:09:13 +0200 Subject: [PATCH] utility to convert from one format to other Signed-off-by: Ivailo Monev --- util/CMakeLists.txt | 1 + util/imgconv/CMakeLists.txt | 19 ++++++++++++++ util/imgconv/README | 1 + util/imgconv/main.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 util/imgconv/CMakeLists.txt create mode 100644 util/imgconv/README create mode 100644 util/imgconv/main.cpp diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 2e1bec09a..f9959839b 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -3,3 +3,4 @@ add_subdirectory(lexgen) add_subdirectory(normalize) add_subdirectory(plugintest) add_subdirectory(qlalr) +add_subdirectory(imgconv) diff --git a/util/imgconv/CMakeLists.txt b/util/imgconv/CMakeLists.txt new file mode 100644 index 000000000..1e73fbee8 --- /dev/null +++ b/util/imgconv/CMakeLists.txt @@ -0,0 +1,19 @@ +# add_definitions() +set(EXTRA_IMGCONV_LIBS KtCore KtGui) + +include_directories( + ${CMAKE_BINARY_DIR}/include + ${CMAKE_BINARY_DIR}/privateinclude + ${CMAKE_BINARY_DIR}/include/QtCore + ${CMAKE_BINARY_DIR}/include/QtGui + ${CMAKE_CURRENT_SOURCE_DIR} +) + +set(IMGCONV_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp +) + +katie_setup_target(imgconv ${IMGCONV_SOURCES}) + +add_executable(imgconv ${imgconv_SOURCES}) +target_link_libraries(imgconv ${EXTRA_IMGCONV_LIBS}) diff --git a/util/imgconv/README b/util/imgconv/README new file mode 100644 index 000000000..4dedabe08 --- /dev/null +++ b/util/imgconv/README @@ -0,0 +1 @@ +This utility will convert any readable image format to any writable format. diff --git a/util/imgconv/main.cpp b/util/imgconv/main.cpp new file mode 100644 index 000000000..7be6e5580 --- /dev/null +++ b/util/imgconv/main.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2022 Ivailo Monev +** +** This file is part of the utils of the Katie Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +QT_USE_NAMESPACE + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + + const QStringList args = app.arguments().mid(1); + if (args.size() != 2) { + qWarning() << "Usage: imgconv "; + return 1; + } + + const QString inputpath(args.at(0)); + QImageReader imagereader(inputpath); + QImage inputimage = imagereader.read(); + if (inputimage.isNull()) { + qWarning() << "Cannot not read" << inputpath << ":" << imagereader.errorString(); + return 2; + } + + const QString outputpath(args.at(1)); + const QFileInfo outputinfo(outputpath); + const QByteArray outputformat(outputinfo.completeSuffix().toLocal8Bit()); + if (outputformat.isEmpty()) { + qWarning() << "Could not determine format for" << outputpath; + return 3; + } + + if (inputimage.save(outputpath, outputformat) == false) { + qWarning() << "Could not save" << outputpath; + return 4; + } + + return 0; +} + -- 2.11.0