Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var imageThatHides = new SimpleImage("astrachan.jpg");//240 x 360
- var imageToHide = new SimpleImage("duvall.jpg");//200 x 300
- //print(imageThatHides);
- //print(imageToHide);
- var smallerPicture = whichOneIsSmaller(imageThatHides, imageToHide);
- var desiredWidth = smallerPicture.getWidth();
- var desiredHeight = smallerPicture.getHeight();
- imageThatHides = crop(imageThatHides, desiredWidth, desiredHeight);
- imageToHide = crop(imageToHide, desiredWidth, desiredHeight);
- //print("Before applying the chopToHide function to the image imageThatHides:");
- //print(imageThatHides);
- imageThatHides = chopToHide(imageThatHides);
- //print("After applying the chopToHide function to the image imageThatHides:");
- //print(imageThatHides);
- print("Before applying the shift function to the image imageToHide:");
- for(i = 1; i <= 100; i+=20 ){
- var pixel = imageToHide.getPixel(i, i+5);
- print("pixel at (" + pixel.getX() + "," + pixel.getY() + ")-> R= " + pixel.getRed() + " : G= " + pixel.getGreen() + " : B= " + pixel.getBlue() );
- }
- //Call the shift function on the image you want to hide to prepare it for hiding.
- imageToHide = shift(imageToHide);
- print("After applying the shift function to the image imageToHide:");
- for(i = 1; i <= 100; i+=20 ){
- var pixel = imageToHide.getPixel(i, i+5);
- print("pixel at (" + pixel.getX() + "," + pixel.getY() + ")-> R= " + pixel.getRed() + " : G= " + pixel.getGreen() + " : B= " + pixel.getBlue() );
- }
- function combine(imageToHide, imageThatHides){
- }
- //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.
- function shift(oldImage){
- var newImage = new SimpleImage(oldImage.getWidth(), oldImage.getHeight());
- for(var oldPixel of oldImage.values()){
- var x = oldPixel.getX();
- var y = oldPixel.getY();
- var newPixel = newImage.getPixel(x, y);
- newPixel.setRed( Math.floor(oldPixel.getRed()/16) );
- newPixel.setGreen( Math.floor(oldPixel.getGreen()/16) );
- newPixel.setBlue( Math.floor(oldPixel.getBlue()/16) );
- }
- return newImage;
- }
- //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?
- function whichOneIsSmaller(image1, image2){
- var smallerInHeight;
- var smallerInWidth;
- if(image1.getWidth() <= image2.getWidth()){
- smallerInWidth = image1;
- }else{
- smallerInWidth = image2;
- }
- if(image1.getHeight() <= image2.getHeight()){
- smallerInHeight = image1;
- }else{
- smallerInHeight = image2;
- }
- if(smallerInHeight === smallerInWidth){
- return smallerInWidth;//Both pics have the same height and width
- }else{
- //Decide on the basis of the width which one is smaller pic.
- if(smallerInHeight.getWidth() <= smallerInWidth.getWidth()){
- return smallerInHeight;
- }else{
- return smallerInWidth;
- }
- }
- }
- function crop(image, width, height){
- var newImage = new SimpleImage(width, height);
- for(var pixel of newImage.values()){
- var x = pixel.getX();
- var y = pixel.getY();
- var p = image.getPixel(x,y);
- pixel.setRed(p.getRed());
- pixel.setGreen(p.getGreen());
- pixel.setBlue(p.getBlue());
- }
- return newImage;
- }
- function chopToHide(image){
- for(var pixel of image.values()){
- pixel.setRed(pixelChange(pixel.getRed()));
- pixel.setGreen(pixelChange(pixel.getGreen()));
- pixel.setBlue(pixelChange(pixel.getBlue()));
- }
- return image;
- }
- function pixelChange(pixelValue){
- return Math.floor(pixelValue/16) * 16;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement