Perceptual Color

interlacingpass.h
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4#ifndef InterlacingPass_H
5#define InterlacingPass_H
6
7#include "helpermath.h"
8#include <qsize.h>
9
10namespace PerceptualColor
11{
12/** @internal
13 *
14 * @brief Describes an interlacing pass.
15 *
16 * Objects of this class provide information about interlacing passes
17 * for <a href="https://en.wikipedia.org/wiki/Adam7_algorithm">Adam7</a>-like
18 * interlacing.
19 *
20 * To do <a href="https://en.wikipedia.org/wiki/Adam7_algorithm">Adam7</a>
21 * interlacing, construct an object of this class with a <tt>passCount</tt>
22 * of <tt>7</tt>. Do the first pass using the values provided
23 * by this object. Then, call @ref switchToNextPass to update the
24 * values and do the next interlacing pass.
25 *
26 * The pixels in your image are divided in lines, who in turn are subdivided
27 * in columns. Within each interlacing pass, go through every
28 * @ref lineFrequency th line, starting with the line at @ref lineOffset.
29 * Within each line, go through every @ref columnFrequency th column, starting
30 * with @ref columnOffset. Draw a rectangle with the size @ref rectangleSize
31 * who’s top-left pixel is at the current column and line.
32 *
33 * @note As this is just an internal class which is not part of the public API,
34 * there is direct access to its data members for simplicity reasons. However,
35 * it is not allowed to change them directly! Use them read-only. */
36class InterlacingPass final
37{
38public:
39 explicit InterlacingPass(const double passCount);
40
41 /**
42 * @brief Factory constructor
43 *
44 * Constructs an object for a new interlacing cycle.
45 *
46 * @tparam passCount Number of passes within this interlacing
47 * cycle. Use <tt>7</tt>
48 * for <a href="https://en.wikipedia.org/wiki/Adam7_algorithm">Adam7</a>
49 * interlacing, or any other positive odd number for
50 * <a href="https://en.wikipedia.org/wiki/Adam7_algorithm">Adam7</a>-like
51 * interlacing, but with a different number of steps.
52 * The value must be an integer type, a <tt>constexpr</tt> and
53 * a positive odd number.
54 *
55 * @returns A corresponding object.
56 *
57 * This function checks for valid parameters at compile time.
58 *
59 * @sa @ref InterlacingPass(const double passCount)
60 */
61 template<int passCount>
62 static InterlacingPass make()
63 {
64 static_assert(passCount > 0, "passCount must be positive.");
65 static_assert(isOdd(passCount), "passCount must be odd.");
66 return InterlacingPass(passCount);
67 }
68
69 void switchToNextPass();
70
71 /** @brief Size of the rectangles drawn during this pass. */
72 QSize rectangleSize;
73 /** @brief Draw a rectangle every umpteenth column. */
74 int columnFrequency;
75 /** @brief First column on a given line to draw a rectangle. */
76 int columnOffset;
77 /** @brief Draw a rectangle every umpteenth line. */
78 int lineFrequency;
79 /** @brief First line to process. */
80 int lineOffset;
81 /** @brief Pass countdown.
82 *
83 * Inverse counting of the interlacing passes.
84 *
85 * Example for
86 * <a href="https://en.wikipedia.org/wiki/Adam7_algorithm">Adam7</a>:
87 *
88 * | Pass | @ref countdown |
89 * | :---------- | :------------: |
90 * | 1st | 7 |
91 * | 2nd | 6 |
92 * | 3rd | 5 |
93 * | 4th | 4 |
94 * | 5th | 3 |
95 * | 6th | 2 |
96 * | 7th (last) | 1 | */
97 int countdown;
98
99private:
100 /** @internal @brief Only for unit tests. */
101 friend class TestInterlacingPass;
102
103 [[nodiscard]] static int roundToNearestPositiveOdd(const double value);
104};
105
106} // namespace PerceptualColor
107
108#endif // InterlacingPass_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.