Skip to content

Commit 674c956

Browse files
authored
hw jpg encoder for orion o6 (#189)
1 parent 57b84b1 commit 674c956

File tree

5 files changed

+1375
-1
lines changed

5 files changed

+1375
-1
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
rm -rf modules/ts
7777
sed -e 's/__VERSION__/${{ env.opencv-version }}/g' ../patches/Info.plist > ./Info.plist
7878
cp ../opencv2_cmake_options.txt ./options.txt
79+
cp -r ../toolchains .
7980
cd ..
8081
mv opencv-${{ env.opencv-version }} opencv-mobile-${{ env.opencv-version }}
8182
zip -9 -r opencv-mobile-${{ env.opencv-version }}.zip opencv-mobile-${{ env.opencv-version }}
@@ -153,6 +154,7 @@ jobs:
153154
rm -rf modules/dnn
154155
sed -e 's/__VERSION__/${{ env.opencv-version }}/g' ../patches/Info.plist > ./Info.plist
155156
cp ../opencv3_cmake_options.txt ./options.txt
157+
cp -r ../toolchains .
156158
cd ..
157159
mv opencv-${{ env.opencv-version }} opencv-mobile-${{ env.opencv-version }}
158160
zip -9 -r opencv-mobile-${{ env.opencv-version }}.zip opencv-mobile-${{ env.opencv-version }}
@@ -228,6 +230,7 @@ jobs:
228230
rm -rf modules/dnn
229231
sed -e 's/__VERSION__/${{ env.opencv-version }}/g' ../patches/Info.plist > ./Info.plist
230232
cp ../opencv4_cmake_options.txt ./options.txt
233+
cp -r ../toolchains .
231234
cd ..
232235
mv opencv-${{ env.opencv-version }} opencv-mobile-${{ env.opencv-version }}
233236
zip -9 -r opencv-mobile-${{ env.opencv-version }}.zip opencv-mobile-${{ env.opencv-version }}
@@ -1787,7 +1790,7 @@ jobs:
17871790
echo "fine :)"
17881791
setup-test-env-cmd: |
17891792
echo "fine :)"
1790-
cmake-options: -DWITH_RPI=ON
1793+
cmake-options: -DWITH_KLEIDICV=ON -DWITH_RPI=ON -DWITH_CIX=ON
17911794

17921795
- name: milkv-duo
17931796
single-core: true

highgui/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ option(WITH_CVI "build with cvi" OFF)
55
option(WITH_AW "build with aw" OFF)
66
option(WITH_RK "build with rk" OFF)
77
option(WITH_RPI "build with rpi" OFF)
8+
option(WITH_CIX "build with cix" OFF)
89

910
set(highgui_srcs
1011
${CMAKE_CURRENT_LIST_DIR}/src/exif.cpp
@@ -61,6 +62,13 @@ if(WITH_RPI)
6162
message(STATUS "highgui rpi enabled")
6263
endif()
6364

65+
if(WITH_CIX)
66+
list(APPEND highgui_srcs
67+
${CMAKE_CURRENT_LIST_DIR}/src/jpeg_encoder_v4l_cix.cpp)
68+
add_definitions(-DCV_WITH_CIX=1)
69+
message(STATUS "highgui cix enabled")
70+
endif()
71+
6472
file(GLOB highgui_ext_hdrs
6573
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/*.hpp"
6674
"${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/*.hpp"

highgui/src/highgui.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
#if CV_WITH_RPI
5555
#include "jpeg_encoder_v4l_rpi.h"
5656
#endif
57+
#if CV_WITH_CIX
58+
#include "jpeg_encoder_v4l_cix.h"
59+
#endif
5760
#if defined __linux__ && !__ANDROID__
5861
#include "display_fb.h"
5962
#endif
@@ -454,6 +457,56 @@ bool imwrite(const String& filename, InputArray _img, const std::vector<int>& pa
454457
}
455458
}
456459
}
460+
// fallback to stb_image_write
461+
}
462+
#endif
463+
#if CV_WITH_CIX
464+
if (jpeg_encoder_v4l_cix::supported(img.cols, img.rows, c))
465+
{
466+
// anything to bgr
467+
if (!img.isContinuous())
468+
{
469+
img = img.clone();
470+
}
471+
472+
int quality = 95;
473+
for (size_t i = 0; i < params.size(); i += 2)
474+
{
475+
if (params[i] == IMWRITE_JPEG_QUALITY)
476+
{
477+
quality = params[i + 1];
478+
break;
479+
}
480+
}
481+
482+
// cache jpeg_encoder_v4l_cix context
483+
static int old_w = 0;
484+
static int old_h = 0;
485+
static int old_ch = 0;
486+
static int old_quality = 0;
487+
static jpeg_encoder_v4l_cix e;
488+
if (img.cols == old_w && img.rows == old_h && c == old_ch && quality == old_quality)
489+
{
490+
int ret = e.encode(img.data, filename.c_str());
491+
if (ret == 0)
492+
return true;
493+
}
494+
else
495+
{
496+
int ret = e.init(img.cols, img.rows, c, quality);
497+
if (ret == 0)
498+
{
499+
ret = e.encode(img.data, filename.c_str());
500+
if (ret == 0)
501+
{
502+
old_w = img.cols;
503+
old_h = img.rows;
504+
old_ch = c;
505+
old_quality = quality;
506+
return true;
507+
}
508+
}
509+
}
457510

458511
// fallback to stb_image_write
459512
}
@@ -808,6 +861,39 @@ bool imencode(const String& ext, InputArray _img, std::vector<uchar>& buf, const
808861
return true;
809862
}
810863
}
864+
// fallback to stb_image_write
865+
}
866+
#endif
867+
#if CV_WITH_CIX
868+
if (jpeg_encoder_v4l_cix::supported(img.cols, img.rows, c))
869+
{
870+
// anything to bgr
871+
if (!img.isContinuous())
872+
{
873+
img = img.clone();
874+
}
875+
876+
int quality = 95;
877+
for (size_t i = 0; i < params.size(); i += 2)
878+
{
879+
if (params[i] == IMWRITE_JPEG_QUALITY)
880+
{
881+
quality = params[i + 1];
882+
break;
883+
}
884+
}
885+
886+
jpeg_encoder_v4l_cix e;
887+
int ret = e.init(img.cols, img.rows, c, quality);
888+
if (ret == 0)
889+
{
890+
ret = e.encode(img.data, buf);
891+
if (ret == 0)
892+
{
893+
e.deinit();
894+
return true;
895+
}
896+
}
811897

812898
// fallback to stb_image_write
813899
}

0 commit comments

Comments
 (0)