Snippets
Created by
Elvis Morales
last modified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | function shift( im ){
var nim = new SimpleImage( im.getWidth(), im.getHeight() );
for ( var px of im.values() ) {
var x = px.getX();
var y = px.getY();
var npx = nim.getPixel( x, y );
npx.setRed( Math.floor( px.getRed()/16 ) );
npx.setGreen( Math.floor( px.getGreen()/16 ) );
npx.setBlue( Math.floor( px.getBlue()/16 ) );
}
return nim;
}
function pixchange( pixval ) {
var x = Math.floor( pixval/16 ) * 16;
return x;
}
function chop2Hide( image ) {
for ( var px of image.values() ) {
px.setRed( pixchange( px.getRed() ) );
px.setGreen( pixchange( px.getGreen() ) );
px.setBlue( pixchange( px.getBlue() ) );
}
return image;
}
function crop( image, width, height ) {
var croppedImage = new SimpleImage( width, height );
for ( var px of image.values() ) {
var x = px.getX();
var y = px.getY();
if ( x < width && y < height ) {
var npx = croppedImage.getPixel( x, y );
npx.setRed( px.getRed() );
npx.setGreen( px.getGreen() );
npx.setBlue( px.getBlue() );
}
}
return croppedImage;
}
function combine( a, b ) {
var combinedImage = new SimpleImage( a.getWidth(), a.getHeight() );
for ( var px of a.values() ) {
var x = px.getX();
var y = px.getY();
var bImgPx = b.getPixel( x, y );
var newImgPx = combinedImage.getPixel( x, y );
newImgPx.setRed( newpv( px.getRed(), bImgPx.getRed() ) );
newImgPx.setGreen( newpv( px.getGreen(), bImgPx.getGreen() ) );
newImgPx.setBlue( newpv( px.getBlue(), bImgPx.getBlue() ) );
}
return combinedImage;
}
function newpv( p, q ) {
var result = p+q;
if ( result > 255 ) {
print( "Error on newpv() function, the sum of P and Q is greater than 255" );
} else {
return result;
}
}
// Program - Put it all together.
var start = new SimpleImage( "astrachan.jpg" );
var hide = new SimpleImage( "duvall.jpg" );
print( start );
print( hide );
print( "Width and height of Astrachan picture" );
print( start.getWidth(), start.getHeight() );
print( "Width and height of Duvall picture" );
print( hide.getWidth(), hide.getHeight() );
var cropWidth = 200;
var cropHeight = 300;
var start = crop( start, cropWidth, cropHeight );
var hide = crop( hide, cropWidth, cropHeight );
print( "Cropped two pictures" );
print( start );
print( hide );
print( "Width and height of Astrachan cropped picture" );
print( start.getWidth(), start.getHeight() );
print( "Width and height of Duvall cropped picture" );
print( hide.getWidth(), hide.getHeight() );
// Hide picture in image - in lower half of each pixel.
print( "red at (42,42)" );
var sPixel = start.getPixel( 42,42 );
print( sPixel.getRed() );
start = chop2Hide( start );
print( "Red at (42,42) after chop2Hide" );
var sPixel = start.getPixel( 42,42 );
print( sPixel.getRed() );
print( "Red at (42,42) before shift" );
var hPixel = hide.getPixel( 42, 42 );
print( hPixel.getRed() );
hide = shift( hide );
print( "Red at (42,42) after shift" );
var hPixel = hide.getPixel(42,42);
print( hPixel.getRed() );
var stego = combine( hide, start );
print( "Here is the image with the hidden picture" );
print( stego );
print( "red at (42,42) after combine" );
var hPixel = stego.getPixel( 42,42 );
print( hPixel.getRed() );
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.