Plasma Engine  2.0
Loading...
Searching...
No Matches
Image_inl.h
1#pragma once
2
3template <typename T>
5{
6 static constexpr size_t Size = sizeof(T);
7};
8
9template <>
11{
12 static constexpr size_t Size = 1;
13};
14
15template <>
16struct plImageSizeofHelper<const void>
17{
18 static constexpr size_t Size = 1;
19};
20
21template <typename T>
23{
24 for (plUInt32 uiPlaneIndex = 0; uiPlaneIndex < GetPlaneCount(); ++uiPlaneIndex)
25 {
26 ValidateDataTypeAccessor<T>(uiPlaneIndex);
27 }
28 return plBlobPtr<const T>(reinterpret_cast<T*>(static_cast<plUInt8*>(m_DataPtr.GetPtr())), m_DataPtr.GetCount() / plImageSizeofHelper<T>::Size);
29}
30
31inline plConstByteBlobPtr plImageView::GetByteBlobPtr() const
32{
33 for (plUInt32 uiPlaneIndex = 0; uiPlaneIndex < GetPlaneCount(); ++uiPlaneIndex)
34 {
35 ValidateDataTypeAccessor<plUInt8>(uiPlaneIndex);
36 }
37 return plConstByteBlobPtr(static_cast<plUInt8*>(m_DataPtr.GetPtr()), m_DataPtr.GetCount());
39
40template <typename T>
42{
44
45 return plBlobPtr<T>(const_cast<T*>(static_cast<const T*>(constPtr.GetPtr())), constPtr.GetCount());
46}
47
48inline plByteBlobPtr plImage::GetByteBlobPtr()
49{
50 plConstByteBlobPtr constPtr = plImageView::GetByteBlobPtr();
51
52 return plByteBlobPtr(const_cast<plUInt8*>(constPtr.GetPtr()), constPtr.GetCount());
53}
54
55template <typename T>
56const T* plImageView::GetPixelPointer(plUInt32 uiMipLevel /*= 0*/, plUInt32 uiFace /*= 0*/, plUInt32 uiArrayIndex /*= 0*/, plUInt32 x /*= 0*/,
57 plUInt32 y /*= 0*/, plUInt32 z /*= 0*/, plUInt32 uiPlaneIndex /*= 0*/) const
58{
59 ValidateDataTypeAccessor<T>(uiPlaneIndex);
60 PL_ASSERT_DEV(x < GetNumBlocksX(uiMipLevel, uiPlaneIndex), "Invalid x coordinate");
61 PL_ASSERT_DEV(y < GetNumBlocksY(uiMipLevel, uiPlaneIndex), "Invalid y coordinate");
62 PL_ASSERT_DEV(z < GetNumBlocksZ(uiMipLevel, uiPlaneIndex), "Invalid z coordinate");
63
64 plUInt64 offset = GetSubImageOffset(uiMipLevel, uiFace, uiArrayIndex, uiPlaneIndex) +
65 z * GetDepthPitch(uiMipLevel, uiPlaneIndex) +
66 y * GetRowPitch(uiMipLevel, uiPlaneIndex) +
67 x * plImageFormat::GetBitsPerBlock(m_Format, uiPlaneIndex) / 8;
68 return reinterpret_cast<const T*>(&m_DataPtr[offset]);
69}
70
71template <typename T>
73 plUInt32 uiMipLevel /*= 0*/, plUInt32 uiFace /*= 0*/, plUInt32 uiArrayIndex /*= 0*/, plUInt32 x /*= 0*/, plUInt32 y /*= 0*/, plUInt32 z /*= 0*/, plUInt32 uiPlaneIndex /*= 0*/)
74{
75 return const_cast<T*>(plImageView::GetPixelPointer<T>(uiMipLevel, uiFace, uiArrayIndex, x, y, z, uiPlaneIndex));
76}
77
78
79template <typename T>
80void plImageView::ValidateDataTypeAccessor(plUInt32 uiPlaneIndex) const
81{
82 plUInt32 bytesPerBlock = plImageFormat::GetBitsPerBlock(GetImageFormat(), uiPlaneIndex) / 8;
83 PL_IGNORE_UNUSED(bytesPerBlock);
84 PL_ASSERT_DEV(bytesPerBlock % plImageSizeofHelper<T>::Size == 0, "Accessor type is not suitable for interpreting contained data");
85}
This class encapsulates a blob's storage and it's size. It is recommended to use this class instead o...
Definition Blob.h:13
PL_ALWAYS_INLINE PointerType GetPtr() const
Returns the pointer to the array.
Definition Blob.h:80
PL_ALWAYS_INLINE plUInt64 GetCount() const
Returns the number of elements in the array.
Definition Blob.h:95
T * GetPixelPointer(plUInt32 uiMipLevel=0, plUInt32 uiFace=0, plUInt32 uiArrayIndex=0, plUInt32 x=0, plUInt32 y=0, plUInt32 z=0, plUInt32 uiPlaneIndex=0)
Returns a pointer to a given pixel or block contained in a sub-image.
Definition Image_inl.h:72
plBlobPtr< T > GetBlobPtr()
Returns a view to the entire data contained in this image.
Definition Image_inl.h:41
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
plBlobPtr< const T > GetBlobPtr() const
Returns a view to the entire data contained in this image.
Definition Image_inl.h:22
plUInt32 GetPlaneCount() const
Returns the number of image planes.
Definition ImageHeader.h:93
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
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
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
static plUInt32 GetBitsPerBlock(Enum format, plUInt32 uiPlaneIndex=0)
Returns the block size in bits. For uncompressed formats, a block is considered a single pixel.
Definition ImageFormat.cpp:466
Definition Image_inl.h:5