public override void Run()
        {
            int dx = 0;
            int dy = 23;

            string sampleASSEvent = @"Dialogue: 0,0:23:44.77,0:23:59.75,quiz_an7,NTP,0000,0000,0000,,{\pos(594,68)}\N富\N含\N养\N分\N的\N变\N厚\N的\N叶\N,\N像\N葱\N和\N薤\N这\N些\N植\N物\N都\N长\N有\N鳞\N茎\N。";

            ASSEvent srcEv = ASSEvent.FromString(sampleASSEvent);
            string   srcS  = @"教\N师\N评\N语";

            srcS = srcS.Replace(@"\N", "");

            int x0 = 455;
            int y0 = 260;

            int    x    = x0;
            int    y    = y0;
            string outS = "";

            foreach (char ch in srcS)
            {
                ASSEvent ev = ASSEvent.FromString(sampleASSEvent);
                ev.Text = pos(x, y) + ch;
                x      += dx;
                y      += dy;
                outS   += ev.ToString() + "\r\n";
            }

            StreamWriter fout = new StreamWriter(new FileStream(@"G:\Workshop\baka\01\1.txt", FileMode.Append), Encoding.Default);

            fout.WriteLine(outS);
            fout.Close();
        }
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            string ptString = @"{\p8}m 0 0 l 128 0 128 128 0 128";

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                if (iEv != 0)
                {
                    continue;
                }
                ASSEvent        ev     = ass_in.Events[iEv];
                List <KElement> kelems = ev.SplitK(true);

                /// an7 pos
                int x0 = (PlayResX - GetTotalWidth(ev)) / 2;
                int y0 = PlayResY - MarginBottom - FontHeight;

                Random rnd = new Random();

                int kSum = 0;

                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);

                    KElement   ke   = kelems[iK];
                    double     r    = (double)iK / (double)(kelems.Count - 1);
                    StringMask mask = GetMask(ke.KText, x0, y0);
                    Size       sz   = new Size(mask.Width, mask.Height);

                    /// an5 pos
                    int x = x0 + this.FontSpace + sz.Width / 2;
                    int y = y0 + FontHeight;

                    x0 += this.FontSpace + sz.Width;
                    y0  = y0;

                    foreach (ASSPoint pt in mask.Points)
                    {
                        ass_out.Events.Add(
                            ev.StyleReplace("pt").TextReplace(
                                ASSEffect.pos(pt.X, pt.Y) +
                                ASSEffect.a(1, Common.ToHex2(255 - pt.Brightness)) + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "FF") +
                                ptString
                                ));
                    }
                }
            }
            ass_out.SaveFile(OutFileName);
        }
Example #3
0
        public int GetTotalWidth(ASSEvent ev)
        {
            List <KElement> a   = ev.SplitK(false);
            int             sum = 0;

            foreach (KElement k in a)
            {
                sum += GetSize(k.KText).Width;
            }
            return(sum + (a.Count - 1) * FontSpace);
        }
Example #4
0
        public IList <ASSEvent> Run(ASSEvent evt)
        {
            var list = new List <ASSEvent>();

            if (Condition.Check(evt))
            {
                foreach (var ac in Actions)
                {
                    list.Add(ac.Apply(evt));
                }
            }
            return(list);
        }
Example #5
0
        public string Escape(ASSEvent evtLine)
        {
            var text = Right
                       .Replace("@Layer", evtLine.Layer.ToString())
                       .Replace("@Start", evtLine.Start.ToString())
                       .Replace("@End", evtLine.End.ToString())
                       .Replace("@Style", evtLine.Style)
                       .Replace("@Name", evtLine.Name)
                       .Replace("@MarginL", evtLine.MarginL.ToString())
                       .Replace("@MarginR", evtLine.MarginR.ToString())
                       .Replace("@MarginV", evtLine.MarginV.ToString())
                       .Replace("@Effect", evtLine.Effect.ToString())
                       .Replace("@Text", evtLine.Text);

            return(text);
        }
Example #6
0
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            Random rnd = new Random();

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                ASSEvent        ev     = ass_in.Events[iEv];
                List <KElement> kelems = ev.SplitK(false);

                this.MaskStyle = "Style: Default,DFGMaruGothic-Md,35,&H00FF0000,&HFF000000,&HFFFFFFFF,&HFFFF0000,-1,0,0,0,100,100,2,0,1,2,0,5,25,25,25,128";
                int x0      = MarginLeft;
                int startx0 = x0;
                int y0      = PlayResY - MarginBottom - FontHeight;
                int kSum    = 0;

                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                    KElement ke     = kelems[iK];
                    Size     sz     = GetSize(ke.KText);
                    double   kStart = ev.Start + kSum * 0.01;
                    double   kEnd   = kStart + ke.KValue * 0.01;
                    kSum += ke.KValue;
                    int        x     = x0 + this.FontSpace + sz.Width / 2;
                    int        y     = y0 + FontHeight / 2;
                    int        x_an7 = x0;
                    int        y_an7 = y0;
                    StringMask mask  = GetMask(ke.KText, x, y);
                    x0 += this.FontSpace + sz.Width;
                    if (ke.KText.Trim().Length == 0)
                    {
                        continue;
                    }
                }
            }

            ass_out.SaveFile(OutFileName);
            Console.WriteLine("Lines : {0}", ass_out.Events.Count);
        }
Example #7
0
        public bool Check(ASSEvent evtLine)
        {
            var prop = evtLine.GetType().GetProperty(Left, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase);

            if (prop != null)
            {
                var value = prop.GetValue(evtLine);
                switch (Oprt)
                {
                case TemplateOperator.Equals:
                    if (value.GetType().Name.Equals("string", StringComparison.OrdinalIgnoreCase))
                    {
                        return(value.ToString().Equals(Right, StringComparison.OrdinalIgnoreCase));
                    }
                    if (value.GetType().Name.Equals("ASSEventTime", StringComparison.OrdinalIgnoreCase))
                    {
                        return(value.Equals(Right));
                    }
                    if (value.GetType().Name.Equals("int", StringComparison.OrdinalIgnoreCase) ||
                        value.GetType().Name.Equals("Int32", StringComparison.OrdinalIgnoreCase))
                    {
                        return(value.Equals(Convert.ToInt32(Right)));
                    }
                    return(false);

                case TemplateOperator.Contains:
                    if (value.GetType().Name.Equals("string", StringComparison.OrdinalIgnoreCase))
                    {
                        return(value.ToString().Contains(Right));
                    }
                    if (value.GetType().Name.Equals("ASSEventTime", StringComparison.OrdinalIgnoreCase))
                    {
                        return(value.Equals(Right));
                    }
                    if (value.GetType().Name.Equals("int", StringComparison.OrdinalIgnoreCase) ||
                        value.GetType().Name.Equals("Int32", StringComparison.OrdinalIgnoreCase))
                    {
                        return(value.Equals(Convert.ToInt32(Right)));
                    }
                    return(false);
                }
            }
            return(false);
        }
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                ASSEvent        ev     = ass_in.Events[iEv];
                List <KElement> kelems = ev.SplitK(iEv > 130);
                StringBuilder   sb     = new StringBuilder();
                int             kSum   = 30;
                ev.Start -= 0.3;
                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    KElement ke     = kelems[iK];
                    double   kStart = kSum * 0.01;
                    sb.Append(
                        ASSEffect.be(1) +
                        ASSEffect.a(3, "FF") + ASSEffect.a(1, "FF") + ASSEffect.t(0, 0.3, ASSEffect.a(3, "00").t() + ASSEffect.a(1, "00").t()) +
                        //ASSEffect.t(kStart, kStart + 0.3, ASSEffect.a(1, "77").t()) +
                        ASSEffect.t(kStart + 0, kStart + 0.5, ASSEffect.a(1, "FF").t() + ASSEffect.a(3, "FF").t()) +
                        ke.KText + ASSEffect.r()
                        );
                    kSum += ke.KValue;
                    if (ev.Last < kStart + 1.0)
                    {
                        ev.End += (kStart + 1.0 - ev.Last);
                    }
                }
                ass_out.Events.Add(ev.LayerReplace(iEv).TextReplace(sb.ToString()));
            }

            ass_out.SaveFile(OutFileName);
        }
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            string ms1    = "Style: Default,DFGMaruGothic-Md,30,&H00FF0000,&HFF600D00,&H000000FF,&HFF0A5A84,-1,0,0,0,100,100,0,0,0,2,0,5,20,20,20,128";
            string ms3    = "Style: Default,DFGMaruGothic-Md,30,&H000000FF,&HFF600D00,&H00FF0000,&HFF0A5A84,-1,0,0,0,100,100,0,0,0,2,0,5,20,20,20,128";
            string ptstr  = @"{\p1}m 0 0 l 1 0 1 1 0 1";
            string pt0Str = @"{\blur2\bord3\p4}m 5 5 s 5 -5 -5 -5 -5 5";

            Random rnd = new Random();

            InitBFS();

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                //if (iEv != 0) continue;
                ASSEvent        ev     = ass_in.Events[iEv];
                List <KElement> kelems = ev.SplitK(false);

                this.MaskStyle = ms3;
                double sw = (iEv % 2 == 0) ? 0 : GetTotalWidth(ev);
                /// an7 pos
                int x0      = (iEv % 2 == 0) ? MarginLeft : (int)(PlayResX - MarginRight - sw);
                int startx0 = x0;
                int y0      = PlayResY - MarginBottom - FontHeight;

                int kSum = 0;

                int           lum0count = 0;
                List <double> lum0x     = new List <double>();
                List <double> lum0y     = new List <double>();
                for (int lumx0 = -20; lumx0 < PlayResX;)
                {
                    lumx0 += Common.RandomInt(rnd, 5, 10);
                    lum0x.Add(lumx0);
                    lum0y.Add(Common.RandomInt(rnd, PlayResY - MarginBottom - FontHeight - 2, PlayResY - MarginBottom + 2));
                    lum0count++;
                }

                int           lumcount = 0;
                List <double> lumx     = new List <double>();
                List <double> lumy     = new List <double>();
                for (int lumx0 = -20; lumx0 < PlayResX;)
                {
                    lumx0 += Common.RandomInt(rnd, 25, 45);
                    lumx.Add(lumx0);
                    lumy.Add(Common.RandomInt(rnd, PlayResY - MarginBottom - FontHeight - 10, PlayResY - MarginBottom + 10));
                    lumcount++;
                }

                string[] lumcol =
                {
                    "003DB8",
                    "003DB8",
                    "000000",
                    "B54F00",
                    "0068B8",
                    "B88000"
                };

                string[] lum3 =
                {
                    "00B88F", //23:49.678
                    "003DB8", //23:50.429
                    "5972B8", //23:51.931
                    "B86459"  //23:54.516
                };
                double[] lum3t =
                {
                    23 * 60 + 49 + 0.65,
                    23 * 60 + 50 + 0.40,
                    23 * 60 + 51 + 0.91,
                    23 * 60 + 54 + 0.49
                };

                string[] lum4 =
                {
                    "003DB8" //24:06.528
                };
                double[] lum4t =
                {
                    24 * 60 + 6 + 0.50
                };


                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    //if (iK > 3) continue;
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                    KElement ke = kelems[iK];
                    double   r  = (double)iK / (double)(kelems.Count - 1);
                    this.MaskStyle = ms3;
                    StringMask mask = GetMask(ke.KText, x0, y0);
                    Size       sz   = new Size(mask.Width, mask.Height);

                    double kStart = ev.Start + kSum * 0.01;
                    double kEnd   = kStart + ke.KValue * 0.01;
                    kSum += ke.KValue;

                    /// an5 pos
                    int x = x0 + this.FontSpace + sz.Width / 2;
                    int y = y0 + FontHeight / 2;

                    this.MaskStyle = ms1;
                    mask           = GetMask(ke.KText, x, y);

                    int bakx0 = x0;

                    x0 += this.FontSpace + sz.Width;
                    y0  = y0;

                    if (ke.KText.Trim().Length == 0)
                    {
                        continue;
                    }

                    double t0  = ev.Start - 1.0 + r * 2;
                    double t1  = t0 + 1;
                    double t11 = kStart - 0.4;
                    double t2  = ev.End;

                    ass_out.Events.Add(
                        ev.StartReplace(t11).EndReplace(t11 + 0.8).TextReplace(
                            ASSEffect.pos(x, y) + ASSEffect.a(1, "00") + ASSEffect.a(3, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.c(3, "FFFFFF") +
                            ASSEffect.fad(0.2, 0.6) + ASSEffect.bord(0) + ASSEffect.blur(0) +
                            ASSEffect.t(0, 1, ASSEffect.bord(5).t() + ASSEffect.blur(5).t()) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t11 + 0.4).EndReplace(t2 + 0.5).TextReplace(
                            ASSEffect.pos(x, y) + ASSEffect.a(1, "00") + ASSEffect.a(3, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.c(3, "FFFFFF") +
                            ASSEffect.fad(0.4, 1) + ASSEffect.bord(2) + ASSEffect.blur(2) +
                            ke.KText));

                    if (iEv == 3)
                    {
                        ass_out.Events.Add(
                            ev.StartReplace(ev.Start + 0.5).EndReplace(ev.Start + 2.0).LayerReplace(20).TextReplace(
                                ASSEffect.pos(x, y) + ASSEffect.a(1, "00") + ASSEffect.a(3, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.c(3, "FFFFFF") +
                                ASSEffect.fad(0, 0.5) + ASSEffect.bord(9) + ASSEffect.blur(8) +
                                ke.KText));
                    }
                    if (iEv == 5)
                    {
                        ass_out.Events.Add(
                            ev.StartReplace(ev.End).EndReplace(ev.End + 1.5).LayerReplace(20).TextReplace(
                                ASSEffect.pos(x, y) + ASSEffect.a(1, "00") + ASSEffect.a(3, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.c(3, "FFFFFF") +
                                ASSEffect.fad(0.3, 0.5) + ASSEffect.bord(6) + ASSEffect.blur(6) +
                                ke.KText));
                    }

                    /*for (int i = 1; i <= 5; i++)
                     * {
                     *  ass_out.Events.Add(
                     *      ev.StartReplace(kStart + 0).EndReplace(t2 + 0.5).TextReplace(
                     *      ASSEffect.pos(x, y) + ASSEffect.a(1, "00") + ASSEffect.a(3, "FF") + ASSEffect.c(1, "FFFFFF") +
                     *      ASSEffect.fad(0.4, 1) + ASSEffect.bord(2) + ASSEffect.blur(2) +
                     *      ke.KText));
                     * }*/

                    int[]    ind = CalculateBFSOrder(mask);
                    double[] wt  = new double[mask.Points.Count];
                    double[] wt0 = new double[mask.Points.Count];
                    for (int i = 0; i < ind.Length; i++)
                    {
                        ASSPoint pt = mask.Points[i];
                        double   ag = Common.GetAngle(pt.X, pt.Y, x, y);
                        double   r0 = Common.GetDistance(pt.X, pt.Y, x, y) * 1.0;
                        double   r1 = Common.GetDistance(pt.X, pt.Y, x, y) * 1.3;
                        //double r2 = Common.GetDistance(pt.X, pt.Y, x, y) * 1.1;
                        double ptx0 = pt.X; // (double)x + Math.Cos(ag) * r0;
                        double pty0 = pt.Y; // (double)y - Math.Sin(ag) * r0;
                        double ptx  = (double)x + Math.Cos(ag) * r1;
                        double pty  = (double)y - Math.Sin(ag) * r1;
                        //double ptx2 = (double)x + Math.Cos(ag) * r2;
                        //double pty2 = (double)y - Math.Sin(ag) * r2;
                        string bt  = Common.ToHex2((255 - pt.Brightness) * Common.RandomDouble(rnd, 0.7, 0.9));
                        string bt2 = bt;
                        string bt3 = Common.ToHex2((255 - pt.Brightness * 0.8) * Common.RandomDouble(rnd, 0.7, 0.9));
                        double pt2 = kStart + (kEnd - kStart) * (pt.X - bakx0) / mask.Width + Common.RandomDouble_Gauss(rnd, -0.15, 0.00, 2);
                        wt[i] = 1;
                        for (int j = 0; j < lumcount; j++)
                        {
                            double dis = Common.GetDistance(pt.X, pt.Y, lumx[j], lumy[j]) / 30.0;
                            if (wt[i] > dis)
                            {
                                wt[i] = dis;
                            }
                        }
                        wt0[i] = 1;
                        for (int j = 0; j < lum0count; j++)
                        {
                            double dis = Common.GetDistance(pt.X, pt.Y, lum0x[j], lum0y[j]) / 10.0;
                            if (wt0[i] > dis)
                            {
                                wt0[i] = dis;
                            }
                        }
                        string col0 = Common.scaleColor("222222", "FFFFFF", wt0[i]);
                        if (iEv == 2)
                        {
                            col0 = Common.scaleColor("444444", "FFFFFF", wt0[i]);
                        }
                        if (iEv >= 3)
                        {
                            col0 = Common.scaleColor("777777", "FFFFFF", wt0[i]);
                        }
                        double pt3 = t2 + wt[i] + Common.RandomDouble_Gauss(rnd, -0.08, 0.08, 2);

                        if (iEv >= 2)
                        {
                            ass_out.Events.Add(
                                ev.StartReplace(pt2 - 0.1).EndReplace(pt2).StyleReplace("pt").LayerReplace(15).TextReplace(
                                    ASSEffect.a(1, "CC") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "CC") + ASSEffect.c(1, "FFFFFF") +
                                    ASSEffect.bord(1) + ASSEffect.be(1) +
                                    ASSEffect.pos(ptx0, pty0) + ptstr));
                        }

                        if (iEv != 3 && iEv != 4)
                        {
                            string ptc = Common.scaleColor("FFFFFF", lumcol[iEv], wt[i]);
                            ass_out.Events.Add(
                                ev.StartReplace(t0).EndReplace(t1).StyleReplace("pt").TextReplace(
                                    ASSEffect.a(1, bt) + ASSEffect.c(1, col0) + ASSEffect.fad(0.1, 0) + ASSEffect.a(3, "FF") +
                                    ASSEffect.move(ptx, pty, ptx0, pty0) + ptstr));
                            ass_out.Events.Add(
                                ev.StartReplace(t1).EndReplace(pt2 + 0.2).StyleReplace("pt").TextReplace(
                                    ASSEffect.a(1, bt) + ASSEffect.c(1, col0) + ASSEffect.a(3, "FF") +
                                    ASSEffect.fad(0, 0.3) +
                                    ASSEffect.pos(ptx0, pty0) + ptstr));
                            ass_out.Events.Add(
                                ev.StartReplace(pt2 - 0.1).EndReplace(pt3).StyleReplace("pt").TextReplace(
                                    ASSEffect.a(1, bt2) + ASSEffect.c(1, ptc) + ASSEffect.a(3, "FF") +
                                    ASSEffect.fad(0.3, 0.3) +
                                    ASSEffect.pos(ptx0, pty0) + ptstr));
                        }
                        else if (iEv == 3)
                        {
                            for (int j = 0; j <= lum3.Length; j++)
                            {
                                string ptc = Common.scaleColor("FFFFFF", (j > 0) ? lum3[j - 1] : lumcol[iEv], wt[i]);
                                double tlo = (j > 0) ? lum3t[j - 1] : t0;
                                double thi = (j < lum3.Length) ? lum3t[j] : pt3;
                                Func <double, double> flo = xx => (xx < tlo) ? tlo : xx;
                                Func <double, double> fhi = xx => (xx > thi) ? thi : xx;
                                ass_out.Events.Add(
                                    ev.StartReplace(flo(t0)).EndReplace(fhi(t1)).StyleReplace("pt").TextReplace(
                                        ASSEffect.a(1, bt) + ASSEffect.c(1, col0) + ASSEffect.fad((j == 0) ? 0.1 : 0, 0) + ASSEffect.a(3, "FF") +
                                        ASSEffect.move(ptx, pty, ptx0, pty0) + ptstr));
                                ass_out.Events.Add(
                                    ev.StartReplace(flo(t1)).EndReplace(fhi(pt2 + 0.2)).StyleReplace("pt").TextReplace(
                                        ASSEffect.a(1, bt) + ASSEffect.c(1, col0) + ASSEffect.a(3, "FF") +
                                        ASSEffect.fad(0, (j == lum3.Length) ? 0.3 : 0) +
                                        ASSEffect.pos(ptx0, pty0) + ptstr));
                                ass_out.Events.Add(
                                    ev.StartReplace(flo(pt2 - 0.1)).EndReplace(fhi(pt3)).StyleReplace("pt").TextReplace(
                                        ASSEffect.a(1, bt) + ASSEffect.c(1, ptc) + ASSEffect.a(3, "FF") +
                                        ASSEffect.fad((j == 0) ? 0.3 : 0, (j == lum3.Length) ? 0.3 : 0) +
                                        ASSEffect.pos(ptx0, pty0) + ptstr));
                            }
                        }
                        else if (iEv == 4)
                        {
                            for (int j = 0; j <= lum4.Length; j++)
                            {
                                string ptc = Common.scaleColor("FFFFFF", (j > 0) ? lum4[j - 1] : lumcol[iEv], wt[i]);
                                double tlo = (j > 0) ? lum4t[j - 1] : t0;
                                double thi = (j < lum4.Length) ? lum4t[j] : pt3;
                                Func <double, double> flo = xx => (xx < tlo) ? tlo : xx;
                                Func <double, double> fhi = xx => (xx > thi) ? thi : xx;
                                ass_out.Events.Add(
                                    ev.StartReplace(flo(t0)).EndReplace(fhi(t1)).StyleReplace("pt").TextReplace(
                                        ASSEffect.a(1, bt) + ASSEffect.c(1, col0) + ASSEffect.fad((j == 0) ? 0.1 : 0, 0) + ASSEffect.a(3, "FF") +
                                        ASSEffect.move(ptx, pty, ptx0, pty0) + ptstr));
                                ass_out.Events.Add(
                                    ev.StartReplace(flo(t1)).EndReplace(fhi(pt2 + 0.2)).StyleReplace("pt").TextReplace(
                                        ASSEffect.a(1, bt) + ASSEffect.c(1, col0) + ASSEffect.a(3, "FF") +
                                        ASSEffect.fad(0, (j == lum4.Length) ? 0.3 : 0) +
                                        ASSEffect.pos(ptx0, pty0) + ptstr));
                                ass_out.Events.Add(
                                    ev.StartReplace(flo(pt2 - 0.1)).EndReplace(fhi(pt3)).StyleReplace("pt").TextReplace(
                                        ASSEffect.a(1, bt) + ASSEffect.c(1, ptc) + ASSEffect.a(3, "FF") +
                                        ASSEffect.fad((j == 0) ? 0.3 : 0, (j == lum4.Length) ? 0.3 : 0) +
                                        ASSEffect.pos(ptx0, pty0) + ptstr));
                            }
                        }

                        if (iEv == 2 && Common.RandomBool(rnd, 0.05))
                        {
                            ass_out.Events.Add(
                                ev.StartReplace(pt2).EndReplace(pt2 + 1.5).StyleReplace("pt").LayerReplace(13).TextReplace(
                                    ASSEffect.move(ptx0, pty0, ptx0, pty0 + FontHeight + MarginBottom) +
                                    ASSEffect.fad(0, 0.6) + ASSEffect.a(1, "CC") + ASSEffect.c(1, "FFFFFF") +
                                    ASSEffect.a(3, "00") + ASSEffect.c(3, "FFFFFF") +
                                    ASSEffect.t(0, Common.RandomDouble(rnd, 1.5, 3), ASSEffect.fry(-720).t()) +
                                    ASSEffect.bord(2) + ASSEffect.blur(2) + CreatePolygon(rnd, 30, 30, 4)));
                        }
                    }

                    if (iEv == 3)
                    {
                        for (int i = 0; i < (int)(Math.Round((kEnd - kStart) * 50)); i++)
                        {
                            ASSPoint pt = new ASSPoint {
                                X = Common.RandomInt(rnd, startx0, startx0 + (int)sw), Y = Common.RandomInt(rnd, y0, y0 + FontHeight)
                            };
                            double pt0 = Common.RandomDouble(rnd, ev.Start, ev.Start + 1.62);
                            double pt1 = pt0 + 0.5;
                            ass_out.Events.Add(
                                ev.StartReplace(pt0).EndReplace(pt1).StyleReplace("pt").TextReplace(
                                    ASSEffect.move(pt.X, pt.Y, Common.RandomInt(rnd, pt.X - 30, pt.X - 50), Common.RandomInt(rnd, pt.Y - 35, pt.Y - 55)) +
                                    ASSEffect.fad(0, 0.3) + ASSEffect.a(1, "CC") + ASSEffect.c(1, "FFFFFF") +
                                    ASSEffect.a(3, "00") + ASSEffect.c(3, "FFFFFF") +
                                    ASSEffect.t(0, Common.RandomDouble(rnd, 0.5, 1.5), ASSEffect.frz(Common.RandomInt(rnd, -500, 500)).t() + ASSEffect.fry(Common.RandomInt(rnd, -500, 500)).t() + ASSEffect.frx(Common.RandomInt(rnd, -500, 500)).t()) +
                                    ASSEffect.bord(3) + ASSEffect.blur(2) + CreatePolygon(rnd, 10, 25, Common.RandomInt(rnd, 5, 7))));
                        }
                        for (int i = 0; i < (int)(Math.Round((kEnd - kStart) * 200)); i++)
                        {
                            ASSPoint pt  = mask.Points[Common.RandomInt(rnd, 0, mask.Points.Count - 1)];
                            double   pt0 = Common.RandomDouble(rnd, kStart, kEnd);
                            double   pt1 = pt0 + 1.5;
                            string   ptc = lumcol[iEv];
                            for (int j = 0; j < lum3t.Length; j++)
                            {
                                if (pt0 >= lum3t[j] - 0.5)
                                {
                                    ptc = lum3[j];
                                }
                            }
                            ptc = Common.scaleColor(ptc, "FFFFFF", 0.75);
                            ass_out.Events.Add(
                                ev.StartReplace(pt0).EndReplace(pt1).StyleReplace("pt").LayerReplace(5).TextReplace(
                                    ASSEffect.move(pt.X, pt.Y, Common.RandomInt(rnd, pt.X + 50, pt.X - 50), Common.RandomInt(rnd, pt.Y + 35, pt.Y - 35)) +
                                    ASSEffect.fad(0, 0.3) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") +
                                    ASSEffect.a(3, "00") + ASSEffect.c(3, ptc) +
                                    ASSEffect.bord(2) + ASSEffect.blur(2) + CreatePolygon(rnd, 15, 15, 6)));
                        }
                    }

                    if (iEv == 4)
                    {
                        for (int i = 0; i < (int)(Math.Round((kEnd - kStart) * 200)); i++)
                        {
                            ASSPoint pt  = mask.Points[Common.RandomInt(rnd, 0, mask.Points.Count - 1)];
                            double   pt0 = Common.RandomDouble(rnd, kStart, kEnd);
                            double   pt1 = pt0 + 1.5;
                            string   ptc = lumcol[iEv];
                            if (pt0 >= lum4t[0] - 0.5)
                            {
                                ptc = lum4[0];
                            }
                            ptc = Common.scaleColor(ptc, "FFFFFF", 0.65);
                            ass_out.Events.Add(
                                ev.StartReplace(pt0).EndReplace(pt1).StyleReplace("pt").LayerReplace(5).TextReplace(
                                    ASSEffect.move(pt.X, pt.Y, Common.RandomInt(rnd, pt.X + 50, pt.X - 50), Common.RandomInt(rnd, pt.Y + 35, pt.Y - 35)) +
                                    ASSEffect.fad(0, 0.3) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") +
                                    ASSEffect.a(3, "00") + ASSEffect.c(3, ptc) +
                                    ASSEffect.bord(2) + ASSEffect.blur(2) + CreatePolygon(rnd, 15, 15, 6)));
                        }
                    }

                    if (iEv == 5)
                    {
                        for (int i = 0; i < 100; i++)
                        {
                            ASSPoint pt = new ASSPoint {
                                X = Common.RandomInt(rnd, startx0, startx0 + (int)sw), Y = Common.RandomInt(rnd, y0, y0 + FontHeight)
                            };
                            double pt0 = Common.RandomDouble(rnd, ev.End, ev.End + 1.8);
                            double pt1 = pt0 + 0.5;
                            string ptc = Common.scaleColor(lumcol[iEv], "FFFFFF", 0.9);
                            ass_out.Events.Add(
                                ev.StartReplace(pt0).EndReplace(pt1).StyleReplace("pt").TextReplace(
                                    ASSEffect.move(pt.X, pt.Y, Common.RandomInt(rnd, pt.X - 30, pt.X - 50), Common.RandomInt(rnd, pt.Y - 35, pt.Y - 55)) +
                                    ASSEffect.fad(0, 0.3) + ASSEffect.a(1, "CC") + ASSEffect.c(1, "FFFFFF") +
                                    ASSEffect.a(3, "00") + ASSEffect.c(3, ptc) +
                                    ASSEffect.t(0, Common.RandomDouble(rnd, 0.5, 1.5), ASSEffect.frz(Common.RandomInt(rnd, -500, 500)).t() + ASSEffect.fry(Common.RandomInt(rnd, -500, 500)).t() + ASSEffect.frx(Common.RandomInt(rnd, -500, 500)).t()) +
                                    ASSEffect.bord(3) + ASSEffect.blur(2) + CreatePolygon(rnd, 10, 25, Common.RandomInt(rnd, 5, 7))));
                        }
                        for (int i = 0; i < (int)(Math.Round((kEnd - kStart) * 200)); i++)
                        {
                            ASSPoint pt  = mask.Points[Common.RandomInt(rnd, 0, mask.Points.Count - 1)];
                            double   pt0 = Common.RandomDouble(rnd, kStart, kEnd);
                            double   pt1 = pt0 + 1.5;
                            string   ptc = lumcol[iEv];
                            ptc = Common.scaleColor(ptc, "FFFFFF", 0.75);
                            ass_out.Events.Add(
                                ev.StartReplace(pt0).EndReplace(pt1).StyleReplace("pt").LayerReplace(5).TextReplace(
                                    ASSEffect.move(pt.X, pt.Y, Common.RandomInt(rnd, pt.X + 50, pt.X - 50), Common.RandomInt(rnd, pt.Y + 35, pt.Y - 35)) +
                                    ASSEffect.fad(0, 0.3) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") +
                                    ASSEffect.a(3, "00") + ASSEffect.c(3, ptc) +
                                    ASSEffect.bord(2) + ASSEffect.blur(2) + CreatePolygon(rnd, 15, 15, 6)));
                        }
                    }
                }
            }

            ass_out.SaveFile(OutFileName);
            Console.WriteLine("Lines : {0}", ass_out.Events.Count);
        }
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                ASSEvent        ev     = ass_in.Events[iEv];
                List <KElement> kelems = ev.SplitK(false);

                /// an7 pos
                int x0 = (PlayResX - GetTotalWidth(ev)) / 2;
                int y0 = PlayResY - MarginBottom - FontHeight;

                Random rnd = new Random();

                int kSum = 0;

                //ASSColor col1 = Common.RandomColor(rnd, 1, new ASSColor { A = 0, R = 20, B = 20, G = 20 }, new ASSColor { A = 0, R = 235, B = 235, G = 235 });
                //ASSColor col2 = Common.RandomColor(rnd, 1, new ASSColor { A = 0, R = col1.R - 40, B = col1.B - 40, G = col1.G - 40 }, new ASSColor { A = 0, R = col1.R + 40, B = col1.B + 40, G = col1.G + 40 });
                ASSColor col1 = Common.RandomColor(rnd, 1);
                ASSColor col2 = Common.RandomColor(rnd, 1);

                while (Math.Abs(col1.R - col2.R) + Math.Abs(col1.G - col2.G) + Math.Abs(col1.B - col2.B) < 100)
                {
                    col1 = Common.RandomColor(rnd, 1);
                    col2 = Common.RandomColor(rnd, 1);
                }

                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    KElement ke = kelems[iK];
                    double   r  = (double)iK / (double)(kelems.Count - 1);
                    Size     sz = GetSize(ke.KText);

                    string colStr = Common.scaleColor(col1, col2, r);

                    /// an5 pos
                    int x = x0 + this.FontSpace + sz.Width / 2;
                    int y = y0 + FontHeight / 2;
                    x0 += this.FontSpace + sz.Width;
                    y0  = y0;

                    if (iEv % 2 != 0 && ev.Start - ass_in.Events[iEv - 1].End < 0.1)
                    {
                        y -= FontHeight + 3;
                    }

                    double kStart = ev.Start + kSum * 0.01;
                    kSum += ke.KValue;
                    double kEnd = ev.Start + kSum * 0.01;

                    double t0 = ev.Start + r * 0.5 - 1.0;
                    if (iEv % 2 != 0)
                    {
                        t0 = ev.Start - r * 0.5 - 1.0;
                    }
                    double t01 = t0 + 0.5;
                    double t1  = kStart - 0.1;
                    if (t01 > t1)
                    {
                        t01 = t1;
                        t0  = t01 - 0.5;
                    }
                    double t2 = kStart + 0.2;
                    double t3 = kStart + 0.5;
                    double t4 = ev.End + r * 1.0 - 1.0;
                    if (iEv % 2 != 0)
                    {
                        t4 = ev.End - r * 1.0 + 1.0;
                    }
                    if (t4 < t3)
                    {
                        t4 = t3;
                    }
                    double t5 = t4 + 0.5;

                    double speed  = -20;
                    int    StartX = 848;
                    int    EndX   = 0;
                    if (iEv % 2 != 0)
                    {
                        speed  = 20;
                        StartX = 0;
                        EndX   = 848;
                    }

                    GetX_orgX      = x;
                    GetX_Speed     = speed;
                    GetX_StartTime = ev.Start;

                    ass_out.Events.Add(
                        ev.StartReplace(t0).EndReplace(t01).TextReplace(
                            ASSEffect.move(StartX, y, GetX(t01), y) + ASSEffect.a(1, "FF") + ASSEffect.a(3, "AA") + ASSEffect.c(3, "FFFFFF") +
                            ASSEffect.xbord(2) + ASSEffect.ybord(2) + ASSEffect.be(10) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t01).EndReplace(t2).TextReplace(
                            ASSEffect.move(GetX(t01), y, GetX(t2), y) + ASSEffect.a(1, "FF") + ASSEffect.a(3, "AA") + ASSEffect.c(3, "FFFFFF") +
                            ASSEffect.xbord(2) + ASSEffect.ybord(2) + ASSEffect.be(10) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t2).EndReplace(t3).TextReplace(
                            ASSEffect.move(GetX(t2), y, GetX(t3), y) + ASSEffect.a(1, "FF") + ASSEffect.a(3, "AA") + ASSEffect.c(3, "FFFFFF") +
                            ASSEffect.xbord(2) + ASSEffect.ybord(2) + ASSEffect.be(10) + ASSEffect.t(0, t3 - t2, ASSEffect.a(1, "77").t() + ASSEffect.c(3, colStr).t()) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t3).EndReplace(t4).TextReplace(
                            ASSEffect.move(GetX(t3), y, GetX(t4), y) + ASSEffect.a(1, "FF") + ASSEffect.a(3, "77") + ASSEffect.c(3, colStr) +
                            ASSEffect.xbord(2) + ASSEffect.ybord(2) + ASSEffect.be(10) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t4).EndReplace(t5).TextReplace(
                            ASSEffect.move(GetX(t4), y, EndX, y) + ASSEffect.a(1, "FF") + ASSEffect.a(3, "77") + ASSEffect.c(3, colStr) +
                            ASSEffect.xbord(2) + ASSEffect.ybord(2) + ASSEffect.be(10) +
                            ke.KText));

                    ass_out.Events.Add(
                        ev.StartReplace(t0).EndReplace(t01).TextReplace(
                            ASSEffect.move(StartX, y, GetX(t01), y) + ASSEffect.fad(t01 - t0, 0) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t01).EndReplace(t1).TextReplace(
                            ASSEffect.move(GetX(t01), y, GetX(t1), y) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t1).EndReplace(t2).TextReplace(
                            ASSEffect.move(GetX(t1), y, GetX(t2), y - 10) +
                            ASSEffect.t(0, t2 - t1, ASSEffect.frx(180 * 3).t()) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t2).EndReplace(t3).TextReplace(
                            ASSEffect.move(GetX(t2), y - 10, GetX(t3), y) + ASSEffect.frx(180) +
                            ASSEffect.t(0, t3 - t2, ASSEffect.frx(360).t() + ASSEffect.c(1, colStr).t()) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t3).EndReplace(t4).TextReplace(
                            ASSEffect.move(GetX(t3), y, GetX(t4), y) + ASSEffect.c(1, colStr) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t4).EndReplace(t5).TextReplace(
                            ASSEffect.move(GetX(t4), y, EndX, y) + ASSEffect.c(1, colStr) + ASSEffect.fad(0, t5 - t4) +
                            ke.KText));
                }
            }
            ass_out.SaveFile(OutFileName);
        }
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            this.Font      = new System.Drawing.Font("FA 瑞筆行書M", 26, GraphicsUnit.Pixel);
            this.MaskStyle = "Style: Default,FA 瑞筆行書M,26,&H00FFCEE7,&HFF0000FF,&H00FF2D49,&HFF0A5A84,-1,0,0,0,100,100,1,0,1,2,0,5,20,20,10,128";

            for (int i = 0; i < 21; i++)
            {
                ASSEvent        ev     = ass_in.Events[i];
                List <KElement> kelems = ev.SplitK(true);
                if (i >= 11)
                {
                    this.Font      = new System.Drawing.Font("華康行書體(P)", 26, GraphicsUnit.Pixel);
                    this.MaskStyle = "Style: Default,華康行書體(P),26,&H00FFCEE7,&HFF0000FF,&H00FF2D49,&HFF0A5A84,-1,0,0,0,100,100,1,0,1,2,0,5,20,20,10,136";
                }
                int sumw = GetTotalWidth(ev);
                int x0   = (PlayResX - MarginLeft - MarginRight - sumw) / 2 + MarginLeft;
                int kSum = 0;
                for (int ik = 0; ik < kelems.Count; ik++)
                {
                    Console.WriteLine("{0} / {1} : {2} / {3}", i + 1, ass_in.Events.Count, ik + 1, kelems.Count);
                    KElement elem = kelems[ik];
                    Size     sz   = this.GetSize(elem.KText);
                    int      x    = x0;
                    x0 += sz.Width + this.FontSpace;
                    int y = PlayResY - MarginBottom;
                    if (i == 5)
                    {
                        y -= FontHeight + 10;
                    }
                    if (i >= 11)
                    {
                        y = MarginTop + FontHeight;
                    }
                    double kStart = (double)kSum * 0.01;
                    double kEnd   = (double)(kSum + elem.KValue) * 0.01;
                    kEnd = kStart + 0.6;
                    double kMid = (kStart + kEnd) * 0.5;
                    double kQ1  = kStart + (kEnd - kStart) * 0.1;

                    double r  = (double)ik / (double)(kelems.Count - 1);
                    double r0 = 1.0 - r;

                    int fd_xof = (int)((double)(ik - (kelems.Count - 1) / 2) / (double)(kelems.Count - 1) * (double)PlayResX * 0.2);

                    // an7 -> an5
                    x += sz.Width / 2;
                    y -= FontHeight / 2;

                    // 0.5秒内出现
                    ass_out.Events.Add(ev.StartReplace(ev.Start - r0 * 0.5).EndReplace(ev.Start - r0 * 0.5 + 0.3).TextReplace(
                                           ASSEffect.move(x + fd_xof, y, x, y) + ASSEffect.an(5) + ASSEffect.be(1) + ASSEffect.a(1, "FF") + ASSEffect.a(3, "FF") + ASSEffect.fsc(400, 400) +
                                           ASSEffect.t(0, 0.3, ASSEffect.fsc(100, 100).t() + ASSEffect.a(1, "00").t() + ASSEffect.a(3, "00").t() + ASSEffect.fry(-360).t()) +
                                           elem.KText));

                    double newStart = ev.Start;
                    if (ev.Start - r0 * 0.5 + 0.3 > ev.Start)
                    {
                        newStart = ev.Start - r0 * 0.5 + 0.3;
                    }
                    else
                    {
                        ass_out.Events.Add(ev.StartReplace(ev.Start - r0 * 0.5 + 0.3).EndReplace(ev.Start).TextReplace(
                                               ASSEffect.pos(x, y) + ASSEffect.an(5) + ASSEffect.be(1) + elem.KText));
                    }

                    //ass_out.Events.Add(ev.TextReplace(
                    //  ASSEffect.pos(x, y) + ASSEffect.an(5) + elem.KText));
                    if (i < 11)
                    {
                        ass_out.Events.Add(ev.StartReplace(newStart).EndReplace(ev.Start + kStart).TextReplace(
                                               ASSEffect.pos(x, y) + ASSEffect.an(5) + ASSEffect.be(1) + elem.KText));
                        ass_out.Events.Add(ev.StartReplace(ev.Start + kStart).EndReplace(ev.Start + kEnd).TextReplace(
                                               ASSEffect.pos(x, y) + ASSEffect.an(5) + ASSEffect.be(1) +
                                               ASSEffect.t(0, kQ1 - kStart, ASSEffect.c(1, "FFFFFF").t() + ASSEffect.c(1, "FFFFFF").t() + ASSEffect.fsc(200, 200).t()) +
                                               ASSEffect.t(kQ1 - kStart, kEnd - kStart, ASSEffect.c(3, "A4CEE7").t() + ASSEffect.c(1, "072D49").t() + ASSEffect.fsc(100, 100).t()) +
                                               elem.KText));
                        ass_out.Events.Add(ev.StartReplace(ev.Start + kEnd).EndReplace(ev.End).TextReplace(
                                               ASSEffect.pos(x, y) + ASSEffect.an(5) + ASSEffect.be(1) + ASSEffect.c(1, "072D49") + ASSEffect.c(3, "A4CEE7") + elem.KText));
                    }
                    else
                    {
                        ass_out.Events.Add(ev.StartReplace(newStart).TextReplace(
                                               ASSEffect.pos(x, y) + ASSEffect.an(5) + ASSEffect.be(1) + elem.KText));
                    }

                    // 0.5秒内消失
                    if (i < 11)
                    {
                        ass_out.Events.Add(ev.StartReplace(ev.End + r * 0.5).EndReplace(ev.End + r * 0.5 + 0.3).TextReplace(
                                               ASSEffect.move(x, y, x + fd_xof, y) + ASSEffect.be(1) + ASSEffect.an(5) + ASSEffect.c(1, "072D49") + ASSEffect.c(3, "A4CEE7") +
                                               ASSEffect.t(0, 0.3, ASSEffect.fsc(400, 400).t() + ASSEffect.a(1, "FF").t() + ASSEffect.a(3, "FF").t() + ASSEffect.fry(-360).t()) +
                                               elem.KText));
                        ass_out.Events.Add(ev.StartReplace(ev.End).EndReplace(ev.End + r * 0.5).TextReplace(
                                               ASSEffect.pos(x, y) + ASSEffect.an(5) + ASSEffect.be(1) + ASSEffect.c(1, "072D49") + ASSEffect.c(3, "A4CEE7") + elem.KText));
                    }
                    else
                    {
                        ass_out.Events.Add(ev.StartReplace(ev.End + r * 0.5).EndReplace(ev.End + r * 0.5 + 0.3).TextReplace(
                                               ASSEffect.move(x, y, x + fd_xof, y) + ASSEffect.be(1) + ASSEffect.an(5) +
                                               ASSEffect.t(0, 0.3, ASSEffect.fsc(400, 400).t() + ASSEffect.a(1, "FF").t() + ASSEffect.a(3, "FF").t() + ASSEffect.fry(-360).t()) +
                                               elem.KText));
                        ass_out.Events.Add(ev.StartReplace(ev.End).EndReplace(ev.End + r * 0.5).TextReplace(
                                               ASSEffect.pos(x, y) + ASSEffect.an(5) + ASSEffect.be(1) + elem.KText));
                    }

                    kSum += elem.KValue;
                }
            }

            ass_out.SaveFile(OutFileName);
        }
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS()
            {
                Header = ass_in.Header, Events = new List <ASSEvent>()
            };

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                bool isJp = iEv <= 9;
                //if (iEv != 0) continue;
                //if (iEv != 9) continue;
                //if (!isJp) continue;
                //if (iEv != 5 && iEv != 6) continue;
                //if (iEv != 19 && iEv != 9) continue;
                //if (iEv < 20) continue;
                ASSEvent        ev     = ass_in.Events[iEv];
                List <KElement> kelems = ev.SplitK(!isJp);
                int             x0     = MarginLeft;
                int             y0     = (isJp || iEv >= 20) ? (PlayResY - MarginBottom - FontHeight) : MarginTop;
                int             kSum   = 0;

                /// 两句英文
                if (iEv >= 20)
                {
                    y0            -= 45;
                    x0            += 4;
                    this.MaskStyle = "Style: Default,DFMincho-UB,30,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,5,0,0,0,128";
                    for (int iK = 0; iK < kelems.Count; iK++)
                    {
                        Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                        KElement ke     = kelems[iK];
                        Size     sz     = GetSize(ke.KText);
                        double   kStart = ev.Start + kSum * 0.01;
                        double   kEnd   = kStart + ke.KValue * 0.01;
                        kSum += ke.KValue;
                        int        x     = x0 + this.FontSpace + sz.Width / 2;
                        int        y     = y0 + FontHeight / 2;
                        int        x_an7 = x0 + 2;
                        int        y_an7 = y0;
                        StringMask mask  = GetMask(ke.KText, x, y);
                        x0 += this.FontSpace + sz.Width;
                        if (ke.KText.Trim().Length == 0)
                        {
                            x0 -= sz.Width / 2;
                        }
                        if (ke.KText.Trim().Length == 0)
                        {
                            continue;
                        }

                        double t0 = ev.Start - 0.5 + iK * 0.07;
                        double t1 = t0 + 0.35;
                        double t2 = kStart;
                        double t3 = kEnd;
                        double t4 = ev.End - 0.5 + iK * 0.07;
                        double t5 = t4 + 0.35;

                        Func <double, double> fPosX = h => (x + (h - ev.Start) * 20);

                        ass_out.AppendEvent(50, "en", t0, t4,
                                            move(fPosX(t0), y, fPosX(t4), y) + a(1, "00") +
                                            fsc(0, 0) + fad(0.1, 0) +
                                            t(0, 0.28, fsc(140, 140).t()) + t(0.28, 0.35, fsc(100, 100).t()) +
                                            ke.KText);
                        ass_out.AppendEvent(30, "en", t0, t4,
                                            fsc(0, 0) + fad(0.1, 0) +
                                            t(0, 0.28, fsc(140, 140).t()) + t(0.28, 0.35, fsc(100, 100).t()) +
                                            move(fPosX(t0), y, fPosX(t4), y) + a(3, "44") + bord(3) + blur(3) + c(3, "6888FF") +
                                            ke.KText);
                        ass_out.AppendEvent(50, "en", t4, t5,
                                            move(fPosX(t4), y, fPosX(t5), y) + a(1, "00") +
                                            fad(0, 0.1) +
                                            t(0, 0.07, fsc(140, 140).t()) + t(0.07, 0.35, fsc(0, 0).t()) +
                                            ke.KText);
                        ass_out.AppendEvent(30, "en", t4, t5,
                                            fad(0, 0.1) +
                                            t(0, 0.07, fsc(140, 140).t()) + t(0.07, 0.35, fsc(0, 0).t()) +
                                            move(fPosX(t4), y, fPosX(t5), y) + a(3, "44") + bord(3) + blur(3) + c(3, "6888FF") +
                                            ke.KText);

                        string ptcol = "FF68AD";
                        for (int i = 0; i < 50; i++)
                        {
                            double ptx0 = Common.RandomDouble_Gauss(rnd, x - 2, x + 2);
                            double pty0 = Common.RandomDouble_Gauss(rnd, y - 2, y + 2);
                            double ptag = Common.RandomDouble(rnd, 0, Math.PI * 2);
                            double ptr  = Common.RandomDouble_Gauss(rnd, 50, 75);
                            double ptx1 = ptx0 + Math.Cos(ptag) * ptr;
                            double pty1 = pty0 + Math.Sin(ptag) * ptr;
                            double ptt0 = Common.RandomDouble(rnd, t0, t0 + 0.2);
                            double ptt1 = ptt0 + Common.RandomDouble(rnd, 2, 3);

                            string tstr = "";
                            for (double tmpt = 0; tmpt <= ptt1 - ptt0; tmpt += 0.40)
                            {
                                tstr += t(tmpt, tmpt + 0.20, a(1, "FF").t() + a(3, "FF").t()) + t(tmpt + 0.20, tmpt + 0.40, a(1, "44").t() + a(3, "88").t());
                            }
                            ass_out.AppendEvent(0, "pt", ptt0, ptt1,
                                                move(ptx0, pty0, ptx1, pty1) + a(1, "44") + a(3, "88") + c(3, Common.RandomBool(rnd, 0.5) ? ptcol : "FFFFFF") +
                                                bord(1.5) + blur(1.5) + fsc(150, 150) + tstr +
                                                p(1) + "m 0 0 l 1 0 1 1 0 1");
                        }
                    }
                    continue;
                }

                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                    if (iEv == 19)
                    {
                        isJp = iK <= 10;
                    }
                    this.MaskStyle = isJp ?
                                     "Style: Default,DFMincho-UB,38,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,5,0,0,0,128" :
                                     "Style: Default,汉仪粗宋繁,38,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,1,0,0,0,100,100,0,0,0,0,0,5,0,0,0,134";
                    string evStyle         = isJp ? "" : "cn";
                    string outlineFontname = isJp ? "DFMincho-UB" : "汉仪粗宋繁";
                    int    outlineEncoding = isJp ? 128 : 134;
                    isJp = iEv <= 9;
                    KElement ke = kelems[iK];
                    Size     sz = GetSize(ke.KText);
                    if (ke.KText[0] == 'く')
                    {
                        x0 += 2;
                    }
                    double kStart = ev.Start + kSum * 0.01;
                    double kEnd   = kStart + ke.KValue * 0.01;
                    kSum += ke.KValue;
                    int        x     = x0 + this.FontSpace + sz.Width / 2;
                    int        y     = y0 + FontHeight / 2;
                    int        x_an7 = x0 + 2;
                    int        y_an7 = y0;
                    StringMask mask  = GetMask(ke.KText, x, y);
                    x0 += this.FontSpace + sz.Width;
                    if (ke.KText.Trim().Length == 0)
                    {
                        continue;
                    }
                    string outlineString = GetOutline(x - FontHeight / 2, y - FontHeight / 2, ke.KText[0], outlineFontname, outlineEncoding, 38, 0, 262);

                    if (iEv == 9 && iK == 0)
                    {
                        outlineString = GetOutline(x - FontHeight / 2 + 10, y - FontHeight / 2, 'I', outlineFontname, outlineEncoding, 38, 0, 262);
                    }
                    if (iEv == 9 && iK == 2)
                    {
                        outlineString =
                            GetOutline(x - FontHeight / 2 - 29, y - FontHeight / 2, 'w', outlineFontname, outlineEncoding, 38, 0, 262) +
                            GetOutline(x - FontHeight / 2 - 29 + 30 - 12 + 1, y - FontHeight / 2, 'a', outlineFontname, outlineEncoding, 38, 0, 262) +
                            GetOutline(x - FontHeight / 2 - 29 + 60 - 20 - 2, y - FontHeight / 2, 'n', outlineFontname, outlineEncoding, 38, 0, 262) +
                            GetOutline(x - FontHeight / 2 - 29 + 90 - 34, y - FontHeight / 2, 'n', outlineFontname, outlineEncoding, 38, 0, 262) +
                            GetOutline(x - FontHeight / 2 - 29 + 120 - 44, y - FontHeight / 2, 'a', outlineFontname, outlineEncoding, 38, 0, 262);
                    }
                    if (iEv == 9 && iK == 4)
                    {
                        outlineString =
                            GetOutline(x - FontHeight / 2 - 29 - 11 + 30, y - FontHeight / 2, 's', outlineFontname, outlineEncoding, 38, 0, 262) +
                            GetOutline(x - FontHeight / 2 - 29 + 30 - 12 + 1 + 20, y - FontHeight / 2, 'a', outlineFontname, outlineEncoding, 38, 0, 262) +
                            GetOutline(x - FontHeight / 2 - 29 + 60 - 20 - 2 + 19, y - FontHeight / 2, 'y', outlineFontname, outlineEncoding, 38, 0, 262);
                    }

                    if (iEv == 19 && iK <= 10)
                    {
                        outlineString = GetOutline(x - FontHeight / 2 + 8, y - FontHeight / 2, ke.KText[0], outlineFontname, outlineEncoding, 38, 0, 262);
                    }

                    if (!isJp)
                    {
                        y += 2;
                    }

                    double t0 = ev.Start - 0.5 + iK * 0.07;
                    double t1 = t0 + 0.5;
                    double t2 = kStart;
                    double t3 = kEnd;
                    double t4 = ev.End - 0.6 + iK * 0.07;
                    double t5 = t4 + 0.5;

                    int lumsz = 12;
                    if (iEv == 9 && iK == 2)
                    {
                        lumsz = 18;
                    }
                    if (iEv == 1 || iEv == 2)
                    {
                        lumsz = 15;
                    }
                    ASSPointF[] lums = new ASSPointF[1];
                    for (int i = 0; i < lums.Length; i++)
                    {
                        lums[i] = new ASSPointF {
                            X = Common.RandomDouble(rnd, x_an7 - 2, x0), Y = Common.RandomDouble(rnd, y - 18, y + 18)
                        }
                    }
                    ;
                    string[] lumcols   = { "002BC8" };
                    string[] lumalphas = { "00" };

                    string shadCol1 = "000000";
                    if (!isJp)
                    {
                        shadCol1 = "FFFFFF";
                    }
                    string shadCol2 = "FFFFFF";

                    string lightCol = "6888FF";

                    if (isJp)
                    {
                        ass_out.AppendEvent(50, evStyle, t2 - 0.15, t3 - 0.15,
                                            pos(x + 1, y + 2) + fad(0.1, Common.Min(0.3, t3 - t2 - 0.2)) + fsc(150, 150) + t(fsc(100, 100).t()) +
                                            a(1, "00") + a(3, "66") + c(3, lumcols[0]) + bord(3) + blur(3) +
                                            ke.KText);
                        ass_out.AppendEvent(8, evStyle, t0, t2 + 0.8,
                                            pos(x + 2, y + 2) + fad(0.8, 0.8) +
                                            a(1, "77") + c(1, shadCol1) + blur(2) +
                                            ke.KText);
                        ass_out.AppendEvent(8, evStyle, t2, t5 - 0.5,
                                            pos(x + 2, y + 2) + fad(0.8, 0.8) +
                                            a(1, "00") + c(1, shadCol2) + blur(2) +
                                            ke.KText);
                    }
                    else
                    {
                        ass_out.AppendEvent(8, evStyle, t0, t5 - 0.5,
                                            pos(x + 2, y + 2) + fad(0.8, 0.8) +
                                            a(1, "00") + c(1, shadCol1) + blur(2) +
                                            ke.KText);
                    }

                    for (int iLum = 0; iLum < lums.Length; iLum++)
                    {
                        string col1   = lumcols[iLum];
                        double lum1_x = lums[iLum].X;
                        double lum1_y = lums[iLum].Y;
                        for (int i = 0; i < 2; i++)
                        {
                            ass_out.AppendEvent(20, "pt", t0, t1,
                                                an(5) +
                                                clip(4, outlineString) + pos(lum1_x, lum1_y) +
                                                a(1, lumalphas[iLum]) + a(3, "00") + c(1, col1) + c(3, col1) +
                                                t(bord(lumsz).t() + blur(lumsz).t()) +
                                                @"{\p1}m 0 0 l 1 0 1 1 0 1");
                            ass_out.AppendEvent(20, "pt", t1, t4,
                                                an(5) +
                                                clip(4, outlineString) + pos(lum1_x, lum1_y) +
                                                a(1, lumalphas[iLum]) + a(3, "00") + c(1, col1) + c(3, col1) +
                                                blur(lumsz) + bord(lumsz) +
                                                @"{\p1}m 0 0 l 1 0 1 1 0 1");
                            ass_out.AppendEvent(20, "pt", t4, t5,
                                                an(5) +
                                                clip(4, outlineString) + pos(lum1_x, lum1_y) +
                                                a(1, lumalphas[iLum]) + a(3, "00") + c(1, col1) + c(3, col1) +
                                                blur(lumsz) + bord(lumsz) +
                                                t(bord(0).t() + blur(0).t()) +
                                                @"{\p1}m 0 0 l 1 0 1 1 0 1");
                        }
                    }

                    if (!isJp)
                    {
                        continue;
                    }

                    /*if (iEv == 9)
                     * {
                     *  string strikeCol = "FF68AD";
                     *  for (int j = 0; j < 40; j++)
                     *  {
                     *      for (int i = 0; i < 20; i++)
                     *      {
                     *          double ptt0 = t2 - 0.3 + i * 0.01;
                     *          double ptt1 = ptt0 + 0.3;
                     *          string ptCol1 = Common.scaleColor(strikeCol, "FFFFFF", 1 - (double)i / 19.0 * 0.5);
                     *          string ptAlpha = "77";
                     *          if (i >= 17) ptAlpha = "00";
                     *          int ag1 = j * 9 + (int)(((double)i * 0.01) * 360);
                     *          int ag2 = ag1 + 360;
                     *          ass_out.AppendEvent(0 + i / 2, "pt", ptt0, ptt1,
                     *              move(x + 50, y, x + 50, y - 50) + org(x, y) + blur(2.3 - i * 0.07) + a(1, ptAlpha) + a(3, ptAlpha) + frz(-ag1) +
                     *              c(1, ptCol1) + c(3, ptCol1) + t(0, 0.1, fscx(250 - 10 * i).t()) + fscy(100 - i * 5) + t(frz(-ag2).t()) +
                     *              p(3) + "m 100 0 b 20 10 -20 10 -100 0 -20 -10 20 -10 100 0");
                     *      }
                     *  }
                     * }*/
                    if (iEv == 0)
                    {
                        foreach (ASSPoint pt in mask.Points)
                        {
                            double ag  = (double)(pt.Y - mask.Y0) / (double)mask.Height * 0.25;
                            int    iag = (int)(ag / Math.PI / 2 * 360);
                            ass_out.AppendEvent(70, "pt", t2 - 0.2, t5,
                                                pos(pt.X, pt.Y) + frz(iag) + t(fry(180).t()) + fad(0.1, 0.5) +
                                                a(1, "F4") + c(1, lightCol) + be(1) +
                                                @"{\p2}m 0 0 l -200 0 0 2");
                        }
                    }
                    if (iEv == 1 || iEv == 2)
                    {
                        double ptt0 = t2 - 0.2;
                        double ptt1 = t3 - 0.2;
                        double ptt2 = t3 + 2;
                        if (ptt2 > t4)
                        {
                            ptt2 = t4;
                        }
                        ass_out.AppendEvent(5, "pt", ptt0, ptt2,
                                            pos(x, y) + an(5) + blur(2) + bord(2) + fad(0.3, 0.5) +
                                            a(1, "00") + c(1, "FFFFFF") + fsc(50, 50) +
                                            t(0, 0.01, fsc(130, 130).t()) +
                                            t(ptt1 - ptt0 - 0.3, ptt1 - ptt0, fsc(70, 70).t() + a(1, "AA").t()) +
                                            a(3, "44") + c(3, "FF68AD") + t(frz((int)((ptt2 - ptt0) * ((((iEv + iK) % 2 == 1) ? 100 : -100)))).t()) +
                                            p(2) + "m 64 14 b 66 10 67 5 66 1 b 59 0 50 0 46 2 b 45 6 47 10 48 15 b 42 15 37 17 32 21 b 31 18 27 13 24 11 b 18 15 14 20 10 25 b 13 29 17 31 21 32 b 17 38 14 43 14 49 b 10 47 5 46 1 47 b 0 53 0 60 1 67 b 5 68 10 66 14 64 b 15 70 17 76 20 81 b 17 83 13 85 10 88 b 13 94 18 98 25 103 b 27 101 31 96 32 92 b 36 95 42 98 48 99 b 47 103 46 107 46 112 b 53 113 59 113 66 112 b 66 107 66 104 64 99 b 70 98 75 95 81 92 b 81 95 84 100 88 103 b 93 100 99 94 102 88 b 99 85 95 83 92 81 b 95 76 97 70 98 65 b 103 66 106 68 111 67 b 113 60 113 55 111 47 b 107 46 103 48 98 49 b 97 44 95 38 92 32 b 95 31 100 29 102 25 b 98 19 94 15 88 11 b 85 13 82 18 81 21 b 76 18 70 15 64 14 l 55 37 b 68 38 75 45 76 57 b 76 68 68 76 56 77 b 44 75 37 68 36 57 b 37 45 44 38 55 37 l 59 37 l 66 15 l 64 14");
                    }
                    if (iEv == 3 || iEv == 4)
                    {
                        string strikeCol = "FF68AD";
                        if (iEv == 3)
                        {
                            for (int i = 0; i < 20; i++)
                            {
                                double ptt0    = t2 - 0.3 + i * 0.01;
                                double ptt1    = ptt0 + 0.3;
                                string ptCol1  = Common.scaleColor(strikeCol, "FFFFFF", (double)i / 19.0 * 0.8);
                                string ptCol2  = Common.scaleColor(strikeCol, "FFFFFF", (double)i / 19.0 * 0.5);
                                string ptAlpha = "77";
                                if (i >= 17)
                                {
                                    ptAlpha = "00";
                                }
                                ass_out.AppendEvent(15, "pt", ptt0, ptt1,
                                                    pos(x, y) + blur(2.3 - i * 0.07) + a(1, ptAlpha) + a(3, ptAlpha) + frz(90) +
                                                    c(1, ptCol1) + c(3, ptCol1) + t(0, 0.1, fscx(500 - 20 * i).t()) + fscy(100 - i * 5) +
                                                    p(3) + "m 100 0 b 20 10 -20 10 -100 0 -20 -10 20 -10 100 0");
                            }
                        }
                        else if (iEv == 4)
                        {
                            for (int j = 0; j < 4; j++)
                            {
                                if ((iEv + iK + (j / 2)) % 2 == 0)
                                {
                                    continue;
                                }
                                string ptStr = "m 100 0 b 20 10 -20 10 -100 0 -20 -10 20 -10 100 0";
                                if (j >= 2)
                                {
                                    ptStr = "m 0 -100 b 10 -20 10 20 0 100 -10 20 -10 -20 0 -100";
                                }
                                Func <double, ASSPointF> fpos = ti => new ASSPointF();
                                if (j == 2)
                                {
                                    fpos = ti => new ASSPointF {
                                        X = x - 20, Y = y + ti * 200
                                    }
                                }
                                ;
                                else if (j == 3)
                                {
                                    fpos = ti => new ASSPointF {
                                        X = x + 20, Y = y - ti * 200
                                    }
                                }
                                ;
                                else if (j == 0)
                                {
                                    fpos = ti => new ASSPointF {
                                        X = x + ti * 200, Y = y - 20
                                    }
                                }
                                ;
                                else if (j == 1)
                                {
                                    fpos = ti => new ASSPointF {
                                        X = x - ti * 200, Y = y + 20
                                    }
                                }
                                ;
                                for (int i = 0; i < 20; i++)
                                {
                                    double ptt0    = t2 - 0.3 + i * 0.01;
                                    double ptt1    = ptt0 + 0.3;
                                    string ptCol1  = Common.scaleColor(strikeCol, "FFFFFF", (double)i / 19.0 * 0.8);
                                    string ptCol2  = Common.scaleColor(strikeCol, "FFFFFF", (double)i / 19.0 * 0.5);
                                    string ptAlpha = "77";
                                    if (i >= 17)
                                    {
                                        ptAlpha = "00";
                                    }
                                    ass_out.AppendEvent(15, "pt", ptt0, ptt1,
                                                        move(fpos(ptt0 - t2 + 0.3 - 0.3), fpos(ptt1 - t2 + 0.3)) + blur(2.3 - i * 0.07) + a(1, ptAlpha) + a(3, ptAlpha) +
                                                        c(1, ptCol1) + c(3, ptCol1) + ((j <= 1) ? (t(0, 0.1, fscx(500 - 20 * i).t()) + fscy(100 - i * 5)) : (t(0, 0.1, fscy(500 - 20 * i).t()) + fscx(100 - i * 5))) +
                                                        p(3) + ptStr);
                                }
                            }
                        }
                        {
                            double ptt0 = t2 - 0.2;
                            double ptt1 = t3 - 0.2;
                            double ptt2 = t3 + 2;
                            if (ptt2 > t4)
                            {
                                ptt2 = t4;
                            }
                            ass_out.AppendEvent(5, "pt", ptt0, ptt2,
                                                pos(x, y + 15) + an(5) + blur(2) + bord(2) + fad(0.3, 0.5) +
                                                a(1, "00") + c(1, "FFFFFF") + fsc(50, 50) + frx(60) +
                                                t(0, 0.01, fsc(130, 130).t()) +
                                                t(ptt1 - ptt0 - 0.3, ptt1 - ptt0, fsc(70, 70).t() + a(1, "77").t()) +
                                                a(3, "44") + c(3, "FF68AD") + t(frz((int)((ptt2 - ptt0) * ((((iEv + iK) % 2 == 1) ? 100 : -100)))).t()) +
                                                p(2) + "m 64 14 b 66 10 67 5 66 1 b 59 0 50 0 46 2 b 45 6 47 10 48 15 b 42 15 37 17 32 21 b 31 18 27 13 24 11 b 18 15 14 20 10 25 b 13 29 17 31 21 32 b 17 38 14 43 14 49 b 10 47 5 46 1 47 b 0 53 0 60 1 67 b 5 68 10 66 14 64 b 15 70 17 76 20 81 b 17 83 13 85 10 88 b 13 94 18 98 25 103 b 27 101 31 96 32 92 b 36 95 42 98 48 99 b 47 103 46 107 46 112 b 53 113 59 113 66 112 b 66 107 66 104 64 99 b 70 98 75 95 81 92 b 81 95 84 100 88 103 b 93 100 99 94 102 88 b 99 85 95 83 92 81 b 95 76 97 70 98 65 b 103 66 106 68 111 67 b 113 60 113 55 111 47 b 107 46 103 48 98 49 b 97 44 95 38 92 32 b 95 31 100 29 102 25 b 98 19 94 15 88 11 b 85 13 82 18 81 21 b 76 18 70 15 64 14 l 55 37 b 68 38 75 45 76 57 b 76 68 68 76 56 77 b 44 75 37 68 36 57 b 37 45 44 38 55 37 l 59 37 l 66 15 l 64 14");
                        }
                    }
                    if (iEv >= 5 && iEv <= 9)
                    {
                        string strikeCol = "FF68AD";
                        double ptt0      = t2 - 0.3;
                        double ptt1      = t3 - 0.2 - 0.1;
                        if (ptt1 > t4)
                        {
                            ptt1 = t4;
                        }
                        double           theta1 = Common.RandomDouble(rnd, 0, Math.PI);
                        List <BaseCurve> curves = new List <BaseCurve>();
                        Circle2          cl     = new Circle2 {
                            X0 = x, Y0 = y, A = 60, B = 27, MinT = 0 + ptt0 * 4, MaxT = (ptt1 - ptt0) * Math.PI * 2 + ptt0 * 4, Theta = theta1, dTheta = 0
                        };
                        CompositeCurve cc = new CompositeCurve {
                            MinT = ptt0, MaxT = ptt1
                        };
                        cc.AddCurve(cc.MinT, cc.MaxT, cl);
                        curves.Add(cc);
                        cl = new Circle2 {
                            X0 = x, Y0 = y, A = 60, B = 27, MinT = 0 + ptt0 * 4 + Math.PI, MaxT = Math.PI + (ptt1 - ptt0) * Math.PI * 2 + ptt0 * 4, Theta = theta1, dTheta = 0
                        };
                        cc = new CompositeCurve {
                            MinT = ptt0, MaxT = ptt1
                        };
                        cc.AddCurve(cc.MinT, cc.MaxT, cl);
                        curves.Add(cc);
                        for (int i = 0; i < curves.Count; i++)
                        {
                            BaseCurve        curve      = curves[i];
                            List <ASSPointF> path       = curve.GetPath_Dis(6, 7);
                            string           strikeCol2 = Common.scaleColor(strikeCol, "FFFFFF", 0.5);
                            foreach (ASSPointF pt in path)
                            {
                                ass_out.AppendEvent((pt.Theta < Math.PI) ? 0 : 100, "pt", pt.T, pt.T + 0.3,
                                                    pos(pt.X, pt.Y) + a(1, "44") + a(3, "77") + c(1, "FFFFFF") + c(3, "FFFFFF") +
                                                    bord(8) + blur(8) +
                                                    t(0, 0.04, c(1, strikeCol2).t() + c(3, strikeCol2).t() + bord(4).t() + blur(4).t()) +
                                                    t(0.04, 0.3, c(1, strikeCol).t() + c(3, strikeCol).t() + bord(2).t() + blur(2).t()) +
                                                    p(1) + "m 0 0 l 1 0 1 1 0 1");
                                ass_out.AppendEvent((pt.Theta < Math.PI) ? 0 : 100, "pt", pt.T, pt.T + 0.3,
                                                    pos(pt.X, pt.Y) + a(1, "44") + a(3, "44") + c(1, "FFFFFF") + c(3, "FFFFFF") +
                                                    bord(4) + blur(4) +
                                                    t(0, 0.04, bord(2.5).t() + blur(2.5).t()) +
                                                    t(0.04, 0.3, bord(1.3).t() + blur(1.3).t()) +
                                                    p(1) + "m 0 0 l 1 0 1 1 0 1");
                            }
                        }
                        for (int j = 0; j < 10; j++)
                        {
                            double             dz    = Common.RandomDouble(rnd, -30, 30);
                            Func <double, int> fz    = ti => (int)((theta1 + Math.PI * 0.5) / Math.PI / 2.0 * 360.0 + dz * (ptt1 - ti) / (ptt1 - ptt0));
                            string             ptStr = "m 100 0 b 20 10 -20 10 -100 0 -20 -10 20 -10 100 0";
                            for (int i = 0; i < 20; i++)
                            {
                                double pttt0   = ptt0 + i * 0.01;
                                double pttt1   = ptt1;
                                string ptCol1  = Common.scaleColor(strikeCol, "FFFFFF", (double)i / 19.0 * 0.8);
                                string ptCol2  = Common.scaleColor(strikeCol, "FFFFFF", (double)i / 19.0 * 0.5);
                                string ptAlpha = "77";
                                if (i >= 17)
                                {
                                    ptAlpha = "00";
                                }
                                ass_out.AppendEvent(0 + i, "pt", pttt0, pttt1,
                                                    fad(0, 0.5) + pos(x, y) + blur(2.3 - i * 0.07) + a(1, ptAlpha) + a(3, ptAlpha) + frz(fz(pttt0)) +
                                                    c(1, ptCol1) + c(3, ptCol1) + t(0, 0.1, fscx(500 - 20 * i).t()) + fscy(100 - i * 5) + t(0, (pttt1 - pttt0) * 0.9, frz(fz(pttt1)).t()) +
                                                    p(3) + ptStr);
                            }
                        }
                    }
                }
            }

            Console.WriteLine(ass_out.Events.Count);
            ass_out.SaveFile(this.OutFileName);
        }
    }
}
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            Random rnd = new Random();

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                bool     isJp = iEv <= 23;
                ASSEvent ev   = ass_in.Events[iEv];
                if (!isJp)
                {
                    ev.Start = ass_in.Events[iEv - 24].Start;
                    ev.End   = ass_in.Events[iEv - 24].End;
                }
                ass_out.Events.Add(ev);
            }

            /*
             * for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
             * {
             *  int jEv = -1;
             *  if (iEv >= 535 && iEv <= 558) jEv = iEv - 535;
             *  if (iEv >= 559 && iEv <= 582) jEv = iEv - 559;
             *  if (jEv < 0) continue;
             *  ASSEvent ev = ass_in.Events[iEv];
             *  ev.Text = ev.Text.Replace(@"{\fad(150,150)}", "");
             *  string stmp = "";
             *  bool inb = false;
             *  foreach (char ch in ev.Text)
             *  {
             *      if (ch == '{') inb = true;
             *      if (!inb) stmp += ch;
             *      if (ch == '}') inb = false;
             *  }
             *  ev.Text = stmp;
             *  Console.WriteLine(ev.Text);
             *
             *  string c0 = "DA9500";
             *  string c1 = "5DFA49";
             *
             *  if (jEv == 6)
             *  {
             *      c0 = "B967FF";
             *      c1 = "F1E3FE";
             *  }
             *  if (jEv == 5)
             *  {
             *      c0 = "FFDF5D";
             *      c1 = "FFF5CA";
             *  }
             *  if (jEv == 7)
             *  {
             *      c0 = "60FF5C";
             *      c1 = "CEFFCF";
             *  }
             *  if (jEv == 8)
             *  {
             *      c0 = "5BB0FF";
             *      c1 = "DAEEFD";
             *  }
             *  if (jEv == 9)
             *  {
             *      c0 = "7E76FF";
             *      c1 = "D6D2FF";
             *  }
             *  if (jEv == 10)
             *  {
             *      c0 = "FF59C0";
             *      c1 = "FFD8F1";
             *  }
             *  if (jEv == 11)
             *  {
             *      c0 = "0CC6FD";
             *      c1 = "B3EDFD";
             *  }
             *  if (jEv == 12)
             *  {
             *      c0 = "E76298";
             *      c1 = "E1D3DA";
             *  }
             *  if (jEv >= 5 && jEv <= 12) c1 = c0;
             *
             *  StringBuilder sb = new StringBuilder();
             *  sb.Append(fad(0.25, 0.25) + a(1, "00") + c(1, "FFFFFF") + a(4, "FF") + a(3, "33") + bord(2.5) + blur(3.2));
             *  for (int iCh = 0; iCh < ev.Text.Length; iCh++)
             *  {
             *      char ch = ev.Text[iCh];
             *      string cc = Common.scaleColor(c0, c1, (double)iCh / (double)(ev.Text.Length - 1));
             *      sb.Append(c(3, cc) + ch);
             *  }
             *
             *  //ass_out.AppendEvent(0, ev.Style, ev.Start, ev.End, ev.Text);
             *  ass_out.AppendEvent(0, ev.Style, ev.Start, ev.End, sb.ToString());
             * }
             * */

            ass_out.SaveFile(OutFileName);
        }
Example #14
0
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            string ptString = @"{\p8}m 0 0 l 128 0 128 128 0 128";

            string[] colString = { "4BFCCC", "CE8046", "52065D", "8F0036", "33AE52", "6ADB57" };
            colString = colString.Select(s => ASSColor.HtmlToASS(s)).ToArray();

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                Console.WriteLine("{0} / {1}", iEv + 1, ass_in.Events.Count);

                ASSEvent        ev     = ass_in.Events[iEv];
                List <KElement> kelems = ev.SplitK(true);

                /// an7 pos
                int x0 = (PlayResX - GetTotalWidth(ev)) / 2;
                int y0 = PlayResY - MarginBottom - FontHeight;

                Random rnd = new Random();

                int kSum = 0;

                string col0  = colString[iEv % colString.Length];
                string col1  = (iEv >= 7 && iEv <= 10) ? "CCCCCC" : "CCCCCC";
                string col20 = "FFFFFF";
                string col21 = "CCCCCC";
                string col22 = "888888";
                string col23 = "444444";
                string col24 = "111111";
                if (iEv >= 7 && iEv <= 10)
                {
                    col20 = "111111";
                    col21 = "444444";
                    col23 = "CCCCCC";
                    col24 = "FFFFFF";
                }

                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    KElement ke = kelems[iK];
                    double   r  = (double)iK / (double)(kelems.Count - 1);
                    Size     sz = GetSize(ke.KText);

                    /// an5 pos
                    int x = x0 + this.FontSpace + sz.Width / 2;
                    int y = y0 + FontHeight;

                    int        mask_x0 = x0 + 2;
                    int        mask_y0 = y0 + 0;
                    StringMask mask    = GetMask(ke.KText, mask_x0, mask_y0);
                    if (ke.KText == "ト")
                    {
                        mask = GetMask(ke.KText, mask_x0 + 3, mask_y0);
                    }
                    if (ke.KText == "ル")
                    {
                        mask = GetMask(ke.KText, mask_x0 + 1, mask_y0);
                    }
                    if (ke.KText == "ば")
                    {
                        mask = GetMask(ke.KText, mask_x0 + 1, mask_y0);
                    }
                    if (ke.KText == "し")
                    {
                        mask = GetMask(ke.KText, mask_x0 + 1, mask_y0);
                    }
                    if (ke.KText == "ダ")
                    {
                        mask = GetMask(ke.KText, mask_x0 + 1, mask_y0);
                    }
                    if (ke.KText == "ユ")
                    {
                        mask = GetMask(ke.KText, mask_x0 + 1, mask_y0);
                    }
                    if (ke.KText == "ン")
                    {
                        mask = GetMask(ke.KText, mask_x0, mask_y0);
                    }
                    if (ke.KText == "ざ")
                    {
                        mask = GetMask(ke.KText, mask_x0, mask_y0);
                    }
                    if (ke.KText == "に")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "浮")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "な")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "く")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "の")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "肩")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "を")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "て")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "テ")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "熱")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "る")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "こ")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "読")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "ま")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "さ")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "波")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "時")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "間")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "柄")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }
                    if (ke.KText == "焼")
                    {
                        mask = GetMask(ke.KText, mask_x0 - 1, mask_y0);
                    }

                    x0 += this.FontSpace + sz.Width;
                    y0  = y0;

                    double kStart = ev.Start + kSum * 0.01;
                    kSum += ke.KValue;
                    double kEnd = ev.Start + kSum * 0.01;

                    double t0 = ev.Start + r * 1.0 - 1.0;
                    double t1 = t0 + 0.2;
                    double t2 = t0 + 0.4;
                    double t3 = t0 + 0.6;
                    double t4 = t0 + 0.8;
                    double t5 = kStart - 0.1;
                    double t6 = kStart + 0.05;
                    double t7 = kStart + 0.15;
                    double t8 = kStart + 0.3;
                    double t9 = ev.End + r * 1.0 - 1.0;
                    double tA = t9 + 0.4;

                    ass_out.Events.Add(
                        ev.StyleReplace("bd").StartReplace(t5).EndReplace(t7).TextReplace(
                            ASSEffect.pos(x, y) + ASSEffect.fad(t6 - t5, 0) + ASSEffect.bord(15) +
                            ASSEffect.a(1, "FF") + ASSEffect.c(3, col0) + ASSEffect.blur(10) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StyleReplace("bd").StartReplace(t7).EndReplace(t8 + 0.15).TextReplace(
                            ASSEffect.pos(x, y) + ASSEffect.bord(15) + ASSEffect.fad(0, t8 + 0.15 - t7) +
                            ASSEffect.a(1, "FF") + ASSEffect.c(3, col0) + ASSEffect.blur(10) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StyleReplace("bd").StartReplace(t7).EndReplace(t8 + 0.15).TextReplace(
                            ASSEffect.pos(x, y) + ASSEffect.fad(t8 + 0.15 - t7, 0) +
                            ASSEffect.a(1, "FF") + ASSEffect.c(3, col0) + ASSEffect.blur(10) + ASSEffect.a(3, "77") +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StyleReplace("bd").StartReplace(t8 + 0.15).EndReplace(t9).TextReplace(
                            ASSEffect.pos(x, y) +
                            ASSEffect.a(1, "FF") + ASSEffect.c(3, col0) + ASSEffect.blur(10) + ASSEffect.a(3, "77") +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StyleReplace("bd").StartReplace(t9).EndReplace(tA).TextReplace(
                            ASSEffect.pos(x, y) + ASSEffect.fad(0, tA - t9) +
                            ASSEffect.a(1, "FF") + ASSEffect.c(3, col0) + ASSEffect.blur(10) + ASSEffect.a(3, "77") +
                            ke.KText));

                    ass_out.Events.Add(
                        ev.StartReplace(kEnd - 0.1).EndReplace(t9).TextReplace(
                            ASSEffect.pos(x, y) + ASSEffect.fad(t9 - kEnd + 0.1, 0) +
                            ASSEffect.a(3, "FF") + ASSEffect.c(1, col0) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t9).EndReplace(tA).TextReplace(
                            ASSEffect.pos(x, y) + ASSEffect.fad(0, tA - t9) +
                            ASSEffect.a(3, "FF") + ASSEffect.c(1, col0) +
                            ke.KText));

                    ass_out.Events.Add(
                        ev.StartReplace(t0).EndReplace(t1).TextReplace(
                            ASSEffect.move(x, y, x, y - 75) + ASSEffect.a(1, "FF") + ASSEffect.a(3, "FF") + ASSEffect.blur(1) + ASSEffect.c(3, col20) +
                            ASSEffect.t(0, t1 - t0, ASSEffect.a(3, "C0").t() + ASSEffect.frx(180).t() + ASSEffect.c(3, col21).t()) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t1).EndReplace(t2).TextReplace(
                            ASSEffect.move(x, y - 75, x, y) + ASSEffect.a(1, "FF") + ASSEffect.a(3, "C0") + ASSEffect.frx(180) + ASSEffect.blur(1) + ASSEffect.c(3, col21) +
                            ASSEffect.t(0, t2 - t1, ASSEffect.a(3, "80").t() + ASSEffect.frx(360).t() + ASSEffect.c(3, col22).t()) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t2).EndReplace(t3).TextReplace(
                            ASSEffect.move(x, y, x, y - 75) + ASSEffect.a(1, "FF") + ASSEffect.a(3, "80") + ASSEffect.blur(1) + ASSEffect.c(3, col22) +
                            ASSEffect.t(0, t3 - t2, ASSEffect.a(3, "40").t() + ASSEffect.frx(180).t() + ASSEffect.c(3, col23).t()) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t3).EndReplace(t4).TextReplace(
                            ASSEffect.move(x, y - 75, x, y) + ASSEffect.a(1, "FF") + ASSEffect.a(3, "40") + ASSEffect.frx(180) + ASSEffect.blur(1) + ASSEffect.c(3, col23) +
                            ASSEffect.t(0, t4 - t3, ASSEffect.a(3, "00").t() + ASSEffect.frx(360).t() + ASSEffect.c(3, col24).t() + ASSEffect.blur(1).t()) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t4).EndReplace(t5).TextReplace(
                            ASSEffect.pos(x, y) + ASSEffect.c(3, col24) +
                            ASSEffect.a(1, "FF") + ASSEffect.blur(1) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t5).EndReplace(t8 + 0.1).TextReplace(
                            ASSEffect.pos(x, y) +
                            ASSEffect.a(1, "FF") + ASSEffect.t(0, t8 + 0.1 - t5, ASSEffect.c(3, col20).t() + ASSEffect.fry(360 * 3).t()) + ASSEffect.blur(1) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t8 + 0.1).EndReplace(t9).TextReplace(
                            ASSEffect.pos(x, y) +
                            ASSEffect.a(1, "FF") + ASSEffect.c(3, col20) + ASSEffect.blur(1) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t9).EndReplace(tA).TextReplace(
                            ASSEffect.pos(x, y) +
                            ASSEffect.a(1, "FF") + ASSEffect.c(3, col20) + ASSEffect.blur(1) +
                            ASSEffect.fad(0, tA - t9) + ASSEffect.t(0, tA - t9, ASSEffect.fry(700).t()) +
                            ke.KText));

                    foreach (ASSPoint pt in mask.Points)
                    {
                        double ptx0  = Common.RandomInt_Gauss(rnd, pt.X, 10);
                        double pty0  = Common.RandomInt_Gauss(rnd, pt.Y - 60, 10);
                        double ptx1  = Common.RandomInt_Gauss(rnd, pt.X - 60, 20);
                        double pty1  = Common.RandomInt_Gauss(rnd, pt.Y, 10);
                        double pt_kt = ((double)(pt.X - mask.X0) / (double)mask.Width) * (kEnd - kStart) + kStart;
                        double ptt0  = Common.RandomDouble(rnd, pt_kt - 0.4, pt_kt);
                        double ptt1  = Common.RandomDouble(rnd, ptt0 + 0.25, ptt0 + 0.45);
                        double ptt2  = ev.End - 1.0 * (1.0 - r) + 0.3 * (double)(pt.Y - y0) / (double)FontHeight + Common.RandomDouble(rnd, 0, 0.2);
                        double ptt3  = Common.RandomDouble(rnd, ptt2 + 0.25, ptt2 + 0.45);
                        string ptcol = Common.scaleColor(col0, col1, (double)(pt.Y - y0) / (double)FontHeight);

                        ass_out.Events.Add(
                            ev.StartReplace(ptt0).EndReplace(ptt1).StyleReplace("pt").TextReplace(
                                ASSEffect.move(ptx0, pty0, pt.X, pt.Y) +
                                ASSEffect.a(1, Common.ToHex2(255 - pt.Brightness)) + ASSEffect.c(1, ptcol) +
                                ASSEffect.fad(0.4 * (ptt1 - ptt0), 0) +
                                ptString
                                ));
                        ass_out.Events.Add(
                            ev.StartReplace(ptt1).EndReplace(ptt2).StyleReplace("pt").TextReplace(
                                ASSEffect.pos(pt.X, pt.Y) +
                                ASSEffect.a(1, Common.ToHex2(255 - pt.Brightness)) + ASSEffect.c(1, ptcol) +
                                ptString
                                ));
                        ass_out.Events.Add(
                            ev.StartReplace(ptt2).EndReplace(ptt3).StyleReplace("pt").TextReplace(
                                ASSEffect.move(pt.X, pt.Y, ptx1, pty1) +
                                ASSEffect.a(1, Common.ToHex2(255 - pt.Brightness)) + ASSEffect.c(1, ptcol) +
                                ASSEffect.fad(0, ptt3 - ptt2) +
                                ptString
                                ));
                    }
                }
            }
            ass_out.SaveFile(OutFileName);
        }
Example #15
0
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            Random rnd = new Random();

            string col0   = "96726A";
            string col1   = "D17C6A";
            string ptcol2 = "644BFF";
            string ptcol1 = "5BFF4B";
            string ptstr  = @"{\p1}m 0 0 l 1 0 1 1 0 1";

            string[] ptcollist =
            {
                "5A3AFF",
                "3A5BFF",
                "FF3A5D",
                "3AFF4E",
                "FF3AD9",
                "FFD13A"
            };
            string lastptcol = "";

            string[] firestr =
            {
                @"{\p5}m 0 0 b 8 1 9 -28 -2 -41 b 3 -23 -17 0 0 0",
                @"{\p5}m 1 41 b 20 39 1 13 13 -11 b 5 1 -18 22 1 41",
                @"{\p4}m 6 39 b 4 29 1 13 27 -37 b -1 -3 -15 34 6 39",
                @"{\p5}m -3 43 b -9 22 -1 33 16 -47 b 1 3 -17 0 -3 43"
            };

            string spstr = @"{\p1}m 3 0 b 7 0 12 0 16 0 b 19 0 19 2 16 2 b 12 2 7 2 3 2 b 0 2 0 0 3 0{\p0}";

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                //if (iEv > 0) continue;
                ASSEvent        ev     = ass_in.Events[iEv];
                List <KElement> kelems = ev.SplitK(false);

                int x0      = MarginLeft;
                int startx0 = x0;
                int y0      = PlayResY - MarginBottom - FontHeight;
                int kSum    = 0;

                List <ASSPointF> poslist = new List <ASSPointF>();

                string ptcol = ptcollist[Common.RandomInt(rnd, 0, ptcollist.Length - 1)];
                while (ptcol == lastptcol)
                {
                    ptcol = ptcollist[Common.RandomInt(rnd, 0, ptcollist.Length - 1)];
                }
                lastptcol = ptcol;

                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                    KElement ke     = kelems[iK];
                    double   r      = (double)iK / (double)(kelems.Count - 1);
                    Size     sz     = GetSize(ke.KText);
                    double   kStart = ev.Start + kSum * 0.01;
                    double   kEnd   = kStart + ke.KValue * 0.01;
                    kSum += ke.KValue;
                    int        x    = x0 + this.FontSpace + sz.Width / 2;
                    int        y    = y0 + FontHeight / 2;
                    StringMask mask = GetMask(ke.KText, x, y);
                    x0 += this.FontSpace + sz.Width;
                    y0  = y0;
                    if (ke.KText.Trim().Length == 0)
                    {
                        continue;
                    }
                    poslist.Add(new ASSPointF {
                        X = x, Y = y, Start = kStart, End = kEnd
                    });

                    double t0 = ev.Start - 0.5 + iK * 0.05;
                    double t1 = t0 + 0.3;
                    double t2 = kStart;
                    double t3 = kEnd;
                    double t4 = ev.End - 0.5 + iK * 0.05;
                    double t5 = t4 + 0.3;

                    ass_out.AppendEvent(60, "Default", t0, t1,
                                        pos(x, y) + frz(-30) + a(1, "00") +
                                        fad((t1 - t0) * 0.5, 0) + fsc(130, 200) + blur(3) + bord(0) +
                                        t(0, t1 - t0, frz(0).t() + fsc(100, 100).t() + c(1, col0).t() + blur(0).t()) +
                                        ke.KText);
                    ass_out.AppendEvent(50, "Default", t1, t2,
                                        pos(x, y) + a(1, "00") + c(1, col0) +
                                        ke.KText);
                    ass_out.AppendEvent(60, "Default", t2, t3,
                                        pos(x, y) + a(1, "00") + a(3, "00") + c(3, col1) +
                                        bord(4) + blur(4) + fsc(200, 200) +
                                        t(0, t3 - t2, fsc(110, 110).t() + bord(2).t() + blur(2).t()) +
                                        ke.KText);
                    ass_out.AppendEvent(30, "Default", t2, t4,
                                        pos(x, y) + a(1, "FF") + a(3, "44") +
                                        bord(2) + blur(2) +
                                        fad(0.3, 0.1) +
                                        ke.KText);
                    ass_out.AppendEvent(50, "Default", t3, t4,
                                        pos(x, y) + a(1, "00") + c(1, "FFFFFF") + a(3, "00") +
                                        c(3, col1) + bord(1) +
                                        ke.KText);
                    ass_out.AppendEvent(40, "Default", t4, t5,
                                        pos(x, y) + a(1, "00") + c(1, "FFFFFF") + a(3, "FF") +
                                        bord(0) + blur(0) + fad(0, t5 - t4) +
                                        t(0, t5 - t4, frz(30).t() + fsc(130, 200).t() + blur(4).t()) +
                                        ke.KText);

                    //continue;
                    for (int i = 0; i < (t2 - t1) * 100; i++)
                    {
                        ASSPoint pt     = mask.Points[Common.RandomInt(rnd, 0, mask.Points.Count - 1)];
                        double   ptx    = pt.X;
                        double   pty    = pt.Y;
                        double   ptt0   = Common.RandomDouble(rnd, t1, t2);
                        double   ptt1   = ptt0 + 0.3;
                        int      tmpz   = Common.RandomInt(rnd, 0, 359);
                        string   tmpstr = firestr[Common.RandomInt(rnd, 0, firestr.Length - 1)];
                        ass_out.AppendEvent(100, "pt", ptt0, ptt1,
                                            move(ptx, pty, ptx, pty - 20) + a(1, "D0") + c(1, "B79E8A") +
                                            a(3, "C0") + c(3, "B79E8A") + bord(3) + blur(3) +
                                            frz(tmpz) +
                                            t(0, ptt1 - ptt0, fsc(80, 80).t() + bord(1).t() + frx(0).t() + fry(361).t() + frz(-57).t()) +
                                            tmpstr);
                    }
                    for (int i = 0; i < (t4 - t3) * 100; i++)
                    {
                        ASSPoint pt     = mask.Points[Common.RandomInt(rnd, 0, mask.Points.Count - 1)];
                        double   ptx    = pt.X;
                        double   pty    = pt.Y;
                        double   ptt0   = Common.RandomDouble(rnd, t3, t4);
                        double   ptt1   = ptt0 + 0.3;
                        int      tmpz   = Common.RandomInt(rnd, 0, 359);
                        string   tmpstr = firestr[Common.RandomInt(rnd, 0, firestr.Length - 1)];
                        ass_out.AppendEvent(100, "pt", ptt0, ptt1,
                                            move(ptx, pty, ptx, pty - 20) + a(1, "D0") + c(1, "3D3EE7") + //354CB9
                                            a(3, "C0") + c(3, "3D3EE7") + bord(3) + blur(3) +
                                            frz(tmpz) +
                                            t(0, ptt1 - ptt0, fsc(80, 80).t() + bord(1).t() + frx(0).t() + fry(361).t() + frz(-57).t()) +
                                            tmpstr);
                    }
                }

                //continue;

                for (int i = 1; i < poslist.Count; i++)
                {
                    if (poslist[i].End - poslist[i].Start < 1e-8)
                    {
                        poslist[i - 1].End -= 0.1;
                        poslist[i].Start   -= 0.1;
                    }
                }

                for (int i = 0; i < 3; i++)
                {
                    /*
                     * if (i > 1) continue;
                     * CompositeCurve curve = new CompositeCurve() { MinT = ev.Start - 0.1, MaxT = ev.End + (PlayResX - x0) * 0.002 };
                     * bool lastup = i == 0;
                     * if (lastup)
                     *  curve.AddCurve(curve.MinT, ev.Start, new Line() { MinT = 0, MaxT = 1, X0 = 0, X1 = MarginLeft, Y0 = y0 - FontHeight * 0.5, Y1 = y0 - FontHeight * 0.5 });
                     * else
                     *  curve.AddCurve(curve.MinT, ev.Start, new Line() { MinT = 0, MaxT = 1, X0 = 0, X1 = MarginLeft, Y0 = y0 + FontHeight * 1.5, Y1 = y0 + FontHeight * 1.5 });
                     * string ptcol = lastup ? ptcol1 : ptcol2;
                     * double lastx1 = MarginLeft;
                     * double lasty1 = 0;
                     * double lastt = 0;
                     * foreach (ASSPointF pos in poslist)
                     * {
                     *  double thisx1 = pos.X + FontWidth / 2;
                     *  double yy0 = y0 - FontHeight * 0.5;
                     *  double yy1 = y0 + FontHeight * 1.5;
                     *  if (!lastup)
                     *  {
                     *      yy0 = y0 + FontHeight * 1.5;
                     *      yy1 = y0 - FontHeight * 0.5;
                     *  }
                     *  lastup = !lastup;
                     *  //curve.AddCurve(pos.Start, pos.End, new Line() { MinT = 0, MaxT = 1, X0 = lastx1, X1 = thisx1, Y0 = yy0, Y1 = yy1 });
                     *  curve.AddCurve(pos.Start, pos.End, Sine.Create(lastx1, yy0, thisx1, yy1));
                     *  lastx1 = thisx1;
                     *  lasty1 = yy1;
                     *  lastt = pos.End;
                     * }
                     * curve.AddCurve(lastt, curve.MaxT, new Line() { MinT = 0, MaxT = 1, X0 = lastx1, X1 = PlayResX, Y0 = lasty1, Y1 = lasty1 });
                     * */
                    CompoundCurve curve = new CompoundCurve()
                    {
                        MinT = ev.Start - 0.2, MaxT = ev.End + 1
                    };
                    curve.AddCurve(curve.MinT, curve.MaxT, new Circle()
                    {
                        X0 = 0, Y0 = 0, R = 30, MinT = 0 + i * 2.0 / 3.0 * Math.PI, MaxT = Math.PI * 2 * (curve.MaxT - curve.MinT) * 1.3 + i * 2.0 / 3.0 * Math.PI
                    });
                    CompositeCurve pathcurve = new CompositeCurve()
                    {
                        MinT = curve.MinT, MaxT = curve.MaxT
                    };
                    double lastx = 0;
                    double lastt = curve.MinT;
                    double yyy   = y0 + FontHeight * 0.5;
                    for (int j = 0; j < poslist.Count; j++)
                    {
                        double thist = poslist[j].Start;
                        double thisx = poslist[j].X;
                        pathcurve.AddCurve(lastt, thist, new Line()
                        {
                            X0 = lastx, X1 = thisx, Y0 = yyy, Y1 = yyy
                        });
                        if (j + 1 == poslist.Count)
                        {
                            thist = curve.MaxT;
                        }
                        else
                        {
                            thist = poslist[j + 1].Start - 0.2;
                            if (thist < poslist[j].Start)
                            {
                                thist = poslist[j].Start * 0.25 + poslist[j + 1].Start * 0.75;
                            }
                        }
                        pathcurve.AddCurve(poslist[j].Start, thist, new Line()
                        {
                            X0 = thisx, X1 = thisx, Y0 = yyy, Y1 = yyy
                        });
                        lastt = thist;
                        lastx = thisx;
                    }
                    curve.AddCurve(curve.MinT, curve.MaxT, pathcurve);

                    List <ASSPointF> pts = curve.GetPath_Dis(1, 1.2);
                    foreach (ASSPointF pt in pts)
                    {
                        double ptx2 = Common.RandomDouble(rnd, pt.X - 10, pt.X - 15);
                        double pty2 = pt.Y * 0.25 + (y0 + FontHeight * 0.5) * 0.75;
                        ass_out.AppendEvent(55, "pt", pt.T, pt.T + 0.3,
                                            pos(pt.X, pt.Y) +
                                            //                          move(pt.X, pt.Y, ptx2, pty2, 0.4, 1) +
                                            a(1, "AA") + c(1, "FFFFFF") +
                                            a(3, "AA") + c(3, ptcol) +
                                            bord(6) + blur(6) +
                                            t(0, 0.1, bord(3).t() + blur(3).t()) +
                                            fad(0, 0.2) +
                                            ptstr);
                        ass_out.AppendEvent(55, "pt", pt.T, pt.T + 0.3,
                                            pos(pt.X, pt.Y) +
//                            move(pt.X, pt.Y, ptx2, pty2, 0.4, 1) +
                                            a(1, "AA") + c(1, "FFFFFF") +
                                            a(3, "00") + c(3, "FFFFFF") +
                                            bord(4) + blur(4) +
                                            t(0, 0.1, bord(1).t() + blur(1).t() + a(3, "44").t()) +
                                            fad(0, 0.2) +
                                            ptstr);
                    }
                }
            }

            ass_out.SaveFile(OutFileName);
            Console.WriteLine("Lines : {0}", ass_out.Events.Count);
        }
Example #16
0
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            string ptString = @"{\p8}m 0 0 l 128 0 128 128 0 128";

            int[,] map = new int[this.PlayResX, this.PlayResY];

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                //if (iEv != 0) continue;
                ASSEvent        ev     = ass_in.Events[iEv];
                List <KElement> kelems = ev.SplitK(false);

                /// an7 pos
                int x0 = MarginLeft;
                if (iEv == 5)
                {
                    x0 = PlayResX - GetTotalWidth(ev) - MarginRight;
                }
                int y0 = PlayResY - MarginBottom - FontHeight;

                Random rnd = new Random();

                int kSum = 0;

                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);

                    KElement   ke   = kelems[iK];
                    double     r    = (double)iK / (double)(kelems.Count - 1);
                    StringMask mask = GetMask(ke.KText, x0, y0);
                    Size       sz   = new Size(mask.Width, mask.Height);

                    /// an5 pos
                    int x = x0 + this.FontSpace + sz.Width / 2;
                    int y = y0 + FontHeight / 2;
                    mask = GetMask(ke.KText, x, y);

                    x0 += this.FontSpace + sz.Width;
                    y0  = y0;

                    double kStart = ev.Start + kSum * 0.01;
                    kSum += ke.KValue;
                    double kEnd = ev.Start + kSum * 0.01;

                    double t0 = ev.Start - 1.0 + 0.1 * iK;
                    double t1 = t0 + 0.4;
                    double t2 = ev.End - 1.0 + 0.1 * iK;
                    double t3 = t2 + 0.4;

                    for (int i = 1; i <= 5; i++)
                    {
                        ass_out.Events.Add(
                            ev.StartReplace(t0 + i * 0.03).EndReplace(t1 + i * 0.03).TextReplace(
                                ASSEffect.move(x + 30, y - 30, x, y) + ASSEffect.a(1, "FF") + ASSEffect.blur(2) +
                                ASSEffect.fad((t1 - t0) * 2, 0) + ASSEffect.fry(-180) +
                                ASSEffect.t(0, t1 - t0, ASSEffect.fry(0).t()) +
                                ke.KText));
                    }
                    ass_out.Events.Add(
                        ev.StartReplace(t0).EndReplace(t1).TextReplace(
                            ASSEffect.move(x + 30, y - 30, x, y) + ASSEffect.a(1, "FF") + ASSEffect.blur(2) +
                            ASSEffect.fad(t1 - t0, 0) + ASSEffect.fry(-180) +
                            ASSEffect.t(0, t1 - t0, ASSEffect.fry(0).t()) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(kStart).EndReplace(t2).TextReplace(
                            ASSEffect.pos(x + 1, y + 1) + ASSEffect.a(1, "FF") + ASSEffect.a(3, "77") + ASSEffect.c(3, "000000") +
                            ASSEffect.bord(8) + ASSEffect.blur(8) + ASSEffect.fad(0.2, 0.2) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t1).EndReplace(t2).TextReplace(
                            ASSEffect.pos(x, y) + ASSEffect.a(1, "FF") + ASSEffect.blur(2) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t0).EndReplace(t1).TextReplace(
                            ASSEffect.move(x + 31, y - 29, x + 1, y + 1) + ASSEffect.a(1, "FF") + ASSEffect.a(3, "77") + ASSEffect.c(3, "000000") +
                            ASSEffect.bord(8) + ASSEffect.blur(8) + ASSEffect.fad(t1 - t0, 0) + ASSEffect.fry(-180) +
                            ASSEffect.t(0, t1 - t0, ASSEffect.fry(0).t()) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t1).EndReplace(kStart + 0.2).TextReplace(
                            ASSEffect.pos(x + 1, y + 1) + ASSEffect.a(1, "FF") + ASSEffect.a(3, "77") + ASSEffect.c(3, "000000") +
                            ASSEffect.bord(8) + ASSEffect.blur(8) + ASSEffect.fad(0, 0.2) +
                            ke.KText));
                    for (int i = 1; i <= 5; i++)
                    {
                        ass_out.Events.Add(
                            ev.StartReplace(t2 + i * 0.03).EndReplace(t3 + i * 0.03).TextReplace(
                                ASSEffect.move(x, y, x - 30, y + 30) + ASSEffect.a(1, "00") + ASSEffect.blur(2) +
                                ASSEffect.fad(0, 2 * (t3 - t2)) + ASSEffect.t(0, t3 - t2, ASSEffect.fry(180).t()) +
                                ke.KText));
                    }
                    ass_out.Events.Add(
                        ev.StartReplace(t2).EndReplace(t3).TextReplace(
                            ASSEffect.move(x, y, x - 30, y + 30) + ASSEffect.a(1, "00") + ASSEffect.blur(2) +
                            ASSEffect.fad(0, t3 - t2) + ASSEffect.t(0, t3 - t2, ASSEffect.fry(180).t()) +
                            ke.KText));

                    for (int i = 0; i < this.PlayResX; i++)
                    {
                        for (int j = 0; j < this.PlayResY; j++)
                        {
                            map[i, j] = -1;
                        }
                    }
                    for (int i = 0; i < mask.Points.Count; i++)
                    {
                        ASSPoint pt = mask.Points[i];
                        map[pt.X, pt.Y] = i;
                    }
                    int[] dx0 = { 0, 1, 0, -1 };
                    int[] dy0 = { 1, 0, -1, 0 };
                    int[] dx1 = { 1, 1, -1, -1 };
                    int[] dy1 = { -1, 1, -1, 1 };
                    int[] ind = new int[mask.Points.Count]; // 顺序标号
                    for (int i = 0; i < ind.Length; i++)
                    {
                        ind[i] = -1;
                    }
                    Queue <int> q;
                    int         left = ind.Length; // 剩下
                    while (left > 0)
                    {
                        q = new Queue <int>();
                        for (int i = 0; i < ind.Length; i++)
                        {
                            if (ind[i] == -1)
                            {
                                q.Enqueue(i);
                                ind[i] = 0;
                                break;
                            }
                        }
                        while (q.Count > 0)
                        {
                            int s = q.Dequeue();
                            left--;
                            ASSPoint pt = mask.Points[s];
                            int      x1, y1, t;
                            for (int i = 0; i < 4; i++)
                            {
                                x1 = pt.X + dx0[i];
                                y1 = pt.Y + dy0[i];
                                if (x1 >= 0 && x1 < PlayResX && y1 >= 0 && y1 < PlayResY && map[x1, y1] >= 0)
                                {
                                    t = map[x1, y1];
                                    if (ind[t] < 0)
                                    {
                                        ind[t] = ind[s] + 1;
                                        q.Enqueue(t);
                                    }
                                }
                            }
                            for (int i = 0; i < 4; i++)
                            {
                                if (Common.RandomBool(rnd, 0.5))
                                {
                                    continue;
                                }
                                x1 = pt.X + dx0[i];
                                y1 = pt.Y + dy0[i];
                                if (x1 >= 0 && x1 < PlayResX && y1 >= 0 && y1 < PlayResY && map[x1, y1] >= 0)
                                {
                                    t = map[x1, y1];
                                    if (ind[t] < 0)
                                    {
                                        ind[t] = ind[s] + 1;
                                        q.Enqueue(t);
                                    }
                                }
                            }
                        }
                    }

                    for (int i = 0; i < mask.Points.Count; i++)
                    {
                        ASSPoint pt    = mask.Points[i];
                        double   indsc = 50.0;
                        if (iEv >= 4)
                        {
                            indsc = 75.0;
                        }
                        double tp0 = kStart - 0.1 + (double)ind[i] / indsc + Common.RandomDouble_Gauss(rnd, -0.2, 0.2);
                        double tp1 = tp0 + 0.3;
                        double tp2 = tp1 + 0.3;
                        string pc0 = "5955FF";
                        string pc1 = "55FDFF";
                        string pc2 = "9C4E4D";
                        ass_out.Events.Add(
                            ev.StartReplace(tp0).EndReplace(tp1).StyleReplace("pt").LayerReplace(5).TextReplace(
                                ASSEffect.pos(pt.X, pt.Y) + ASSEffect.fad(0.3, 0) +
                                ASSEffect.a(1, Common.ToHex2(255 - pt.Brightness)) + ASSEffect.c(1, pc0) +
                                ptString
                                ));
                        ass_out.Events.Add(
                            ev.StartReplace(tp1).EndReplace(tp2).StyleReplace("pt").LayerReplace(5).TextReplace(
                                ASSEffect.pos(pt.X, pt.Y) +
                                ASSEffect.a(1, Common.ToHex2(255 - pt.Brightness)) + ASSEffect.c(1, pc0) +
                                ASSEffect.t(0, tp2 - tp1, ASSEffect.c(1, pc1).t()) +
                                ptString
                                ));
                        ass_out.Events.Add(
                            ev.StartReplace(tp2).EndReplace(t2).StyleReplace("pt").LayerReplace(5).TextReplace(
                                ASSEffect.pos(pt.X, pt.Y) +
                                ASSEffect.a(1, Common.ToHex2(255 - pt.Brightness)) + ASSEffect.c(1, pc1) +
                                ASSEffect.t(0, 0.3, ASSEffect.c(1, pc2).t()) +
                                ptString
                                ));
                    }
                }
            }
            ass_out.SaveFile(OutFileName);
        }
        public void Run()
        {
            ASS ass    = ASS.FromFile(InFileName);
            ASS outass = new ASS();

            outass.Header = ass.Header;
            outass.Events = new List <ASSEvent>();
            Particle particle = new Particle
            {
                IsMove          = false,
                IsRandomColor   = false,
                IsPatternScale  = true,
                Count           = 1,
                FontSize        = 26,
                MinLast         = 0.5,
                MaxLast         = 0.8,
                ParticlePattern = ParticlePatternType.Circle,
                PatternScaleX   = 600,
                PatternScaleY   = 600,
                Style           = "Circle",
                XOffset         = 0,
                YOffset         = 0
            };

            ASSColor[] colors =
            {
                new ASSColor {
                    A = 0, Index = 1, R = 0xCA, G = 0xB4, B = 0x6D
                },
                new ASSColor {
                    A = 0, Index = 1, R = 0xEE, G = 0x85, B = 0x57
                },
                new ASSColor {
                    A = 0, Index = 1, R = 0xE4, G = 0x30, B = 0x99
                },
                new ASSColor {
                    A = 0, Index = 1, R = 0x5D, G = 0xD3, B = 0xEE
                },
                new ASSColor {
                    A = 0, Index = 1, R = 0xE1, G = 0x32, B = 0x63
                }
            };
            for (int i = 0; i < ass.Events.Count; i++)
            {
                ASSEvent        ev     = ass.Events[i];
                List <KElement> klist  = ev.SplitK();
                int             ksum   = 0;
                ASSColor        lastcc = null;
                for (int j = 0; j < klist.Count; j++)
                {
                    int x = (PlayResX - klist.Count * FontWidth) / 2 + j * FontWidth + FontWidth / 2;
                    int y = PlayResY - MarginBottom - FontHeight / 2;
                    if (i == 7)
                    {
                        y = MarginTop + FontHeight / 2;
                    }
                    double   kStart = ksum * 0.01;
                    double   kEnd   = (ksum + klist[j].KValue) * 0.01;
                    ASSColor cc     = colors[(i + j) % colors.Length];

                    /*while (lastcc == cc)
                     *  cc = colors[rnd.Next(colors.Length)];
                     * lastcc = cc;*/
                    if (!Char.IsWhiteSpace(klist[j].KText[0]))
                    {
                        outass.Events.Add(ev.TextReplace(
                                              ASSEffect.an(5) + ASSEffect.pos(x, y) + ASSEffect.a(1, "FF") +
                                              ASSEffect.t(kStart, kStart + 0.2, cc.ToString()) +
                                              (i % 4 <= 1 ?
                                               ASSEffect.t(ev.Last - 0.3 - 0.5 * (1 - ((double)j / (double)klist.Count)), ev.Last - 0.5 * (1 - ((double)j / (double)klist.Count)), @"\1a&HFF&\2a&HFF&\3a&HFF&\4a&HFF&" + ((i % 2 == 0) ? @"\frx700" : @"\fry700")) :
                                               (i % 4 == 3 ? ASSEffect.t(ev.Last - 0.5 * (1 - ((double)j / (double)klist.Count)), ev.Last - 0.5 * (1 - ((double)j / (double)klist.Count)) + 0.01, @"\1a&HFF&\2a&HFF&\3a&HFF&\4a&HFF&") : ASSEffect.t(ev.Last - 0.8 - 0.5 * (1 - ((double)j / (double)klist.Count)), ev.Last - 0.5 * (1 - ((double)j / (double)klist.Count)), @"\1a&HFF&\2a&HFF&\3a&HFF&\4a&HFF&" + @"\frz700"))) +
                                              klist[j].KText
                                              ));
                        if (i % 4 == 3)
                        {
                            outass.Events.Add(ev.StartReplace(ev.Start + ev.Last - 0.5 * (1 - ((double)j / (double)klist.Count)) + 0.01).EndReplace(ev.Start + ev.Last - 0.5 * (1 - ((double)j / (double)klist.Count)) + 0.01 + 0.2).TextReplace(
                                                  ASSEffect.an(5) + ASSEffect.move(x, y, x - 40, y) + ASSEffect.fad(0, 0.2) + ASSEffect.c(cc) + klist[j].KText));
                        }
                        particle.X     = x - FontWidth / 2;
                        particle.Y     = y - FontHeight / 2;
                        particle.Start = ev.Start + kStart;
                        particle.End   = particle.Start;
                        particle.Color = cc;
                        outass.Events.AddRange(particle.Create());
                    }
                    ksum += klist[j].KValue;
                }
            }
            outass.Shift(Shift);
            outass.SaveFile(OutFileName);
        }
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            string ptStr = @"{\p4}m 0 100 l 1 1 100 0 1 -1 0 -100 -1 -1 -100 0 -1 1 c m 10 10 s 10 -10 -10 -10 -10 10 c";

            GetMask("!", 0, 0);

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                ASSEvent        ev     = ass_in.Events[iEv];
                List <KElement> kelems = ev.SplitK(false);

                /// an7 pos
                int x0 = (PlayResX - GetTotalWidth(ev)) / 2;
                int y0 = PlayResY - MarginBottom - FontHeight;

                Random rnd = new Random();

                int kSum = 0;

                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    KElement ke = kelems[iK];
                    double   r  = (double)iK / (double)(kelems.Count - 1);
                    Size     sz = GetSize(ke.KText);

                    /// an5 pos
                    int x = x0 + this.FontSpace + sz.Width / 2;
                    int y = y0 + FontHeight;

                    StringMask mk = GetMask(ke.KText, x0, y0);
                    if (ke.KText.ToLower() == "silky")
                    {
                        mk = GetMask(ke.KText, x0 - 2, y0);
                    }

                    int bx0 = x0;
                    int by0 = y0;

                    x0 += this.FontSpace + sz.Width;
                    y0  = y0;

                    double kStart = ev.Start + kSum * 0.01;
                    kSum += ke.KValue;
                    double kEnd = ev.Start + kSum * 0.01;

                    double t0 = ev.Start + r * 1.0 - 1.0;
                    double t1 = t0 + 0.2;
                    double t2 = t0 + 0.4;
                    double t3 = t0 + 0.6;
                    double t4 = t0 + 0.8;
                    double t5 = ev.End + r * 1.0 - 1.0;
                    if (t5 < t4)
                    {
                        t5 = t4;
                    }
                    double t6 = t5 + 0.5;

                    ass_out.Events.Add(
                        ev.StartReplace(t0).EndReplace(t1).TextReplace(
                            ASSEffect.move(x, y, x, y - 60) + ASSEffect.a(1, "FF") + ASSEffect.a(3, "FF") +
                            ASSEffect.t(0, t1 - t0, ASSEffect.a(1, "C0").t() + ASSEffect.a(3, "C0").t() + ASSEffect.frx(180).t()) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t1).EndReplace(t2).TextReplace(
                            ASSEffect.move(x, y - 60, x, y) + ASSEffect.a(1, "C0") + ASSEffect.a(3, "C0") + ASSEffect.frx(180) +
                            ASSEffect.t(0, t2 - t1, ASSEffect.a(1, "80").t() + ASSEffect.a(3, "80").t() + ASSEffect.frx(360).t()) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t2).EndReplace(t3).TextReplace(
                            ASSEffect.move(x, y, x, y - 60) + ASSEffect.a(1, "80") + ASSEffect.a(3, "80") +
                            ASSEffect.t(0, t3 - t2, ASSEffect.a(1, "40").t() + ASSEffect.a(3, "40").t() + ASSEffect.frx(180).t()) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t3).EndReplace(t4).TextReplace(
                            ASSEffect.move(x, y - 60, x, y) + ASSEffect.a(1, "40") + ASSEffect.a(3, "40") + ASSEffect.frx(180) +
                            ASSEffect.t(0, t4 - t3, ASSEffect.a(1, "00").t() + ASSEffect.a(3, "00").t() + ASSEffect.frx(360).t()) +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t4).EndReplace(t5).TextReplace(
                            ASSEffect.pos(x, y) + ASSEffect.a(1, "00") + ASSEffect.a(3, "00") +
                            ke.KText));
                    ass_out.Events.Add(
                        ev.StartReplace(t5).EndReplace(t6).TextReplace(
                            ASSEffect.move(x, y, x + r * 100 - 50, y + 30) + ASSEffect.a(1, "00") + ASSEffect.a(3, "00") +
                            ASSEffect.fad(0, t6 - t5) +
                            ke.KText));

                    ASSColor col = Common.RandomColor(rnd, 1);

                    foreach (ASSPoint pt in mk.Points)
                    {
                        if (!Common.RandomBool(rnd, 0.5))
                        {
                            continue;
                        }
                        double r1  = Common.RandomDouble(rnd, kStart - 0.15, kEnd + 0.15);
                        double r0  = r1 - 0.5;
                        double r2  = Common.RandomDouble(rnd, kStart + 0.9, kStart + 1.2);
                        double r3  = r2 + 0.5;
                        int    x_0 = Common.RandomInt(rnd, pt.X - 80, pt.X - 30);
                        int    y_0 = Common.RandomInt(rnd, pt.Y - 30, pt.Y + 30);
                        int    x_1 = Common.RandomInt(rnd, pt.X + 80, pt.X + 30);
                        int    y_1 = Common.RandomInt(rnd, pt.Y - 30, pt.Y + 30);
                        ass_out.Events.Add(
                            ev.StartReplace(r0).EndReplace(r1).StyleReplace("pt").TextReplace(
                                ASSEffect.move(x_0, y_0, pt.X, pt.Y) + ASSEffect.c(col) + ASSEffect.fad(r1 - r0, 0) + ptStr));
                        ass_out.Events.Add(
                            ev.StartReplace(r1).EndReplace(r2).StyleReplace("pt").TextReplace(
                                ASSEffect.pos(pt.X, pt.Y) + ASSEffect.c(col) + ptStr));
                        ass_out.Events.Add(
                            ev.StartReplace(r2).EndReplace(r3).StyleReplace("pt").TextReplace(
                                ASSEffect.move(pt.X, pt.Y, x_1, y_1) + ASSEffect.c(col) + ASSEffect.fad(0, r3 - r2) + ptStr));
                    }
                }
            }
            ass_out.SaveFile(OutFileName);
        }
Example #19
0
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            int y0min = 0;
            int y0max = 100;

            string color1 = "DDC3B2";
            string color2 = "C69A7B";

            List <StringMask> lastMasks = new List <StringMask>();
            List <StringMask> thisMasks = new List <StringMask>();

            Random rnd = new Random();

            /// 所有的不动点最后一次写入
            List <ASSPoint> allPoints = new List <ASSPoint>();

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                ASSEvent        ev     = ass_in.Events[iEv];
                List <KElement> kelems = ev.SplitK(false);

                int x0 = MarginLeft;
                int y0 = PlayResY - FontHeight - MarginBottom;

                thisMasks.Clear();
                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    KElement   elem = kelems[iK];
                    StringMask mask = GetMask(elem.KText, x0, y0);
                    thisMasks.Add(GetMask(kelems[iK].KText, x0, y0));
                    x0 += mask.Width + this.FontSpace;
                }

                List <ASSPoint> lastPts = new List <ASSPoint>();
                if (iEv > 0)
                {
                    if (Math.Abs(ev.Start - ass_in.Events[iEv - 1].End) < 2)
                    {
                        foreach (StringMask sm in lastMasks)
                        {
                            lastPts.AddRange(sm.Points);
                        }
                    }
                }
                if (lastPts.Count == 0)
                {
                    lastPts.Add(new ASSPoint {
                        X = -100 * ScaleRate, Y = y0 - 100 * ScaleRate, Brightness = 255
                    });
                }

                bool   next = (iEv + 1 < ass_in.Events.Count) && (Math.Abs(ev.End - ass_in.Events[iEv + 1].Start) < 2);
                bool[] used = new bool[lastPts.Count];
                for (int i = 0; i < used.Length; i++)
                {
                    used[i] = false;
                }

                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    double r  = (double)iK / (double)(kelems.Count - 1);
                    double r0 = 1.0 - r;

                    StringMask      mask = thisMasks[iK];
                    List <ASSPoint> pts  = mask.Points;

                    foreach (ASSPoint pt in pts)
                    {
                        int zz = 0;
                        if (used.Length > 1)
                        {
                            zz = Common.RandomInt_Gauss2(rnd, used.Length, (int)(r * (used.Length - 1)));
                        }
                        used[zz] = true;
                        ASSPoint        srcpt   = lastPts[zz];
                        List <ASSPoint> bez_pts = new Bezier(srcpt,
                                                             new ASSPoint {
                            X = Common.RandomInt_Gauss(rnd, srcpt.X - 30 * ScaleRate, 80 * ScaleRate), Y = Common.RandomInt_Gauss(rnd, srcpt.Y - 50 * ScaleRate, 80 * ScaleRate)
                        },
                                                             new ASSPoint {
                            X = Common.RandomInt_Gauss(rnd, pt.X + 30 * ScaleRate, 80 * ScaleRate), Y = Common.RandomInt_Gauss(rnd, pt.Y - 50 * ScaleRate, 80 * ScaleRate)
                        }, pt).Create(0.1f);

                        /// for test
                        double f1 = ev.Start - r0 * 1.0;
                        double f0 = f1 - 1;
                        srcpt.End = f0;
                        pt.Color  = Common.scaleColor(color1, color2, mask.Y0, PlayResY - MarginBottom, pt.Y);
                        for (int i = 0; i + 1 < bez_pts.Count; i++)
                        {
                            ASSPoint p0 = bez_pts[i];
                            ASSPoint p1 = bez_pts[i + 1];
                            ass_out.Events.Add(CreateMovingPixel(f0, f0 + 0.1, p0.X, p0.Y, p1.X, p1.Y, Common.scaleColor(srcpt.Color, pt.Color, srcpt.End, f0 + 1, f0), "00"));
                            f0 += 0.1;
                        }
                        pt.Start      = f0;
                        pt.End        = ev.End;
                        pt.Brightness = 255;
                        allPoints.Add(pt);

                        if (!next)
                        {
                            ass_out.Events.Add(CreateMovingPixel(pt.End, pt.End + 1, pt.X, pt.Y, Common.RandomInt_Gauss(rnd, pt.X, 80 * ScaleRate), Common.RandomInt_Gauss(rnd, pt.Y, 80 * ScaleRate), pt.Color, "00", 2));
                        }
                    }
                }

                for (int i = 0; i < used.Length; i++)
                {
                    if (!used[i])
                    {
                        ASSPoint pt = lastPts[i];
                        if (pt.End > ev.Start - 1.5)
                        {
                            pt.End = ev.Start - 1.5;
                        }
                    }
                }

                Console.WriteLine(iEv);

                lastMasks.Clear();
                lastMasks.AddRange(thisMasks);
            }

            foreach (ASSPoint pt in allPoints)
            {
                ass_out.Events.Add(CreatePixel(pt.Start, pt.End, pt.X, pt.Y, pt.Color, Common.ToHex2(255 - pt.Brightness)));
            }

            ass_out.SaveFiles(@"G:\Workshop\natsume2\op_", 500000);
        }
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS()
            {
                Header = ass_in.Header, Events = new List <ASSEvent>()
            };

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                bool isJp = iEv <= 10;
                this.MaskStyle = isJp ?
                                 "Style: Default,HGKyokashotai,40,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,1,0,0,5,0,0,0,128" :
                                 "Style: Default,仿宋,36,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,1,0,0,5,0,0,0,1";
                this.FontHeight = isJp ? 40 : 36;
                int jEv = isJp ? iEv : iEv - 11;
                //if (jEv != 4) continue;
                ASSEvent        ev         = ass_in.Events[iEv];
                List <KElement> kelems     = ev.SplitK(true);
                int             totalWidth = GetTotalWidth(ev);
                int             x0         = MarginLeft;
                if (jEv % 2 != 0)
                {
                    x0 = PlayResX - MarginRight - totalWidth;
                }
                int y0       = (isJp) ? (PlayResY - MarginBottom - FontHeight) : MarginTop;
                int kSum     = 0;
                int x0_start = x0;
                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                    KElement ke     = kelems[iK];
                    Size     sz     = GetSize(ke.KText);
                    double   kStart = ev.Start + kSum * 0.01;
                    double   kEnd   = kStart + ke.KValue * 0.01;
                    kSum += ke.KValue;
                    int x     = x0 + this.FontSpace + sz.Width / 2;
                    int y     = y0 + FontHeight / 2;
                    int x_an7 = x0;
                    int y_an7 = y0;
                    x0 += this.FontSpace + sz.Width;
                    if (ke.KText.Trim().Length == 0)
                    {
                        continue;
                    }
                    StringMask mask    = GetMask(ke.KText, x, y);
                    string     evStyle = isJp ? "op_jp" : "op_cn";

                    string col_aoi = "ADA088";

                    double t0 = ev.Start - Common.RandomDouble(rnd, 0.5, 1.5);
                    double t1 = kStart - 0.1;
                    if (!isJp)
                    {
                        t1 = ev.Start + iK * 0.1;
                    }
                    double t2 = t1 + 0.3;
                    double t3 = ev.End;
                    if (isJp && iEv == 6 && iK <= 4)
                    {
                        t3 = ev.Start + 3;
                    }
                    double t4 = t3 + 0.5;

                    double y_start = y - Common.RandomDouble(rnd, 10, 20);
                    double y_end   = y;

                    double tmve = ev.Start + 2;
                    if (!isJp)
                    {
                        tmve = ev.Start + iK * 0.1;
                    }
                    if (tmve > kStart)
                    {
                        tmve = kStart;
                    }
                    Func <double, double> fPosY = ti => (ti < tmve ? (ti - t0) / (tmve - t0) * (y_end - y_start) + y_start : y_end);

                    ass_out.AppendEvent(50, evStyle, t0, t1,
                                        move(x, fPosY(t0), x, fPosY(t1)) + a(1, "00") + a(4, "66") +
                                        c(1, "FFFFFF") + c(4, "777777") + shad(1) + fad(0.5, 0) +
                                        ke.KText);
                    ass_out.AppendEvent(50, evStyle, t1, t2,
                                        move(x, fPosY(t1), x, fPosY(t2)) + a(1, "00") + a(4, "66") +
                                        c(1, "FFFFFF") + c(4, "777777") + shad(1) + fad(0, t2 - t1) + t(blur(2.5).t()) +
                                        ke.KText);
                    ass_out.AppendEvent(50, evStyle, t1, t2,
                                        move(x, fPosY(t1), x, fPosY(t2)) + a(1, "00") + a(4, "66") +
                                        c(1, col_aoi) + c(4, "777777") + shad(1) + fad(t2 - t1, 0) + blur(2.5) + t(blur(0).t()) +
                                        ke.KText);
                    ass_out.AppendEvent(50, evStyle, t2, t3,
                                        move(x, fPosY(t2), x, fPosY(t3)) + a(1, "00") + a(4, "66") +
                                        c(1, col_aoi) + c(4, "777777") + shad(1) +
                                        ke.KText);
                    if (!(isJp && iEv >= 5))
                    {
                        ass_out.AppendEvent(50, evStyle, t3, t4,
                                            move(x, fPosY(t3), x, fPosY(t4)) + a(1, "00") + a(4, "66") +
                                            c(1, col_aoi) + c(4, "777777") + shad(1) + fad(0, t4 - t3) + t(blur(2.5).t()) +
                                            ke.KText);
                    }

                    ass_out.AppendEvent(49, evStyle, t1, (!(isJp && iEv >= 4)) ? t4 : t3,
                                        move(x, fPosY(t1), x, fPosY(t4)) + a(1, "77") + c(1, col_aoi) +
                                        fad(0.4, 0.4) + blur(2) +
                                        ke.KText);

                    int mo = 4;
                    if (!isJp)
                    {
                        mo = 0;
                    }
                    ass_out.AppendEvent(40, evStyle, t0, t1,
                                        pos(x, y + FontHeight / 2 - mo) + an(2) + a(1, "44") + c(1, "AAAAAA") +
                                        blur(1) + frx(125) + fad(t1 - t0, 0) +
                                        ke.KText);
                    ass_out.AppendEvent(41, evStyle, t1, t1 + 0.8,
                                        pos(x, y + FontHeight / 2 - mo) + an(2) + a(1, "77") + c(1, "333333") +
                                        blur(3) + frx(125) + fad(0, 0.8) +
                                        ke.KText);
                    ass_out.AppendEvent(40, evStyle, t1, t3,
                                        pos(x, y + FontHeight / 2 - mo) + an(2) + a(1, "44") + c(1, "AAAAAA") +
                                        blur(1) + frx(125) +
                                        ke.KText);
                    ass_out.AppendEvent(40, evStyle, t3, t4,
                                        pos(x, y + FontHeight / 2 - mo) + an(2) + a(1, "44") + c(1, "AAAAAA") +
                                        blur(1) + frx(125) + fad(0, t4 - t3) +
                                        ke.KText);

                    if (!isJp)
                    {
                        continue;
                    }

                    if (isJp && iEv >= 5)
                    {
                        foreach (ASSPoint pt in mask.Points)
                        {
                            double ptx1 = pt.X - Common.RandomDouble(rnd, 100, 300);
                            double pty1 = pt.Y - Common.RandomDouble(rnd, 10, 100);
                            double ptt0 = t3 + (double)(pt.X - x0_start) / 200 + Common.RandomDouble(rnd, -0.15, 0.15);
                            if (isJp && iEv == 6 && iK > 4)
                            {
                                ptt0 -= 1;
                            }
                            double ptt1 = ptt0 + Common.RandomDouble(rnd, 0.5, 1);
                            ass_out.AppendEvent(60, "pt", t3, ptt0,
                                                pos(pt.X, pt.Y) + a(1, Common.ToHex2(255 - pt.Brightness)) +
                                                shad(1) + a(4, "66") + c(4, "777777") + c(1, col_aoi) +
                                                p(1) + "m 0 0 l 1 0 1 1 0 1");

                            if (Common.RandomBool(rnd, 0.5))
                            {
                                ass_out.AppendEvent(61, "pt", ptt0, ptt1,
                                                    move(pt.X, pt.Y, ptx1, pty1) + a(1, "77") +
                                                    fad(0, 0.5) + c(1, "FFFFFF") + frz(Common.RandomInt(rnd, 0, 359)) +
                                                    CreatePolygon(rnd, 20, 30, 6));
                                ass_out.AppendEvent(60, "pt", ptt0, ptt1,
                                                    move(pt.X, pt.Y, ptx1, pty1) + a(1, "00") +
                                                    fad(0, 0.5) + c(1, col_aoi) + frz(Common.RandomInt(rnd, 0, 359)) +
                                                    CreatePolygon(rnd, 20, 30, 6));
                            }

                            continue;
                            ass_out.AppendEvent(60, "pt", t3, ptt1,
                                                move(pt.X, pt.Y, ptx1, pty1, ptt0 - t3, ptt1 - t3) + a(1, Common.ToHex2(255 - pt.Brightness)) +
                                                fad(0, 0.5) + shad(1) + a(4, "66") + c(4, "777777") + c(1, col_aoi) +
                                                p(1) + "m 0 0 l 1 0 1 1 0 1");
                        }
                    }
                }
            }

            Console.WriteLine(ass_out.Events.Count);
            ass_out.SaveFile(this.OutFileName);
        }
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS()
            {
                Header = ass_in.Header, Events = new List <ASSEvent>()
            };

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                bool isJp = iEv <= 47;
                this.MaskStyle = "Style:Default,DFSoGei-W5,25,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,1,1,0,5,0,0,0,1";
                int jEv = isJp ? iEv : iEv - 48;
                //if (jEv > 0) continue;
                //if (iEv > 2) continue;
                ASSEvent         ev     = ass_in.Events[iEv];
                List <KElement>  kelems = ev.SplitK(false);
                List <ASSPointF> path   = new List <ASSPointF>();

                {
                    int totalWidth = GetTotalWidth(ev);
                    int x0         = (PlayResX - MarginRight - totalWidth - MarginLeft) / 2 + MarginLeft;
                    int y0         = (isJp) ? (PlayResY - MarginBottom - FontHeight) : MarginTop;
                    int kSum       = 0;
                    for (int iK = 0; iK < kelems.Count; iK++)
                    {
                        double sr = (double)iK / (double)(kelems.Count - 1);
                        Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                        KElement ke     = kelems[iK];
                        Size     sz     = GetSize(ke.KText);
                        double   kStart = ev.Start + kSum * 0.01;
                        double   kEnd   = kStart + ke.KValue * 0.01;
                        kSum += ke.KValue;
                        int x     = x0 + this.FontSpace + sz.Width / 2;
                        int y     = y0 + FontHeight / 2;
                        int x_an7 = x0;
                        int y_an7 = y0;
                        x0 += this.FontSpace + sz.Width;
                        if (ke.KText.Trim().Length == 0)
                        {
                            continue;
                        }
                        StringMask mask    = GetMask(ke.KText, x, y);
                        string     evStyle = isJp ? "jp" : "roma";

                        path.Add(new ASSPointF {
                            X = x, Y = y, Start = kStart, End = kEnd, T = kStart
                        });

                        double t0  = ev.Start - 0.5 + iK * 0.065;
                        double t1  = t0 + 0.5;
                        double t2  = kStart;
                        double t21 = kEnd;
                        double t3  = ev.End - 0.5 + iK * 0.065;
                        double t4  = t3 + 0.5;
                        if (t21 > t3)
                        {
                            t21 = t3;
                        }

                        string MainColor = "0000A7";
                        {
                            Line line = new Line {
                                X0 = x, X1 = x, Y0 = y - 35, Y1 = y, Acc = 0.4
                            };
                            CompositeCurve curve = new CompositeCurve {
                                MinT = t0, MaxT = t1
                            };
                            curve.AddCurve(t0, t1, line);
                            foreach (ASSPointF pt in curve.GetPath_Dis(1, 1.1).OrderByDescending(xx => xx.T))
                            {
                                ass_out.AppendEvent(40, evStyle, pt.T, pt.T + 0.3,
                                                    pos(pt.X, pt.Y) + fad(0, 0.3) + a(1, "DD") + blur(1.8) + c(1, MainColor) +
                                                    a(3, "DD") + c(3, "EEEEEE") + bord(1.8) +
                                                    ke.KText);
                            }
                        }
                        {
                            Line line = new Line {
                                X0 = x, X1 = x, Y0 = y, Y1 = y + 35, Acc = 0.4
                            };
                            CompositeCurve curve = new CompositeCurve {
                                MinT = t3, MaxT = t4
                            };
                            curve.AddCurve(t3, t4, line);
                            foreach (ASSPointF pt in curve.GetPath_Dis(1, 1.1).OrderByDescending(xx => xx.T))
                            {
                                double last = 0.3 + 0.2 - Math.Abs((t4 - t3) * 0.5 + t3 - pt.T) * 1.2;
                                ass_out.AppendEvent(40, evStyle, pt.T, pt.T + last,
                                                    pos(pt.X, pt.Y) + fad(0, last) + a(1, "DD") + blur(1.8) + c(1, MainColor) +
                                                    a(3, "DD") + c(3, "EEEEEE") + bord(1.8) +
                                                    ke.KText);
                            }
                        }

                        ass_out.AppendEvent(40, evStyle, t1 - 0.1, t2,
                                            fad(0.4, 0) + pos(x + 2, y + 2) + a(1, "77") + c(1, "000000") + blur(1) +
                                            ke.KText);
                        ass_out.AppendEvent(40, evStyle, t21, t3 + 0.1,
                                            fad(0, 0.4) + pos(x + 2, y + 2) + a(1, "77") + c(1, "000000") + blur(1) +
                                            ke.KText);

                        /*
                         * ass_out.AppendEvent(50, evStyle, t1, t2,
                         *  pos(x, y) + a(1, "66") + c(1, MainColor) + blur(1) + a(3, "00") + c(3, "EEEEEE") + bord(1.8) +
                         *  ke.KText);
                         * ass_out.AppendEvent(50, evStyle, t21, t3,
                         *  pos(x, y) + a(1, "66") + c(1, MainColor) + blur(1) + a(3, "00") + c(3, "EEEEEE") + bord(1.8) +
                         *  ke.KText);
                         * */
                        {
                            Func <double, double> tempFunc = xx => Math.Sin(xx * 1.4);
                            Func <double, string> colFunc  = xx => ((tempFunc(xx) > 0) ? ASSColor.FromRGB(1, tempFunc(xx) * 255.0, 0, 255.0).ToColString() : ASSColor.FromRGB(1, 0, -tempFunc(xx) * 255.0, 255.0).ToColString());
                            string tstring = "";
                            tstring += t(0, t2 - t1, c(1, colFunc(t2)).t());
                            tstring += t(t2 - t1, t2 - t1 + 0.01, a(1, "FF").t() + a(3, "FF").t());
                            tstring += t(t21 - t1 - 0.01, t21 - t1, a(1, "66").t() + a(3, "00").t() + c(1, colFunc(t21)).t());
                            tstring += t(t21 - t1, t3 - t1, c(1, MainColor).t());
                            ass_out.AppendEvent(50, evStyle, t1, t3,
                                                pos(x, y) + a(1, "66") + c(1, MainColor) + blur(1) + a(3, "00") + c(3, "EEEEEE") + bord(1.8) +
                                                tstring +
                                                ke.KText);
                            for (double ti = t2; ti < t21 && ti < t2 + 0.2; ti += 0.01)
                            {
                                ass_out.AppendEvent(60, evStyle, ti, t21,
                                                    fad(0, t21 - ti) + pos(x, y) + a(1, "AA") + c(1, "FFFFFF") + blur(0) + a(3, "EE") + c(3, colFunc(ti)) + bord(2.5) +
                                                    t(0, 0.3, 0.6, fsc(150, 150).t()) + t(0.3, t21 - ti, blur(2.5).t() + bord(3.5).t()) +
                                                    ke.KText);
                            }
                        }
                    }
                }

                {
                    double         spd   = 750; // pixel / sec
                    double         x0    = path[0].X - 30;
                    double         y0    = path[0].Y;
                    double         t0    = path[0].T - 0.3;
                    CompositeCurve curve = new CompositeCurve {
                        MinT = ev.Start - 0.3, MaxT = ev.End
                    };
                    bool lastVertical = true;
                    int  p            = 0;
                    while (t0 < curve.MaxT)
                    {
                        double x1 = x0;
                        double y1 = y0;
                        while (p + 1 < path.Count && path[p].End <= t0)
                        {
                            p++;
                        }
                        int sig = Common.RandomSig(rnd);
                        if (lastVertical)
                        {
                            if (x0 < path[p].X)
                            {
                                sig = 1;
                            }
                            else
                            {
                                sig = -1;
                            }
                            x1 = x0 + Common.RandomDouble(rnd, 5, 50) * sig;
                        }
                        else
                        {
                            if (y0 < path[p].Y)
                            {
                                sig = 1;
                            }
                            else
                            {
                                sig = -1;
                            }
                            y1 = y0 + Common.RandomDouble(rnd, 5, 40) * sig;
                        }
                        double t1 = t0 + Common.GetDistance(x0, y0, x1, y1) / spd;
                        if (t1 >= curve.MaxT)
                        {
                            t1 = curve.MaxT;
                        }
                        curve.AddCurve(t0, t1, new Line {
                            X0 = x0, Y0 = y0, X1 = x1, Y1 = y1
                        });
                        x0           = x1;
                        y0           = y1;
                        t0           = t1;
                        lastVertical = !lastVertical;
                    }
                    foreach (ASSPointF pt in curve.GetPath_Dis(0.9, 1.0))
                    {
                        double tt  = Math.Sin(pt.T * 1.4); // DO NO CHANGE
                        string col = "";
                        if (tt > 0)
                        {
                            col = ASSColor.FromRGB(1, tt * 255.0, 0, 255.0).ToColString();
                        }
                        else
                        {
                            col = ASSColor.FromRGB(1, 0, -tt * 255.0, 255.0).ToColString();
                        }
                        ass_out.AppendEvent(20, "pt", pt.T, pt.T + 1.5,
                                            fad(0, 0.5) + pos(pt.X, pt.Y) + bord(0.8) + blur(1) +
                                            a(1, "00") + a(3, "77") + c(1, Common.scaleColor("FFFFFF", col, 0.7)) + c(3, col) +
                                            ASSEffect.p(1) + "m 0 0 l 1 0 1 1 0 1");
                    }
                }
            }

            Console.WriteLine(ass_out.Events.Count);
            ass_out.SaveFile(this.OutFileName);
        }
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS()
            {
                Header = ass_in.Header, Events = new List <ASSEvent>()
            };

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                bool isJp = true;
                //if (iEv > 1) continue;
                this.MaskStyle = isJp ?
                                 "Style: Default,DFMincho-UB,38,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,5,0,0,0,128" :
                                 "Style: Default,汉仪粗宋繁,38,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,1,0,0,0,100,100,0,0,0,0,0,5,0,0,0,134";
                ASSEvent        ev       = ass_in.Events[iEv];
                List <KElement> kelems   = ev.SplitK(false);
                int             x0       = (PlayResX - GetTotalWidth(ev) - MarginLeft - MarginRight) / 2 + MarginLeft;
                int             x0_start = x0;
                int             y0       = MarginTop;
                int             kSum     = 0;

                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                    KElement ke     = kelems[iK];
                    Size     sz     = GetSize(ke.KText);
                    double   kStart = ev.Start + kSum * 0.01;
                    double   kEnd   = kStart + ke.KValue * 0.01;
                    kSum += ke.KValue;
                    int        x     = x0 + this.FontSpace + sz.Width / 2;
                    int        y     = y0 + FontHeight / 2;
                    int        x_an7 = x0 + 2;
                    int        y_an7 = y0;
                    StringMask mask  = GetMask(ke.KText, x, y);
                    x0 += this.FontSpace + sz.Width;
                    if (ke.KText.Trim().Length == 0)
                    {
                        continue;
                    }
                    string evStyle = "jp";

                    double t0 = ev.Start - 0.5 + iK * 0.1;
                    double t1 = t0 + 0.5;
                    double t2 = kStart;
                    double t3 = kEnd;
                    double t4 = ev.End - 0.5 + iK * 0.1;
                    double t5 = t4 + 0.5;

                    string[,] bordColors =
                    {
                        { "FFB9A8", "BC5237", "6B1905" },
//                                        {"FFE1DA","FFBCAB","EF6C4B"},
                        { "FFB9A8", "BC5237", "6B1905" },
                        { "AFAFFF", "595AF1", "595AF1" },
                        { "AFAFFF", "595AF1", "595AF1" },
                        { "8DEDFF", "5CCFFF", "2BABF5" },
                        { "8DEDFF", "5CCFFF", "2BABF5" },
                        { "8DEDFF", "5CCFFF", "2BABF5" },
                        { "AFAFFF", "595AF1", "595AF1" },
                        { "AFAFFF", "595AF1", "595AF1" },
                        { "FFB9A8", "BC5237", "6B1905" },
                        { "AFAFFF", "595AF1", "595AF1" }
                    };
                    string MainColor = bordColors[iEv, 2];



                    for (int i = -20; i <= 20; i++) // 50 - 70
                    {
                        //string col = Common.scaleColor(MainColor, "FFFFFF", 1.0 - Math.Pow((double)Math.Abs(i) / 20.0, 2));
                        string col = i == 0 ? "FFFFFF" : MainColor;
                        col = Common.scaleColor(MainColor, "FFFFFF", 1.0 - Math.Pow((double)Math.Abs(i) / 20.0, 3));
                        string alp = i == 0 ? "DD" : "DD";
                        ass_out.AppendEvent(70 - Math.Abs(i), evStyle, t0, t1,
                                            move(x + i * 2, y, x, y) + fad(0.15, 0) +
                                            a(1, "DD") + c(1, col) + blur(Math.Abs(i) * 0.2) +
                                            ke.KText);

                        /*ass_out.AppendEvent(70 - Math.Abs(i), evStyle, t1, t4,
                         *  pos(x + i * 0.06, y) +
                         *  a(1, "DD") + c(1, col) + blur(Math.Abs(i) * 0.2) +
                         *  ke.KText);*/
                        { // t1 - t4
                            double ptt0 = t2;
                            double ptt1 = t2;
                            double ptt2 = t2;
                            double ptt3 = t3 + 0.1;
                            if (ptt3 > t4)
                            {
                                ptt3 = t4;
                            }
                            if (ptt1 > t4)
                            {
                                ptt1 = ptt2 = ptt3;
                            }
                            else if (ptt1 > ptt2)
                            {
                                ptt2 = ptt3;
                            }
                            ass_out.AppendEvent(70 - Math.Abs(i), evStyle, t1, ptt0,
                                                pos(x + i * 0.06, y) +
                                                a(1, alp) + c(1, col) + blur(Math.Abs(i) * 0.2) +
                                                ke.KText);
                            ass_out.AppendEvent(70 - Math.Abs(i), evStyle, ptt0, ptt1,
                                                pos(x + i * 0.06, y) +
                                                a(1, alp) + c(1, col) + blur(Math.Abs(i) * 0.2) + t(fsc(130, 130).t()) +
                                                ke.KText);
                            ass_out.AppendEvent(70 - Math.Abs(i), evStyle, ptt1, ptt2,
                                                pos(x + i * 0.06, y) +
                                                a(1, alp) + c(1, col) + blur(Math.Abs(i) * 0.2) + fsc(130, 130) +
                                                ke.KText);
                            ass_out.AppendEvent(70 - Math.Abs(i), evStyle, ptt2, ptt3,
                                                pos(x + i * 0.06, y) +
                                                a(1, alp) + c(1, col) + blur(Math.Abs(i) * 0.2) + fsc(130, 130) + t(fsc(100, 100).t()) +
                                                ke.KText);
                            ass_out.AppendEvent(70 - Math.Abs(i), evStyle, ptt3, t4,
                                                pos(x + i * 0.06, y) +
                                                a(1, alp) + c(1, col) + blur(Math.Abs(i) * 0.2) +
                                                ke.KText);
                            if (i == 0)
                            {
                                {
                                    double[] timeSegs = { t0 + 0.2, ptt0, ptt1, ptt2, ptt3, t5 - 0.2 };
                                    string[] addStrs  = { fad(0.8, 0), t(fsc(130, 130).t()), fsc(130, 130), fsc(130, 130) + t(fsc(100, 100).t()), fad(0, 0.8) };
                                    for (int j = 0; j + 1 < timeSegs.Length; j++)
                                    {
                                        ass_out.AppendEvent(39, evStyle, timeSegs[j], timeSegs[j + 1],
                                                            pos(x, y) +
                                                            a(3, "33") + c(3, bordColors[iEv, 0]) + bord(3) + blur(3) + addStrs[j] +
                                                            ke.KText);
                                        ass_out.AppendEvent(38, evStyle, timeSegs[j], timeSegs[j + 1],
                                                            pos(x, y) +
                                                            a(3, "33") + c(3, bordColors[iEv, 1]) + bord(5) + blur(5) + addStrs[j] +
                                                            ke.KText);
                                        //if (new int[] { 0, 2, 3, 6, 7 }.Contains(iEv)) continue;
                                        ass_out.AppendEvent(37, evStyle, timeSegs[j], timeSegs[j + 1],
                                                            pos(x, y) +
                                                            a(3, "33") + c(3, bordColors[iEv, 2]) + bord(8) + blur(8) + addStrs[j] +
                                                            ke.KText);
                                    }
                                }

                                /*
                                 * ass_out.AppendEvent(29, evStyle, t0, ptt0,
                                 *  pos(x + i * 0.06 + 3, y + 3) + fad(0.3, 0) +
                                 *  a(1, "66") + c(1, "000000") + blur(2) +
                                 *  ke.KText);
                                 * ass_out.AppendEvent(29, evStyle, ptt0, ptt1,
                                 *  pos(x + i * 0.06 + 3, y + 3) +
                                 *  a(1, "66") + c(1, "000000") + blur(2) + t(fsc(130, 130).t()) +
                                 *  ke.KText);
                                 * ass_out.AppendEvent(29, evStyle, ptt1, ptt2,
                                 *  pos(x + i * 0.06 + 3, y + 3) +
                                 *  a(1, "66") + c(1, "000000") + blur(2) + fsc(130, 130) +
                                 *  ke.KText);
                                 * ass_out.AppendEvent(29, evStyle, ptt2, ptt3,
                                 *  pos(x + i * 0.06 + 3, y + 3) +
                                 *  a(1, "66") + c(1, "000000") + blur(2) + fsc(130, 130) + t(fsc(100, 100).t()) +
                                 *  ke.KText);
                                 * ass_out.AppendEvent(29, evStyle, ptt3, t5,
                                 *  pos(x + i * 0.06 + 3, y + 3) + fad(0, 0.3) +
                                 *  a(1, "66") + c(1, "000000") + blur(2) +
                                 *  ke.KText);
                                 * */
                            }
                        }
                        ass_out.AppendEvent(70 - Math.Abs(i), evStyle, t4, t5,
                                            move(x + i * 0.06, y, x + i * 2, y) + fad(0, 0.15) +
                                            a(1, "DD") + c(1, col) + blur(Math.Abs(i) * 0.2) +
                                            ke.KText);
                    }
                }
            }

            Console.WriteLine(ass_out.Events.Count);
            ass_out.SaveFile(this.OutFileName);
        }
Example #23
0
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS()
            {
                Header = ass_in.Header, Events = new List <ASSEvent>()
            };

            double[] light_time_offset = { 3.5, 3.8, 5.9, 4.9, 3.5 };
            double   light_spd         = 400;

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                bool isJp = iEv <= 4;
                this.MaskStyle = isJp ?
                                 "Style: Default,DFGMaruGothic-Md,38,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,1,0,0,5,0,0,0,128" :
                                 "Style: Default,方正准圆_GBK,40,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,1,0,0,5,0,0,0,1";
                this.FontHeight = isJp ? 38 : 40;
                int jEv = isJp ? iEv : iEv - 5;
                //if (!isJp) continue;
                //if (jEv > 0) continue;
                ASSEvent        ev         = ass_in.Events[iEv];
                List <KElement> kelems     = ev.SplitK(true);
                int             totalWidth = GetTotalWidth(ev);
                int             x0         = (PlayResX - MarginRight - totalWidth - MarginLeft) / 2 + MarginLeft;
                int             y0         = (isJp) ? (PlayResY - MarginBottom - FontHeight) : MarginTop;
                int             kSum       = 0;
                int             x0_start   = x0;
                int             lastx0     = 0;
                string          outlines   = "";
                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    double sr = (double)iK / (double)(kelems.Count - 1);
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                    KElement ke     = kelems[iK];
                    Size     sz     = GetSize(ke.KText);
                    double   kStart = ev.Start + kSum * 0.01;
                    double   kEnd   = kStart + ke.KValue * 0.01;
                    kSum += ke.KValue;
                    int x     = x0 + this.FontSpace + sz.Width / 2;
                    int y     = y0 + FontHeight / 2;
                    int x_an7 = x0;
                    int y_an7 = y0;
                    x0    += this.FontSpace + sz.Width;
                    lastx0 = x0;
                    if (ke.KText.Trim().Length == 0)
                    {
                        continue;
                    }
                    StringMask mask    = GetMask(ke.KText, x, y);
                    string     evStyle = isJp ? "ed_jp" : "ed_cn";

                    if (ke.KText == "?")
                    {
                        x += 15;
                    }

                    string outlineFontname = isJp ? "DFGMaruGothic-Md" : "方正准圆_GBK";
                    int    outlineEncoding = isJp ? 128 : 1;
                    int    xoffset         = isJp ? 0 : -1;
                    if (isJp && ke.KText[0] == '中')
                    {
                        xoffset = -2;
                    }
                    string outlineString = GetOutline(x - sz.Width / 2 + xoffset, y - FontHeight / 2, ke.KText[0], outlineFontname, outlineEncoding, FontHeight, 0, 262);
                    outlines += outlineString;

                    double t0 = ev.Start - 0.5 + iK * 0.1;
                    double t1 = t0 + 0.5;
                    double t2 = kStart;
                    double t3 = t2 + 0.8;
                    double t4 = ev.End - 0.5 + iK * 0.1;
                    double t5 = t4 + 0.5;

                    string main_col  = "9699E3";
                    string main_col2 = main_col;
                    if (jEv == 0 || jEv == 1)
                    {
                        main_col  = Common.scaleColor("93CB4B", "E4B281", (sr - 0.2) / 0.8);
                        main_col2 = Common.scaleColor("E4B281", "93CB4B", (sr - 0.2) / 0.8);
                    }
                    if (jEv == 3 || jEv == 4)
                    {
                        main_col  = Common.scaleColor("9699E3", "9CCFD5", "B0CE6E", (sr - 0.2) / 0.8);
                        main_col2 = Common.scaleColor("B0CE6E", "9CCFD5", "9699E3", (sr - 0.2) / 0.8);
                    }

                    if (!isJp)
                    {
                        ass_out.AppendEvent(50, evStyle, t0, t5,
                                            pos(x, y) + a(1, "00") + c(1, main_col) + shad(1) + a(4, "33") + c(4, "FFFFFF") + a(3, "66") +
                                            fad(0.5, 0.5) + blur(2) + bord(2) +
                                            ke.KText);
                        continue;
                    }

                    double midt = (x0 - sz.Width - (x0_start - 20)) / light_spd + light_time_offset[iEv] + ev.Start - 0.6;
                    ass_out.AppendEvent(50, evStyle, t0, midt + 0.5,
                                        pos(x, y) + a(1, "00") + c(1, main_col) + shad(1) + a(4, "33") + c(4, "FFFFFF") + a(3, "66") +
                                        fad(0.5, 0.5) + blur(2) + bord(2) +
                                        ke.KText);
                    ass_out.AppendEvent(50, evStyle, midt, t5,
                                        pos(x, y) + a(1, "00") + c(1, main_col2) + shad(1) + a(4, "33") + c(4, "FFFFFF") + a(3, "66") +
                                        fad(0.5, 0.5) + blur(2) + bord(2) +
                                        ke.KText);

                    ass_out.AppendEvent(55, evStyle, t2, t3,
                                        pos(x, y) + a(1, "55") + c(1, "FFFFFF") + a(3, "55") + c(3, "FFFFFF") + blur(3) + bord(3) + fad(0, t3 - t2) +
                                        ke.KText);

                    if (iEv <= 2)
                    {
                        int tmpyy = Common.RandomInt(rnd, 0, 1);
                        for (int i = 0; i < Common.RandomInt(rnd, 1, 2); i++)
                        {
                            double ptt0 = t2 + Common.RandomDouble(rnd, 0, 0.1);
                            double ptx0 = Common.RandomDouble(rnd, x - sz.Width / 2, x + sz.Width / 2);
                            double yd   = Common.RandomDouble(rnd, 35, 50);
                            double pty0 = 0;
                            double pty1 = 0;
                            if ((tmpyy + i) % 2 == 0)
                            {
                                pty0 = y - yd;
                                pty1 = y + yd;
                            }
                            else
                            {
                                pty0 = y + yd;
                                pty1 = y - yd;
                            }
                            double spd   = 40;
                            string ptcol = (ptt0 < midt + 0.5) ? main_col : main_col2;
                            double ptt1  = ptt0 + Math.Abs(pty0 - pty1) / spd;
                            ass_out.AppendEvent(30, "pt", ptt0, ptt1,
                                                an(5) + move(ptx0, pty0, ptx0, pty1) + a(1, "00") + c(1, ptcol) +
                                                blur(5) + fs(30) + t(fsc(0, 0).t()) +
                                                '●');
                            ass_out.AppendEvent(31, "pt", ptt0, ptt1,
                                                an(5) + move(ptx0, pty0, ptx0, pty1) + a(1, "00") + c(1, Common.scaleColor("FFFFFF", ptcol, 0.7)) +
                                                blur(2.2) + fs(25) + t(fsc(0, 0).t()) +
                                                '●');
                            ass_out.AppendEvent(32, "pt", ptt0, ptt1,
                                                an(5) + move(ptx0, pty0, ptx0, pty1) + a(1, "00") +
                                                blur(1.8) + fs(12) + t(fsc(0, 0).t()) +
                                                '●');
                        }
                    }

                    if (iEv >= 3)
                    {
                        {
                            double           ptt0   = t2 - 0.4;
                            double           ptt1   = t2;
                            string           ptcol  = (ptt0 < midt + 0.5) ? main_col : main_col2;
                            double           theta1 = Common.RandomDouble(rnd, 0, Math.PI);
                            List <BaseCurve> curves = new List <BaseCurve>();
                            double           ra     = 30;
                            double           rb     = 7;
                            Circle2          cl     = new Circle2 {
                                NormTheta = false, X0 = x, Y0 = y, A = ra, B = rb, MinT = -Math.PI * 0.5, MaxT = Math.PI * 0.5, Theta = theta1, dTheta = 0
                            };
                            CompositeCurve cc = new CompositeCurve {
                                MinT = ptt0, MaxT = ptt1
                            };
                            cc.AddCurve(cc.MinT, cc.MaxT, cl);
                            curves.Add(cc);
                            cl = new Circle2 {
                                NormTheta = false, X0 = x, Y0 = y, A = ra, B = rb, MinT = -Math.PI * 0.5, MaxT = -Math.PI * 1.5, Theta = theta1, dTheta = 0
                            };
                            cc = new CompositeCurve {
                                MinT = ptt0, MaxT = ptt1
                            };
                            cc.AddCurve(cc.MinT, cc.MaxT, cl);
                            curves.Add(cc);
                            foreach (BaseCurve curve in curves)
                            {
                                foreach (ASSPointF pt in curve.GetPath_Dis(1, 1.1))
                                {
                                    ass_out.AppendEvent((pt.Theta >= 0 || pt.Theta <= -Math.PI) ? 100 : 0, "pt", pt.T, pt.T + 0.3,
                                                        an(5) + pos(pt.X, pt.Y) + a(1, "00") + c(1, "FFFFFF") + a(3, "77") + c(3, ptcol) +
                                                        bord(3) + blur(3) + fs(8) + t(fsc(0, 0).t() + bord(0).t()) +
                                                        '●');
                                }
                                foreach (ASSPointF pt in curve.GetPath_DT(0.03))
                                {
                                    ass_out.AppendEvent((pt.Theta >= 0 || pt.Theta <= -Math.PI) ? 101 : 1, "pt", pt.T, pt.T + 0.03,
                                                        an(5) + pos(pt.X, pt.Y) + a(1, "00") + c(1, "FFFFFF") +
                                                        blur(5) + fs(12) +
                                                        '●');
                                }
                            }
                            ass_out.AppendEvent(100, evStyle, ptt1, ptt1 + 0.5,
                                                pos(x, y) + a(1, "00") + a(3, "00") + bord(3) + blur(3) + fad(0, 0.3) +
                                                ke.KText);
                        }

                        for (int i = 0; i < 40; i++)
                        {
                            double ptt0  = t2 + Common.RandomDouble(rnd, 0, 0.1);
                            double ptx0  = x;
                            double pty0  = y;
                            double sc    = Common.RandomDouble(rnd, 2, 3);
                            double ptx1  = Common.RandomDouble(rnd, x - sz.Width * sc, x + sz.Width * sc);
                            double pty1  = Common.RandomDouble(rnd, y - sz.Width * sc, y + sz.Width * sc);
                            double spd   = 40;
                            string ptcol = (ptt0 < midt + 0.5) ? main_col : main_col2;
                            double ptt1  = ptt0 + Common.GetDistance(ptx0, pty0, ptx1, pty1) / spd;
                            ass_out.AppendEvent(30, "pt", ptt0, ptt1,
                                                an(5) + move(ptx0, pty0, ptx1, pty1) + a(1, "00") + c(1, ptcol) +
                                                blur(8) + fs(30) + t(fsc(0, 0).t()) +
                                                '●');
                            ass_out.AppendEvent(31, "pt", ptt0, ptt1,
                                                an(5) + move(ptx0, pty0, ptx1, pty1) + a(1, "00") + c(1, Common.scaleColor("FFFFFF", ptcol, 0.7)) +
                                                blur(2.2) + fs(25) + t(fsc(0, 0).t()) +
                                                '●');
                            ass_out.AppendEvent(32, "pt", ptt0, ptt1,
                                                an(5) + move(ptx0, pty0, ptx1, pty1) + a(1, "00") +
                                                blur(1.8) + fs(12) + t(fsc(0, 0).t()) +
                                                '●');
                        }
                    }
                }

                if (isJp)
                {
                    double ptt0 = ev.Start + light_time_offset[iEv] - 0.7;
                    double ptx0 = x0_start - 20;
                    double ptx1 = lastx0 + 20;
                    double ptt1 = ptt0 + (ptx1 - ptx0) / light_spd;
                    ass_out.AppendEvent(100, "pt", ptt0, ptt1,
                                        clip(4, outlines) + move(ptx0, y0 + FontHeight / 2, ptx1, y0 + FontHeight / 2) +
                                        a(1, "55") + frz(-45) + blur(8) + fscx(200) +
                                        p(1) + "m 10 -50 l 10 50 -10 50 -10 -50");
                }
            }

            Console.WriteLine(ass_out.Events.Count);
            ass_out.SaveFile(this.OutFileName);
        }
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS()
            {
                Header = ass_in.Header, Events = new List <ASSEvent>()
            };

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                ASSEvent        ev     = ass_in.Events[iEv];
                List <KElement> kelems = ev.SplitK(false);
                int             sw     = GetTotalWidth(ev);
                int             x0     = (PlayResX - sw) / 2;
                int             xxx    = x0;
                int             y0     = PlayResY - MarginBottom - FontHeight;
                int             kSum   = 0;
                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                    KElement ke     = kelems[iK];
                    Size     sz     = GetSize(ke.KText);
                    double   kStart = ev.Start + kSum * 0.01;
                    double   kEnd   = kStart + ke.KValue * 0.01;
                    kSum += ke.KValue;
                    int        x     = x0 + this.FontSpace + sz.Width / 2;
                    int        y     = y0 + FontHeight / 2;
                    int        x_an7 = x0;
                    int        y_an7 = y0;
                    StringMask mask  = GetMask(ke.KText, x, y);
                    x0 += this.FontSpace + sz.Width;
                    if (ke.KText.Trim().Length == 0)
                    {
                        continue;
                    }

                    double t0 = ev.Start - 0.5 + iK * 0.05;
                    double t1 = t0 + 0.3;
                    double t2 = kStart - 0.07;
                    double t3 = kEnd;
                    double t4 = ev.End - 0.5 + iK * 0.05;
                    double t5 = t4 + 0.3;

                    Func <double, string> fMainColor = ti => (ti < t2) ? Common.scaleColor("FFFFFF", "000000", (ti - t1) / 0.2) : "FFFFFF";
                    Func <double, string> fMainAlpha = ti => (ti < t2) ? "55" : "00";

                    ass_out.AppendEvent(60, "jp", t0, t1,
                                        move(x - 100, y, x, y) + a(1, "55") + fsc(150, 150) + fad(t1 - t0, 0) +
                                        frx(Common.RandomInt(rnd, 200, 500)) +
                                        fry(Common.RandomInt(rnd, 200, 500)) +
                                        frz(Common.RandomInt(rnd, 200, 500)) +
                                        t(frx(0).t() + fry(0).t() + frz(0).t() + fsc(100, 100).t()) +
                                        ke.KText);
                    ass_out.AppendEvent(55, "jp", t2, t2 + 0.25,
                                        pos(x, y) + a(1, "00") + bord(8) + blur(8) + fad(0, 0.18) + a(3, "00") +
                                        ke.KText);
                    {
                        double ti = t1;
                        while (ti < t4)
                        {
                            double ti1 = ti + 0.04;
                            ass_out.AppendEvent(50, "jp", ti, ti1 + 0.04,
                                                pos(Common.RandomInt(rnd, x - 3, x + 3), Common.RandomInt(rnd, y - 3, y + 3)) + a(1, fMainAlpha(ti)) + fad(0, Common.RandomDouble(rnd, 0.04, 0.09)) +
                                                c(1, fMainColor(ti)) +
                                                ke.KText);
                            ti = ti1;
                        }
                        ass_out.AppendEvent(60, "jp", ti, t5,
                                            move(x, y, x + 100, y) + a(1, "00") + fad(0, t5 - ti) + c(1, "FFFFFF") +
                                            t(frx(Common.RandomInt(rnd, 200, 500)).t() + fry(Common.RandomInt(rnd, 200, 500)).t() + frz(Common.RandomInt(rnd, 200, 500)).t() + fsc(150, 150).t()) +
                                            ke.KText);
                    }

                    string cShad = "000000";
                    for (int i = 0; i < 2; i++)
                    {
                        ass_out.AppendEvent(40, "jp", t1, t4,
                                            pos(x, y) + a(1, "00") + blur(2) + c(1, cShad) +
                                            ke.KText);
                    }

                    {
                        CompositeCurve curve = new CompositeCurve {
                            MinT = t2 - 0.1, MaxT = t2 + 0.1
                        };
                        double ptag = Common.RandomDouble(rnd, 0, Math.PI);
                        double ptr  = 100;
                        double ptx0 = x + Math.Cos(ptag) * ptr;
                        double pty0 = y - Math.Sin(ptag) * ptr;
                        double ptx1 = x - Math.Cos(ptag) * ptr;
                        double pty1 = y + Math.Sin(ptag) * ptr;
                        Line   line = new Line {
                            X0 = ptx0, Y0 = pty0, X1 = ptx1, Y1 = pty1
                        };
                        curve.AddCurve(curve.MinT, curve.MaxT, line);
                        List <ASSPointF> pts = curve.GetPath_Dis(1, 1.2);
                        foreach (ASSPointF pt in pts)
                        {
                            if (!Common.InRange(0, PlayResX, pt.X) || !Common.InRange(0, PlayResY, pt.Y))
                            {
                                continue;
                            }
                            ass_out.AppendEvent(30, "pt", pt.T, pt.T + 0.25,
                                                pos(pt.X, pt.Y) + a(1, "00") + a(3, "77") + c(1, "FFD9A1") + c(3, "FFD9A1") + fad(0, 0.1) +
                                                bord(4) + blur(4) + t(bord(2).t() + blur(2).t()) +
                                                p(1) + "m 0 0 l 1 0 1 1 0 1");
                            ass_out.AppendEvent(32, "pt", pt.T, pt.T + 0.25,
                                                pos(pt.X, pt.Y) + a(1, "00") + a(3, "44") + c(1, "FFFFFF") + c(3, "FFFFFF") + fad(0, 0.1) +
                                                bord(2.5) + blur(2.5) + t(bord(1.3).t() + blur(1.3).t()) +
                                                p(1) + "m 0 0 l 1 0 1 1 0 1");
                        }
                        pts = curve.GetPath_DT(0.01);
                        foreach (ASSPointF pt in pts)
                        {
                            if (!Common.InRange(0, PlayResX, pt.X) || !Common.InRange(0, PlayResY, pt.Y))
                            {
                                continue;
                            }
                            ass_out.AppendEvent(35, "pt", pt.T, pt.T + 0.01,
                                                pos(pt.X, pt.Y) + a(1, "00") + a(3, "00") + c(1, "FFFFFF") + c(3, "FFFFFF") +
                                                bord(13) + blur(13) +
                                                p(1) + "m 0 0 l 1 0 1 1 0 1");
                        }
                    }
                }
            }

            Console.WriteLine(ass_out.Events.Count);
            ass_out.SaveFile(this.OutFileName);
        }
Example #25
0
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            ass_out.Events.Add(ass_in.Events[0]);

            this.Font = new System.Drawing.Font("DFGRuLeiA-W5", 13);
            Particle pt = new Particle
            {
                AreaHeight    = 50,
                AreaWidth     = 100,
                IsRandomColor = false,
                Color         = new ASSColor {
                    A = 0, R = 255, G = 255, B = 255, Index = 1
                },
                Count           = 10,
                FontSize        = this.FontHeight,
                MinLast         = 1,
                MaxLast         = 2,
                IsMove          = true,
                IsPatternScale  = true,
                PatternScaleX   = 250,
                PatternScaleY   = 250,
                ParticlePattern = ParticlePatternType.Circle,
                Style           = "particle",
                XOffset         = 0,
                YOffset         = 0,
                IsRotate        = false,
            };

            for (int i = 1; i <= 15; i++)
            {
                ASSEvent        ev     = ass_in.Events[i];
                List <KElement> kelems = ev.SplitK(false);
                int             sumw   = GetTotalWidth(ev);
                int             x0     = (PlayResX - MarginLeft - MarginRight - sumw) / 2 + MarginLeft;
                int             kSum   = 0;
                for (int ik = 0; ik < kelems.Count; ik++)
                {
                    KElement elem = kelems[ik];
                    Size     sz   = this.GetSize(elem.KText);
                    int      x    = x0;
                    x0 += sz.Width + this.FontSpace;
                    int    y      = MarginTop;
                    string color  = Common.scaleColor("7A93EB", "6939C8", (double)ik / (double)(kelems.Count - 1));
                    double kStart = (double)kSum * 0.01;
                    double kEnd   = (double)(kSum + elem.KValue) * 0.01;
                    double kMid   = (kStart + kEnd) * 0.5;
                    double kQ1    = kStart + (kEnd - kStart) * 0.25;

                    // an7 -> an5
                    int x5 = x + sz.Width / 2;
                    int y5 = y + sz.Height / 2;

                    ass_out.Events.Add(ev.TextReplace(ASSEffect.pos(x5, y5) + ASSEffect.c(1, color) +
                                                      ASSEffect.t(0, 0.001, ASSEffect.c(1, "555555").t()) +
                                                      ASSEffect.t(kStart, kQ1, ASSEffect.c(1, "FFFFFF").t() + ASSEffect.fsc(170, 170).t()) +
                                                      ASSEffect.t(kQ1, kEnd, ASSEffect.c(1, color).t() + ASSEffect.fsc(100, 100).t()) +
                                                      elem.KText));

                    pt.X     = x;
                    pt.Y     = y;
                    pt.Start = ev.Start + kStart;
                    pt.End   = ev.Start + kEnd;

                    ass_out.Events.AddRange(pt.Create());

                    kSum += elem.KValue;
                }
            }

            for (int i = 16; i <= 30; i++)
            {
                ass_out.Events.Add(ass_in.Events[i]);
            }

            ass_out.SaveFile(this.OutFileName);
        }
Example #26
0
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS()
            {
                Header = ass_in.Header, Events = new List <ASSEvent>()
            };

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                bool isJp = true;
                this.MaskStyle = isJp ?
                                 "Style: Default,DFMincho-UB,38,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,5,0,0,0,128" :
                                 "Style: Default,汉仪粗宋繁,38,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,1,0,0,0,100,100,0,0,0,0,0,5,0,0,0,134";
                ASSEvent        ev       = ass_in.Events[iEv];
                List <KElement> kelems   = ev.SplitK(true);
                int             x0       = (PlayResX - GetTotalWidth(ev) - MarginLeft - MarginRight) / 2 + MarginLeft;
                int             x0_start = x0;
                int             y0       = MarginTop;
                int             kSum     = 0;

                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    //if (iK > 0) break;
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                    string   evStyle         = isJp ? "jp" : "cn";
                    string   outlineFontname = isJp ? "DFMincho-UB" : "汉仪粗宋繁";
                    int      outlineEncoding = isJp ? 128 : 134;
                    KElement ke = kelems[iK];
                    Size     sz = GetSize(ke.KText);
                    if (ke.KText[0] == 'く')
                    {
                        x0 += 2;
                    }
                    double kStart = ev.Start + kSum * 0.01;
                    double kEnd   = kStart + ke.KValue * 0.01;
                    kSum += ke.KValue;
                    int        x     = x0 + this.FontSpace + sz.Width / 2;
                    int        y     = y0 + FontHeight / 2;
                    int        x_an7 = x0 + 2;
                    int        y_an7 = y0;
                    StringMask mask  = GetMask(ke.KText, x, y);
                    x0 += this.FontSpace + sz.Width;
                    if (ke.KText.Trim().Length == 0)
                    {
                        continue;
                    }
                    string outlineString = GetOutline(x - FontHeight / 2, y - FontHeight / 2, ke.KText[0], outlineFontname, outlineEncoding, 38, 0, 262);

                    double t0 = ev.Start - 0.7 + (x - x0) / PlayResX * 3.0;
                    double t1 = t0 + 0.5;
                    double t2 = (ke.IsSplit ? ke.KStart_NoSplit : kStart) - 0.05;
                    double t25 = t2 + ke.KValue * 0.01;
                    double t21 = 0, t24 = 0;
                    {
                        t21 = (t25 - t2) * 0.3 + t2;
                        if (t21 - t2 > 0.1)
                        {
                            t21 = t2 + 0.1;
                        }
                        t24 = t21;
                    }
                    double t3 = ev.End - 0.7 + (x - x0) / PlayResX * 3.0;
                    if (t25 > t3)
                    {
                        t25 = t3;
                    }
                    if (iK == kelems.Count - 1)
                    {
                        t25 = t3 + 0.25;
                    }
                    double t4 = t3 + 0.5;

                    ass_out.AppendEvent(50, evStyle, t0, t2,
                                        pos(x, y) + fad(0.5, 0) + a(1, "33") + c(1, "2425FF") +
                                        ke.KText);
                    ass_out.AppendEvent(49, evStyle, t0, t2,
                                        pos(x + 1.5, y + 1.5) + fad(0.5, 0) + a(1, "33") + c(1, "000000") + blur(1) +
                                        ke.KText);
                    ass_out.AppendEvent(47, evStyle, t0, t2,
                                        pos(x, y) + fad(0.5, 0) + a(3, "44") + c(3, "000052") + bord(2.5) + blur(3) +
                                        ke.KText);

                    ass_out.AppendEvent(51, evStyle, t2, t21,
                                        pos(x, y) + t(fsc(130, 130).t()) + a(1, "00") + c(1, "FFFFFF") + blur(0.8) +
                                        ke.KText);
                    ass_out.AppendEvent(51, evStyle, t21, t24,
                                        pos(x, y) + fsc(130, 130) + a(1, "00") + c(1, "FFFFFF") + blur(0.8) +
                                        ke.KText);
                    ass_out.AppendEvent(51, evStyle, t24, t25,
                                        pos(x, y) + fsc(130, 130) + t(fsc(100, 100).t()) + a(1, "00") + c(1, "FFFFFF") + blur(0.8) +
                                        ke.KText);
                    ass_out.AppendEvent(51, evStyle, t2, t21,
                                        pos(x, y) + t(fsc(130, 130).t()) + a(3, "22") + c(3, "0000FF") + blur(3) + bord(3) +
                                        ke.KText);
                    ass_out.AppendEvent(51, evStyle, t21, t24,
                                        pos(x, y) + fsc(130, 130) + a(3, "22") + c(3, "0000FF") + blur(3) + bord(3) +
                                        ke.KText);
                    ass_out.AppendEvent(51, evStyle, t24, t25,
                                        pos(x, y) + fsc(130, 130) + t(fsc(100, 100).t()) + a(3, "22") + c(3, "0000FF") + blur(3) + bord(3) +
                                        ke.KText);

                    ass_out.AppendEvent(50, evStyle, t25, t4,
                                        pos(x, y) + fad(0, 0.5) + a(1, "33") + c(1, "2425FF") +
                                        ke.KText);
                    ass_out.AppendEvent(49, evStyle, t25, t4,
                                        pos(x + 1.5, y + 1.5) + fad(0, 0.5) + a(1, "33") + c(1, "000000") + blur(1) +
                                        ke.KText);
                    ass_out.AppendEvent(47, evStyle, t25, t4,
                                        pos(x, y) + fad(0, 0.5) + a(3, "44") + c(3, "000052") + bord(2.5) + blur(3) +
                                        ke.KText);
                }
            }

            Console.WriteLine(ass_out.Events.Count);
            ass_out.SaveFile(this.OutFileName);
        }
Example #27
0
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS();

            ass_out.Header = ass_in.Header;
            ass_out.Events = new List <ASSEvent>();

            this.Font = new System.Drawing.Font("FA 瑞筆行書M", 13);

            Particle pt = new Particle
            {
                AreaHeight    = 80,
                AreaWidth     = 200,
                IsRandomColor = true,
                Color         = new ASSColor {
                    A = 0, R = 255, G = 255, B = 255, Index = 1
                },
                Color1 = new ASSColor {
                    A = 0, R = 255, G = 255, B = 255, Index = 1
                },
                Color2 = new ASSColor {
                    A = 0, R = 0xEF, G = 0xF7, B = 0xFB, Index = 1
                },
                Count           = 100,
                FontSize        = this.FontHeight,
                MinLast         = 1,
                MaxLast         = 2,
                IsMove          = true,
                MoveStyle       = 2,
                IsPatternScale  = false,
                PatternScaleX   = 250,
                PatternScaleY   = 250,
                ParticlePattern = ParticlePatternType.o,
                Style           = "pt",
                XOffset         = 0,
                YOffset         = 0,
                IsRotate        = true,
                BE = 1
            };

            for (int i = 0; i < 20; i++)
            {
                if (i >= 10)
                {
                    this.Font = new System.Drawing.Font("華康行書體(P)", 13);
                }
                ASSEvent        ev     = ass_in.Events[i];
                List <KElement> kelems = ev.SplitK(false);
                int             sumw   = GetTotalWidth(ev);
                int             x0     = (PlayResX - MarginLeft - MarginRight - sumw) / 2 + MarginLeft;
                int             kSum   = 0;
                for (int ik = 0; ik < kelems.Count; ik++)
                {
                    KElement elem = kelems[ik];
                    Size     sz   = this.GetSize(elem.KText);
                    int      x    = x0;
                    x0 += sz.Width + this.FontSpace;
                    int y = PlayResY - MarginBottom;
                    if (i >= 10)
                    {
                        y = MarginTop + FontHeight;
                    }
                    double kStart = (double)kSum * 0.01;
                    double kEnd   = (double)(kSum + elem.KValue) * 0.01;
                    kEnd = kStart + 0.6;
                    double kMid = (kStart + kEnd) * 0.5;
                    double kQ1  = kStart + (kEnd - kStart) * 0.1;

                    double r  = (double)ik / (double)(kelems.Count - 1);
                    double r0 = 1.0 - r;

                    int fd_xof = (int)((double)(ik - (kelems.Count - 1) / 2) / (double)(kelems.Count - 1) * (double)PlayResX * 0.2);

                    // particle need an7 position
                    pt.X     = x;
                    pt.Y     = y - FontHeight;
                    pt.Start = ev.Start + kStart;
                    pt.End   = ev.Start + kEnd;

                    // an7 -> an5
                    x += FontWidth / 2;
                    y -= FontHeight / 2;

                    // 提前1秒出现
                    ass_out.Events.Add(ev.StartReplace(ev.Start - r0 * 1.0).TextReplace(
                                           ASSEffect.fad(0.3, 0) + ASSEffect.be(1) +
                                           ASSEffect.pos(x, y) + ASSEffect.an(5) +
                                           ASSEffect.t(kStart + r0 * 1.0, kEnd + r0 * 1.0, ASSEffect.be(10).t() + ASSEffect.a(1, "FF").t()) +
                                           ASSEffect.t(kStart + r0 * 1.0 + 0.2, kEnd + r0 * 1.0, ASSEffect.a(3, "FF").t()) +
                                           elem.KText));

                    ass_out.Events.AddRange(pt.Create());

                    kSum += elem.KValue;
                }
            }

            ass_out.SaveFile(OutFileName);
        }
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS()
            {
                Header = ass_in.Header, Events = new List <ASSEvent>()
            };

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                ASSEvent ev   = ass_in.Events[iEv];
                bool     isJp = true;
                this.MaskStyle = "Style: Default,DFGMaruGothic-Md,38,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,5,0,0,0,128";

                //if (iEv != 0) continue;

                List <KElement> kelems = ev.SplitK(!isJp);
                int             tw     = GetTotalWidth(ev);
                int             x0     = (PlayResX - MarginLeft - MarginRight - tw) / 2 + MarginLeft;
                int             y0     = isJp ? (PlayResY - MarginBottom - FontHeight) : MarginTop;
                int             x0_bak = x0;

                int kSum = 0;

                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                    KElement ke     = kelems[iK];
                    Size     sz     = GetSize(ke.KText);
                    double   kStart = ev.Start + kSum * 0.01;
                    double   kEnd   = kStart + ke.KValue * 0.01;
                    kSum += ke.KValue;
                    int        x     = x0 + this.FontSpace + sz.Width / 2;
                    int        y     = y0 + FontHeight / 2;
                    int        x_an7 = x0;
                    int        y_an7 = y0;
                    StringMask mask  = GetMask(ke.KText, x, y);
                    x0 += this.FontSpace + sz.Width;
                    if (ke.KText.Trim().Length == 0)
                    {
                        continue;
                    }

                    string evStyle = ev.Style;

                    double t0 = ev.Start - 0.6 + iK * 0.08;
                    double t1 = t0 + 0.6;
                    double t2 = kStart;
                    double t3 = kEnd;
                    double t4 = ev.End - 0.6 + iK * 0.08;
                    double t5 = t4 + 0.6;

                    double xCenter  = PlayResX * 0.5;
                    double dxCenter = x - xCenter;

                    ass_out.AppendEvent(50, evStyle, t0, t1,
                                        pos(x, y) + fad(t1 - t0, 0) + a(1, "00") +
                                        blur(10) + t(blur(0.5).t()) +
                                        ke.KText);
                    ass_out.AppendEvent(50, evStyle, t1, t5,
                                        pos(x, y) + fad(0, t5 - t4) + a(1, "00") +
                                        blur(0.5) +
                                        ke.KText);

                    ass_out.AppendEvent(48, evStyle, t0, t5,
                                        pos(x + 1.5, y + 1.5) + fad(t1 - t0, t5 - t4) +
                                        a(1, "22") + c(1, "000000") + blur(1) +
                                        ke.KText);
                    ass_out.AppendEvent(49, evStyle, t0, t5,
                                        pos(x, y) + fad(t1 - t0, t5 - t4) +
                                        a(1, "55") + c(1, "000000") + blur(3) +
                                        ke.KText);
                }
            }

            Console.WriteLine(ass_out.Events.Count);
            ass_out.SaveFile(this.OutFileName);
        }
Example #29
0
        public ASSEvent Apply(ASSEvent src)
        {
            if (ActionType == TemplateActionType.Copy)
            {
                return(src.Clone() as ASSEvent);
            }
            ASSEvent target;

            if (ActionType == TemplateActionType.New)
            {
                target = new ASSEvent();
            }
            target = src.Clone() as ASSEvent;

            foreach (var p in Parameters)
            {
                var left  = p.Left;
                var right = p.Escape(target);
                var prop  = target.GetType().GetProperty(left, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase);
                var value = prop.GetValue(target);
                switch (p.Oprt)
                {
                case TemplateActionParameterOperator.Assign:
                    if (value.GetType().Name.Equals("string", StringComparison.OrdinalIgnoreCase))
                    {
                        prop.SetValue(target, right);
                    }
                    if (value.GetType().Name.Equals("ASSEventTime", StringComparison.OrdinalIgnoreCase))
                    {
                        prop.SetValue(target, new ASSEventTime(right));
                    }
                    if (value.GetType().Name.Equals("int", StringComparison.OrdinalIgnoreCase) ||
                        value.GetType().Name.Equals("Int32", StringComparison.OrdinalIgnoreCase))
                    {
                        prop.SetValue(target, Convert.ToInt32(right));
                    }
                    break;

                case TemplateActionParameterOperator.Plus:
                    if (value.GetType().Name.Equals("string", StringComparison.OrdinalIgnoreCase))
                    {
                        prop.SetValue(target, prop.GetValue(target).ToString() + right);
                    }
                    if (value.GetType().Name.Equals("ASSEventTime", StringComparison.OrdinalIgnoreCase))
                    {
                        prop.SetValue(target, (prop.GetValue(target) as ASSEventTime + Convert.ToDouble(right)));
                    }
                    if (value.GetType().Name.Equals("int", StringComparison.OrdinalIgnoreCase) ||
                        value.GetType().Name.Equals("Int32", StringComparison.OrdinalIgnoreCase))
                    {
                        prop.SetValue(target, Convert.ToInt32(prop.GetValue(target)) + Convert.ToInt32(right));
                    }
                    break;

                case TemplateActionParameterOperator.Minus:
                    if (value.GetType().Name.Equals("string", StringComparison.OrdinalIgnoreCase))
                    {
                        prop.SetValue(target, prop.GetValue(target).ToString());
                    }
                    if (value.GetType().Name.Equals("ASSEventTime", StringComparison.OrdinalIgnoreCase))
                    {
                        prop.SetValue(target, (prop.GetValue(target) as ASSEventTime - Convert.ToDouble(right)));
                    }
                    if (value.GetType().Name.Equals("int", StringComparison.OrdinalIgnoreCase) ||
                        value.GetType().Name.Equals("Int32", StringComparison.OrdinalIgnoreCase))
                    {
                        prop.SetValue(target, Convert.ToInt32(prop.GetValue(target)) - Convert.ToInt32(right));
                    }
                    break;
                }
            }

            return(target);
        }
Example #30
0
        public override void Run()
        {
            ASS ass_in  = ASS.FromFile(this.InFileName);
            ASS ass_out = new ASS()
            {
                Header = ass_in.Header, Events = new List <ASSEvent>()
            };

            for (int iEv = 0; iEv < ass_in.Events.Count; iEv++)
            {
                //if (iEv > 0) continue;

                bool isJp = true;

                ASSEvent        ev         = ass_in.Events[iEv];
                List <KElement> kelems     = ev.SplitK(true);
                int             x0         = MarginLeft;
                int             totalWidth = 0;
                if (isJp)
                {
                    foreach (KElement ke in kelems)
                    {
                        this.MaskStyle = "Style: Default,宋体,40,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,7,0,0,0,0";
                        string outlineFontname = "DFSoGei-W5";
                        int    outlineEncoding = isJp ? 128 : 136;
                        int    yoffset         = 279;
                        int    ox_offset       = 0;
                        string outlineString   = GetOutline(10, 10, ke.KText[0], outlineFontname, outlineEncoding, FontHeight, 0, yoffset);
                        //Size sz = GetMask(p(4) + outlineString, 0, 0).GetSize();
                        //if (ke.KText.Trim().Length == 0) sz.Width = this.FontHeight;
                        Size sz = GetSize(ke.KText);
                        totalWidth += sz.Width + FontSpace;
                    }
                    x0 = (PlayResX - MarginLeft - MarginRight - totalWidth) / 2 + MarginLeft;

                    if (iEv == 11)
                    {
                        x0 = MarginLeft;
                    }
                    if (iEv == 12)
                    {
                        x0 = PlayResX - MarginRight - totalWidth;
                    }
                }
                else
                {
                    totalWidth = GetTotalWidth(ev);
                }
                int    bakx0    = x0;
                int    y0       = isJp ? (PlayResY - MarginBottom - FontHeight) : MarginTop;
                int    kSum     = 0;
                string outlines = "";
                double lastx0   = 0;
                double lastt0   = 0;
                for (int iK = 0; iK < kelems.Count; iK++)
                {
                    Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count);
                    KElement ke = kelems[iK];
                    this.MaskStyle = "Style: Default,宋体,40,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,7,0,0,0,0";
                    string outlineFontname = "DFSoGei-W5";
                    int    outlineEncoding = isJp ? 128 : 136;
                    int    yoffset         = 279;
                    int    ox_offset       = 0;
                    string outlineString   = "";
                    Size   sz      = new Size();
                    int    xoffset = 0;
                    if (ke.KText == "i")
                    {
                        xoffset = -3;
                    }
                    if (ke.KText == "e" && kelems[iK + 1].KText.Trim() == "")
                    {
                        xoffset = 3;
                    }
                    ox_offset = xoffset;
                    if (ke.KText.Trim().Length > 0)
                    {
                        outlineString = GetOutline(10, 10, ke.KText[0], outlineFontname, outlineEncoding, FontHeight, 0, yoffset);
                    }
                    sz = GetSize(ke.KText);
                    double kStart = ev.Start + kSum * 0.01;
                    double kEnd   = kStart + ke.KValue * 0.01;
                    if (ke.IsSplit)
                    {
                        kStart = ke.KStart_NoSplit;
                        kEnd   = ke.KEnd_NoSplit;
                    }
                    kSum += ke.KValue;
                    int x     = x0 + this.FontSpace + sz.Width / 2;
                    int y     = y0 + FontHeight / 2;
                    int x_an7 = x0;
                    int y_an7 = y0;
                    lastx0 = x0;
                    x0    += this.FontSpace + sz.Width;
                    if (ke.KText.Trim().Length == 0)
                    {
                        continue;
                    }
                    outlineString = GetOutline(ox_offset + x - sz.Width / 2, y - FontHeight / 2, ke.KText[0], outlineFontname, outlineEncoding, FontHeight, 0, yoffset);
                    outlines     += outlineString;

                    string evStyle = "op_jp";

                    ass_out.AppendEvent(60, "pt", kStart, kEnd + 0.2,
                                        pos(0, 0) + a(1, "00") + fad(0.05, kEnd + 0.2 - kStart - 0.05 - 0.08) + a(3, "22") + bord(5) + blur(5) +
                                        p(4) + outlineString);
                    ass_out.AppendEvent(61, "pt", kStart, kEnd + 0.2,
                                        pos(0, 0) + a(1, "00") + fad(0.05, kEnd + 0.2 - kStart - 0.05 - 0.08) + a(3, "22") + bord(3) + blur(3) +
                                        p(4) + outlineString);

                    // shadow
                    ass_out.AppendEvent(48, "pt", ev.Start - 0.2, ev.End + 0.2,
                                        fad(0.3, 0.3) + pos(3.5, 3.5) + a(1, "00") + c(1, "222222") + blur(1.2) +
                                        p(4) + outlineString);
                    // border
                    ass_out.AppendEvent(49, "pt", ev.Start - 0.2, ev.End + 0.2,
                                        fad(0.3, 0.3) + pos(0, 0) + a(3, "22") + c(3, "FFFFFF") + bord(2.5) + blur(1) +
                                        p(4) + outlineString);

                    double pC = (kEnd - kStart) * 50 * 4 * sz.Width / this.FontHeight;
                    if (iEv > 8 || (iEv == 8 && Common.IsLetter(ke.KText[0])))
                    {
                        pC *= 2.1;
                    }
                    for (int iP = 0; iP < pC; iP++)
                    {
                        double ptx0 = Common.RandomDouble(rnd, x - 20, x + 20);
                        double ptx1 = Common.RandomDouble(rnd, x - 50, x + 50);
                        double pty  = y;
                        double ptt0 = Common.RandomDouble(rnd, kStart, kEnd);

                        int startag = Common.RandomInt(rnd, 0, 90);

                        string hStr = "m 0 0 l 0 -70 1 0";
                        ass_out.AppendEvent(40, "pt", ptt0, ptt0 + 1.3,
                                            move(ptx0, pty, ptx1, pty) + a(1, "00") + c(1, "FFBD00") +
                                            blur(0.8) + frx(90) + t(0, 0.25, frx(startag).t()) + t(0.25, 1.3, frx(90).t()) +
                                            p(1) + hStr);
                        hStr = "m 0 0 l 0 70 1 0";
                        ass_out.AppendEvent(40, "pt", ptt0, ptt0 + 1.3,
                                            move(ptx0, pty, ptx1, pty) + a(1, "00") + c(1, "FFBD00") +
                                            blur(0.8) + frx(90) + t(0, 0.25, frx(startag).t()) + t(0.25, 1.3, frx(90).t()) +
                                            p(1) + hStr);

                        hStr = "m 0 0 l 0 -50 1 0";
                        ass_out.AppendEvent(41, "pt", ptt0, ptt0 + 1.3,
                                            move(ptx0, pty, ptx1, pty) + a(1, "77") + c(1, "FFFFFF") +
                                            blur(0.8) + frx(90) + t(0, 0.25, frx(startag).t()) + t(0.25, 1.3, frx(90).t()) +
                                            p(1) + hStr);
                        hStr = "m 0 0 l 0 50 1 0";
                        ass_out.AppendEvent(41, "pt", ptt0, ptt0 + 1.3,
                                            move(ptx0, pty, ptx1, pty) + a(1, "77") + c(1, "FFFFFF") +
                                            blur(0.8) + frx(90) + t(0, 0.25, frx(startag).t()) + t(0.25, 1.3, frx(90).t()) +
                                            p(1) + hStr);
                    }
                }

                ass_out.AppendEvent(51, "pt", ev.Start - 0.2, ev.End + 0.2,
                                    pos(0, y0) + clip(4, outlines) + a(1, "00") + fad(0.3, 0.3) + c(1, "B7AA32") + blur(18) +
                                    p(1) + "m 0 -20 l 1280 -20 1280 20 0 20");
            }

            Console.WriteLine(ass_out.Events.Count);
            ass_out.SaveFile(this.OutFileName);
        }