It looks like you're new here. If you want to get involved, click one of these buttons!
package control;
import gui.MainFrame;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import javax.swing.SwingUtilities;
public class ImageSteno {
public static final int ALPHA = 0;
public static final int RED = 1;
public static final int GREEN = 2;
public static final int BLUE = 3;
private BufferedImage mask;
private BufferedImage toHide;
private BufferedImage toExtract;
private Quality quality = Quality.GOOD;
public static void main(String[] args) throws IOException {
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
new MainFrame();
}
});
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
public void setQuality(Quality quality) {
this.quality = quality;
}
public BufferedImage extractHiddenImage() throws NoImageException {
if (toExtract == null) {
throw new NoImageException();
}
return extractHiddenImage(toExtract);
}
public BufferedImage extractHiddenImage(BufferedImage img) {
BufferedImage imgCopy = copyImage(img);
for (int x = 0; x < imgCopy.getWidth(); x++) {
for (int y = 0; y < imgCopy.getHeight(); y++) {
int rgb = imgCopy.getRGB(x, y);
rgb = extractRGB(rgb);
imgCopy.setRGB(x, y, rgb);
}
}
return imgCopy;
}
public static BufferedImage copyImage(BufferedImage image) {
BufferedImage destImage = new BufferedImage(image.getWidth(),
image.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g = destImage.createGraphics();
g.drawImage(image, null, 0, 0);
g.dispose();
return destImage;
}
public BufferedImage hideImage() throws NoImageException {
if (mask == null || toHide == null) {
throw new NoImageException();
}
BufferedImage maskCopy = getScaledInstance(copyImage(mask),
toHide.getWidth(), toHide.getHeight(),
RenderingHints.VALUE_INTERPOLATION_BICUBIC, false);
for (int x = 0; x < toHide.getWidth(); x++) {
for (int y = 0; y < toHide.getHeight(); y++) {
int destRGB = toHide.getRGB(x, y);
int oldRGB = maskCopy.getRGB(x, y);
int newRGB = computeNewRGB(oldRGB, destRGB);
maskCopy.setRGB(x, y, newRGB);
}
}
return maskCopy;
}
private int extractRGB(int rgb) {
int[] rgbArr = getRGBArray(rgb);
for (int i = 1; i <= 3; i++) {
rgbArr[i] = rgbArr[i] & quality.leastBitsSum;
rgbArr[i] = rgbArr[i] << quality.shift;
}
return getRGBFromArray(rgbArr);
}
private int computeNewRGB(int oldRGB, int destRGB) {
int[] dest = getRGBArray(destRGB);
int[] old = getRGBArray(oldRGB);
for (int i = 1; i <= 3; i++) {
old[i] = old[i] & quality.cuttingMask;
dest[i] = dest[i] >> quality.shift;
old[i] += dest[i];
}
return getRGBFromArray(old);
}
private int getRGBFromArray(int[] rgbArr) {
return new Color(rgbArr[RED], rgbArr[GREEN], rgbArr[BLUE]).getRGB();
}
private int[] getRGBArray(int rgb) {
return new int[] { (rgb >> 24) & 0xff, (rgb >> 16) & 0xff,
(rgb >> 8) & 0xff, rgb & 0xff };
}
}
public enum Quality {
GOOD(4), MEDIUM(3), BAD(2);
public int leastBitsSum;
public int shift;
public int cuttingMask;
private Quality(int bits){
computeLeastBitsSum(bits);
computeCuttingMask(bits);
computeShift(bits);
}
private void computeShift(int bits) {
shift = 8 - bits;
}
private void computeLeastBitsSum(int bits) {
leastBitsSum = 0;
for(int i = 0; i < bits; i++){
leastBitsSum += Math.pow(2, i);
}
}
private void computeCuttingMask(int bits) {
cuttingMask = 255 - leastBitsSum;
}
}
[/spoiler]Copyright 2011 Deque at http://haxme.org, http://poisonhack.info/, http://www.iexploit.org/. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY Deque at http://haxme.org, http://poisonhack.info/, http://www.iexploit.org/ ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the
authors and should not be interpreted as representing official policies, either expressed
or implied, of Deque at http://haxme.org, http://poisonhack.info, http://www.iexploit.org//.