Skip to content

Commit

Permalink
Add mouse tracking and display color information
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoming <2014500726@smail.xtu.edu.cn>
  • Loading branch information
QQxiaoming committed Feb 6, 2024
1 parent 56e52c4 commit 71d745d
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 24 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- 'README_zh_CN.md'
- 'DEVELOPNOTE.md'
- '.readthedocs.yaml'
tags:
- V**
pull_request:
branches: [ main ]
paths-ignore:
Expand Down Expand Up @@ -47,8 +49,7 @@ jobs:
- name: Build all
run: |
git fetch --tags --force
git describe --always --long --dirty --abbrev=10 --tags | awk '{print "\""$0"\""}' > git_tag.inc
sed -i 's/git_tag.inc/git_tag.ci.inc/g' YUVviewer.pro
sed -i 's/--long --dirty/--long/g' ./tools/generate_info.sh
sed -i 's/QT_DIR=\/opt\/Qt6.2.0\/6.2.0\/gcc_64/QT_DIR=$(cd "$(dirname "$0")";pwd)\/..\/Qt\/6.2.0\/gcc_64/g' build_deb.sh
sed -i 's/\/home\/xiaoming\/Desktop\/opencv/\/usr\/local/g' build_deb.sh
sed -i 's/\/home\/xiaoming\/Desktop\/opencv/\/usr\/local/g' partform_unix.pri
Expand Down
53 changes: 51 additions & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- 'README_zh_CN.md'
- 'DEVELOPNOTE.md'
- '.readthedocs.yaml'
tags:
- V**
pull_request:
branches: [ main ]
paths-ignore:
Expand Down Expand Up @@ -49,8 +51,7 @@ jobs:
- name: Build all
run: |
git fetch --tags --force
git describe --always --long --dirty --abbrev=10 --tags | awk '{print "\""$0"\""}' > git_tag.inc
sed -i'.original' -e 's/git_tag.inc/git_tag.ci.inc/g' YUVviewer.pro
sed -i'.original' -e 's/--long --dirty/--long/g' ./tools/generate_info.sh
sed -i'.original' -e 's/QT_DIR=\/opt\/Qt6.2.0\/6.2.0\/gcc_64/QT_DIR=$(cd "$(dirname "$0")";pwd)\/..\/Qt\/6.2.0\/macos/g' build_dmg.sh
sed -i'.original' -e 's/\/home\/xiaoming\/Desktop\/opencv/\/usr\/local/g' build_dmg.sh
sed -i'.original' -e 's/\/home\/xiaoming\/Desktop\/opencv/\/usr\/local/g' partform_unix.pri
Expand All @@ -67,3 +68,51 @@ jobs:
run: |
sudo hdiutil attach ./build_release/out/YUVviewer.dmg
/Volumes/YUVviewer/YUVviewer.app/Contents/MacOS/YUVviewer --version
macos_arm64:
runs-on: macos-14

steps:
- uses: actions/checkout@v4

- name: Install Qt
uses: jurplel/install-qt-action@v3.3.0
with:
version: '6.2.0'

- name: Install prerequisites
shell: bash -l {0}
run: |
ruby - e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2 > /dev/null
brew reinstall --build-from-source cmake
ln -s /usr/local/Cellar/cmake/3.27.1 /usr/local/Cellar/cmake/3.26.4
brew install create-dmg
ruby - e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2 > /dev/null
brew install --build-from-source cmake
git clone https://github.com/opencv/opencv.git --branch 4.0.0 --depth 1
cmake -S opencv -B opencv/build -D ENABLE_PRECOMPILED_HEADERS=OFF -D WITH_MSMF=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -D BUILD_WITH_DEBUG_INFO=OFF -D BUILD_DOCS=OFF -D WITH_JPEG=OFF -D WITH_FFMPEG=OFF -D CMAKE_BUILD_TYPE=RELEASE
cd ./opencv/build
make
sudo make install
- name: Build all
run: |
git fetch --tags --force
sed -i'.original' -e 's/--long --dirty/--long/g' ./tools/generate_info.sh
sed -i'.original' -e 's/QT_DIR=\/opt\/Qt6.2.0\/6.2.0\/gcc_64/QT_DIR=$(cd "$(dirname "$0")";pwd)\/..\/Qt\/6.2.0\/macos/g' build_dmg.sh
sed -i'.original' -e 's/\/home\/xiaoming\/Desktop\/opencv/\/usr\/local/g' build_dmg.sh
sed -i'.original' -e 's/\/home\/xiaoming\/Desktop\/opencv/\/usr\/local/g' partform_unix.pri
./build_dmg.sh
- name: Upload build asserts
uses: actions/upload-artifact@v4.3.0
with:
name: YUVviewer_macos
path: |
./build_release/out/YUVviewer.dmg
- name: Run tests
run: |
sudo hdiutil attach ./build_release/out/YUVviewer.dmg
/Volumes/YUVviewer/YUVviewer.app/Contents/MacOS/YUVviewer --version
5 changes: 3 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- 'README_zh_CN.md'
- 'DEVELOPNOTE.md'
- '.readthedocs.yaml'
tags:
- V**
pull_request:
branches: [ main ]
paths-ignore:
Expand Down Expand Up @@ -69,8 +71,7 @@ jobs:
- name: Build all
run: |
git fetch --tags --force
git describe --always --long --dirty --abbrev=10 --tags | ./tools/awk/awk.exe '{print \"\\\"\"$0\"\\\"\"}' > git_tag.inc
./tools/sed/sed.exe -i "s/git_tag.inc/git_tag.ci.inc/g" YUVviewer.pro
./tools/sed/sed.exe -i 's/--long --dirty/--long/g' ./tools/generate_info.ps1
./tools/sed/sed.exe -i "s/QT_DIR=C:\/Qt\/Qt6.2.0\/6.2.0\/mingw81_32\/bin/QT_DIR=%Qt5_Dir%/g" ./build_setup.bat
./tools/sed/sed.exe -i "s/QT_TOOLS_DIR=C:\/Qt\/Qt6.2.0\/Tools\/mingw810_32\/bin/QT_TOOLS_DIR=C:\/ProgramData\/Chocolatey\/lib\/mingw\/tools\/install\/mingw64\/bin/g" ./build_setup.bat
./tools/sed/sed.exe -i "s/OPENCV_DIR=D:\/Qt\/opencv4.2.0\/x64\/mingw\/bin/OPENCV_DIR=C:\/opencv4.0.0\/x64\/mingw\/bin/g" ./build_setup.bat
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ CMakeLists.txt.user*
# rust
/target

git_tag.inc
git_tag.ci.inc
build_info.inc
.DS_Store
lang/yuvviewer_en_US.qm
lang/yuvviewer_ja_JP.qm
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# YUVviewer

English | [简体中文](./README_zh_CN.md)
🇺🇸 English | [🇨🇳 简体中文](./README_zh_CN.md)

YUVviewer is a small tool for developers to view and preview various original image formats. It is based on the framework of Qt and opencv and supports windows/linux/macos. The interface is simple and clear, and the operation is portable. The main interface is as follows:

Expand Down
2 changes: 1 addition & 1 deletion README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# YUVviewer

[English](./README.md) | 简体中文
[🇺🇸 English](./README.md) | 🇨🇳 简体中文

YUVviewer一款用于开发人员查看预览各种原始图像格式的小工具,其基于Qt和opencv的框架,支持windows/linux/macos,界面简单清晰,操作便携,主界面如下:

Expand Down
14 changes: 7 additions & 7 deletions YUVviewer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ win32:{
QMAKE_TARGET_DESCRIPTION = "YUVviewer based on Qt $$[QT_VERSION]"
QMAKE_TARGET_COPYRIGHT = "GNU General Public License v3.0"

git_tag.commands = $$quote("cd $$PWD && git describe --always --long --dirty --abbrev=10 --tags | $$PWD/tools/awk/awk.exe \'{print \"\\\"\"\$$0\"\\\"\"}\' > git_tag.inc")
build_info.commands = $$quote("c:/Windows/system32/WindowsPowerShell/v1.0/powershell.exe -ExecutionPolicy Bypass -NoLogo -NoProfile -File \"$$PWD/tools/generate_info.ps1\" > $$PWD/build_info.inc")
}

unix:!macx:{
Expand All @@ -105,7 +105,7 @@ unix:!macx:{
LIBS += -L $${OPENCV_DIR}/lib/ -lopencv_imgcodecs
LIBS += -L $${OPENCV_DIR}/lib/ -lopencv_core

git_tag.commands = $$quote("cd $$PWD && git describe --always --long --dirty --abbrev=10 --tags | awk \'{print \"\\\"\"\$$0\"\\\"\"}\' > git_tag.inc")
build_info.commands = $$quote("cd $$PWD && ./tools/generate_info.sh > build_info.inc")
}

macx:{
Expand All @@ -122,12 +122,12 @@ macx:{
LIBS += -L $${OPENCV_DIR}/lib/ -lopencv_imgcodecs
LIBS += -L $${OPENCV_DIR}/lib/ -lopencv_core

git_tag.commands = $$quote("cd $$PWD && git describe --always --long --dirty --abbrev=10 --tags | awk \'{print \"\\\"\"\$$0\"\\\"\"}\' > git_tag.inc")
build_info.commands = $$quote("cd $$PWD && ./tools/generate_info.sh > build_info.inc")
}

git_tag.target = $$PWD/git_tag.inc
git_tag.depends = FORCE
PRE_TARGETDEPS += $$PWD/git_tag.inc
QMAKE_EXTRA_TARGETS += git_tag
build_info.target = $$PWD/build_info.inc
build_info.depends = FORCE
PRE_TARGETDEPS += $$PWD/build_info.inc
QMAKE_EXTRA_TARGETS += build_info

###############################################################################
2 changes: 1 addition & 1 deletion dpkg/YUVviewer/DEBIAN/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Architecture: amd64
Section: utils
Depends:
Recommends:
Source: YUVviewer
Source: yuvviewer
Installed-Size: #SIZE#
Priority: extra
Maintainer: QQxiaoming <2014500726@smail.xtu.edu.cn> zhiliao007 <wenqing.li@aliyun.com>
Expand Down
34 changes: 32 additions & 2 deletions src/ImgViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ ImgViewer::ImgViewer(const QString &folderpath, QWidget *parent,QWidget *parentW
setWindowTitle("loading file, please wait ....");
ui->left_PushButton->setFlat(true);
ui->right_PushButton->setFlat(true);
setMouseTracking(true);
QObject::connect(ui->left_PushButton, SIGNAL(clicked()), this, SLOT(previousImg()));
QObject::connect(ui->right_PushButton, SIGNAL(clicked()), this, SLOT(nextImg()));
left_click = false;
Expand Down Expand Up @@ -214,23 +215,52 @@ void ImgViewer::draw_img(QPainter *painter) {
painter->drawPixmap(this->point, QPixmap::fromImage(this->scaled_img));
}

void ImgViewer::draw_info(QPainter *painter) {
if (isMouseInImg) {
int r = qRed(currentMousePosColor);
int g = qGreen(currentMousePosColor);
int b = qBlue(currentMousePosColor);
int x = currentMousePos.x();
int y = currentMousePos.y();
QString info = QString("x:%1 y:%2 R:%3 G:%4 B:%5").arg(x).arg(y).arg(r).arg(g).arg(b);
QPen pen;
pen.setColor(Qt::black);
painter->setPen(pen);
painter->drawText(20, this->height() - 20, info);
}
}

void ImgViewer::paintEvent(QPaintEvent *event) {
if (!this->img_list.empty()) {
QPainter painter;
painter.begin(this);
draw_img(&painter);
draw_info(&painter);
painter.end();
}
(void)event;
Q_UNUSED(event);
}

void ImgViewer::mouseMoveEvent(QMouseEvent *event) {
if (!this->img_list.empty()) {
QRgb current_color = currentMousePosColor;
bool current_isMouseInImg = isMouseInImg;
if (this->scaled_img.rect().contains(event->pos()-this->point)) {
isMouseInImg = true;
currentMousePosColor = this->scaled_img.pixel(event->pos()-this->point);
currentMousePos = event->pos()-this->point;
} else {
isMouseInImg = false;
}
if( this->left_click) {
this->endPos = event->pos() - this->startPos;
this->point = this->point + this->endPos;
this->startPos = event->pos();
this->repaint();
this->update();
} else {
if(current_color != currentMousePosColor || current_isMouseInImg != isMouseInImg) {
this->update();
}
}
}
(void)event;
Expand Down
4 changes: 4 additions & 0 deletions src/ImgViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private slots:

private:
void draw_img(QPainter *painter);
void draw_info(QPainter *painter);
Ui::ImgViewerWindow *ui;
ImgExport *imgExportWindow;
QWidget *parentWindow;
Expand All @@ -108,6 +109,9 @@ private slots:
QPoint endPos;
bool flipRGB = false;
static void image_cleanup(cv::Mat* ptr);
QRgb currentMousePosColor;
QPoint currentMousePos;
bool isMouseInImg = false;
};

#endif // IMGVIEWER_H
9 changes: 6 additions & 3 deletions src/YUVviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
#include "YUVviewer.h"
#include "ui_UI_YUVviewer.h"

#include "build_info.inc"

const QString VERSION = APP_VERSION;
const QString GIT_TAG =
#include <git_tag.inc>
;
const QString GIT_TAG = BUILD_INFO;
const QString DATE_TAG = BUILD_DATE;
const QString HASH_TAG = BUILD_HASH;
const QString SHORT_HASH_TAG = BUILD_SHORT_HASH;

const QList<QPair<QString, QStringList>> YUVviewer::frameSizeTypeDict = {
{"QQCIF", {"88","72"}},
Expand Down
20 changes: 20 additions & 0 deletions tools/generate_info.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

$git_info = $(git describe --always --long --dirty --abbrev=10 --tags)
$git_short_hash = $(git rev-parse --short HEAD)
$git_hash = $(git rev-parse HEAD)
$date_info = $([String]::Format("{0:yyyy-MM-ddTHH:mm:ss.fffZ}", $(Get-Date).ToUniversalTime()))

Write-Output "#ifndef __BUILD_INFO_H__"
Write-Output "#define __BUILD_INFO_H__"
Write-Output ""
Write-Output "#define BUILD_INFO ""$git_info"""
Write-Output "#define BUILD_INFO_LEN $($git_info.Length)"
Write-Output "#define BUILD_HASH ""$git_hash"""
Write-Output "#define BUILD_HASH_LEN $($git_hash.Length)"
Write-Output "#define BUILD_SHORT_HASH ""$git_short_hash"""
Write-Output "#define BUILD_SHORT_HASH_LEN $($git_short_hash.Length)"
Write-Output "#define BUILD_DATE ""$date_info"""
Write-Output "#define BUILD_DATE_LEN $($date_info.Length)"
Write-Output ""
Write-Output "#endif // __BUILD_INFO_H__"

28 changes: 28 additions & 0 deletions tools/generate_info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

UNAMEOUT="$(uname -s)"
case "${UNAMEOUT}" in
Linux*)
date_info=$(date +"%Y-%m-%dT%H:%M:%S.%3NZ")
;;
Darwin*)
date_info=$(gdate +"%Y-%m-%dT%H:%M:%S.%3NZ")
;;
esac

git_info=$(git describe --always --long --dirty --abbrev=10 --tags)
git_short_hash=$(git rev-parse --short HEAD)
git_hash=$(git rev-parse HEAD)

echo "#ifndef __BUILD_INFO_H__"
echo "#define __BUILD_INFO_H__"
echo
echo "#define BUILD_INFO \"${git_info}\""
echo "#define BUILD_INFO_LEN ${#git_info}"
echo "#define BUILD_HASH \"${git_hash}\""
echo "#define BUILD_HASH_LEN ${#git_hash}"
echo "#define BUILD_SHORT_HASH \"${git_short_hash}\""
echo "#define BUILD_SHORT_HASH_LEN ${#git_short_hash}"
echo "#define BUILD_DATE \"${date_info}\""
echo "#define BUILD_DATE_LEN ${#date_info}"
echo
echo "#endif /* __BUILD_INFO_H__ */"
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.6
0.5.7

0 comments on commit 71d745d

Please sign in to comment.