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 mask The alpha mask, if provided. Renderers may choose whether
55 * to supply an alpha mask. Alpha masks are 1-bit images where white
56 * represents transparency and black represents opacity, defining the
57 * transparency state <i>before</i> any anti-aliasing is applied. This
58 * differs from the potentially anti-aliased image itself, which may
59 * contain partial transparency, making it difficult to determine the
60 * original transparency before anti-aliasing. Typically, fully transparent
61 * pixels will have an alpha value greater than 50% after anti-aliasing,
62 * but in some cases, they may fall below this threshold. The alpha mask,
63 * however, provides a clear and definitive indication of each pixel’s
64 * validity.
65 * @param parameters The parameters of the image
66 * @param state The interlacing state of the image. A render function
67 * must first return zero or more images with intermediate state. After
68 * that, it must return exactly one image with final state (unless it
69 * was aborted). After that, it must not return any more images. */
70 virtual void deliverInterlacingPass(const QImage &image, const QImage &mask, const QVariant &parameters, const InterlacingState state) = 0;
71
72 /** @brief If the render function should abort.
73 *
74 * This function is thread-safe.
75 *
76 * @returns <tt>true</tt> if the render function should abort and
77 * return. <tt>false</tt> otherwise. */
78 [[nodiscard]] virtual bool shouldAbort() const = 0;
79
80protected:
81 AsyncImageRenderCallback() = default;
82
83private:
84 Q_DISABLE_COPY(AsyncImageRenderCallback)
85};
86
87} // namespace PerceptualColor
88
89Q_DECLARE_METATYPE(PerceptualColor::AsyncImageRenderCallback::InterlacingState)
90
91#endif // ASYNCIMAGERENDERCALLBACK_H
The namespace of this library.
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 25 2025 12:03:13 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.