Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aw jpg decoder and encoder #96

Merged
merged 10 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: release
on: pull_request
# on:
# push:
# tags:
# - '*'
# on: pull_request
on:
push:
tags:
- '*'

env:
DEVELOPER_DIR: /Applications/Xcode_13.4.1.app/Contents/Developer
Expand Down Expand Up @@ -1247,21 +1247,21 @@ jobs:
name: ${{ env.PACKAGE_NAME }}
path: ${{ env.PACKAGE_NAME }}.zip

# release:
# permissions:
# contents: write # for softprops/action-gh-release to create a release
# needs: [setup, android, ios, ios-simulator, armlinux, macos, mac-catalyst, windows, ubuntu, webassembly, apple, devboard]
# runs-on: ubuntu-latest
# steps:
# - name: download
# uses: actions/download-artifact@v4
# with:
# path: artifacts
#
# - name: create-release
# uses: softprops/action-gh-release@v1
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
# tag_name: ${{ needs.setup.outputs.VERSION }}
# name: Release ${{ needs.setup.outputs.VERSION }}
# files: artifacts/*/*.zip
release:
permissions:
contents: write # for softprops/action-gh-release to create a release
needs: [setup, android, ios, ios-simulator, armlinux, macos, mac-catalyst, windows, ubuntu, webassembly, apple, devboard]
runs-on: ubuntu-latest
steps:
- name: download
uses: actions/download-artifact@v4
with:
path: artifacts

- name: create-release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ needs.setup.outputs.VERSION }}
name: Release ${{ needs.setup.outputs.VERSION }}
files: artifacts/*/*.zip
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ https://github.com/nihui/opencv-mobile/releases/latest
<br /><b>tinyvision</b>
</a>
<br />arm-linux-uclibcgnueabihf<br />
&#10060; HW JPG decoder (WIP)<br />
&#10060; HW JPG encoder (WIP)<br />
&#9989; HW JPG decoder<br />
&#9989; HW JPG encoder<br />
&#9989; MIPI CSI camera<br />
<a href="https://github.com/nihui/opencv-mobile/releases/latest/download/opencv-mobile-4.9.0-tinyvision.zip">
<img alt="opencv4-tinyvision" src="https://img.shields.io/badge/download-4.9.0-blue?style=for-the-badge">
Expand Down
3 changes: 3 additions & 0 deletions highgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ set(highgui_srcs
${CMAKE_CURRENT_LIST_DIR}/src/capture_v4l2_rk_aiq.cpp
${CMAKE_CURRENT_LIST_DIR}/src/exif.cpp
${CMAKE_CURRENT_LIST_DIR}/src/highgui.cpp
${CMAKE_CURRENT_LIST_DIR}/src/jpeg_decoder_aw.cpp
${CMAKE_CURRENT_LIST_DIR}/src/jpeg_decoder_cvi.cpp
${CMAKE_CURRENT_LIST_DIR}/src/jpeg_encoder_aw.cpp
${CMAKE_CURRENT_LIST_DIR}/src/jpeg_encoder_rk_mpp.cpp
${CMAKE_CURRENT_LIST_DIR}/src/kanna_rotate.cpp
${CMAKE_CURRENT_LIST_DIR}/src/videocapture.cpp
)

Expand Down
126 changes: 126 additions & 0 deletions highgui/src/highgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
#include "stb_image_write.h"

#if defined __linux__
#include "jpeg_decoder_aw.h"
#include "jpeg_decoder_cvi.h"
#include "jpeg_encoder_aw.h"
#include "jpeg_encoder_rk_mpp.h"
#endif

Expand Down Expand Up @@ -154,6 +156,36 @@ Mat imread(const String& filename, int flags)
if (buf_size > 4 && buf_data[0] == 0xFF && buf_data[1] == 0xD8)
{
// jpg magic
if (jpeg_decoder_aw::supported(buf_data, buf_size))
{
int w = 0;
int h = 0;
int c = desired_channels;

jpeg_decoder_aw d;
int ret = d.init(buf_data, buf_size, &w, &h, &c);
if (ret == 0 && (c == 1 || c == 3))
{
Mat img;
if (c == 1)
{
img.create(h, w, CV_8UC1);
}
else // if (c == 3)
{
img.create(h, w, CV_8UC3);
}

ret = d.decode(buf_data, buf_size, img.data);
if (ret == 0)
{
d.deinit();
return img;
}
}

// fallback to stbi_load_from_memory
}
if (jpeg_decoder_cvi::supported(buf_data, buf_size))
{
int w = 0;
Expand Down Expand Up @@ -289,6 +321,38 @@ bool imwrite(const String& filename, InputArray _img, const std::vector<int>& pa
#if defined __linux__
if (ext == ".jpg" || ext == ".jpeg" || ext == ".JPG" || ext == ".JPEG")
{
if (jpeg_encoder_aw::supported(img.cols, img.rows, c))
{
// anything to bgr
if (!img.isContinuous())
{
img = img.clone();
}

int quality = 95;
for (size_t i = 0; i < params.size(); i += 2)
{
if (params[i] == IMWRITE_JPEG_QUALITY)
{
quality = params[i + 1];
break;
}
}

jpeg_encoder_aw e;
int ret = e.init(img.cols, img.rows, c, quality);
if (ret == 0)
{
ret = e.encode(img.data, filename.c_str());
if (ret == 0)
{
e.deinit();
return true;
}
}

// fallback to stb_image_write
}
if (jpeg_encoder_rk_mpp::supported(img.cols, img.rows, c))
{
// anything to bgr
Expand Down Expand Up @@ -410,6 +474,36 @@ Mat imdecode(InputArray _buf, int flags)
if (buf_size > 4 && buf_data[0] == 0xFF && buf_data[1] == 0xD8)
{
// jpg magic
if (jpeg_decoder_aw::supported(buf_data, buf_size))
{
int w = 0;
int h = 0;
int c = desired_channels;

jpeg_decoder_aw d;
int ret = d.init(buf_data, buf_size, &w, &h, &c);
if (ret == 0 && (c == 1 || c == 3))
{
Mat img;
if (c == 1)
{
img.create(h, w, CV_8UC1);
}
else // if (c == 3)
{
img.create(h, w, CV_8UC3);
}

ret = d.decode(buf_data, buf_size, img.data);
if (ret == 0)
{
d.deinit();
return img;
}
}

// fallback to stbi_load_from_memory
}
if (jpeg_decoder_cvi::supported(buf_data, buf_size))
{
int w = 0;
Expand Down Expand Up @@ -543,6 +637,38 @@ bool imencode(const String& ext, InputArray _img, std::vector<uchar>& buf, const
#if defined __linux__
if (ext == ".jpg" || ext == ".jpeg" || ext == ".JPG" || ext == ".JPEG")
{
if (jpeg_encoder_aw::supported(img.cols, img.rows, c))
{
// anything to bgr
if (!img.isContinuous())
{
img = img.clone();
}

int quality = 95;
for (size_t i = 0; i < params.size(); i += 2)
{
if (params[i] == IMWRITE_JPEG_QUALITY)
{
quality = params[i + 1];
break;
}
}

jpeg_encoder_aw e;
int ret = e.init(img.cols, img.rows, c, quality);
if (ret == 0)
{
ret = e.encode(img.data, buf);
if (ret == 0)
{
e.deinit();
return true;
}
}

// fallback to stb_image_write
}
if (jpeg_encoder_rk_mpp::supported(img.cols, img.rows, c))
{
// anything to bgr
Expand Down
Loading