Plasma Engine  2.0
Loading...
Searching...
No Matches
Image.h
1#pragma once
2
3#include <Foundation/Containers/Blob.h>
4#include <Foundation/Containers/DynamicArray.h>
5#include <Foundation/Containers/HybridArray.h>
6#include <Foundation/Logging/Log.h>
7
8#include <Texture/Image/Formats/ImageFileFormat.h>
9#include <Texture/Image/ImageHeader.h>
10
12class PL_TEXTURE_DLL plImageView : protected plImageHeader
13{
14public:
17
19 plImageView(const plImageHeader& header, plConstByteBlobPtr imageData);
20
22 void Clear();
23
25 bool IsValid() const;
26
28 void ResetAndViewExternalStorage(const plImageHeader& header, plConstByteBlobPtr imageData);
29
31 plResult SaveTo(plStringView sFileName) const;
32
34 const plImageHeader& GetHeader() const;
35
37 template <typename T>
38 plBlobPtr<const T> GetBlobPtr() const;
39
40 plConstByteBlobPtr GetByteBlobPtr() const;
41
43 plImageView GetSubImageView(plUInt32 uiMipLevel = 0, plUInt32 uiFace = 0, plUInt32 uiArrayIndex = 0) const;
44
46 plImageView GetPlaneView(plUInt32 uiMipLevel = 0, plUInt32 uiFace = 0, plUInt32 uiArrayIndex = 0, plUInt32 uiPlaneIndex = 0) const;
47
49 plImageView GetSliceView(plUInt32 uiMipLevel = 0, plUInt32 uiFace = 0, plUInt32 uiArrayIndex = 0, plUInt32 z = 0, plUInt32 uiPlaneIndex = 0) const;
50
52 plImageView GetRowView(plUInt32 uiMipLevel = 0, plUInt32 uiFace = 0, plUInt32 uiArrayIndex = 0, plUInt32 y = 0, plUInt32 z = 0, plUInt32 uiPlaneIndex = 0) const;
53
55 template <typename T>
56 const T* GetPixelPointer(
57 plUInt32 uiMipLevel = 0, plUInt32 uiFace = 0, plUInt32 uiArrayIndex = 0, plUInt32 x = 0, plUInt32 y = 0, plUInt32 z = 0, plUInt32 uiPlaneIndex = 0) const;
58
60 void ReinterpretAs(plImageFormat::Enum format);
61
62public:
66
71
73
77
80
81protected:
82 plUInt64 ComputeLayout();
83
84 void ValidateSubImageIndices(plUInt32 uiMipLevel, plUInt32 uiFace, plUInt32 uiArrayIndex, plUInt32 uiPlaneIndex) const;
85 template <typename T>
86 void ValidateDataTypeAccessor(plUInt32 uiPlaneIndex) const;
87
88 const plUInt64& GetSubImageOffset(plUInt32 uiMipLevel, plUInt32 uiFace, plUInt32 uiArrayIndex, plUInt32 uiPlaneIndex) const;
89
90 plHybridArray<plUInt64, 16> m_SubImageOffsets;
91 plBlobPtr<plUInt8> m_DataPtr;
92};
93
102class PL_TEXTURE_DLL plImage : public plImageView
103{
105 void operator=(const plImage& rhs) = delete;
106
108 void operator=(const plImageView& rhs) = delete;
109
111 explicit plImage(const plImageHeader& header);
112
114 explicit plImage(const plImageHeader& header, plByteBlobPtr externalData);
115
117 explicit plImage(const plImageView& other);
118
119public:
120 PL_DECLARE_MEM_RELOCATABLE_TYPE();
121
123 plImage();
124
126 plImage(plImage&& other);
127
128 void operator=(plImage&& rhs);
129
131 void Clear();
132
137 void ResetAndAlloc(const plImageHeader& header);
138
142 void ResetAndUseExternalStorage(const plImageHeader& header, plByteBlobPtr externalData);
143
148 void ResetAndMove(plImage&& other);
149
153 void ResetAndCopy(const plImageView& other);
154
156 plResult LoadFrom(plStringView sFileName);
157
159 plResult Convert(plImageFormat::Enum targetFormat);
160
162 template <typename T>
163 plBlobPtr<T> GetBlobPtr();
164
165 plByteBlobPtr GetByteBlobPtr();
166
168 using plImageView::GetByteBlobPtr;
169
171 plImage GetSubImageView(plUInt32 uiMipLevel = 0, plUInt32 uiFace = 0, plUInt32 uiArrayIndex = 0);
172
174
176 plImage GetPlaneView(plUInt32 uiMipLevel = 0, plUInt32 uiFace = 0, plUInt32 uiArrayIndex = 0, plUInt32 uiPlaneIndex = 0);
177
179
181 plImage GetSliceView(plUInt32 uiMipLevel = 0, plUInt32 uiFace = 0, plUInt32 uiArrayIndex = 0, plUInt32 z = 0, plUInt32 uiPlaneIndex = 0);
182
184
186 plImage GetRowView(plUInt32 uiMipLevel = 0, plUInt32 uiFace = 0, plUInt32 uiArrayIndex = 0, plUInt32 y = 0, plUInt32 z = 0, plUInt32 uiPlaneIndex = 0);
187
189
191 template <typename T>
192 T* GetPixelPointer(plUInt32 uiMipLevel = 0, plUInt32 uiFace = 0, plUInt32 uiArrayIndex = 0, plUInt32 x = 0, plUInt32 y = 0, plUInt32 z = 0, plUInt32 uiPlaneIndex = 0);
193
195
196private:
197 bool UsesExternalStorage() const;
198
199 plBlob m_InternalStorage;
200};
201
202#include <Texture/Image/Implementation/Image_inl.h>
plBlob allows to store simple binary data larger than 4GB. This storage class is used by plImage to a...
Definition Blob.h:319
This class encapsulates a blob's storage and it's size. It is recommended to use this class instead o...
Definition Blob.h:13
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
A class containing image meta data, such as format and dimensions.
Definition ImageHeader.h:15
plUInt32 GetNumBlocksZ(plUInt32 uiMipLevel=0, plUInt32 uiPlaneIndex=0) const
Returns the number of blocks contained in a given mip level in the depth direction.
Definition ImageHeader.h:111
plUInt32 GetHeight(plUInt32 uiMipLevel=0) const
Returns the image height for a given mip level, clamped to 1.
Definition ImageHeader.h:52
plUInt32 GetPlaneCount() const
Returns the number of image planes.
Definition ImageHeader.h:93
plUInt32 GetNumArrayIndices() const
Returns the number of array indices.
Definition ImageHeader.h:90
plUInt32 GetNumFaces() const
Returns the number of cubemap faces, or 1 for a non-cubemap.
Definition ImageHeader.h:82
plUInt32 GetDepth(plUInt32 uiMipLevel=0) const
Returns the image depth for a given mip level, clamped to 1.
Definition ImageHeader.h:62
plUInt64 GetRowPitch(plUInt32 uiMipLevel=0, plUInt32 uiPlaneIndex=0) const
Returns the offset in bytes between two subsequent rows of the given mip level.
Definition ImageHeader.h:117
plImageFormat::Enum GetImageFormat() const
Returns the image format.
Definition ImageHeader.h:36
plUInt32 GetNumBlocksY(plUInt32 uiMipLevel=0, plUInt32 uiPlaneIndex=0) const
Returns the number of blocks contained in a given mip level in the horizontal direction.
Definition ImageHeader.h:105
plUInt32 GetNumBlocksX(plUInt32 uiMipLevel=0, plUInt32 uiPlaneIndex=0) const
Returns the number of blocks contained in a given mip level in the horizontal direction.
Definition ImageHeader.h:99
plUInt32 GetNumMipLevels() const
Returns the number of mip levels, including the full-size image.
Definition ImageHeader.h:74
plUInt32 GetWidth(plUInt32 uiMipLevel=0) const
Returns the image width for a given mip level, clamped to 1.
Definition ImageHeader.h:42
plUInt64 GetDepthPitch(plUInt32 uiMipLevel=0, plUInt32 uiPlaneIndex=0) const
Returns the offset in bytes between two subsequent depth slices of the given mip level.
Definition ImageHeader.h:123
void Clear()
Constructs an image using an unknown format and zero size.
Definition ImageHeader.h:21
A class containing image data and associated meta data.
Definition Image.h:103
plImage GetRowView(plUInt32 uiMipLevel=0, plUInt32 uiFace=0, plUInt32 uiArrayIndex=0, plUInt32 y=0, plUInt32 z=0, plUInt32 uiPlaneIndex=0)
Returns a view to a row of pixels resp. blocks.
A class referencing image data and holding metadata about the image.
Definition Image.h:13
plImageView GetRowView(plUInt32 uiMipLevel=0, plUInt32 uiFace=0, plUInt32 uiArrayIndex=0, plUInt32 y=0, plUInt32 z=0, plUInt32 uiPlaneIndex=0) const
Returns a view to a row of pixels resp. blocks.
Definition Image.cpp:85
plImageView GetSubImageView(plUInt32 uiMipLevel=0, plUInt32 uiFace=0, plUInt32 uiArrayIndex=0) const
Returns a view to the given sub-image.
Definition Image.cpp:291
plBlobPtr< const T > GetBlobPtr() const
Returns a view to the entire data contained in this image.
Definition Image_inl.h:22
plImageView GetPlaneView(plUInt32 uiMipLevel=0, plUInt32 uiFace=0, plUInt32 uiArrayIndex=0, plUInt32 uiPlaneIndex=0) const
Returns a view to a sub-plane.
Definition Image.cpp:319
plImageView GetSliceView(plUInt32 uiMipLevel=0, plUInt32 uiFace=0, plUInt32 uiArrayIndex=0, plUInt32 z=0, plUInt32 uiPlaneIndex=0) const
Returns a view to z slice of the image.
Definition Image.cpp:359
const T * GetPixelPointer(plUInt32 uiMipLevel=0, plUInt32 uiFace=0, plUInt32 uiArrayIndex=0, plUInt32 x=0, plUInt32 y=0, plUInt32 z=0, plUInt32 uiPlaneIndex=0) const
Returns a pointer to a given pixel or block contained in a sub-image.
Definition Image_inl.h:56
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Enum
Enum describing the encoding format of the pixels of an image.
Definition ImageFormat.h:68
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54