/* * Transform.java */ /* * transforms * 0 - none * 1 - inversion * 2-9 - alpha planes * 10-17 - r planes * 18-25 - g planes * 26-33 - b planes * 34 full alpha * 35 full red * 36 full green * 37 full blue * 38 random color1 * 39 random color2 * 40 random color3 * 41 gray bits */ package stegsolve; import java.awt.image.*; import java.util.Random; /** * A transform represents a change to the image such as a bit plane * or recolouring etc * @author Caesum */ public class Transform { /** * Original image */ private BufferedImage originalImage; /** * Transformed image */ private BufferedImage transform; /** * The number of this transformation */ private int transNum; /** * The number of transformations supported */ private static final int MAXTRANS = 41; /** * Create a new transformation * @param bi the image */ Transform(BufferedImage bi) { originalImage = bi; transform = originalImage; transNum=0; } /** * Makes an image from a bit plane * @param d bit to use */ private void transfrombit(int d) { transform = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_INT_RGB); for(int i=0;i>>d)&1)>0) col=0xffffff; transform.setRGB(i, j, col); } } /** * Makes an image given a mask of bit planes * @param mask bit mask to use */ private void transmask(int mask) { transform = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_INT_RGB); for(int i=0;i0xffffff||col<0) col=col>>>8; transform.setRGB(i, j, col); } } /** * Inverts the colours of the image */ private void inversion() { transform = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_INT_RGB); for(int i=0;i>8)&&(fcol&0xff)==((fcol&0xff0000)>>16)) col=0xffffff; transform.setRGB(i, j, col); } } /** * Randomises the colours of the image for a truecolour image */ private void random_colormap() { // straight random mapping Random rnd = new Random(); int bm = rnd.nextInt(256),ba = rnd.nextInt(256),bx = rnd.nextInt(256); int gm = rnd.nextInt(256),ga = rnd.nextInt(256),gx = rnd.nextInt(256); int rm = rnd.nextInt(256),ra = rnd.nextInt(256),rx = rnd.nextInt(256); transform = new BufferedImage(originalImage.getWidth(), originalImage.getHeight(), BufferedImage.TYPE_INT_RGB); for(int i=0;i>8) * gm; g = ((g*gm)^gx)+ga; int r = ((fcol & 0xff0000)>>16) * rm; r = ((r*rm)^rx)+ra; col = (r<<16)+(g<<8)+b+(fcol&0xff000000); transform.setRGB(i, j, col); } } /** * Randomises the colours of the image for an indexed palette image */ private void random_indexmap() { // this would be an indexed palette - this is separate // because two indexes can have the same color value // so the mapping should be done on the palette and not // on the image itself byte [] r, g, b; int bits, size; int [] gcs; Random rnd = new Random(); IndexColorModel cm = (IndexColorModel)originalImage.getColorModel(); gcs = cm.getComponentSize(); bits = gcs[0]; if(gcs[1]>bits) bits=gcs[1]; if(gcs[2]>bits) bits=gcs[2]; size = cm.getMapSize(); r = new byte[size]; g = new byte[size]; b = new byte[size]; cm.getReds(r); cm.getGreens(g); cm.getBlues(b); for(int i=0;iMAXTRANS) transNum=0; calcTrans(); } /** * Return a textual description of the transformation * @return text description for transformation */ public String getText() { switch(transNum) { case 0: return "Normal Image"; case 1: return "Colour Inversion (Xor)"; case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: return "Alpha plane " + (9 - transNum); case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: return "Red plane " + (17 - transNum); case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25: return "Green plane " + (25 - transNum); case 26: case 27: case 28: case 29: case 30: case 31: case 32: case 33: return "Blue plane " + (33 - transNum); case 34: return "Full alpha"; case 35: return "Full red"; case 36: return "Full green"; case 37: return "Full blue"; case 38: return "Random colour map 1"; case 39: return "Random colour map 2"; case 40: return "Random colour map 3"; case 41: return "Gray bits"; default: return ""; } } /** * Get the transformed image * @return transformed image */ public BufferedImage getImage() { return transform; } }