-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageWriter.java
More file actions
35 lines (31 loc) · 1.07 KB
/
ImageWriter.java
File metadata and controls
35 lines (31 loc) · 1.07 KB
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
import java.awt.image.BufferedImage;
// By: Justin Spedding & Andrew Miller
public class ImageWriter extends ImageManipulator {
/**
* Constructs an image writer
*
* @param hostImage
* The host image to write to
* @param password
* The password used to store the stego
* @throws ImageOverflowException
* Throws if the internal algorithm tries to write to a pixel that does not exist
*/
public ImageWriter(BufferedImage hostImage, String password) throws ImageOverflowException {
super(hostImage, password);
}
/**
* Writes a single bit to the next bit in the image
*
* @throws ImageOverflowException
* Throws if the internal algorithm tries to write to a pixel that does not exist
*/
public void writeBit(int bit) throws ImageOverflowException {
if (bit == 0) {
hostImage.setRGB(x, y, (hostImage.getRGB(x, y) & ~(1 << (currentBit + ((x + y + rgb) % 3) * 8)))); // Set the bit to 0
} else {
hostImage.setRGB(x, y, (hostImage.getRGB(x, y) | (1 << (currentBit + ((x + y + rgb) % 3) * 8)))); // set the bit to 1
}
nextPixel();
}
}