Skip to content

Commit 88b17c4

Browse files
committed
reworking of BufferedImage to allow mixed Graphics and Raster operations
1 parent c2d681d commit 88b17c4

39 files changed

+3641
-2922
lines changed

sources/net.sf.j2s.java.core/src/com/sun/imageio/plugins/common/ImageUtil.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
package com.sun.imageio.plugins.common;
2727

28-
import java.awt.Point;
2928
import java.awt.Rectangle;
3029
import java.awt.Transparency;
3130
import java.awt.color.ColorSpace;
@@ -46,12 +45,10 @@
4645
import java.awt.image.SampleModel;
4746
import java.awt.image.SinglePixelPackedSampleModel;
4847
import java.awt.image.WritableRaster;
49-
import java.util.Arrays;
5048

5149
//import javax.imageio.ImageTypeSpecifier;
5250

5351
import javax.imageio.IIOException;
54-
import javax.imageio.IIOImage;
5552
import javax.imageio.ImageTypeSpecifier;
5653
import javax.imageio.ImageWriter;
5754
import javax.imageio.spi.ImageWriterSpi;
@@ -1127,7 +1124,7 @@ public static final void canEncodeImage(ImageWriter writer,
11271124
public static final boolean imageIsContiguous(RenderedImage image) {
11281125
SampleModel sm;
11291126
if(image instanceof BufferedImage) {
1130-
WritableRaster ras = ((BufferedImage)image).秘getRaster();
1127+
WritableRaster ras = ((BufferedImage)image).getRaster();
11311128
sm = ras.getSampleModel();
11321129
} else {
11331130
sm = image.getSampleModel();

sources/net.sf.j2s.java.core/src/java/awt/image/AffineTransformOp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public final BufferedImage filter(BufferedImage src, BufferedImage dst) {
302302
Graphics2D g = origDst.createGraphics();
303303
try {
304304
g.setComposite(AlphaComposite.Src);
305-
((JSGraphics2D)(Object) g).drawImageFromRaster(dst, 0, 0, null);
305+
((JSGraphics2D)(Object) g).drawImageFromPixelsOrRaster(dst, 0, 0, null);
306306
} finally {
307307
g.dispose();
308308
}

sources/net.sf.j2s.java.core/src/java/awt/image/BandedSampleModel.java

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ public BandedSampleModel(int dataType,
130130
* @throws IllegalArgumentException if <code>dataType</code> is not
131131
* one of the supported data types
132132
*/
133-
public SampleModel createCompatibleSampleModel(int w, int h) {
133+
@Override
134+
public SampleModel createCompatibleSampleModel(int w, int h) {
134135
int[] bandOffs;
135136

136137
if (numBanks == 1) {
@@ -157,7 +158,8 @@ public SampleModel createCompatibleSampleModel(int w, int h) {
157158
* @throws IllegalArgumentException if <code>dataType</code> is not
158159
* one of the supported data types
159160
*/
160-
public SampleModel createSubsetSampleModel(int bands[]) {
161+
@Override
162+
public SampleModel createSubsetSampleModel(int bands[]) {
161163
if (bands.length > bankIndices.length)
162164
throw new RasterFormatException("There are only " +
163165
bankIndices.length +
@@ -182,7 +184,8 @@ public SampleModel createSubsetSampleModel(int bands[]) {
182184
* @throws IllegalArgumentException if <code>dataType</code> is not
183185
* one of the supported types.
184186
*/
185-
public DataBuffer createDataBuffer() {
187+
@Override
188+
public DataBuffer createDataBuffer() {
186189
DataBuffer dataBuffer = null;
187190

188191
int size = scanlineStride * height;
@@ -253,11 +256,15 @@ public DataBuffer createDataBuffer() {
253256
* @return the data for the specified pixel.
254257
* @see #setDataElements(int, int, Object, DataBuffer)
255258
*/
256-
public Object getDataElements(int x, int y, Object obj, DataBuffer data) {
259+
@Override
260+
public Object getDataElements(int x, int y, Object obj, DataBuffer data) {
257261
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
258262
throw new ArrayIndexOutOfBoundsException
259263
("Coordinate out of bounds!");
260264
}
265+
266+
data.秘setDoCheckImage(false);
267+
261268
int type = getTransferType();
262269
int numDataElems = getNumDataElements();
263270
int pixelOffset = y*scanlineStride + x;
@@ -355,6 +362,7 @@ public Object getDataElements(int x, int y, Object obj, DataBuffer data) {
355362
obj = (Object)ddata;
356363
break;
357364
}
365+
data.秘setDoCheckImage(true);
358366

359367
return obj;
360368
}
@@ -370,7 +378,8 @@ public Object getDataElements(int x, int y, Object obj, DataBuffer data) {
370378
* @return the samples for the specified pixel.
371379
* @see #setPixel(int, int, int[], DataBuffer)
372380
*/
373-
public int[] getPixel(int x, int y, int iArray[], DataBuffer data) {
381+
@Override
382+
public int[] getPixel(int x, int y, int iArray[], DataBuffer data) {
374383
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
375384
throw new ArrayIndexOutOfBoundsException
376385
("Coordinate out of bounds!");
@@ -406,7 +415,8 @@ public int[] getPixel(int x, int y, int iArray[], DataBuffer data) {
406415
* @return the samples for the pixels within the specified region.
407416
* @see #setPixels(int, int, int, int, int[], DataBuffer)
408417
*/
409-
public int[] getPixels(int x, int y, int w, int h,
418+
@Override
419+
public int[] getPixels(int x, int y, int w, int h,
410420
int iArray[], DataBuffer data) {
411421
int x1 = x + w;
412422
int y1 = y + h;
@@ -417,6 +427,9 @@ public int[] getPixels(int x, int y, int w, int h,
417427
throw new ArrayIndexOutOfBoundsException
418428
("Coordinate out of bounds!");
419429
}
430+
431+
data.秘setDoCheckImage(false);
432+
420433
int[] pixels;
421434

422435
if (iArray != null) {
@@ -439,6 +452,9 @@ public int[] getPixels(int x, int y, int w, int h,
439452
lineOffset += scanlineStride;
440453
}
441454
}
455+
456+
data.秘setDoCheckImage(true);
457+
442458
return pixels;
443459
}
444460

@@ -454,7 +470,8 @@ public int[] getPixels(int x, int y, int w, int h,
454470
* @return the sample in the specified band for the specified pixel.
455471
* @see #setSample(int, int, int, int, DataBuffer)
456472
*/
457-
public int getSample(int x, int y, int b, DataBuffer data) {
473+
@Override
474+
public int getSample(int x, int y, int b, DataBuffer data) {
458475
// Bounds check for 'b' will be performed automatically
459476
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
460477
throw new ArrayIndexOutOfBoundsException
@@ -478,7 +495,8 @@ public int getSample(int x, int y, int b, DataBuffer data) {
478495
* @return a float value that represents the sample in the specified
479496
* band for the specified pixel.
480497
*/
481-
public float getSampleFloat(int x, int y, int b, DataBuffer data) {
498+
@Override
499+
public float getSampleFloat(int x, int y, int b, DataBuffer data) {
482500
// Bounds check for 'b' will be performed automatically
483501
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
484502
throw new ArrayIndexOutOfBoundsException
@@ -502,7 +520,8 @@ public float getSampleFloat(int x, int y, int b, DataBuffer data) {
502520
* @return a double value that represents the sample in the specified
503521
* band for the specified pixel.
504522
*/
505-
public double getSampleDouble(int x, int y, int b, DataBuffer data) {
523+
@Override
524+
public double getSampleDouble(int x, int y, int b, DataBuffer data) {
506525
// Bounds check for 'b' will be performed automatically
507526
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
508527
throw new ArrayIndexOutOfBoundsException
@@ -530,13 +549,17 @@ public double getSampleDouble(int x, int y, int b, DataBuffer data) {
530549
* the specified region.
531550
* @see #setSamples(int, int, int, int, int, int[], DataBuffer)
532551
*/
533-
public int[] getSamples(int x, int y, int w, int h, int b,
552+
@Override
553+
public int[] getSamples(int x, int y, int w, int h, int b,
534554
int iArray[], DataBuffer data) {
535555
// Bounds check for 'b' will be performed automatically
536556
if ((x < 0) || (y < 0) || (x + w > width) || (y + h > height)) {
537557
throw new ArrayIndexOutOfBoundsException
538558
("Coordinate out of bounds!");
539559
}
560+
561+
data.秘setDoCheckImage(false);
562+
540563
int samples[];
541564
if (iArray != null) {
542565
samples = iArray;
@@ -555,6 +578,9 @@ public int[] getSamples(int x, int y, int w, int h, int b,
555578
}
556579
lineOffset += scanlineStride;
557580
}
581+
582+
data.秘setDoCheckImage(true);
583+
558584
return samples;
559585
}
560586

@@ -593,11 +619,15 @@ public int[] getSamples(int x, int y, int w, int h, int b,
593619
* @param data The DataBuffer containing the image data
594620
* @see #getDataElements(int, int, Object, DataBuffer)
595621
*/
596-
public void setDataElements(int x, int y, Object obj, DataBuffer data) {
622+
@Override
623+
public void setDataElements(int x, int y, Object obj, DataBuffer data) {
597624
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
598625
throw new ArrayIndexOutOfBoundsException
599626
("Coordinate out of bounds!");
600627
}
628+
629+
data.秘setDoCheckImage(false);
630+
601631
int type = getTransferType();
602632
int numDataElems = getNumDataElements();
603633
int pixelOffset = y*scanlineStride + x;
@@ -656,6 +686,8 @@ public void setDataElements(int x, int y, Object obj, DataBuffer data) {
656686
break;
657687

658688
}
689+
data.秘setDoCheckImage(true);
690+
659691
}
660692

661693
/**
@@ -668,7 +700,8 @@ public void setDataElements(int x, int y, Object obj, DataBuffer data) {
668700
* @param data The DataBuffer containing the image data
669701
* @see #getPixel(int, int, int[], DataBuffer)
670702
*/
671-
public void setPixel(int x, int y, int iArray[], DataBuffer data) {
703+
@Override
704+
public void setPixel(int x, int y, int iArray[], DataBuffer data) {
672705
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
673706
throw new ArrayIndexOutOfBoundsException
674707
("Coordinate out of bounds!");
@@ -693,7 +726,8 @@ public void setPixel(int x, int y, int iArray[], DataBuffer data) {
693726
* @param data The DataBuffer containing the image data
694727
* @see #getPixels(int, int, int, int, int[], DataBuffer)
695728
*/
696-
public void setPixels(int x, int y, int w, int h,
729+
@Override
730+
public void setPixels(int x, int y, int w, int h,
697731
int iArray[], DataBuffer data) {
698732
int x1 = x + w;
699733
int y1 = y + h;
@@ -704,6 +738,9 @@ public void setPixels(int x, int y, int w, int h,
704738
throw new ArrayIndexOutOfBoundsException
705739
("Coordinate out of bounds!");
706740
}
741+
742+
data.秘setDoCheckImage(false);
743+
707744

708745
for (int k = 0; k < numBands; k++) {
709746
int lineOffset = y*scanlineStride + x + bandOffsets[k];
@@ -719,6 +756,7 @@ public void setPixels(int x, int y, int w, int h,
719756
lineOffset += scanlineStride;
720757
}
721758
}
759+
data.秘setDoCheckImage(true);
722760
}
723761

724762
/**
@@ -733,7 +771,8 @@ public void setPixels(int x, int y, int w, int h,
733771
* @param data The DataBuffer containing the image data
734772
* @see #getSample(int, int, int, DataBuffer)
735773
*/
736-
public void setSample(int x, int y, int b, int s,
774+
@Override
775+
public void setSample(int x, int y, int b, int s,
737776
DataBuffer data) {
738777
// Bounds check for 'b' will be performed automatically
739778
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) {
@@ -756,7 +795,8 @@ public void setSample(int x, int y, int b, int s,
756795
* @param data The DataBuffer containing the image data
757796
* @see #getSample(int, int, int, DataBuffer)
758797
*/
759-
public void setSample(int x, int y, int b,
798+
@Override
799+
public void setSample(int x, int y, int b,
760800
float s ,
761801
DataBuffer data) {
762802
// Bounds check for 'b' will be performed automatically
@@ -780,7 +820,8 @@ public void setSample(int x, int y, int b,
780820
* @param data The DataBuffer containing the image data
781821
* @see #getSample(int, int, int, DataBuffer)
782822
*/
783-
public void setSample(int x, int y, int b,
823+
@Override
824+
public void setSample(int x, int y, int b,
784825
double s,
785826
DataBuffer data) {
786827
// Bounds check for 'b' will be performed automatically
@@ -806,13 +847,17 @@ public void setSample(int x, int y, int b,
806847
* @param data The DataBuffer containing the image data
807848
* @see #getSamples(int, int, int, int, int, int[], DataBuffer)
808849
*/
809-
public void setSamples(int x, int y, int w, int h, int b,
850+
@Override
851+
public void setSamples(int x, int y, int w, int h, int b,
810852
int iArray[], DataBuffer data) {
811853
// Bounds check for 'b' will be performed automatically
812854
if ((x < 0) || (y < 0) || (x + w > width) || (y + h > height)) {
813855
throw new ArrayIndexOutOfBoundsException
814856
("Coordinate out of bounds!");
815857
}
858+
859+
data.秘setDoCheckImage(false);
860+
816861
int lineOffset = y*scanlineStride + x + bandOffsets[b];
817862
int srcOffset = 0;
818863
int bank = bankIndices[b];
@@ -824,6 +869,7 @@ public void setSamples(int x, int y, int w, int h, int b,
824869
}
825870
lineOffset += scanlineStride;
826871
}
872+
data.秘setDoCheckImage(true);
827873
}
828874

829875
private static int[] createOffsetArray(int numBands) {
@@ -843,7 +889,8 @@ private static int[] createIndicesArray(int numBands) {
843889
}
844890

845891
// Differentiate hash code from other ComponentSampleModel subclasses
846-
public int hashCode() {
892+
@Override
893+
public int hashCode() {
847894
return super.hashCode() ^ 0x2;
848895
}
849896
}

0 commit comments

Comments
 (0)