Perceptual Color

asyncimagerendercallback.h
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4#ifndef ASYNCIMAGERENDERCALLBACK_H
5#define ASYNCIMAGERENDERCALLBACK_H
6
7#include <qglobal.h>
8#include <qmetatype.h>
9
10class QImage;
11class QVariant;
12
13namespace PerceptualColor
14{
15/** @internal
16 *
17 * @brief Interface for @ref AsyncImageRenderThread::pointerToRenderFunction
18 * to make callbacks. */
19class AsyncImageRenderCallback
20{
21public:
22 virtual ~AsyncImageRenderCallback() noexcept;
23
24 /** @brief Describes the interlacing state of an image.
25 *
26 * This enum is <em>not</em> declared to the meta-object system.
27 *
28 * This type is declared as type to Qt’s type system via
29 * <tt>Q_DECLARE_METATYPE</tt>. Depending on your use case (for
30 * example if you want to use for <em>queued</em> signal-slot connections),
31 * you might consider calling <tt>qRegisterMetaType()</tt> for
32 * this type, once you have a QApplication object. */
33 // Q_ENUM can only be used within classes that have the Q_OBJECT macro,
34 // which this class template does not have, because we want to avoid
35 // conflicts when doing multiple inheritance with this class.
36 // Tough the Qt documentation allows using Q_ENUM with Q_GADGET instead
37 // of Q_OBJECT, in practice it does not work: It compiles without warnings
38 // or errors, but the meta type is nevertheless not registered and
39 // not available for signals and slots. Therefore, we do not use Q_ENUM
40 // here.
41 enum class InterlacingState {
42 Intermediate, /**< The image represents
43 an intermediate interlacing result. */
44 Final /**< The image represents the final image in full quality.
45 No further interlacing passes will happen. */
46 };
47
48 /** @brief Deliver the result of an interlacing pass of
49 * the <em>rendering</em> operation.
50 *
51 * This function is thread-safe.
52 *
53 * @param image The image
54 * @param parameters The parameters of the image
55 * @param state The interlacing state of the image. A render function
56 * must first return zero or more images with intermediate state. After
57 * that, it must return exactly one image with final state (unless it
58 * was aborted). After that, it must not return any more images. */
59 virtual void deliverInterlacingPass(const QImage &image, const QVariant &parameters, const InterlacingState state) = 0;
60
61 /** @brief If the render function should abort.
62 *
63 * This function is thread-safe.
64 *
65 * @returns <tt>true</tt> if the render function should abort and
66 * return. <tt>false</tt> otherwise. */
67 [[nodiscard]] virtual bool shouldAbort() const = 0;
68
69protected:
70 AsyncImageRenderCallback() = default;
71
72private:
73 Q_DISABLE_COPY(AsyncImageRenderCallback)
74};
75
76} // namespace PerceptualColor
77
78Q_DECLARE_METATYPE(PerceptualColor::AsyncImageRenderCallback::InterlacingState)
79
80#endif // ASYNCIMAGERENDERCALLBACK_H
The namespace of this library.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:17 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.