Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
PictureMeta.h
Go to the documentation of this file.
1#pragma once
2
4#include "Math/TVector2.h"
5#include "Utility/TSpan.h"
6
7#include <Common/assertion.h>
8
9#include <cstddef>
10#include <vector>
11#include <string>
12
13namespace ph
14{
15
16class PictureMeta final
17{
18public:
19 std::size_t numLayers() const;
20 std::size_t numChannels(std::size_t layerIdx = 0) const;
21
22 std::size_t addDefaultLayer();
23 std::size_t addEmptyLayer();
24
28 std::string& pictureName();
29 const std::string& getPictureName() const;
31
35 std::string& name(std::size_t layerIdx = 0);
36 const std::string& getName(std::size_t layerIdx = 0) const;
38
39 math::Vector2S& sizePx(std::size_t layerIdx = 0);
40 math::EColorSpace& colorSpace(std::size_t layerIdx = 0);
41
44 void setNumChannels(std::size_t numChannels, std::size_t layerIdx = 0);
45
52 TSpan<std::string> channelNames(std::size_t layerIdx = 0);
53 TSpanView<std::string> getChannelNames(std::size_t layerIdx = 0) const;
55
56 const math::Vector2S& getSizePx(std::size_t layerIdx = 0) const;
57 const math::EColorSpace& getColorSpace(std::size_t layerIdx = 0) const;
58
59private:
60 struct Layer
61 {
62 std::string name;
63 math::Vector2S sizePx = {0, 0};
65 std::vector<std::string> channelNames = {"R", "G", "B"};
66 };
67
68 auto getLayer(std::size_t layerIdx) -> Layer&;
69 auto getLayer(std::size_t layerIdx) const -> const Layer&;
70
71 std::string m_pictureName;
72 std::vector<Layer> m_layers;
73};
74
75inline std::size_t PictureMeta::numLayers() const
76{
77 return m_layers.size();
78}
79
80inline std::size_t PictureMeta::numChannels(std::size_t layerIdx) const
81{
82 return getLayer(layerIdx).channelNames.size();
83}
84
85inline std::size_t PictureMeta::addDefaultLayer()
86{
87 m_layers.push_back(Layer{});
88 return m_layers.size() - 1;
89}
90
91inline std::size_t PictureMeta::addEmptyLayer()
92{
93 Layer layer;
94 layer.name = "";
95 layer.sizePx = {0, 0};
96 layer.colorSpace = math::EColorSpace::Unspecified;
97 layer.channelNames.clear();
98
99 m_layers.push_back(layer);
100 return m_layers.size() - 1;
101}
102
103inline std::string& PictureMeta::pictureName()
104{
105 return m_pictureName;
106}
107
108inline std::string& PictureMeta::name(std::size_t layerIdx)
109{
110 return getLayer(layerIdx).name;
111}
112
113inline math::Vector2S& PictureMeta::sizePx(std::size_t layerIdx)
114{
115 return getLayer(layerIdx).sizePx;
116}
117inline math::EColorSpace& PictureMeta::colorSpace(std::size_t layerIdx)
118{
119 return getLayer(layerIdx).colorSpace;
120}
121
122inline void PictureMeta::setNumChannels(std::size_t numChannels, std::size_t layerIdx)
123{
124 getLayer(layerIdx).channelNames.resize(numChannels, "");
125}
126
128{
129 return getLayer(layerIdx).channelNames;
130}
131
132inline const std::string& PictureMeta::getPictureName() const
133{
134 return m_pictureName;
135}
136
137inline const std::string& PictureMeta::getName(std::size_t layerIdx) const
138{
139 return getLayer(layerIdx).name;
140}
141
142inline const math::Vector2S& PictureMeta::getSizePx(std::size_t layerIdx) const
143{
144 return getLayer(layerIdx).sizePx;
145}
146
147inline const math::EColorSpace& PictureMeta::getColorSpace(std::size_t layerIdx) const
148{
149 return getLayer(layerIdx).colorSpace;
150}
151
152inline TSpanView<std::string> PictureMeta::getChannelNames(std::size_t layerIdx) const
153{
154 return getLayer(layerIdx).channelNames;
155}
156
157inline auto PictureMeta::getLayer(std::size_t layerIdx) -> Layer&
158{
159 PH_ASSERT_LT(layerIdx, m_layers.size());
160 return m_layers[layerIdx];
161}
162
163inline auto PictureMeta::getLayer(std::size_t layerIdx) const -> const Layer&
164{
165 PH_ASSERT_LT(layerIdx, m_layers.size());
166 return m_layers[layerIdx];
167}
168
169}// end namespace ph
Definition PictureMeta.h:17
std::size_t numLayers() const
Definition PictureMeta.h:75
const std::string & getName(std::size_t layerIdx=0) const
Definition PictureMeta.h:137
const math::Vector2S & getSizePx(std::size_t layerIdx=0) const
Definition PictureMeta.h:142
void setNumChannels(std::size_t numChannels, std::size_t layerIdx=0)
Set the number of channels.
Definition PictureMeta.h:122
std::size_t numChannels(std::size_t layerIdx=0) const
Definition PictureMeta.h:80
std::string & name(std::size_t layerIdx=0)
Access to the name of a layer.
Definition PictureMeta.h:108
TSpan< std::string > channelNames(std::size_t layerIdx=0)
Access to the name of a channel. Some formats have the ability to give names to their color/data chan...
Definition PictureMeta.h:127
math::EColorSpace & colorSpace(std::size_t layerIdx=0)
Definition PictureMeta.h:117
TSpanView< std::string > getChannelNames(std::size_t layerIdx=0) const
Definition PictureMeta.h:152
std::size_t addEmptyLayer()
Definition PictureMeta.h:91
math::Vector2S & sizePx(std::size_t layerIdx=0)
Definition PictureMeta.h:113
std::string & pictureName()
Access to the name of the picture.
Definition PictureMeta.h:103
const math::EColorSpace & getColorSpace(std::size_t layerIdx=0) const
Definition PictureMeta.h:147
const std::string & getPictureName() const
Definition PictureMeta.h:132
std::size_t addDefaultLayer()
Definition PictureMeta.h:85
EColorSpace
Definition color_enums.h:7
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
std::span< T, EXTENT > TSpan
A contiguous sequence of objects of type T. Effectively the same as std::span.
Definition TSpan.h:12