1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/*
* This file is part of the Chalk project
*
* Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_RANDOM_ACCESSOR_H
#define KIS_RANDOM_ACCESSOR_H
#include <ksharedptr.h>
#include <kis_global.h>
class KisTiledRandomAccessor;
typedef KSharedPtr<KisTiledRandomAccessor> KisTiledRandomAccessorSP;
class KisTiledDataManager;
class KisRandomAccessor{
public:
KisRandomAccessor(KisTiledDataManager *ktm, TQ_INT32 x, TQ_INT32 y, TQ_INT32 offsetx, TQ_INT32 offsety, bool writable);
KisRandomAccessor(const KisRandomAccessor& rhs);
~KisRandomAccessor();
public:
/// Move to a given x,y position, fetch tiles and data
void moveTo(TQ_INT32 x, TQ_INT32 y);
TQ_UINT8* rawData() const;
const TQ_UINT8* oldRawData() const;
private:
KisTiledRandomAccessorSP m_accessor;
TQ_INT32 m_offsetx, m_offsety;
};
class KisRandomAccessorPixelTrait {
public:
inline KisRandomAccessorPixelTrait(KisRandomAccessor* underlyingAccessor, KisRandomAccessor* selectionAccessor) : m_underlyingAccessor(underlyingAccessor), m_selectionAccessor(selectionAccessor)
{
}
~KisRandomAccessorPixelTrait() {
if(m_selectionAccessor)
delete m_selectionAccessor;
}
inline bool isSelected() const
{
return (m_selectionAccessor) ? *(m_selectionAccessor->rawData()) > SELECTION_THRESHOLD : true;
};
inline TQ_UINT8 operator[](int index) const
{ return m_underlyingAccessor->rawData()[index]; };
/**
* Returns the degree of selectedness of the pixel.
*/
inline TQ_UINT8 selectedness() const
{
return (m_selectionAccessor) ? *(m_selectionAccessor->rawData()) : MAX_SELECTED;
};
/**
* Returns the selectionmask from the current point; this is guaranteed
* to have the same number of consecutive pixels that the iterator has
* at a given point. It return a 0 if there is no selection.
*/
inline TQ_UINT8 * selectionMask() const
{
return ( m_selectionAccessor ) ? m_selectionAccessor->rawData() : 0;
}
inline void moveTo(TQ_INT32 x, TQ_INT32 y) { if(m_selectionAccessor) m_selectionAccessor->moveTo(x,y); }
private:
KisRandomAccessor* m_underlyingAccessor;
KisRandomAccessor* m_selectionAccessor;
};
class KisRandomAccessorPixel : public KisRandomAccessor, public KisRandomAccessorPixelTrait {
public:
KisRandomAccessorPixel(KisTiledDataManager *ktm, KisTiledDataManager *ktmselect, TQ_INT32 x, TQ_INT32 y, TQ_INT32 offsetx, TQ_INT32 offsety, bool writable);
public:
inline void moveTo(TQ_INT32 x, TQ_INT32 y) { KisRandomAccessor::moveTo(x,y); KisRandomAccessorPixelTrait::moveTo(x,y); }
};
#endif
|