Changing default config + Adding Antialiasing + More settings

This commit is contained in:
Alexis Delhaie
2020-12-05 18:12:21 +01:00
parent c53cc966ab
commit 3fbcadf59b
4 changed files with 501 additions and 341 deletions

View File

@@ -2,7 +2,7 @@ QT += core gui multimedia multimediawidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17 CONFIG += c++11
# The following define makes your compiler emit warnings if you use # The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings # any Qt feature that has been marked deprecated (the exact warnings
@@ -16,6 +16,7 @@ QMAKE_CXXFLAGS_RELEASE -= -O1
QMAKE_CXXFLAGS_RELEASE *= -O2 QMAKE_CXXFLAGS_RELEASE *= -O2
RC_ICONS = icon.ico RC_ICONS = icon.ico
VERSION = 1.1.0.0
# You can also make your code fail to compile if it uses deprecated APIs. # You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line. # In order to do so, uncomment the following line.

View File

@@ -13,6 +13,8 @@ MainWindow::MainWindow(QWidget *parent)
ui->devicesBox->addItem(cameraInfo.description()); ui->devicesBox->addItem(cameraInfo.description());
} }
ui->devicesBox->setEditText(QCameraInfo::defaultCamera().description()); ui->devicesBox->setEditText(QCameraInfo::defaultCamera().description());
canvasFont = QFont("Consolas", 6);
canvasFont.setStyleStrategy(QFont::PreferAntialias);
revert(); revert();
init(QCameraInfo::defaultCamera()); init(QCameraInfo::defaultCamera());
QObject::connect(ui->startAndStopButton, &QPushButton::clicked, this, &MainWindow::start_or_stop); QObject::connect(ui->startAndStopButton, &QPushButton::clicked, this, &MainWindow::start_or_stop);
@@ -21,10 +23,13 @@ MainWindow::MainWindow(QWidget *parent)
QObject::connect(ui->sourceHeight, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &MainWindow::config_changed); QObject::connect(ui->sourceHeight, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &MainWindow::config_changed);
QObject::connect(ui->asciiWidth, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &MainWindow::config_changed); QObject::connect(ui->asciiWidth, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &MainWindow::config_changed);
QObject::connect(ui->asciiHeight, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &MainWindow::config_changed); QObject::connect(ui->asciiHeight, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &MainWindow::config_changed);
QObject::connect(ui->bitmapWidth, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &MainWindow::config_changed);
QObject::connect(ui->bitmapHeight, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &MainWindow::config_changed);
QObject::connect(ui->charEdit, &QLineEdit::textEdited, this, &MainWindow::config_changed); QObject::connect(ui->charEdit, &QLineEdit::textEdited, this, &MainWindow::config_changed);
QObject::connect(ui->disableProcess, &QCheckBox::clicked, this, &MainWindow::config_changed); QObject::connect(ui->disableProcess, &QCheckBox::clicked, this, &MainWindow::config_changed);
QObject::connect(ui->applyButton, &QPushButton::clicked, this, &MainWindow::apply); QObject::connect(ui->applyButton, &QPushButton::clicked, this, &MainWindow::apply);
QObject::connect(ui->revertButton, &QPushButton::clicked, this, &MainWindow::revert); QObject::connect(ui->revertButton, &QPushButton::clicked, this, &MainWindow::revert);
QObject::connect(ui->fontButton, &QPushButton::clicked, this, &MainWindow::change_font);
QObject::connect(this, &MainWindow::image_processed, [&, this] (QPixmap img) { QObject::connect(this, &MainWindow::image_processed, [&, this] (QPixmap img) {
img = img.scaled(ascii_width, ascii_height); img = img.scaled(ascii_width, ascii_height);
ui->screen->setPixmap(img); ui->screen->setPixmap(img);
@@ -87,17 +92,17 @@ void MainWindow::convert(QImage in) {
} }
res += '\n'; res += '\n';
} }
QBitmap bitmap(1920,1080); QImage image(bitmap_width, bitmap_height, QImage::Format_Grayscale8);
bitmap.fill(Qt::white); image.fill(Qt::white);
QPainter painter(&bitmap); QPainter painter(&image);
QFont serifFont("Consolas", 12); painter.setRenderHints(QPainter::TextAntialiasing);
painter.setFont(serifFont); painter.setFont(canvasFont);
painter.setPen(Qt::black); painter.setPen(Qt::black);
const QRect rectangle = QRect(0, 0, 1920, 1080); const QRect rectangle = QRect(0, 0, bitmap_width, bitmap_height);
QRect boundingRect; QRect boundingRect;
painter.drawText(rectangle, 0, res, &boundingRect); painter.drawText(rectangle, 0, res, &boundingRect);
painter.save(); painter.save();
QPixmap pix(bitmap); QPixmap pix = QPixmap::fromImage(image);
emit image_processed(pix); emit image_processed(pix);
} }
@@ -140,9 +145,12 @@ void MainWindow::apply() {
source_height = ui->sourceHeight->value(); source_height = ui->sourceHeight->value();
ascii_width = ui->asciiWidth->value(); ascii_width = ui->asciiWidth->value();
ascii_height = ui->asciiHeight->value(); ascii_height = ui->asciiHeight->value();
bitmap_width = ui->bitmapWidth->value();
bitmap_height = ui->bitmapHeight->value();
chars = ui->charEdit->text(); chars = ui->charEdit->text();
disable_process = ui->disableProcess->checkState(); disable_process = ui->disableProcess->checkState();
refresh_timer = ui->refreshTimer->value(); refresh_timer = ui->refreshTimer->value();
canvasFont = canvasFont_tmp;
} }
void MainWindow::revert() { void MainWindow::revert() {
@@ -150,13 +158,32 @@ void MainWindow::revert() {
ui->sourceHeight->setValue(source_height); ui->sourceHeight->setValue(source_height);
ui->asciiWidth->setValue(ascii_width); ui->asciiWidth->setValue(ascii_width);
ui->asciiHeight->setValue(ascii_height); ui->asciiHeight->setValue(ascii_height);
ui->bitmapWidth->setValue(bitmap_width);
ui->bitmapHeight->setValue(bitmap_height);
ui->charEdit->setText(chars); ui->charEdit->setText(chars);
ui->refreshTimer->setValue(refresh_timer); ui->refreshTimer->setValue(refresh_timer);
ui->applyButton->setEnabled(false); ui->applyButton->setEnabled(false);
ui->revertButton->setEnabled(false); ui->revertButton->setEnabled(false);
canvasFont_tmp = canvasFont;
update_font_label();
} }
void MainWindow::config_changed() { void MainWindow::config_changed() {
ui->applyButton->setEnabled(true); ui->applyButton->setEnabled(true);
ui->revertButton->setEnabled(true); ui->revertButton->setEnabled(true);
} }
void MainWindow::change_font() {
bool ok;
QFont font = QFontDialog::getFont(&ok, canvasFont_tmp, this);
if (ok) {
canvasFont_tmp = font;
canvasFont_tmp.setStyleStrategy(QFont::PreferAntialias);
config_changed();
update_font_label();
}
}
void MainWindow::update_font_label() {
ui->fontLabel->setText(canvasFont_tmp.toString());
}

View File

@@ -14,6 +14,8 @@
#include <QPainter> #include <QPainter>
#include <QStaticText> #include <QStaticText>
#include <QCameraInfo> #include <QCameraInfo>
#include <QFontDialog>
#include <QString>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; } namespace Ui { class MainWindow; }
@@ -32,6 +34,8 @@ public slots:
void apply(); void apply();
void revert(); void revert();
void config_changed(); void config_changed();
void change_font();
void update_font_label();
signals: signals:
void image_processed(QPixmap img); void image_processed(QPixmap img);
@@ -47,13 +51,20 @@ private:
QCameraInfo selected_camera; QCameraInfo selected_camera;
bool thread_running = false; bool thread_running = false;
QString chars = " .~#☻░▒"; QString chars = "@#P+;-. ";
int source_width = 480; int source_width = 320;
int source_height = 360; int source_height = 240;
int ascii_width = 771; int ascii_width = 771;
int ascii_height = 531; int ascii_height = 531;
int bitmap_width = 771;
int bitmap_height = 531;
int refresh_timer = 25; int refresh_timer = 25;
bool disable_process = false; bool disable_process = false;
QFont canvasFont;
QFont canvasFont_tmp;
int fps = 0; int fps = 0;

View File

@@ -12,7 +12,7 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>800</width> <width>1007</width>
<height>561</height> <height>561</height>
</size> </size>
</property> </property>
@@ -42,60 +42,109 @@
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
</property> </property>
</widget> </widget>
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>800</x>
<y>10</y>
<width>20</width>
<height>541</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget> </widget>
<widget class="QComboBox" name="devicesBox"> <widget class="QDockWidget" name="dockWidget">
<property name="minimumSize">
<size>
<width>210</width>
<height>561</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>210</width>
<height>561</height>
</size>
</property>
<property name="features">
<set>QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable</set>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
<attribute name="dockWidgetArea">
<number>2</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents">
<widget class="QSpinBox" name="sourceHeight">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>820</x> <x>126</x>
<y>30</y> <y>110</y>
<width>181</width> <width>61</width>
<height>22</height> <height>22</height>
</rect> </rect>
</property> </property>
<property name="maximum">
<number>2160</number>
</property>
</widget> </widget>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_12">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>820</x> <x>75</x>
<y>10</y> <y>284</y>
<width>47</width> <width>47</width>
<height>14</height> <height>14</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>Device</string> <string>Width</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_11">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>820</x> <x>75</x>
<y>70</y> <y>414</y>
<width>111</width> <width>111</width>
<height>16</height> <height>16</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>Source scale</string> <string>Framerate</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QSpinBox" name="bitmapHeight">
<property name="geometry">
<rect>
<x>127</x>
<y>306</y>
<width>61</width>
<height>22</height>
</rect>
</property>
<property name="maximum">
<number>2160</number>
</property>
</widget>
<widget class="QLabel" name="label_14">
<property name="geometry">
<rect>
<x>76</x>
<y>310</y>
<width>47</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>Height</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_4">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>879</x> <x>74</x>
<y>94</y> <y>88</y>
<width>47</width> <width>47</width>
<height>14</height> <height>14</height>
</rect> </rect>
@@ -107,92 +156,72 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="fontLabel">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>880</x> <x>25</x>
<y>120</y> <y>383</y>
<width>47</width> <width>121</width>
<height>14</height> <height>16</height>
</rect> </rect>
</property> </property>
<property name="maximumSize">
<size>
<width>121</width>
<height>16</height>
</size>
</property>
<property name="text"> <property name="text">
<string>Height</string> <string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
<widget class="QSpinBox" name="sourceWidth"> <widget class="QLabel" name="label_13">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>931</x> <x>15</x>
<y>90</y> <y>254</y>
<width>61</width>
<height>22</height>
</rect>
</property>
<property name="maximum">
<number>3840</number>
</property>
</widget>
<widget class="QSpinBox" name="sourceHeight">
<property name="geometry">
<rect>
<x>931</x>
<y>116</y>
<width>61</width>
<height>22</height>
</rect>
</property>
<property name="maximum">
<number>2160</number>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>820</x>
<y>180</y>
<width>111</width> <width>111</width>
<height>16</height> <height>16</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>ASCII Video output</string> <string>Bitmap (Process)</string>
</property> </property>
</widget> </widget>
<widget class="QSpinBox" name="asciiHeight"> <widget class="QSpinBox" name="refreshTimer">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>932</x> <x>125</x>
<y>232</y> <y>144</y>
<width>61</width> <width>61</width>
<height>22</height> <height>22</height>
</rect> </rect>
</property> </property>
<property name="minimum">
<number>25</number>
</property>
<property name="maximum"> <property name="maximum">
<number>2160</number> <number>5000</number>
</property> </property>
</widget> </widget>
<widget class="QSpinBox" name="asciiWidth"> <widget class="Line" name="line_2">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>932</x> <x>15</x>
<y>206</y> <y>52</y>
<width>61</width> <width>181</width>
<height>22</height> <height>16</height>
</rect> </rect>
</property> </property>
<property name="maximum"> <property name="orientation">
<number>3840</number> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="label_7">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>881</x> <x>76</x>
<y>236</y> <y>230</y>
<width>47</width> <width>47</width>
<height>14</height> <height>14</height>
</rect> </rect>
@@ -204,37 +233,11 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
<widget class="QLabel" name="label_8">
<property name="geometry">
<rect>
<x>880</x>
<y>210</y>
<width>47</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>Width</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QLineEdit" name="charEdit">
<property name="geometry">
<rect>
<x>827</x>
<y>300</y>
<width>161</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_9"> <widget class="QLabel" name="label_9">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>830</x> <x>25</x>
<y>280</y> <y>334</y>
<width>111</width> <width>111</width>
<height>16</height> <height>16</height>
</rect> </rect>
@@ -243,14 +246,215 @@
<string>Characters</string> <string>Characters</string>
</property> </property>
</widget> </widget>
<widget class="QSpinBox" name="asciiWidth">
<property name="geometry">
<rect>
<x>127</x>
<y>200</y>
<width>61</width>
<height>22</height>
</rect>
</property>
<property name="maximum">
<number>3840</number>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>15</x>
<y>64</y>
<width>111</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Source scale (IN)</string>
</property>
</widget>
<widget class="QComboBox" name="devicesBox">
<property name="geometry">
<rect>
<x>15</x>
<y>24</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QSpinBox" name="bitmapWidth">
<property name="geometry">
<rect>
<x>127</x>
<y>280</y>
<width>61</width>
<height>22</height>
</rect>
</property>
<property name="maximum">
<number>3840</number>
</property>
</widget>
<widget class="QLabel" name="label_10">
<property name="geometry">
<rect>
<x>10</x>
<y>145</y>
<width>111</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Refresh timer (ms)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>75</x>
<y>114</y>
<width>47</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>Height</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QCheckBox" name="disableProcess">
<property name="geometry">
<rect>
<x>102</x>
<y>253</y>
<width>111</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Disable process</string>
</property>
</widget>
<widget class="QLineEdit" name="charEdit">
<property name="geometry">
<rect>
<x>22</x>
<y>354</y>
<width>161</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<family>Consolas</family>
<pointsize>9</pointsize>
</font>
</property>
</widget>
<widget class="QLCDNumber" name="framerate">
<property name="geometry">
<rect>
<x>118</x>
<y>434</y>
<width>71</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>15</x>
<y>174</y>
<width>171</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>ASCII Video output (OUT)</string>
</property>
</widget>
<widget class="QLabel" name="label_8">
<property name="geometry">
<rect>
<x>75</x>
<y>204</y>
<width>47</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>Width</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QSpinBox" name="sourceWidth">
<property name="geometry">
<rect>
<x>126</x>
<y>84</y>
<width>61</width>
<height>22</height>
</rect>
</property>
<property name="maximum">
<number>3840</number>
</property>
</widget>
<widget class="QSpinBox" name="asciiHeight">
<property name="geometry">
<rect>
<x>127</x>
<y>226</y>
<width>61</width>
<height>22</height>
</rect>
</property>
<property name="maximum">
<number>2160</number>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>15</x>
<y>4</y>
<width>47</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>Device</string>
</property>
</widget>
<widget class="QPushButton" name="startAndStopButton">
<property name="geometry">
<rect>
<x>26</x>
<y>470</y>
<width>161</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Start</string>
</property>
</widget>
<widget class="QPushButton" name="applyButton"> <widget class="QPushButton" name="applyButton">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>915</x> <x>111</x>
<y>520</y> <y>502</y>
<width>80</width> <width>80</width>
<height>22</height> <height>22</height>
</rect> </rect>
@@ -265,8 +469,8 @@
</property> </property>
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>827</x> <x>23</x>
<y>520</y> <y>502</y>
<width>80</width> <width>80</width>
<height>22</height> <height>22</height>
</rect> </rect>
@@ -275,102 +479,19 @@
<string>Revert</string> <string>Revert</string>
</property> </property>
</widget> </widget>
<widget class="QPushButton" name="startAndStopButton"> <widget class="QPushButton" name="fontButton">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>830</x> <x>151</x>
<y>488</y> <y>379</y>
<width>161</width> <width>31</width>
<height>22</height> <height>22</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>Start</string> <string>...</string>
</property> </property>
</widget> </widget>
<widget class="Line" name="line_2">
<property name="geometry">
<rect>
<x>820</x>
<y>58</y>
<width>181</width>
<height>16</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QCheckBox" name="disableProcess">
<property name="geometry">
<rect>
<x>830</x>
<y>330</y>
<width>161</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Disable process</string>
</property>
</widget>
<widget class="QLabel" name="label_10">
<property name="geometry">
<rect>
<x>815</x>
<y>151</y>
<width>111</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Refresh timer (ms)</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
<widget class="QSpinBox" name="refreshTimer">
<property name="geometry">
<rect>
<x>930</x>
<y>150</y>
<width>61</width>
<height>22</height>
</rect>
</property>
<property name="minimum">
<number>25</number>
</property>
<property name="maximum">
<number>5000</number>
</property>
</widget>
<widget class="QLCDNumber" name="framerate">
<property name="geometry">
<rect>
<x>923</x>
<y>440</y>
<width>71</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_11">
<property name="geometry">
<rect>
<x>880</x>
<y>420</y>
<width>111</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Framerate</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</widget> </widget>
</widget> </widget>