Skip to content

Commit fb07309

Browse files
committed
Add P010 HDR10 video format support (signal range is fixed again)
1 parent 85d321e commit fb07309

File tree

15 files changed

+425
-64
lines changed

15 files changed

+425
-64
lines changed

include/lut-calibrator/BestResult.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct BestResult
8080
double upYLimit = 0;
8181
double downYLimit = 0;
8282
double yShift = 0;
83+
bool isSourceP010 = false;
8384
} signal;
8485

8586
long long int minError = MAX_CALIBRATION_ERROR;
@@ -121,6 +122,7 @@ struct BestResult
121122
out << "bestResult.signal.upYLimit = " << std::to_string(signal.upYLimit) << ";" << std::endl;
122123
out << "bestResult.signal.downYLimit = " << std::to_string(signal.downYLimit) << ";" << std::endl;
123124
out << "bestResult.signal.yShift = " << std::to_string(signal.yShift) << ";" << std::endl;
125+
out << "bestResult.signal.isSourceP010 = " << std::to_string(signal.isSourceP010) << ";" << std::endl;
124126
out << "bestResult.minError = " << std::to_string(std::round(minError * 100.0) / 30000.0) << ";" << std::endl;
125127
out << "*/" << std::endl;
126128
}

include/lut-calibrator/BoardUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace BoardUtils
6161
constexpr int SCREEN_CRC_LINES = 2;
6262
constexpr int SCREEN_CRC_COUNT = 5;
6363
constexpr int SCREEN_MAX_CRC_BRIGHTNESS_ERROR = 1;
64-
constexpr int SCREEN_MAX_COLOR_NOISE_ERROR = 8;
64+
constexpr int SCREEN_MAX_COLOR_NOISE_ERROR = 16;
6565
constexpr int SCREEN_SAMPLES_PER_BOARD = (SCREEN_BLOCKS_X / 2) * (SCREEN_BLOCKS_Y - SCREEN_CRC_LINES);
6666
const int SCREEN_LAST_BOARD_INDEX = std::pow(SCREEN_COLOR_DIMENSION, 3) / SCREEN_SAMPLES_PER_BOARD;
6767

include/lut-calibrator/ColorSpace.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ using namespace aliases;
4444

4545
namespace ColorSpaceMath
4646
{
47-
enum PRIMARIES { SRGB = 0, BT_2020, WIDE_GAMMUT };
47+
enum PRIMARIES { SRGB = 0, BT_2020, WIDE_GAMMUT };
4848

4949
QString gammaToString(HDR_GAMMA gamma);
5050

@@ -85,6 +85,8 @@ namespace ColorSpaceMath
8585

8686
double3 bt2020_linear_to_nonlinear(double3 input);
8787

88+
double srgb_nonlinear_to_linear(double input);
89+
8890
double3 srgb_nonlinear_to_linear(double3 input);
8991

9092
double3 srgb_linear_to_nonlinear(double3 input);

include/lut-calibrator/LutCalibrator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace linalg {
5858
}
5959

6060
namespace ColorSpaceMath {
61-
enum HDR_GAMMA { PQ = 0, HLG, sRGB, BT2020inSRGB, PQinSRGB};
61+
enum HDR_GAMMA { PQ = 0, HLG, sRGB, BT2020inSRGB, PQinSRGB, P010 };
6262
}
6363

6464
struct BestResult;

include/utils/FrameDecoder.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@
88
// some stuff for HDR tone mapping
99
#define LUT_INDEX(y,u,v) ((y + (u<<8) + (v<<16))*3)
1010

11+
namespace FrameDecoderUtils
12+
{
13+
double unpackChromaP010(double x);
14+
double unpackLuminanceP010(double val);
15+
}
16+
1117
class FrameDecoder
1218
{
1319
public:
1420
static void processImage(
1521
int _cropLeft, int _cropRight, int _cropTop, int _cropBottom,
1622
const uint8_t* data, const uint8_t* dataUV, int width, int height, int lineLength,
17-
const PixelFormat pixelFormat, const uint8_t* lutBuffer, Image<ColorRgb>& outputImage);
23+
const PixelFormat pixelFormat, const uint8_t* lutBuffer, Image<ColorRgb>& outputImage, bool toneMapping = true);
1824

1925
static void processQImage(
2026
const uint8_t* data, const uint8_t* dataUV, int width, int height, int lineLength,
21-
const PixelFormat pixelFormat, const uint8_t* lutBuffer, Image<ColorRgb>& outputImage);
27+
const PixelFormat pixelFormat, const uint8_t* lutBuffer, Image<ColorRgb>& outputImage, bool toneMapping = true);
2228

2329
static void processSystemImageBGRA(Image<ColorRgb>& image, int targetSizeX, int targetSizeY,
2430
int startX, int startY,

sources/base/Grabber.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void Grabber::setEnabled(bool enable)
101101

102102
void Grabber::setMonitorNits(int nits)
103103
{
104-
if (_targetMonitorNits != nits)
104+
if (static_cast<int>(_targetMonitorNits) != nits)
105105
{
106106
_targetMonitorNits = nits;
107107

sources/grabber/linux/v4l2/V4L2Grabber.cpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,30 @@
6161
// some stuff for HDR tone mapping
6262
#define LUT_FILE_SIZE 50331648
6363

64+
namespace
65+
{
66+
#ifdef V4L2_PIX_FMT_P010
67+
#pragma message "P010 is supported on the build machine"
68+
bool supportedP010 = true;
69+
#else
70+
#pragma message "P010 is NOT supported on the build machine"
71+
bool supportedP010 = false;
72+
#endif
73+
};
74+
75+
#ifndef V4L2_PIX_FMT_P010
76+
#define V4L2_PIX_FMT_P010 v4l2_fourcc('P', '0', '1', '0')
77+
#endif
78+
6479
static const V4L2Grabber::HyperHdrFormat supportedFormats[] =
6580
{
6681
{ V4L2_PIX_FMT_YUYV, PixelFormat::YUYV },
6782
{ V4L2_PIX_FMT_XRGB32, PixelFormat::XRGB },
6883
{ V4L2_PIX_FMT_RGB24, PixelFormat::RGB24 },
6984
{ V4L2_PIX_FMT_YUV420, PixelFormat::I420 },
7085
{ V4L2_PIX_FMT_NV12, PixelFormat::NV12 },
71-
{ V4L2_PIX_FMT_MJPEG, PixelFormat::MJPEG }
72-
#ifdef V4L2_PIX_FMT_P010
73-
,{ V4L2_PIX_FMT_P010, PixelFormat::P010 }
74-
#endif
86+
{ V4L2_PIX_FMT_MJPEG, PixelFormat::MJPEG },
87+
{ V4L2_PIX_FMT_P010, PixelFormat::P010 }
7588
};
7689

7790

@@ -84,6 +97,8 @@ V4L2Grabber::V4L2Grabber(const QString& device, const QString& configurationPath
8497
{
8598
// Refresh devices
8699
getV4L2devices();
100+
101+
Debug(_log, "P010 was %s on the build machine", (supportedP010) ? "supported" : "unsupported");
87102
}
88103

89104
QString V4L2Grabber::GetSharedLut()
@@ -132,7 +147,8 @@ void V4L2Grabber::setHdrToneMappingEnabled(int mode)
132147
{
133148
Debug(_log, "setHdrToneMappingMode replacing LUT and restarting");
134149
_V4L2WorkerManager.Stop();
135-
if ((_actualVideoFormat == PixelFormat::YUYV) || (_actualVideoFormat == PixelFormat::I420) || (_actualVideoFormat == PixelFormat::NV12) || (_actualVideoFormat == PixelFormat::MJPEG))
150+
if ((_actualVideoFormat == PixelFormat::YUYV) || (_actualVideoFormat == PixelFormat::I420) || (_actualVideoFormat == PixelFormat::NV12)
151+
|| (_actualVideoFormat == PixelFormat::P010) || (_actualVideoFormat == PixelFormat::MJPEG))
136152
loadLutFile(PixelFormat::YUYV);
137153
else
138154
loadLutFile(PixelFormat::RGB24);
@@ -985,6 +1001,16 @@ bool V4L2Grabber::init_device(QString selectedDeviceName, DevicePropertiesItem p
9851001
}
9861002
break;
9871003

1004+
case V4L2_PIX_FMT_P010:
1005+
{
1006+
loadLutFile(PixelFormat::YUYV);
1007+
_actualVideoFormat = PixelFormat::P010;
1008+
_frameByteSize = (props.x * props.y * 6) / 2;
1009+
_lineLength = props.x * 2;
1010+
Info(_log, "Video pixel format is set to: P010");
1011+
}
1012+
break;
1013+
9881014
case V4L2_PIX_FMT_NV12:
9891015
{
9901016
loadLutFile(PixelFormat::YUYV);

sources/grabber/linux/v4l2/V4L2Worker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void V4L2Worker::runMe()
201201
{
202202
Image<ColorRgb> image(_width >> 1, _height >> 1);
203203
FrameDecoder::processQImage(
204-
_sharedData, nullptr, _width, _height, _lineLength, _pixelFormat, _lutBuffer, image);
204+
_sharedData, nullptr, _width, _height, _lineLength, _pixelFormat, _lutBuffer, image, _hdrToneMappingEnabled);
205205

206206
image.setBufferCacheSize();
207207
if (!_directAccess)
@@ -222,7 +222,7 @@ void V4L2Worker::runMe()
222222

223223
FrameDecoder::processImage(
224224
_cropLeft, _cropRight, _cropTop, _cropBottom,
225-
_sharedData, nullptr, _width, _height, _lineLength, _pixelFormat, _lutBuffer, image);
225+
_sharedData, nullptr, _width, _height, _lineLength, _pixelFormat, _lutBuffer, image, _hdrToneMappingEnabled);
226226

227227
image.setBufferCacheSize();
228228
if (!_directAccess)

sources/grabber/windows/MF/MFGrabber.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void MFGrabber::setHdrToneMappingEnabled(int mode)
189189
{
190190
Debug(_log, "setHdrToneMappingMode replacing LUT and restarting");
191191
_MFWorkerManager.Stop();
192-
if ((_actualVideoFormat == PixelFormat::YUYV) || (_actualVideoFormat == PixelFormat::I420) || (_actualVideoFormat == PixelFormat::NV12) || (_actualVideoFormat == PixelFormat::MJPEG))
192+
if ((_actualVideoFormat == PixelFormat::YUYV) || (_actualVideoFormat == PixelFormat::I420) || (_actualVideoFormat == PixelFormat::P010) || (_actualVideoFormat == PixelFormat::NV12) || (_actualVideoFormat == PixelFormat::MJPEG))
193193
loadLutFile(PixelFormat::YUYV);
194194
else
195195
loadLutFile(PixelFormat::RGB24);
@@ -869,6 +869,14 @@ bool MFGrabber::init_device(QString selectedDeviceName, DevicePropertiesItem pro
869869
}
870870
break;
871871

872+
case PixelFormat::P010:
873+
{
874+
loadLutFile(PixelFormat::YUYV);
875+
_frameByteSize = (6 * props.x * props.y) / 2;
876+
_lineLength = props.x * 2;
877+
}
878+
break;
879+
872880
case PixelFormat::RGB24:
873881
{
874882
loadLutFile(PixelFormat::RGB24);

sources/grabber/windows/MF/MFWorker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void MFWorker::runMe()
199199
{
200200
Image<ColorRgb> image(_width >> 1, _height >> 1);
201201
FrameDecoder::processQImage(
202-
_localBuffer.data(), nullptr, _width, _height, _lineLength, _pixelFormat, _lutBuffer, image);
202+
_localBuffer.data(), nullptr, _width, _height, _lineLength, _pixelFormat, _lutBuffer, image, _hdrToneMappingEnabled);
203203

204204
image.setBufferCacheSize();
205205
if (!_directAccess)
@@ -218,7 +218,7 @@ void MFWorker::runMe()
218218

219219
FrameDecoder::processImage(
220220
_cropLeft, _cropRight, _cropTop, _cropBottom,
221-
_localBuffer.data(), nullptr, _width, _height, _lineLength, _pixelFormat, _lutBuffer, image);
221+
_localBuffer.data(), nullptr, _width, _height, _lineLength, _pixelFormat, _lutBuffer, image, _hdrToneMappingEnabled);
222222

223223
image.setBufferCacheSize();
224224
if (!_directAccess)

0 commit comments

Comments
 (0)