IRSOL
C++ code implementing socket server for interacting with Baumer camera.
pixel_format.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include "irsol/assert.hpp"
9#include "irsol/macros.hpp"
10
11#include <algorithm>
12#include <stdint.h>
13
14namespace irsol {
15
16namespace camera {
17
33template<uint8_t BitDepth>
34struct PixelRepresentation; // no default definition on purpose
35
39template<>
41{
42 using type = uint8_t;
43};
44
51template<>
53{
54 using type = uint16_t;
55};
56
62template<>
64{
65 using type = uint16_t;
66};
67
76template<uint8_t BitDepth>
77struct Pixel
78{
81
89 static constexpr uint64_t max()
90 {
91 return (1ULL << BitDepth) - 1;
92 }
93
99 static constexpr uint64_t min()
100 {
101 return 0;
102 }
103};
104
121template<uint8_t SourceBitDepth, uint8_t TargetBitDepth>
123{
125 static constexpr double factor =
127
139 {
140 auto rawScale = factor * value;
141 return static_cast<typename Pixel<TargetBitDepth>::representation>(
142 std::min(rawScale, static_cast<decltype(rawScale)>(Pixel<TargetBitDepth>::max())));
143 }
144};
145
156template<bool swap>
158{
159 template<typename Iterator>
160 void operator()(IRSOL_MAYBE_UNUSED Iterator begin, IRSOL_MAYBE_UNUSED Iterator end) const
161 {
163 begin <= end, "PixelByteSwapper: begin iterator must not be after end iterator");
164 // No-op for swap == false
165 }
166};
167
168template<>
170{
171 template<typename Iterator>
172 void operator()(Iterator begin, Iterator end) const
173 {
175 begin <= end, "PixelByteSwapper: begin iterator must not be after end iterator");
176 // Assumes 16-bit data: swap each pair of bytes in-place
177 for(auto it = begin; it != end; ++it) {
178 auto next = std::next(it);
179 if(next == end)
180 break;
181 std::iter_swap(it, next);
182 ++it;
183 }
184 }
185};
186
187} // namespace camera
188} // namespace irsol
Assertion macros and utilities based on the PPK_ASSERT library.
#define IRSOL_ASSERT_ERROR
Error-level assertion macro.
Definition assert.hpp:134
Common portability and diagnostic macros for the irsol library.
#define IRSOL_MAYBE_UNUSED
Suppresses compiler warnings about unused variables or parameters.
Definition macros.hpp:39
void operator()(Iterator begin, Iterator end) const
Utility for swapping pixel bytes in a buffer.
void operator()(IRSOL_MAYBE_UNUSED Iterator begin, IRSOL_MAYBE_UNUSED Iterator end) const
Helper to convert pixel values from one bit depth to another with scaling.
static constexpr double factor
Compile-time scaling factor: max(Target) / max(Source)
static Pixel< TargetBitDepth >::representation scale(typename Pixel< SourceBitDepth >::representation value)
Scales a pixel value from source bit depth to target bit depth.
Helper trait to map a pixel bit depth to an appropriate integral representation type.
Represents a pixel with a given bit depth.
typename PixelRepresentation< BitDepth >::type representation
The integral type used to represent pixel values at this bit depth.
static constexpr uint64_t max()
Returns the maximum representable pixel value for this bit depth.
static constexpr uint64_t min()
Returns the minimum representable pixel value (always zero).
auto value