ezEngine  Milestone 9
Image.h
1 #pragma once
2 
3 #include <Foundation/Containers/DynamicArray.h>
4 #include <Foundation/Containers/HybridArray.h>
5 #include <Foundation/Logging/Log.h>
6 
7 #include <Texture/Image/ImageHeader.h>
8 
10 class EZ_TEXTURE_DLL ezImageView : protected ezImageHeader
11 {
12 public:
14  ezImageView();
15 
17  ezImageView(const ezImageHeader& header, ezArrayPtr<const void> imageData);
18 
20  void Clear();
21 
23  bool IsValid() const;
24 
26  void ResetAndViewExternalStorage(const ezImageHeader& header, ezArrayPtr<const void> imageData);
27 
29  ezResult SaveTo(const char* szFileName, ezLogInterface* pLog = ezLog::GetThreadLocalLogSystem()) const;
30 
32  const ezImageHeader& GetHeader() const;
33 
35  template <typename T>
36  ezArrayPtr<const T> GetArrayPtr() const;
37 
39  ezImageView GetSubImageView(ezUInt32 uiMipLevel = 0, ezUInt32 uiFace = 0, ezUInt32 uiArrayIndex = 0) const;
40 
42  ezImageView GetSliceView(ezUInt32 uiMipLevel = 0, ezUInt32 uiFace = 0, ezUInt32 uiArrayIndex = 0, ezUInt32 z = 0) const;
43 
45  ezImageView GetRowView(ezUInt32 uiMipLevel = 0, ezUInt32 uiFace = 0, ezUInt32 uiArrayIndex = 0, ezUInt32 y = 0, ezUInt32 z = 0) const;
46 
48  template <typename T>
49  const T* GetPixelPointer(ezUInt32 uiMipLevel = 0, ezUInt32 uiFace = 0, ezUInt32 uiArrayIndex = 0, ezUInt32 x = 0, ezUInt32 y = 0,
50  ezUInt32 z = 0) const;
51 
53  void ReinterpretAs(ezImageFormat::Enum format);
54 
55 public:
59 
63 
65 
69 
72 
73 protected:
74  ezUInt32 ComputeLayout();
75 
76  void ValidateSubImageIndices(ezUInt32 uiMipLevel, ezUInt32 uiFace, ezUInt32 uiArrayIndex) const;
77  template <typename T>
78  void ValidateDataTypeAccessor() const;
79 
80  const ezUInt32& GetSubImageOffset(ezUInt32 uiMipLevel, ezUInt32 uiFace, ezUInt32 uiArrayIndex) const;
81 
82  ezHybridArray<ezUInt32, 16> m_subImageOffsets;
83  ezArrayPtr<ezUInt8> m_dataPtr;
84 };
85 
94 class EZ_TEXTURE_DLL ezImage : public ezImageView
95 {
97  void operator=(const ezImage& rhs) = delete;
98 
100  void operator=(const ezImageView& rhs) = delete;
101 
103  explicit ezImage(const ezImageHeader& header);
104 
106  explicit ezImage(const ezImageHeader& header, ezArrayPtr<void> externalData);
107 
109  explicit ezImage(const ezImageView& other);
110 
111 public:
113 
115  ezImage();
116 
118  ezImage(ezImage&& other);
119 
120  void operator=(ezImage&& rhs);
121 
123  void Clear();
124 
129  void ResetAndAlloc(const ezImageHeader& header);
130 
134  void ResetAndUseExternalStorage(const ezImageHeader& header, ezArrayPtr<void> externalData);
135 
140  void ResetAndMove(ezImage&& other);
141 
145  void ResetAndCopy(const ezImageView& other);
146 
148  ezResult LoadFrom(const char* szFileName, ezLogInterface* pLog = ezLog::GetThreadLocalLogSystem());
149 
151  ezResult Convert(ezImageFormat::Enum targetFormat);
152 
154  template <typename T>
156 
158 
160  ezImage GetSubImageView(ezUInt32 uiMipLevel = 0, ezUInt32 uiFace = 0, ezUInt32 uiArrayIndex = 0);
161 
163 
165  ezImage GetSliceView(ezUInt32 uiMipLevel = 0, ezUInt32 uiFace = 0, ezUInt32 uiArrayIndex = 0, ezUInt32 z = 0);
166 
168 
170  ezImage GetRowView(ezUInt32 uiMipLevel = 0, ezUInt32 uiFace = 0, ezUInt32 uiArrayIndex = 0, ezUInt32 y = 0, ezUInt32 z = 0);
171 
173 
175  template <typename T>
176  T* GetPixelPointer(ezUInt32 uiMipLevel = 0, ezUInt32 uiFace = 0, ezUInt32 uiArrayIndex = 0, ezUInt32 x = 0, ezUInt32 y = 0,
177  ezUInt32 z = 0);
178 
180 
181 private:
182  bool UsesExternalStorage() const;
183 
184  ezDynamicArray<ezUInt8> m_internalStorage;
185 };
186 
187 #include <Texture/Image/Implementation/Image_inl.h>
188 
A class referencing image data and holding metadata about the image.
Definition: Image.h:10
ezImageView GetSubImageView(ezUInt32 uiMipLevel=0, ezUInt32 uiFace=0, ezUInt32 uiArrayIndex=0) const
Returns a view to the given sub-image.
Definition: Image.cpp:281
ezUInt32 GetNumBlocksY(ezUInt32 uiMipLevel=0) const
Returns the number of blocks contained in a given mip level in the horizontal direction.
Definition: ImageHeader.h:96
#define EZ_DECLARE_MEM_RELOCATABLE_TYPE()
Embed this into a class to mark it as memory relocatable. Memory relocatable types will get special t...
Definition: TypeTraits.h:135
A class containing image data and associated meta data.
Definition: Image.h:94
Enum
Enum describing the encoding format of the pixels of an image.
Definition: ImageFormat.h:56
Base class for all logging classes.
Definition: Log.h:63
ezArrayPtr< const T > GetArrayPtr() const
Returns a view to the entire data contained in this image.
Definition: Image_inl.h:21
ezUInt32 GetNumFaces() const
Returns the number of cubemap faces, or 1 for a non-cubemap.
Definition: ImageHeader.h:82
ezUInt32 GetRowPitch(ezUInt32 uiMipLevel=0) const
Returns the offset in bytes between two subsequent rows of the given mip level.
Definition: ImageHeader.h:102
ezUInt32 GetDepthPitch(ezUInt32 uiMipLevel=0) const
Returns the offset in bytes between two subsequent depth slices of the given mip level.
Definition: ImageHeader.h:105
ezImageView GetSliceView(ezUInt32 uiMipLevel=0, ezUInt32 uiFace=0, ezUInt32 uiArrayIndex=0, ezUInt32 z=0) const
Returns a view to z slice of the image.
Definition: Image.cpp:318
ezUInt32 GetNumMipLevels() const
Returns the number of mip levels, including the full-size image.
Definition: ImageHeader.h:74
static ezLogInterface * GetThreadLocalLogSystem()
Returns the currently set default logging system, or a thread local instance of ezGlobalLog, if nothing else was set.
Definition: Log.cpp:180
ezUInt32 GetNumBlocksZ(ezUInt32 uiMipLevel=0) const
Returns the number of blocks contained in a given mip level in the depth direction.
Definition: ImageHeader.h:99
void Clear()
Constructs an empty image view.
Definition: Image.cpp:19
ezImageView GetRowView(ezUInt32 uiMipLevel=0, ezUInt32 uiFace=0, ezUInt32 uiArrayIndex=0, ezUInt32 y=0, ezUInt32 z=0) const
Returns a view to a row of pixels resp. blocks.
Definition: Image.cpp:83
ezUInt32 GetDepth(ezUInt32 uiMipLevel=0) const
Returns the image depth for a given mip level, clamped to 1.
Definition: ImageHeader.h:62
A class containing image meta data, such as format and dimensions.
Definition: ImageHeader.h:14
ezUInt32 GetNumArrayIndices() const
Returns the number of array indices.
Definition: ImageHeader.h:90
ezUInt32 GetWidth(ezUInt32 uiMipLevel=0) const
Returns the image width for a given mip level, clamped to 1.
Definition: ImageHeader.h:42
ezImageFormat::Enum GetImageFormat() const
Returns the image format.
Definition: ImageHeader.h:36
void Clear()
Constructs an image using an unknown format and zero size.
Definition: ImageHeader.h:21
ezUInt32 GetHeight(ezUInt32 uiMipLevel=0) const
Returns the image height for a given mip level, clamped to 1.
Definition: ImageHeader.h:52
Default enum for returning failure or success, instead of using a bool.
Definition: Types.h:51
const T * GetPixelPointer(ezUInt32 uiMipLevel=0, ezUInt32 uiFace=0, ezUInt32 uiArrayIndex=0, ezUInt32 x=0, ezUInt32 y=0, ezUInt32 z=0) const
Returns a pointer to a given pixel or block contained in a sub-image.
Definition: Image_inl.h:36
ezUInt32 GetNumBlocksX(ezUInt32 uiMipLevel=0) const
Returns the number of blocks contained in a given mip level in the horizontal direction.
Definition: ImageHeader.h:93
This class encapsulates an array and it&#39;s size. It is recommended to use this class instead of plain ...
Definition: ArrayPtr.h:82