4#include <Common/assertion.h>
5#include <Common/utility.h>
24 const std::size_t numPicComponents,
28 , m_numComponents(numPicComponents)
29 , m_componentType(componentType)
34 m_data = std::make_unique<std::byte[]>(m_numBytesInData);
37template<
typename PixelData>
40 const std::size_t numPicComponents,
42 const PixelData*
const pixelData,
43 const std::size_t pixelDataSize)
56 *
this = std::move(other);
76 return m_numComponents;
81 return m_componentType;
86 return {m_data.get(), m_numBytesInData};
91 return {m_data.get(), m_numBytesInData};
94template<
typename PixelData>
96 const PixelData*
const pixelData,
97 const std::size_t numPixelDataElements)
107 PH_ASSERT_EQ(m_numBytesInData, numPixelDataElements *
sizeof(PixelData));
114 static_assert(std::is_trivially_copyable_v<PixelData>);
117 reinterpret_cast<const std::byte*
>(pixelData),
118 reinterpret_cast<const std::byte*
>(pixelData + numPixelDataElements),
122template<
typename FrameComponent, std::
size_t N>
125 switch(m_componentType)
128 return pictureToFrame<int8, FrameComponent, N>();
131 return pictureToFrame<uint8, FrameComponent, N>();
134 return pictureToFrame<int16, FrameComponent, N>();
137 return pictureToFrame<uint16, FrameComponent, N>();
140 return pictureToFrame<int32, FrameComponent, N>();
143 return pictureToFrame<uint32, FrameComponent, N>();
146 return pictureToFrame<int64, FrameComponent, N>();
149 return pictureToFrame<uint64, FrameComponent, N>();
152 return pictureToFrame<float32, FrameComponent, N>();
155 return pictureToFrame<float64, FrameComponent, N>();
158 PH_ASSERT_UNREACHABLE_SECTION();
167 return m_data ==
nullptr;
172 m_sizePx = rhs.m_sizePx;
173 m_numComponents = rhs.m_numComponents;
174 m_componentType = rhs.m_componentType;
175 m_data = std::move(rhs.m_data);
176 m_numBytesInData = rhs.m_numBytesInData;
181template<
typename PictureComponent,
typename FrameComponent, std::
size_t N>
186 static_assert(std::is_trivially_copyable_v<PictureComponent>);
187 static_assert(std::is_trivially_copyable_v<FrameComponent>);
192 using FramePixelType =
typename FrameType::PixelType;
196 const std::size_t minComponents = std::min(m_numComponents, N);
199 lossless_cast<uint32>(m_sizePx.
x()),
200 lossless_cast<uint32>(m_sizePx.
y()));
202 [
this, minComponents](
const std::size_t x,
const std::size_t y)
204 FramePixelType pixel;
205 for(std::size_t ci = 0; ci < minComponents; ++ci)
207 const std::size_t byteIndex = getByteIndex<PictureComponent>(x, y, ci);
209 PictureComponent pictureComponent;
211 m_data.get() + byteIndex,
212 m_data.get() + byteIndex +
sizeof(PictureComponent),
213 reinterpret_cast<std::byte*
>(&pictureComponent));
215 pixel[ci] =
static_cast<FrameComponent
>(pictureComponent);
224template<
typename PictureComponent>
225inline std::size_t PictureData::getByteIndex(
226 const std::size_t xPx,
227 const std::size_t yPx,
228 const std::size_t componentIndex)
const
230 PH_ASSERT_LT(xPx, m_sizePx.
x());
231 PH_ASSERT_LT(yPx, m_sizePx.
y());
232 PH_ASSERT_LT(componentIndex, m_numComponents);
234 const auto linearPixelIndex = yPx * m_sizePx.
x() + xPx;
235 return (linearPixelIndex * m_numComponents + componentIndex) *
sizeof(PictureComponent);
Definition PictureData.h:21
const math::Vector2S & getSizePx() const
Definition PictureData.ipp:59
PictureData & operator=(PictureData &&rhs)
Definition PictureData.ipp:170
PictureData()
Creates an empty picture.
Definition PictureData.ipp:14
std::size_t getHeightPx() const
Definition PictureData.ipp:69
TSpan< std::byte > getBytes()
Definition PictureData.ipp:84
EPicturePixelComponent getComponentType() const
Definition PictureData.ipp:79
std::size_t getWidthPx() const
Definition PictureData.ipp:64
bool isEmpty() const
Definition PictureData.ipp:165
void setPixels(const PixelData *pixelData, std::size_t numPixelDataElements)
Set pixel data directly. This method also supports packed pixel data. For example,...
Definition PictureData.ipp:95
TFrame< FrameComponent, N > toFrame() const
Definition PictureData.ipp:123
std::size_t numComponents() const
Definition PictureData.ipp:74
T & x()
Definition TVector2.ipp:38
T & y()
Definition TVector2.ipp:44
T product() const
Definition TArithmeticArrayBase.ipp:358
The root for all renderer implementations.
Definition EEngineProject.h:6
std::span< const T, EXTENT > TSpanView
Same as TSpan, except that the objects are const-qualified. Note that for pointer types,...
Definition TSpan.h:19
EPicturePixelComponent
Definition picture_basics.h:11
std::span< T, EXTENT > TSpan
A contiguous sequence of objects of type T. Effectively the same as std::span.
Definition TSpan.h:12
std::size_t num_bytes_in_component(const EPicturePixelComponent componentType)
Definition picture_basics.h:27