GfxHelper.java
2.52 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.image.Layer
* javax.jcr.RepositoryException
*/
package com.day.crx.packaging.gfx;
import com.day.crx.packaging.gfx.DownloadResource;
import com.day.crx.packaging.gfx.ImageHelper;
import com.day.crx.packaging.gfx.ImageResource;
import com.day.image.Layer;
import java.awt.Color;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import javax.jcr.RepositoryException;
public class GfxHelper {
static final String GFX_MASK_ALPHA_PATH = "com/day/crx/packaging/mask.gif";
static final String GFX_MASK_GLARE_PATH = "com/day/crx/packaging/mask.png";
public static Layer stampThumbnail(ImageResource image) throws IOException, RepositoryException {
if (!image.hasContent()) {
return null;
}
Layer layer = image.getLayer(false, false, false);
image.crop(layer);
int w = layer.getWidth();
int h = layer.getHeight();
if (h < w) {
image.set("height", "64");
} else {
image.set("width", "64");
}
image.resize(layer);
layer.crop((Rectangle2D)new Rectangle(0, 0, 64, 64));
image.rotate(layer);
Layer alpha = ImageHelper.createLayer(DownloadResource.class.getClassLoader(), "com/day/crx/packaging/mask.gif");
Layer alpha2 = new Layer(layer.getWidth(), layer.getHeight(), (Paint)Color.WHITE);
alpha2.copyChannel(layer, 3, 0);
alpha2.copyChannel(alpha, 0, 3);
alpha2.flatten(Color.BLACK);
layer.copyChannel(alpha2, 0, 3);
Layer mask = ImageHelper.createLayer(DownloadResource.class.getClassLoader(), "com/day/crx/packaging/mask.png");
layer.merge(mask);
return layer;
}
public static Layer stampScreenshot(ImageResource image) throws IOException, RepositoryException {
return GfxHelper.stampScreenshot(image, false);
}
public static Layer stampScreenshot(ImageResource image, boolean notNull) throws IOException, RepositoryException {
if (!image.hasContent()) {
return null;
}
Layer layer = image.getLayer(false, false, false);
boolean modified = false;
if (layer != null) {
modified = image.crop(layer) != null;
modified |= image.resize(layer) != null;
modified |= image.rotate(layer) != null;
}
if (modified || notNull) {
return layer;
}
return null;
}
}