document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. var imageThatHides = new SimpleImage("astrachan.jpg");//240 x 360
  2. var imageToHide = new SimpleImage("duvall.jpg");//200 x 300
  3. //print(imageThatHides);
  4. //print(imageToHide);
  5. var smallerPicture = whichOneIsSmaller(imageThatHides, imageToHide);
  6. var desiredWidth = smallerPicture.getWidth();
  7. var desiredHeight = smallerPicture.getHeight();
  8. imageThatHides = crop(imageThatHides, desiredWidth, desiredHeight);
  9. imageToHide = crop(imageToHide, desiredWidth, desiredHeight);
  10. print("Before applying the chopToHide function to the image imageThatHides:");
  11. for(i = 1; i <= 100; i+=20 ){
  12.     var pixel = imageThatHides.getPixel(i, i+5);
  13.     print("pixel at (" + pixel.getX() + "," + pixel.getY() + ")-> R= " + pixel.getRed() + " : G= " + pixel.getGreen() + " : B= " + pixel.getBlue() );
  14. }
  15. imageThatHides = chopToHide(imageThatHides);
  16. print("After applying the chopToHide function to the image imageThatHides:");
  17. for(i = 1; i <= 100; i+=20 ){
  18.     var pixel = imageThatHides.getPixel(i, i+5);
  19.     print("pixel at (" + pixel.getX() + "," + pixel.getY() + ")-> R= " + pixel.getRed() + " : G= " + pixel.getGreen() + " : B= " + pixel.getBlue() );
  20. }
  21.  
  22. function whichOneIsSmaller(image1, image2){
  23.     var smallerInHeight;
  24.     var smallerInWidth;
  25.     if(image1.getWidth() <= image2.getWidth()){
  26.         smallerInWidth = image1;
  27.     }else{
  28.         smallerInWidth = image2;
  29.     }
  30.     if(image1.getHeight() <= image2.getHeight()){
  31.         smallerInHeight = image1;
  32.     }else{
  33.         smallerInHeight = image2;
  34.     }
  35.     if(smallerInHeight === smallerInWidth){
  36.         return smallerInWidth;//Both pics have the same height and width
  37.     }else{
  38.         //Decide on the basis of the width which one is smaller pic.
  39.         if(smallerInHeight.getWidth() <= smallerInWidth.getWidth()){
  40.             return smallerInHeight;
  41.         }else{
  42.             return smallerInWidth;
  43.         }
  44.     }
  45. }
  46. function crop(image, width, height){
  47.     var newImage = new SimpleImage(width, height);
  48.     for(var pixel of newImage.values()){
  49.         var x = pixel.getX();
  50.         var y = pixel.getY();
  51.         var p = image.getPixel(x,y);
  52.         pixel.setRed(p.getRed());
  53.         pixel.setGreen(p.getGreen());
  54.         pixel.setBlue(p.getBlue());
  55.     }
  56.     return newImage;
  57. }
  58. function chopToHide(image){
  59.     for(var pixel of image.values()){
  60.         pixel.setRed(pixelChange(pixel.getRed()));
  61.         pixel.setGreen(pixelChange(pixel.getGreen()));
  62.         pixel.setBlue(pixelChange(pixel.getBlue()));
  63.     }
  64.     return image;
  65. }
  66. function pixelChange(pixelValue){
  67. /*
  68. Pixels use 8 bits for each RGB value. We want to use half of these bits i.e., 4 bits to hide data (another picture in this example) Since a bit can have a zero or one value therefore 2 raised to the power 4 is equal to 16 and we will divide the value that is passed to this function by 16 to get the two bits in the higher significant position and then in order to fill the last two positions with zeros we multiply it with 16.
  69. */
  70.     return Math.floor(pixelValue/16) * 16;
  71. }
');