-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreation.java
More file actions
139 lines (123 loc) · 5.65 KB
/
Copy pathCreation.java
File metadata and controls
139 lines (123 loc) · 5.65 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import java.util.LinkedList;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
public class Creation {
public static BufferedImage convertBytesToImage(LinkedList<Integer> bytes, int height, int width, int[] colors){
//If you use an array for colors, you must be sure that you have the right number of bytes in the list
//If, for example, you only have red bytes in your list bc you pulled red bytes from another image, then you would but array {0} as an arg
LinkedList<Integer> localBytes = new LinkedList<Integer>();
for (Integer i : bytes){
localBytes.add(i);
}
//now turn local bytes into a png
BufferedImage image = new BufferedImage (width, height, 6);//just trust the constant
WritableRaster raster = image.getRaster();
for (int yy =0; yy< height; yy++) {
for (int xx = 0; xx< width; xx++){
int[] pixels = raster.getPixel(xx, yy, (int[]) null);
for (int l:colors){
int byte1 = localBytes.removeFirst();
pixels[l]=byte1;
pixels [3]=255;
}
raster.setPixel(xx, yy, pixels);
}
}
return image;
}
public static BufferedImage convertBytesToImage(LinkedList<Integer> bytes, int height, int width){
//if no specirfic colors specified, do all three
return convertBytesToImage(bytes,height,width, new int[]{0,1,2});
}
public static String convertBytesToStringOriginal(LinkedList<Integer> bytes, int length){
LinkedList<Integer> localBytes = new LinkedList<Integer>();
for (Integer i : bytes){localBytes.add(i);}//Copies bytes into a local variable
//This method should not modify the List called bytes, rather copy it and
//modify the local version
String toReturn = "";
//insert code here to throwaway header/garbage bytes
for (int i=0; i<length; i++){
int temp = localBytes.removeFirst().intValue();
if ((temp > 64 & temp < 91) || (temp > 96 & temp < 123) || temp ==32 || temp == 10 || temp==44 || temp == 46 || temp == 63 || temp == 33 || (temp >47 && temp<58))
System.out.print((char)temp);
//toReturn += (char) localBytes.removeFirst().intValue();
}
return toReturn;
}
public static String convertBytesToStringOriginal(LinkedList<Integer> bytes){
//if no length specified, do 500
return convertBytesToStringOriginal(bytes, 500);
}
public static BufferedImage convertBytesToImageWithAlpha(LinkedList<Integer> bytes, int height, int width){
int[] colors = new int[]{0,1,2,3};
LinkedList<Integer> localBytes = new LinkedList<Integer>();
for (Integer i : bytes){
localBytes.add(i);
}
//now turn local bytes into a png
BufferedImage image = new BufferedImage (width, height, 6);//just trust the constant
WritableRaster raster = image.getRaster();
for (int yy =0; yy< height; yy++) {
for (int xx = 0; xx< width; xx++){
int[] pixels = raster.getPixel(xx, yy, (int[]) null);
for (int l:colors){
int byte1 = localBytes.removeFirst();
pixels[l]=byte1;
}
raster.setPixel(xx, yy, pixels);
}
}
return image;
}
public static BufferedImage createBrotherImage(LinkedList<Integer> bytes, int height, int width, int[] colors){
//THIS WAS USED FOR ONE SPECIFIC IMAGE FOR A PROJECT
LinkedList<Integer> localBytes = new LinkedList<Integer>();
for (Integer i : bytes){
localBytes.add(i);
}
LinkedList<Integer> firstBytes = new LinkedList<Integer>();
LinkedList<Integer> secondBytes = new LinkedList<Integer>();
LinkedList<Integer> thirdBytes = new LinkedList<Integer>();
LinkedList<Integer> fourthBytes = new LinkedList<Integer>();
int imageCount = 0; //This is what image we're on
for (int i = 0; i <bytes.size(); i++){
if (imageCount%4==0)
firstBytes.add(localBytes.removeFirst());
else if (imageCount%4==1)
secondBytes.add(localBytes.removeFirst());
else if (imageCount%4==2)
thirdBytes.add(localBytes.removeFirst());
else if (imageCount%4==3)
fourthBytes.add(localBytes.removeFirst());
if ((i+1)%(512*3)==0)
imageCount++;
}
//now turn local bytes into a png
BufferedImage image = new BufferedImage (width, height, 6);//just trust the constant
WritableRaster raster = image.getRaster();
for (int yy =0; yy< height; yy++) {
for (int xx = 0; xx< width; xx++){
int[] pixels = raster.getPixel(xx, yy, (int[]) null);
for (int l:colors){
int byte1=0;
if(xx<512){
byte1 = firstBytes.removeFirst();
}
else if (xx<1024){
byte1 = secondBytes.removeFirst();
}
else if (xx<1536){
byte1 = thirdBytes.removeFirst();
}
else{
byte1 = fourthBytes.removeFirst();
}
pixels[l]=byte1;
pixels [3]=255;
}
raster.setPixel(xx, yy, pixels);
}
}
return image;
}
}