diff --git a/Cam2Ascii.pro b/Cam2Ascii.pro index 16f137c..c78c58e 100644 --- a/Cam2Ascii.pro +++ b/Cam2Ascii.pro @@ -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. diff --git a/mainwindow.cpp b/mainwindow.cpp index 3019fab..5cb0d03 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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(&QSpinBox::valueChanged), this, &MainWindow::config_changed); QObject::connect(ui->asciiWidth, static_cast(&QSpinBox::valueChanged), this, &MainWindow::config_changed); QObject::connect(ui->asciiHeight, static_cast(&QSpinBox::valueChanged), this, &MainWindow::config_changed); + QObject::connect(ui->bitmapWidth, static_cast(&QSpinBox::valueChanged), this, &MainWindow::config_changed); + QObject::connect(ui->bitmapHeight, static_cast(&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()); +} diff --git a/mainwindow.h b/mainwindow.h index 33d0349..768df23 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -14,6 +14,8 @@ #include #include #include +#include +#include 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; diff --git a/mainwindow.ui b/mainwindow.ui index af8a5af..7e23fac 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -12,7 +12,7 @@ - 800 + 1007 561 @@ -42,335 +42,456 @@ Qt::AlignCenter - - - - 800 - 10 - 20 - 541 - - - - Qt::Vertical - - - - - - 820 - 30 - 181 - 22 - - - - - - - 820 - 10 - 47 - 14 - - - - Device - - - - - - 820 - 70 - 111 - 16 - - - - Source scale - - - - - - 879 - 94 - 47 - 14 - - - - Width - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 880 - 120 - 47 - 14 - - - - Height - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 931 - 90 - 61 - 22 - - - - 3840 - - - - - - 931 - 116 - 61 - 22 - - - - 2160 - - - - - - 820 - 180 - 111 - 16 - - - - ASCII Video output - - - - - - 932 - 232 - 61 - 22 - - - - 2160 - - - - - - 932 - 206 - 61 - 22 - - - - 3840 - - - - - - 881 - 236 - 47 - 14 - - - - Height - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 880 - 210 - 47 - 14 - - - - Width - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 827 - 300 - 161 - 21 - - - - - - - 830 - 280 - 111 - 16 - - - - Characters - - - - - false - - - - 915 - 520 - 80 - 22 - - - - Apply - - - - - false - - - - 827 - 520 - 80 - 22 - - - - Revert - - - - - - 830 - 488 - 161 - 22 - - - - Start - - - - - - 820 - 58 - 181 - 16 - - - - Qt::Horizontal - - - - - - 830 - 330 - 161 - 20 - - - - Disable process - - - - - - 815 - 151 - 111 - 20 - - - - Refresh timer (ms) - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 930 - 150 - 61 - 22 - - - - 25 - - - 5000 - - - - - - 923 - 440 - 71 - 31 - - - - - - - 880 - 420 - 111 - 16 - - - - Framerate - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + + + + + 210 + 561 + + + + + 210 + 561 + + + + QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable + + + Settings + + + 2 + + + + + + 126 + 110 + 61 + 22 + + + + 2160 + + + + + + 75 + 284 + 47 + 14 + + + + Width + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 75 + 414 + 111 + 16 + + + + Framerate + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 127 + 306 + 61 + 22 + + + + 2160 + + + + + + 76 + 310 + 47 + 14 + + + + Height + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 74 + 88 + 47 + 14 + + + + Width + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 25 + 383 + 121 + 16 + + + + + 121 + 16 + + + + TextLabel + + + + + + 15 + 254 + 111 + 16 + + + + Bitmap (Process) + + + + + + 125 + 144 + 61 + 22 + + + + 25 + + + 5000 + + + + + + 15 + 52 + 181 + 16 + + + + Qt::Horizontal + + + + + + 76 + 230 + 47 + 14 + + + + Height + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 25 + 334 + 111 + 16 + + + + Characters + + + + + + 127 + 200 + 61 + 22 + + + + 3840 + + + + + + 15 + 64 + 111 + 16 + + + + Source scale (IN) + + + + + + 15 + 24 + 181 + 22 + + + + + + + 127 + 280 + 61 + 22 + + + + 3840 + + + + + + 10 + 145 + 111 + 20 + + + + Refresh timer (ms) + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 75 + 114 + 47 + 14 + + + + Height + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 102 + 253 + 111 + 20 + + + + Disable process + + + + + + 22 + 354 + 161 + 21 + + + + + Consolas + 9 + + + + + + + 118 + 434 + 71 + 31 + + + + + + + 15 + 174 + 171 + 16 + + + + ASCII Video output (OUT) + + + + + + 75 + 204 + 47 + 14 + + + + Width + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 126 + 84 + 61 + 22 + + + + 3840 + + + + + + 127 + 226 + 61 + 22 + + + + 2160 + + + + + + 15 + 4 + 47 + 14 + + + + Device + + + + + + 26 + 470 + 161 + 22 + + + + Start + + + + + false + + + + 111 + 502 + 80 + 22 + + + + Apply + + + + + false + + + + 23 + 502 + 80 + 22 + + + + Revert + + + + + + 151 + 379 + 31 + 22 + + + + ... + +