color.cpp 53 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
//                           License Agreement
//                For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//
//   * The name of the copyright holders may not be used to endorse or promote products
//     derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

#include "precomp.hpp"

using namespace cv;
using namespace cv::gpu;

#if !defined (HAVE_CUDA)

50
void cv::gpu::cvtColor(const GpuMat&, GpuMat&, int, int, Stream&) { throw_nogpu(); }
51
void cv::gpu::swapChannels(GpuMat&, const int[], Stream&) { throw_nogpu(); }
52 53 54

#else /* !defined (HAVE_CUDA) */

55
namespace cv { namespace gpu { namespace device
56
{
57 58 59 60 61 62 63 64 65 66 67 68 69 70
#define OPENCV_GPU_DECLARE_CVTCOLOR_ONE(name) \
    void name(const DevMem2Db& src, const DevMem2Db& dst, cudaStream_t stream);

#define OPENCV_GPU_DECLARE_CVTCOLOR_ALL(name) \
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(name ## _8u) \
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(name ## _16u) \
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(name ## _32f)

#define OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(name) \
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(name ## _8u) \
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(name ## _32f) \
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(name ## _full_8u) \
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(name ## _full_32f)

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgr_to_rgb)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgr_to_bgra)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgr_to_rgba)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgra_to_bgr)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgra_to_rgb)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgra_to_rgba)

    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(bgr_to_bgr555)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(bgr_to_bgr565)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(rgb_to_bgr555)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(rgb_to_bgr565)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(bgra_to_bgr555)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(bgra_to_bgr565)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(rgba_to_bgr555)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(rgba_to_bgr565)

    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(bgr555_to_rgb)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(bgr565_to_rgb)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(bgr555_to_bgr)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(bgr565_to_bgr)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(bgr555_to_rgba)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(bgr565_to_rgba)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(bgr555_to_bgra)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(bgr565_to_bgra)

    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(gray_to_bgr)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(gray_to_bgra)

    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(gray_to_bgr555)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(gray_to_bgr565)

    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(bgr555_to_gray)
    OPENCV_GPU_DECLARE_CVTCOLOR_ONE(bgr565_to_gray)

    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(rgb_to_gray)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgr_to_gray)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(rgba_to_gray)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgra_to_gray)

    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(rgb_to_yuv)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(rgba_to_yuv)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(rgb_to_yuv4)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(rgba_to_yuv4)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgr_to_yuv)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgra_to_yuv)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgr_to_yuv4)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgra_to_yuv4)

    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(yuv_to_rgb)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(yuv_to_rgba)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(yuv4_to_rgb)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(yuv4_to_rgba)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(yuv_to_bgr)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(yuv_to_bgra)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(yuv4_to_bgr)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(yuv4_to_bgra)

    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(rgb_to_YCrCb)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(rgba_to_YCrCb)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(rgb_to_YCrCb4)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(rgba_to_YCrCb4)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgr_to_YCrCb)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgra_to_YCrCb)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgr_to_YCrCb4)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgra_to_YCrCb4)

    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(YCrCb_to_rgb)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(YCrCb_to_rgba)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(YCrCb4_to_rgb)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(YCrCb4_to_rgba)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(YCrCb_to_bgr)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(YCrCb_to_bgra)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(YCrCb4_to_bgr)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(YCrCb4_to_bgra)

    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(rgb_to_xyz)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(rgba_to_xyz)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(rgb_to_xyz4)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(rgba_to_xyz4)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgr_to_xyz)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgra_to_xyz)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgr_to_xyz4)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(bgra_to_xyz4)

    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(xyz_to_rgb)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(xyz4_to_rgb)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(xyz_to_rgba)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(xyz4_to_rgba)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(xyz_to_bgr)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(xyz4_to_bgr)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(xyz_to_bgra)
    OPENCV_GPU_DECLARE_CVTCOLOR_ALL(xyz4_to_bgra)

    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(rgb_to_hsv)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(rgba_to_hsv)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(rgb_to_hsv4)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(rgba_to_hsv4)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(bgr_to_hsv)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(bgra_to_hsv)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(bgr_to_hsv4)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(bgra_to_hsv4)

    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hsv_to_rgb)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hsv_to_rgba)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hsv4_to_rgb)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hsv4_to_rgba)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hsv_to_bgr)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hsv_to_bgra)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hsv4_to_bgr)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hsv4_to_bgra)

    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(rgb_to_hls)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(rgba_to_hls)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(rgb_to_hls4)
185

186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(rgba_to_hls4)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(bgr_to_hls)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(bgra_to_hls)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(bgr_to_hls4)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(bgra_to_hls4)

    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hls_to_rgb)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hls_to_rgba)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hls4_to_rgb)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hls4_to_rgba)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hls_to_bgr)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hls_to_bgra)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hls4_to_bgr)
    OPENCV_GPU_DECLARE_CVTCOLOR_8U32F(hls4_to_bgra)

    #undef OPENCV_GPU_DECLARE_CVTCOLOR_ONE
    #undef OPENCV_GPU_DECLARE_CVTCOLOR_ALL
    #undef OPENCV_GPU_DECLARE_CVTCOLOR_8U32F
}}}

using namespace ::cv::gpu::device;
207

208 209
namespace
{
210
    typedef void (*gpu_func_t)(const DevMem2Db& src, const DevMem2Db& dst, cudaStream_t stream);
211

212 213
    void bgr_to_rgb(const GpuMat& src, GpuMat& dst, int, Stream& stream)
    {
214
        using namespace cv::gpu::device;
215
        static const gpu_func_t funcs[] = {bgr_to_rgb_8u, 0, bgr_to_rgb_16u, 0, 0, bgr_to_rgb_32f};
216

217 218
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3);
219

220
        dst.create(src.size(), CV_MAKETYPE(src.depth(), 3));
221

222 223
        funcs[src.depth()](src, dst, StreamAccessor::getStream(stream));
    }
224

225 226
    void bgr_to_bgra(const GpuMat& src, GpuMat& dst, int, Stream& stream)
    {
227
        using namespace cv::gpu::device;
228
        static const gpu_func_t funcs[] = {bgr_to_bgra_8u, 0, bgr_to_bgra_16u, 0, 0, bgr_to_bgra_32f};
229

230 231 232
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3);

233
        dst.create(src.size(), CV_MAKETYPE(src.depth(), 4));
234 235 236

        funcs[src.depth()](src, dst, StreamAccessor::getStream(stream));
    }
237

238 239
    void bgr_to_rgba(const GpuMat& src, GpuMat& dst, int, Stream& stream)
    {
240
        using namespace cv::gpu::device;
241
        static const gpu_func_t funcs[] = {bgr_to_rgba_8u, 0, bgr_to_rgba_16u, 0, 0, bgr_to_rgba_32f};
242

243 244
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3);
245

246
        dst.create(src.size(), CV_MAKETYPE(src.depth(), 4));
247

248 249
        funcs[src.depth()](src, dst, StreamAccessor::getStream(stream));
    }
250

251 252
    void bgra_to_bgr(const GpuMat& src, GpuMat& dst, int, Stream& stream)
    {
253
        using namespace cv::gpu::device;
254
        static const gpu_func_t funcs[] = {bgra_to_bgr_8u, 0, bgra_to_bgr_16u, 0, 0, bgra_to_bgr_32f};
255

256 257
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 4);
258

259
        dst.create(src.size(), CV_MAKETYPE(src.depth(), 3));
260

261 262
        funcs[src.depth()](src, dst, StreamAccessor::getStream(stream));
    }
263

264 265
    void bgra_to_rgb(const GpuMat& src, GpuMat& dst, int, Stream& stream)
    {
266
        using namespace cv::gpu::device;
267
        static const gpu_func_t funcs[] = {bgra_to_rgb_8u, 0, bgra_to_rgb_16u, 0, 0, bgra_to_rgb_32f};
268

269 270 271
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 4);

272
        dst.create(src.size(), CV_MAKETYPE(src.depth(), 3));
273 274 275 276 277 278

        funcs[src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void bgra_to_rgba(const GpuMat& src, GpuMat& dst, int, Stream& stream)
    {
279
        using namespace cv::gpu::device;
280
        static const gpu_func_t funcs[] = {bgra_to_rgba_8u, 0, bgra_to_rgba_16u, 0, 0, bgra_to_rgba_32f};
281

282 283 284
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 4);

285
        dst.create(src.size(), CV_MAKETYPE(src.depth(), 4));
286 287 288 289 290

        funcs[src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void bgr_to_bgr555(const GpuMat& src, GpuMat& dst, int, Stream& stream)
291
    {
292 293 294
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 3);

295
        dst.create(src.size(), CV_8UC2);
296

297
        device::bgr_to_bgr555(src, dst, StreamAccessor::getStream(stream));
298 299 300
    }

    void bgr_to_bgr565(const GpuMat& src, GpuMat& dst, int, Stream& stream)
301
    {
302 303 304
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 3);

305
        dst.create(src.size(), CV_8UC2);
306

307
        device::bgr_to_bgr565(src, dst, StreamAccessor::getStream(stream));
308 309 310
    }

    void rgb_to_bgr555(const GpuMat& src, GpuMat& dst, int, Stream& stream)
311
    {
312 313 314
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 3);

315
        dst.create(src.size(), CV_8UC2);
316

317
        device::rgb_to_bgr555(src, dst, StreamAccessor::getStream(stream));
318 319 320
    }

    void rgb_to_bgr565(const GpuMat& src, GpuMat& dst, int, Stream& stream)
321
    {
322 323 324
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 3);

325
        dst.create(src.size(), CV_8UC2);
326

327
        device::rgb_to_bgr565(src, dst, StreamAccessor::getStream(stream));
328 329 330
    }

    void bgra_to_bgr555(const GpuMat& src, GpuMat& dst, int, Stream& stream)
331
    {
332 333 334
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 4);

335
        dst.create(src.size(), CV_8UC2);
336

337
        device::bgra_to_bgr555(src, dst, StreamAccessor::getStream(stream));
338 339 340
    }

    void bgra_to_bgr565(const GpuMat& src, GpuMat& dst, int, Stream& stream)
341
    {
342 343 344
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 4);

345
        dst.create(src.size(), CV_8UC2);
346

347
        device::bgra_to_bgr565(src, dst, StreamAccessor::getStream(stream));
348 349 350
    }

    void rgba_to_bgr555(const GpuMat& src, GpuMat& dst, int, Stream& stream)
351
    {
352 353 354
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 4);

355
        dst.create(src.size(), CV_8UC2);
356

357
        device::rgba_to_bgr555(src, dst, StreamAccessor::getStream(stream));
358 359 360
    }

    void rgba_to_bgr565(const GpuMat& src, GpuMat& dst, int, Stream& stream)
361
    {
362 363 364
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 4);

365
        dst.create(src.size(), CV_8UC2);
366

367
        device::rgba_to_bgr565(src, dst, StreamAccessor::getStream(stream));
368 369 370
    }

    void bgr555_to_rgb(const GpuMat& src, GpuMat& dst, int, Stream& stream)
371
    {
372 373 374
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 2);

375
        dst.create(src.size(), CV_8UC3);
376

377
        device::bgr555_to_rgb(src, dst, StreamAccessor::getStream(stream));
378 379 380
    }

    void bgr565_to_rgb(const GpuMat& src, GpuMat& dst, int, Stream& stream)
381
    {
382 383 384
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 2);

385
        dst.create(src.size(), CV_8UC3);
386

387
        device::bgr565_to_rgb(src, dst, StreamAccessor::getStream(stream));
388 389 390
    }

    void bgr555_to_bgr(const GpuMat& src, GpuMat& dst, int, Stream& stream)
391
    {
392 393 394
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 2);

395
        dst.create(src.size(), CV_8UC3);
396

397
        device::bgr555_to_bgr(src, dst, StreamAccessor::getStream(stream));
398 399 400
    }

    void bgr565_to_bgr(const GpuMat& src, GpuMat& dst, int, Stream& stream)
401
    {
402 403 404
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 2);

405
        dst.create(src.size(), CV_8UC3);
406

407
        device::bgr565_to_bgr(src, dst, StreamAccessor::getStream(stream));
408 409 410
    }

    void bgr555_to_rgba(const GpuMat& src, GpuMat& dst, int, Stream& stream)
411
    {
412 413 414
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 2);

415
        dst.create(src.size(), CV_8UC4);
416

417
        device::bgr555_to_rgba(src, dst, StreamAccessor::getStream(stream));
418 419 420
    }

    void bgr565_to_rgba(const GpuMat& src, GpuMat& dst, int, Stream& stream)
421
    {
422 423 424
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 2);

425
        dst.create(src.size(), CV_8UC4);
426

427
        device::bgr565_to_rgba(src, dst, StreamAccessor::getStream(stream));
428 429 430
    }

    void bgr555_to_bgra(const GpuMat& src, GpuMat& dst, int, Stream& stream)
431
    {
432 433 434
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 2);

435
        dst.create(src.size(), CV_8UC4);
436

437
        device::bgr555_to_bgra(src, dst, StreamAccessor::getStream(stream));
438 439 440
    }

    void bgr565_to_bgra(const GpuMat& src, GpuMat& dst, int, Stream& stream)
441
    {
442 443 444
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 2);

445
        dst.create(src.size(), CV_8UC4);
446

447
        device::bgr565_to_bgra(src, dst, StreamAccessor::getStream(stream));
448 449 450 451
    }

    void gray_to_bgr(const GpuMat& src, GpuMat& dst, int, Stream& stream)
    {
452
        using namespace cv::gpu::device;
453
        static const gpu_func_t funcs[] = {gray_to_bgr_8u, 0, gray_to_bgr_16u, 0, 0, gray_to_bgr_32f};
454

455 456 457
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 1);

458
        dst.create(src.size(), CV_MAKETYPE(src.depth(), 3));
459 460 461 462 463 464

        funcs[src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void gray_to_bgra(const GpuMat& src, GpuMat& dst, int, Stream& stream)
    {
465
        using namespace cv::gpu::device;
466
        static const gpu_func_t funcs[] = {gray_to_bgra_8u, 0, gray_to_bgra_16u, 0, 0, gray_to_bgra_32f};
467

468 469 470
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 1);

471
        dst.create(src.size(), CV_MAKETYPE(src.depth(), 4));
472 473 474 475 476

        funcs[src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void gray_to_bgr555(const GpuMat& src, GpuMat& dst, int, Stream& stream)
477
    {
478 479 480
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 1);

481
        dst.create(src.size(), CV_8UC2);
482

483
        device::gray_to_bgr555(src, dst, StreamAccessor::getStream(stream));
484 485 486
    }

    void gray_to_bgr565(const GpuMat& src, GpuMat& dst, int, Stream& stream)
487
    {
488 489 490
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 1);

491
        dst.create(src.size(), CV_8UC2);
492

493
        device::gray_to_bgr565(src, dst, StreamAccessor::getStream(stream));
494 495 496
    }

    void bgr555_to_gray(const GpuMat& src, GpuMat& dst, int, Stream& stream)
497
    {
498 499 500
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 2);

501
        dst.create(src.size(), CV_8UC1);
502

503
        device::bgr555_to_gray(src, dst, StreamAccessor::getStream(stream));
504 505 506
    }

    void bgr565_to_gray(const GpuMat& src, GpuMat& dst, int, Stream& stream)
507
    {
508 509 510
        CV_Assert(src.depth() == CV_8U);
        CV_Assert(src.channels() == 2);

511
        dst.create(src.size(), CV_8UC1);
512

513
        device::bgr565_to_gray(src, dst, StreamAccessor::getStream(stream));
514 515 516 517
    }

    void rgb_to_gray(const GpuMat& src, GpuMat& dst, int, Stream& stream)
    {
518
        using namespace cv::gpu::device;
519
        static const gpu_func_t funcs[] = {rgb_to_gray_8u, 0, rgb_to_gray_16u, 0, 0, rgb_to_gray_32f};
520

521 522 523
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3);

524
        dst.create(src.size(), CV_MAKETYPE(src.depth(), 1));
525 526 527 528 529 530

        funcs[src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void bgr_to_gray(const GpuMat& src, GpuMat& dst, int, Stream& stream)
    {
531
        using namespace cv::gpu::device;
532
        static const gpu_func_t funcs[] = {bgr_to_gray_8u, 0, bgr_to_gray_16u, 0, 0, bgr_to_gray_32f};
533

534 535 536
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3);

537
        dst.create(src.size(), CV_MAKETYPE(src.depth(), 1));
538 539 540 541 542 543

        funcs[src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void rgba_to_gray(const GpuMat& src, GpuMat& dst, int, Stream& stream)
    {
544
        using namespace cv::gpu::device;
545
        static const gpu_func_t funcs[] = {rgba_to_gray_8u, 0, rgba_to_gray_16u, 0, 0, rgba_to_gray_32f};
546

547 548 549
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 4);

550
        dst.create(src.size(), CV_MAKETYPE(src.depth(), 1));
551 552 553 554 555 556

        funcs[src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void bgra_to_gray(const GpuMat& src, GpuMat& dst, int, Stream& stream)
    {
557
        using namespace cv::gpu::device;
558
        static const gpu_func_t funcs[] = {bgra_to_gray_8u, 0, bgra_to_gray_16u, 0, 0, bgra_to_gray_32f};
559

560 561 562
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 4);

563
        dst.create(src.size(), CV_MAKETYPE(src.depth(), 1));
564 565 566

        funcs[src.depth()](src, dst, StreamAccessor::getStream(stream));
    }
567

568 569
    void rgb_to_yuv(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
570
        using namespace cv::gpu::device;
571
        static const gpu_func_t funcs[2][2][6] =
572 573 574 575 576 577 578 579 580 581 582 583
        {
            {
                {rgb_to_yuv_8u, 0, rgb_to_yuv_16u, 0, 0, rgb_to_yuv_32f},
                {rgba_to_yuv_8u, 0, rgba_to_yuv_16u, 0, 0, rgba_to_yuv_32f}
            },
            {
                {rgb_to_yuv4_8u, 0, rgb_to_yuv4_16u, 0, 0, rgb_to_yuv4_32f},
                {rgba_to_yuv4_8u, 0, rgba_to_yuv4_16u, 0, 0, rgba_to_yuv4_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
584

585 586 587
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);
588

589
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
590 591 592 593 594 595

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void bgr_to_yuv(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
596
        using namespace cv::gpu::device;
597
        static const gpu_func_t funcs[2][2][6] =
598 599 600 601 602 603 604 605 606 607 608 609
        {
            {
                {bgr_to_yuv_8u, 0, bgr_to_yuv_16u, 0, 0, bgr_to_yuv_32f},
                {bgra_to_yuv_8u, 0, bgra_to_yuv_16u, 0, 0, bgra_to_yuv_32f}
            },
            {
                {bgr_to_yuv4_8u, 0, bgr_to_yuv4_16u, 0, 0, bgr_to_yuv4_32f},
                {bgra_to_yuv4_8u, 0, bgra_to_yuv4_16u, 0, 0, bgra_to_yuv4_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
610

611 612 613 614
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

615
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
616 617 618 619 620 621

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void yuv_to_rgb(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
622
        using namespace cv::gpu::device;
623
        static const gpu_func_t funcs[2][2][6] =
624 625 626 627 628 629 630 631 632 633 634 635
        {
            {
                {yuv_to_rgb_8u, 0, yuv_to_rgb_16u, 0, 0, yuv_to_rgb_32f},
                {yuv4_to_rgb_8u, 0, yuv4_to_rgb_16u, 0, 0, yuv4_to_rgb_32f}
            },
            {
                {yuv_to_rgba_8u, 0, yuv_to_rgba_16u, 0, 0, yuv_to_rgba_32f},
                {yuv4_to_rgba_8u, 0, yuv4_to_rgba_16u, 0, 0, yuv4_to_rgba_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
636

637 638 639 640
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

641
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
642 643 644 645 646 647

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void yuv_to_bgr(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
648
        using namespace cv::gpu::device;
649
        static const gpu_func_t funcs[2][2][6] =
650 651 652 653 654 655 656 657 658 659 660 661
        {
            {
                {yuv_to_bgr_8u, 0, yuv_to_bgr_16u, 0, 0, yuv_to_bgr_32f},
                {yuv4_to_bgr_8u, 0, yuv4_to_bgr_16u, 0, 0, yuv4_to_bgr_32f}
            },
            {
                {yuv_to_bgra_8u, 0, yuv_to_bgra_16u, 0, 0, yuv_to_bgra_32f},
                {yuv4_to_bgra_8u, 0, yuv4_to_bgra_16u, 0, 0, yuv4_to_bgra_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
662

663 664 665 666
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

667
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
668 669 670

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }
671

672 673
    void rgb_to_YCrCb(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
674
        using namespace cv::gpu::device;
675
        static const gpu_func_t funcs[2][2][6] =
676 677 678 679 680 681 682 683 684 685 686 687
        {
            {
                {rgb_to_YCrCb_8u, 0, rgb_to_YCrCb_16u, 0, 0, rgb_to_YCrCb_32f},
                {rgba_to_YCrCb_8u, 0, rgba_to_YCrCb_16u, 0, 0, rgba_to_YCrCb_32f}
            },
            {
                {rgb_to_YCrCb4_8u, 0, rgb_to_YCrCb4_16u, 0, 0, rgb_to_YCrCb4_32f},
                {rgba_to_YCrCb4_8u, 0, rgba_to_YCrCb4_16u, 0, 0, rgba_to_YCrCb4_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
688

689 690 691 692
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

693
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
694 695 696 697 698 699

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void bgr_to_YCrCb(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
700
        using namespace cv::gpu::device;
701
        static const gpu_func_t funcs[2][2][6] =
702 703 704 705 706 707 708 709 710 711 712 713
        {
            {
                {bgr_to_YCrCb_8u, 0, bgr_to_YCrCb_16u, 0, 0, bgr_to_YCrCb_32f},
                {bgra_to_YCrCb_8u, 0, bgra_to_YCrCb_16u, 0, 0, bgra_to_YCrCb_32f}
            },
            {
                {bgr_to_YCrCb4_8u, 0, bgr_to_YCrCb4_16u, 0, 0, bgr_to_YCrCb4_32f},
                {bgra_to_YCrCb4_8u, 0, bgra_to_YCrCb4_16u, 0, 0, bgra_to_YCrCb4_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
714

715 716 717 718
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

719
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
720 721 722 723 724 725

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void YCrCb_to_rgb(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
726
        using namespace cv::gpu::device;
727
        static const gpu_func_t funcs[2][2][6] =
728 729 730 731 732 733 734 735 736 737 738 739
        {
            {
                {YCrCb_to_rgb_8u, 0, YCrCb_to_rgb_16u, 0, 0, YCrCb_to_rgb_32f},
                {YCrCb4_to_rgb_8u, 0, YCrCb4_to_rgb_16u, 0, 0, YCrCb4_to_rgb_32f}
            },
            {
                {YCrCb_to_rgba_8u, 0, YCrCb_to_rgba_16u, 0, 0, YCrCb_to_rgba_32f},
                {YCrCb4_to_rgba_8u, 0, YCrCb4_to_rgba_16u, 0, 0, YCrCb4_to_rgba_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
740

741 742 743 744
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

745
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
746 747 748 749 750 751

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void YCrCb_to_bgr(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
752
        using namespace cv::gpu::device;
753
        static const gpu_func_t funcs[2][2][6] =
754 755 756 757 758 759 760 761 762 763 764 765
        {
            {
                {YCrCb_to_bgr_8u, 0, YCrCb_to_bgr_16u, 0, 0, YCrCb_to_bgr_32f},
                {YCrCb4_to_bgr_8u, 0, YCrCb4_to_bgr_16u, 0, 0, YCrCb4_to_bgr_32f}
            },
            {
                {YCrCb_to_bgra_8u, 0, YCrCb_to_bgra_16u, 0, 0, YCrCb_to_bgra_32f},
                {YCrCb4_to_bgra_8u, 0, YCrCb4_to_bgra_16u, 0, 0, YCrCb4_to_bgra_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
766

767 768 769 770
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

771
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
772 773 774 775 776 777

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void rgb_to_xyz(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
778
        using namespace cv::gpu::device;
779
        static const gpu_func_t funcs[2][2][6] =
780 781 782 783 784 785 786 787 788 789 790 791
        {
            {
                {rgb_to_xyz_8u, 0, rgb_to_xyz_16u, 0, 0, rgb_to_xyz_32f},
                {rgba_to_xyz_8u, 0, rgba_to_xyz_16u, 0, 0, rgba_to_xyz_32f}
            },
            {
                {rgb_to_xyz4_8u, 0, rgb_to_xyz4_16u, 0, 0, rgb_to_xyz4_32f},
                {rgba_to_xyz4_8u, 0, rgba_to_xyz4_16u, 0, 0, rgba_to_xyz4_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
792

793 794 795 796
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

797
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
798 799 800 801 802 803

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void bgr_to_xyz(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
804
        using namespace cv::gpu::device;
805
        static const gpu_func_t funcs[2][2][6] =
806 807 808 809 810 811 812 813 814 815 816 817
        {
            {
                {bgr_to_xyz_8u, 0, bgr_to_xyz_16u, 0, 0, bgr_to_xyz_32f},
                {bgra_to_xyz_8u, 0, bgra_to_xyz_16u, 0, 0, bgra_to_xyz_32f}
            },
            {
                {bgr_to_xyz4_8u, 0, bgr_to_xyz4_16u, 0, 0, bgr_to_xyz4_32f},
                {bgra_to_xyz4_8u, 0, bgra_to_xyz4_16u, 0, 0, bgra_to_xyz4_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
818

819 820 821 822
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

823
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
824 825 826 827 828 829

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void xyz_to_rgb(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
830
        using namespace cv::gpu::device;
831
        static const gpu_func_t funcs[2][2][6] =
832 833 834 835 836 837 838 839 840 841 842 843
        {
            {
                {xyz_to_rgb_8u, 0, xyz_to_rgb_16u, 0, 0, xyz_to_rgb_32f},
                {xyz4_to_rgb_8u, 0, xyz4_to_rgb_16u, 0, 0, xyz4_to_rgb_32f}
            },
            {
                {xyz_to_rgba_8u, 0, xyz_to_rgba_16u, 0, 0, xyz_to_rgba_32f},
                {xyz4_to_rgba_8u, 0, xyz4_to_rgba_16u, 0, 0, xyz4_to_rgba_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
844

845 846 847 848
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

849
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
850 851 852 853 854 855

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void xyz_to_bgr(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
856
        using namespace cv::gpu::device;
857
        static const gpu_func_t funcs[2][2][6] =
858 859 860 861 862 863 864 865 866 867 868 869
        {
            {
                {xyz_to_bgr_8u, 0, xyz_to_bgr_16u, 0, 0, xyz_to_bgr_32f},
                {xyz4_to_bgr_8u, 0, xyz4_to_bgr_16u, 0, 0, xyz4_to_bgr_32f}
            },
            {
                {xyz_to_bgra_8u, 0, xyz_to_bgra_16u, 0, 0, xyz_to_bgra_32f},
                {xyz4_to_bgra_8u, 0, xyz4_to_bgra_16u, 0, 0, xyz4_to_bgra_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
870

871 872 873 874
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_16U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

875
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
876 877 878 879 880 881

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void rgb_to_hsv(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
882
        using namespace cv::gpu::device;
883
        static const gpu_func_t funcs[2][2][6] =
884 885 886 887 888 889 890 891 892 893 894 895
        {
            {
                {rgb_to_hsv_8u, 0, 0, 0, 0, rgb_to_hsv_32f},
                {rgba_to_hsv_8u, 0, 0, 0, 0, rgba_to_hsv_32f},
            },
            {
                {rgb_to_hsv4_8u, 0, 0, 0, 0, rgb_to_hsv4_32f},
                {rgba_to_hsv4_8u, 0, 0, 0, 0, rgba_to_hsv4_32f},
            }
        };

        if (dcn <= 0) dcn = 3;
896

897 898 899 900
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

901
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
902 903 904 905 906 907

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void bgr_to_hsv(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
908
        using namespace cv::gpu::device;
909
        static const gpu_func_t funcs[2][2][6] =
910 911 912 913 914 915 916 917 918 919 920 921
        {
            {
                {bgr_to_hsv_8u, 0, 0, 0, 0, bgr_to_hsv_32f},
                {bgra_to_hsv_8u, 0, 0, 0, 0, bgra_to_hsv_32f}
            },
            {
                {bgr_to_hsv4_8u, 0, 0, 0, 0, bgr_to_hsv4_32f},
                {bgra_to_hsv4_8u, 0, 0, 0, 0, bgra_to_hsv4_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
922

923 924 925 926
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

927
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
928 929 930 931 932 933

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void hsv_to_rgb(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
934
        using namespace cv::gpu::device;
935
        static const gpu_func_t funcs[2][2][6] =
936 937 938 939 940 941 942 943 944 945 946 947
        {
            {
                {hsv_to_rgb_8u, 0, 0, 0, 0, hsv_to_rgb_32f},
                {hsv4_to_rgb_8u, 0, 0, 0, 0, hsv4_to_rgb_32f}
            },
            {
                {hsv_to_rgba_8u, 0, 0, 0, 0, hsv_to_rgba_32f},
                {hsv4_to_rgba_8u, 0, 0, 0, 0, hsv4_to_rgba_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
948

949 950 951 952
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

953
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
954 955 956 957 958 959

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void hsv_to_bgr(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
960
        using namespace cv::gpu::device;
961
        static const gpu_func_t funcs[2][2][6] =
962 963 964 965 966 967 968 969 970 971 972 973
        {
            {
                {hsv_to_bgr_8u, 0, 0, 0, 0, hsv_to_bgr_32f},
                {hsv4_to_bgr_8u, 0, 0, 0, 0, hsv4_to_bgr_32f}
            },
            {
                {hsv_to_bgra_8u, 0, 0, 0, 0, hsv_to_bgra_32f},
                {hsv4_to_bgra_8u, 0, 0, 0, 0, hsv4_to_bgra_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
974

975 976 977 978
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

979
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
980 981

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
982
    }
983 984 985

    void rgb_to_hls(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
986
        using namespace cv::gpu::device;
987
        static const gpu_func_t funcs[2][2][6] =
988 989 990 991 992 993 994 995 996 997 998 999
        {
            {
                {rgb_to_hls_8u, 0, 0, 0, 0, rgb_to_hls_32f},
                {rgba_to_hls_8u, 0, 0, 0, 0, rgba_to_hls_32f},
            },
            {
                {rgb_to_hls4_8u, 0, 0, 0, 0, rgb_to_hls4_32f},
                {rgba_to_hls4_8u, 0, 0, 0, 0, rgba_to_hls4_32f},
            }
        };

        if (dcn <= 0) dcn = 3;
1000

1001 1002 1003 1004
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

1005
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
1006 1007 1008 1009 1010 1011

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void bgr_to_hls(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
1012
        using namespace cv::gpu::device;
1013
        static const gpu_func_t funcs[2][2][6] =
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
        {
            {
                {bgr_to_hls_8u, 0, 0, 0, 0, bgr_to_hls_32f},
                {bgra_to_hls_8u, 0, 0, 0, 0, bgra_to_hls_32f}
            },
            {
                {bgr_to_hls4_8u, 0, 0, 0, 0, bgr_to_hls4_32f},
                {bgra_to_hls4_8u, 0, 0, 0, 0, bgra_to_hls4_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
1026

1027 1028 1029 1030
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

1031
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
1032 1033 1034 1035 1036 1037

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void hls_to_rgb(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
1038
        using namespace cv::gpu::device;
1039
        static const gpu_func_t funcs[2][2][6] =
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
        {
            {
                {hls_to_rgb_8u, 0, 0, 0, 0, hls_to_rgb_32f},
                {hls4_to_rgb_8u, 0, 0, 0, 0, hls4_to_rgb_32f}
            },
            {
                {hls_to_rgba_8u, 0, 0, 0, 0, hls_to_rgba_32f},
                {hls4_to_rgba_8u, 0, 0, 0, 0, hls4_to_rgba_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
1052

1053 1054 1055 1056
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

1057
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
1058 1059 1060 1061 1062 1063

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void hls_to_bgr(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
1064
        using namespace cv::gpu::device;
1065
        static const gpu_func_t funcs[2][2][6] =
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077
        {
            {
                {hls_to_bgr_8u, 0, 0, 0, 0, hls_to_bgr_32f},
                {hls4_to_bgr_8u, 0, 0, 0, 0, hls4_to_bgr_32f}
            },
            {
                {hls_to_bgra_8u, 0, 0, 0, 0, hls_to_bgra_32f},
                {hls4_to_bgra_8u, 0, 0, 0, 0, hls4_to_bgra_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
1078

1079 1080 1081 1082
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

1083
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
1084 1085

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
1086
    }
1087 1088 1089

    void rgb_to_hsv_full(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
1090
        using namespace cv::gpu::device;
1091
        static const gpu_func_t funcs[2][2][6] =
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
        {
            {
                {rgb_to_hsv_full_8u, 0, 0, 0, 0, rgb_to_hsv_full_32f},
                {rgba_to_hsv_full_8u, 0, 0, 0, 0, rgba_to_hsv_full_32f},
            },
            {
                {rgb_to_hsv4_full_8u, 0, 0, 0, 0, rgb_to_hsv4_full_32f},
                {rgba_to_hsv4_full_8u, 0, 0, 0, 0, rgba_to_hsv4_full_32f},
            }
        };

        if (dcn <= 0) dcn = 3;
1104

1105 1106 1107 1108
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

1109
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
1110 1111 1112 1113 1114 1115

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void bgr_to_hsv_full(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
1116
        using namespace cv::gpu::device;
1117
        static const gpu_func_t funcs[2][2][6] =
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
        {
            {
                {bgr_to_hsv_full_8u, 0, 0, 0, 0, bgr_to_hsv_full_32f},
                {bgra_to_hsv_full_8u, 0, 0, 0, 0, bgra_to_hsv_full_32f}
            },
            {
                {bgr_to_hsv4_full_8u, 0, 0, 0, 0, bgr_to_hsv4_full_32f},
                {bgra_to_hsv4_full_8u, 0, 0, 0, 0, bgra_to_hsv4_full_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
1130

1131 1132 1133 1134
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

1135
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
1136 1137 1138 1139 1140 1141

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void hsv_to_rgb_full(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
1142
        using namespace cv::gpu::device;
1143
        static const gpu_func_t funcs[2][2][6] =
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
        {
            {
                {hsv_to_rgb_full_8u, 0, 0, 0, 0, hsv_to_rgb_full_32f},
                {hsv4_to_rgb_full_8u, 0, 0, 0, 0, hsv4_to_rgb_full_32f}
            },
            {
                {hsv_to_rgba_full_8u, 0, 0, 0, 0, hsv_to_rgba_full_32f},
                {hsv4_to_rgba_full_8u, 0, 0, 0, 0, hsv4_to_rgba_full_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
1156

1157 1158 1159 1160
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

1161
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
1162 1163 1164 1165 1166 1167

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void hsv_to_bgr_full(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
1168
        using namespace cv::gpu::device;
1169
        static const gpu_func_t funcs[2][2][6] =
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181
        {
            {
                {hsv_to_bgr_full_8u, 0, 0, 0, 0, hsv_to_bgr_full_32f},
                {hsv4_to_bgr_full_8u, 0, 0, 0, 0, hsv4_to_bgr_full_32f}
            },
            {
                {hsv_to_bgra_full_8u, 0, 0, 0, 0, hsv_to_bgra_full_32f},
                {hsv4_to_bgra_full_8u, 0, 0, 0, 0, hsv4_to_bgra_full_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
1182

1183 1184 1185 1186
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

1187
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
1188 1189

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
1190
    }
1191 1192

    void rgb_to_hls_full(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
1193
    {
1194
        using namespace cv::gpu::device;
1195
        static const gpu_func_t funcs[2][2][6] =
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
        {
            {
                {rgb_to_hls_full_8u, 0, 0, 0, 0, rgb_to_hls_full_32f},
                {rgba_to_hls_full_8u, 0, 0, 0, 0, rgba_to_hls_full_32f},
            },
            {
                {rgb_to_hls4_full_8u, 0, 0, 0, 0, rgb_to_hls4_full_32f},
                {rgba_to_hls4_full_8u, 0, 0, 0, 0, rgba_to_hls4_full_32f},
            }
        };

        if (dcn <= 0) dcn = 3;
1208

1209 1210 1211 1212
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

1213
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
1214

1215 1216 1217 1218 1219
        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void bgr_to_hls_full(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
1220
        using namespace cv::gpu::device;
1221
        static const gpu_func_t funcs[2][2][6] =
1222
        {
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
            {
                {bgr_to_hls_full_8u, 0, 0, 0, 0, bgr_to_hls_full_32f},
                {bgra_to_hls_full_8u, 0, 0, 0, 0, bgra_to_hls_full_32f}
            },
            {
                {bgr_to_hls4_full_8u, 0, 0, 0, 0, bgr_to_hls4_full_32f},
                {bgra_to_hls4_full_8u, 0, 0, 0, 0, bgra_to_hls4_full_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
1234

1235 1236 1237 1238
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

1239
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
1240 1241 1242 1243 1244 1245

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void hls_to_rgb_full(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
1246
        using namespace cv::gpu::device;
1247
        static const gpu_func_t funcs[2][2][6] =
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
        {
            {
                {hls_to_rgb_full_8u, 0, 0, 0, 0, hls_to_rgb_full_32f},
                {hls4_to_rgb_full_8u, 0, 0, 0, 0, hls4_to_rgb_full_32f}
            },
            {
                {hls_to_rgba_full_8u, 0, 0, 0, 0, hls_to_rgba_full_32f},
                {hls4_to_rgba_full_8u, 0, 0, 0, 0, hls4_to_rgba_full_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
1260

1261 1262 1263 1264
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

1265
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
1266 1267 1268 1269 1270 1271

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
    }

    void hls_to_bgr_full(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream)
    {
1272
        using namespace cv::gpu::device;
1273
        static const gpu_func_t funcs[2][2][6] =
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
        {
            {
                {hls_to_bgr_full_8u, 0, 0, 0, 0, hls_to_bgr_full_32f},
                {hls4_to_bgr_full_8u, 0, 0, 0, 0, hls4_to_bgr_full_32f}
            },
            {
                {hls_to_bgra_full_8u, 0, 0, 0, 0, hls_to_bgra_full_32f},
                {hls4_to_bgra_full_8u, 0, 0, 0, 0, hls4_to_bgra_full_32f}
            }
        };

        if (dcn <= 0) dcn = 3;
1286

1287 1288 1289 1290
        CV_Assert(src.depth() == CV_8U || src.depth() == CV_32F);
        CV_Assert(src.channels() == 3 || src.channels() == 4);
        CV_Assert(dcn == 3 || dcn == 4);

1291
        dst.create(src.size(), CV_MAKETYPE(src.depth(), dcn));
1292 1293

        funcs[dcn == 4][src.channels() == 4][src.depth()](src, dst, StreamAccessor::getStream(stream));
1294 1295 1296
    }
}

1297
void cv::gpu::cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn, Stream& stream)
1298
{
1299
    typedef void (*func_t)(const GpuMat& src, GpuMat& dst, int dcn, Stream& stream);
1300
    static const func_t funcs[] =
1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355
    {
        bgr_to_bgra,            // CV_BGR2BGRA    =0
        bgra_to_bgr,            // CV_BGRA2BGR    =1
        bgr_to_rgba,            // CV_BGR2RGBA    =2
        bgra_to_rgb,            // CV_RGBA2BGR    =3
        bgr_to_rgb,             // CV_BGR2RGB     =4
        bgra_to_rgba,           // CV_BGRA2RGBA   =5

        bgr_to_gray,            // CV_BGR2GRAY    =6
        rgb_to_gray,            // CV_RGB2GRAY    =7
        gray_to_bgr,            // CV_GRAY2BGR    =8
        gray_to_bgra,           // CV_GRAY2BGRA   =9
        bgra_to_gray,           // CV_BGRA2GRAY   =10
        rgba_to_gray,           // CV_RGBA2GRAY   =11

        bgr_to_bgr565,          // CV_BGR2BGR565  =12
        rgb_to_bgr565,          // CV_RGB2BGR565  =13
        bgr565_to_bgr,          // CV_BGR5652BGR  =14
        bgr565_to_rgb,          // CV_BGR5652RGB  =15
        bgra_to_bgr565,         // CV_BGRA2BGR565 =16
        rgba_to_bgr565,         // CV_RGBA2BGR565 =17
        bgr565_to_bgra,         // CV_BGR5652BGRA =18
        bgr565_to_rgba,         // CV_BGR5652RGBA =19

        gray_to_bgr565,         // CV_GRAY2BGR565 =20
        bgr565_to_gray,         // CV_BGR5652GRAY =21

        bgr_to_bgr555,          // CV_BGR2BGR555  =22
        rgb_to_bgr555,          // CV_RGB2BGR555  =23
        bgr555_to_bgr,          // CV_BGR5552BGR  =24
        bgr555_to_rgb,          // CV_BGR5552RGB  =25
        bgra_to_bgr555,         // CV_BGRA2BGR555 =26
        rgba_to_bgr555,         // CV_RGBA2BGR555 =27
        bgr555_to_bgra,         // CV_BGR5552BGRA =28
        bgr555_to_rgba,         // CV_BGR5552RGBA =29

        gray_to_bgr555,         // CV_GRAY2BGR555 =30
        bgr555_to_gray,         // CV_BGR5552GRAY =31

        bgr_to_xyz,             // CV_BGR2XYZ     =32
        rgb_to_xyz,             // CV_RGB2XYZ     =33
        xyz_to_bgr,             // CV_XYZ2BGR     =34
        xyz_to_rgb,             // CV_XYZ2RGB     =35

        bgr_to_YCrCb,           // CV_BGR2YCrCb   =36
        rgb_to_YCrCb,           // CV_RGB2YCrCb   =37
        YCrCb_to_bgr,           // CV_YCrCb2BGR   =38
        YCrCb_to_rgb,           // CV_YCrCb2RGB   =39

        bgr_to_hsv,             // CV_BGR2HSV     =40
        rgb_to_hsv,             // CV_RGB2HSV     =41

        0,                      //                =42
        0,                      //                =43

1356
        0,                      // CV_BGR2Lab     =44
1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370
        0,                      // CV_RGB2Lab     =45

        0,                      // CV_BayerBG2BGR =46
        0,                      // CV_BayerGB2BGR =47
        0,                      // CV_BayerRG2BGR =48
        0,                      // CV_BayerGR2BGR =49

        0,                      // CV_BGR2Luv     =50
        0,                      // CV_RGB2Luv     =51

        bgr_to_hls,             // CV_BGR2HLS     =52
        rgb_to_hls,             // CV_RGB2HLS     =53

        hsv_to_bgr,             // CV_HSV2BGR     =54
1371
        hsv_to_rgb,             // CV_HSV2RGB     =55
1372 1373 1374 1375 1376

        0,                      // CV_Lab2BGR     =56
        0,                      // CV_Lab2RGB     =57
        0,                      // CV_Luv2BGR     =58
        0,                      // CV_Luv2RGB     =59
1377

1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413
        hls_to_bgr,             // CV_HLS2BGR     =60
        hls_to_rgb,             // CV_HLS2RGB     =61

        0,                      // CV_BayerBG2BGR_VNG =62
        0,                      // CV_BayerGB2BGR_VNG =63
        0,                      // CV_BayerRG2BGR_VNG =64
        0,                      // CV_BayerGR2BGR_VNG =65

        bgr_to_hsv_full,        // CV_BGR2HSV_FULL = 66
        rgb_to_hsv_full,        // CV_RGB2HSV_FULL = 67
        bgr_to_hls_full,        // CV_BGR2HLS_FULL = 68
        rgb_to_hls_full,        // CV_RGB2HLS_FULL = 69

        hsv_to_bgr_full,        // CV_HSV2BGR_FULL = 70
        hsv_to_rgb_full,        // CV_HSV2RGB_FULL = 71
        hls_to_bgr_full,        // CV_HLS2BGR_FULL = 72
        hls_to_rgb_full,        // CV_HLS2RGB_FULL = 73

        0,                      // CV_LBGR2Lab     = 74
        0,                      // CV_LRGB2Lab     = 75
        0,                      // CV_LBGR2Luv     = 76
        0,                      // CV_LRGB2Luv     = 77

        0,                      // CV_Lab2LBGR     = 78
        0,                      // CV_Lab2LRGB     = 79
        0,                      // CV_Luv2LBGR     = 80
        0,                      // CV_Luv2LRGB     = 81

        bgr_to_yuv,             // CV_BGR2YUV      = 82
        rgb_to_yuv,             // CV_RGB2YUV      = 83
        yuv_to_bgr,             // CV_YUV2BGR      = 84
        yuv_to_rgb,             // CV_YUV2RGB      = 85

        0,                      // CV_BayerBG2GRAY = 86
        0,                      // CV_BayerGB2GRAY = 87
        0,                      // CV_BayerRG2GRAY = 88
1414
        0                       // CV_BayerGR2GRAY = 89
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424
    };

    CV_Assert(code < 94);

    func_t func = funcs[code];

    if (func == 0)
        CV_Error( CV_StsBadFlag, "Unknown/unsupported color conversion code" );

    func(src, dst, dcn, stream);
1425 1426
}

1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438
void cv::gpu::swapChannels(GpuMat& image, const int dstOrder[4], Stream& s)
{
    CV_Assert(image.type() == CV_8UC4);

    cudaStream_t stream = StreamAccessor::getStream(s);

    NppStreamHandler h(stream);

    NppiSize sz;
    sz.width  = image.cols;
    sz.height = image.rows;

1439 1440 1441 1442
    nppSafeCall( nppiSwapChannels_8u_C4IR(image.ptr<Npp8u>(), static_cast<int>(image.step), sz, dstOrder) );

    if (stream == 0)
        cudaSafeCall( cudaDeviceSynchronize() );
1443 1444
}

1445
#endif /* !defined (HAVE_CUDA) */