summaryrefslogtreecommitdiffstats
path: root/Tools/AnvilStats/ImageComposingCallback.h
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-08-30 20:46:16 +0200
committermadmaxoft <github@xoft.cz>2013-08-30 20:46:16 +0200
commit7f4c880147719d7b2d3cd97c68ad5af76764042b (patch)
treeea752b9936978067728d7bfda744f66c6ff0f0a2 /Tools/AnvilStats/ImageComposingCallback.h
parentAnvilStats: Callbacks can now use CALLBACK_CONTINUE and CALLBACK_ABORT instead of bool return values. (diff)
downloadcuberite-7f4c880147719d7b2d3cd97c68ad5af76764042b.tar
cuberite-7f4c880147719d7b2d3cd97c68ad5af76764042b.tar.gz
cuberite-7f4c880147719d7b2d3cd97c68ad5af76764042b.tar.bz2
cuberite-7f4c880147719d7b2d3cd97c68ad5af76764042b.tar.lz
cuberite-7f4c880147719d7b2d3cd97c68ad5af76764042b.tar.xz
cuberite-7f4c880147719d7b2d3cd97c68ad5af76764042b.tar.zst
cuberite-7f4c880147719d7b2d3cd97c68ad5af76764042b.zip
Diffstat (limited to '')
-rw-r--r--Tools/AnvilStats/ImageComposingCallback.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/Tools/AnvilStats/ImageComposingCallback.h b/Tools/AnvilStats/ImageComposingCallback.h
new file mode 100644
index 000000000..c04dc869f
--- /dev/null
+++ b/Tools/AnvilStats/ImageComposingCallback.h
@@ -0,0 +1,95 @@
+
+// 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
+ } ;
+
+ 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;
+
+ // New introduced overridable functions:
+
+ /// Called when a file is about to be saved, to generate the filename
+ virtual AString GetFileName(int a_RegionX, int a_RegionZ);
+
+ /// Called before the file is saved
+ virtual void OnBeforeImageSaved(int a_RegionX, int a_RegionZ, const AString & a_FileName) {}
+
+ /// Called after the image is saved to a file
+ virtual void OnAfterImageSaved(int a_RegionX, int a_RegionZ, const AString & a_FileName) {}
+
+ /// Called when a new region is beginning, to erase the image data
+ virtual void OnEraseImage(void);
+
+ // Functions for manipulating the image:
+
+ /// Erases the entire image with the specified color
+ void EraseImage(int a_Color);
+
+ /// Erases the specified chunk's portion of the image with the specified color. Note that chunk coords are relative to the current region
+ void EraseChunk(int a_Color, int a_RelChunkX, int a_RelChunkZ);
+
+ /// Returns the current region X coord
+ int GetCurrentRegionX(void) const { return m_CurrentRegionX; }
+
+ /// Returns the current region Z coord
+ int GetCurrentRegionZ(void) const { return m_CurrentRegionZ; }
+
+ /// Sets the pixel at the specified UV coords to the specified color
+ void SetPixel(int a_RelU, int a_RelV, int a_Color);
+
+ /// Returns the color of the pixel at the specified UV coords; -1 if outside
+ int GetPixel(int a_RelU, int a_RelV);
+
+ /// 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
+ void SetPixelURow(int a_RelUStart, int a_RelV, int a_CountU, int * a_Pixels);
+
+protected:
+ /// Prefix for the filenames, when generated by the default GetFileName() function
+ AString m_FileNamePrefix;
+
+ /// Coords of the currently processed region
+ int m_CurrentRegionX, m_CurrentRegionZ;
+
+ /// Raw image data; 1 MiB worth of data, therefore unsuitable for stack allocation. [u + IMAGE_WIDTH * v]
+ int * m_ImageData;
+
+ void SaveImage(const AString & a_FileName);
+} ;
+
+
+
+