Perceptual Color

interlacingpass.cpp
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4// Own header
5#include "interlacingpass.h"
6
7#include "helpermath.h"
8#include <qglobal.h>
9#include <qmath.h>
10#include <type_traits>
11
12namespace PerceptualColor
13{
14/** @brief Constructor
15 *
16 * Constructs an object for a new interlacing cycle.
17 *
18 * @param passCount Number of passes within this interlacing cycle. This MUST
19 * be a positive odd number (otherwise an exception is thrown). Use <tt>7</tt>
20 * for <a href="https://en.wikipedia.org/wiki/Adam7_algorithm">Adam7</a>
21 * interlacing, or any other positive odd number for
22 * <a href="https://en.wikipedia.org/wiki/Adam7_algorithm">Adam7</a>-like
23 * interlacing, but with a different number of steps.
24 *
25 * @exception int Thrown when the parameter is not a positive odd number. */
26InterlacingPass::InterlacingPass(const int passCount)
27{
28 if (!isOdd(passCount)) {
29 throw 0;
30 }
31 if (passCount < 1) {
32 throw 0;
33 }
34
35 const int floorOfHalfCoundown = qFloor(passCount / 2.0);
36 const int baseSize = qRound(qPow(2, floorOfHalfCoundown));
37
38 countdown = passCount;
39 rectangleSize.setWidth(baseSize);
40 rectangleSize.setHeight(baseSize);
41 columnFrequency = baseSize;
42 columnOffset = 0;
43 lineFrequency = baseSize;
44 lineOffset = 0;
45}
46
47/** @brief Switches to the next pass, reducing @ref countdown by 1 and
48 * changing all other values accordingly.
49 *
50 * If @ref countdown ≤ 0 than nothing happens. */
51void InterlacingPass::switchToNextPass()
52{
53 if (countdown <= 1) {
54 return;
55 }
56
57 countdown--;
58
59 const int floorOfHalfCoundown = qFloor(countdown / 2.0);
60 const int baseSize = qRound(qPow(2, floorOfHalfCoundown));
61
62 if (isOdd(countdown)) {
63 rectangleSize.setWidth(baseSize);
64 rectangleSize.setHeight(baseSize);
65 columnFrequency = baseSize;
66 columnOffset = 0;
67 lineFrequency = baseSize * 2;
68 lineOffset = baseSize;
69 } else {
70 const int halfBaseSize = baseSize / 2; // Dividing without rounding
71 // problems because baseSize is always an even number (it’s always
72 // a power of two and bigger than 2 while countdown is ≥ 1).
73 rectangleSize.setWidth(halfBaseSize);
74 rectangleSize.setHeight(baseSize);
75 columnFrequency = baseSize;
76 columnOffset = halfBaseSize;
77 lineFrequency = baseSize;
78 lineOffset = 0;
79 }
80}
81
82static_assert(std::is_trivially_copyable_v<InterlacingPass>);
83
84static_assert(std::is_standard_layout_v<InterlacingPass>);
85
86} // namespace PerceptualColor
The namespace of this library.
void setHeight(int height)
void setWidth(int width)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:48:43 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.