-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.java
More file actions
90 lines (71 loc) · 3.15 KB
/
Copy pathMain.java
File metadata and controls
90 lines (71 loc) · 3.15 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
import lib.Picture;
import lib.Pixel;
import java.awt.*;
public class Main {
private static final Picture PLASMA = new Picture("Plasma.jpg");
private static final Picture CALEB = new Picture ("Caleb.jpeg");
private static final Picture RED_SHADES = new Picture("ShadesRed.png");
private static final Picture BLUE_SHADES = new Picture("ShadesBlue.png");
private static final Picture BLISS = new Picture("Bliss.jpg");
private static final Picture SHIFU = new Picture("Shifu.jpg");
public static void main(String[] args) {
System.out.printf("PLASMA:\tWidth: %d\tHeight: %d\n", PLASMA.getWidth(), PLASMA.getHeight());
System.out.printf("CALEB:\tWidth: %d\tHeight: %d\n", CALEB.getWidth(), CALEB.getHeight());
System.out.printf("RED_SHADES:\tWidth: %d\tHeight: %d\n", RED_SHADES.getWidth(), RED_SHADES.getHeight());
System.out.printf("BLISS:\tWidth: %d\tHeight: %d\n", BLISS.getWidth(), BLISS.getHeight());
System.out.printf("SHIFU:\tWidth: %d\tHeight: %d\n", SHIFU.getWidth(), SHIFU.getHeight());
// Uncomment each block to see what each method does
// CALEB.show();
// BLISS.show();
// combine(BLISS, CALEB, false).show();
// SHIFU.show();
// RED_SHADES.show();
// combine(RED_SHADES, SHIFU, false).show();
// SHIFU.show();
// setVibrant(SHIFU).show();
// PLASMA.show();
// setVibrant(PLASMA).show();
// combine(BLUE_SHADES, RED_SHADES, true).show();
}
/**
* Creates an image with the highest R, G or B values set for each pixel
* @param pSingular The image to use
* @return The image with the new values set
*/
public static Picture setVibrant(Picture pSingular){
Picture p = new Picture(pSingular);
Pixel[][] pixelArray = p.getPixels2D();
for (Pixel[] pA : pixelArray) {
for (Pixel pix : pA) {
pix.setColor(Utils.max(pix.getColor()));
}
}
return p;
}
/**
* Combines p1 and p2. p1 has to be BIGGER than p2 in both width and height
* @param p1 The bigger picture
* @param p2 The smaller picture
* @param vibrant Set to true if the new image should have the R, G, and B values maxed
* @return New image with p2 combined with p1.
*/
public static Picture combine(Picture p1, Picture p2, boolean vibrant){
if(!Utils.isBigger(p1, p2)) return p1;
Picture ret = new Picture(p2.getHeight(), p2.getWidth());
Pixel[][] retArray = ret.getPixels2D();
Pixel[][] p1Array = p1.getPixels2D();
Pixel[][] p2Array = p2.getPixels2D();
for(int i = 0; i < p1Array.length; i++){
for (int j = 0; j < p1Array[0].length; j++){
Color p1Col = p1Array[i][j].getColor();
if(i < p2.getHeight() && j < p2.getWidth()){
Color p2Col = p2Array[i][j].getColor();
Color avgCol = Utils.getAvg(p1Col,p2Col);
if(vibrant) retArray[i][j].setColor(Utils.max(avgCol));
else retArray[i][j].setColor(avgCol);
}
}
}
return ret;
}
}