Unverified Commit 088ec1ac authored by Exr0n's avatar Exr0n
Browse files

just missing hide_text

parent 9538580e
No related merge requests found
Showing with 55 additions and 3 deletions
+55 -3
...@@ -6,6 +6,9 @@ import javax.imageio.ImageIO; ...@@ -6,6 +6,9 @@ import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Image { public class Image {
private Pixel[][] pixels; private Pixel[][] pixels;
...@@ -25,15 +28,64 @@ public class Image { ...@@ -25,15 +28,64 @@ public class Image {
} }
public Image transpose() { public Image transpose() {
return null; int height = this.pixels.length;
int width = this.pixels[0].length; // ASSUME: at least one row of pixels
Pixel[][] new_pix = new Pixel[width][height];
for (int i=0; i<height; i++) {
for (int j=0; j<width; j++) {
new_pix[j][i] = pixels[i][j];
}
}
return new Image(new_pix);
} }
public String decodeText() { public String decodeText() {
return null; var lsbs = Stream.of(this.pixels)
.flatMap((row) -> Arrays.stream(row)) // flatten 2d array
.mapToInt((p) -> p.getLowestBitOfR())
.boxed() // https://howtodoinjava.com/java8/convert-intstream-collection-array/
.collect(Collectors.toList())
.toArray(new Integer[0]);
int height = this.pixels.length;
int width = this.pixels[0].length;
String ret = "";
for (int i=0; i+7<height*width; i += 8) {
int c = 0;
for (int j=0; j<8; j++) c += lsbs[i + j] << j;
if (c == 0) break;
ret += "" + (char) c;
}
return ret;
} }
public Image hideText(String text) { public Image hideText(String text) {
return null; int height = this.pixels.length;
int width = this.pixels[0].length;
int[] bits_to_write = new int[height * width];
int ctr = 0;
for (char c : text.toCharArray()) { // https://stackoverflow.com/a/2451660
for (int j=0; j<8; j++) {
bits_to_write[ctr] = (c >> j) & 1;
ctr ++;
}
}
Pixel[][] new_pix = new Pixel[height][width];
ctr = 0;
for (int i=0; i<height; i++) {
for (int j=0; j<width; j++) {
new_pix[i][j] = this.pixels[i][j];
new_pix[i][j].fixLowestBitOfR(bits_to_write[ctr]);
ctr ++;
}
}
return new Image(new_pix);
} }
public BufferedImage toBufferedImage() { public BufferedImage toBufferedImage() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment