From 1d6d828dfd0d47fa7536ac0a9628bbdd123d3ff1 Mon Sep 17 00:00:00 2001 From: Aditya Ghidora Date: Mon, 9 Oct 2023 12:03:29 +0530 Subject: [PATCH 1/3] added randomize pixels function to pixelate tool --- src/tools/pixelate/pixelatetool.cpp | 15 ++++++++++++++- src/tools/pixelate/pixelatetool.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/tools/pixelate/pixelatetool.cpp b/src/tools/pixelate/pixelatetool.cpp index 18f15bdd95..afbf4c2afe 100644 --- a/src/tools/pixelate/pixelatetool.cpp +++ b/src/tools/pixelate/pixelatetool.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include PixelateTool::PixelateTool(QObject* parent) : AbstractTwoPointTool(parent) @@ -78,10 +80,21 @@ void PixelateTool::process(QPainter& painter, const QPixmap& pixmap) QPixmap t = pixmap.copy(selectionScaled); t = t.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); t = t.scaled(selection.width(), selection.height()); - painter.drawImage(selection, t.toImage()); + QImage image = t.toImage(); + image = randomizePixels(image); + painter.drawImage(selection, image); } } +QImage PixelateTool::randomizePixels(const QImage& image) +{ + QVector pixels(image.height() * image.width()); + std::memcpy(pixels.data(), image.bits(), image.byteCount()); + std::random_shuffle(pixels.begin(), pixels.end()); + QImage shuffledImage(image.width(), image.height(), image.format()); + std::memcpy(shuffledImage.bits(), pixels.data(), image.byteCount()); + return shuffledImage; +} void PixelateTool::drawSearchArea(QPainter& painter, const QPixmap& pixmap) { Q_UNUSED(pixmap) diff --git a/src/tools/pixelate/pixelatetool.h b/src/tools/pixelate/pixelatetool.h index f4fd3b6df1..7957537d26 100644 --- a/src/tools/pixelate/pixelatetool.h +++ b/src/tools/pixelate/pixelatetool.h @@ -24,6 +24,7 @@ class PixelateTool : public AbstractTwoPointTool protected: CaptureTool::Type type() const override; + QImage randomizePixels(const QImage& image); public slots: void pressed(CaptureContext& context) override; From d3bd236c340086a4914ce1c9038b3751d4a04790 Mon Sep 17 00:00:00 2001 From: Aditya Ghidora Date: Tue, 10 Oct 2023 11:00:12 +0530 Subject: [PATCH 2/3] adding setting for randomizing pixelation --- src/config/generalconf.cpp | 17 +++++++++++++++++ src/config/generalconf.h | 3 +++ src/tools/pixelate/pixelatetool.cpp | 10 +++++++--- src/utils/confighandler.cpp | 1 + src/utils/confighandler.h | 1 + 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/config/generalconf.cpp b/src/config/generalconf.cpp index 8c8024def7..0ad250bc2d 100644 --- a/src/config/generalconf.cpp +++ b/src/config/generalconf.cpp @@ -81,6 +81,7 @@ void GeneralConf::_updateComponents(bool allowEmptySavePath) m_saveAfterCopy->setChecked(config.saveAfterCopy()); m_copyPathAfterSave->setChecked(config.copyPathAfterSave()); m_antialiasingPinZoom->setChecked(config.antialiasingPinZoom()); + m_randomizePixelation->setChecked(config.randomizePixelation()); m_useJpgForClipboard->setChecked(config.useJpgForClipboard()); m_copyOnDoubleClick->setChecked(config.copyOnDoubleClick()); m_uploadWithoutConfirmation->setChecked(config.uploadWithoutConfirmation()); @@ -150,6 +151,11 @@ void GeneralConf::allowMultipleGuiInstancesChanged(bool checked) ConfigHandler().setAllowMultipleGuiInstances(checked); } +void GeneralConf::setRandomizePixelation(bool checked) +{ + ConfigHandler().setRandomizePixelation(checked); +} + void GeneralConf::autoCloseIdleDaemonChanged(bool checked) { ConfigHandler().setAutoCloseIdleDaemon(checked); @@ -264,6 +270,17 @@ void GeneralConf::initSaveLastRegion() this, &GeneralConf::saveLastRegion); } +void GeneralConf::initRandomizePixelation() +{ + m_randomizePixelation = new QCheckBox(tr("Randomize pixelation"), this); + m_randomizePixelation->setToolTip( + tr("Randomly shuffle pixels to make it harder to recover the contents")); + m_scrollAreaLayout->addWidget(m_randomizePixelation); + connect(m_randomizePixelation, + &QCheckBox::clicked, + this, + &GeneralConf::setRandomizePixelation); +} void GeneralConf::initShowSidePanelButton() { diff --git a/src/config/generalconf.h b/src/config/generalconf.h index e1f4979163..3a89a20cbc 100644 --- a/src/config/generalconf.h +++ b/src/config/generalconf.h @@ -43,6 +43,7 @@ private slots: void allowMultipleGuiInstancesChanged(bool checked); void autoCloseIdleDaemonChanged(bool checked); void autostartChanged(bool checked); + void setRandomizePixelation(bool checked); void historyConfirmationToDelete(bool checked); void uploadHistoryMaxChanged(int max); void undoLimit(int limit); @@ -81,6 +82,7 @@ private slots: void initShowHelp(); void initShowMagnifier(); void initShowSidePanelButton(); + void initRandomizePixelation(); void initShowStartupLaunchMessage(); void initShowTrayIcon(); void initSquareMagnifier(); @@ -113,6 +115,7 @@ private slots: QCheckBox* m_copyURLAfterUpload; QCheckBox* m_copyPathAfterSave; QCheckBox* m_antialiasingPinZoom; + QCheckBox* m_randomizePixelation; QCheckBox* m_saveLastRegion; QCheckBox* m_uploadWithoutConfirmation; QPushButton* m_importButton; diff --git a/src/tools/pixelate/pixelatetool.cpp b/src/tools/pixelate/pixelatetool.cpp index afbf4c2afe..ece19608b0 100644 --- a/src/tools/pixelate/pixelatetool.cpp +++ b/src/tools/pixelate/pixelatetool.cpp @@ -9,7 +9,9 @@ #include #include #include +#include // std::chrono::system_clock #include +#include // std::default_random_engine PixelateTool::PixelateTool(QObject* parent) : AbstractTwoPointTool(parent) @@ -89,10 +91,12 @@ void PixelateTool::process(QPainter& painter, const QPixmap& pixmap) QImage PixelateTool::randomizePixels(const QImage& image) { QVector pixels(image.height() * image.width()); - std::memcpy(pixels.data(), image.bits(), image.byteCount()); - std::random_shuffle(pixels.begin(), pixels.end()); + std::memcpy(pixels.data(), image.bits(), image.sizeInBytes()); + unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); + std::shuffle( + pixels.begin(), pixels.end(), std::default_random_engine(seed)); QImage shuffledImage(image.width(), image.height(), image.format()); - std::memcpy(shuffledImage.bits(), pixels.data(), image.byteCount()); + std::memcpy(shuffledImage.bits(), pixels.data(), image.sizeInBytes()); return shuffledImage; } void PixelateTool::drawSearchArea(QPainter& painter, const QPixmap& pixmap) diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index cb9ae5d7e0..f5dca82b1f 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -98,6 +98,7 @@ static QMap> OPTION("saveAfterCopy" ,Bool ( false )), OPTION("savePath" ,ExistingDir ( )), OPTION("savePathFixed" ,Bool ( false )), + OPTION("randomizePixelation" ,Bool ( false )), OPTION("saveAsFileExtension" ,SaveFileExtension ( )), OPTION("saveLastRegion" ,Bool (false )), OPTION("uploadHistoryMax" ,LowerBoundedInt (0, 25 )), diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index aedd732915..769e7a2662 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -74,6 +74,7 @@ class ConfigHandler : public QObject CONFIG_GETTER_SETTER(userColors, setUserColors, QVector); CONFIG_GETTER_SETTER(savePath, setSavePath, QString) CONFIG_GETTER_SETTER(savePathFixed, setSavePathFixed, bool) + CONFIG_GETTER_SETTER(randomizePixelation, setRandomizePixelation, bool) CONFIG_GETTER_SETTER(uiColor, setUiColor, QColor) CONFIG_GETTER_SETTER(contrastUiColor, setContrastUiColor, QColor) CONFIG_GETTER_SETTER(drawColor, setDrawColor, QColor) From 641ffe055ed5707e10a7e505ed7234b75993efa6 Mon Sep 17 00:00:00 2001 From: Aditya Ghidora Date: Thu, 16 May 2024 14:53:21 +0530 Subject: [PATCH 3/3] added initRandomizePixels to constructor --- src/config/generalconf.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config/generalconf.cpp b/src/config/generalconf.cpp index 0ad250bc2d..a4a07242aa 100644 --- a/src/config/generalconf.cpp +++ b/src/config/generalconf.cpp @@ -52,6 +52,7 @@ GeneralConf::GeneralConf(QWidget* parent) initCopyPathAfterSave(); initCopyAndCloseAfterUpload(); initUploadWithoutConfirmation(); + initRandomizePixelation(); initHistoryConfirmationToDelete(); initAntialiasingPinZoom(); initUploadHistoryMax();