summaryrefslogtreecommitdiffstats
path: root/chalk/core/kis_datamanager.h
blob: 79f7ddb8c349c4836590602ead02718d468733b0 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
 *  Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
 *
 *  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_DATAMANAGER_H_
#define KIS_DATAMANAGER_H_

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

class KoStore;


// Change the following two lines to switch (at compiletime) to another datamanager
#include "tiles/kis_tileddatamanager.h"
#define ACTUAL_DATAMGR KisTiledDataManager

/**
 * KisDataManager defines the interface that modules responsible for
 * storing and retrieving data must inmplement. Data modules, like
 * the tile manager, are responsible for:
 *
 * * Storing undo/redo data
 * * Offering ordererd and unordered iterators over rects of pixels
 * * (eventually) efficiently loading and saving data in a format
 * that may allow deferred loading.
 *
 * A datamanager knows nothing about the type of pixel data except
 * how many TQ_UINT8's a single pixel takes.
 */
class KisDataManager : public ACTUAL_DATAMGR {

public:
    KisDataManager(TQ_UINT32 pixelSize, const TQ_UINT8 *defPixel) : ACTUAL_DATAMGR(pixelSize, defPixel) {}
    KisDataManager(const KisDataManager& dm) : ACTUAL_DATAMGR(dm) { }

public:
    /**
     * Sets the default pixel. Note that this might change every occurrance, and it might not, but new data
     * well be initialised with this pixel
     */
    inline void setDefaultPixel(const TQ_UINT8 *defPixel) { return ACTUAL_DATAMGR::setDefaultPixel(defPixel); }

    /**
     * Gets the default pixel.
     */
     inline const TQ_UINT8 *defaultPixel() const { return ACTUAL_DATAMGR::defaultPixel(); }

    /**
     * Reguests a memento from the data manager. There is only one memento active
     * at any given moment for a given paint device and all and any
     * write actions on the datamanger builds undo data into this memento
     * necessary to rollback the transaction.
     */
    inline KisMementoSP getMemento() { return ACTUAL_DATAMGR::getMemento(); }

    /**
     * Restores the image data to the state at the time of the getMemento() call.
     *
     * Note that rollback should be performed with mementos in the reverse order of
     * their creation, as mementos only store incremental changes
     */
    inline void rollback(KisMementoSP memento) { ACTUAL_DATAMGR::rollback(memento); }

    /**
     * Restores the image data to the state at the time of the rollback call of the memento.
     *
     * Note that rollforward must only be called when an rollback have previously been performed, and
     * no intermittent actions have been performed (though it's ok to rollback other mementos and
     * roll them forward again)
     */
    inline void rollforward(KisMementoSP memento) { ACTUAL_DATAMGR::rollforward(memento); }

public:
    /**
     * Reads and writes the tiles from/onto a KoStore (wich is simply a file within a zip file)
     *
     */
    inline bool write(KoStore *store) { return ACTUAL_DATAMGR::write(store); }
    inline bool read(KoStore *store) { return ACTUAL_DATAMGR::read(store); }

public:

    /**
     * Returns the number of bytes a pixel takes
     */
    inline TQ_UINT32 pixelSize() { return ACTUAL_DATAMGR::pixelSize(); }

    /**
     * Return the extent of the data in x,y,w,h.
     */
    inline void extent(TQ_INT32 &x, TQ_INT32 &y, TQ_INT32 &w, TQ_INT32 &h) const
                         { return ACTUAL_DATAMGR::extent(x, y, w, h); }

     TQRect extent() const { return ACTUAL_DATAMGR::extent(); }


public:

    /**
      * Crop or extend the data to x, y, w, h.
      */
    inline void setExtent(TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h)
                         { return ACTUAL_DATAMGR::setExtent(x, y, w, h); }

    inline void setExtent(const TQRect & rect) { setExtent(rect.x(), rect.y(), rect.width(), rect.height()); }

public:

    /**
     * Clear the specified rect to the specified value.
     */
    inline void clear(TQ_INT32 x, TQ_INT32 y,
           TQ_INT32 w, TQ_INT32 h,
           TQ_UINT8 def) { ACTUAL_DATAMGR::clear(x, y, w, h, def); }

    /**
     * Clear the specified rect to the specified pixel value.
     */
    inline void clear(TQ_INT32 x, TQ_INT32 y,
           TQ_INT32 w, TQ_INT32 h,
           const TQ_UINT8 * def) { ACTUAL_DATAMGR::clear(x, y, w, h, def); }

    /**
     * Clear all back to default values.
     */
    inline void clear() { ACTUAL_DATAMGR::clear(); }


public:

    /**
     * Copy the specified rect from the specified data into this
     * data.
     */
    inline void paste(KisDataManagerSP data,  TQ_INT32 sx, TQ_INT32 sy, TQ_INT32 dx, TQ_INT32 dy,
           TQ_INT32 w, TQ_INT32 h) { ACTUAL_DATAMGR::paste(data, sx, sy, dx, dy, w, h); }

public:
    /**
     * Get a read-only pointer to the specified pixel.
     */
    inline KDE_DEPRECATED const TQ_UINT8* pixel(TQ_INT32 x, TQ_INT32 y)
          { return ACTUAL_DATAMGR::pixel(x, y); }

    /**
     * Get a read-write pointer to the specified pixel.
     */
    inline KDE_DEPRECATED TQ_UINT8* writablePixel(TQ_INT32 x, TQ_INT32 y)
          { return ACTUAL_DATAMGR::writablePixel(x, y); }

    /**
     * Write the specified data to x, y. There is no checking on pixelSize!
     */
    inline void setPixel(TQ_INT32 x, TQ_INT32 y, const TQ_UINT8 * data)
        { ACTUAL_DATAMGR::setPixel(x, y, data);}


     /**
      * Copy the bytes in the specified rect to a chunk of memory.
      * The pixelSize in bytes is w * h * pixelSize. XXX: Better
      * use TQValueVector?
      */
     inline void readBytes(TQ_UINT8 * data,
               TQ_INT32 x, TQ_INT32 y,
               TQ_INT32 w, TQ_INT32 h)
        { ACTUAL_DATAMGR::readBytes(data, x, y, w, h);}

     /**
     * Copy the bytes to the specified rect. w * h * pixelSize bytes will be read, whether
     * the caller prepared them or not. XXX: Better use TQValueVector?
      */
     inline void writeBytes(const TQ_UINT8 * data,
             TQ_INT32 x, TQ_INT32 y,
             TQ_INT32 w, TQ_INT32 h)
        {ACTUAL_DATAMGR::writeBytes( data, x, y, w, h); }

    // Get the number of contiguous columns starting at x, valid for all values
    // of y between minY and maxY.
    inline TQ_INT32 numContiguousColumns(TQ_INT32 x, TQ_INT32 minY, TQ_INT32 maxY)
        { return ACTUAL_DATAMGR::numContiguousColumns(x, minY, maxY); }


    // Get the number of contiguous rows starting at y, valid for all values
    // of x between minX and maxX.
    inline TQ_INT32 numContiguousRows(TQ_INT32 y, TQ_INT32 minX, TQ_INT32 maxX)
        { return ACTUAL_DATAMGR::numContiguousRows(y, minX, maxX); }


    // Get the row stride at pixel (x, y). This is the number of bytes to add to a
    // pointer to pixel (x, y) to access (x, y + 1).
    inline TQ_INT32 rowStride(TQ_INT32 x, TQ_INT32 y)
        { return ACTUAL_DATAMGR::rowStride(x, y); }

protected:
    friend class KisRectIterator;
    friend class KisHLineIterator;
    friend class KisVLineIterator;
};


#endif // KIS_DATAMANAGER_H_