File indexing completed on 2025-07-06 04:19:54
0001 // SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com> 0002 // SPDX-License-Identifier: BSD-2-Clause OR MIT 0003 0004 #ifndef ASYNCIMAGERENDERCALLBACK_H 0005 #define ASYNCIMAGERENDERCALLBACK_H 0006 0007 #include <qglobal.h> 0008 #include <qmetatype.h> 0009 0010 class QImage; 0011 class QVariant; 0012 0013 namespace PerceptualColor 0014 { 0015 /** @internal 0016 * 0017 * @brief Interface for @ref AsyncImageRenderThread::pointerToRenderFunction 0018 * to make callbacks. */ 0019 class AsyncImageRenderCallback 0020 { 0021 public: 0022 virtual ~AsyncImageRenderCallback() noexcept; 0023 0024 /** @brief Describes the interlacing state of an image. 0025 * 0026 * This enum is <em>not</em> declared to the meta-object system. 0027 * 0028 * This type is declared as type to Qt’s type system via 0029 * <tt>Q_DECLARE_METATYPE</tt>. Depending on your use case (for 0030 * example if you want to use for <em>queued</em> signal-slot connections), 0031 * you might consider calling <tt>qRegisterMetaType()</tt> for 0032 * this type, once you have a QApplication object. */ 0033 // Q_ENUM can only be used within classes that have the Q_OBJECT macro, 0034 // which this class template does not have, because we want to avoid 0035 // conflicts when doing multiple inheritance with this class. 0036 // Tough the Qt documentation allows using Q_ENUM with Q_GADGET instead 0037 // of Q_OBJECT, in practice it does not work: It compiles without warnings 0038 // or errors, but the meta type is nevertheless not registered and 0039 // not available for signals and slots. Therefore, we do not use Q_ENUM 0040 // here. 0041 enum class InterlacingState { 0042 Intermediate, /**< The image represents 0043 an intermediate interlacing result. */ 0044 Final /**< The image represents the final image in full quality. 0045 No further interlacing passes will happen. */ 0046 }; 0047 0048 /** @brief Deliver the result of an interlacing pass of 0049 * the <em>rendering</em> operation. 0050 * 0051 * This function is thread-safe. 0052 * 0053 * @param image The image 0054 * @param parameters The parameters of the image 0055 * @param state The interlacing state of the image. A render function 0056 * must first return zero or more images with intermediate state. After 0057 * that, it must return exactly one image with final state (unless it 0058 * was aborted). After that, it must not return any more images. */ 0059 virtual void deliverInterlacingPass(const QImage &image, const QVariant ¶meters, const InterlacingState state) = 0; 0060 0061 /** @brief If the render function should abort. 0062 * 0063 * This function is thread-safe. 0064 * 0065 * @returns <tt>true</tt> if the render function should abort and 0066 * return. <tt>false</tt> otherwise. */ 0067 [[nodiscard]] virtual bool shouldAbort() const = 0; 0068 0069 protected: 0070 AsyncImageRenderCallback() = default; 0071 0072 private: 0073 Q_DISABLE_COPY(AsyncImageRenderCallback) 0074 }; 0075 0076 } // namespace PerceptualColor 0077 0078 Q_DECLARE_METATYPE(PerceptualColor::AsyncImageRenderCallback::InterlacingState) 0079 0080 #endif // ASYNCIMAGERENDERCALLBACK_H