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. //print(imageThatHides);
  12. imageThatHides = chopToHide(imageThatHides);
  13. //print("After applying the chopToHide function to the image imageThatHides:");
  14. //print(imageThatHides);
  15. print("Before applying the shift function to the image imageToHide:");
  16. for(i = 1; i <= 100; i+=20 ){
  17.     var pixel = imageToHide.getPixel(i, i+5);
  18.     print("pixel at (" + pixel.getX() + "," + pixel.getY() + ")-> R= " + pixel.getRed() + " : G= " + pixel.getGreen() + " : B= " + pixel.getBlue() );
  19. }
  20. //Call the shift function on the image you want to hide to prepare it for hiding.
  21. imageToHide = shift(imageToHide);
  22. print("After applying the shift function to the image imageToHide:");
  23. for(i = 1; i <= 100; i+=20 ){
  24.     var pixel = imageToHide.getPixel(i, i+5);
  25.     print("pixel at (" + pixel.getX() + "," + pixel.getY() + ")-> R= " + pixel.getRed() + " : G= " + pixel.getGreen() + " : B= " + pixel.getBlue() );
  26. }
  27.  
  28. function combine(imageToHide, imageThatHides){
  29.    
  30. }
  31. //Prepare the imageToHide by shifting the left most half of the bits to the right and replacing the leftmost half of the bits to 0.
  32. function shift(oldImage){
  33.     var newImage = new SimpleImage(oldImage.getWidth(), oldImage.getHeight());
  34.     for(var oldPixel of oldImage.values()){
  35.         var x = oldPixel.getX();
  36.         var y = oldPixel.getY();
  37.         var newPixel = newImage.getPixel(x, y);
  38.         newPixel.setRed( Math.floor(oldPixel.getRed()/16) );
  39.         newPixel.setGreen( Math.floor(oldPixel.getGreen()/16) );
  40.         newPixel.setBlue( Math.floor(oldPixel.getBlue()/16) );
  41.     }
  42.     return newImage;
  43. }
  44. //Type in the shift function from the lesson. How well did you understand it? Can you write it without looking at the code from the lesson?
  45.  
  46. function whichOneIsSmaller(image1, image2){
  47.     var smallerInHeight;
  48.     var smallerInWidth;
  49.     if(image1.getWidth() <= image2.getWidth()){
  50.         smallerInWidth = image1;
  51.     }else{
  52.         smallerInWidth = image2;
  53.     }
  54.     if(image1.getHeight() <= image2.getHeight()){
  55.         smallerInHeight = image1;
  56.     }else{
  57.         smallerInHeight = image2;
  58.     }
  59.     if(smallerInHeight === smallerInWidth){
  60.         return smallerInWidth;//Both pics have the same height and width
  61.     }else{
  62.         //Decide on the basis of the width which one is smaller pic.
  63.         if(smallerInHeight.getWidth() <= smallerInWidth.getWidth()){
  64.             return smallerInHeight;
  65.         }else{
  66.             return smallerInWidth;
  67.         }
  68.     }
  69. }
  70. function crop(image, width, height){
  71.     var newImage = new SimpleImage(width, height);
  72.     for(var pixel of newImage.values()){
  73.         var x = pixel.getX();
  74.         var y = pixel.getY();
  75.         var p = image.getPixel(x,y);
  76.         pixel.setRed(p.getRed());
  77.         pixel.setGreen(p.getGreen());
  78.         pixel.setBlue(p.getBlue());
  79.     }
  80.     return newImage;
  81. }
  82. function chopToHide(image){
  83.     for(var pixel of image.values()){
  84.         pixel.setRed(pixelChange(pixel.getRed()));
  85.         pixel.setGreen(pixelChange(pixel.getGreen()));
  86.         pixel.setBlue(pixelChange(pixel.getBlue()));
  87.     }
  88.     return image;
  89. }
  90. function pixelChange(pixelValue){
  91.     return Math.floor(pixelValue/16) * 16;
  92. }
');