From a3392513e316c33ee084802d418a792bd62fb2b0 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Sat, 4 Jul 2020 22:51:42 +0800 Subject: [PATCH] init commit --- .gitignore | 5 +++ .gitmodules | 3 ++ CMakeLists.txt | 14 +++++++++ imageformats/CMakeLists.txt | 17 +++++++++++ imageformats/sai.cpp | 61 +++++++++++++++++++++++++++++++++++++ imageformats/sai.json | 4 +++ imageformats/sai_p.h | 25 +++++++++++++++ vendor/libsai | 1 + 8 files changed, 130 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 imageformats/CMakeLists.txt create mode 100644 imageformats/sai.cpp create mode 100644 imageformats/sai.json create mode 100644 imageformats/sai_p.h create mode 160000 vendor/libsai diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5784eda --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# build +build/ + +# user files +*.user diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a86dbeb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/libsai"] + path = vendor/libsai + url = https://github.com/Wunkolo/libsai diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e1b77ee --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +project (pimageformats) + +cmake_minimum_required (VERSION 3.9.5) + +include (GNUInstallDirs) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(QT_MINIMUM_VERSION "5.10") + +find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Gui) + +add_subdirectory(vendor/libsai) +add_subdirectory(imageformats) diff --git a/imageformats/CMakeLists.txt b/imageformats/CMakeLists.txt new file mode 100644 index 0000000..248e1e4 --- /dev/null +++ b/imageformats/CMakeLists.txt @@ -0,0 +1,17 @@ +set (plugin pimg_sai) + +set (PLUGIN_SOURCES + sai_p.h + sai.cpp +) + +# {{{ KCM style +set(CMAKE_SHARED_MODULE_PREFIX "") +unset(CMAKE_LIBRARY_OUTPUT_DIRECTORY) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") +# }}} + +add_library(${plugin} MODULE ${PLUGIN_SOURCES}) +set_property(TARGET ${plugin} APPEND PROPERTY AUTOGEN_TARGET_DEPENDS "sai.json") +set_target_properties(${plugin} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/imageformats") +target_link_libraries(${plugin} Qt5::Gui sai) diff --git a/imageformats/sai.cpp b/imageformats/sai.cpp new file mode 100644 index 0000000..f55aaa1 --- /dev/null +++ b/imageformats/sai.cpp @@ -0,0 +1,61 @@ +#include "sai_p.h" + +#include "sai.hpp" + +SAIHandler::SAIHandler() +{ + +} + +bool SAIHandler::canRead() const +{ + if (canRead(device())) { + setFormat("sai"); + return true; + } + return false; +} + +bool SAIHandler::read(QImage *image) +{ + Q_UNUSED(image) + return false; +} + +bool SAIHandler::write(const QImage &image) +{ + Q_UNUSED(image) + return false; +} + +bool SAIHandler::canRead(QIODevice *device) +{ + if (!device) { + qWarning("SAIHandler::canRead() called with no device"); + return false; + } + + // FIXME: check + return true; +} + +QImageIOPlugin::Capabilities SAIPlugin::capabilities(QIODevice *device, const QByteArray &format) const +{ + if (!format.isEmpty()) { + return {}; + } + + if (!device->isOpen()) { + return {}; + } + + return Capabilities(CanRead); +} + +QImageIOHandler *SAIPlugin::create(QIODevice *device, const QByteArray &format) const +{ + QImageIOHandler *handler = new SAIHandler; + handler->setDevice(device); + handler->setFormat(format); + return handler; +} diff --git a/imageformats/sai.json b/imageformats/sai.json new file mode 100644 index 0000000..612553d --- /dev/null +++ b/imageformats/sai.json @@ -0,0 +1,4 @@ +{ + "Keys": [ "sai" ], + "MimeTypes": [] +} diff --git a/imageformats/sai_p.h b/imageformats/sai_p.h new file mode 100644 index 0000000..28cb0e0 --- /dev/null +++ b/imageformats/sai_p.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +class SAIHandler : public QImageIOHandler +{ +public: + SAIHandler(); + + bool canRead() const override; + bool read(QImage *image) override; + bool write(const QImage &image) override; + + static bool canRead(QIODevice *device); +}; + +class SAIPlugin : public QImageIOPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QImageIOHandlerFactoryInterface" FILE "sai.json") + +public: + Capabilities capabilities(QIODevice *device, const QByteArray &format) const override; + QImageIOHandler *create(QIODevice *device, const QByteArray &format = QByteArray()) const override; +}; diff --git a/vendor/libsai b/vendor/libsai new file mode 160000 index 0000000..607ec7a --- /dev/null +++ b/vendor/libsai @@ -0,0 +1 @@ +Subproject commit 607ec7acb817b52a4d2bc2682fcd07c0a78b4f19