StampOp.java
3.41 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
/*
* Decompiled with CFR 0_118.
*/
package com.day.image;
import com.day.image.AbstractBufferedImageOp;
import com.day.image.ResizeOp;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
public class StampOp
extends AbstractBufferedImageOp {
private BufferedImage stamp;
private volatile BufferedImage stampCache;
private Rectangle2D stampPosition = new Rectangle2D.Double(0.0, 0.0, 15.0, 15.0);
private Composite stampComposite = AlphaComposite.Src;
public StampOp(RenderingHints hints) {
super(hints);
}
public StampOp() {
super(null);
}
public void setStamp(BufferedImage stamp) {
this.stamp = stamp;
this.stampCache = null;
}
public BufferedImage getStamp() {
return this.stamp;
}
public void setStampLocation(int x, int y) {
this.stampPosition.setRect(x, y, this.stampPosition.getWidth(), this.stampPosition.getHeight());
}
public void setStampSize(int width, int height) {
this.stampPosition.setRect(this.stampPosition.getX(), this.stampPosition.getY(), width, height);
this.stampCache = null;
}
public Rectangle2D getStampPosition() {
return this.stampPosition;
}
public void setStampComposite(Composite stampComposite) {
if (stampComposite != null) {
this.stampComposite = stampComposite;
}
}
public Composite getStampComposite() {
return this.stampComposite;
}
public BufferedImage filter(BufferedImage src, BufferedImage dst) {
if (src == dst && src != null) {
this.doFilter(src, dst);
return dst;
}
return super.filter(src, dst);
}
protected void doFilter(BufferedImage src, BufferedImage dst) {
Graphics2D gDst = dst.createGraphics();
if (src.getHeight() != dst.getHeight() || src.getWidth() != dst.getWidth()) {
ResizeOp sizer = new ResizeOp(dst.getWidth() / src.getWidth(), dst.getHeight() / src.getHeight(), this.getRenderingHints());
sizer.filter(src, dst);
} else if (src != dst) {
gDst.drawRenderedImage(src, new AffineTransform());
}
BufferedImage stamp = this.getSizedStamp();
if (stamp != null) {
Composite oldComposite = gDst.getComposite();
gDst.setComposite(this.getStampComposite());
gDst.drawImage(stamp, (int)this.getStampPosition().getX(), (int)this.getStampPosition().getY(), null);
gDst.setComposite(oldComposite);
}
}
private BufferedImage getSizedStamp() {
BufferedImage stamp;
if (this.stampCache == null && (stamp = this.getStamp()) != null) {
Rectangle2D stampPosition = this.getStampPosition();
double stampWidth = stamp.getWidth();
double stampHeight = stamp.getHeight();
if (stampPosition.getWidth() == stampWidth && stampPosition.getHeight() == stampHeight) {
this.stampCache = stamp;
} else {
double scaleX = stampPosition.getWidth() / stampWidth;
double scaleY = stampPosition.getHeight() / stampHeight;
ResizeOp stampSizer = new ResizeOp(scaleX, scaleY, this.getRenderingHints());
this.stampCache = stampSizer.filter(stamp, null);
}
}
return this.stampCache;
}
}