NDEVR
API Documentation
RasterHelperFunctions.h
1#pragma once
2#include "RasterFrame.h"
3#include "Base/Headers/RGBColor.h"
4namespace NDEVR
5{
8 # define Y_OFFSET 16
9 # define UV_OFFSET 128
10 # define YUV2RGB_11 298
11 # define YUV2RGB_12 -1
12 # define YUV2RGB_13 409
13 # define YUV2RGB_22 -100
14 # define YUV2RGB_23 -210
15 # define YUV2RGB_32 519
16 # define YUV2RGB_33 0
21 static inline RGBColor PullAsYUV(const VideoFrameDetails&, int Text_Index, const uint01* memory)
22 {
23 int value = ((Text_Index - (Text_Index % 2)) * 2);
24 int y, u, v;
25 int uv_r, uv_g, uv_b;
26
27 if (Text_Index % 2 == 0)
28 {
29 y = YUV2RGB_11 * (memory[value] - Y_OFFSET);
30 }
31 else
32 {
33 y = YUV2RGB_11 * (memory[value + 2] - Y_OFFSET);
34 }
35 u = memory[value + 1] - UV_OFFSET;
36 v = memory[value + 3] - UV_OFFSET;
37
38 uv_r = YUV2RGB_12 * u + YUV2RGB_13 * v;
39 uv_g = YUV2RGB_22 * u + YUV2RGB_23 * v;
40 uv_b = YUV2RGB_32 * u + YUV2RGB_33 * v;
41
42 return RGBColor(
43 clip((y + uv_r) >> 8, 0, 255)
44 , clip((y + uv_g) >> 8, 0, 255)
45 , clip((y + uv_b) >> 8, 0, 255));
46
47
48 }
49
54 static inline RGBColor PullAsRGB(const VideoFrameDetails& texture, int Text_Index, const uint01* memory)
55 {
56 int value = Text_Index * texture.bytes_per_pixel;
57 return RGBColor(memory[value], memory[value + 1], memory[value + 2], 255U);
58 }
59
64 static inline RGBColor PullAsBGR(const VideoFrameDetails& texture, int Text_Index, const uint01* memory)
65 {
66 int value = Text_Index * texture.bytes_per_pixel;
67 return RGBColor(memory[value + 2], memory[value + 1], memory[value + 0], 255U);
68 }
69
74 static inline RGBColor PullAsY8(const VideoFrameDetails& texture, int Text_Index, const uint01* memory)
75 {
76 int value = Text_Index * texture.bytes_per_pixel;
77 return RGBColor(memory[value], memory[value], memory[value], 255U);
78 }
79
85 static inline RGBColor PullRGB(const VideoFrameDetails& texture, int index, const uint01* memory)
86 {
87 switch (texture.format)
88 {
89 case RasterColorFormat::e_bgr: return PullAsBGR(texture, index, memory);
90 case RasterColorFormat::e_rgb: return PullAsRGB(texture, index, memory);
91 case RasterColorFormat::e_y8: return PullAsY8(texture, index, memory);
92 case RasterColorFormat::e_yuv: return PullAsYUV(texture, index, memory);
93 default: lib_assert(false, "unknown format"); return Constant<RGBColor>::Invalid;
94 }
95 }
96
102 static inline fltp04 PullDepth(const VideoFrameDetails& texture, int index, const uint01* memory)
103 {
104 uint64_t pixel = 0;
105 switch (texture.bytes_per_pixel) // bits per pixel
106 {
107 case 1:
108 pixel = memory[index];
109 break;
110 case 2:
111 pixel = reinterpret_cast<const uint16_t*>(memory)[index];
112 break;
113 case 4:
114 pixel = reinterpret_cast<const uint32_t*>(memory)[index];
115 break;
116 case 8:
117 pixel = reinterpret_cast<const uint64_t*>(memory)[index];
118 break;
119 }
120 return cast<fltp04>(pixel);
121 }
122}
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:57
The primary namespace for the NDEVR SDK.
static RGBColor PullAsRGB(const VideoFrameDetails &texture, int Text_Index, const uint01 *memory)
Extract an RGB color from a pixel in RGB byte order.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
static RGBColor PullAsYUV(const VideoFrameDetails &, int Text_Index, const uint01 *memory)
Convert a YUV 4:2:2 pixel to an RGBColor.
static RGBColor PullAsY8(const VideoFrameDetails &texture, int Text_Index, const uint01 *memory)
Extract an RGB color from an 8-bit grayscale pixel.
static RGBColor PullRGB(const VideoFrameDetails &texture, int index, const uint01 *memory)
Extract an RGB color from a pixel, dispatching to the correct format converter.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
static RGBColor PullAsBGR(const VideoFrameDetails &texture, int Text_Index, const uint01 *memory)
Extract an RGB color from a pixel in BGR byte order.
@ e_bgr
Blue-Green-Red byte order.
Definition RasterFrame.h:33
@ e_y8
8-bit grayscale
Definition RasterFrame.h:35
@ e_rgb
Red-Green-Blue byte order.
Definition RasterFrame.h:32
@ e_yuv
YUV 4:2:2 packed format.
Definition RasterFrame.h:34
static fltp04 PullDepth(const VideoFrameDetails &texture, int index, const uint01 *memory)
Extract a depth value from a pixel, handling 1/2/4/8 byte depths.
constexpr t_type clip(const t_type &value, const t_type &lower_bound, const t_type &upper_bound)
Clips the value given so that that the returned value falls between upper and lower bound.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408
Describes the pixel format and dimensions of a video frame from a raster camera.
Definition RasterFrame.h:79
RasterColorFormat format
Pixel color format.
Definition RasterFrame.h:80
uint04 bytes_per_pixel
Number of bytes per pixel.
Definition RasterFrame.h:83