2013-08-30 14:46:16 -04:00
|
|
|
|
|
|
|
// ImageComposingCallback
|
|
|
|
|
|
|
|
// Declares the cImageComposingCallback class that implements a subset of cCallback for composing per-region images
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Callback.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Implements the plumbing for composing per-region images from multiple chunks.
|
|
|
|
To use this class, create a descendant that writes the image data using
|
|
|
|
SetPixel() or SetPixelURow() functions.
|
|
|
|
|
|
|
|
For the purpose of this class the image data is indexed U (horz) * V (vert), to avoid confusion with other coords.
|
|
|
|
The image is a 32bpp raw imagedata, written into a BMP file.
|
|
|
|
*/
|
|
|
|
class cImageComposingCallback :
|
|
|
|
public cCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
INVALID_REGION_COORD = 99999, ///< Used for un-assigned region coords
|
|
|
|
IMAGE_WIDTH = 32 * 16,
|
|
|
|
IMAGE_HEIGHT = 32 * 16,
|
|
|
|
PIXEL_COUNT = IMAGE_WIDTH * IMAGE_HEIGHT, ///< Total pixel count of the image data
|
|
|
|
} ;
|
2017-12-23 07:49:08 -05:00
|
|
|
|
2013-08-30 14:46:16 -04:00
|
|
|
cImageComposingCallback(const AString & a_FileNamePrefix);
|
|
|
|
virtual ~cImageComposingCallback();
|
|
|
|
|
|
|
|
// cCallback overrides:
|
|
|
|
virtual bool OnNewRegion(int a_RegionX, int a_RegionZ) override;
|
|
|
|
virtual void OnRegionFinished(int a_RegionX, int a_RegionZ) override;
|
2017-12-23 07:49:08 -05:00
|
|
|
|
2013-08-30 14:46:16 -04:00
|
|
|
// New introduced overridable functions:
|
2017-12-23 07:49:08 -05:00
|
|
|
|
|
|
|
/** Called when a file is about to be saved, to generate the filename */
|
2013-08-30 14:46:16 -04:00
|
|
|
virtual AString GetFileName(int a_RegionX, int a_RegionZ);
|
2017-12-23 07:49:08 -05:00
|
|
|
|
|
|
|
/** Called before the file is saved */
|
2013-08-30 14:46:16 -04:00
|
|
|
virtual void OnBeforeImageSaved(int a_RegionX, int a_RegionZ, const AString & a_FileName) {}
|
2017-12-23 07:49:08 -05:00
|
|
|
|
|
|
|
/** Called after the image is saved to a file */
|
2013-08-30 14:46:16 -04:00
|
|
|
virtual void OnAfterImageSaved(int a_RegionX, int a_RegionZ, const AString & a_FileName) {}
|
2017-12-23 07:49:08 -05:00
|
|
|
|
|
|
|
/** Called when a new region is beginning, to erase the image data */
|
2013-08-30 14:46:16 -04:00
|
|
|
virtual void OnEraseImage(void);
|
2017-12-23 07:49:08 -05:00
|
|
|
|
2013-08-30 14:46:16 -04:00
|
|
|
// Functions for manipulating the image:
|
2017-12-23 07:49:08 -05:00
|
|
|
|
|
|
|
/** Erases the entire image with the specified color */
|
2013-08-30 14:46:16 -04:00
|
|
|
void EraseImage(int a_Color);
|
2017-12-23 07:49:08 -05:00
|
|
|
|
|
|
|
/** Erases the specified chunk's portion of the image with the specified color. Note that chunk coords are relative to the current region */
|
2013-08-30 14:46:16 -04:00
|
|
|
void EraseChunk(int a_Color, int a_RelChunkX, int a_RelChunkZ);
|
2017-12-23 07:49:08 -05:00
|
|
|
|
|
|
|
/** Returns the current region X coord */
|
2013-08-30 14:46:16 -04:00
|
|
|
int GetCurrentRegionX(void) const { return m_CurrentRegionX; }
|
2017-12-23 07:49:08 -05:00
|
|
|
|
|
|
|
/** Returns the current region Z coord */
|
2013-08-30 14:46:16 -04:00
|
|
|
int GetCurrentRegionZ(void) const { return m_CurrentRegionZ; }
|
2017-12-23 07:49:08 -05:00
|
|
|
|
|
|
|
/** Sets the pixel at the specified UV coords to the specified color */
|
2013-08-30 14:46:16 -04:00
|
|
|
void SetPixel(int a_RelU, int a_RelV, int a_Color);
|
2017-12-23 07:49:08 -05:00
|
|
|
|
|
|
|
/** Returns the color of the pixel at the specified UV coords; -1 if outside */
|
2013-08-30 14:46:16 -04:00
|
|
|
int GetPixel(int a_RelU, int a_RelV);
|
2017-12-23 07:49:08 -05:00
|
|
|
|
|
|
|
/** Sets a row of pixels. a_Pixels is expected to be a_CountU pixels wide. a_RelUStart + a_CountU is assumed less than image width */
|
2013-08-30 14:46:16 -04:00
|
|
|
void SetPixelURow(int a_RelUStart, int a_RelV, int a_CountU, int * a_Pixels);
|
2017-12-23 07:49:08 -05:00
|
|
|
|
2013-08-30 17:32:27 -04:00
|
|
|
/** "Shades" the given color based on the shade amount given
|
|
|
|
Shade amount 0 .. 63 shades the color from black to a_Color.
|
|
|
|
Shade amount 64 .. 127 shades the color from a_Color to white.
|
|
|
|
All other shade amounts have undefined results.
|
|
|
|
*/
|
|
|
|
static int ShadeColor(int a_Color, int a_Shade);
|
2017-12-23 07:49:08 -05:00
|
|
|
|
|
|
|
/** Mixes the two colors in the specified ratio; a_Ratio is between 0 and 256, 0 returning a_Src */
|
2013-08-30 17:32:27 -04:00
|
|
|
static int MixColor(int a_Src, int a_Dest, int a_Ratio);
|
2017-12-23 07:49:08 -05:00
|
|
|
|
2013-08-30 14:46:16 -04:00
|
|
|
protected:
|
2017-12-23 07:49:08 -05:00
|
|
|
/** Prefix for the filenames, when generated by the default GetFileName() function */
|
2013-08-30 14:46:16 -04:00
|
|
|
AString m_FileNamePrefix;
|
2017-12-23 07:49:08 -05:00
|
|
|
|
|
|
|
/** Coords of the currently processed region */
|
2013-08-30 14:46:16 -04:00
|
|
|
int m_CurrentRegionX, m_CurrentRegionZ;
|
2017-12-23 07:49:08 -05:00
|
|
|
|
|
|
|
/** Raw image data; 1 MiB worth of data, therefore unsuitable for stack allocation. [u + IMAGE_WIDTH * v] */
|
2013-08-30 14:46:16 -04:00
|
|
|
int * m_ImageData;
|
2017-12-23 07:49:08 -05:00
|
|
|
|
2013-08-30 14:46:16 -04:00
|
|
|
void SaveImage(const AString & a_FileName);
|
|
|
|
} ;
|