Commit bebbb0fd by xmh

添加关于整个合成图的字母

重构坐标计算方式
1 parent 8033818e
...@@ -25,6 +25,7 @@ public enum Dict { ...@@ -25,6 +25,7 @@ public enum Dict {
picType.put(6, "车牌特写"); picType.put(6, "车牌特写");
picType.put(7, "车标特写"); picType.put(7, "车标特写");
picType.put(8, "人脸特写"); picType.put(8, "人脸特写");
picType.put(9, "合成图");
captionType.put(1, "抓拍时间"); captionType.put(1, "抓拍时间");
captionType.put(2, "地点名称"); captionType.put(2, "地点名称");
......
...@@ -253,6 +253,65 @@ public class Generator { ...@@ -253,6 +253,65 @@ public class Generator {
} }
} }
// 整张合成图的字幕处理
CaptionNode mainCaptionNode = picConfigGenerator.getMainCaptionNode();
for (int j = 0; j < 4; j++) {
CaptionVo caption;
String content;
String height;
if (j == 0 && mainCaptionNode.getTop() != null) {
caption = mainCaptionNode.getTop();
content = mainCaptionNode.getTopContent();
height = String.valueOf(mainCaptionNode.getTopHeight());
} else if (j == 1 && mainCaptionNode.getBottom() != null) {
caption = mainCaptionNode.getBottom();
content = mainCaptionNode.getBottomContent();
height = String.valueOf(mainCaptionNode.getBottomHeight());
} else if (j == 2 && mainCaptionNode.getSecond() != null) {
caption = mainCaptionNode.getSecond();
content = mainCaptionNode.getSecondContent();
height = String.valueOf(mainCaptionNode.getSecondHeight());
} else if (j == 3 && mainCaptionNode.getThird() != null) {
caption = mainCaptionNode.getThird();
content = mainCaptionNode.getThirdContent();
height = String.valueOf(mainCaptionNode.getThirdHeight());
} else {
continue;
}
captionCount++;
Element ele = XmlUtil.appendChild(captionsElement, "Caption" + captionCount);
XmlUtil.appendChild(ele, "Content").setTextContent(content);
XmlUtil.appendChild(ele, "bgColor").setTextContent(caption.getBgColor().toString());
XmlUtil.appendChild(ele, "Font").setTextContent(caption.getFont().toString());
XmlUtil.appendChild(ele, "FontSize").setTextContent(caption.getFontSize().toString());
XmlUtil.appendChild(ele, "fgColor").setTextContent(caption.getFgColor().toString());
XmlUtil.appendChild(ele, "ShadowColor").setTextContent("4");
XmlUtil.appendChild(ele, "ShadowSize").setTextContent("0");
XmlUtil.appendChild(ele, "bgTransparency").setTextContent(caption.getBgTransparency().toString());
Element coordinateElement = XmlUtil.appendChild(ele, "Coordinate");
// 坐标需要根据 positionType 来算
Integer positionType = caption.getPositionType();
String y;
if (positionType == 0) {
y = "0";
} else if (positionType == 1) {
PicNode lastNode = picNodes[picNodes.length - 1];
y = lastNode.getY() + "+全景1高+" + lastNode.getMaxBottomCaptionHeight();
} else if (positionType == 2) {
y = picNodes[0].getY();
} else if (positionType == 3) {
PicNode lastNode = picNodes[picNodes.length - 1];
y = lastNode.getY() + "+全景1高-" + height;
} else {
throw new IllegalArgumentException(positionType + "");
}
XmlUtil.appendChild(coordinateElement, "left").setTextContent("0");
XmlUtil.appendChild(coordinateElement, "top").setTextContent(y);
XmlUtil.appendChild(coordinateElement, "width").setTextContent(picConfigGenerator.getLayoutType() / 10 + "*全景1宽");
XmlUtil.appendChild(coordinateElement, "height").setTextContent(height);
}
XmlUtil.appendChild(captionsElement, "Count").setTextContent(String.valueOf(captionCount)); XmlUtil.appendChild(captionsElement, "Count").setTextContent(String.valueOf(captionCount));
return configNode; return configNode;
} }
...@@ -299,43 +358,22 @@ public class Generator { ...@@ -299,43 +358,22 @@ public class Generator {
if (this.x != null) { if (this.x != null) {
return this.x; return this.x;
} }
this.x = "0";
PicNode left = getLeft(); PicNode left = getLeft();
if (index != 0) { int colIndex = index % (generator.getLayoutType() / 10);
switch (generator.getLayoutType()) { switch (colIndex) {
case 21: case 0:
case 31:
case 41:
case 51:
case 61:
this.x = left.x + "+" + "全景1宽";
break;
case 12:
case 13:
case 14:
case 15:
case 16:
this.x = "0";
break;
case 22:
case 23:
if (index % 2 == 0) {
this.x = "0"; this.x = "0";
} else {
this.x = "全景1宽";
}
break; break;
case 32: case 1:
if (index % 3 == 0) { case 2:
this.x = "0"; case 3:
} else { case 4:
this.x = left.getX() + "+" + "全景1宽"; case 5:
} this.x = "0".equals(left.x) ? "全景1宽" : left.x + "+" + "全景1宽";
break; break;
default: default:
throw new RuntimeException("no such type"); throw new RuntimeException("no such type");
} }
}
return this.x; return this.x;
} }
...@@ -347,41 +385,20 @@ public class Generator { ...@@ -347,41 +385,20 @@ public class Generator {
return this.y; return this.y;
} }
PicNode upside = this.getUpside(); PicNode upside = this.getUpside();
String mainPaddingTop = generator.paddingTop();
String paddingTop = paddingTop(); String paddingTop = paddingTop();
switch (generator.getLayoutType()) {
case 11: int rowIndex = index / (generator.getLayoutType() / 10);
case 21: switch (rowIndex) {
case 31: case 0:
case 41: this.y = paddingTop + "+" + mainPaddingTop;
case 51:
case 61:
this.y = paddingTop;
break;
case 12:
case 13:
case 14:
case 15:
case 16:
if (index == 0) {
this.y = paddingTop;
} else {
this.y = upside.y + "+" + "全景1高" + "+" + paddingTop;
}
break; break;
case 22: case 1:
case 23: case 2:
if (index < 2) { case 3:
this.y = paddingTop; case 4:
} else { case 5:
this.y = upside.y + "+" + "全景1高" + "+" + paddingTop; this.y = upside.y + "+" + "全景1高" + "+" + paddingTop;
}
break;
case 32:
if (index < 3) {
this.y = paddingTop;
} else {
this.y = upside.y + "+" + "全景1高" + "+" + paddingTop;
}
break; break;
default: default:
throw new RuntimeException("no such type"); throw new RuntimeException("no such type");
...@@ -401,36 +418,18 @@ public class Generator { ...@@ -401,36 +418,18 @@ public class Generator {
* D,E,F 的 paddingTop = {@code max(A外下字幕高度 + D外上字幕高度, B外下字幕高度 + E外上字幕高度, C外下字幕高度 + F外上字幕高度)} * D,E,F 的 paddingTop = {@code max(A外下字幕高度 + D外上字幕高度, B外下字幕高度 + E外上字幕高度, C外下字幕高度 + F外上字幕高度)}
*/ */
private String paddingTop() { private String paddingTop() {
PicNode node = this; PicNode upside = getUpside();
int maxPaddingTop = Integer.MIN_VALUE; String a = Optional.ofNullable(upside).map(PicNode::getMaxBottomCaptionHeight).orElse("0");
while (node != null) { String b = getMaxTopCaptionHeight();
PicNode upside = node.getUpside(); return a + "+" + b;
int bottomHeight = Optional.ofNullable(upside).map(x -> x.captionNode).map(CaptionNode::getBottomHeight).orElse(0);
int topHeight = node.getCaptionNode().getTopHeight() == null ? 0 : node.getCaptionNode().getTopHeight();
maxPaddingTop = Math.max(maxPaddingTop, bottomHeight + topHeight);
node = node.getLeft();
}
node = this;
while (node != null) {
PicNode upside = node.getUpside();
int bottomHeight = Optional.ofNullable(upside).map(x -> x.captionNode).map(CaptionNode::getBottomHeight).orElse(0);
int topHeight = node.getCaptionNode().getTopHeight() == null ? 0 : node.getCaptionNode().getTopHeight();
maxPaddingTop = Math.max(maxPaddingTop, bottomHeight + topHeight);
node = node.getRight();
}
return String.valueOf(maxPaddingTop);
} }
private String getMaxTopCaptionHeight() { private String getMaxTopCaptionHeight() {
PicNode node = this; PicNode node = this;
int maxTop = Integer.MIN_VALUE; int maxTop = Integer.MIN_VALUE;
while (node != null) { while (node.getLeft() != null) {
int topHeight = node.getCaptionNode().getTopHeight() == null ? 0 : node.getCaptionNode().getTopHeight();
maxTop = Math.max(maxTop, topHeight);
node = node.getLeft(); node = node.getLeft();
} }
node = this;
while (node != null) { while (node != null) {
int topHeight = node.getCaptionNode().getTopHeight() == null ? 0 : node.getCaptionNode().getTopHeight(); int topHeight = node.getCaptionNode().getTopHeight() == null ? 0 : node.getCaptionNode().getTopHeight();
maxTop = Math.max(maxTop, topHeight); maxTop = Math.max(maxTop, topHeight);
...@@ -442,12 +441,9 @@ public class Generator { ...@@ -442,12 +441,9 @@ public class Generator {
private String getMaxBottomCaptionHeight() { private String getMaxBottomCaptionHeight() {
PicNode node = this; PicNode node = this;
int maxBottom = Integer.MIN_VALUE; int maxBottom = Integer.MIN_VALUE;
while (node != null) { while (node.getLeft() != null) {
int bottomHeight = node.getCaptionNode().getBottomHeight() == null ? 0 : node.getCaptionNode().getBottomHeight();
maxBottom = Math.max(maxBottom, bottomHeight);
node = node.getLeft(); node = node.getLeft();
} }
node = this;
while (node != null) { while (node != null) {
int bottomHeight = node.getCaptionNode().getBottomHeight() == null ? 0 : node.getCaptionNode().getBottomHeight(); int bottomHeight = node.getCaptionNode().getBottomHeight() == null ? 0 : node.getCaptionNode().getBottomHeight();
maxBottom = Math.max(maxBottom, bottomHeight); maxBottom = Math.max(maxBottom, bottomHeight);
...@@ -460,112 +456,37 @@ public class Generator { ...@@ -460,112 +456,37 @@ public class Generator {
* 获取一个图片节点的左侧图片节点 * 获取一个图片节点的左侧图片节点
*/ */
public PicNode getLeft() { public PicNode getLeft() {
if (index == 0) { int colIndex = index % (generator.getLayoutType() / 10);
return null; if (colIndex == 0) {
}
switch (generator.getLayoutType()) {
case 21:
case 31:
case 41:
case 51:
case 61:
return generator.getPicNodes()[index - 1];
case 22:
case 23:
if (index % 2 == 0) {
return null; return null;
} else { } else {
return generator.picNodes[index - 1]; return generator.picNodes[index - 1];
} }
case 32:
if (index % 3 == 0) {
return null;
} else {
return generator.picNodes[index - 1];
}
case 12:
case 13:
case 14:
case 15:
case 16:
default:
return null;
}
} }
/** /**
* 获取一个图片节点的右侧图片节点 * 获取一个图片节点的右侧图片节点
*/ */
public PicNode getRight() { public PicNode getRight() {
if (index == generator.picNodes.length - 1) { int colIndex = index % (generator.getLayoutType() / 10);
return null; int maxColIndex = generator.getLayoutType() / 10 - 1;
} if (colIndex == maxColIndex) {
switch (generator.getLayoutType()) {
case 21:
case 31:
case 41:
case 51:
case 61:
return generator.getPicNodes()[index + 1];
case 22:
case 23:
if (index % 2 == 1) {
return null; return null;
} else { } else {
return generator.picNodes[index + 1]; return generator.picNodes[index + 1];
} }
case 32:
if (index % 3 == 2) {
return null;
} else {
return generator.picNodes[index + 1];
}
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
default:
return null;
}
} }
/** /**
* 获取一个图片节点的上层图片节点 * 获取一个图片节点的上层图片节点
*/ */
public PicNode getUpside() { public PicNode getUpside() {
if (index == 0) { int colNum = generator.getLayoutType() / 10;
return null; int rowIndex = index / (colNum);
} if (rowIndex == 0) {
switch (generator.getLayoutType()) {
case 12:
case 13:
case 14:
case 15:
case 16:
return generator.picNodes[index - 1];
case 22:
case 23:
if (index < 2) {
return null; return null;
} else { } else {
return generator.picNodes[index - 2]; return generator.picNodes[index - colNum];
}
case 32:
if (index < 3) {
return null;
} else {
return generator.picNodes[index - 3];
}
case 11:
case 21:
case 31:
case 41:
case 51:
case 61:
default:
return null;
} }
} }
} }
...@@ -579,6 +500,8 @@ public class Generator { ...@@ -579,6 +500,8 @@ public class Generator {
@Accessors(chain = true) @Accessors(chain = true)
static class PicConfigGenerator { static class PicConfigGenerator {
private final CaptionNode mainCaptionNode = new CaptionNode();
private final PicNode[] picNodes; private final PicNode[] picNodes;
/** 图片排列方式类型 */ /** 图片排列方式类型 */
private final int layoutType; private final int layoutType;
...@@ -597,6 +520,10 @@ public class Generator { ...@@ -597,6 +520,10 @@ public class Generator {
} }
for (CaptionVo captionVo : captionVos) { for (CaptionVo captionVo : captionVos) {
// 9 代表合成图
if (captionVo.getPicType() == 9) {
mainCaptionNode.add(captionVo);
} else {
for (PicNode picNode : picNodes) { for (PicNode picNode : picNodes) {
if (picNode.getPicType() == captionVo.getPicType()) { if (picNode.getPicType() == captionVo.getPicType()) {
picNode.getCaptionNode().add(captionVo); picNode.getCaptionNode().add(captionVo);
...@@ -606,6 +533,15 @@ public class Generator { ...@@ -606,6 +533,15 @@ public class Generator {
} }
} }
public String paddingTop() {
if (mainCaptionNode.getTopHeight() == null) {
return "0";
} else {
return String.valueOf(mainCaptionNode.getTopHeight());
}
}
}
/** /**
* 字幕节点 * 字幕节点
* 每个图片节点对应一个字幕节点 * 每个图片节点对应一个字幕节点
...@@ -695,7 +631,9 @@ public class Generator { ...@@ -695,7 +631,9 @@ public class Generator {
int wrapCount = 0; int wrapCount = 0;
for (Context context : contexts) { for (Context context : contexts) {
Integer type = context.getType(); Integer type = context.getType();
if (type != 16) {
sb.append(Dict.INSTANCE.captionType.get(type)).append(":+"); sb.append(Dict.INSTANCE.captionType.get(type)).append(":+");
}
switch (type) { switch (type) {
case 1: case 1:
if (picTypeName.contains("特写")) { if (picTypeName.contains("特写")) {
......
...@@ -11,9 +11,9 @@ spring: ...@@ -11,9 +11,9 @@ spring:
# 服务发现配置 # 服务发现配置
discovery: discovery:
# 启用服务发现 # 启用服务发现
enabled: false enabled: true
# 启用服务注册 # 启用服务注册
register: false register: true
# 服务停止时取消注册 # 服务停止时取消注册
deregister: true deregister: true
# 表示注册时使用IP而不是hostname # 表示注册时使用IP而不是hostname
...@@ -28,7 +28,7 @@ spring: ...@@ -28,7 +28,7 @@ spring:
instance-id: ${spring.application.name}:${spring.cloud.consul.discovery.ip-address}:${server.port} instance-id: ${spring.application.name}:${spring.cloud.consul.discovery.ip-address}:${server.port}
ip-address: 192.168.9.146 ip-address: 192.168.9.146
datasource: datasource:
url: jdbc:h2:tcp://localhost:9092/F:\\myIDEAworkspace\\繁星\\storage-config\\h2\\storeConfig url: jdbc:h2:file:F:\\myIDEAworkspace\\繁星\\storage-config\\h2\\storeConfig
username: root username: root
password: vion password: vion
schema: classpath:db/init.sql schema: classpath:db/init.sql
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!