1 Commits

Author SHA1 Message Date
Alexis Delhaie
3fbcadf59b Changing default config + Adding Antialiasing + More settings 2020-12-05 18:12:21 +01:00
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
CONFIG += c++17
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
@@ -16,6 +16,7 @@ QMAKE_CXXFLAGS_RELEASE -= -O1
QMAKE_CXXFLAGS_RELEASE *= -O2
RC_ICONS = icon.ico
VERSION = 1.1.0.0
# You can also make your code fail to compile if it uses deprecated APIs.
# 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->setEditText(QCameraInfo::defaultCamera().description());
canvasFont = QFont("Consolas", 6);
canvasFont.setStyleStrategy(QFont::PreferAntialias);
revert();
init(QCameraInfo::defaultCamera());
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->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->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->disableProcess, &QCheckBox::clicked, this, &MainWindow::config_changed);
QObject::connect(ui->applyButton, &QPushButton::clicked, this, &MainWindow::apply);
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) {
img = img.scaled(ascii_width, ascii_height);
ui->screen->setPixmap(img);
@@ -87,17 +92,17 @@ void MainWindow::convert(QImage in) {
}
res += '\n';
}
QBitmap bitmap(1920,1080);
bitmap.fill(Qt::white);
QPainter painter(&bitmap);
QFont serifFont("Consolas", 12);
painter.setFont(serifFont);
QImage image(bitmap_width, bitmap_height, QImage::Format_Grayscale8);
image.fill(Qt::white);
QPainter painter(&image);
painter.setRenderHints(QPainter::TextAntialiasing);
painter.setFont(canvasFont);
painter.setPen(Qt::black);
const QRect rectangle = QRect(0, 0, 1920, 1080);
const QRect rectangle = QRect(0, 0, bitmap_width, bitmap_height);
QRect boundingRect;
painter.drawText(rectangle, 0, res, &boundingRect);
painter.save();
QPixmap pix(bitmap);
QPixmap pix = QPixmap::fromImage(image);
emit image_processed(pix);
}
@@ -140,9 +145,12 @@ void MainWindow::apply() {
source_height = ui->sourceHeight->value();
ascii_width = ui->asciiWidth->value();
ascii_height = ui->asciiHeight->value();
bitmap_width = ui->bitmapWidth->value();
bitmap_height = ui->bitmapHeight->value();
chars = ui->charEdit->text();
disable_process = ui->disableProcess->checkState();
refresh_timer = ui->refreshTimer->value();
canvasFont = canvasFont_tmp;
}
void MainWindow::revert() {
@@ -150,13 +158,32 @@ void MainWindow::revert() {
ui->sourceHeight->setValue(source_height);
ui->asciiWidth->setValue(ascii_width);
ui->asciiHeight->setValue(ascii_height);
ui->bitmapWidth->setValue(bitmap_width);
ui->bitmapHeight->setValue(bitmap_height);
ui->charEdit->setText(chars);
ui->refreshTimer->setValue(refresh_timer);
ui->applyButton->setEnabled(false);
ui->revertButton->setEnabled(false);
canvasFont_tmp = canvasFont;
update_font_label();
}
void MainWindow::config_changed() {
ui->applyButton->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 <QStaticText>
#include <QCameraInfo>
#include <QFontDialog>
#include <QString>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
@@ -32,6 +34,8 @@ public slots:
void apply();
void revert();
void config_changed();
void change_font();
void update_font_label();
signals:
void image_processed(QPixmap img);
@@ -47,13 +51,20 @@ private:
QCameraInfo selected_camera;
bool thread_running = false;
QString chars = " .~#☻░▒";
int source_width = 480;
int source_height = 360;
QString chars = "@#P+;-. ";
int source_width = 320;
int source_height = 240;
int ascii_width = 771;
int ascii_height = 531;
int bitmap_width = 771;
int bitmap_height = 531;
int refresh_timer = 25;
bool disable_process = false;
QFont canvasFont;
QFont canvasFont_tmp;
int fps = 0;

View File

@@ -12,7 +12,7 @@
</property>
<property name="minimumSize">
<size>
<width>800</width>
<width>1007</width>
<height>561</height>
</size>
</property>
@@ -42,335 +42,456 @@
<set>Qt::AlignCenter</set>
</property>
</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 class="QComboBox" name="devicesBox">
<property name="geometry">
<rect>
<x>820</x>
<y>30</y>
<width>181</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>820</x>
<y>10</y>
<width>47</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>Device</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>820</x>
<y>70</y>
<width>111</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Source scale</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>879</x>
<y>94</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="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>880</x>
<y>120</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="QSpinBox" name="sourceWidth">
<property name="geometry">
<rect>
<x>931</x>
<y>90</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>
<height>16</height>
</rect>
</property>
<property name="text">
<string>ASCII Video output</string>
</property>
</widget>
<widget class="QSpinBox" name="asciiHeight">
<property name="geometry">
<rect>
<x>932</x>
<y>232</y>
<width>61</width>
<height>22</height>
</rect>
</property>
<property name="maximum">
<number>2160</number>
</property>
</widget>
<widget class="QSpinBox" name="asciiWidth">
<property name="geometry">
<rect>
<x>932</x>
<y>206</y>
<width>61</width>
<height>22</height>
</rect>
</property>
<property name="maximum">
<number>3840</number>
</property>
</widget>
<widget class="QLabel" name="label_7">
<property name="geometry">
<rect>
<x>881</x>
<y>236</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="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">
<property name="geometry">
<rect>
<x>830</x>
<y>280</y>
<width>111</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Characters</string>
</property>
</widget>
<widget class="QPushButton" name="applyButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>915</x>
<y>520</y>
<width>80</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
<widget class="QPushButton" name="revertButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>827</x>
<y>520</y>
<width>80</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Revert</string>
</property>
</widget>
<widget class="QPushButton" name="startAndStopButton">
<property name="geometry">
<rect>
<x>830</x>
<y>488</y>
<width>161</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Start</string>
</property>
</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 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">
<rect>
<x>126</x>
<y>110</y>
<width>61</width>
<height>22</height>
</rect>
</property>
<property name="maximum">
<number>2160</number>
</property>
</widget>
<widget class="QLabel" name="label_12">
<property name="geometry">
<rect>
<x>75</x>
<y>284</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="QLabel" name="label_11">
<property name="geometry">
<rect>
<x>75</x>
<y>414</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 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>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>74</x>
<y>88</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="QLabel" name="fontLabel">
<property name="geometry">
<rect>
<x>25</x>
<y>383</y>
<width>121</width>
<height>16</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>121</width>
<height>16</height>
</size>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QLabel" name="label_13">
<property name="geometry">
<rect>
<x>15</x>
<y>254</y>
<width>111</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Bitmap (Process)</string>
</property>
</widget>
<widget class="QSpinBox" name="refreshTimer">
<property name="geometry">
<rect>
<x>125</x>
<y>144</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="Line" name="line_2">
<property name="geometry">
<rect>
<x>15</x>
<y>52</y>
<width>181</width>
<height>16</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QLabel" name="label_7">
<property name="geometry">
<rect>
<x>76</x>
<y>230</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="QLabel" name="label_9">
<property name="geometry">
<rect>
<x>25</x>
<y>334</y>
<width>111</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Characters</string>
</property>
</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">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>111</x>
<y>502</y>
<width>80</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
<widget class="QPushButton" name="revertButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>23</x>
<y>502</y>
<width>80</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Revert</string>
</property>
</widget>
<widget class="QPushButton" name="fontButton">
<property name="geometry">
<rect>
<x>151</x>
<y>379</y>
<width>31</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</widget>
</widget>
</widget>