-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEasyBufferedImage.java
638 lines (576 loc) · 23.8 KB
/
EasyBufferedImage.java
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import javax.imageio.*;
import java.net.*;
import java.io.*;
/**
* Code obtained from Dr. Kenny Hunt, The University of Wisconsin La Crosse.
* "Using image processing to teach cs1 and cs2" (2003). SIGCSE Bulletin.
*
*
* Represents an image that can be manipulated without a thorough understanding
* of the built-in image classes. Performance (in terms of memory and speed) is sacrificed in order to provide
* simplified access to pixel data. Allows direct read/write access to individual pixels
* and a factory method for creating EasyBufferedImages from files. The image always
* appears as either a gray-scale image, an RGB image or an RGBA image. The data is
* never packed or interleaved (at least with respect to the get/set pixel methods).
* <p>
* Please note that grayscale processing of a <b>color</b> image always maintains the color information of the image while
* altering the <b>intensity</b> channel. To perform operations on a purely gray-scale image, convert any color
* images to grayscale prior to processing.
* <p>
* Since the EasyBufferedImage class is a sub-class of Image and BufferedImage, it
* is fully integrated into the standard Swing libraries for viewing and manipulation.
* To create an EasyBufferedImage you must use the factory method shown below:
* <p><b><blockquote><pre>EasyBufferedImage image = EasyBufferedImage.createImage(filename);</pre></blockquote></b>
* where the filename is a String representing an image file in either GIF, PNG, or JPEG
* formats. The following code fragment is an example of how to invert a gray-scale image:
* <b><font color="#115500"><blockquote><pre>
* int[] pixels = image.getPixels1D(EasyBufferedImage.GRAY);
* for(int i=0; i < pixels.length; i++) {
* pixels[i] = 255-pixels[i];
* }
* image.setPixels(pixels);
* </pre></blockquote></font></b>
* @see Image
* @see BufferedImage
*/
public class EasyBufferedImage extends BufferedImage {
public static final int GRAY = 4, RED = 0, GREEN = 1, BLUE = 2, ALPHA = 3;
public static final int JPEG = 0, GIF = 1, PNG = 2;
private static final String[] TYPES = {"JPEG", "GIF", "PNG"};
private static int windowCount = 0;
/**
* Returns a String array listing the file formats supported by this class.
* @param none
* @return an array of strings listing the supported file formats.
*/
public String[] getSupportedFormats() {
return TYPES;
}
public static EasyBufferedImage createImage(BufferedImage image) {
return toBufferedImage(image);
}
/**
* Returns an EasyBufferedImage object by reading the image file
* specified by the filename. The format of the file may be any
* one of GIF, PNG, or JPEG. This is a factory method to create
* EasyBufferedImages. There is no direct constructor access.
* <p>
* @param filename the name of the file to load.
* @return the EasyBufferedImage stored in the file.
* @throws FileNotFoundException
* @see Image
* @see BufferedImage
*/
public static EasyBufferedImage createImage(String filename) throws FileNotFoundException {
File file = new File(filename);
if(!file.exists()) throw new FileNotFoundException(filename);
return toBufferedImage(Toolkit.getDefaultToolkit().createImage(filename));
}
public static EasyBufferedImage createImage(File file) throws IOException, FileNotFoundException {
if(!file.exists()) throw new FileNotFoundException(file.getName());
return toBufferedImage(ImageIO.read(file));
}
/**
* Returns an EasyBufferedImage object by reading the image
* specified by the url. The format of the file may be any
* one of GIF, PNG, or JPEG. This is a factory method to create
* EasyBufferedImages. There is no direct constructor access.
* <p>
* @param url is the URL of an image file to load.
* @return the EasyBufferedImage stored in the file.
* @see Image
* @see BufferedImage
*/
public static EasyBufferedImage createImage(URL url) {
return toBufferedImage(Toolkit.getDefaultToolkit().createImage(url));
}
/**
* Returns an EasyBufferedImage object represented by the specified pixels.
* The dimensions of the pixel array must be [height][width][bands] where bands may
* be either 1 (gray-scale) or 3 (red-green-blue).
* This is a factory method to create EasyBufferedImages. There is no direct constructor access.
* <p>
* @param pixels is an array of [height][width][bands] pixels that represents the image.
* @return An EasyBufferedImage representation of the pixels.
* @throws IllegalArgumentException if pixels is null
* @see Image
* @see BufferedImage
*/
public static EasyBufferedImage createImage(int[][][] pixels) {
if(pixels == null) throw new IllegalArgumentException("null pixels array");
// create the BufferedImage (doesn't include transparency!)
EasyBufferedImage result = new EasyBufferedImage(pixels[0].length,
pixels.length,
BufferedImage.TYPE_INT_RGB);
result.setPixels(pixels);
return result;
}
/**
* Returns an EasyBufferedImage object represented by the specified pixels.
* The dimensions of the pixel array must be [height][width] and is assumed
* to be gray-scale.
* This is a factory method to create EasyBufferedImages. There is no direct constructor access.
* <p>
* @param pixels is an array of [height][width] pixels that represents the image.
* @return An EasyBufferedImage representation of the pixels.
* @throws IllegalArgumentException if pixels is null
* @see Image
* @see BufferedImage
*/
public static EasyBufferedImage createImage(int[][] pixels) {
if(pixels == null) throw new IllegalArgumentException("null pixels array");
// create the BufferedImage (doesn't include transparency!)
EasyBufferedImage result = new EasyBufferedImage(pixels[0].length,
pixels.length,
BufferedImage.TYPE_INT_RGB);
result.setPixels(pixels, RED);
result.setPixels(pixels, GREEN);
result.setPixels(pixels, BLUE);
return result;
}
/**
* Returns an EasyBufferedImage object represented by the specified pixels.
* The dimensions of the pixel array must be [height * width] and layed out in
* row-major format. The image is assumed to be gray-scale.
* This is a factory method to create EasyBufferedImages. There is no direct constructor access.
* <p>
* @param pixels is an array of [height * width] pixels that represents the image.
* @param height is the height (in pixels) of the image.
* @param width is the width (in pixels) of the image.
* @return An EasyBufferedImage representation of the pixels.
* @throws IllegalArgumentException if pixels is null or the length is not width * height.
* @see Image
* @see BufferedImage
*/
public static EasyBufferedImage createImage(int[] pixels, int width, int height) {
if(pixels == null) {
throw new IllegalArgumentException("null pixels array");
} else if((width * height) != pixels.length) {
throw new IllegalArgumentException("pixels dimensions doesn't match width/height parameters");
}
if(pixels == null) throw new IllegalArgumentException("null pixels array");
// create the BufferedImage (doesn't include transparency!)
EasyBufferedImage result = new EasyBufferedImage(width,
height,
BufferedImage.TYPE_INT_RGB);
result.setPixels(pixels, RED);
result.setPixels(pixels, GREEN);
result.setPixels(pixels, BLUE);
return result;
}
private EasyBufferedImage(int w, int h, int type) {
super(w, h, type);
}
/**
* Returns the value of v clamped to the range 0-255.
* This is a convenience method for working with image pixel values.
* <p>
* @param v is the value of a pixel to be clamped.
* @return the value v clamped to the range 0-255.
*/
public static int clamp(double v) {
if(v < 0) return 0;
else if(v > 255) return 255;
else return (int)v;
}
/**
* Returns an EasyBufferedImage object that is a gray-scale copy
* of the calling image.
* <p>
* @param None
* @return an EasyBufferedImage that is a gray-scale copy of the caller.
*/
public EasyBufferedImage copyToGrayScale() {
EasyBufferedImage result = new EasyBufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_BYTE_GRAY);
WritableRaster input = getRaster();
WritableRaster output = result.getRaster();
for(int row=0; row < input.getHeight(); row++) {
for(int col=0; col < input.getWidth(); col++) {
int red = input.getSample(col, row, 0);
int green = input.getSample(col, row, 1);
int blue = input.getSample(col, row, 2);
output.setSample(col, row, 0, clamp((red+green+blue)/3.0));
}
}
return result;
}
private static EasyBufferedImage toBufferedImage(Image image) {
// make sure that the Image is loaded (images can be loaded asynchronously)
image = new ImageIcon(image).getImage();
// create the BufferedImage (doesn't include transparency!)
EasyBufferedImage result = new EasyBufferedImage(image.getWidth(null),
image.getHeight(null),
BufferedImage.TYPE_INT_RGB);
// Draw the input onto the BufferedImage and return
Graphics g = result.createGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
return result;
}
/**
* Returns a 3D array of pixel values. The dimensions of the array correspond
* to the [height][width][bands] of the EasyBufferedImage. The number of bands
* will be 1 for a gray-scale or binary image, 3 for a color image without
* transparency, and 4 for a color image with transparency. The bands are (in
* order) RED (or GRAY), GREEN, BLUE, ALPHA. Pixel values are in the range 0-255.
* <p>
* @param None
* @return an array of pixels accessed.
*/
public int[][][] getPixels3D() {
int width = getWidth();
int height = getHeight();
int bands = getSampleModel().getNumBands();
int[][][] pixels = new int[height][width][bands];
WritableRaster raster = getRaster();
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
for(int k=0; k<bands; k++) {
pixels[i][j][k] = raster.getSample(j,i,k);
}
}
}
return pixels;
}
/**
* Returns a 2D array of pixel values corresponding to the specified band.
* The dimensions of the array correspond to the [height][width] of the EasyBufferedImage.
* The number of bands will be 1 for a gray-scale or binary image, 3 for a color image without
* transparency, and 4 for a color image with transparency. The bands are (in
* order) RED (or GRAY), GREEN, BLUE, ALPHA. Pixel values are in the range 0-255.
* <p>
* @param band is either RED, GREEN, BLUE, ALPHA, or GRAY
* @return an array of pixels.
*/
public int[][] getPixels2D(int band) {
int width = getWidth();
int height = getHeight();
int[][] pixels = new int[height][width];
WritableRaster raster = getRaster();
if(band == GRAY && isColor()) {
float hsb[] = new float[3];
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
int pixel = getRGB(j, i);
Color.RGBtoHSB(raster.getSample(j, i, 0),
raster.getSample(j, i, 1),
raster.getSample(j, i, 2),
hsb);
pixels[i][j] = clamp(hsb[2] * 255);
}
}
} else {
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
pixels[i][j] = raster.getSample(j,i,band);
}
}
}
return pixels;
}
/**
* Returns a 1D array of pixel values corresponding to the specified band.
* The array is layed out in row-major format and contains height*width pixel values.
* The number of bands will be 1 for a gray-scale or binary image, 3 for a color image without
* transparency, and 4 for a color image with transparency. The bands are (in
* order) RED (or GRAY), GREEN, BLUE, ALPHA. Pixel values are in the range 0-255.
* <p>
* @param band is either RED, GREEN, BLUE, ALPHA, or GRAY
* @return an array of pixels.
*/
public int[] getPixels1D(int band) {
int width = getWidth();
int height = getHeight();
int[]pixels = new int[height * width];
WritableRaster raster = getRaster();
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
pixels[i*width + j] = raster.getSample(j,i,band);
}
}
return pixels;
}
/**
* The array is layed out in row-major format and contains height*width pixel values.
* The number of bands will be 1 for a gray-scale or binary image, 3 for a color image without
* transparency, and 4 for a color image with transparency. The bands are (in
* order) RED (or GRAY), GREEN, BLUE, ALPHA. Pixel values are in the range 0-255.
* <p>
* @return an array of pixels.
*/
public int[] getPixels1D() {
int width = getWidth();
int height = getHeight();
int bands = getRaster().getNumBands();
int[]pixels = new int[height * width * bands];
WritableRaster raster = getRaster();
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
for(int k=0; k<bands; k++) {
pixels[i*width*bands + j*bands + k] = raster.getSample(j,i,k); // probably not correct here.............
}
}
}
return pixels;
}
/**
* Sets all of the EasyBufferedImages pixels in the specified band. The number of elements
* in the array must be equal to height*width of the EasyBufferedImage. The band must
* be either GRAY, RED, GREEN, BLUE, or ALPHA. Pixel values not in the range 0-255
* will be stripped of their higher-order bits.
* <p>
* @param pixels is an array of the "new" image for the specified band.
* @param band is one of GRAY, RED, GREEN, BLUE, or ALPHA
* @throws IllegalArgumentException if the pixels array is not compatible with the image.
* @return None
*/
public void setPixels(int[] pixels, int band) {
int width = getWidth();
int height = getHeight();
if(pixels == null || width * height != pixels.length)
throw new IllegalArgumentException("pixel array doesn't match the image size");
WritableRaster raster = getRaster();
if(band == GRAY && isColor()) {
float hsb[] = new float[3];
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
Color.RGBtoHSB(raster.getSample(j, i, 0),
raster.getSample(j, i, 1),
raster.getSample(j, i, 2),
hsb);
hsb[2] = (float)(pixels[i * width + j] / 255.0);
int pixel = Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]);
setRGB(j, i, pixel);
}
}
} else {
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
raster.setSample(j, i, band, pixels[i*width + j]);
}
}
}
}
/**
* Sets all of the EasyBufferedImages pixels in the specified band. The dimensions of the pixels array
* must correspond to [height][width] of the EasyBufferedImage. The band must
* be either GRAY, RED, GREEN, BLUE, or ALPHA. Pixel values not in the range 0-255
* will be stripped of their higher-order bits.
* <p>
* @param pixels is an array of the "new" image in the specified band.
* @param band is one of GRAY, RED, GREEN, BLUE, or ALPHA
* @throws IllegalArgumentException if the pixels array is not compatible with the image.
* @return None
*/
public void setPixels(int[][] pixels, int band) {
int width = getWidth();
int height = getHeight();
if(pixels == null ||
pixels[0] == null ||
width != pixels[0].length || height != pixels.length)
throw new IllegalArgumentException("pixel array doesn't match the image size");
WritableRaster raster = getRaster();
if(band == GRAY && isColor()) {
float hsb[] = new float[3];
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
Color.RGBtoHSB(raster.getSample(j, i, 0),
raster.getSample(j, i, 1),
raster.getSample(j, i, 2),
hsb);
hsb[2] = (float)(pixels[i][j] / 255.0);
int pixel = Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]);
setRGB(j, i, pixel);
}
}
} else {
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
raster.setSample(j, i, band, pixels[i][j]);
}
}
}
}
/**
* Sets all of the EasyBufferedImages pixels. The dimensions of the pixels array
* must correspond to [height][width][bands] of the EasyBufferedImage. The number of bands
* will be 1 for a gray-scale or binary image, 3 for a color image without
* transparency, and 4 for a color image with transparency. The bands are (in
* order) RED (or GRAY), GREEN, BLUE, ALPHA. Pixel values not in the range 0-255
* will be stripped of their higher-order bits.
* <p>
* @param pixels is a 3D array of HEIGHT by WIDTH by DEPTH pixels of the image
* @throws IllegalArgumentException if the pixels array is not compatible with the image.
* @return None
*/
public void setPixels(int[][][] pixels) {
int width = getWidth();
int height = getHeight();
int bands = getSampleModel().getNumBands();
if(pixels == null ||
pixels[0] == null ||
pixels[0][0] == null ||
width != pixels[0].length || height != pixels.length || bands != pixels[0][0].length)
throw new IllegalArgumentException("pixel array doesn't match the image size");
WritableRaster raster = getRaster();
for(int i=0; i<height; i++) {
for(int j=0; j<width; j++) {
for(int k=0; k<bands; k++) {
raster.setSample(j, i, k, pixels[i][j][k]);
}
}
}
}
/**
* Returns true if the image is a color image and false otherwise.
* @param None
* @return true if the image is a color image and false otherwise.
*/
public boolean isColor() {
return getSampleModel().getNumBands() >= 3;
}
/**
* Returns a copy of the calling EasyBufferedImage.
* @param None
* @return A copy of the EasyBufferedImage.
*/
public EasyBufferedImage copy() {
return toBufferedImage(this);
}
/**
* Creates a window that will display this EasyBufferedImage
* This method maintains a count of all windows opened via calls to this method
* and will terminate the application if <b>all</b> such windows are closed.
* @param None
* @return None
*/
public void show(String title) {
JFrame window = new JFrame(title);
window.getContentPane().add(new ImagePanel(this.copy()));
window.setSize(getWidth(), getHeight());
windowCount++;
window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if(--windowCount == 0) System.exit(0); else e.getWindow().dispose();
}
});
window.show();
}
private static class ImagePanel extends JPanel {
BufferedImage image;
ImagePanel(BufferedImage im) {
image = im;
setMinimumSize(new Dimension(im.getWidth(), im.getHeight()));
}
public void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
// center the image
int dx = (getWidth() - image.getWidth())/2;
if(dx < 0) dx = 0;
int dy = (getHeight() - image.getHeight())/2;
if(dy < 0) dy = 0;
g.drawImage(image, dx, dy, this);
}
}
/**
* Creates an image file having the specified name and of the specified format.
* @param filename the name of the file to be saved
* @param format one of EasyBufferedImage.PNG, EasyBufferedImage.GIF or EasyBufferedImage.JPEG
* @return None
* @throws IOException if the file cannot be created.
*/
public void save(String filename, int format) throws IOException {
if(format != JPEG && format != PNG && format != GIF) throw new IllegalArgumentException("Type must be either GIF, PNG, or JPEG");
ImageIO.write(this, TYPES[format], new File(filename));
}
/**
* A demo application that shows simple ways of using the EasyBufferedImage class. Execute from the command line
* by typing
* <p><b><blockquote><pre>java EasyBufferedImage ImageFileName AlphaValue</pre></blockquote></b>
* where the <tt>AlphaValue</tt> is a percentage value in the range [0..100] and serves as a brightness control. Values in the range
* [0..1) will darken the image while values above 1 will brighten the input image. This application also saves the processed
* file in GIF format to a file named "Sample.gif".
* <b><font color="#115500"><blockquote><pre>
public static void main(String[] args) throws IOException {
EasyBufferedImage image = EasyBufferedImage.createImage(args[0]);
double alpha = Double.parseDouble(args[1]);
EasyBufferedImage copy = image.copy();
int[][] data = image.getPixels2D(EasyBufferedImage.RED);
for(int i=0; i < image.getHeight(); i++){
for(int j=0; j < image.getWidth(); j++){
data[i][j] = clamp(data[i][j] * alpha);
}
}
image.setPixels(data, EasyBufferedImage.RED);
data = image.getPixels2D(EasyBufferedImage.GREEN);
for(int i=0; i < image.getHeight(); i++){
for(int j=0; j < image.getWidth(); j++){
data[i][j] = clamp(data[i][j] * alpha);
}
}
image.setPixels(data, EasyBufferedImage.GREEN);
data = image.getPixels2D(EasyBufferedImage.BLUE);
for(int i=0; i < image.getHeight(); i++){
for(int j=0; j < image.getWidth(); j++){
data[i][j] = clamp(data[i][j] * alpha);
}
}
image.setPixels(data, EasyBufferedImage.BLUE);
image.show(args[0]);
data = copy.getPixels2D(EasyBufferedImage.GRAY);
for(int i=0; i < copy.getHeight(); i++){
for(int j=0; j < copy.getWidth(); j++){
data[i][j] = clamp(data[i][j] * alpha);
}
}
copy.setPixels(data, EasyBufferedImage.GRAY);
copy.show("GRAY SCALE PROCESSING");
image.save("Sample.gif", EasyBufferedImage.GIF);
}
</pre></blockquote></font></b>
* @param args is an array of two strings. The first is the filename of the file to process and the second is a perctage value to brighten/darken an image.
* @throws IOException.
*/
public static void main(String[] args) throws IOException {
EasyBufferedImage image = EasyBufferedImage.createImage(args[0]);
double alpha = Double.parseDouble(args[1]);
EasyBufferedImage copy = image.copy();
image.show("Original Image");
int[][] data = image.getPixels2D(EasyBufferedImage.RED);
for(int i=0; i<image.getHeight(); i++){
for(int j=0; j<image.getWidth(); j++){
data[i][j] = clamp(data[i][j] * alpha);
}
}
image.setPixels(data, EasyBufferedImage.RED);
data = image.getPixels2D(EasyBufferedImage.GREEN);
for(int i=0; i<image.getHeight(); i++){
for(int j=0; j<image.getWidth(); j++){
data[i][j] = clamp(data[i][j] * alpha);
}
}
image.setPixels(data, EasyBufferedImage.GREEN);
data = image.getPixels2D(EasyBufferedImage.BLUE);
for(int i=0; i<image.getHeight(); i++){
for(int j=0; j<image.getWidth(); j++){
data[i][j] = clamp(data[i][j] * alpha);
}
}
image.setPixels(data, EasyBufferedImage.BLUE);
image.show(args[0]);
data = copy.getPixels2D(EasyBufferedImage.GRAY);
for(int i=0; i<copy.getHeight(); i++){
for(int j=0; j<copy.getWidth(); j++){
data[i][j] = clamp(data[i][j] * alpha);
}
}
copy.setPixels(data, EasyBufferedImage.GRAY);
copy.show("Gray Scale Processing");
image.save("Sample.gif", EasyBufferedImage.GIF);
}
}