MediaSetNodeFrame.java
7.94 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
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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.catalog.util.localization.LocaleMap
* com.scene7.is.catalog.util.localization.LocalizedText
* com.scene7.is.provider.UserData
* com.scene7.is.provider.ZoomTarget
* com.scene7.is.provider.ZoomTargets
* com.scene7.is.provider.ZoomTargets$Builder
* com.scene7.is.sleng.HotSpot
* com.scene7.is.util.DigestAdler32
* com.scene7.is.util.RectInt
* com.scene7.is.util.SizeInt
* com.scene7.is.util.collections.CollectionUtil
* com.scene7.is.util.error.ApplicationException
* org.jetbrains.annotations.NotNull
*/
package com.scene7.is.ps.provider.fvctx;
import com.scene7.is.catalog.util.localization.LocaleMap;
import com.scene7.is.catalog.util.localization.LocalizedText;
import com.scene7.is.provider.UserData;
import com.scene7.is.provider.ZoomTarget;
import com.scene7.is.provider.ZoomTargets;
import com.scene7.is.ps.provider.IZoomException;
import com.scene7.is.ps.provider.ModifierSet;
import com.scene7.is.ps.provider.Request;
import com.scene7.is.ps.provider.defs.ModifierEnum;
import com.scene7.is.ps.provider.fvctx.FvctxImageProps;
import com.scene7.is.ps.provider.fvctx.FvctxNode;
import com.scene7.is.ps.provider.fvctx.FvctxNodeNull;
import com.scene7.is.ps.provider.fvctx.MediaSetMetaData;
import com.scene7.is.ps.provider.fvctx.MediaSetVideoProps;
import com.scene7.is.sleng.HotSpot;
import com.scene7.is.util.DigestAdler32;
import com.scene7.is.util.RectInt;
import com.scene7.is.util.SizeInt;
import com.scene7.is.util.collections.CollectionUtil;
import com.scene7.is.util.error.ApplicationException;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.util.List;
import java.util.zip.Adler32;
import org.jetbrains.annotations.NotNull;
class MediaSetNodeFrame
extends FvctxNodeNull {
private int frameImageWidth = 0;
private SizeInt size = SizeInt.zeroSizeInt();
private Adler32 frameDigest = DigestAdler32.createMessageDigest();
private MediaSetMetaData metaData = MediaSetMetaData.EMPTY_MEDIA_SET_META_DATA;
MediaSetNodeFrame(@NotNull FvctxNode next) {
super(next);
}
@Override
public void startFrame(@NotNull String netPath, @NotNull String query, @NotNull Request parsedRequest, @NotNull FvctxImageProps imageProps, boolean hasNestedFrame, boolean isMediaSetItem) throws ApplicationException {
this.frameDigest = DigestAdler32.createMessageDigest();
FvctxImageProps.updateImageDigest(this.frameDigest, imageProps);
this.size = imageProps.getSize();
this.frameImageWidth = this.size.width;
LocaleMap localeMap = parsedRequest.getCatalogValue(ModifierEnum.I_LOCALE_STR_MAP);
String locale = parsedRequest.getGlobalAttributes().getOrDie(ModifierEnum.LOCALE);
this.metaData = new MediaSetMetaData(imageProps.getTargets(), CollectionUtil.copy(imageProps.getMaps()), CollectionUtil.immutableListOf((Object[])new UserData[]{imageProps.getUserData()}), localeMap, locale);
this.getNext().startFrame(netPath, query, parsedRequest, imageProps, hasNestedFrame, isMediaSetItem);
}
@Override
public void endFrame(SizeInt size, @NotNull String imageVersion, @NotNull MediaSetMetaData metaData, boolean hasNestedFrame) throws IZoomException {
String iv = DigestAdler32.createSignature((long)this.frameDigest.getValue());
this.getNext().endFrame(this.size, iv, this.metaData, hasNestedFrame);
}
@Override
public void startVideoFrame(@NotNull String netPath, @NotNull String query, @NotNull MediaSetVideoProps videoProps) throws ApplicationException {
this.frameDigest = DigestAdler32.createMessageDigest();
MediaSetVideoProps.updateVideoDigest(this.frameDigest, videoProps);
this.size = SizeInt.zeroSizeInt();
this.frameImageWidth = this.size.width;
this.metaData = new MediaSetMetaData(MediaSetMetaData.EMPTY_TARGETS, MediaSetMetaData.EMPTY_MAPS, videoProps.getUserData(), videoProps.getLocaleMap(), videoProps.getLocale());
this.getNext().startVideoFrame(netPath, query, videoProps);
}
@Override
public void endVideoFrame(@NotNull MediaSetMetaData metaData, @NotNull String version, @NotNull String suffix) throws IZoomException {
String iv = DigestAdler32.createSignature((long)this.frameDigest.getValue());
this.getNext().endVideoFrame(this.metaData, iv, suffix);
}
@Override
public void startAnonymousFrame() throws IZoomException {
this.frameDigest = DigestAdler32.createMessageDigest();
this.size = SizeInt.zeroSizeInt();
this.frameImageWidth = this.size.width;
this.metaData = MediaSetMetaData.EMPTY_MEDIA_SET_META_DATA;
this.getNext().startAnonymousFrame();
}
@Override
public void image(@NotNull String netPath, @NotNull String query, @NotNull Request parsedRequest, @NotNull FvctxImageProps imageProps) throws ApplicationException {
int xOffset = this.size.width;
this.size = SizeInt.sizeInt((int)(xOffset + this.frameImageWidth), (int)this.size.height);
double xScaleFactor = (double)this.frameImageWidth / (double)imageProps.getSize().getWidth();
double yScaleFactor = (double)this.size.height / (double)imageProps.getSize().getHeight();
FvctxImageProps.updateImageDigest(this.frameDigest, imageProps);
ZoomTargets.Builder targetsModified = new ZoomTargets.Builder(this.metaData.getTargets());
MediaSetNodeFrame.translateAndScaleTargets(targetsModified, imageProps.getTargets(), xOffset, 0, xScaleFactor, yScaleFactor);
List<HotSpot> mapsModified = this.metaData.getMaps();
MediaSetNodeFrame.translateAndScaleMaps(mapsModified, imageProps.getMaps(), xOffset, 0.0, xScaleFactor, yScaleFactor);
List<UserData> userDataModified = this.metaData.getUserData();
userDataModified.add(imageProps.getUserData());
LocaleMap localeMap = parsedRequest.getCatalogValue(ModifierEnum.I_LOCALE_STR_MAP);
String locale = parsedRequest.getGlobalAttributes().getOrDie(ModifierEnum.LOCALE);
this.metaData = new MediaSetMetaData(targetsModified.getProduct(), mapsModified, userDataModified, localeMap, locale);
this.getNext().image(netPath, query, parsedRequest, imageProps);
}
@Override
public void swatch(@NotNull String netPath, @NotNull String query, @NotNull Request parsedRequest, @NotNull FvctxImageProps imageProps, boolean hasNestedFrame, boolean isMediaItemSwatch) throws ApplicationException {
FvctxImageProps.updateImageDigest(this.frameDigest, imageProps);
this.getNext().swatch(netPath, query, parsedRequest, imageProps, hasNestedFrame, isMediaItemSwatch);
}
private static void translateAndScaleTargets(@NotNull ZoomTargets.Builder dst, @NotNull ZoomTargets src1, int tx, int ty, double xScaleFactor, double yScaleFactor) {
ZoomTargets.Builder src = src1.removeEmptyTargets().getBuilder();
for (ZoomTarget t : src.targets) {
int scaledX = (int)Math.round((double)t.rect.x * xScaleFactor);
int scaledY = (int)Math.round((double)t.rect.y * yScaleFactor);
int scaledWidth = (int)Math.round((double)t.rect.width * xScaleFactor);
int scaledHeight = (int)Math.round((double)t.rect.height * yScaleFactor);
RectInt scaledRect = RectInt.rectInt((Rectangle)new Rectangle(scaledX, scaledY, scaledWidth, scaledHeight));
dst.add(new ZoomTarget(t.frame, scaledRect.translate(tx, ty), t.label, t.userData));
}
}
private static void translateAndScaleMaps(@NotNull List<HotSpot> dst, @NotNull List<HotSpot> src, double tx, double ty, double xScaleFactor, double yScaleFactor) {
AffineTransform scaleTranform = AffineTransform.getScaleInstance(xScaleFactor, yScaleFactor);
AffineTransform tm = AffineTransform.getTranslateInstance(tx, ty);
for (HotSpot h : src) {
HotSpot map = new HotSpot(h);
map.transform(scaleTranform);
map.transform(tm);
dst.add(map);
}
}
}