AbstractBufferedImageOp.java
3.71 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
/*
* Decompiled with CFR 0_118.
*/
package com.day.image;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.color.ColorSpace;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ColorConvertOp;
import java.awt.image.ColorModel;
import java.awt.image.ImageObserver;
import java.awt.image.IndexColorModel;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.util.Hashtable;
import java.util.Map;
public abstract class AbstractBufferedImageOp
implements BufferedImageOp {
protected final RenderingHints hints;
protected AbstractBufferedImageOp(RenderingHints hints) {
this.hints = hints == null ? null : new RenderingHints(hints);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
if (src == null) {
throw new NullPointerException("src image is null");
}
if (src == dst) {
throw new IllegalArgumentException("src image cannot be the same as the dst image");
}
boolean needToConvert = false;
ColorModel srcCM = src.getColorModel();
BufferedImage origDst = dst;
if (srcCM instanceof IndexColorModel) {
IndexColorModel icm = (IndexColorModel)srcCM;
src = icm.convertToIntDiscrete(src.getRaster(), true);
srcCM = src.getColorModel();
}
if (dst == null) {
dst = this.createCompatibleDestImage(src, null);
ColorModel dstCM = srcCM;
origDst = dst;
} else {
ColorModel dstCM = dst.getColorModel();
if (srcCM.getColorSpace().getType() != dstCM.getColorSpace().getType()) {
needToConvert = true;
dst = this.createCompatibleDestImage(src, null);
dstCM = dst.getColorModel();
} else if (dstCM instanceof IndexColorModel) {
dst = this.createCompatibleDestImage(src, null);
dstCM = dst.getColorModel();
}
}
this.doFilter(src, dst);
if (needToConvert) {
ColorConvertOp ccop = new ColorConvertOp(this.hints);
ccop.filter(dst, origDst);
} else if (origDst != dst) {
Graphics2D g = origDst.createGraphics();
try {
g.drawImage(dst, 0, 0, null);
}
finally {
g.dispose();
}
}
return origDst;
}
public Rectangle2D getBounds2D(BufferedImage src) {
return src.getRaster().getBounds();
}
public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel destCM) {
Rectangle2D bounds = this.getBounds2D(src);
int w = (int)bounds.getWidth();
int h = (int)bounds.getHeight();
if (destCM == null && (destCM = src.getColorModel()) instanceof IndexColorModel) {
destCM = ColorModel.getRGBdefault();
}
BufferedImage image = new BufferedImage(destCM, destCM.createCompatibleWritableRaster(w, h), destCM.isAlphaPremultiplied(), null);
return image;
}
public Point2D getPoint2D(Point2D srcPt, Point2D dstPt) {
if (dstPt == null) {
dstPt = (Point2D)srcPt.clone();
} else {
dstPt.setLocation(srcPt);
}
return dstPt;
}
public final RenderingHints getRenderingHints() {
return this.hints == null ? null : new RenderingHints(this.hints);
}
protected abstract void doFilter(BufferedImage var1, BufferedImage var2);
}