Kstars

imagemask.h
1/*
2 SPDX-FileCopyrightText: 2023 Wolfgang Reissenberger <sterne-jaeger@openfuture.de>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7
8#pragma once
9
10#include <stdint.h>
11#include <QRect>
12#include <QVector>
13
14class ImageMask
15{
16public:
17 /**
18 * @brief ImageMask Create an image mask with image dimensions
19 * @param width image width
20 * @param height image height
21 */
22 ImageMask(const uint16_t width=0, const uint16_t height=0);
23 virtual ~ImageMask(){};
24
25 /**
26 * @brief setImageGeometry set the image geometry
27 * @param width image width
28 * @param height image height
29 */
30 virtual void setImageGeometry(const uint16_t width, const uint16_t height);
31
32 /**
33 * @brief isVisible test if the given position is visible
34 * @return in this basic version, a point is visible as long as it lies
35 * within the image dimensions
36 */
37 virtual bool isVisible(uint16_t posX, uint16_t posY);
38
39 /**
40 * @brief translate which position on the frame has a point after masking
41 * @param original point to be translated
42 * @return same position as on the original image
43 */
44 QPointF translate(QPointF original) { return original; }
45
46 /**
47 * @brief active is the mask active (pure virtual)
48 */
49 virtual bool active() = 0;
50
51 uint16_t width() const;
52
53 uint16_t height() const;
54
55protected:
56 uint16_t m_width, m_height;
57
58 virtual void refresh() = 0;
59};
60
61class ImageRingMask : public ImageMask
62{
63public:
64 /**
65 * @brief ImageRingMask Create an image mask with a ring form
66 * @param innerRadius inner ring radius in percent
67 * @param outerRadius outer ring radius in percent
68 * @param width image width
69 * @param height image height
70 */
71 ImageRingMask(const float innerRadius=0, const float outerRadius=1, const uint16_t width=0, const uint16_t height=0);
72
73 virtual ~ImageRingMask() {};
74
75 /**
76 * @brief isVisible test if the given position is visible
77 * @return check if the position is inside the outer radius and outside the inner radius
78 */
79 bool isVisible(uint16_t posX, uint16_t posY) override;
80
81 /**
82 * @brief active The mask is active if either the inner radius > 0% or the outer radius < 100%
83 */
84 bool active() override { return m_width > 0 && m_height > 0 && (m_innerRadius > 0 || m_outerRadius < 1.0); };
85
86 float innerRadius() const;
87 void setInnerRadius(float newInnerRadius);
88
89 float outerRadius() const;
90 void setOuterRadius(float newOuterRadius);
91
92protected:
93 // mask radius in percent of image diagonal
94 float m_innerRadius {0};
95 float m_outerRadius {1.0};
96 // cached values for fast visibility calculation
97 long m_InnerRadiusSquare, m_OuterRadiusSquare;
98 // re-calculate the cached squares
99 virtual void refresh() override;
100};
101
102class ImageMosaicMask : public ImageMask
103{
104public:
105 /**
106 * @brief ImageMosaicMask Creates a 3x3 mosaic mask
107 * @param tileWidth width of a single mosaic tile (in percent of the image width)
108 * @param space space between the mosaic tiles
109 * @param width source image width
110 * @param height source image height
111 */
112 ImageMosaicMask (const uint16_t tileWidth, const uint16_t space, const uint16_t width=0, const uint16_t height=0);
113
114 /**
115 * @brief isVisible test if the given position is visible
116 * @return check if the position is inside one of the tiles
117 */
118 virtual bool isVisible(uint16_t posX, uint16_t posY) override;
119
120 /**
121 * @brief translate Calculate the new position of a point inside of the mosaic
122 * @param original original position
123 * @return position inside the mosaic
124 */
125 QPointF translate(QPointF original);
126
127 /**
128 * @brief active The mask is active if the mosaic raster is present
129 */
130 bool active() override { return m_width > 0 && m_height > 0 && m_tiles.length() > 0; };
131
132 const QVector<QRect> tiles();
133
134 float tileWidth() const;
135 void setTileWidth(float newTileWidth);
136
137 uint16_t space() const;
138 void setSpace(uint16_t newSpace);
139
140
141protected:
142 // width of a single mosaic tile (in percent of the image width)
143 float m_tileWidth;
144 // space between the mosaic tiles
145 uint16_t m_space;
146 // 3x3 mosaic raster, sorted linewise top down
147 QVector<QRect> m_tiles;
148 // re-calculate the tiles
149 virtual void refresh() override;
150};
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.