No Description

mainwindow.cpp 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /// \file
  2. #include "mainwindow.h"
  3. #include "ui_mainwindow.h"
  4. #include <QtDebug>
  5. #include <QLabel>
  6. #include "steganography.h"
  7. StegaPanel::StegaPanel(QWidget *parent) :
  8. QMainWindow(parent),
  9. ui(new Ui::StegaPanel)
  10. {
  11. ui->setupUi(this); //
  12. }
  13. void StegaPanel::hideMessage()
  14. {
  15. string binMsg ; // Will be used to store the message in a binary String format
  16. ui->error_msg_label->clear(); //clear error text
  17. orig_msg = ui->textEdit->toPlainText(); //obtain msg from textEdit
  18. if(old_image.isNull()){
  19. qDebug() << "Load an image first!";
  20. ui->error_msg_label->setText("NO IMAGE LOADED!");
  21. }
  22. else if (orig_msg == NULL){
  23. ui->error_msg_label->setText("No message to hide!");
  24. }
  25. else{
  26. binMsg = messageToBinaryString(orig_msg.toStdString()) ;
  27. if(((old_image.width() * old_image.height()) * 3) < (int)binMsg.length())
  28. {
  29. ui->error_msg_label->setText("IMAGE NOT BIG ENOUGH FOR MESSAGE!");
  30. }
  31. else
  32. {
  33. EmbbedMessage(old_image, new_image, orig_msg.toStdString()) ;
  34. }
  35. ui->error_msg_label->setText("Message hidden in Stego Image with 1 stego bits.");
  36. }
  37. }
  38. void StegaPanel::revealMessage()
  39. {
  40. string msg = ExtractMessage(new_image) ;
  41. if (msg.length() > 0){
  42. ui->textEdit->setText(QString::fromStdString(msg));
  43. ui->error_msg_label->setText("Message extracted!");
  44. }
  45. else{
  46. ui->error_msg_label->setText("Could not extract message!");
  47. }
  48. }
  49. void StegaPanel::on_loadImage_clicked()
  50. {
  51. QString fname = QFileDialog::getOpenFileName(this, tr("Choose an image"), QDir::homePath());
  52. if (!fname.isEmpty()){
  53. QImage image(fname);
  54. if (image.isNull())
  55. QMessageBox::information(this, tr("Choose an image"),tr("Cannot load %1.").arg(fname));
  56. old_image=image;
  57. new_image=image;
  58. repaint();
  59. }
  60. ui->old_image->setPixmap(QPixmap::fromImage(old_image));
  61. ui->new_image->setPixmap(QPixmap::fromImage(new_image));
  62. ui->textEdit->setText("");
  63. ui->error_msg_label->setText("Image loaded!");
  64. }
  65. void StegaPanel::on_hideMessage_clicked()
  66. {
  67. hideMessage();
  68. ui->new_image->setPixmap(QPixmap::fromImage(new_image));
  69. }
  70. void StegaPanel::on_getMessage_clicked()
  71. {
  72. revealMessage();
  73. }
  74. StegaPanel::~StegaPanel()
  75. {
  76. delete ui;
  77. }
  78. void StegaPanel::on_storeImage_clicked()
  79. {
  80. QPixmap out = QPixmap::grabWidget(this,361,10,481,481);
  81. QString fname = QFileDialog::getSaveFileName(this, tr("Save Edited Image"), (""), tr("PNG (*.png)" ));
  82. new_image.save(fname, "PNG");
  83. ui->error_msg_label->setText("Image saved to" + fname + " !");
  84. }