|
Krita Source Code Documentation
|
#include <kis_gap_map.h>
Inheritance diagram for KisGapMap:Classes | |
| struct | Data |
Public Types | |
| typedef std::function< bool(KisPaintDevice *devicePtr, const QRect &rect) | FillOpacityFunc) |
Public Member Functions | |
| ALWAYS_INLINE quint16 | distance (int x, int y) |
| ALWAYS_INLINE int | gapSize () const |
| template<bool BoundsCheck> | |
| bool | isOpaque (const QPoint &p) |
| template<bool BoundsCheck> | |
| bool | isOpaque (int x, int y) |
| KisGapMap (int gapSize, const QRect &mapBounds, const FillOpacityFunc &fillOpacityFunc) | |
Public Member Functions inherited from KisShared | |
| bool | deref () |
| bool | ref () |
| int | refCount () |
| QAtomicInt * | sharedWeakReference () |
Static Public Attributes | |
| static constexpr quint16 | DISTANCE_INFINITE = UINT16_MAX |
Private Types | |
| enum | TileFlagBits { TILE_DISTANCE_LOADED = 0x1 , TILE_OPACITY_LOADED = 0x2 , TILE_HAS_OPAQUE_PIXELS = 0x4 } |
| typedef quint8 | TileFlags |
Private Member Functions | |
| ALWAYS_INLINE Data * | dataPtr (int x, int y) |
| void | distanceSearchRowInnerLoop (bool boundsCheck, int y, int x1, int x2) |
| template<bool BoundsCheck, typename CoordinateTransform > | |
| void | gapDistanceSearch (int x, int y, CoordinateTransform op) |
| ALWAYS_INLINE bool | isDistanceAvailable (int x, int y) |
| template<bool BoundsCheck> | |
| ALWAYS_INLINE bool | isOpaque (const QPoint &p) |
| template<bool BoundsCheck> | |
| ALWAYS_INLINE bool | isOpaque (int x, int y) |
| quint16 | lazyDistance (int x, int y) |
| void | loadDistanceTile (const QPoint &tile, const QRect &nearbyTilesRect, int guardBand) |
| void | loadOpacityTiles (const QRect &tileRect) |
| Q_DISABLE_COPY (KisGapMap) | |
| ALWAYS_INLINE TileFlags * | tileFlagsPtr (int tileX, int tileY) |
| void | updateDistance (const QPoint &globalPosition, quint16 newDistance) |
Private Attributes | |
| std::unique_ptr< KisTileOptimizedAccessor > | m_accessor |
| An accessor for the paint device. | |
| KisPaintDeviceSP | m_deviceSp |
| A 32-bit per pixel paint device that holds the distance and other data. | |
| const FillOpacityFunc | m_fillOpacityFunc |
| A callback to get the opacity data from the fill class. | |
| const int | m_gapSize |
| Gap size in pixels for this map. | |
| const QSize | m_numTiles |
| Map size in tiles. | |
| const QSize | m_size |
| Size in pixels of the opacity/gap map. | |
| Data * | m_tileDataPtr |
| The pointer to the currently computed tile data. | |
| QPoint | m_tilePosition |
| The position of the currently computed tile compared to the whole region. | |
Static Private Attributes | |
| static constexpr int | TileSize = 64 |
Additional Inherited Members | |
Protected Member Functions inherited from KisShared | |
| KisShared () | |
| ~KisShared () | |
Creates a "gap map", which is a pixel map of distances from lineart gaps (discontinuities in opaque lines), that helps detect these gaps and stop a bucket fill before spilling.
Definition at line 80 of file kis_gap_map.h.
| typedef std::function<bool(KisPaintDevice* devicePtr, const QRect& rect) KisGapMap::FillOpacityFunc) |
A callback to request opacity data for pixels in the image. It can be called at any time distance() function is invoked.
| devicePtr | our underlying paint device, it contains opacity among other data. For each pixel, the offset of opacity quint8 data is 2 bytes. |
| rect | the bounds within the fill region (image) that are requested. |
Definition at line 94 of file kis_gap_map.h.
|
private |
Definition at line 150 of file kis_gap_map.h.
|
private |
| Enumerator | |
|---|---|
| TILE_DISTANCE_LOADED | Distance data is available. |
| TILE_OPACITY_LOADED | Opacity data is available. |
| TILE_HAS_OPAQUE_PIXELS | Some pixels of the loaded tile are opaque. |
Definition at line 151 of file kis_gap_map.h.
| KisGapMap::KisGapMap | ( | int | gapSize, |
| const QRect & | mapBounds, | ||
| const FillOpacityFunc & | fillOpacityFunc ) |
Create a new gap distance map object and prepare it for lazy initialization. Some memory allocation will happen upfront, but most of the calculations are deferred until distance() function is called.
| gapSize | maximum size of lineart gap to look for. |
| mapBounds | must begin in (0,0) and must have the same size as the filled region. |
| fillOpacityFunc | a callback to obtain the opacity of pixels |
Definition at line 89 of file kis_gap_map.cpp.
References KisGapMap::Data::distance, DISTANCE_INFINITE, KisPaintDevice::fill(), KoColorSpaceRegistry::instance(), KIS_ASSERT, m_deviceSp, MAX_SELECTED, and KisPaintDevice::setDefaultPixel().
|
inlineprivate |
Definition at line 186 of file kis_gap_map.h.
|
inline |
Query the gap distance at a pixel. (x, y) are the filled region's coordinates, always starting at (0, 0).
Important: This function is not thread-safe.
Definition at line 113 of file kis_gap_map.h.
|
private |
This is a part of loadDistanceTile() implementation.
Definition at line 147 of file kis_gap_map.cpp.
|
private |
Update the distance map in an octant (a 45-degree sector of a half-circle) originating from the (x, y) point.
Important: The radius of the right half-circle is equal to the (gap size) for distance map, and the (gap size + 1) for the opacity map.
Which octant is used depends on the transform function. With 0 degrees being the -y axis (up): 0-45 deg - TransformNone 45-90 deg - TransformRotateClockwiseMirrorHorizontally 90-135 deg - TransformRotateClockwise 135-180 deg - TransformMirrorHorizontally
This function is a bit tricky to reason about:
Definition at line 281 of file kis_gap_map.cpp.
References m_gapSize, and updateDistance().
|
inline |
Definition at line 122 of file kis_gap_map.h.
|
inlineprivate |
Definition at line 181 of file kis_gap_map.h.
| bool KisGapMap::isOpaque | ( | const QPoint & | p | ) |
|
private |
| bool KisGapMap::isOpaque | ( | int | x, |
| int | y ) |
Definition at line 63 of file kis_gap_map.cpp.
References dataPtr(), KIS_SAFE_ASSERT_RECOVER, m_size, MIN_SELECTED, KisGapMap::Data::opacity, TILE_OPACITY_LOADED, tileFlagsPtr(), and TileSize.
|
private |
|
private |
Load the required tiles and return pixel's distance data.
Definition at line 334 of file kis_gap_map.cpp.
References dataPtr(), KisGapMap::Data::distance, loadDistanceTile(), loadOpacityTiles(), m_gapSize, m_numTiles, and TileSize.
|
private |
Calculate the gap distance data in the specified rect. NOTE: Opacity data must have been loaded already.
If the rect is smaller than the whole fill region, then the guardBand is needed and must be at least equal to the gap size. We need to do calculations in a larger region in order to compute correct distances within the requested rect.
Definition at line 180 of file kis_gap_map.cpp.
References distanceSearchRowInnerLoop(), m_accessor, m_gapSize, m_size, m_tileDataPtr, m_tilePosition, TILE_DISTANCE_LOADED, TILE_HAS_OPAQUE_PIXELS, tileFlagsPtr(), and TileSize.
|
private |
Definition at line 113 of file kis_gap_map.cpp.
References KisSharedPtr< T >::data(), m_deviceSp, m_fillOpacityFunc, m_size, TILE_HAS_OPAQUE_PIXELS, TILE_OPACITY_LOADED, tileFlagsPtr(), and TileSize.
|
private |
|
inlineprivate |
Definition at line 191 of file kis_gap_map.h.
|
private |
Definition at line 319 of file kis_gap_map.cpp.
References KisGapMap::Data::distance, m_tileDataPtr, m_tilePosition, p, and TileSize.
|
staticconstexpr |
A magic number to express a pixel that is very far from any gaps.
Definition at line 84 of file kis_gap_map.h.
|
private |
An accessor for the paint device.
Definition at line 206 of file kis_gap_map.h.
|
private |
A 32-bit per pixel paint device that holds the distance and other data.
Definition at line 205 of file kis_gap_map.h.
|
private |
A callback to get the opacity data from the fill class.
Definition at line 200 of file kis_gap_map.h.
|
private |
Gap size in pixels for this map.
Definition at line 197 of file kis_gap_map.h.
|
private |
Map size in tiles.
Definition at line 199 of file kis_gap_map.h.
|
private |
Size in pixels of the opacity/gap map.
Definition at line 198 of file kis_gap_map.h.
|
private |
The pointer to the currently computed tile data.
Definition at line 203 of file kis_gap_map.h.
|
private |
The position of the currently computed tile compared to the whole region.
Definition at line 202 of file kis_gap_map.h.
|
staticconstexprprivate |
For the purpose of lazy loading, the data is fetched in tile increments.
Definition at line 148 of file kis_gap_map.h.