ezEngine  Milestone 9
Image_inl.h
1 #pragma once
2 
3 template<typename T> struct ezImageSizeofHelper
4 {
5  static constexpr size_t Size = sizeof (T);
6 };
7 
8 template <>
9 struct ezImageSizeofHelper<void>
10 {
11  static constexpr size_t Size = 1;
12 };
13 
14 template <>
15 struct ezImageSizeofHelper<const void>
16 {
17  static constexpr size_t Size = 1;
18 };
19 
20 template <typename T>
22 {
23  ValidateDataTypeAccessor<T>();
24  return ezArrayPtr<const T>(reinterpret_cast<T*>(static_cast<ezUInt8*>(m_dataPtr.GetPtr())), m_dataPtr.GetCount() / ezImageSizeofHelper<T>::Size);
25 }
26 
27 template <typename T>
29 {
30  ezArrayPtr<const T> constPtr = ezImageView::GetArrayPtr<T>();
31 
32  return ezArrayPtr<T>(const_cast<T*>(static_cast<const T*>(constPtr.GetPtr())), constPtr.GetCount());
33 }
34 
35 template <typename T>
36 const T* ezImageView::GetPixelPointer(ezUInt32 uiMipLevel /*= 0*/, ezUInt32 uiFace /*= 0*/, ezUInt32 uiArrayIndex /*= 0*/, ezUInt32 x /*= 0*/,
37  ezUInt32 y /*= 0*/, ezUInt32 z /*= 0*/) const
38 {
39  ValidateDataTypeAccessor<T>();
40  EZ_ASSERT_DEV(x < GetNumBlocksX(uiMipLevel), "Invalid x coordinate");
41  EZ_ASSERT_DEV(y < GetNumBlocksY(uiMipLevel), "Invalid y coordinate");
42  EZ_ASSERT_DEV(z < GetNumBlocksZ(uiMipLevel), "Invalid z coordinate");
43 
44  ezUInt32 offset = GetSubImageOffset(uiMipLevel, uiFace, uiArrayIndex) + z * GetDepthPitch(uiMipLevel) + y * GetRowPitch(uiMipLevel) + x * ezImageFormat::GetBitsPerBlock(m_format) / 8;
45  return reinterpret_cast<const T*>(&m_dataPtr[offset]);
46 }
47 
48 template <typename T>
49  T* ezImage::GetPixelPointer(ezUInt32 uiMipLevel /*= 0*/, ezUInt32 uiFace /*= 0*/, ezUInt32 uiArrayIndex /*= 0*/,
50  ezUInt32 x /*= 0*/, ezUInt32 y /*= 0*/, ezUInt32 z /*= 0*/)
51 {
52  return const_cast<T*>(ezImageView::GetPixelPointer<T>(uiMipLevel, uiFace, uiArrayIndex, x, y, z));
53 }
54 
55 
56 template <typename T>
57 void ezImageView::ValidateDataTypeAccessor() const
58 {
59  ezUInt32 bytesPerBlock = ezImageFormat::GetBitsPerBlock(GetImageFormat()) / 8;
60  EZ_ASSERT_DEV(bytesPerBlock % ezImageSizeofHelper<T>::Size == 0, "Accessor type is not suitable for interpreting contained data");
61 }
Definition: Image_inl.h:3
static ezUInt32 GetBitsPerBlock(Enum format)
Returns the block size in bits. For uncompressed formats, a block is considered a single pixel...
Definition: ImageFormat.cpp:430
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_ASSERT_DEV(bCondition, szErrorMsg,...)
Macro to raise an error, if a condition is not met.
Definition: Assert.h:116
ezArrayPtr< const T > GetArrayPtr() const
Returns a view to the entire data contained in this image.
Definition: Image_inl.h:21
EZ_ALWAYS_INLINE ezUInt32 GetCount() const
Returns the number of elements in the array.
Definition: ArrayPtr.h:182
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
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
EZ_ALWAYS_INLINE const PointerType GetPtr() const
Returns the pointer to the array.
Definition: ArrayPtr.h:158
ezArrayPtr< T > GetArrayPtr()
Returns a view to the entire data contained in this image.
Definition: Image_inl.h:28
ezImageFormat::Enum GetImageFormat() const
Returns the image format.
Definition: ImageHeader.h:36
T * GetPixelPointer(ezUInt32 uiMipLevel=0, ezUInt32 uiFace=0, ezUInt32 uiArrayIndex=0, ezUInt32 x=0, ezUInt32 y=0, ezUInt32 z=0)
Returns a pointer to a given pixel or block contained in a sub-image.
Definition: Image_inl.h:49
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