Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
GammaCorrection.h
Go to the documentation of this file.
1#pragma once
2
4#include "Core/Quantity/ColorSpace.h"
5#include "Math/TVector3.h"
6
7#include <Common/assertion.h>
8#include <Common/primitive_type.h>
9
10#include <cmath>
11
12namespace ph
13{
14
16{
17public:
18 explicit GammaCorrection(real gamma);
19
20 void operate(const HdrRgbFrame& srcFrame, HdrRgbFrame* out_dstFrame) override;
21
22 void useSrgbStandard(bool value);
23
24private:
25 real m_reciGamma;
26 bool m_useSrgbStandard;
27};
28
29// In-header Implementations:
30
31inline GammaCorrection::GammaCorrection(const real gamma) :
32 m_reciGamma(1.0_r / gamma), m_useSrgbStandard(true)
33{}
34
35inline void GammaCorrection::operate(const HdrRgbFrame& srcFrame, HdrRgbFrame* const out_dstFrame)
36{
37 PH_ASSERT(out_dstFrame);
38
39 out_dstFrame->setSize(srcFrame.getSizePx());
40
41 if(m_useSrgbStandard)
42 {
43 srcFrame.forEachPixel(
44 [this, out_dstFrame]
45 (const uint32 x, const uint32 y, const HdrRgbFrame::PixelType& srcPixel)
46 {
47 const math::Vector3R linearSrgb(srcPixel[0], srcPixel[1], srcPixel[2]);
48 const math::Vector3R srgb = ColorSpace::linear_sRGB_to_sRGB(linearSrgb);
49
50 out_dstFrame->setPixel(x, y, HdrRgbFrame::PixelType({srgb.x, srgb.y, srgb.z}));
51 });
52 }
53 else
54 {
55 srcFrame.forEachPixel(
56 [this, out_dstFrame]
57 (const uint32 x, const uint32 y, const HdrRgbFrame::PixelType& pixel)
58 {
59 const math::Vector3R rgb(
60 std::pow(pixel[0], m_reciGamma),
61 std::pow(pixel[1], m_reciGamma),
62 std::pow(pixel[2], m_reciGamma));
63
64 out_dstFrame->setPixel(x, y, HdrRgbFrame::PixelType({rgb.x, rgb.y, rgb.z}));
65 });
66 }
67}
68
69inline void GammaCorrection::useSrgbStandard(const bool value)
70{
71 m_useSrgbStandard = value;
72}
73
74}// end namespace ph
Definition FrameOperator.h:9
Definition GammaCorrection.h:16
GammaCorrection(real gamma)
Definition GammaCorrection.h:31
void operate(const HdrRgbFrame &srcFrame, HdrRgbFrame *out_dstFrame) override
Definition GammaCorrection.h:35
void useSrgbStandard(bool value)
Definition GammaCorrection.h:69
void forEachPixel(PerPixelOperation op)
Iterate over all pixels in the frame in row-major order.
Definition TFrame.ipp:252
void setPixel(const math::TVector2< uint32 > &coordPx, const PixelType &pixel)
Definition TFrame.ipp:370
math::TVector2< uint32 > getSizePx() const
Definition TFrame.ipp:428
void setSize(uint32 wPx, uint32 hPx)
Definition TFrame.ipp:237
Definition TArithmeticArray.h:13
T & y()
Definition TVector3.ipp:189
T & z()
Definition TVector3.ipp:195
T & x()
Definition TVector3.ipp:183
The root for all renderer implementations.
Definition EEngineProject.h:6