Keine Beschreibung

panel.cpp 3.0KB

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