11
11
import java .util .stream .Stream ;
12
12
13
13
public class ImageManipulator {
14
- private final String rawImagePath ;
15
- private BufferedImage imageBuffer ;
16
- private File fileBuffer ;
14
+ private final String raw_image_path ;
15
+ private BufferedImage image_buffer ;
16
+ private File file_buffer ;
17
17
private final String format ;
18
18
19
- public ImageManipulator (String rawImagePath , String format ) {
20
- this .rawImagePath = rawImagePath ;
21
- this .imageBuffer = null ;
22
- this .fileBuffer = null ;
19
+ public ImageManipulator (String raw_image_path , String format ) {
20
+ this .raw_image_path = raw_image_path ;
21
+ this .image_buffer = null ;
22
+ this .file_buffer = null ;
23
23
this .format = format ;
24
24
}
25
25
26
- public void addSepia (String outputImagePath ) {
26
+ public void addSepia (String out_image_path ) {
27
27
setBuffer ();
28
- int width = imageBuffer .getWidth ();
29
- int height = imageBuffer .getHeight ();
28
+ int width = image_buffer .getWidth ();
29
+ int height = image_buffer .getHeight ();
30
30
31
31
for (int vertical = 0 ; vertical < height ; vertical ++) {
32
32
for (int horizontal = 0 ; horizontal < width ; horizontal ++) {
33
- int pixels = imageBuffer .getRGB (horizontal , vertical );
33
+ int pixels = image_buffer .getRGB (horizontal , vertical );
34
34
35
35
int autos = (pixels >> 24 ) & 0xff ;
36
36
int red = (pixels >> 16 ) & 0xff ;
@@ -46,39 +46,39 @@ public void addSepia(String outputImagePath) {
46
46
blue = Math .min (avgBlue , 255 );
47
47
48
48
pixels = (autos << 24 ) | (red << 16 ) | (green << 8 ) | blue ;
49
- imageBuffer .setRGB (horizontal , vertical , pixels );
49
+ image_buffer .setRGB (horizontal , vertical , pixels );
50
50
}
51
51
}
52
- writeImage (outputImagePath , format );
52
+ writeImage (out_image_path , format );
53
53
}
54
54
55
- public void addRedDevil (String outputImagePath ) {
55
+ public void addRedDevil (String out_image_path ) {
56
56
setBuffer ();
57
- int width = imageBuffer .getWidth ();
58
- int height = imageBuffer .getHeight ();
57
+ int width = image_buffer .getWidth ();
58
+ int height = image_buffer .getHeight ();
59
59
60
60
for (int vertical = 0 ; vertical < height ; vertical ++) {
61
61
for (int horizontal = 0 ; horizontal < width ; horizontal ++) {
62
- int pixels = imageBuffer .getRGB (horizontal , vertical );
62
+ int pixels = image_buffer .getRGB (horizontal , vertical );
63
63
64
64
int autos = (pixels >> 24 ) & 0xff ;
65
65
int red = (pixels >> 16 ) & 0xff ;
66
66
67
67
pixels = (autos << 24 ) | (red << 16 ) | (0 );
68
- imageBuffer .setRGB (horizontal , vertical , pixels );
68
+ image_buffer .setRGB (horizontal , vertical , pixels );
69
69
}
70
70
}
71
- writeImage (outputImagePath , format );
71
+ writeImage (out_image_path , format );
72
72
}
73
73
74
- public void addNegativeEffect (String outputImagePath ) {
74
+ public void addNegativeEffect (String out_image_path ) {
75
75
setBuffer ();
76
- int width = imageBuffer .getWidth ();
77
- int height = imageBuffer .getHeight ();
76
+ int width = image_buffer .getWidth ();
77
+ int height = image_buffer .getHeight ();
78
78
79
79
for (int vertical = 0 ; vertical < height ; vertical ++) {
80
80
for (int horizontal = 0 ; horizontal < width ; horizontal ++) {
81
- int pixels = imageBuffer .getRGB (horizontal , vertical );
81
+ int pixels = image_buffer .getRGB (horizontal , vertical );
82
82
83
83
int autos = (pixels >> 24 ) & 0xff ;
84
84
int red = (pixels >> 16 ) & 0xff ;
@@ -90,36 +90,36 @@ public void addNegativeEffect(String outputImagePath) {
90
90
blue = 255 - blue ;
91
91
92
92
pixels = (autos << 24 ) | (red << 16 ) | (green << 8 ) | blue ;
93
- imageBuffer .setRGB (horizontal , vertical , pixels );
93
+ image_buffer .setRGB (horizontal , vertical , pixels );
94
94
}
95
95
}
96
- writeImage (outputImagePath , format );
96
+ writeImage (out_image_path , format );
97
97
}
98
98
99
- public void addGreenMatrix (String outputImagePath ) {
99
+ public void addGreenMatrix (String out_image_path ) {
100
100
setBuffer ();
101
- int width = imageBuffer .getWidth ();
102
- int height = imageBuffer .getHeight ();
101
+ int width = image_buffer .getWidth ();
102
+ int height = image_buffer .getHeight ();
103
103
104
104
for (int vertical = 0 ; vertical < height ; vertical ++) {
105
105
for (int horizontal = 0 ; horizontal < width ; horizontal ++) {
106
- int pixels = imageBuffer .getRGB (horizontal , vertical );
106
+ int pixels = image_buffer .getRGB (horizontal , vertical );
107
107
int autos = (pixels >> 24 ) & 0xff ;
108
108
int green = (pixels >> 8 ) & 0xff ;
109
109
pixels = (autos << 24 ) | (0 ) | (green << 8 );
110
- imageBuffer .setRGB (horizontal , vertical , pixels );
110
+ image_buffer .setRGB (horizontal , vertical , pixels );
111
111
}
112
112
}
113
- writeImage (outputImagePath , format );
113
+ writeImage (out_image_path , format );
114
114
}
115
115
116
- public void addGrayScale (String outputImagePath ) {
116
+ public void addGrayScale (String out_image_path ) {
117
117
setBuffer ();
118
- int width = imageBuffer .getWidth ();
119
- int height = imageBuffer .getHeight ();
118
+ int width = image_buffer .getWidth ();
119
+ int height = image_buffer .getHeight ();
120
120
for (int vertical = 0 ; vertical < height ; vertical ++) {
121
121
for (int horizontal = 0 ; horizontal < width ; horizontal ++) {
122
- int pixels = imageBuffer .getRGB (horizontal , vertical );
122
+ int pixels = image_buffer .getRGB (horizontal , vertical );
123
123
int autos = (pixels >> 24 ) & 0xff ;
124
124
int red = (pixels >> 16 ) & 0xff ;
125
125
int green = (pixels >> 8 ) & 0xff ;
@@ -129,60 +129,60 @@ public void addGrayScale(String outputImagePath) {
129
129
.getAverage ();
130
130
pixels = (autos << 24 ) | (average << 16 )
131
131
| (average << 8 ) | average ;
132
- imageBuffer .setRGB (horizontal , vertical , pixels );
132
+ image_buffer .setRGB (horizontal , vertical , pixels );
133
133
}
134
134
}
135
- writeImage (outputImagePath , format );
135
+ writeImage (out_image_path , format );
136
136
}
137
137
138
138
public void addBlueEffect (String outputImagePath ) {
139
139
setBuffer ();
140
- int width = imageBuffer .getWidth ();
141
- int height = imageBuffer .getHeight ();
140
+ int width = image_buffer .getWidth ();
141
+ int height = image_buffer .getHeight ();
142
142
143
143
for (int vertical = 0 ; vertical < height ; vertical ++) {
144
144
for (int horizontal = 0 ; horizontal < width ; horizontal ++) {
145
- int pixels = imageBuffer .getRGB (horizontal , vertical );
145
+ int pixels = image_buffer .getRGB (horizontal , vertical );
146
146
int autos = (pixels >> 24 ) & 0xff ;
147
147
int blue = pixels & 0xff ;
148
148
pixels = (autos << 24 ) | (0 ) | blue ;
149
- imageBuffer .setRGB (horizontal , vertical , pixels );
149
+ image_buffer .setRGB (horizontal , vertical , pixels );
150
150
}
151
151
}
152
152
writeImage (outputImagePath , format );
153
153
}
154
154
155
155
private void setBuffer () {
156
156
try {
157
- fileBuffer = new File (rawImagePath );
158
- imageBuffer = ImageIO .read (fileBuffer );
157
+ file_buffer = new File (raw_image_path );
158
+ image_buffer = ImageIO .read (file_buffer );
159
159
} catch (IOException ex ) {
160
160
logger (ex .getMessage ());
161
161
}
162
162
}
163
163
164
- private void writeImage (String filePath , String format ) {
164
+ private void writeImage (String file_path , String format ) {
165
165
try {
166
- fileBuffer = new File (filePath );
167
- ImageIO .write (imageBuffer , format , fileBuffer );
168
- logger ("Image successfully saved to " + filePath );
166
+ file_buffer = new File (file_path );
167
+ ImageIO .write (image_buffer , format , file_buffer );
168
+ logger ("Image successfully saved to " + file_path );
169
169
} catch (IOException ex ) {
170
170
logger (ex .getMessage ());
171
171
}
172
172
}
173
173
174
174
private void logger (String message ) {
175
- final String filePath = "details.log" ;
175
+ final String file_path = "details.log" ;
176
176
try {
177
- File file = new File (filePath );
177
+ File file = new File (file_path );
178
178
if (!file .exists ())
179
179
file .createNewFile ();
180
180
181
- try (FileWriter writer = new FileWriter (filePath , true )) {
181
+ try (FileWriter writer = new FileWriter (file_path , true )) {
182
182
writer .append ("\n " ).append (message );
183
183
}
184
184
} catch (Exception e ) {
185
- System .err .println ("A full log can be found at " + filePath );
185
+ System .err .println ("A full log can be found at " + file_path );
186
186
}
187
187
}
188
188
}
0 commit comments