2016-07-12 17:40:45 +00:00
|
|
|
#pragma once
|
2014-06-05 15:12:49 +00:00
|
|
|
|
|
|
|
#include "software_global.h"
|
|
|
|
|
2015-12-29 23:43:35 +00:00
|
|
|
#include <string>
|
|
|
|
|
2014-06-05 15:12:49 +00:00
|
|
|
namespace paysages {
|
|
|
|
namespace software {
|
|
|
|
|
|
|
|
/**
|
2014-08-18 10:17:16 +00:00
|
|
|
* Rectangular portion of a Canvas.
|
2014-06-05 15:12:49 +00:00
|
|
|
*
|
|
|
|
* Contains the pixels of a canvas region (CanvasPixel).
|
2014-08-18 15:16:17 +00:00
|
|
|
*
|
|
|
|
* Pixels are not allocated until preparePixels is called.
|
2014-06-05 15:12:49 +00:00
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
class SOFTWARESHARED_EXPORT CanvasPortion {
|
|
|
|
public:
|
|
|
|
CanvasPortion(int index = 0, CanvasPreview *preview = NULL);
|
2014-08-21 07:58:11 +00:00
|
|
|
virtual ~CanvasPortion();
|
2014-06-05 15:12:49 +00:00
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
inline int getWidth() const {
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
inline int getHeight() const {
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
inline int getXOffset() const {
|
|
|
|
return xoffset;
|
|
|
|
}
|
|
|
|
inline int getYOffset() const {
|
|
|
|
return yoffset;
|
|
|
|
}
|
2014-06-10 13:13:16 +00:00
|
|
|
int getFragmentCount(int x, int y) const;
|
|
|
|
const CanvasFragment *getFrontFragment(int x, int y) const;
|
2014-06-05 15:12:49 +00:00
|
|
|
|
2014-06-10 13:13:16 +00:00
|
|
|
void clear();
|
2015-11-09 21:30:46 +00:00
|
|
|
void setSize(int width, int height, int xoffset = 0, int yoffset = 0);
|
2014-06-05 15:12:49 +00:00
|
|
|
|
2014-08-18 15:16:17 +00:00
|
|
|
/**
|
|
|
|
* Prepare (allocate in memory) the pixels area.
|
|
|
|
*/
|
|
|
|
void preparePixels();
|
|
|
|
|
2014-08-18 15:33:15 +00:00
|
|
|
/**
|
|
|
|
* Discard the memory used by pixels.
|
2014-08-21 07:58:11 +00:00
|
|
|
*
|
|
|
|
* If save is true, the portion will be saved to disk before.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
void discardPixels(bool save = true);
|
2014-08-21 07:58:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the portion to a picture file on disk.
|
2014-08-18 15:33:15 +00:00
|
|
|
*/
|
2014-08-21 07:58:11 +00:00
|
|
|
void saveToDisk();
|
2014-08-18 15:33:15 +00:00
|
|
|
|
2014-08-21 10:36:28 +00:00
|
|
|
/**
|
|
|
|
* Bind a stream to pixel data, and position it on a given pixel.
|
|
|
|
*
|
|
|
|
* Returns true if the stream was successfully located, false if it was not possible.
|
|
|
|
*/
|
2015-11-09 21:30:46 +00:00
|
|
|
bool getReadStream(PackStream &stream, int x = 0, int y = 0);
|
2014-08-21 10:36:28 +00:00
|
|
|
|
2014-06-10 13:13:16 +00:00
|
|
|
/**
|
2014-08-18 10:17:16 +00:00
|
|
|
* Add a fragment to the pixel located at (x, y).
|
2014-06-10 13:13:16 +00:00
|
|
|
*
|
|
|
|
* Checking x and y coordinates to be in the canvas portion should be done before this call.
|
|
|
|
*/
|
|
|
|
void pushFragment(int x, int y, const CanvasFragment &fragment);
|
|
|
|
|
2014-08-18 10:17:16 +00:00
|
|
|
/**
|
|
|
|
* Get the CanvasPixel at a given coordinates.
|
|
|
|
*
|
|
|
|
* Checking x and y coordinates to be in the canvas portion should be done before this call.
|
|
|
|
*/
|
|
|
|
const CanvasPixel &at(int x, int y);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the final color of the pixel.
|
|
|
|
*
|
|
|
|
* Checking x and y coordinates to be in the canvas portion should be done before this call.
|
|
|
|
*/
|
|
|
|
void setColor(int x, int y, const Color &color);
|
|
|
|
|
2015-11-09 21:30:46 +00:00
|
|
|
private:
|
2014-08-21 07:58:11 +00:00
|
|
|
int index;
|
2014-06-05 15:12:49 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
2014-08-18 15:33:15 +00:00
|
|
|
int xoffset;
|
|
|
|
int yoffset;
|
2014-06-10 13:13:16 +00:00
|
|
|
CanvasPixel *pixels;
|
2014-08-21 07:58:11 +00:00
|
|
|
CanvasPreview *preview;
|
2015-12-10 23:36:50 +00:00
|
|
|
string filepath;
|
2014-06-05 15:12:49 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|