Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Albert Y. Huang
lab02
Commits
088ec1ac
Unverified
Commit
088ec1ac
authored
1 year ago
by
Exr0n
Browse files
Options
Download
Email Patches
Plain Diff
just missing hide_text
parent
9538580e
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/edu/caltech/cs2/lab02/Image.java
+55
-3
src/edu/caltech/cs2/lab02/Image.java
with
55 additions
and
3 deletions
+55
-3
src/edu/caltech/cs2/lab02/Image.java
View file @
088ec1ac
...
@@ -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
()
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help