Browse Source

feat: 添加gap参数

hexleo 5 years ago
parent
commit
558984ea9b

+ 7 - 7
Android/PlayerProj/animtool/src/main/java/com/tencent/qgame/playerproj/animtool/AnimTool.java

@@ -73,10 +73,10 @@ public class AnimTool {
         }
 
         // 宽高必须是16的倍数,某些机行会进行对齐
-        if (commonArg.videoW % 16 != 0 || commonArg.videoH % 16 != 0) {
+        /*if (commonArg.videoW % 16 != 0 || commonArg.videoH % 16 != 0) {
             TLog.i(TAG, "error: video size " + commonArg.videoW + "x" + commonArg.videoH + " can not be divisible by 16");
             return false;
-        }
+        }*/
 
         File input = new File(commonArg.inputPath);
         if (!input.exists()) {
@@ -154,7 +154,7 @@ public class AnimTool {
         int w = commonArg.videoW;
         int h = commonArg.videoH;
         File inputFile = new File(commonArg.inputPath + String.format("%03d", frameIndex)+".png");
-        GetAlphaFrame.AlphaFrameOut videoFrame = getAlphaFrame.createFrame(commonArg.orin,w, h, inputFile);
+        GetAlphaFrame.AlphaFrameOut videoFrame = getAlphaFrame.createFrame(commonArg.orin,w, h, commonArg.gap, inputFile);
         if (videoFrame == null) {
             TLog.i(TAG, "frameIndex="+frameIndex +" is empty");
             return;
@@ -226,15 +226,15 @@ public class AnimTool {
         String aFrame = "[0,0,"+commonArg.videoW+","+commonArg.videoH+"]";
         String rgbFrame = "[0,0,0,0]";
         if (commonArg.orin == CommonArg.ORIN_H) { // 水平对齐
-            realW = 2 * commonArg.videoW;
+            realW = 2 * commonArg.videoW + commonArg.gap;
             realH = commonArg.videoH;
-            cx = commonArg.videoW;
+            cx = commonArg.videoW + commonArg.gap;
             cy = 0;
         } else { // 上下对齐
             realW = commonArg.videoW;
-            realH = 2 * commonArg.videoH;
+            realH = 2 * commonArg.videoH + commonArg.gap;
             cx = 0;
-            cy = commonArg.videoH;
+            cy = commonArg.videoH + commonArg.gap;
         }
         rgbFrame = "["+cx+","+cy+","+commonArg.videoW+","+commonArg.videoH+"]";
 

+ 15 - 7
Android/PlayerProj/animtool/src/main/java/com/tencent/qgame/playerproj/animtool/CommonArg.java

@@ -26,6 +26,19 @@ public class CommonArg {
 
     public boolean enableH265 = false; // 是否开启h265
 
+
+    public int fps = 0;
+
+    public String inputPath; // 输入帧文件地址
+
+    public String outputPath; // 输出地址
+
+
+    /**
+     * 无需手动配置
+     */
+    public String frameOutputPath; // 帧图片输出路径
+
     public int version = 2;
 
     public int orin = ORIN_H;
@@ -34,13 +47,8 @@ public class CommonArg {
 
     public int videoH;
 
-    public int totalFrame;
+    public int gap; // rgb 与 alpha 之间间隔距离
 
-    public int fps = 0;
-
-    public String inputPath; // 输入帧文件地址
-
-    public String outputPath; // 输出地址
+    public int totalFrame;
 
-    public String frameOutputPath; // 帧图片输出路径
 }

+ 18 - 17
Android/PlayerProj/animtool/src/main/java/com/tencent/qgame/playerproj/animtool/GetAlphaFrame.java

@@ -25,8 +25,6 @@ public class GetAlphaFrame {
     public static final int ORIN_H = 1; // 左右对齐
     public static final int ORIN_V = 2; // 上下对齐
 
-    public static final int MASK_TEX_GAP = 10; // 遮罩纹理之间的间距,防止光栅化导致边界模糊问题
-
 
     public static class AlphaFrameOut {
 
@@ -37,34 +35,39 @@ public class GetAlphaFrame {
         public int h;
         public int outW;
         public int outH;
+        public int gap;
 
-        // 一帧里纹理开始的位置
-        int lastX;
-        int lastY;
-        int curMaxY;
 
-        public AlphaFrameOut(int orin, int[] argb, int w, int h, int outW, int outH) {
+        public AlphaFrameOut(int orin, int[] argb, int w, int h, int outW, int outH, int gap) {
             this.orin = orin;
             this.argb = argb;
             this.w = w;
             this.h = h;
             this.outW = outW;
             this.outH = outH;
-            lastX = MASK_TEX_GAP;
-            lastY = MASK_TEX_GAP;
-            curMaxY = lastY;
+            this.gap = gap;
         }
 
     }
 
-    public AlphaFrameOut createFrame(int orin, int w, int h, File inputFile) throws IOException {
+    /**
+     *
+     * @param orin
+     * @param w 原图像宽
+     * @param h 原图像高
+     * @param gap rgb 与 alpha 之间间隔距离
+     * @param inputFile
+     * @return
+     * @throws IOException
+     */
+    public AlphaFrameOut createFrame(int orin, int w, int h, int gap, File inputFile) throws IOException {
 
         if (!inputFile.exists()) {
             return null;
         }
 
-        int outW = orin == ORIN_H ? w * 2 : w;
-        int outH = orin == ORIN_H ? h : h * 2;
+        int outW = orin == ORIN_H ? (w * 2 + gap) : w;
+        int outH = orin == ORIN_H ? h : (h * 2 + gap);
 
         BufferedImage inputBuf = ImageIO.read(inputFile);
         int[] inputArgb = inputBuf.getRGB(0, 0, w, h, null, 0, w);
@@ -76,13 +79,11 @@ public class GetAlphaFrame {
         for (int k=0; k<2; k++) {
             for (int x = 0; x < w; x++) {
                 for (int y = 0; y < h; y++) {
-                    int outPoint = orin == ORIN_H ? k * w + x + y * outW : k * w * h + x + y * w;
+                    int outPoint = orin == ORIN_H ? k * (w + gap) + x + y * outW : k * w * (h + gap) + x + y * w;
                     if (k == 0) {
                         int alpha = inputArgb[x + y * w] >>> 24;
                         // r = g = b
                         outputArgb[outPoint] = 0xff000000 + (alpha << 16) + (alpha << 8) + alpha;
-                        // r = b g = 0
-                        // outputArgb[outPoint] = 0xff000000 + (alpha << 16) + (0x00 << 8) + alpha;
                     } else {
                         outputArgb[outPoint] = blendBg(inputArgb[x + y * w], 0xff000000);
                     }
@@ -90,7 +91,7 @@ public class GetAlphaFrame {
             }
         }
 
-        return new AlphaFrameOut(orin, outputArgb, w, h, outW, outH);
+        return new AlphaFrameOut(orin, outputArgb, w, h, outW, outH, gap);
 
     }