Changeset View
Changeset View
Standalone View
Standalone View
libs/image/KisPrecisePaintDeviceWrapper.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2018 Dmitry Kazakov <dimula73@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #ifndef KISPRECISEPAINTDEVICEWRAPPER_H | ||||
20 | #define KISPRECISEPAINTDEVICEWRAPPER_H | ||||
21 | | ||||
22 | #include <QScopedPointer> | ||||
23 | | ||||
24 | #include "kis_types.h" | ||||
25 | #include "kritaimage_export.h" | ||||
26 | | ||||
27 | class KoColorSpace; | ||||
28 | class QRegion; | ||||
29 | | ||||
30 | /** | ||||
31 | * A special wrapper class for a paint device that allows working with | ||||
32 | * parts of the source paint device as if it had higher bit depth. | ||||
33 | * | ||||
34 | * For example, you have an RGBA8 paint device, but you want all the | ||||
35 | * blending happen in higher bit depth. You wrap your paint device (source paint | ||||
36 | * device) into KisPrecisePaintDeviceWrapper, and the wrapper creates a temporary | ||||
37 | * device (precise paint device) in RGBA16 colorspace. The you work with this precise | ||||
38 | * paint device as usual, uploading and downloading pixel data to/from the source | ||||
39 | * paint device using readRect() and writeRect() | ||||
40 | * | ||||
41 | * If the source device is already "precise", that is having the bit depth higher than | ||||
42 | * 8 bit per channel, no temporary device is created. All the operations are forwarded | ||||
43 | * directly to the source device | ||||
44 | * | ||||
45 | * Example: | ||||
46 | * | ||||
47 | * \code{.cpp} | ||||
48 | * // initialize the wrapper with the source device, | ||||
49 | * // it creates a precise device if needed | ||||
50 | * KisPrecisePaintDeviceWrapper wrapper(sourceDevice); | ||||
51 | * | ||||
52 | * // download the data from the source device, the operation | ||||
53 | * // might be cached due to keepRectsHistory option | ||||
54 | * wrapper.readRect(accessRect); | ||||
55 | * | ||||
56 | * // start modifying the data | ||||
57 | * KisPainter gc(wrapper.preciseDevice()); | ||||
58 | * | ||||
59 | * // low opacity might be handled incorrectly in the original | ||||
60 | * // color space, but we work in a precise one! | ||||
61 | * gc.setOpacity(1); | ||||
62 | * gc.bitBlt(accessRect.topLeft(), someOtherDevice, accessRect); | ||||
63 | * | ||||
64 | * // ... repeat multiple times if needed ... | ||||
65 | * | ||||
66 | * // upload the data back to the original source device | ||||
67 | * wrapper.writeRect(accessRect); | ||||
68 | * \endcode | ||||
69 | * | ||||
70 | */ | ||||
71 | | ||||
72 | class KRITAIMAGE_EXPORT KisPrecisePaintDeviceWrapper | ||||
73 | { | ||||
74 | public: | ||||
75 | /** | ||||
76 | * Create a wrapper, attach it to \p device and create a temporary precise | ||||
77 | * paint device if needed. The temporary device is created iff the source | ||||
78 | * device has 8 bit bit-depth. | ||||
79 | * | ||||
80 | * \param device source device | ||||
81 | * \param keepRectsHistory shown how many rects in readRect() should be cached | ||||
82 | */ | ||||
83 | KisPrecisePaintDeviceWrapper(KisPaintDeviceSP device, int keepRectsHistory = 50); | ||||
84 | ~KisPrecisePaintDeviceWrapper(); | ||||
85 | | ||||
86 | /** | ||||
87 | * \return the color space of preciseDevice() | ||||
88 | */ | ||||
89 | const KoColorSpace* preciseColorSpace() const; | ||||
90 | | ||||
91 | /** | ||||
92 | * \return the source device attached to the wrapper | ||||
93 | */ | ||||
94 | KisPaintDeviceSP sourceDevice() const; | ||||
95 | | ||||
96 | /** | ||||
97 | * \return the precise device. If the source device color space is "precise", then | ||||
98 | * there is no separate precise device, and the original device is returned | ||||
99 | */ | ||||
100 | KisPaintDeviceSP preciseDevice() const; | ||||
101 | | ||||
102 | /** | ||||
103 | * \return the region of the source device that is guaranteed to be cached by | ||||
104 | * previous calls to readRect(). If one asks for reading a cached rect, | ||||
105 | * it is not read and just reused. | ||||
106 | */ | ||||
107 | QRegion cachedRegion() const; | ||||
108 | | ||||
109 | /** | ||||
110 | * Reset the region of the cached data from the source paint device | ||||
111 | */ | ||||
112 | void resetCachedRegion(); | ||||
113 | | ||||
114 | /** | ||||
115 | * Read rect \p rc from the source device and upload it into the precision device. | ||||
116 | * If rounding correction is not used, the function does nothing. | ||||
117 | */ | ||||
118 | void readRect(const QRect &rc); | ||||
119 | | ||||
120 | /** | ||||
121 | * Write rect \p rc from the precision to source device | ||||
122 | * If rounding correction is not used, the function does nothing. | ||||
123 | */ | ||||
124 | void writeRect(const QRect &rc); | ||||
125 | | ||||
126 | /** | ||||
127 | * \see readRect() | ||||
128 | */ | ||||
129 | void readRects(const QVector<QRect> &rects); | ||||
130 | | ||||
131 | /** | ||||
132 | * \see writeRect() | ||||
133 | */ | ||||
134 | void writeRects(const QVector<QRect> &rects); | ||||
135 | | ||||
136 | private: | ||||
137 | struct Private; | ||||
138 | const QScopedPointer<Private> m_d; | ||||
139 | }; | ||||
140 | | ||||
141 | #endif // KISPRECISEPAINTDEVICEWRAPPER_H |