@@ -142,36 +142,101 @@ class NVSurfaceToColorConverterImpl : public NVSurfaceToColorConverter {
142
142
const bool yuv420 = surfaceFormat == SurfaceFormat::SF_NV12 || surfaceFormat == SurfaceFormat::SF_P016;
143
143
CV_Assert (yuv.cols () % 2 == 0 );
144
144
145
- typedef void (*func_t )(uint8_t * yuv, int yuvPitch, uint8_t * color, int colorPitch, int width, int height, bool videoFullRangeFlag, cudaStream_t stream);
146
- static const func_t funcs[4 ][5 ][2 ][2 ] =
145
+ using func_t = void (*)(uint8_t * yuv, int yuvPitch, uint8_t * color, int colorPitch, int width, int height, bool videoFullRangeFlag, cudaStream_t stream);
146
+
147
+ static const func_t funcsNV12[5 ][2 ][2 ] =
148
+ {
149
+ {
150
+ { Nv12ToColor24<BGR24>, Nv12ToColorPlanar24<BGR24> },
151
+ { Nv12ToColor48<BGR48>, Nv12ToColorPlanar48<BGR48> }
152
+ },
153
+ {
154
+ { Nv12ToColor24<RGB24>, Nv12ToColorPlanar24<RGB24> },
155
+ { Nv12ToColor48<RGB48>, Nv12ToColorPlanar48<RGB48> }
156
+ },
157
+ {
158
+ { Nv12ToColor32<BGRA32>, Nv12ToColorPlanar32<BGRA32> },
159
+ { Nv12ToColor64<BGRA64>, Nv12ToColorPlanar64<BGRA64> }
160
+ },
161
+ {
162
+ { Nv12ToColor32<RGBA32>, Nv12ToColorPlanar32<RGBA32> },
163
+ { Nv12ToColor64<RGBA64>, Nv12ToColorPlanar64<RGBA64> }
164
+ },
165
+ {
166
+ { Y8ToGray8, Y8ToGray8 },
167
+ { Y8ToGray16, Y8ToGray16 }
168
+ }
169
+ };
170
+
171
+ static const func_t funcsP016[5 ][2 ][2 ] =
172
+ {
173
+ {
174
+ { P016ToColor24<BGR24>, P016ToColorPlanar24<BGR24> },
175
+ { P016ToColor48<BGR48>, P016ToColorPlanar48<BGR48> }
176
+ },
177
+ {
178
+ { P016ToColor24<RGB24>, P016ToColorPlanar24<RGB24> },
179
+ { P016ToColor48<RGB48>, P016ToColorPlanar48<RGB48> }
180
+ },
181
+ {
182
+ { P016ToColor32<BGRA32>, P016ToColorPlanar32<BGRA32> },
183
+ { P016ToColor64<BGRA64>, P016ToColorPlanar64<BGRA64> }
184
+ },
185
+ {
186
+ { P016ToColor32<RGBA32>, P016ToColorPlanar32<RGBA32> },
187
+ { P016ToColor64<RGBA64>, P016ToColorPlanar64<RGBA64> }
188
+ },
189
+ {
190
+ { Y16ToGray8, Y16ToGray8 },
191
+ { Y16ToGray16, Y16ToGray16 }
192
+ }
193
+ };
194
+
195
+ static const func_t funcsYUV444[5 ][2 ][2 ] =
147
196
{
148
197
{
149
- {{{Nv12ToColor24<BGR24>},{Nv12ToColorPlanar24<BGR24>}},{{Nv12ToColor48<BGR48>},{Nv12ToColorPlanar48<BGR48>}}},
150
- {{{Nv12ToColor24<RGB24>},{Nv12ToColorPlanar24<RGB24>}},{{Nv12ToColor48<RGB48>},{Nv12ToColorPlanar48<RGB48>}}},
151
- {{{Nv12ToColor32<BGRA32>},{Nv12ToColorPlanar32<BGRA32>}},{{Nv12ToColor64<BGRA64>},{Nv12ToColorPlanar64<BGRA64>}}},
152
- {{{Nv12ToColor32<RGBA32>},{Nv12ToColorPlanar32<RGBA32>}},{{Nv12ToColor64<RGBA64>},{Nv12ToColorPlanar64<RGBA64>}}},
153
- {{{Y8ToGray8},{Y8ToGray8}},{{Y8ToGray16},{Y8ToGray16}}}
198
+ { YUV444ToColor24<BGR24>, YUV444ToColorPlanar24<BGR24> },
199
+ { YUV444ToColor48<BGR48>, YUV444ToColorPlanar48<BGR48> }
200
+ },
201
+ {
202
+ { YUV444ToColor24<RGB24>, YUV444ToColorPlanar24<RGB24> },
203
+ { YUV444ToColor48<RGB48>, YUV444ToColorPlanar48<RGB48> }
154
204
},
155
205
{
156
- {{{P016ToColor24<BGR24>},{P016ToColorPlanar24<BGR24>}},{{P016ToColor48<BGR48>},{P016ToColorPlanar48<BGR48>}}},
157
- {{{P016ToColor24<RGB24>},{P016ToColorPlanar24<RGB24>}},{{P016ToColor48<RGB48>},{P016ToColorPlanar48<RGB48>}}},
158
- {{{P016ToColor32<BGRA32>},{P016ToColorPlanar32<BGRA32>}},{{P016ToColor64<BGRA64>},{P016ToColorPlanar64<BGRA64>}}},
159
- {{{P016ToColor32<RGBA32>},{P016ToColorPlanar32<RGBA32>}},{{P016ToColor64<RGBA64>},{P016ToColorPlanar64<RGBA64>}}},
160
- {{{Y16ToGray8},{Y16ToGray8}},{{Y16ToGray16},{Y16ToGray16}}}
206
+ { YUV444ToColor32<BGRA32>, YUV444ToColorPlanar32<BGRA32> },
207
+ { YUV444ToColor64<BGRA64>, YUV444ToColorPlanar64<BGRA64> }
161
208
},
162
209
{
163
- {{{YUV444ToColor24<BGR24>},{YUV444ToColorPlanar24<BGR24>}},{{YUV444ToColor48<BGR48>},{YUV444ToColorPlanar48<BGR48>}}},
164
- {{{YUV444ToColor24<RGB24>},{YUV444ToColorPlanar24<RGB24>}},{{YUV444ToColor48<RGB48>},{YUV444ToColorPlanar48<RGB48>}}},
165
- {{{YUV444ToColor32<BGRA32>},{YUV444ToColorPlanar32<BGRA32>}},{{YUV444ToColor64<BGRA64>},{YUV444ToColorPlanar64<BGRA64>}}},
166
- {{{YUV444ToColor32<RGBA32>},{YUV444ToColorPlanar32<RGBA32>}},{{YUV444ToColor64<RGBA64>},{YUV444ToColorPlanar64<RGBA64>}}},
167
- {{{Y8ToGray8},{Y8ToGray8}},{{Y8ToGray16},{Y8ToGray16}}}
210
+ { YUV444ToColor32<RGBA32>, YUV444ToColorPlanar32<RGBA32> },
211
+ { YUV444ToColor64<RGBA64>, YUV444ToColorPlanar64<RGBA64> }
168
212
},
169
213
{
170
- {{{YUV444P16ToColor24<BGR24>},{YUV444P16ToColorPlanar24<BGR24>}},{{YUV444P16ToColor48<BGR48>},{YUV444P16ToColorPlanar48<BGR48>}}},
171
- {{{YUV444P16ToColor24<RGB24>},{YUV444P16ToColorPlanar24<RGB24>}},{{YUV444P16ToColor48<RGB48>},{YUV444P16ToColorPlanar48<RGB48>}}},
172
- {{{YUV444P16ToColor32<BGRA32>},{YUV444P16ToColorPlanar32<BGRA32>}},{{YUV444P16ToColor64<BGRA64>},{YUV444P16ToColorPlanar64<BGRA64>}}},
173
- {{{YUV444P16ToColor32<RGBA32>},{YUV444P16ToColorPlanar32<RGBA32>}},{{YUV444P16ToColor64<RGBA64>},{YUV444P16ToColorPlanar64<RGBA64>}}},
174
- {{{Y16ToGray8},{Y16ToGray8}},{{Y16ToGray16},{Y16ToGray16}}}
214
+ { Y8ToGray8, Y8ToGray8 },
215
+ { Y8ToGray16, Y8ToGray16 }
216
+ }
217
+ };
218
+
219
+ static const func_t funcsYUV444P16[5 ][2 ][2 ] =
220
+ {
221
+ {
222
+ { YUV444P16ToColor24<BGR24>, YUV444P16ToColorPlanar24<BGR24> },
223
+ { YUV444P16ToColor48<BGR48>, YUV444P16ToColorPlanar48<BGR48> }
224
+ },
225
+ {
226
+ { YUV444P16ToColor24<RGB24>, YUV444P16ToColorPlanar24<RGB24> },
227
+ { YUV444P16ToColor48<RGB48>, YUV444P16ToColorPlanar48<RGB48> }
228
+ },
229
+ {
230
+ { YUV444P16ToColor32<BGRA32>, YUV444P16ToColorPlanar32<BGRA32> },
231
+ { YUV444P16ToColor64<BGRA64>, YUV444P16ToColorPlanar64<BGRA64> }
232
+ },
233
+ {
234
+ { YUV444P16ToColor32<RGBA32>, YUV444P16ToColorPlanar32<RGBA32> },
235
+ { YUV444P16ToColor64<RGBA64>, YUV444P16ToColorPlanar64<RGBA64> }
236
+ },
237
+ {
238
+ { Y16ToGray8, Y16ToGray8 },
239
+ { Y16ToGray16, Y16ToGray16 }
175
240
}
176
241
};
177
242
@@ -183,11 +248,31 @@ class NVSurfaceToColorConverterImpl : public NVSurfaceToColorConverter {
183
248
const int nChannels = NumChannels (outputFormat);
184
249
const int nRowsOut = nRows * (planar ? nChannels : 1 );
185
250
const BitDepth bitDepth_ = GetBitDepthOut (bitDepth, yuv.depth ());
251
+ const int iBitDepth = bitDepth_ == BitDepth::EIGHT ? 0 : 1 ;
186
252
const int typeOut = CV_MAKE_TYPE (bitDepth_ == BitDepth::EIGHT ? CV_8U : CV_16U, planar ? 1 : nChannels);
187
253
GpuMat out_ = getOutputMat (out, nRowsOut, yuv.cols (), typeOut, stream);
188
254
255
+ const int iSurfaceFormat = static_cast <int >(surfaceFormat);
256
+ const int iPlanar = planar ? 1 : 0 ;
189
257
const int iOutputFormat = OutputColorFormatIdx (outputFormat);
190
- const func_t func = funcs[static_cast <int >(surfaceFormat)][iOutputFormat][static_cast <int >(bitDepth_)][planar];
258
+ func_t func = nullptr ;
259
+
260
+ switch (iSurfaceFormat)
261
+ {
262
+ case 0 :
263
+ func = funcsNV12[iOutputFormat][iBitDepth][iPlanar];
264
+ break ;
265
+ case 1 :
266
+ func = funcsP016[iOutputFormat][iBitDepth][iPlanar];
267
+ break ;
268
+ case 2 :
269
+ func = funcsYUV444[iOutputFormat][iBitDepth][iPlanar];
270
+ break ;
271
+ case 3 :
272
+ func = funcsYUV444P16[iOutputFormat][iBitDepth][iPlanar];
273
+ break ;
274
+ }
275
+
191
276
if (!func)
192
277
CV_Error (Error::StsUnsupportedFormat, " Unsupported combination of source and destination types" );
193
278
0 commit comments