Commit bebbb0fd by xmh

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

重构坐标计算方式
1 parent 8033818e
......@@ -25,6 +25,7 @@ public enum Dict {
picType.put(6, "车牌特写");
picType.put(7, "车标特写");
picType.put(8, "人脸特写");
picType.put(9, "合成图");
captionType.put(1, "抓拍时间");
captionType.put(2, "地点名称");
......
......@@ -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));
return configNode;
}
......@@ -299,43 +358,22 @@ public class Generator {
if (this.x != null) {
return this.x;
}
this.x = "0";
PicNode left = getLeft();
if (index != 0) {
switch (generator.getLayoutType()) {
case 21:
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) {
int colIndex = index % (generator.getLayoutType() / 10);
switch (colIndex) {
case 0:
this.x = "0";
} else {
this.x = "全景1宽";
}
break;
case 32:
if (index % 3 == 0) {
this.x = "0";
} else {
this.x = left.getX() + "+" + "全景1宽";
}
case 1:
case 2:
case 3:
case 4:
case 5:
this.x = "0".equals(left.x) ? "全景1宽" : left.x + "+" + "全景1宽";
break;
default:
throw new RuntimeException("no such type");
}
}
return this.x;
}
......@@ -347,41 +385,20 @@ public class Generator {
return this.y;
}
PicNode upside = this.getUpside();
String mainPaddingTop = generator.paddingTop();
String paddingTop = paddingTop();
switch (generator.getLayoutType()) {
case 11:
case 21:
case 31:
case 41:
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;
}
int rowIndex = index / (generator.getLayoutType() / 10);
switch (rowIndex) {
case 0:
this.y = paddingTop + "+" + mainPaddingTop;
break;
case 22:
case 23:
if (index < 2) {
this.y = paddingTop;
} else {
case 1:
case 2:
case 3:
case 4:
case 5:
this.y = upside.y + "+" + "全景1高" + "+" + paddingTop;
}
break;
case 32:
if (index < 3) {
this.y = paddingTop;
} else {
this.y = upside.y + "+" + "全景1高" + "+" + paddingTop;
}
break;
default:
throw new RuntimeException("no such type");
......@@ -401,36 +418,18 @@ public class Generator {
* D,E,F 的 paddingTop = {@code max(A外下字幕高度 + D外上字幕高度, B外下字幕高度 + E外上字幕高度, C外下字幕高度 + F外上字幕高度)}
*/
private String paddingTop() {
PicNode node = this;
int maxPaddingTop = Integer.MIN_VALUE;
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.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);
PicNode upside = getUpside();
String a = Optional.ofNullable(upside).map(PicNode::getMaxBottomCaptionHeight).orElse("0");
String b = getMaxTopCaptionHeight();
return a + "+" + b;
}
private String getMaxTopCaptionHeight() {
PicNode node = this;
int maxTop = Integer.MIN_VALUE;
while (node != null) {
int topHeight = node.getCaptionNode().getTopHeight() == null ? 0 : node.getCaptionNode().getTopHeight();
maxTop = Math.max(maxTop, topHeight);
while (node.getLeft() != null) {
node = node.getLeft();
}
node = this;
while (node != null) {
int topHeight = node.getCaptionNode().getTopHeight() == null ? 0 : node.getCaptionNode().getTopHeight();
maxTop = Math.max(maxTop, topHeight);
......@@ -442,12 +441,9 @@ public class Generator {
private String getMaxBottomCaptionHeight() {
PicNode node = this;
int maxBottom = Integer.MIN_VALUE;
while (node != null) {
int bottomHeight = node.getCaptionNode().getBottomHeight() == null ? 0 : node.getCaptionNode().getBottomHeight();
maxBottom = Math.max(maxBottom, bottomHeight);
while (node.getLeft() != null) {
node = node.getLeft();
}
node = this;
while (node != null) {
int bottomHeight = node.getCaptionNode().getBottomHeight() == null ? 0 : node.getCaptionNode().getBottomHeight();
maxBottom = Math.max(maxBottom, bottomHeight);
......@@ -460,112 +456,37 @@ public class Generator {
* 获取一个图片节点的左侧图片节点
*/
public PicNode getLeft() {
if (index == 0) {
return null;
}
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) {
int colIndex = index % (generator.getLayoutType() / 10);
if (colIndex == 0) {
return null;
} else {
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() {
if (index == generator.picNodes.length - 1) {
return null;
}
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) {
int colIndex = index % (generator.getLayoutType() / 10);
int maxColIndex = generator.getLayoutType() / 10 - 1;
if (colIndex == maxColIndex) {
return null;
} else {
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() {
if (index == 0) {
return null;
}
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) {
int colNum = generator.getLayoutType() / 10;
int rowIndex = index / (colNum);
if (rowIndex == 0) {
return null;
} else {
return generator.picNodes[index - 2];
}
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;
return generator.picNodes[index - colNum];
}
}
}
......@@ -579,6 +500,8 @@ public class Generator {
@Accessors(chain = true)
static class PicConfigGenerator {
private final CaptionNode mainCaptionNode = new CaptionNode();
private final PicNode[] picNodes;
/** 图片排列方式类型 */
private final int layoutType;
......@@ -597,6 +520,10 @@ public class Generator {
}
for (CaptionVo captionVo : captionVos) {
// 9 代表合成图
if (captionVo.getPicType() == 9) {
mainCaptionNode.add(captionVo);
} else {
for (PicNode picNode : picNodes) {
if (picNode.getPicType() == captionVo.getPicType()) {
picNode.getCaptionNode().add(captionVo);
......@@ -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 {
int wrapCount = 0;
for (Context context : contexts) {
Integer type = context.getType();
if (type != 16) {
sb.append(Dict.INSTANCE.captionType.get(type)).append(":+");
}
switch (type) {
case 1:
if (picTypeName.contains("特写")) {
......
......@@ -11,9 +11,9 @@ spring:
# 服务发现配置
discovery:
# 启用服务发现
enabled: false
enabled: true
# 启用服务注册
register: false
register: true
# 服务停止时取消注册
deregister: true
# 表示注册时使用IP而不是hostname
......@@ -28,7 +28,7 @@ spring:
instance-id: ${spring.application.name}:${spring.cloud.consul.discovery.ip-address}:${server.port}
ip-address: 192.168.9.146
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
password: vion
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!