|
51 | 51 | #if CV_WITH_RK |
52 | 52 | #include "jpeg_encoder_rk_mpp.h" |
53 | 53 | #endif |
| 54 | +#if CV_WITH_RPI |
| 55 | +#include "jpeg_encoder_v4l_rpi.h" |
| 56 | +#endif |
54 | 57 | #if defined __linux__ && !__ANDROID__ |
55 | 58 | #include "display_fb.h" |
56 | 59 | #endif |
@@ -404,6 +407,57 @@ bool imwrite(const String& filename, InputArray _img, const std::vector<int>& pa |
404 | 407 | // fallback to stb_image_write |
405 | 408 | } |
406 | 409 | #endif |
| 410 | +#if CV_WITH_RPI |
| 411 | + if (jpeg_encoder_v4l_rpi::supported(img.cols, img.rows, c)) |
| 412 | + { |
| 413 | + // anything to bgr |
| 414 | + if (!img.isContinuous()) |
| 415 | + { |
| 416 | + img = img.clone(); |
| 417 | + } |
| 418 | + |
| 419 | + int quality = 95; |
| 420 | + for (size_t i = 0; i < params.size(); i += 2) |
| 421 | + { |
| 422 | + if (params[i] == IMWRITE_JPEG_QUALITY) |
| 423 | + { |
| 424 | + quality = params[i + 1]; |
| 425 | + break; |
| 426 | + } |
| 427 | + } |
| 428 | + |
| 429 | + // cache jpeg_encoder_v4l_rpi context |
| 430 | + static int old_w = 0; |
| 431 | + static int old_h = 0; |
| 432 | + static int old_ch = 0; |
| 433 | + static int old_quality = 0; |
| 434 | + static jpeg_encoder_v4l_rpi e; |
| 435 | + if (img.cols == old_w && img.rows == old_h && c == old_ch && quality == old_quality) |
| 436 | + { |
| 437 | + int ret = e.encode(img.data, filename.c_str()); |
| 438 | + if (ret == 0) |
| 439 | + return true; |
| 440 | + } |
| 441 | + else |
| 442 | + { |
| 443 | + int ret = e.init(img.cols, img.rows, c, quality); |
| 444 | + if (ret == 0) |
| 445 | + { |
| 446 | + ret = e.encode(img.data, filename.c_str()); |
| 447 | + if (ret == 0) |
| 448 | + { |
| 449 | + old_w = img.cols; |
| 450 | + old_h = img.rows; |
| 451 | + old_ch = c; |
| 452 | + old_quality = quality; |
| 453 | + return true; |
| 454 | + } |
| 455 | + } |
| 456 | + } |
| 457 | + |
| 458 | + // fallback to stb_image_write |
| 459 | + } |
| 460 | +#endif |
407 | 461 | } |
408 | 462 |
|
409 | 463 | // bgr to rgb |
@@ -724,6 +778,40 @@ bool imencode(const String& ext, InputArray _img, std::vector<uchar>& buf, const |
724 | 778 | // fallback to stb_image_write |
725 | 779 | } |
726 | 780 | #endif |
| 781 | +#if CV_WITH_RPI |
| 782 | + if (jpeg_encoder_v4l_rpi::supported(img.cols, img.rows, c)) |
| 783 | + { |
| 784 | + // anything to bgr |
| 785 | + if (!img.isContinuous()) |
| 786 | + { |
| 787 | + img = img.clone(); |
| 788 | + } |
| 789 | + |
| 790 | + int quality = 95; |
| 791 | + for (size_t i = 0; i < params.size(); i += 2) |
| 792 | + { |
| 793 | + if (params[i] == IMWRITE_JPEG_QUALITY) |
| 794 | + { |
| 795 | + quality = params[i + 1]; |
| 796 | + break; |
| 797 | + } |
| 798 | + } |
| 799 | + |
| 800 | + jpeg_encoder_v4l_rpi e; |
| 801 | + int ret = e.init(img.cols, img.rows, c, quality); |
| 802 | + if (ret == 0) |
| 803 | + { |
| 804 | + ret = e.encode(img.data, buf); |
| 805 | + if (ret == 0) |
| 806 | + { |
| 807 | + e.deinit(); |
| 808 | + return true; |
| 809 | + } |
| 810 | + } |
| 811 | + |
| 812 | + // fallback to stb_image_write |
| 813 | + } |
| 814 | +#endif |
727 | 815 | } |
728 | 816 |
|
729 | 817 | // bgr to rgb |
|
0 commit comments