@@ -44,14 +44,18 @@ static const std::map<PixelFormat, BayerFormat> bayer_formats =
44
44
{ formats::SGRBG12_CSI2P, { " GRBG-12" , 12 , TIFF_GRBG } },
45
45
{ formats::SBGGR12_CSI2P, { " BGGR-12" , 12 , TIFF_BGGR } },
46
46
{ formats::SGBRG12_CSI2P, { " GBRG-12" , 12 , TIFF_GBRG } },
47
+ { formats::SRGGB16, { " RGGB-16" , 16 , TIFF_RGGB } },
48
+ { formats::SGRBG16, { " GRBG-16" , 16 , TIFF_GRBG } },
49
+ { formats::SBGGR16, { " BGGR-16" , 16 , TIFF_BGGR } },
50
+ { formats::SGBRG16, { " GBRG-16" , 16 , TIFF_GBRG } },
47
51
};
48
52
49
- static void unpack_10bit (uint8_t *src, StreamInfo const &info, uint16_t *dest)
53
+ static void unpack_10bit (uint8_t const *src, StreamInfo const &info, uint16_t *dest)
50
54
{
51
55
unsigned int w_align = info.width & ~3 ;
52
56
for (unsigned int y = 0 ; y < info.height ; y++, src += info.stride )
53
57
{
54
- uint8_t *ptr = src;
58
+ uint8_t const *ptr = src;
55
59
unsigned int x;
56
60
for (x = 0 ; x < w_align; x += 4 , ptr += 5 )
57
61
{
@@ -65,12 +69,12 @@ static void unpack_10bit(uint8_t *src, StreamInfo const &info, uint16_t *dest)
65
69
}
66
70
}
67
71
68
- static void unpack_12bit (uint8_t *src, StreamInfo const &info, uint16_t *dest)
72
+ static void unpack_12bit (uint8_t const *src, StreamInfo const &info, uint16_t *dest)
69
73
{
70
74
unsigned int w_align = info.width & ~1 ;
71
75
for (unsigned int y = 0 ; y < info.height ; y++, src += info.stride )
72
76
{
73
- uint8_t *ptr = src;
77
+ uint8_t const *ptr = src;
74
78
unsigned int x;
75
79
for (x = 0 ; x < w_align; x += 2 , ptr += 3 )
76
80
{
@@ -82,6 +86,18 @@ static void unpack_12bit(uint8_t *src, StreamInfo const &info, uint16_t *dest)
82
86
}
83
87
}
84
88
89
+ static void unpack_16bit (uint8_t const *src, StreamInfo const &info, uint16_t *dest)
90
+ {
91
+ /* Assume the pixels in memory are already in native byte order */
92
+ unsigned int w = info.width ;
93
+ for (unsigned int y = 0 ; y < info.height ; y++)
94
+ {
95
+ memcpy (dest, src, 2 * w);
96
+ dest += w;
97
+ src += info.stride ;
98
+ }
99
+ }
100
+
85
101
struct Matrix
86
102
{
87
103
Matrix (float m0, float m1, float m2,
@@ -144,14 +160,13 @@ void dng_save(std::vector<libcamera::Span<uint8_t>> const &mem, StreamInfo const
144
160
145
161
std::vector<uint16_t > buf (info.width * info.height );
146
162
if (bayer_format.bits == 10 )
147
- unpack_10bit (( uint8_t *) mem[0 ].data (), info, &buf[0 ]);
163
+ unpack_10bit (mem[0 ].data (), info, &buf[0 ]);
148
164
else if (bayer_format.bits == 12 )
149
- unpack_12bit (( uint8_t *) mem[0 ].data (), info, &buf[0 ]);
165
+ unpack_12bit (mem[0 ].data (), info, &buf[0 ]);
150
166
else
151
- throw std::runtime_error ( " unsupported bit depth " + std::to_string (bayer_format. bits ) );
167
+ unpack_16bit (mem[ 0 ]. data (), info, &buf[ 0 ] );
152
168
153
169
// We need to fish out some metadata values for the DNG.
154
-
155
170
float black = 4096 * (1 << bayer_format.bits ) / 65536.0 ;
156
171
float black_levels[] = { black, black, black, black };
157
172
auto bl = metadata.get (controls::SensorBlackLevels);
0 commit comments