Don't know what to really put here.. You'd need to know some theory first..
Generally I'm trying to hide (watermark) information (text) into an image. I do that with ANDing the blue pixel with 254->"11111110". So the LSB of the pixel is 0 and then I add the bits of the text the user puts (after making the text to a binary table).
Variables aside, which you don't know what they represent without the UI, do you see any problems with the code below? Qt turns out no errors.. But when I run it, it crashes (windows 7).
So there goes:
Code:void MainWindow::on_InsertWatermarkButton_clicked() { if (imageloaded==false) { ui->ImagePreviewLabel->setText("No image is loaded, you idiot !"); } else { QString watermarkdata = ui->WatermarkTextEdit->toPlainText(); int length = watermarkdata.size(); while (length%8!=0) // for the Blowfish encryption { length++; } image->convertToFormat(QImage::Format_RGB888); // convert to 24-bit image, 8 bits per pixel numx = image->width(); //width in pixels probably numy = image->height(); //height if (3*7*(length*8)>3*numx*numy) //if more, it doesn't fit according to the key { QMessageBox msgBox; msgBox.setText("Watermark text is\ntoo big for this image."); msgBox.exec(); } else { QString pass = ui->BlowfishLineEdit->text(); int passlength = pass.size(); char *key = new char[passlength]; //table holding the bytes of password key = pass.toAscii().data(); char *bytes = new char[length]; //table holding the bytes of the watermark message bytes = watermarkdata.toAscii().data(); CBlowFish blow( reinterpret_cast<unsigned char*>(key), passlength); blow.Encrypt(reinterpret_cast<unsigned char*>(bytes),length); // Blowfish encryption int *binary=new int[length*8]; //this will hold the binary table QString *bin = new QString[256]; //look up table bin[0]="00000000"; bin[1]="00000001"; bin[2]="00000010"; ........... ........... ........... bin[253]="11111101"; bin[254]="11111110"; bin[255]="11111111"; QString temp; //temporary string int a=0; //counter for (int i=0;i<length;i++) { temp=bin[bytes[i]]; binary[a] = temp[0].digitValue(); //MSB binary[a+1]= temp[1].digitValue(); // . binary[a+2]= temp[2].digitValue(); // . binary[a+3]= temp[3].digitValue(); // . binary[a+4]= temp[4].digitValue(); // . binary[a+5]= temp[5].digitValue(); // . binary[a+6]= temp[6].digitValue(); // . binary[a+7]= temp[7].digitValue(); //LSB a=a+8; } for (int h=0;h<a;h++) //converting from ascii to binary binary[h]-=48; int x,y; int g=3; int cnt=0; for (int s=0;s<length*8;s++) { x=3*7*g; //random number generator if (x>numx) y=(int) (x/numx); QRgb value = image->pixel(x,y); int red = qRed(value); int green = qGreen(value); int blue = qGreen (value); blue = blue & 254; //ANDing pixels with 254->"11111110" blue+=binary[cnt]; //adding information value = qRgb( red, green, blue); image->setPixel(x, y, value); cnt++; g++; } delete [] key; delete [] bin; delete [] bytes; delete [] binary; QString temp2= "Watermarked "; QString savefilename = temp2 + filename; image->save(savefilename,"BMP",100); ui->ImagePreviewLabel->setPixmap(QPixmap::fromImage(*image)); ui->WatermarkTextEdit->setPlainText("Watermarked:\nImage is saved in a Bitmap format"); delete image; } } }

So there goes:
Reply With Quote


