summaryrefslogtreecommitdiffstats
path: root/chalk/core/tiles/kis_tile.h
blob: 2a0b3a2280327f4e4090b5b2c0b1408fe142b53d (plain)
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
/*
 *  Copyright (c) 2004 Casper Boemann <[email protected]>
 *
 *  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; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  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_TILE_H_
#define KIS_TILE_H_

#include <tqglobal.h>
#include <tqrect.h>

class KisTiledDataManager;
class KisTiledIterator;

/**
 * Provides abstraction to a tile.  A tile contains
 * a part of a PaintDevice, but only the individual pixels
 * are accesable and that only via iterators.
 */
class KisTile  {
public:
    KisTile(TQ_INT32 pixelSize, TQ_INT32 col, TQ_INT32 row, const TQ_UINT8 *defPixel);
    KisTile(const KisTile& rhs, TQ_INT32 col, TQ_INT32 row);
    KisTile(const KisTile& rhs);
    ~KisTile();

public:
    void release();
    void allocate();

    TQ_UINT8 *data(TQ_INT32 xoff, TQ_INT32 yoff) const;
    TQ_UINT8 *data() const { return m_data; }

    void setData(const TQ_UINT8 *pixel);

    TQ_INT32 refCount() const;
    void ref();

    TQ_INT32 getRow() const { return m_row; }
    TQ_INT32 getCol() const { return m_col; }

    TQRect extent() const { return TQRect(m_col * WIDTH, m_row * HEIGHT, WIDTH, HEIGHT); }

    void setNext(KisTile *);
    KisTile *getNext() const { return m_nextTile; }

    // These are const because they don't change the external data the tile represents,
    // although they do change internal representations. We need to be able to request
    // access to a tile in a const enviroment (like copyconstructor and so)!
    void addReader() const;
    void removeReader() const;
    TQ_INT32 readers() { return m_nReadlock; }

    friend class KisTiledIterator;
    friend class KisTiledDataManager;
    friend class KisMemento;
    friend class KisTileManager;
private:
    KisTile& operator=(const KisTile&);

private:
    TQ_UINT8 *m_data;
    mutable TQ_INT32 m_nReadlock;
    TQ_INT32 m_row;
    TQ_INT32 m_col;
    TQ_INT32 m_pixelSize;
    KisTile *m_nextTile;

public:
    static const TQ_INT32 WIDTH;
    static const TQ_INT32 HEIGHT;
};

#endif // KIS_TILE_H_