diff options
Diffstat (limited to 'video')
-rw-r--r-- | video/CMakeLists.txt | 1 | ||||
-rw-r--r-- | video/export.hpp | 11 | ||||
-rw-r--r-- | video/lang/nl_NL.ts | 4 | ||||
-rw-r--r-- | video/lang/ru_RU.ts | 4 | ||||
-rw-r--r-- | video/lang/stub.ts | 4 | ||||
-rw-r--r-- | video/lang/zh_CN.ts | 4 | ||||
-rw-r--r-- | video/video-widget.cpp | 84 | ||||
-rw-r--r-- | video/video-widget.hpp | 46 |
8 files changed, 158 insertions, 0 deletions
diff --git a/video/CMakeLists.txt b/video/CMakeLists.txt new file mode 100644 index 00000000..0a9dfd24 --- /dev/null +++ b/video/CMakeLists.txt @@ -0,0 +1 @@ +otr_module(video BIN) diff --git a/video/export.hpp b/video/export.hpp new file mode 100644 index 00000000..fc850193 --- /dev/null +++ b/video/export.hpp @@ -0,0 +1,11 @@ +// generates export.hpp for each module from compat/linkage.hpp + +#pragma once + +#include "compat/linkage-macros.hpp" + +#ifdef BUILD_VIDEO +# define OTR_VIDEO_EXPORT OTR_GENERIC_EXPORT +#else +# define OTR_VIDEO_EXPORT OTR_GENERIC_IMPORT +#endif diff --git a/video/lang/nl_NL.ts b/video/lang/nl_NL.ts new file mode 100644 index 00000000..6401616d --- /dev/null +++ b/video/lang/nl_NL.ts @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1"> +</TS> diff --git a/video/lang/ru_RU.ts b/video/lang/ru_RU.ts new file mode 100644 index 00000000..6401616d --- /dev/null +++ b/video/lang/ru_RU.ts @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1"> +</TS> diff --git a/video/lang/stub.ts b/video/lang/stub.ts new file mode 100644 index 00000000..6401616d --- /dev/null +++ b/video/lang/stub.ts @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1"> +</TS> diff --git a/video/lang/zh_CN.ts b/video/lang/zh_CN.ts new file mode 100644 index 00000000..6401616d --- /dev/null +++ b/video/lang/zh_CN.ts @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.1"> +</TS> diff --git a/video/video-widget.cpp b/video/video-widget.cpp new file mode 100644 index 00000000..3e6d9038 --- /dev/null +++ b/video/video-widget.cpp @@ -0,0 +1,84 @@ +#include "video-widget.hpp" + +#include "compat/check-visible.hpp" +#include "compat/math.hpp" + +#include <cstddef> +#include <cstring> + +#include <QPainter> + +void video_widget::init_image_nolock() +{ + texture = QImage(W, H, QImage::Format_ARGB32); + texture.setDevicePixelRatio(devicePixelRatioF()); +} + +video_widget::video_widget(QWidget* parent) : QWidget(parent) +{ + W = width(); H = height(); + init_image_nolock(); texture.fill(Qt::gray); + + connect(&timer, &QTimer::timeout, this, &video_widget::update_and_repaint, Qt::DirectConnection); + timer.start(65); +} + +void video_widget::update_image(const QImage& img) +{ + QMutexLocker l(&mtx); + + if (freshp) + return; + freshp = true; + + unsigned nbytes = (unsigned)(img.bytesPerLine() * img.height()); + vec.resize(nbytes); vec.shrink_to_fit(); + std::memcpy(vec.data(), img.constBits(), nbytes); + + texture = QImage((const unsigned char*) vec.data(), img.width(), img.height(), img.bytesPerLine(), img.format()); + texture.setDevicePixelRatio(devicePixelRatioF()); +} + +void video_widget::paintEvent(QPaintEvent*) +{ + QMutexLocker foo(&mtx); + + if (texture.width() != W || texture.height() != H) + { + init_image_nolock(); + texture.fill(Qt::gray); + } + + QPainter painter(this); + painter.drawImage(rect(), texture); +} + +void video_widget::update_and_repaint() +{ + if (!check_is_visible()) + return; + + QMutexLocker l(&mtx); + + if (freshp) + { + freshp = false; + repaint(); + } +} + +void video_widget::resizeEvent(QResizeEvent*) +{ + QMutexLocker l(&mtx); + double dpr = devicePixelRatioF(); + W = iround(width() * dpr); + H = iround(height() * dpr); + init_image_nolock(); +} + +void video_widget::get_preview_size(int& w, int& h) +{ + QMutexLocker l(&mtx); + w = W; h = H; +} + diff --git a/video/video-widget.hpp b/video/video-widget.hpp new file mode 100644 index 00000000..563f468c --- /dev/null +++ b/video/video-widget.hpp @@ -0,0 +1,46 @@ +/* Copyright (c) 2014-2016, 2019 Stanislaw Halik <sthalik@misaki.pl> + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + +#pragma once + +#include "compat/math.hpp" +#include "export.hpp" + +#include <vector> + +#include <QWidget> +#include <QTimer> +#include <QMutex> + +class OTR_VIDEO_EXPORT video_widget : public QWidget +{ + Q_OBJECT + +public: + video_widget(QWidget* parent = nullptr); + + void update_image(const QImage& image); + void get_preview_size(int& w, int& h); + void resizeEvent(QResizeEvent*) override; +protected slots: + void paintEvent(QPaintEvent*) override; + void update_and_repaint(); +private: + QTimer timer; + +protected: + QMutex mtx { QMutex::Recursive }; + QImage texture; + std::vector<unsigned char> vec; + + bool freshp = false; + + int W = iround(QWidget::width() * devicePixelRatioF()); + int H = iround(QWidget::height() * devicePixelRatioF()); + + void init_image_nolock(); +}; |