1 /*
2    Drawpile - a collaborative drawing program.
3 
4    Copyright (C) 2018 Calle Laakkonen
5 
6    Drawpile is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation, either version 3 of the License, or
9    (at your option) any later version.
10 
11    Drawpile is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with Drawpile.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef DP_CORE_TILEVECTOR_H
21 #define DP_CORE_TILEVECTOR_H
22 
23 #include "tile.h"
24 #include "../libshared/net/message.h"
25 
26 #include <QVector>
27 #include <QColor>
28 
29 class QSize;
30 class QPoint;
31 
32 namespace paintcore {
33 
34 class Layer;
35 
36 /**
37  * @brief One or more tile to be placed on a layer
38  */
39 struct TileRun {
40 	Tile tile;
41 	int col;
42 	int row;
43 	int len;      // the length of the tile run (always at least 1)
44 	QColor color; // if valid, this tile is filled with solid color
45 };
46 
47 /**
48  * @brief An RLE compressed representation of a layer's tiles
49  */
50 struct LayerTileSet {
51 	QVector<TileRun> tiles;
52 	QColor background;
53 
54 	/**
55 	 * @brief Generate a compressed tile set representation of a layer
56 	 *
57 	 * Using the PutTile command, this is used to make an efficient
58 	 * layer initialization command sequence.
59 	 */
60 	static LayerTileSet fromLayer(const Layer &layer);
61 	static LayerTileSet fromImage(const QImage &image);
62 	static LayerTileSet fromImage(const QImage &image, const QSize &layerSize, const QPoint &offset);
63 
64 	/**
65 	 * @brief Generate PutTiles commands
66 	 * @param contextid the message context ID to use
67 	 * @param layerId target layer ID
68 	 * @param sublayer target sublayer (0 for normal layers)
69 	 * @param msgs where to put the messages
70 	 */
71 	void toPutTiles(uint8_t contextid, uint16_t layerId, uint8_t sublayer, protocol::MessageList &msgs) const;
72 };
73 
74 }
75 
76 #endif
77