public virtual Size GetSize(string s) { Graphics g = GetGraphics(); StringMask mk = GetMask(s, this.PlayResX / 2, this.PlayResY / 2); return(new Size { Height = mk.Height, Width = mk.Width }); }
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); }
public StringMask GetMask(string s, int x, int y, string style) { if (!IsAvsMask) { return(base.GetMask(s, x, y)); } if (s.Trim() == "") { return new StringMask { Height = FontHeight, Width = (WhitespaceWidth >= 0) ? WhitespaceWidth : FontWidth, X0 = x, Y0 = y, Points = new List <ASSPoint>() } } ; using (MaskDataContext db = new MaskDataContext()) { var ma = db.Masks.Where(m => m.X == x && m.Y == y && m.PlayResX == this.PlayResX && m.PlayResY == this.PlayResY && m.Style == this.MaskStyle && m.Str == s.GetHashCode().ToString()); if (ma.Count() > 0) { return(new BinaryFormatter().Deserialize(new MemoryStream(ma.First().Data.ToArray())) as StringMask); } } // generate ass file string assFN = "BaseAnime2_Temp.ass"; StreamWriter assOut = new StreamWriter(new FileStream(assFN, FileMode.Create), Encoding.Unicode); assOut.WriteLine("[Script Info]"); assOut.WriteLine("Synch Point:0"); assOut.WriteLine("ScriptType: v4.00+"); assOut.WriteLine("Collisions:Normal"); assOut.WriteLine("PlayResX:{0}", this.PlayResX); assOut.WriteLine("PlayResY:{0}", this.PlayResY); assOut.WriteLine("Timer:100.0000"); assOut.WriteLine(""); assOut.WriteLine("[V4+ Styles]"); assOut.WriteLine("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding"); assOut.WriteLine(style); assOut.WriteLine(""); assOut.WriteLine("[Events]"); assOut.WriteLine("Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text"); assOut.WriteLine("Dialogue: 0,0:00:00.00,0:01:00.00,Default,NTP,0000,0000,0000,,{0}{1}", ASSEffect.pos(x, y), s); assOut.Close(); // generate avs file string avsFN = "BaseAnime2_Temp.avs"; StreamWriter avsOut = new StreamWriter(new FileStream(avsFN, FileMode.Create), Encoding.Default); avsOut.WriteLine("BlankClip(height={0}, width={1}, length=1000, fps=23.976)", this.PlayResY, this.PlayResX); avsOut.WriteLine("ConvertToRGB24()"); avsOut.WriteLine("TextSub(\"{0}\")", assFN); avsOut.Close(); AvsFile avs = AvsFile.OpenScriptFile(avsFN); if (!avs.CanReadVideo) { return(null); } IVideoReader ivr = avs.GetVideoReader(); Bitmap bmp = ivr.ReadFrameBitmap(0); BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); List <ASSPoint> result = new List <ASSPoint>(); unsafe { byte *p = (byte *)(void *)bd.Scan0; for (int x1 = 0; x1 < bmp.Width; x1++) { for (int y1 = 0; y1 < bmp.Height; y1++) { byte *q = p + bd.Stride * y1 + x1 * 3; if (q[0] > 0) { result.Add(new ASSPoint { Brightness = q[0], X = x1, Y = y1 }); } } } } bmp.UnlockBits(bd); bmp.Dispose(); avs.Dispose(); if (result.Count == 0) { return new StringMask { Height = 0, Width = 0, X0 = x, Y0 = y, Points = result } } ; int xmin = 10000; int ymin = 10000; int xmax = -1; int ymax = -1; foreach (ASSPoint pt in result) { if (xmin > pt.X) { xmin = pt.X; } if (xmax < pt.X) { xmax = pt.X; } if (ymin > pt.Y) { ymin = pt.Y; } if (ymax < pt.Y) { ymax = pt.Y; } } StringMask sm = new StringMask { Height = ymax - ymin + 1, Width = xmax - xmin + 1, X0 = x, Y0 = y, Points = result }; //sm.CalculateEdgeDistance(); using (MaskDataContext db = new MaskDataContext()) { try { MemoryStream ms = new MemoryStream(); new BinaryFormatter().Serialize(ms, sm); ms.Position = 0; db.Masks.InsertOnSubmit(new Mask { X = x, Y = y, PlayResX = this.PlayResX, PlayResY = this.PlayResY, Style = this.MaskStyle, Str = s.GetHashCode().ToString(), Data = new Binary(ms.ToArray()) }); db.SubmitChanges(); } catch (Exception e) { throw e; } } return(sm); }
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 = iEv <= 18; this.MaskStyle = "Style: Default,DFKoIn-W4,38,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,5,0,0,0,128"; //if (iEv != 7) continue; //if (isJp) continue; //if (!((iEv <= 5 || (iEv >= 19 && iEv <= 21)))) continue; if (!isJp) { double t0 = ev.Start; double t1 = ev.End; if (iEv <= 21) { t0 -= 0.6; t1 += 0.5; } ass_out.AppendEvent(30, "op_cn", t0, t1, pos(PlayResX / 2, MarginTop + FontHeight / 2) + an(5) + fad(0.3, 0.3) + a(1, "22") + blur(1) + ev.Text); ass_out.AppendEvent(0, "op_cn", t0, t1, pos(PlayResX / 2 + 3, MarginTop + FontHeight / 2 + 3) + an(5) + fad(0.3, 0.3) + a(1, "22") + blur(1.3) + c(1, "000000") + ev.Text); for (int i = 0; i < 10; i++) { ass_out.AppendEvent(20, "op_cn", t0, t1, fad(0.3, 0.3) + pos(PlayResX / 2 + Common.RandomDouble(rnd, -1, 1), MarginTop + FontHeight / 2 + Common.RandomDouble(rnd, -1, 1)) + an(5) + a(1, "AA") + blur(2) + (iEv <= 21 ? "" : c(1, Common.scaleColor("FF0A00", "FFFFFF", 0.83))) + ev.Text); } continue; } List <KElement> kelems = ev.SplitK(!isJp); int tw = GetTotalWidth(ev); int x0 = (PlayResX - MarginLeft - MarginRight - tw) / 2 + MarginLeft; if (iEv == 5 || iEv == 7) { x0 = MarginLeft; } if (iEv == 6 || iEv == 8) { x0 = (PlayResX - MarginRight - tw); } 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; //ass_out.AppendEvent(50, evStyle, ev.Start, ev.End, pos(x, y) + a(1, "00") + ke.KText); if (iEv >= 5)// && iEv <= 8) { double t0 = ev.Start - 0.5 + iK * 0.08; double t1 = t0 + 0.35; double t2 = kStart; double t3 = kEnd; double t4 = ev.End - 0.5 + iK * 0.08; double t5 = t4 + 0.35; double xCenter = tw / 2 + x0_bak; double dx = x - xCenter; string mainColor = "FFFFFF"; //mainColor = "000000"; string mainColor2 = "FFFFFF"; mainColor = mainColor2 = Common.scaleColor("FF0A00", "E8FF00", (double)iK / (double)kelems.Count); mainColor2 = mainColor = Common.scaleColor(mainColor, "FFFFFF", 0.6); mainColor2 = "FFFFFF"; //swap( Func <int, string> fMainColor = ti => Common.scaleColor(mainColor2, mainColor, (double)ti / 5); string shadColor = "000000"; double tmpSc = 0.99; if (iEv > 8) { double rt0 = 7; double rt1 = 0; double rt2 = -7; if (iEv == 11 || iEv == 14 || iEv == 17 || iEv == 18) { rt2 = -4.5; } for (int i = 1; i <= 30; i++) { string alpha = Common.scaleAlpha("AA", "FF", (double)i / 30); string alpha2 = Common.scaleAlpha(alpha, "FF", 0.2); ass_out.AppendEvent(60, evStyle, t0, t2, fad(t1 - t0, 0) + move(x + i * rt0, y, x + i * rt1, y) + a(1, alpha) + c(1, "FFFFFF") + blur((double)(i + 1) * 0.5) + fsc(100 + i * 2) + t(a(1, alpha2).t()) + ke.KText); ass_out.AppendEvent(60, evStyle, t2, t5, fad(0, t5 - t4) + move(x + i * rt1, y, x + i * rt2, y) + a(1, alpha2) + c(1, "FFFFFF") + blur((double)(i + 1) * 0.5) + fsc(100 + i * 2) + t(a(1, alpha).t()) + ke.KText); } int[,] bombs = { { Common.RandomInt(rnd, x - 40, x + 40), Common.RandomInt(rnd, y - 40, y - 20) }, { Common.RandomInt(rnd, x - 40, x + 40), Common.RandomInt(rnd, y + 20, y + 40) } }; for (int iBomb = 0; iBomb < bombs.GetLength(0); iBomb++) { for (int i = 0; i < 200; i++) { string sFrz = frz(Common.RandomInt(rnd, 0, 359)); string sMoveT = t(0, 1, 0.5, fscx(Common.RandomInt(rnd, 5, 120) * 100).t()); ass_out.AppendEvent(80, "pt", t2, t2 + 1, org(bombs[iBomb, 0], bombs[iBomb, 1]) + pos(bombs[iBomb, 0], bombs[iBomb, 1]) + sMoveT + sFrz + p(1) + "m 0 0 l 1 0 1 1 0 1" + r() + sFrz + fad(0, 0.4) + t(0, 0.3, fscx(700).t()) + t(0.3, 1, fscx(100).t()) + blur(1) + a(1, "00") + c(1, "FFFFFF") + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(20, "pt", t2, t2 + 1, org(bombs[iBomb, 0], bombs[iBomb, 1]) + pos(bombs[iBomb, 0], bombs[iBomb, 1]) + sMoveT + sFrz + p(1) + "m 0 0 l 1 0 1 1 0 1" + r() + sFrz + fad(0, 0.4) + t(0, 0.3, fscx(1000).t()) + t(0.3, 1, fscx(150).t()) + fscy(150) + blur(2) + a(1, "00") + c(1, mainColor) + p(1) + "m 0 0 l 1 0 1 1 0 1"); } } } for (int i = 0; i < 40; i++) { string tString = ""; if (i < 5) { tString = t(a(1, "22").t() + blur((double)(i + 1) * 0.5).t()); } else { tString = t(a(1, "FF").t()); } ass_out.AppendEvent(50, evStyle, t0, t1, move(xCenter + dx * (1.0 + (double)(i + 20) * 0.010), y, x, y) + fad(t1 - t0, 0) + a(1, "AA") + c(1, fMainColor(i)) + blur(2 + i * 0.05) + tString + fsc(120 + i * 2) + t(fsc(100).t()) + ke.KText); } for (int i = 0; i < 40; i++) { string aString = a(1, "22"); if (i >= 5) { aString = a(1, Common.scaleAlpha("AA", "FF", tmpSc)); } string blurString = blur((double)(i + 1) * 0.5); if (i >= 5) { blurString = blur(2 + i * 0.05); } ass_out.AppendEvent(50, evStyle, t1, t4, pos(Common.scaleDouble(xCenter + dx * (1.0 + (double)(i + 20) * 0.010), x, tmpSc), y) + aString + c(1, fMainColor(i)) + blurString + ke.KText); } ass_out.AppendEvent(51, evStyle, t2 - 0.06, t2 + 0.5 - 0.06, pos(Common.scaleDouble(xCenter + dx * (1.0 + (double)(0 + 20) * 0.010), x, tmpSc), y) + fad(0.05, 0.3) + a(1, "00") + c(1, "FFFFFF") + a(3, "00") + c(3, "FFFFFF") + bord(5) + blur(6) + ke.KText); ass_out.AppendEvent(52, evStyle, t2 - 0.06, t2 + 0.5 - 0.06, pos(Common.scaleDouble(xCenter + dx * (1.0 + (double)(0 + 20) * 0.010), x, tmpSc), y) + fad(0.05, 0.3) + a(1, "00") + c(1, "FFFFFF") + blur(2) + ke.KText); ass_out.AppendEvent(49, evStyle, t0, t5, fad(1, 1) + pos(Common.scaleDouble(xCenter + dx * (1.0 + (double)(0 + 20) * 0.010), x, tmpSc) + 4, y + 4) + a(1, "00") + c(1, shadColor) + blur(1.2) + ke.KText); ass_out.AppendEvent(49, evStyle, t0, t5, fad(1, 1) + pos(Common.scaleDouble(xCenter + dx * (1.0 + (double)(0 + 20) * 0.010), x, tmpSc) + 4, y + 4) + a(1, "00") + c(1, shadColor) + blur(0.7) + ke.KText); for (int i = 0; i < 40; i++) { string startString = ""; if (i < 5) { startString = a(1, "22") + blur((double)(i + 1) * 0.5); } else { startString = a(1, Common.scaleAlpha("AA", "FF", tmpSc)) + blur(2 + i * 0.05); } ass_out.AppendEvent(50, evStyle, t4, t5, move(x, y, xCenter + dx * (1.0 + (double)(i + 20) * 0.010), y) + fad(0, t5 - t4) + c(1, fMainColor(i)) + startString + t(blur(2 + i * 0.05).t() + a(1, "AA").t() + fsc(120 + i * 2).t()) + ke.KText); } if (iEv <= 8) { for (int i = 0; i < 200; i++) { string sFrz = frz(Common.RandomInt(rnd, 0, 359)); string sMove = move(x, y, x + Common.RandomInt(rnd, 20, 120), y); string sMoveT = t(0, 1, 0.5, fscx(Common.RandomInt(rnd, 5, 120) * 100).t()); ass_out.AppendEvent(80, "pt", t2, t2 + 1, org(x, y) + pos(x, y) + sMoveT + sFrz + p(1) + "m 0 0 l 1 0 1 1 0 1" + r() + sFrz + fad(0, 0.4) + t(0, 0.3, fscx(700).t()) + t(0.3, 1, fscx(100).t()) + blur(1) + a(1, "00") + c(1, "FFFFFF") + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(20, "pt", t2, t2 + 1, org(x, y) + pos(x, y) + sMoveT + sFrz + p(1) + "m 0 0 l 1 0 1 1 0 1" + r() + sFrz + fad(0, 0.4) + t(0, 0.3, fscx(1000).t()) + t(0.3, 1, fscx(150).t()) + fscy(150) + blur(2) + a(1, "00") + c(1, mainColor) + p(1) + "m 0 0 l 1 0 1 1 0 1"); continue; // backup ass_out.AppendEvent(20, "pt", t2, t2 + 1, org(x, y) + sMove + sFrz + t(0, 0.3, fscx(700).t()) + t(0.3, 1, fscx(100).t()) + blur(1) + a(1, "00") + c(1, "FFFFFF") + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(19, "pt", t2, t2 + 1, org(x, y) + sMove + sFrz + t(0, 0.3, fscx(900).t()) + t(0.3, 1, fscx(100).t()) + fscy(120) + blur(2) + a(1, "00") + c(1, mainColor) + p(1) + "m 0 0 l 1 0 1 1 0 1"); } } } if (iEv >= 0 && iEv <= 4) { double t0 = ev.Start - 0.6; double t1 = ev.Start; double t2 = kStart; double t3 = kEnd; double t4 = ev.End; double t5 = t4 + 0.6; string mainColor = "FFFFFF"; Func <double, int> fScale = ti => (int)((ti <= t1 ? (Common.scaleDouble(150, 110, (ti - t0) / (t1 - t0))) : (ti <= t4 ? (Common.scaleDouble(110, 90, (ti - t1) / (t4 - t1))) : (Common.scaleDouble(90, 50, (ti - t4) / (t5 - t4)))))); Func <double, double, string> tsScale = (_t0, _t1) => (fsc(fScale(_t0)) + t(fsc(fScale(_t1)).t())); double dx = (x - this.PlayResX / 2); Func <double, double> fKdx = ti => (ti <= t1 ? 1.8 : (ti <= t4 ? (Common.scaleDouble(1.8, 1, (ti - t1) / (t4 - t1))) : Common.scaleDouble(1, 0.8, (ti - t4) / (t5 - t4)))); Func <double, double> fPosX = ti => (dx * fKdx(ti) + this.PlayResX / 2); { double rt = 0.5 + Math.Abs(dx) / 150; for (int i = 0; i < 20 * rt; i++) { double tx0 = dx * (fKdx(t0) + (double)i * 0.05 / rt) + this.PlayResX / 2; double tx1 = dx * (fKdx(t1) + (double)i * 0.03 / rt) + this.PlayResX / 2; ass_out.AppendEvent(50, evStyle, t0, t1, fad(t1 - t0, 0) + move(tx0, y, tx1, y) + a(1, Common.scaleAlpha("AA", "FF", (double)i / (40 * rt))) + c(1, mainColor) + blur((double)(i + 1) * 0.5) + tsScale(t0, t1) + ke.KText); } for (int i = 0; i < 20 * rt; i++) { double tx0 = dx * (fKdx(t1) + (double)i * 0.03 / rt) + this.PlayResX / 2; double tx1 = dx * (fKdx(t4) + (double)i * 0.00) + this.PlayResX / 2; ass_out.AppendEvent(50, evStyle, t1, t4, move(tx0, y, tx1, y) + a(1, Common.scaleAlpha("AA", "FF", (double)i / (40 * rt))) + c(1, mainColor) + blur((double)(i + 1) * 0.5) + tsScale(t1, t4) + ke.KText); } for (int i = 0; i < 20 * rt; i++) { double tx0 = dx * (fKdx(t4) + (double)i * 0.00) + this.PlayResX / 2; double tx1 = dx * (fKdx(t5) + (double)i * -0.05 / rt) + this.PlayResX / 2; ass_out.AppendEvent(50, evStyle, t4, t5, fad(0, t5 - t4) + move(tx0, y, tx1, y) + a(1, Common.scaleAlpha("AA", "FF", (double)i / (40 * rt))) + c(1, mainColor) + blur((double)(i + 1) * 0.5) + tsScale(t4, t5) + ke.KText); } } } } } 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>(); 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); }
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); }
public override void Run() { ASS ass_in = ASS.FromFile(this.InFileName); ASS ass_out = new ASS() { Header = ass_in.Header, Events = new List <ASSEvent>() }; string cPink = "8283FE"; for (int iEv = 0; iEv < ass_in.Events.Count; iEv++) { bool isJp = iEv <= 12; //if (isJp) continue; //if (iEv != 13) continue; //if (!(iEv >= 0 && 7 >= iEv)) continue; ASSEvent ev = ass_in.Events[iEv]; List <KElement> kelems = ev.SplitK(!isJp); if (!isJp) { foreach (KElement ke in kelems) { ke.KValue = 10; } } int x0 = MarginLeft; int y0 = (isJp) ? (PlayResY - MarginBottom - FontHeight) : MarginTop; int kSum = 0; string outlines = ""; double ev0_sp = 500; for (int iK = 0; iK < kelems.Count; iK++) { Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count); this.MaskStyle = isJp ? "Style: Default,DFGMaruGothic-Md,28,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,5,0,0,0,128" : "Style: Default,方正准圆_GBK,28,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,5,0,0,0,134"; string evStyle = isJp ? "jp" : "cn"; string outlineFontname = isJp ? "DFGMaruGothic-Md" : "方正准圆_GBK"; int outlineEncoding = isJp ? 128 : 134; 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 outlineString = GetOutline(x - sz.Width / 2, y - FontHeight / 2, ke.KText[0], outlineFontname, outlineEncoding, FontHeight, 0, 191); if (!isJp) { outlineString = GetOutline(x - sz.Width / 2, y - FontHeight / 2, ke.KText[0], outlineFontname, outlineEncoding, FontHeight, 0, 177); } outlines += outlineString; if (iEv == 0) { double t0 = kStart - 1; double t1 = kStart - 0.1; double t2 = kStart + 0.4; double t3 = ev.End - 0.5 + iK * 0.07; double t4 = t3 + 0.5; string cMain = "000071"; string cMain2 = "1DA4DD";// "10B7FC"; ass_out.AppendEvent(30, evStyle, t0, t3, pos(x + 2, y + 2) + a(1, "00") + c(1, "000000") + blur(1.2) + fad(0.8, 0) + ke.KText); ass_out.AppendEvent(30, evStyle, t3, t4, pos(x + 2, y + 2) + a(1, "00") + c(1, "000000") + blur(1.2) + fad(0, t4 - t3) + ke.KText); ass_out.AppendEvent(40, "pt", t1, 7 + x / ev0_sp + 0.3, clip(4, outlineString) + pos(x, y) + a(1, "33") + c(1, "222222") + fad(t2 - t1, 0.3) + p(1) + "m -20 -20 l 20 -20 20 20 -20 20"); ass_out.AppendEvent(40, "pt", 7 + x / ev0_sp - 0.3, t3, clip(4, outlineString) + pos(x, y) + a(1, "33") + c(1, cMain) + fad(0.3, 0) + p(1) + "m -20 -20 l 20 -20 20 20 -20 20"); ass_out.AppendEvent(40, "pt", t3, t4, clip(4, outlineString) + pos(x, y) + a(1, "33") + c(1, cMain) + fad(0, t4 - t3) + p(1) + "m -20 -20 l 20 -20 20 20 -20 20"); for (int i = 0; i < 4; i++) { int lumsz = 5 - i; ass_out.AppendEvent(40, "pt", 7 + x / ev0_sp - 0.3, t4, pos(0, 0) + a(1, "FF") + a(3, "DD") + blur(lumsz) + bord(lumsz) + c(3, "1D4FDD") + fad(0.3, 0.5) + p(4) + outlineString); } double lumX = Common.RandomInt(rnd, x - 12, x + 12); double lumY = Common.RandomInt(rnd, y - 12, y + 12); for (int i = 0; i < 3; i++) { int lumsz = 8 + i * 2; int lumsz2 = lumsz - 1; ass_out.AppendEvent(50, "pt", t1, t2, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, cMain) + c(3, cMain) + t(bord(lumsz).t() + blur(lumsz).t()) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(50, "pt", t2, 7 + x / ev0_sp + 0.3, // Speed : 200 clip(4, outlineString) + pos(lumX, lumY) + fad(0, 0.3) + a(1, "44") + a(3, "00") + c(1, cMain) + c(3, cMain) + bord(lumsz) + blur(lumsz) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(50, "pt", 7 + x / ev0_sp - 0.3, t3,// Speed : 200 clip(4, outlineString) + pos(lumX, lumY) + fad(0.3, 0) + a(1, "44") + a(3, "00") + c(1, cMain2) + c(3, cMain2) + bord(lumsz2) + blur(lumsz2) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(50, "pt", t3, t4, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, cMain2) + c(3, cMain2) + bord(lumsz2) + blur(lumsz2) + t(bord(0).t() + blur(0).t()) + p(1) + "m 0 0 l 1 0 1 1 0 1"); } for (int i = 0; i < 4; i++) { double ptt0 = Common.RandomDouble(rnd, 7, 9); double ptt1 = ptt0 + 0.5; double ptx0 = Common.RandomDouble(rnd, x - 15, x + 15); double pty0 = Common.RandomDouble(rnd, y - 15, y + 15) + 40; double ptx1 = Common.RandomDouble(rnd, ptx0 + 10, ptx0 + 15); double pty1 = Common.RandomDouble(rnd, pty0 - 80, pty0 - 100); for (int j = 0; j < 3; j++) { double lumsz = 4 - j * 1; ass_out.AppendEvent(90, "pt", ptt0, ptt1, move(ptx0, pty0, ptx1, pty1) + a(1, "44") + a(3, "00") + bord(lumsz) + blur(lumsz) + fad(0, ptt1 - ptt0) + p(1) + "m 0 0 l 1 0 1 1 0 1"); } ass_out.AppendEvent(89, "pt", ptt0, ptt1, move(ptx0, pty0, ptx1, pty1) + a(1, "44") + a(3, "77") + bord(8) + blur(8) + fad(0, ptt1 - ptt0) + p(1) + "m 0 0 l 1 0 1 1 0 1"); } } else if (iEv == 1) { double t0 = ev.Start - 0.5 + iK * 0.07; double t1 = kStart - 0.1; double t2 = kStart + 0.4; double t3 = ev.End - 0.5 + iK * 0.07; double t4 = t3 + 0.5; string cMain = "FFFFFF"; if (iEv != 1) { cMain = cPink; } string cShad = "222222"; if (iEv != 1) { cShad = "FFFFFF"; } ass_out.AppendEvent(30, evStyle, t0, t3, pos(x + 2, y + 2) + a(1, "00") + c(1, "000000") + blur(1.2) + fad(0.8, 0) + ke.KText); ass_out.AppendEvent(30, evStyle, t3, t4, pos(x + 2, y + 2) + a(1, "00") + c(1, "000000") + blur(1.2) + fad(0, t4 - t3) + ke.KText); ass_out.AppendEvent(40, "pt", t1, t3, clip(4, outlineString) + pos(x, y) + a(1, "33") + c(1, cShad) + fad(t2 - t1, 0) + p(1) + "m -20 -20 l 20 -20 20 20 -20 20"); ass_out.AppendEvent(40, "pt", t3, t4, clip(4, outlineString) + pos(x, y) + a(1, "33") + c(1, cShad) + fad(0, t4 - t3) + p(1) + "m -20 -20 l 20 -20 20 20 -20 20"); for (int i = 0; i < 4; i++) { int lumsz = 5 - i; ass_out.AppendEvent(30, "pt", t1, t4, pos(0, 0) + a(1, "FF") + a(3, "DD") + blur(lumsz) + bord(lumsz) + c(3, "FFFFFF") + fad(0.3, 0.5) + p(4) + outlineString); } double lumX = Common.RandomInt(rnd, x - 12, x + 12); double lumY = Common.RandomInt(rnd, y - 12, y + 12); for (int i = 0; i < 3; i++) { int lumsz = 8 + i * 2; ass_out.AppendEvent(50, "pt", t1, t2, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, cMain) + c(3, cMain) + t(bord(lumsz).t() + blur(lumsz).t()) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(50, "pt", t2, t3, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, cMain) + c(3, cMain) + bord(lumsz) + blur(lumsz) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(50, "pt", t3, t4, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, cMain) + c(3, cMain) + bord(lumsz) + blur(lumsz) + t(bord(0).t() + blur(0).t()) + p(1) + "m 0 0 l 1 0 1 1 0 1"); } for (int i = 0; i < 30 * (t3 - t1); i++) { double ptt0 = Common.RandomDouble(rnd, t1, t3); double ptt1 = ptt0 + 0.5; int pxid = Common.RandomInt(rnd, 0, mask.Points.Count - 1); ASSPoint ogpt = mask.Points[pxid]; double ptx0 = ogpt.X; double pty0 = ogpt.Y; double ptx1 = Common.RandomDouble(rnd, ptx0 - 50, ptx0 + 50); double pty1 = Common.RandomDouble(rnd, pty0 - 50, pty0 + 50); string obj = CreatePolygon(rnd, 10, 15, 5); string moveString = Common.RandomBool(rnd, 0.75) ? move(ptx0, pty0, ptx1, pty1) : move(ptx1, pty1, ptx0, pty0); ass_out.AppendEvent(20, "pt", ptt0, ptt1, moveString + a(1, "00") + a(3, "55") + c(1, "A266FD") + c(3, "A266FD") + bord(2) + blur(2) + fad(0, ptt1 - ptt0) + obj); ass_out.AppendEvent(20, "pt", ptt0, ptt1, moveString + a(1, "00") + a(3, "00") + c(1, "A266FD") + c(3, "A266FD") + bord(1.2) + blur(1.2) + fad(0, ptt1 - ptt0) + obj); ass_out.AppendEvent(20, "pt", ptt0, ptt1, moveString + a(1, "00") + a(3, "00") + bord(0.8) + blur(0.8) + fad(0, ptt1 - ptt0) + obj); } } else if (isJp) { double t0 = ev.Start - 0.5 + iK * 0.07; double t1 = kStart - 0.1; double t2 = kStart + 0.4; double t3 = ev.End - 0.5 + iK * 0.07; double t4 = t3 + 0.5; string cMain = "3C3DFF"; if (iEv == 2) { cMain = "FF8D3C"; } if (iEv == 3) { cMain = "FC7D7F"; } if (iEv == 4) { cMain = "FFC6D2"; } if (iEv == 5) { cMain = "5758FF"; } if (iEv == 6) { cMain = "5758FF"; } if (iEv == 7) { cMain = "FF55C6"; } if (iEv >= 8) { cMain = "FF8D3C"; } string cShad = "EEEEEE"; ass_out.AppendEvent(30, evStyle, t0, t3, pos(x + 2, y + 2) + a(1, "00") + c(1, "000000") + blur(1.2) + fad(0.8, 0) + ke.KText); ass_out.AppendEvent(30, evStyle, t3, t4, pos(x + 2, y + 2) + a(1, "00") + c(1, "000000") + blur(1.2) + fad(0, t4 - t3) + ke.KText); ass_out.AppendEvent(40, "pt", t1, t3, clip(4, outlineString) + pos(x, y) + a(1, "33") + c(1, cShad) + fad(t2 - t1, 0) + p(1) + "m -20 -20 l 20 -20 20 20 -20 20"); ass_out.AppendEvent(40, "pt", t3, t4, clip(4, outlineString) + pos(x, y) + a(1, "33") + c(1, cShad) + fad(0, t4 - t3) + p(1) + "m -20 -20 l 20 -20 20 20 -20 20"); for (int i = 0; i < 4; i++) { int lumsz = 5 - i; ass_out.AppendEvent(30, "pt", t1, t4, pos(0, 0) + a(1, "FF") + a(3, "DD") + blur(lumsz) + bord(lumsz) + c(3, cMain) + fad(0.3, 0.5) + p(4) + outlineString); } double lumX = Common.RandomInt(rnd, x - 12, x + 12); double lumY = Common.RandomInt(rnd, y - 12, y + 12); for (int i = 0; i < 3; i++) { int lumsz = 8 + i * 2; ass_out.AppendEvent(50, "pt", t1, t2, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, cMain) + c(3, cMain) + t(bord(lumsz).t() + blur(lumsz).t()) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(50, "pt", t2, t3, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, cMain) + c(3, cMain) + bord(lumsz) + blur(lumsz) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(50, "pt", t3, t4, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, cMain) + c(3, cMain) + bord(lumsz) + blur(lumsz) + t(bord(0).t() + blur(0).t()) + p(1) + "m 0 0 l 1 0 1 1 0 1"); } if (iEv == 2) { for (double ti = t1; ti <= kEnd + 0.3; ti += 0.01) { double ag = ti * Math.PI * 1.5; int iag = (int)((ag / 2.0 / Math.PI) * 360) % 360; string alpha = "00"; if (kEnd - ti < 0.3) { alpha = Common.scaleAlpha("FF", "00", (kEnd - ti) / 0.3); } if (ti - t1 < 0.3) { alpha = Common.scaleAlpha("FF", "00", (ti - t1) / 0.3); } ass_out.AppendEvent(10, "pt", ti, ti + 0.5, pos(x, y) + a(1, alpha) + be(1) + frz(-iag) + fad(0, 0.3) + p(1) + "m 1 0 l 0 30 -1 0 0 -30"); } } if (iEv == 3) { for (int i = 0; i < 15 * (t3 - t1); i++) { int pxid = Common.RandomInt(rnd, 0, mask.Points.Count - 1); ASSPoint ogpt = mask.Points[pxid]; int ptx0 = ogpt.X; int pty0 = y; double ptt0 = Common.RandomDouble(rnd, t1, t3); double ptt1 = ptt0 + 0.1; ass_out.AppendEvent(110, "pt", ptt0, ptt1, clip(4, outlineString) + pos(ptx0, pty0) + a(1, "77") + blur(1.8) + fad(0, 0) + c(1, "000000") + frz(-30) + p(1) + "m 2 0 l 0 20 -2 0 0 -20"); } } if (iEv == 4) { for (int i = 0; i < 25 * (t3 - t1); i++) { double ptt0 = Common.RandomDouble(rnd, t1, t1 + 0.3); double ptt1 = ptt0 + Common.RandomDouble(rnd, 0, t3 - t1 - 0.3) + 1; int pxid = Common.RandomInt(rnd, 0, mask.Points.Count - 1); ASSPoint ogpt = mask.Points[pxid]; double ptx0 = ogpt.X; double pty0 = ogpt.Y; double ptx1 = Common.RandomDouble(rnd, ptx0 - 50, ptx0 - 150); double pty1 = Common.RandomDouble(rnd, pty0 + 10, pty0 + 50); string obj = CreatePolygon(rnd, 7, 10, 5); string moveString = move(ptx0, pty0, ptx1, pty1, ptt1 - ptt0 - 1, ptt1 - ptt0); /*ass_out.AppendEvent(110, "pt", ptt0, ptt1, * moveString + a(1, "00") + a(3, "55") + c(1, "FFF3F3") + c(3, "FFF3F3") + * bord(2) + blur(2) + fad(0, ptt1 - ptt0) + * obj);*/ ass_out.AppendEvent(110, "pt", ptt0, ptt1, moveString + a(1, "00") + a(3, "00") + c(1, "FFF3F3") + c(3, "FFF3F3") + bord(1.2) + blur(1.2) + fad(0, ptt1 - ptt0) + obj); ass_out.AppendEvent(110, "pt", ptt0, ptt1, moveString + a(1, "00") + a(3, "00") + bord(0.8) + blur(0.8) + fad(0, ptt1 - ptt0) + obj); } } if (iEv == 5 || iEv == 6 || iEv == 7) { ass_out.AppendEvent(109, "jp", kStart, kStart + 0.15, pos(x, y) + a(1, "00") + a(3, "44") + bord(4) + blur(4) + fad(0, 0.12) + ke.KText); ass_out.AppendEvent(109, "jp", kStart, kStart + 0.15, pos(x, y) + a(1, "00") + a(3, "44") + bord(6) + blur(6) + fad(0, 0.12) + ke.KText); for (int i = 0; i < 2; i++) { CompositeCurve curve = new CompositeCurve { MinT = kStart - 0.5 * 0.25, MaxT = kStart + 0.5 * 0.25 }; Line line = new Line { X0 = x + 50 - 5 - 5, X1 = x - 50 - 5 - 5, Y0 = y - 30 - 5 - 5, Y1 = y + 30 - 5 - 5 }; if (i == 1) { line = new Line { Y1 = y - 30 + i * 15 - 5, Y0 = y + 30 + i * 15 - 5, X1 = x + 50 + i * 15 - 5, X0 = x - 50 + i * 15 - 5 } } ; curve.AddCurve(curve.MinT, curve.MaxT, line); List <ASSPointF> pts = curve.GetPath_Dis(1, 1.1); foreach (ASSPointF pt in pts) { if (!Common.InRange(0, PlayResX, pt.X) || !Common.InRange(0, PlayResY, pt.Y)) { continue; } ass_out.AppendEvent(0, "pt", pt.T, pt.T + 0.25, pos(pt.X, pt.Y) + a(1, "00") + a(3, "77") + c(1, cMain) + c(3, cMain) + fad(0, 0.1) + bord(1.5) + blur(1.5) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(0, "pt", pt.T, pt.T + 0.25, pos(pt.X, pt.Y) + a(1, "00") + a(3, "BB") + c(1, cMain) + c(3, cMain) + fad(0, 0.1) + bord(4) + blur(4) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(2, "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(1) + blur(1) + 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(115, "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(8) + blur(8) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(114, "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(6) + blur(6) + p(1) + "m 0 0 l 1 0 1 1 0 1"); } } } if (iEv >= 8 && iEv <= 12) { ass_out.AppendEvent(109, "jp", kStart, kStart + 0.35, pos(x, y) + a(1, "00") + a(3, "44") + bord(4) + blur(4) + fad(0, 0.25) + ke.KText); ass_out.AppendEvent(109, "jp", kStart, kStart + 0.35, pos(x, y) + a(1, "00") + a(3, "44") + bord(6) + blur(6) + fad(0, 0.25) + ke.KText); string pCol = "A266FD"; if (iEv >= 11) { pCol = Common.scaleColor("FFFFFF", pCol, 0.5); } for (int i = 0; i < (30 + (iEv - 7) * 10) * (t3 - t1); i++) { double ptt0 = Common.RandomDouble(rnd, t1, t3); double ptt1 = ptt0 + 0.5; int pxid = Common.RandomInt(rnd, 0, mask.Points.Count - 1); ASSPoint ogpt = mask.Points[pxid]; double ptx0 = ogpt.X; double pty0 = ogpt.Y; double ptx1 = Common.RandomDouble(rnd, ptx0 - 50, ptx0 + 50); double pty1 = Common.RandomDouble(rnd, pty0 - 50, pty0 + 50); string obj = CreatePolygon(rnd, 10, 15, 5); string moveString = Common.RandomBool(rnd, 0.75) ? move(ptx0, pty0, ptx1, pty1) : move(ptx1, pty1, ptx0, pty0); ass_out.AppendEvent(20, "pt", ptt0, ptt1, moveString + a(1, "00") + a(3, "55") + c(1, pCol) + c(3, pCol) + bord(2) + blur(2) + fad(0, ptt1 - ptt0) + obj); ass_out.AppendEvent(20, "pt", ptt0, ptt1, moveString + a(1, "00") + a(3, "00") + c(1, pCol) + c(3, pCol) + bord(1.2) + blur(1.2) + fad(0, ptt1 - ptt0) + obj); ass_out.AppendEvent(20, "pt", ptt0, ptt1, moveString + a(1, "00") + a(3, "00") + bord(0.8) + blur(0.8) + fad(0, ptt1 - ptt0) + obj); } } } if (!isJp) { if (iEv == 13) { double t0 = kStart - 1; double t1 = kStart - 0.1; double t2 = kStart + 0.4; double t3 = ev.End - 0.5 + iK * 0.07; double t4 = t3 + 0.5; string cMain = "000071"; string cMain2 = "1DA4DD";// "10B7FC"; ass_out.AppendEvent(30, evStyle, t0, t3, pos(x + 2, y + 2) + a(1, "00") + c(1, "000000") + blur(1.2) + fad(0.8, 0) + ke.KText); ass_out.AppendEvent(30, evStyle, t3, t4, pos(x + 2, y + 2) + a(1, "00") + c(1, "000000") + blur(1.2) + fad(0, t4 - t3) + ke.KText); ass_out.AppendEvent(40, "pt", t1, 7 + x / ev0_sp + 0.3, clip(4, outlineString) + pos(x, y) + a(1, "33") + c(1, "222222") + fad(t2 - t1, 0.3) + p(1) + "m -20 -20 l 20 -20 20 20 -20 20"); ass_out.AppendEvent(40, "pt", 7 + x / ev0_sp - 0.3, t3, clip(4, outlineString) + pos(x, y) + a(1, "33") + c(1, cMain) + fad(0.3, 0) + p(1) + "m -20 -20 l 20 -20 20 20 -20 20"); ass_out.AppendEvent(40, "pt", t3, t4, clip(4, outlineString) + pos(x, y) + a(1, "33") + c(1, cMain) + fad(0, t4 - t3) + p(1) + "m -20 -20 l 20 -20 20 20 -20 20"); for (int i = 0; i < 4; i++) { int lumsz = 5 - i; ass_out.AppendEvent(40, "pt", 7 + x / ev0_sp - 0.3, t4, pos(0, 0) + a(1, "FF") + a(3, "DD") + blur(lumsz) + bord(lumsz) + c(3, "1D4FDD") + fad(0.3, 0.5) + p(4) + outlineString); } double lumX = Common.RandomInt(rnd, x - 12, x + 12); double lumY = Common.RandomInt(rnd, y - 12, y + 12); for (int i = 0; i < 3; i++) { int lumsz = 8 + i * 2; int lumsz2 = lumsz - 1; ass_out.AppendEvent(50, "pt", t1, t2, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, cMain) + c(3, cMain) + t(bord(lumsz).t() + blur(lumsz).t()) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(50, "pt", t2, 7 + x / ev0_sp + 0.3, // Speed : 200 clip(4, outlineString) + pos(lumX, lumY) + fad(0, 0.3) + a(1, "44") + a(3, "00") + c(1, cMain) + c(3, cMain) + bord(lumsz) + blur(lumsz) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(50, "pt", 7 + x / ev0_sp - 0.3, t3,// Speed : 200 clip(4, outlineString) + pos(lumX, lumY) + fad(0.3, 0) + a(1, "44") + a(3, "00") + c(1, cMain2) + c(3, cMain2) + bord(lumsz2) + blur(lumsz2) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(50, "pt", t3, t4, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, cMain2) + c(3, cMain2) + bord(lumsz2) + blur(lumsz2) + t(bord(0).t() + blur(0).t()) + p(1) + "m 0 0 l 1 0 1 1 0 1"); } } else { double t0 = ev.Start - 0.5 + iK * 0.07; double t1 = kStart - 0.1; double t2 = kStart + 0.4; double t3 = ev.End - 0.5 + iK * 0.07; double t4 = t3 + 0.5; string cMain = "3C3DFF"; int jEv = iEv - 13; if (jEv == 1) { cMain = "FFFFFF"; } if (jEv == 2) { cMain = "FF8D3C"; } if (jEv == 3) { cMain = "FC7D7F"; } if (jEv == 4) { cMain = "FFC6D2"; } if (jEv == 5) { cMain = "5758FF"; } if (jEv == 6) { cMain = "5758FF"; } if (jEv == 7) { cMain = "FF55C6"; } if (jEv >= 8) { cMain = "FF8D3C"; } string cShad = "EEEEEE"; if (jEv == 1) { cShad = "222222"; } ass_out.AppendEvent(30, evStyle, t0, t3, pos(x + 2, y + 2) + a(1, "00") + c(1, "000000") + blur(1.2) + fad(0.8, 0) + ke.KText); ass_out.AppendEvent(30, evStyle, t3, t4, pos(x + 2, y + 2) + a(1, "00") + c(1, "000000") + blur(1.2) + fad(0, t4 - t3) + ke.KText); ass_out.AppendEvent(40, "pt", t1, t3, clip(4, outlineString) + pos(x, y) + a(1, "33") + c(1, cShad) + fad(t2 - t1, 0) + p(1) + "m -20 -20 l 20 -20 20 20 -20 20"); ass_out.AppendEvent(40, "pt", t3, t4, clip(4, outlineString) + pos(x, y) + a(1, "33") + c(1, cShad) + fad(0, t4 - t3) + p(1) + "m -20 -20 l 20 -20 20 20 -20 20"); for (int i = 0; i < 4; i++) { int lumsz = 5 - i; ass_out.AppendEvent(30, "pt", t1, t4, pos(0, 0) + a(1, "FF") + a(3, "DD") + blur(lumsz) + bord(lumsz) + c(3, cMain) + fad(0.3, 0.5) + p(4) + outlineString); } double lumX = Common.RandomInt(rnd, x - 12, x + 12); double lumY = Common.RandomInt(rnd, y - 12, y + 12); for (int i = 0; i < 3; i++) { int lumsz = 8 + i * 2; ass_out.AppendEvent(50, "pt", t1, t2, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, cMain) + c(3, cMain) + t(bord(lumsz).t() + blur(lumsz).t()) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(50, "pt", t2, t3, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, cMain) + c(3, cMain) + bord(lumsz) + blur(lumsz) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(50, "pt", t3, t4, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, cMain) + c(3, cMain) + bord(lumsz) + blur(lumsz) + t(bord(0).t() + blur(0).t()) + p(1) + "m 0 0 l 1 0 1 1 0 1"); } } } } if (iEv == 0 || iEv == 13) { double ptx0 = MarginLeft; double ptx1 = x0 + 30; double pty = y0 + FontHeight / 2; string cMain = "1DA4DD"; double tStart = 7; for (int i = 0; i < 3; i++) { int lumsz = 18 + i * 2; ass_out.AppendEvent(70, "pt", tStart, tStart + (ptx1 - ptx0) / ev0_sp, clip(4, outlines) + move(ptx0, pty, ptx1, pty) + fad(0.3, 0.3) + bord(lumsz) + blur(lumsz) + a(1, "44") + a(3, "00") + c(1, cMain) + c(3, cMain) + p(1) + "m 0 -20 l 1 -20 1 20 0 20"); } } } Console.WriteLine(ass_out.Events.Count); ass_out.SaveFile(this.OutFileName); } }
public void CalculateEdgeDistance() { StringMask mask = this; if (mask.Points.Count == 0) { return; } int mask_minx = 100000; int mask_miny = 100000; int mask_maxx = -100000; int mask_maxy = -100000; foreach (ASSPoint pt in mask.Points) { if (mask_minx > pt.X) { mask_minx = pt.X; } if (mask_miny > pt.Y) { mask_miny = pt.Y; } if (mask_maxx < pt.X) { mask_maxx = pt.X; } if (mask_maxy < pt.Y) { mask_maxy = pt.Y; } } foreach (ASSPoint pt in mask.Points) { pt.X -= mask_minx - 1; pt.Y -= mask_miny - 1; pt.EdgeDistance = -1; } map = new int[mask_maxx - mask_minx + 2, mask_maxy - mask_miny + 2]; edge = new int[mask_maxx - mask_minx + 2, mask_maxy - mask_miny + 2]; for (int i = 0; i < map.GetLength(0); i++) { for (int j = 0; j < map.GetLength(1); j++) { map[i, j] = -1; edge[i, j] = -1; } } for (int i = 0; i < mask.Points.Count; i++) { ASSPoint pt = mask.Points[i]; map[pt.X, pt.Y] = i; edge[pt.X, pt.Y] = -2; } for (int i = 0; i < map.GetLength(0); i++) { for (int j = 0; j < map.GetLength(1); j++) { if (edge[i, j] == -1 && map[i, j] == -1) { CalculateEdgeDistance_DFS(i, j); } } } for (int i = 0; i < map.GetLength(0); i++) { for (int j = 0; j < map.GetLength(1); j++) { if (map[i, j] != -1 && edge[i, j] == 0) { mask.Points[map[i, j]].EdgeDistance = 0; } } } foreach (ASSPoint pt in mask.Points) { pt.X += mask_minx - 1; pt.Y += mask_miny - 1; } for (int i = 0; i < mask.Points.Count; i++) { ASSPoint pt = mask.Points[i]; if (pt.EdgeDistance == 0) { continue; } pt.EdgeDistance = 1e8; for (int j = 0; j < mask.Points.Count; j++) { ASSPoint pt2 = mask.Points[j]; if (pt2.EdgeDistance != 0) { continue; } double dis = Common.GetDistance(pt.X, pt.Y, pt2.X, pt2.Y); if (pt.EdgeDistance > dis) { pt.EdgeDistance = dis; } } } map = edge = null; }
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,26,&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,26,&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 < 8) continue; ASSEvent ev = ass_in.Events[iEv]; List <KElement> kelems = ev.SplitK(false); this.MaskStyle = ms3; /// an7 pos int x0 = PlayResX - MarginRight - FontWidth; if (iEv % 2 == 0) { x0 = MarginLeft; } int startx0 = x0; int y0 = MarginTop; int kSum = 0; int lum0count = 0; List <double> lum0x = new List <double>(); List <double> lum0y = new List <double>(); for (int lumy0 = -20; lumy0 < PlayResY;) { lumy0 += Common.RandomInt(rnd, 5, 10); lum0y.Add(lumy0); lum0x.Add(Common.RandomInt(rnd, x0 - 2, x0 + FontWidth + 2)); lum0count++; } int lumcount = 0; List <double> lumx = new List <double>(); List <double> lumy = new List <double>(); for (int lumy0 = -20; lumy0 < PlayResY;) { lumy0 += Common.RandomInt(rnd, 20, 40); lumy.Add(lumy0); lumx.Add(Common.RandomInt(rnd, x0 - 10, x0 + FontWidth + 10)); lumcount++; } string[] lumcol = { "003DB8", }; for (int iK = 0; iK < kelems.Count; iK++) { if (iK == 16) { int sadf = 2; } //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 + FontWidth / 2; int y = y0 + FontHeight / 2; int baky0 = y0; y0 += sz.Height + FontSpace; Console.WriteLine(y0); this.MaskStyle = ms1; mask = GetMask(ke.KText, x, y); int bakx0 = x0; 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)); 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.Y - baky0) / mask.Height + 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]) / 35.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]) / 8.0; if (wt0[i] > dis) { wt0[i] = dis; } } string col0 = Common.scaleColor("222222", "FFFFFF", wt0[i]); double pt3 = t2 + wt[i] + Common.RandomDouble_Gauss(rnd, -0.08, 0.08, 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)); string ptc = Common.scaleColor("FFFFFF", lumcol[0], 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)); } 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[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))); } } } 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() { 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++) { if (iEv != 0) { continue; } ASSEvent ev = ass_in.Events[iEv]; List <KElement> kelems = ev.SplitK(true); int x0 = MarginLeft; int totalWidth = GetTotalWidth(ev); x0 = (PlayResX - MarginLeft - MarginRight - totalWidth) / 2 + MarginLeft; int bakx0 = x0; int y0 = PlayResY - MarginBottom - FontHeight; int kSum = 0; double lastx0 = 0; double lastt0 = 0; string outlines = ""; 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 = new Size(); if (ke.KText.Trim().Length == 0) { sz = new Size { Width = FontHeight, Height = FontHeight }; } else { sz = GetMask(ke.KText, x0, y0).GetSize(); } 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; } string outlineFontname = "DFMincho-UB"; int outlineEncoding = 128; string outlineString = GetOutline(x - FontHeight / 2, y - FontHeight / 2, ke.KText[0], outlineFontname, outlineEncoding, FontHeight, 0, 168); outlines += outlineString; double appearOffset = (x - PlayResX * 0.5) * (2.0 / PlayResX); double t0 = ev.Start + appearOffset; double t1 = t0 + 0.6; if (t1 > kStart) { t1 = kStart; } double t2 = kStart; double t3 = kEnd; double t4 = ev.End + appearOffset - 0.3; double t5 = t4 + 0.6; ass_out.AppendEvent(20, "", t0, t5, // Blured Shadow pos(x + 1, y + 1) + fad(0.6, 0.6) + a(1, "00") + c(1, "000000") + blur(2) + ke.KText); ass_out.AppendEvent(40, "pt", t0, t5, // Black pos(x, y) + clip(4, outlineString) + fad(0.6, 0.6) + a(1, "00") + c(1, "000000") + p(1) + "m -20 -20 l 20 -20 20 20 -20 20"); ass_out.AppendEvent(41, "pt", t0, t5, // White pos(x, y + 3) + clip(4, outlineString) + fad(0.6, 0.6) + a(3, "00") + bord(10) + blur(10) + p(1) + "m -20 15 l 20 15 20 16 -20 16"); // Highlight ass_out.AppendEvent(50, "", t2, t3, pos(x, y) + fad(0, t3 - t2) + a(3, "00") + bord(2) + blur(2) + a(1, "00") + c(1, "000000") + t(0, 0.04, fsc(130, 130).t()) + t(0.3, t3 - t2, fsc(110, 110).t()) + ke.KText); { string bak = this.MaskStyle; 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"; StringMask mask = GetMask(p(4) + outlineString, 0, 0); this.MaskStyle = bak; StringBuilder sb = new StringBuilder(); foreach (ASSPoint pt in mask.Points) { double xag = (pt.X - x) / ((double)FontHeight * 0.5) * 0.5; xag -= 0.5; double lw = Math.Cos(xag) * 100; if (Math.Abs(lw) < 20) { lw = 20 * Common.RandomSig(rnd); } double yag = (pt.Y - y) / ((double)FontHeight * 0.5) * 0.5; int ptx = (int)(pt.X + lw); int pty = (int)(Math.Sin(yag) * FontHeight + pt.Y); Console.WriteLine(xag); if (pt.X < x) { sb.Append(string.Format(" m {0} {1} l {2} {3} {4} {5} c", pt.X, pt.Y, pt.X, pt.Y + 1, ptx, pty)); } else { sb.Append(string.Format(" m {0} {1} l {2} {3} {4} {5} c", pt.X, pt.Y, ptx, pty, pt.X, pt.Y + 1)); } } ass_out.AppendEvent(100, "pt", t2, t3 + 0.5, pos(0, 0) + a(1, "70") + be(1) + fad(0, t3 - t2) + org(x, y) + t(fry(90).t()) + p(1) + sb); } } } 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; this.MaskStyle = isJp ? "Style: Default,EPSON 行書体M,26,&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 ? 26 : 30; int jEv = isJp ? iEv : iEv; //if (jEv != 0) continue; ASSEvent ev = ass_in.Events[iEv]; List <KElement> kelems = ev.SplitK(true); int totalWidth = GetTotalWidth(ev); int x0 = (PlayResX - MarginLeft - MarginRight - totalWidth) / 2 + MarginLeft; int y0 = (isJp) ? (PlayResY - MarginBottom - FontHeight) : MarginTop; int kSum = 0; int x0_start = x0; string outlines = ""; List <KeyValuePair <double, ASSPoint> > textpath = new List <KeyValuePair <double, ASSPoint> >(); string MainColor = "112836"; if (iEv >= 8) { MainColor = "C5A8A0"; } 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 outlineFontname = isJp ? "EPSON 行書体M" : "方正准圆_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, 179); * outlines += outlineString; * */ double t0 = ev.Start - 0.5 + iK * 0.1; double t1 = t0 + 0.5; double t2 = kStart; double t3 = ev.End - 0.5 + iK * 0.1; double t4 = t3 + 0.5; ass_out.AppendEvent(50, evStyle, t0, t4, fad(t1 - t0, t4 - t3) + pos(x, y) + a(1, "00") + c(1, MainColor) + ke.KText); ass_out.AppendEvent(49, evStyle, t0, t4, fad(t1 - t0, t4 - t3) + pos(x + 1.5, y + 1.5) + a(1, "00") + c(1, "000000") + blur(1) + ke.KText); ass_out.AppendEvent(60, evStyle, t2, t2 + 0.5, fad(0, 0.42) + pos(x, y) + a(1, "00") + c(1, "FFFFFF") + ke.KText); ass_out.AppendEvent(60, evStyle, t2, t2 + 1, pos(x + 1.5, y + 1.5) + a(1, "00") + c(1, "FFFFFF") + blur(1) + t(0, 1, 0.8, a(1, "FF").t()) + ke.KText); ass_out.AppendEvent(60, evStyle, t2, t2 + 1, fad(0, 0.42) + pos(x, y) + a(1, "FF") + a(3, "BB") + c(3, "FFFFFF") + blur(3) + bord(2.5) + t(0, 1, 0.8, a(3, "FF").t()) + ke.KText); textpath.Add(new KeyValuePair <double, ASSPoint>(kStart, new ASSPoint { X = x, Y = y, Start = kStart, End = kEnd })); if (iEv == 1) { for (int i = 0; i < 100; i++) { double ptt0 = Common.RandomDouble(rnd, t3, t4); double ptt1 = ptt0 + Common.RandomDouble(rnd, 0.5, 1); double ptx0 = Common.RandomDouble(rnd, x - 17, x + 17) - 25; double pty0 = Common.RandomDouble(rnd, y - 17, y + 17); double ptx1 = ptx0 + Common.RandomDouble(rnd, 30, 50) * 1.4; double pty1 = pty0 + Common.RandomDouble(rnd, 5, 30) * Common.RandomSig(rnd); int tmp1 = Common.RandomInt(rnd, 0, 359); ass_out.AppendEvent(70, "pt", ptt0, ptt1, move(ptx0, pty0, ptx1, pty1) + a(1, "00") + blur(0.5) + a(4, "DD") + c(4, "000000") + shad(2) + fad(0, 0.5) + //c(1, Common.RandomBool(rnd, 0.9) ? MainColor : Common.scaleColor(MainColor, "FFFFFF", 0.2)) + c(1, Common.scaleColor(MainColor, "FFFFFF", Common.RandomDouble(rnd, 0, 0.15))) + frz(tmp1) + CreatePolygon(rnd, 15, 23, 6)); } } if (iEv >= 2 && iEv <= 4) { for (int i = 0; i < (kEnd - kStart) * 30; i++) { double ptt0 = Common.RandomDouble(rnd, kStart, kEnd); double ptt1 = ptt0 + Common.RandomDouble(rnd, 0.5, 1) * 2; double ptx0 = Common.RandomDouble(rnd, x - 13, x + 13); double pty0 = Common.RandomDouble(rnd, y - 13, y + 13); double ptx1 = ptx0 - Common.RandomDouble(rnd, 30, 100) * 1.4; double pty1 = pty0 + Common.RandomDouble(rnd, 20, 45); int tmp1 = Common.RandomInt(rnd, 0, 359); ass_out.AppendEvent(70, "pt", ptt0, ptt1, move(ptx0, pty0, ptx1, pty1) + a(1, "00") + blur(0.5) + a(4, "DD") + c(4, "000000") + shad(2) + fad(0, 0.5) + //c(1, Common.RandomBool(rnd, 0.9) ? MainColor : Common.scaleColor(MainColor, "FFFFFF", 0.2)) + c(1, Common.scaleColor(MainColor, "FFFFFF", Common.RandomDouble(rnd, 0, 0.15))) + frz(tmp1) + CreatePolygon(rnd, 15, 23, 6)); } } } if (iEv >= 5)// && iEv <= 7) { for (int i = 0; i < textpath.Count - 1; i++) { if (textpath[i].Value.End < textpath[i + 1].Value.Start) { textpath[i].Value.End = textpath[i + 1].Value.Start; } } textpath[textpath.Count - 1].Value.End = ev.End; emitterList = new List <ASSPointF>(); foreach (KeyValuePair <double, ASSPoint> pair in textpath) { emitterList.Add(new ASSPointF { Start = pair.Value.Start, End = pair.Value.End, X = pair.Value.X + Common.RandomDouble(rnd, -20, 20), Y = pair.Value.Y + Common.RandomDouble(rnd, -20, 20) }); } forceCurve = new CompositeCurve { MinT = ev.Start, MaxT = ev.End + 10 }; double lastag = 0; for (double time = forceCurve.MinT; time <= forceCurve.MaxT; time += 0.7) { double ag = Common.RandomDouble(rnd, 0, Math.PI * 2); while (Math.Abs(ag - lastag) < Math.PI * 0.5 || Math.Abs(ag - lastag) > Math.PI * 1.5) { ag = Common.RandomDouble(rnd, 0, Math.PI * 2); } lastag = ag; double x = 1500.0 * Math.Cos(ag); double y = 800.0 * Math.Sin(ag); forceCurve.AddCurve(time, time + 0.7, new Line { X0 = x, Y0 = y, X1 = 0, Y1 = 0, Acc = 0.7 }); } NumberPerSecond = 110; XXParticleSystem xxps = new XXParticleSystem(); xxps.Emitter = this; xxps.ForceField = this; xxps.StartTime = ev.Start; xxps.EndTime = ev.End; xxps.InterpolationPrecision = 0.03; xxps.Resistance = 0.04; xxps.Repulsion = -3600; xxps.Gravity = 0; xxps.GravityPosition = this; xxps.InterpolationPrecision = 0.01; List <KeyValuePair <XXParticleElement, List <string> > > result = xxps.RenderT(); foreach (KeyValuePair <XXParticleElement, List <string> > pair in result) { string s = CreatePolygon(rnd, 12, 12, 4); string ptstr = @"{\p1}m 0 0 l 1 0 1 1 0 1"; string ptcol = "532BFF"; ass_out.AppendEvent(70, "pt", pair.Key.Born, pair.Key.Born + pair.Key.Life, pos(-100, -100) + pair.Value[1] + ptstr + "\\N" + r() + pair.Value[0] + ptstr + r() + a(1, "00") + blur((iEv <= 7) ? 0.6 : 0.8) + a(4, "DD") + c(4, "000000") + shad(2) + fad(0, 0.5) + c(1, Common.scaleColor(MainColor, "FFFFFF", Common.RandomDouble(rnd, 0, 0.15))) + CreatePolygon(rnd, 15, 23, 6)); } } } 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>() }; ParticleIllusionExporter pie = new ParticleIllusionExporter(); for (int iEv = 0; iEv < ass_in.Events.Count; iEv++) { bool isJp = iEv <= 13; int iiEv = isJp ? iEv : iEv - 14; //if (iiEv !=4 && iiEv != 5) continue; this.MaskStyle = isJp ? "Style: Default,HGSGyoshotai,26,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,5,0,0,0,128" : "Style: Default,方正行楷简体,30,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,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 sw = GetTotalWidth(ev); int x0 = (isJp) ? MarginLeft : PlayResX - MarginRight - sw; int y0 = (!isJp) ? (PlayResY - MarginBottom - FontHeight) : MarginTop; int startx0 = x0; int kSum = 0; string outlines = ""; for (int iK = 0; iK < kelems.Count; iK++) { Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count); string evStyle = isJp ? "jp" : "cn"; string ptStyle = "pt"; 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; StringMask mask = GetMask(ke.KText, x, y); x0 += this.FontSpace + sz.Width; if (ke.KText.Trim().Length == 0) { continue; } double t0 = ev.Start - 1 + (double)(x0 - startx0 - sz.Width) / 300.0; double t1 = t0 + 1; double t2 = kStart; //if (iEv <= 3) t2 = ke.KStart_NoSplit; double t3 = kEnd; double t4 = ev.End - 1 + (double)(x0 - startx0 - sz.Width) / 300.0; if (t4 < t3) { t4 = t3; } double t5 = t4 + 1; if (iEv == 4 && iK == 0) { pie.Add(t2 - 0.35, new ASSPointF(0, y)); } if (iEv >= 4 && isJp) { double last = ke.KValue * 0.01; pie.Add(t2, new ASSPointF(x, y)); if (last > 0.23 && !Common.IsLetter(ke.KText[0])) { pie.Add(t2 + last - 0.23, new ASSPointF(x, y)); } } if (!isJp) { ass_out.AppendEvent(40, evStyle, t0, t5, pos(x + 1, y + 1) + fad(0.5, 0.5) + a(1, "00") + c(1, "000000") + blur(1) + ke.KText); ass_out.AppendEvent(50, evStyle, t0, t5, pos(x, y) + fad(0.5, 0.5) + a(1, "00") + ke.KText); continue; } { CompositeCurve curve = new CompositeCurve { MinT = t0, MaxT = t1 }; curve.AddCurve(t0, t1, new Curve1 { X0 = x, Y0 = y, R = 30 }); foreach (ASSPointF pt in curve.GetPath_DT(0.007)) { double tmp = pt.Theta * 100; ass_out.AppendEvent(70, evStyle, pt.T, pt.T + 0.4, pos(pt.X, pt.Y) + fad(0, 0.3) + a(1, "00") + be(1) + fsc((int)tmp, (int)tmp) + ke.KText); ass_out.AppendEvent(60, evStyle, pt.T, pt.T + 0.4, pos(pt.X + 1, pt.Y + 1) + fad(0, 0.3) + a(1, "DD") + c(1, "000000") + be(1) + fsc((int)tmp, (int)tmp) + ke.KText); } { ass_out.AppendEvent(40, evStyle, t1, t5, pos(x + 1, y + 1) + fad(0.3, 0.5) + a(1, "00") + c(1, "000000") + blur(1) + ke.KText); ass_out.AppendEvent(50, evStyle, t1, t5, pos(x, y) + fad(0.3, 0.5) + a(1, "00") + ke.KText); } if (iEv <= 3 || Common.IsLetter(ke.KText[0])) { for (double ti = ke.KStart_NoSplit; ti <= ke.KEnd_NoSplit; ti += 0.01) { ass_out.AppendEvent(70, evStyle, ti, ti + 0.35, move(x, y, Common.RandomDouble(rnd, x - 5, x + 5), Common.RandomDouble(rnd, y - 5, y + 5)) + fad(0, 0.2) + blur(1) + a(1, "AA") + ke.KText); } } else { for (double ti = t2; ti <= t3; ti += 0.01) { ass_out.AppendEvent(70, evStyle, ti, ti + 0.35, move(x, y, Common.RandomDouble(rnd, x - 5, x + 5), Common.RandomDouble(rnd, y - 5, y + 5)) + fad(0, 0.2) + blur(1) + a(1, "AA") + ke.KText); } } } } } pie.SaveToFile(@"G:\Workshop\hanasakeru\op\pi_export.txt"); 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++) { //if (iEv != 15) continue; ASSEvent ev = ass_in.Events[iEv]; List <KElement> kelems = ev.SplitK(false); this.MaskStyle = "Style: Default,TT-曲水B,44,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,5,0,0,0,128"; this.FontName = "TT-曲水B"; this.FontCharset = 128; this.FontHeight = 44; int totalWidth = GetTotalWidth(ev); int x0 = (PlayResX - MarginLeft - MarginRight - totalWidth) / 2 + MarginLeft; int x0_start = x0; int y0 = PlayResY - MarginBottom - FontHeight; int kSum = 0; CompositeCurve curve = new CompositeCurve { MinT = ev.Start - 0.5, MaxT = ev.End }; double curve_x0 = x0_start - FontHeight; double curve_y0 = y0 + 0.5 * FontHeight; double curve_t0 = curve.MinT; string[] mainColors = { "21184E", // red "4E1842", // purple "4E181A", // blue "184E1E", // green "184E4D", // yellow "393F15" // another blue... }; string mainColor = mainColors[2]; if (iEv >= 4 && iEv <= 7) { mainColor = mainColors[0]; } if (iEv >= 8 && iEv <= 10) { mainColor = mainColors[1]; } if (iEv >= 11) { mainColor = mainColors[5]; } mainColor = "000000"; string[] ptColors = { "3600FF", // red "FF00B0", // purple "FF1C00", // blue "00FFFF", // yellow "00FF08", // green "DCFF00" // another blue... }; string ptColor = ptColors[2]; if (iEv > 10) { ptColor = ptColors[5]; } string ringColor = ptColors[1]; if (iEv >= 11) { ringColor = ptColors[5]; } if (iEv >= 13) { ringColor = "FFB100"; } string torchColor = ptColors[1]; if (iEv >= 11) { torchColor = "FF7C00"; } if (iEv == 3) { ptColor = Common.scaleColor(ptColor, "FFFFFF", 0.7); } else { ptColor = Common.scaleColor(ptColor, "FFFFFF", 0.5); } ringColor = Common.scaleColor(ringColor, "FFFFFF", 0.5); torchColor = Common.scaleColor(torchColor, "FFFFFF", 0.5); 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; double x = x0 + this.FontSpace + sz.Width / 2; double y = y0 + FontHeight / 2; int x_an7 = x0; int y_an7 = y0; StringMask mask = GetMask(ke.KText, (int)x, (int)y); x0 += this.FontSpace + sz.Width; if (ke.KText.Trim().Length == 0) { continue; } curve.AddCurve(curve_t0, kStart, new Line { X0 = curve_x0, Y0 = curve_y0, X1 = x, Y1 = y }); curve_x0 = x; curve_y0 = y; curve_t0 = kStart; string evStyle = "op_jp"; ass_out.AppendEvent(49, evStyle, ev.Start - 0.3, ev.End + 0.3, pos(x + 1, y + 1) + fad(0.3, 0.3) + a(1, "77") + c(1, "000000") + blur(1) + ke.KText); ass_out.AppendEvent(50, evStyle, ev.Start - 0.3, ev.End + 0.3, pos(x, y) + fad(0.3, 0.3) + a(1, "00") + ke.KText); ass_out.AppendEvent(51, evStyle, ev.Start - 0.3, ev.End + 0.3, pos(x + 2, y + 2) + fad(0.3, 0.3) + a(1, "22") + c(1, mainColor) + blur(1) + ke.KText); double remainStr = 0; if (iEv == 3) { remainStr = 0.5; } if (iEv == 18) { remainStr = 0.5; } // light double lastStr = 0.1; // ring particle if (iEv >= 8) { ass_out.AppendEvent(70, "pt", kStart, kStart + 0.4, pos(x, y) + fad(0.04, 0.25) + a(1, "77") + blur(1) + CreateCircle(50.5, 52.5)); ass_out.AppendEvent(70, "pt", kStart, kStart + 0.4, pos(x, y) + fad(0.04, 0.25) + a(1, "77") + blur(2) + CreateCircle(49, 54)); int ptCount = 150; if (iEv >= 10) { ptCount = 250; } int ptRange = 12; if (iEv >= 10) { ptRange = 20; } for (int iPt = 0; iPt < ptCount; iPt++) { double ptag = Common.RandomDouble(rnd, 0, Math.PI * 2); double ptx0 = x + 51.5 * Math.Cos(ptag); double pty0 = y + 51.5 * Math.Sin(ptag); double ptx1 = Common.RandomDouble(rnd, ptx0 - ptRange, ptx0 + ptRange); double pty1 = Common.RandomDouble(rnd, pty0 - ptRange, pty0 + ptRange); double ptt = 0.7; double ptSize = 1; ass_out.AppendEvent(81, "pt", kStart, kStart + ptt, move(ptx0, pty0, ptx1, pty1) + fad(0.04, 0.35) + a(1, "00") + blur(1) + fsc((int)(ptSize * 200)) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(80, "pt", kStart, kStart + ptt, move(ptx0, pty0, ptx1, pty1) + fad(0.04, 0.35) + a(1, "33") + blur(2) + fsc((int)(ptSize * 300)) + c(1, ringColor) + p(1) + "m 0 0 l 1 0 1 1 0 1"); } } // torch light if (iEv >= 10) { ass_out.AppendEvent(70, "pt", kStart, kStart + 0.4, pos(x, y) + fad(0.04, 0.45) + a(1, "CC") + blur(1) + fsc(80) + t(fsc(160).t()) + CreateCircle(50.5, 52.5)); ass_out.AppendEvent(70, "pt", kStart, kStart + 0.4, pos(x, y) + fad(0.04, 0.45) + a(1, "CC") + blur(2) + fsc(80) + t(fsc(160).t()) + CreateCircle(49, 54)); ass_out.AppendEvent(70, "pt", kStart, kStart + 0.4, pos(x, y) + fad(0.04, 0.45) + a(1, "AA") + blur(1) + fsc(80) + t(fsc(20).t()) + CreateCircle(50.5, 52.5)); ass_out.AppendEvent(70, "pt", kStart, kStart + 0.4, pos(x, y) + fad(0.04, 0.45) + a(1, "AA") + blur(2) + fsc(80) + t(fsc(20).t()) + CreateCircle(49, 54)); if ((iEv == 10 && iK + 1 == kelems.Count) || iEv >= 15) { double tStep = 0.02; for (double ptt0 = kStart - 0.1; ptt0 < kEnd; ptt0 += tStep) { int startag = Common.RandomInt(rnd, 0, 359); int endag = startag + Common.RandomSig(rnd) * Common.RandomInt(rnd, 50, 100); ass_out.AppendEvent(20, "pt", ptt0, ptt0 + 1, pos(x, y) + fad(0.3, 0.3) + a(1, "00") + be(1) + c(1, torchColor) + frz(startag) + t(frz(endag).t()) + CreateLight1(rnd)); ass_out.AppendEvent(21, "pt", ptt0, ptt0 + 1, pos(x, y) + fad(0.3, 0.3) + a(1, "11") + be(1) + frz(startag) + t(frz(endag).t()) + CreateLight1(rnd, 60)); } } } // starglow foreach (ASSPoint point in mask.Points) { if (!Common.RandomBool(rnd, 0.4)) { continue; } double xr = (double)(point.X - mask.X0) / mask.Width; double yr = (double)(point.Y - mask.Y0) / mask.Height; Func <double, double> f1 = _x => Math.Pow(Math.Abs(_x) * 2.0, 1.5); ass_out.AppendEvent(70, "pt", kStart, kEnd + lastStr, an(7) + pos(point.X, point.Y) + fad(0.05, kEnd + 0.2 - kStart - 0.05 - 0.08) + a(1, Common.scaleAlpha("FF", "AA", f1(xr))) + be(1) + fscx(100 + f1(xr) * 60) + p(1) + "m 0 0 l 40 0 0 1 -40 0 0 0"); ass_out.AppendEvent(70, "pt", kStart, kEnd + lastStr, an(7) + pos(point.X, point.Y) + fad(0.05, kEnd + 0.2 - kStart - 0.05 - 0.08) + a(1, Common.scaleAlpha("FF", "AA", f1(yr))) + be(1) + fscx(100 + f1(yr) * 60) + frz(90) + p(1) + "m 0 0 l 40 0 0 1 -40 0 0 0"); if (remainStr > 0) { // remain "starglow" ass_out.AppendEvent(70, "pt", (kEnd + lastStr - kStart) * 0.5 + kStart, ev.End + 0.3, an(7) + pos(point.X, point.Y) + fad((kEnd + lastStr - kStart) * 0.5, 0.3) + a(1, Common.scaleAlpha("FF", "AA", remainStr * f1(xr))) + be(1) + fscx(100 + f1(xr) * 60) + p(1) + "m 0 0 l 40 0 0 1 -40 0 0 0"); ass_out.AppendEvent(70, "pt", (kEnd + lastStr - kStart) * 0.5 + kStart, ev.End + 0.3, an(7) + pos(point.X, point.Y) + fad((kEnd + lastStr - kStart) * 0.5, 0.3) + a(1, Common.scaleAlpha("FF", "AA", remainStr * f1(yr))) + be(1) + fscx(100 + f1(yr) * 60) + frz(90) + p(1) + "m 0 0 l 40 0 0 1 -40 0 0 0"); // disappear with particles if (Common.RandomBool(rnd, 1)) { double ptt0 = ev.End + iK * 0.02; double ptt1 = ptt0 + Common.RandomDouble_Gauss(rnd, 1.2, 2.4, 2); string sFrz = frz(Common.RandomInt(rnd, 0, 359)); string sMove = move(point.X, point.Y, point.X + Common.RandomInt(rnd, 100, 200), point.Y); string sMoveT = t(0, ptt1 - ptt0, 0.5, fscx((Math.Abs(Common.RandomDouble_Gauss(rnd, -1, 1, 3)) * 180 + 20) * 100).t()); string tS1 = t(0, Common.RandomDouble(rnd, 1, 2) * (ptt1 - ptt0), a(1, "FFFF").t()); point.Y += Common.RandomInt(rnd, -5, 5); ass_out.AppendEvent(80, "pt", ptt0, ptt1, org(point.X, point.Y) + pos(point.X, point.Y) + sMoveT + sFrz + p(1) + "m 0 0 l 1 0 1 1 0 1" + r() + sFrz + fad(0, 0.4) + t(0, 0.3, fscx(700).t()) + t(0.3, 1, 2, fscx(150).t()) + blur(1) + a(1, "00") + tS1 + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(20, "pt", ptt0, ptt1, org(point.X, point.Y) + pos(point.X, point.Y) + sMoveT + sFrz + p(1) + "m 0 0 l 1 0 1 1 0 1" + r() + sFrz + fad(0, 0.4) + t(0, 0.3, fscx(1000).t()) + t(0.3, 1, 2, fscx(250).t()) + fscy(150) + c(1, ptColor) + blur(2) + a(1, "00") + tS1 + p(1) + "m 0 0 l 1 0 1 1 0 1"); } } } ass_out.AppendEvent(60, evStyle, kStart, kEnd + lastStr, pos(x + 1, y + 1) + fad(0.05, kEnd + lastStr - kStart - 0.05 - 0.08) + a(1, "00") + a(3, "22") + bord(2.5) + blur(2.5) + ke.KText); ass_out.AppendEvent(60, evStyle, kStart, kEnd + lastStr, pos(x + 1, y + 1) + fad(0.05, kEnd + lastStr - kStart - 0.05 - 0.08) + a(1, "00") + a(3, "22") + bord(5) + blur(5) + ke.KText); if (remainStr > 0) { ass_out.AppendEvent(60, evStyle, (kEnd + lastStr - kStart) * 0.5 + kStart + iK * 0.02, ev.End + 0.3 + iK * 0.02, pos(x + 1, y + 1) + fad((kEnd + lastStr - kStart) * 0.5, 0.3) + a(1, Common.scaleAlpha("FF", "00", remainStr)) + a(3, Common.scaleAlpha("FF", "22", remainStr)) + bord(2.5) + blur(2.5) + ke.KText); ass_out.AppendEvent(60, evStyle, kStart + iK * 0.02, kEnd + lastStr + iK * 0.02, pos(x + 1, y + 1) + fad(0.05, kEnd + lastStr - kStart - 0.05 - 0.08) + a(1, Common.scaleAlpha("FF", "00", remainStr)) + a(3, Common.scaleAlpha("FF", "22", remainStr)) + bord(5) + blur(5) + ke.KText); ass_out.AppendEvent(60, evStyle, ev.End - 0.1 + iK * 0.02, ev.End + 0.3 + iK * 0.02, pos(x + 1, y + 1) + fad(0.05, 0.2) + a(1, "00") + a(3, "22") + bord(2.5) + blur(2.5) + ke.KText); ass_out.AppendEvent(60, evStyle, ev.End - 0.1 + iK * 0.02, ev.End + 0.3 + iK * 0.02, pos(x + 1, y + 1) + fad(0.05, 0.2) + a(1, "00") + a(3, "22") + bord(5) + blur(5) + ke.KText); } } if (iEv > 10) { curve.AddCurve(curve_t0, curve.MaxT, new Line { X0 = curve_x0, Y0 = curve_y0, X1 = curve_x0, Y1 = curve_y0 }); foreach (ASSPointF point in curve.GetPath_DT(0.002)) { double ptt0 = point.T; double ptt1 = ptt0 + Common.RandomDouble_Gauss(rnd, 1.2, 1.8, 2); string sFrz = frz(Common.RandomInt(rnd, 0, 359)); string sMove = move(point.X, point.Y, point.X + Common.RandomInt(rnd, 100, 200), point.Y); string sMoveT = t(0, ptt1 - ptt0, 0.5, fscx((Math.Abs(Common.RandomDouble_Gauss(rnd, -1, 1, 3)) * 180 + 20) * 100).t()); string tS1 = t(0, Common.RandomDouble(rnd, 1, 2) * (ptt1 - ptt0), a(1, "FFFF").t()); ass_out.AppendEvent(80, "pt", ptt0, ptt1, org(point.X, point.Y) + pos(point.X, point.Y) + sMoveT + sFrz + p(1) + "m 0 0 l 1 0 1 1 0 1" + r() + sFrz + fad(0, 0.4) + t(0, 0.3, fscx(700).t()) + t(0.3, 1, 2, fscx(150).t()) + blur(1) + a(1, "00") + tS1 + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(20, "pt", ptt0, ptt1, org(point.X, point.Y) + pos(point.X, point.Y) + sMoveT + sFrz + p(1) + "m 0 0 l 1 0 1 1 0 1" + r() + sFrz + fad(0, 0.4) + t(0, 0.3, fscx(1000).t()) + t(0.3, 1, 2, fscx(250).t()) + fscy(150) + c(1, ptColor) + blur(2) + a(1, "00") + tS1 + p(1) + "m 0 0 l 1 0 1 1 0 1"); } } } 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() { Header = ass_in.Header, Events = new List <ASSEvent>() }; string mainCol = "FF51C5"; string fCol = "595AFF"; for (int iEv = 0; iEv < ass_in.Events.Count; iEv++) { bool isJp = iEv <= 15; //if (iEv != 0) continue; this.MaskStyle = isJp ? "Style: Default,DFMincho-UB,28,&H00FFFFFF,&HFFFFFFFF,&HFFFFFFFF,&HFFFFFFFF,0,0,0,0,100,100,0,0,0,0,0,5,0,0,0,128" : "Style: Default,汉仪粗宋繁,28,&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(!isJp); if (!isJp) { foreach (KElement ke in kelems) { ke.KValue = 10; } } int sw = GetTotalWidth(ev); int x0 = (!isJp) ? MarginLeft : PlayResX - MarginRight - sw; int y0 = (!isJp) ? (PlayResY - MarginBottom - FontHeight) : MarginTop; int kSum = 0; string outlines = ""; for (int iK = 0; iK < kelems.Count; iK++) { Console.WriteLine("{0} / {1} : {2} / {3}", iEv + 1, ass_in.Events.Count, iK + 1, kelems.Count); string evStyle = isJp ? "Default" : "cn"; string outlineFontname = isJp ? "DFMincho-UB" : "汉仪粗宋繁"; int outlineEncoding = isJp ? 128 : 134; 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 outlineString = GetOutline(x - FontHeight / 2, y - FontHeight / 2, ke.KText[0], outlineFontname, outlineEncoding, FontHeight, 0, isJp ? 193 : 178); outlines += outlineString; double t0 = ev.Start - 0.5 + iK * 0.08; double t1 = t0 + 0.4; double t2 = kStart - 0.1; double t3 = kEnd; double t4 = ev.End - 0.5 + iK * 0.08; double t5 = t4 + 0.4; ass_out.AppendEvent(30, "pt", t0, t5, pos(2, 2) + fad(0.5, 0.5) + a(1, "00") + c(1, "222222") + blur(2) + p(4) + outlineString); ass_out.AppendEvent(35, "pt", t0, t5, pos(0, 0) + fad(0.5, 0.5) + a(1, "00") + c(1, "FFFFFF") + p(4) + outlineString); double lumX = Common.RandomInt(rnd, x - 12, x + 12); double lumY = Common.RandomInt(rnd, y - 12, y + 12); for (int i = 0; i < 3; i++) { int lumsz = 8 + i * 2; double t24 = t2 + 1; if (t24 > t4) { t24 = (t2 + t4) * 0.5; } ass_out.AppendEvent(40, "pt", t2, t24, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, mainCol) + c(3, mainCol) + t(bord(lumsz).t() + blur(lumsz).t()) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(40, "pt", t24, t4, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, mainCol) + c(3, mainCol) + bord(lumsz) + blur(lumsz) + p(1) + "m 0 0 l 1 0 1 1 0 1"); ass_out.AppendEvent(40, "pt", t4, t5, clip(4, outlineString) + pos(lumX, lumY) + a(1, "44") + a(3, "00") + c(1, mainCol) + c(3, mainCol) + bord(lumsz) + blur(lumsz) + t(bord(0).t() + blur(0).t()) + p(1) + "m 0 0 l 1 0 1 1 0 1"); } if (!isJp) { continue; } for (int iP = 0; iP < 10 * (t3 - t2); iP++) { int pid = Common.RandomInt(rnd, 0, mask.Points.Count - 1); ASSPoint orgpt = mask.Points[pid]; double ptt0 = Common.RandomDouble(rnd, t2, t3); double ptt1 = ptt0 + 2; double ptx0 = orgpt.X; double pty0 = orgpt.Y; double ag = Common.RandomDouble(rnd, 0, 2 * Math.PI); double ptx1 = ptx0 + Common.RandomDouble(rnd, -160, -100); double pty1 = pty0 + Common.RandomDouble(rnd, 60, 35); string ptstr = CreatePolygon(rnd, 40, 40, 3); int tmpx = Common.RandomInt(rnd, 100, 400); int tmpy = Common.RandomInt(rnd, 100, 400); int tmpz = Common.RandomInt(rnd, 100, 400); for (int i = 0; i < 3; i++) { ass_out.AppendEvent(70 + i, "pt", ptt0, ptt1, move(ptx0, pty0, ptx1, pty1) + a(1, "44") + a(3, "44") + c(1, mainCol) + c(3, mainCol) + t(frx(tmpx).t() + fry(tmpy).t() + frz(tmpz).t()) + blur(3 - i) + ptstr); } ass_out.AppendEvent(90, "pt", ptt0, ptt1, move(ptx0, pty0, ptx1, pty1) + a(1, "44") + a(3, "44") + c(1, "FFFFFF") + c(3, "FFFFFF") + t(frx(tmpx).t() + fry(tmpy).t() + frz(tmpz).t()) + blur(2) + ptstr); ass_out.AppendEvent(60, "pt", ptt0, ptt1, move(ptx0 + 2, pty0 + 3, ptx1 + 2, pty1 + 3) + a(1, "44") + a(3, "44") + c(1, "000000") + c(3, "000000") + t(frx(tmpx).t() + fry(tmpy).t() + frz(tmpz).t()) + blur(1) + ptstr); } } } Console.WriteLine(ass_out.Events.Count); ass_out.SaveFile(this.OutFileName); }
public int[] CalculateBFSOrder(StringMask mask) { 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; break; 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); } } } } } return(ind); }
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); }
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 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,35,&H00FF0000,&HFF000000,&HFFFFFFFF,&HFFFF0000,-1,0,0,0,100,100,2,0,1,2,0,5,25,25,25,128"; string ptstr = @"{\p1}m 0 0 l 1 0 1 1 0 1"; Random rnd = new Random(); for (int iEv = 0; iEv < ass_in.Events.Count; iEv++) { //if (iEv != 1) continue; ASSEvent ev = ass_in.Events[iEv]; List <KElement> kelems = ev.SplitK(false); this.MaskStyle = ms1; int x0 = MarginLeft; int startx0 = x0; int y0 = PlayResY - MarginBottom - FontHeight; if (iEv == -1) { bool zz = false; foreach (Beat bt in GetBeats()) { ass_out.Events.Add( ev.StartReplace(bt.Time).EndReplace(bt.Time + 0.3).TextReplace( ASSEffect.pos(30, zz ? 30 : 80) + ASSEffect.an(7) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "FF") + ASSEffect.fad(0.05, 0.2) + string.Format("ID:{0} STR:{1}", bt.Id, bt.Strength))); zz = !zz; } } if (iEv == 0) { int reg0 = 0; int[] blurstrar = new int[] { 2, 3, 4, 5, 6, 7, 8 }; blurstrar = blurstrar.Select(bs => bs + 4).ToArray(); foreach (Beat bt in GetBeats()) { if (bt.Id >= 151) { if (bt.Reg) { reg0 = 0; } else { reg0++; } int blurstr = blurstrar[reg0]; ass_out.Events.Add( ev.StartReplace(bt.Time).EndReplace(bt.Time + 0.3).LayerReplace(5).TextReplace( ASSEffect.an(7) + ASSEffect.pos(0, 0) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "44") + ASSEffect.c(3, "ED6D64") + ASSEffect.fad(0.05, 0.2) + ASSEffect.blur(blurstr) + ASSEffect.bord(blurstr) + @"{\p1}m 0 678 l 1280 678 1280 679 0 679")); ass_out.Events.Add( ev.StartReplace(bt.Time).EndReplace(bt.Time + 0.3).LayerReplace(6).TextReplace( ASSEffect.an(7) + ASSEffect.pos(0, 0) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "44") + ASSEffect.c(3, "FFFFFF") + ASSEffect.fad(0.05, 0.2) + ASSEffect.blur(2) + ASSEffect.bord(2) + @"{\p1}m 0 678 l 1280 678 1280 679 0 679")); } } foreach (Beat bt in GetBeats()) { if (bt.Id < 151 || bt.Strength == 0) { continue; } for (int i = 0; i < 0.3 * 1500; i++) { double parx0 = Common.RandomInt(rnd, 0, PlayResX); double pary0 = Common.RandomInt(rnd, 678 - 30, 678 + 20); double parx1 = parx0 + Common.RandomInt(rnd, -5, 5); double pary1 = pary0 - 30; double part0 = bt.Time; double part1 = bt.Time + 0.3; ass_out.Events.Add( ev.StartReplace(part0).EndReplace(part1).StyleReplace("pt").LayerReplace(3).TextReplace( ASSEffect.move(parx0, pary0, parx1, pary1) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "55") + ASSEffect.c(3, "ED6D64") + ASSEffect.bord(2) + ASSEffect.blur(2) + ASSEffect.fad(0.05, 0.2) + ASSEffect.frz(Common.RandomInt(rnd, 0, 360)) + CreatePolygon(rnd, 10, 25, 6))); } } } int kSum = 0; //if (!(iEv == 1 || iEv == 3 || iEv == 5 || iEv == 7)) if (iEv + 1 < ass_in.Events.Count && ass_in.Events[iEv + 1].Start - ev.End > 0.5) { ev.End = ass_in.Events[iEv + 1].Start - 0.5; } 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 = ms1; Size sz = GetSize(ke.KText); if (ke.KText.Trim() == "") { sz.Width = 15; } double kStart = ev.Start + kSum * 0.01; double kEnd = kStart + ke.KValue * 0.01; kSum += ke.KValue; if (iK + 1 == kelems.Count && kEnd < ev.End) { kEnd = ev.End; } 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; } double r0 = ev.Start - 0.3; double t0 = kStart - 0.4; double t1 = t0 + 0.4; double t2 = ev.End; double r1 = r0 + 0.3; if (!(iEv == 0 || iEv == 2 || iEv == 4 || iEv == 6 || iEv == 8)) { for (int i = -1; i <= 1; i++) { ass_out.Events.Add( ev.StartReplace(r0).EndReplace(r1).TextReplace( ASSEffect.move(x + i * 10, y, x, y) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "00") + ASSEffect.c(3, "FFFFFF") + ASSEffect.xbord(20) + ASSEffect.be(20) + ASSEffect.ybord(0) + ASSEffect.t(0, r1 - r0, ASSEffect.xbord(0).t() + ASSEffect.be(0).t()) + ASSEffect.fad((r1 - r0) * 1, 0) + ke.KText)); } } else { ass_out.Events.Add( ev.StartReplace(ev.Start - 0.3).EndReplace(t1).LayerReplace(10).TextReplace( ASSEffect.pos(x, y) + ASSEffect.a(1, "77") + ASSEffect.c(1, "777777") + ASSEffect.a(3, "FF") + ASSEffect.fad(0.5, 0) + ke.KText)); } if (iEv == 4 || iEv == 5) { ass_out.Events.Add( ev.StartReplace(kStart - 0.1).EndReplace(kEnd).StyleReplace("pt").LayerReplace(0).TextReplace( ASSEffect.an(7) + ASSEffect.pos(0, 0) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "77") + ASSEffect.c(3, "ED6D64") + ASSEffect.bord(10) + ASSEffect.blur(10) + ASSEffect.fad(0.2, 0.2) + @"{\p1}" + string.Format("m {0} {1} l {0} {2} {3} {2} {3} {1}", x, PlayResY, PlayResY - MarginBottom - FontHeight - 285, x + 1))); ass_out.Events.Add( ev.StartReplace(kStart - 0.1).EndReplace(kEnd).StyleReplace("pt").LayerReplace(1).TextReplace( ASSEffect.an(7) + ASSEffect.pos(0, 0) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "77") + ASSEffect.c(3, "FFFFFF") + ASSEffect.bord(2) + ASSEffect.blur(2) + ASSEffect.fad(0.2, 0.2) + @"{\p1}" + string.Format("m {0} {1} l {0} {2} {3} {2} {3} {1}", x, PlayResY, PlayResY - MarginBottom - FontHeight - 285, x + 1))); for (int i = 0; i < (int)((kEnd - kStart) * 200); i++) { double parx0 = Common.RandomInt(rnd, x - 5, x + 5); double pary0 = Common.RandomInt(rnd, PlayResY - MarginBottom - FontHeight - 285, PlayResY); double parx1 = parx0 + Common.RandomInt(rnd, -20, 20); double pary1 = pary0 + Common.RandomInt(rnd, -5, 5); double part0 = Common.RandomDouble(rnd, kStart - 0.1, kEnd - 0.1); double part1 = part0 + Common.GetDistance(parx0, pary0, parx1, pary1) / 50.0; ass_out.Events.Add( ev.StartReplace(part0).EndReplace(part1).StyleReplace("pt").LayerReplace(3).TextReplace( ASSEffect.move(parx0, pary0, parx1, pary1) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "55") + ASSEffect.c(3, "ED6D64") + ASSEffect.bord(2) + ASSEffect.blur(2) + ASSEffect.fad(0.05, 0.2) + ASSEffect.frz(Common.RandomInt(rnd, 0, 360)) + CreatePolygon(rnd, 10, 25, 6))); } } if (iEv == 0 || iEv == 2 || iEv == 4 || iEv == 6 || iEv == 8) { double dt = 0.002; double dx, dy; { double t = t1; double ag = Math.PI * 2.0 * (t - t0) / (t1 - t0) - Math.PI * 0.5; double ca = 40; double cb = 18; double cx0 = ca * Math.Cos(ag); double cy0 = cb * Math.Sin(-ag); double cag = Math.PI * 0.25; double cx1 = cx0 * Math.Cos(cag) + cy0 * Math.Sin(cag); double cy1 = -cx0 *Math.Sin(cag) + cy0 * Math.Cos(cag); dx = -cx1; dy = -cy1; } for (double t = t0; t <= t1; t += dt) { double ag = Math.PI * 2.0 * (t - t0) / (t1 - t0) - Math.PI * 0.5; double ca = 40; double cb = 18; double cx0 = ca * Math.Cos(ag); double cy0 = cb * Math.Sin(-ag); double cag = Math.PI * 0.25; double cx1 = cx0 * Math.Cos(cag) + cy0 * Math.Sin(cag); double cy1 = -cx0 *Math.Sin(cag) + cy0 * Math.Cos(cag); cx1 += x + dx; cy1 += y + dy; int fs = (int)((double)this.FontHeight * (t - t0) / (t1 - t0) + 1); ass_out.Events.Add( ev.StartReplace(t).EndReplace(t + 0.4).LayerReplace(20).TextReplace( ASSEffect.pos(cx1, cy1) + ASSEffect.fs(fs) + ASSEffect.a(1, "E0") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "E0") + ASSEffect.c(3, "FFFFFF") + ASSEffect.fad(0, 0.3) + ASSEffect.bord(1) + ASSEffect.blur(1) + ke.KText)); ass_out.Events.Add( ev.StartReplace(t).EndReplace(t + dt).TextReplace( ASSEffect.pos(cx1, cy1) + ASSEffect.fs(fs) + ASSEffect.pos(x, y) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "FF") + ke.KText)); } ass_out.Events.Add( ev.StartReplace(t1).EndReplace(t1 + 0.35).LayerReplace(30).TextReplace( ASSEffect.pos(x, y) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "00") + ASSEffect.c(3, "FFFFFF") + ASSEffect.bord(8) + ASSEffect.blur(8) + ASSEffect.fad(0.05, 0.2) + ke.KText)); ass_out.Events.Add( ev.StartReplace(t1).EndReplace(t2 + 0.2).LayerReplace(30).TextReplace( ASSEffect.pos(x, y) + ASSEffect.a(1, "BB") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "BB") + ASSEffect.c(3, "FFFFFF") + ASSEffect.bord(2) + ASSEffect.blur(2) + 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, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "FF") + ke.KText)); } else { t0 += 0.2; t1 += 0.2; if (t0 < ev.Start) { t0 = ev.Start; t1 = t0 + 0.4; } ass_out.Events.Add( ev.StartReplace(r1 - 0.2).EndReplace(t0 + 0.2).LayerReplace(30).TextReplace( ASSEffect.pos(x, y) + ASSEffect.a(1, "E0") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "E0") + ASSEffect.c(3, "FFFFFF") + ASSEffect.bord(2) + ASSEffect.blur(2) + ASSEffect.fad(0.2, 0.2) + ke.KText)); ass_out.Events.Add( ev.StartReplace(r1).EndReplace(t0).TextReplace( ASSEffect.pos(x, y) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "FF") + ke.KText)); double dt = 0.002; double dx, dy; { double t = t1; double ag = Math.PI * 2.0 * (t - t0) / (t1 - t0) - Math.PI * 0.5; double ca = 40; double cb = 18; double cx0 = ca * Math.Cos(ag); double cy0 = cb * Math.Sin(-ag); double cag = Math.PI * 0.25; double cx1 = cx0 * Math.Cos(cag) + cy0 * Math.Sin(cag); double cy1 = -cx0 *Math.Sin(cag) + cy0 * Math.Cos(cag); dx = -cx1; dy = -cy1; } for (double t = t0; t <= t1; t += dt) { double ag = Math.PI * 2.0 * (t1 - t) / (t1 - t0) - Math.PI * 0.5; double ca = 40; double cb = 18; double cx0 = ca * Math.Cos(ag); double cy0 = cb * Math.Sin(-ag); double cag = Math.PI * 0.25; double cx1 = cx0 * Math.Cos(cag) + cy0 * Math.Sin(cag); double cy1 = -cx0 *Math.Sin(cag) + cy0 * Math.Cos(cag); cx1 += x + dx; cy1 += y + dy; int fs = (int)((double)this.FontHeight * (t1 - t) / (t1 - t0) + 1); ass_out.Events.Add( ev.StartReplace(t).EndReplace(t + 0.4).LayerReplace(20).TextReplace( ASSEffect.pos(cx1, cy1) + ASSEffect.fs(fs) + ASSEffect.a(1, "BB") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "BB") + ASSEffect.c(3, "FFFFFF") + ASSEffect.fad(0, 0.3) + ASSEffect.bord(1) + ASSEffect.blur(1) + ke.KText)); ass_out.Events.Add( ev.StartReplace(t).EndReplace(t + dt).TextReplace( ASSEffect.pos(cx1, cy1) + ASSEffect.fs(fs) + ASSEffect.pos(x, y) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "FF") + ke.KText)); } } double bt_lo = t1; bt_lo = ev.Start - 0.3 + 0.2; double bt_hi = t2; Func <double, bool> bbt = ti => ti >= t1; if (!(iEv == 0 || iEv == 2 || iEv == 4 || iEv == 6 || iEv == 8)) { bt_lo = ev.Start - 0.2; bt_hi = t1; bbt = ti => ti < kStart; } if (iEv == 0 || iEv == 2 || iEv == 4 || iEv == 6 || iEv == 8) { double t3 = t2 + 0.3; if (iEv + 1 < ass_in.Events.Count && ass_in.Events[iEv + 1].Start - ev.End < 0.3) { t3 = t2 + 0.1; } for (int i = -1; i <= 1; i++) { ass_out.Events.Add( ev.StartReplace(t2).EndReplace(t3).TextReplace( ASSEffect.move(x, y, x + i * 10, y) + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(3, "00") + ASSEffect.c(3, "FFFFFF") + ASSEffect.bord(0) + ASSEffect.blur(0) + ASSEffect.t(0, t3 - t2, ASSEffect.xbord(20).t() + ASSEffect.be(20).t()) + ASSEffect.fad(0, t3 - t2) + ke.KText)); } } else { double te = ev.End + 0.5; //if (iEv == 9) te -= 1; bt_hi = te - 0.5; ass_out.Events.Add( ev.EndReplace(te).LayerReplace(10).TextReplace( ASSEffect.pos(x, y) + ASSEffect.a(1, "77") + ASSEffect.c(1, "777777") + ASSEffect.a(3, "FF") + ASSEffect.fad(0, 0.5) + ke.KText)); } foreach (Beat bt in GetBeats()) { if (bt.Strength == 0) { continue; } if (bt.Time >= bt_lo && bt.Time < bt_hi) { string col = "FFFFFF"; int blurstr = 4; string ac = "44"; if (bt.Strength == 2) { col = "EEEEEE"; blurstr = 3; ac = "77"; } if (bt.Strength == 10) { blurstr = 5; ac = "00"; } if (!bbt(bt.Time)) { blurstr = 2; col = "111111"; } ass_out.Events.Add( ev.StartReplace(bt.Time).EndReplace(bt.Time + 0.3).LayerReplace(55).TextReplace( ASSEffect.pos(x, y) + ASSEffect.fad(0.05, 0.2) + ASSEffect.a(1, ac) + ASSEffect.c(1, col) + ASSEffect.a(3, ac) + ASSEffect.c(3, col) + ASSEffect.bord(blurstr) + ASSEffect.blur(blurstr) + ke.KText)); } } } } 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() { 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); }
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,DFGMaruMoji-SL,28,&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 ? 28 : 30; int jEv = isJp ? iEv : iEv; //if (jEv != 0) continue; ASSEvent ev = ass_in.Events[iEv]; List <KElement> kelems = ev.SplitK(true); int totalWidth = GetTotalWidth(ev); int x0 = (PlayResX - MarginLeft - MarginRight - totalWidth) / 2 + MarginLeft; 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 ? "ed_jp" : "ed_cn"; string mainColor = "505E66"; double t0 = ev.Start - 0.9 + (x - x0_start) / 848.0 * 3.0; double t1 = t0 + 0.5; double t2 = (ke.IsSplit ? ke.KStart_NoSplit : kStart) - 0.3; double t25 = t2 + 0.6; double t3 = ev.End - 0.9 + (x - x0_start) / 848.0 * 3.0; double t4 = t3 + 0.8; ass_out.AppendEvent(50, evStyle, t0, t1, fad((t1 - t0), 0) + pos(x, y) + a(1, "00") + c(1, mainColor) + fsc(1, 1) + t(0, 0.35, fsc(125, 125).t()) + t(0.35, 0.5, fsc(100, 100).t()) + ke.KText); ass_out.AppendEvent(50, evStyle, t1, t2, pos(x, y) + a(1, "00") + c(1, mainColor) + ke.KText); double[] tl = { t2, t2 + 0.15, t2 + 0.3, t2 + 0.45, t2 + 0.6 }; int[] xl = { 100, 80, 100, 115, 100 }; int[] yl = { 100, 120, 100, 80, 100 }; double[] yo = { 0, -10, 0, 2, 0 }; for (int i = 0; i < tl.Length - 1; i++) { ass_out.AppendEvent(50, evStyle, tl[i], tl[i + 1], move(x, y + yo[i], x, y + yo[i + 1]) + a(1, "00") + c(1, mainColor) + fsc(xl[i], yl[i]) + t(fsc(xl[i + 1], yl[i + 1]).t()) + ke.KText); } ass_out.AppendEvent(50, evStyle, t25, t3, pos(x, y) + a(1, "00") + c(1, mainColor) + ke.KText); /* * ass_out.AppendEvent(50, evStyle, t3, t4, * fad(0, (t4 - t3)) + pos(x, y) + * a(1, "00") + c(1, mainColor) + * t(0, 0.15, fsc(125, 125).t()) + t(0.15, 0.5, fsc(1, 1).t()) + * ke.KText); * */ ass_out.AppendEvent(50, evStyle, t3, t3 + 0.5, pos(x, y) + a(1, "00") + c(1, mainColor) + t(0, 0.15, fsc(125, 125).t()) + t(0.15, 0.5, fsc(0, 0).t()) + ke.KText); continue; //原本的矩形 double orgrec_x0 = x - sz.Width / 2 - 1; double orgrec_x1 = x + sz.Width / 2 + 1; double orgrec_y0 = y - FontHeight / 2 - 1; double orgrec_y1 = y + FontHeight / 2 + 1; //随机产生两个切割四边形 List <ASSPointF> cut0 = new List <ASSPointF>(); List <ASSPointF> cut1 = new List <ASSPointF>(); if (true)//(Common.RandomBool(rnd, 0.5)) { //竖直方向 double cutx0 = Common.RandomDouble_Gauss(rnd, orgrec_x0, orgrec_x1, 2); double cutx1 = Common.RandomDouble_Gauss(rnd, orgrec_x0, orgrec_x1, 2); cut0.Add(new ASSPointF { X = orgrec_x0, Y = orgrec_y0 }); cut0.Add(new ASSPointF { X = cutx0, Y = orgrec_y0 }); cut0.Add(new ASSPointF { X = cutx1, Y = orgrec_y1 }); cut0.Add(new ASSPointF { X = orgrec_x0, Y = orgrec_y1 }); cut1.Add(new ASSPointF { X = cutx0, Y = orgrec_y0 }); cut1.Add(new ASSPointF { X = orgrec_x1, Y = orgrec_y0 }); cut1.Add(new ASSPointF { X = orgrec_x1, Y = orgrec_y1 }); cut1.Add(new ASSPointF { X = cutx1, Y = orgrec_y1 }); } List <List <ASSPointF> > cutList = new List <List <ASSPointF> >(); cutList.Add(cut0); cutList.Add(cut1); foreach (List <ASSPointF> cut in cutList) { //累积旋转的角度 double rot_x = Common.RandomDouble(rnd, 0, Math.PI * 2) * Common.RandomSig(rnd); double rot_y = Common.RandomDouble(rnd, 0, Math.PI * 2) * Common.RandomSig(rnd); double rot_z = Common.RandomDouble(rnd, 0, Math.PI * 2) * Common.RandomSig(rnd); Func <double, double> frotx = ti => (ti - t3) / (t4 - t3) * rot_x; Func <double, double> froty = ti => (ti - t3) / (t4 - t3) * rot_y; Func <double, double> frotz = ti => (ti - t3) / (t4 - t3) * rot_z; Func <double, int> f1 = ti => (int)(ti / 2.0 / Math.PI * 360.0); double jumpTime = t4 - t3; Func <double, double> forgy = ti => y - 300.0 * (0.25 * jumpTime * jumpTime - ((ti - t3) - 0.5 * jumpTime) * ((ti - t3) - 0.5 * jumpTime)); double orgx1 = Common.RandomDouble(rnd, 20, 40) * (cut == cut0 ? -1 : 1) + x; Func <double, double> forgx = ti => (ti - t3) / jumpTime * (orgx1 - x) + x; for (double ti = t3; ti <= t4; ti += 0.04) { double rotx = frotx(ti); double roty = froty(ti); double rotz = frotz(ti); double org_x = forgx(ti); double org_y = forgy(ti); List <ASSPointF> newCut = new List <ASSPointF>(); foreach (ASSPointF pt in cut) { double caz = Math.Cos(rotz); double saz = Math.Sin(rotz); double cax = Math.Cos(rotx); double sax = Math.Sin(rotx); double cay = Math.Cos(roty); double say = Math.Sin(roty); double rx = pt.X - x; double ry = pt.Y - y; double rz = 0; double rxx = rx * caz + ry * saz; double ryy = -(rx * saz - ry * caz); double rzz = rz; rx = rxx; ry = ryy * cax + rzz * sax; rz = ryy * sax - rzz * cax; rxx = rx * cay + rz * say; ryy = ry; rzz = rx * say - rz * cay; rzz = Math.Max(rzz, -19000); rx = (rxx * 20000) / (rzz + 20000); ry = (ryy * 20000) / (rzz + 20000); newCut.Add(new ASSPointF { X = rx + org_x, Y = ry + org_y }); } ass_out.AppendEvent(50, evStyle, ti, ti + 0.04, pos(org_x, org_y) + clip(1, Pts2AssVec(newCut)) + a(1, Common.scaleAlpha("00", "FF", (ti - t3) / (t4 - t3))) + c(1, mainColor) + frx(f1(rotx)) + fry(f1(roty)) + frz(f1(rotz)) + ke.KText); /* * ass_out.AppendEvent(50, evStyle, ti, ti + 0.04, * pos(org_x, org_y) + a(1, "00") + * frx(f1(rotx)) + fry(f1(roty)) + frz(f1(rotz)) + * ke.KText); * ass_out.AppendEvent(51, "pt", ti, ti + 0.04, * pos(0, 0) + a(1, "44") + * p(1) + Pts2AssVec(newCut)); * */ } } /* * ass_out.AppendEvent(100, evStyle, t3, t4, * clip(1, Pts2AssVec(cut0)) + pos(x, y) + a(1, "00") + c(1, mainColor) + * ke.KText); * ass_out.AppendEvent(100, evStyle, t3, t4, * clip(1, Pts2AssVec(cut1)) + pos(x, y) + a(1, "00") + c(1, mainColor) + * ke.KText); * */ } } 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>(); 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() { Header = ass_in.Header, Events = new List <ASSEvent>() }; for (int iEv = 0; iEv < ass_in.Events.Count; iEv++) { bool isJp = iEv <= 6; //if (!isJp || iEv < 4 || iEv > 4) 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(!isJp); int x0 = MarginLeft; if ((isJp && iEv >= 4) || (!isJp && iEv - 7 >= 4)) { x0 = PlayResX - MarginRight - GetTotalWidth(ev); } int y0 = (isJp) ? (PlayResY - MarginBottom - FontHeight) : MarginTop; int kSum = 0; List <KeyValuePair <double, ASSPoint> > textpath = new List <KeyValuePair <double, ASSPoint> >(); 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); if (!isJp) { y += 2; } textpath.Add(new KeyValuePair <double, ASSPoint>(kStart, new ASSPoint { X = x, Y = y, Start = kStart, End = kEnd })); 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; { string red = "1A037C"; red = "3B1FB6"; string aoi = "9D3653"; string scol = iEv <= 1 ? red : aoi; if (iEv >= 4) { scol = red; } if (isJp) { ass_out.AppendEvent(51, "pt", t2, t2 + 1, pos(0, 0) + fad(0, 0.9) + a(1, "00") + a(3, "77") + blur(5) + bord(5) + t(bord(0).t()) + p(4) + outlineString); } ass_out.AppendEvent(40, "pt", t0, t5, pos(1, 1) + fad(0.5, 0.5) + a(1, "00") + blur(1.3) + c(1, "000000") + p(4) + outlineString); if (true) { double lastptx0 = 0; double lastpty0 = 0; bool first = true; for (double ti = t0 - 1 + Common.RandomDouble(rnd, -0.3, 0.3); ti <= t5 - 1.5; ti += Common.RandomDouble(rnd, 1.2, 1.65)) { double ptt0 = ti; double ptt1 = ptt0 + 3; double ptx0 = Common.RandomDouble(rnd, x - 20, x + 20); double pty0 = Common.RandomDouble(rnd, y - 20, y + 20); if (!first) { for (int i = 0; i < 2; i++) { double ptx0_tmp = Common.RandomDouble(rnd, x - 20, x + 20); double pty0_tmp = Common.RandomDouble(rnd, y - 20, y + 20); if (Common.GetDistance(lastptx0, lastpty0, ptx0, pty0) < Common.GetDistance(lastptx0, lastpty0, ptx0_tmp, pty0_tmp)) { ptx0 = ptx0_tmp; pty0 = pty0_tmp; } } } first = false; lastptx0 = ptx0; lastpty0 = pty0; string ptcol = "FFFFFF"; double lumsz = 15 + Common.GetDistance(x, y, ptx0, pty0) * 0.5; if (ptt0 >= kStart - 1 && ptt0 <= kEnd - 1) { lumsz += 0; } //if (iEv <= 3) if (isJp) { if (ptt0 >= t2) { ptcol = scol; } } string ts0 = ""; //if (iEv <= 3) if (isJp) { if (ptt0 < t2 && ptt1 > t2) { ts0 = t(t2 - ptt0 - 0.01, t2 - ptt0, c(1, scol).t() + c(3, scol).t()); } } int dup = 1; if ((isJp && iEv >= 4) || (!isJp && iEv - 7 >= 4)) { dup = 2; } while (dup-- > 0) { ass_out.AppendEvent(50, "pt", ptt0, ptt1, pos(ptx0, pty0) + clip(4, outlineString) + org(x, y) + t(frz(Common.RandomSig(rnd) * Common.RandomInt(rnd, 80, 120)).t()) + fad(0.8, 0.8) + t(0, ptt1 - ptt0, bord(lumsz).t() + blur(lumsz).t()) + a(1, "44") + a(3, "44") + c(1, ptcol) + c(3, ptcol) + ts0 + t((ptt1 - ptt0) * 0.7, ptt1, c(1, "000000").t() + c(3, "000000").t()) + p(1) + "m 0 0 l 1 0 1 1 0 1"); } } } } if (!isJp) { continue; } if (iEv <= 3) { for (int i = 0; i < (kEnd - kStart) * 7; i++) { double ptx0 = Common.RandomDouble(rnd, x - 20, x + 20); double pty0 = Common.RandomDouble(rnd, y - 5, y + 20); double ptx1 = Common.RandomDouble(rnd, ptx0 - 150, ptx0 - 250); double pty1 = Common.RandomDouble(rnd, pty0 - 30, pty0 - 80); double ptt0 = Common.RandomDouble(rnd, kStart, kEnd) - 0.3; double ptt1 = ptt0 + 5; double posx = 0, posy = 0; if (ptx0 < 0 || ptx1 < 0) { posx = Math.Min(ptx0, ptx1); ptx0 -= posx; ptx1 -= posx; } if (pty0 < 0 || pty1 < 0) { posy = Math.Min(pty0, pty1); pty0 -= posy; pty1 -= posy; } string moveStringX = fscx((int)(ptx0 * 100)) + t(0, 5, 3, fscx((int)(ptx1 * 100)).t()); string moveStringY = fscy((int)(pty0 * 100)) + t(0, 5, 0.6, fscy((int)(pty1 * 100)).t()); string splashString = ""; for (double ti = 0; ti <= ptt1 - ptt0; ti += 0.8) { splashString += t(ti + 0, ti + 0.4, a(1, "FF").t() + a(3, "FF").t()) + t(ti + 0.4, ti + 0.8, a(1, "22").t() + a(3, "44").t()); } string ptstr = @"{\p1}m 0 0 l 1 0 1 1 0 1"; string par = CreatePolygon(rnd, 5, 10, 6); string parcol = "EC3667"; if (iEv <= 1) { parcol = "532BFF"; } for (int j = 0; j < 1; j++) { ass_out.AppendEvent(12, "pt", ptt0 + j * 0.1, ptt1 + j * 0.1, pos(posx, posy) + moveStringY + ptstr + "\\N" + r() + moveStringX + ptstr + r() + fad(0, 0.5) + pos(0, 0) + a(1, "22") + a(3, "44") + blur(1.5) + bord(1.5) + c(3, parcol) + splashString + par); } } } } if (!isJp) { continue; } //continue; if (iEv >= 4) { for (int i = 0; i < textpath.Count - 1; i++) { if (textpath[i].Value.End < textpath[i + 1].Value.Start) { textpath[i].Value.End = textpath[i + 1].Value.Start; } } textpath[textpath.Count - 1].Value.End = ev.End; emitterList = new List <ASSPointF>(); foreach (KeyValuePair <double, ASSPoint> pair in textpath) { emitterList.Add(new ASSPointF { Start = pair.Value.Start, End = pair.Value.End, X = pair.Value.X + Common.RandomDouble(rnd, -20, 20), Y = pair.Value.Y + Common.RandomDouble(rnd, -20, 20) }); } forceCurve = new CompositeCurve { MinT = ev.Start, MaxT = ev.End + 10 }; double lastag = 0; for (double time = forceCurve.MinT; time <= forceCurve.MaxT; time += 0.7) { double ag = Common.RandomDouble(rnd, 0, Math.PI * 2); while (Math.Abs(ag - lastag) < Math.PI * 0.5 || Math.Abs(ag - lastag) > Math.PI * 1.5) { ag = Common.RandomDouble(rnd, 0, Math.PI * 2); } lastag = ag; double x = 1500.0 * Math.Cos(ag); double y = 800.0 * Math.Sin(ag); forceCurve.AddCurve(time, time + 0.7, new Line { X0 = x, Y0 = y, X1 = 0, Y1 = 0, Acc = 0.7 }); } NumberPerSecond = 90; XXParticleSystem xxps = new XXParticleSystem(); xxps.Emitter = this; xxps.ForceField = this; xxps.StartTime = ev.Start; xxps.EndTime = ev.End; xxps.InterpolationPrecision = 0.03; xxps.Resistance = 0.04; xxps.Repulsion = -3600; xxps.Gravity = 0; xxps.GravityPosition = this; xxps.InterpolationPrecision = 0.01; List <KeyValuePair <XXParticleElement, List <string> > > result = xxps.RenderT(); foreach (KeyValuePair <XXParticleElement, List <string> > pair in result) { string s = CreatePolygon(rnd, 12, 12, 4); string ptstr = @"{\p1}m 0 0 l 1 0 1 1 0 1"; string ptcol = "532BFF"; ass_out.AppendEvent(100, "pt", pair.Key.Born, pair.Key.Born + pair.Key.Life, pos(-100, -100) + pair.Value[1] + ptstr + "\\N" + r() + pair.Value[0] + ptstr + r() + a(1, "22") + a(3, "77") + blur(2.5) + bord(2) + c(3, ptcol) + s); } /* * List<KeyValuePair<XXParticleElement, List<ASSPointF>>> result = xxps.RenderPoint(); * foreach (KeyValuePair<XXParticleElement, List<ASSPointF>> pair in result) * { * string s = CreatePolygon(rnd, 12, 12, 4); * foreach (ASSPointF pt in pair.Value) * { * pt.T -= 0.3; * string ptcol = "532BFF"; * ass_out.AppendEvent(100, "pt", pt.T, pt.T + xxps.InterpolationPrecision, * pos(pt.X, pt.Y) + a(1, "22") + a(3, "77") + blur(2.5) + bord(2) + c(3, ptcol) + * s); * } * } * */ } } 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 <= 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 <= 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>(); 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); }
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++) { 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); }
public override void Run() { string ms3 = "Style: Default,DFGMaruMoji-SL,44,&H0000FFFF,&HFF000000,&H00FF0000,&HFF000000,0,0,0,0,100,100,2,0,1,2,0,5,30,30,10,128"; string msc = "Style: Default,華康少女文字W5(P),44,&H0000FFFF,&HFF000000,&H00FF0000,&HFF000000,0,0,0,0,100,100,2,0,1,2,0,5,30,30,10,136"; // 8BFF97 green 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(); int testEv = -1; for (int iEv = 0; iEv <= 22; iEv++) { if (testEv >= 0 && iEv != testEv) { 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 y0 = PlayResY - MarginBottom - FontHeight; int kSum = 0; 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; x0 += this.FontSpace + sz.Width; y0 = y0; if (ke.KText.Trim().Length == 0) { continue; } string col1 = "3CD846"; string green = col1; if (iEv == 1) { col1 = "C13BA5"; } if (iEv == 2) { col1 = "3E58A6"; } if (iEv == 3) { col1 = (iK % 2 == 0) ? "D4004D" : "E79805"; } if (iEv == 4) { if (iK <= 7) { col1 = (iK % 2 == 0) ? "D4004D" : "E79805"; } else if (iK <= 9) { col1 = "1FBD3E"; } else { col1 = "C41426"; } } if (iEv == 5) { if (iK >= 8 && iK <= 10) { col1 = "F1D53C"; } } if (iEv == 6) { if (iK >= 4 && iK <= 8) { col1 = "F1D53C"; } else if (iK >= 10) { col1 = "F25756"; } } if (iEv == 7) { if (iK >= 6 && iK <= 10) { col1 = "5D477C"; } } if (iEv == 8) { if (iK <= 1) { col1 = "5D477C"; } } if (iEv == 9) { col1 = "4399AE"; } if (iEv == 10 || iEv == 11) { col1 = "AE4343"; } if (iEv == 12) { col1 = "4344AE"; } if (iEv == 13) { col1 = (iK % 2 == 0) ? green : "DC49A6"; } if (iEv == 14) { col1 = (iK % 2 == 0) ? green : "C13BA5"; } if (iEv == 15) { col1 = (iK % 2 == 0) ? green : "3E58A6"; } if (iEv == 16) { col1 = (iK % 2 == 0) ? "D4004D" : "E79805"; } if (iEv == 17) { if (iK <= 7) { col1 = (iK % 2 == 0) ? "D4004D" : "E79805"; } else if (iK <= 9) { col1 = "1FBD3E"; } else { col1 = "C41426"; } } if (iEv == 18 || iEv == 19) { col1 = (iK % 2 == 0) ? green : "4B84C7"; } if (iEv == 20) { col1 = (iK % 2 == 0) ? green : "C3577F"; } if (iEv == 21) { col1 = (iK % 2 == 0) ? green : "882DB5"; } if (iEv == 22) { if (iK >= 5 && iK <= 10) { col1 = (iK % 2 == 0) ? "D4004D" : "E79805"; } else if (iK <= 12) { col1 = "1FBD3E"; } else { col1 = "C41426"; } } col1 = ASSColor.HtmlToASS(col1); // bezier if (iEv >= 5) { List <ASSPoint> pts = new Bezier( new ASSPoint { X = (iEv % 2 == 0) ? x - 100 : x + 100, Y = y - 50 }, new ASSPoint { X = x + ((iEv % 2 == 0) ? 50 : -40), Y = y - 50 }, new ASSPoint { X = x + ((iEv % 2 == 0) ? 50 : -40), Y = y + 30 }, new ASSPoint { X = (iEv % 2 == 0) ? x - 100 : x + 100, Y = y + 30 } ).Create(0.005f); double lastt0 = kStart - 0.3; for (int i = 0; i < pts.Count; i++) { ASSPoint pt = pts[i]; double t0 = kStart - 0.3 + 0.6 * (double)i / (double)pts.Count; double t1 = t0 + 0.3; ass_out.Events.Add( ev.StartReplace(t0).EndReplace(t1).StyleReplace("pt").LayerReplace(15).TextReplace( ASSEffect.pos(pt.X, pt.Y) + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(1, "00") + ASSEffect.c(3, col1) + ASSEffect.a(3, "77") + ASSEffect.bord((iEv >= 0) ? 2 : 1) + ASSEffect.blur((iEv >= 0) ? 2 : 1) + ASSEffect.fad(0, 0.3) + ASSEffect.t(0, t1 - t0, ASSEffect.c(1, "FFFFFF").t() + ASSEffect.c(3, "FFFFFF").t()) + @"{\p1}m 0 0 l 1 0 1 1 0 1")); if (t0 - lastt0 >= 0.04 || i + 1 == pts.Count) { string colb = Common.scaleColor(col1, "FFFFFF", 0.3); ass_out.Events.Add( ev.StartReplace(t0).EndReplace(t0 + 0.04).StyleReplace("pt").LayerReplace(16).TextReplace( ASSEffect.pos(pt.X, pt.Y) + ASSEffect.c(1, "FFFFFF") + ASSEffect.a(1, "00") + ASSEffect.c(3, colb) + ASSEffect.a(3, "00") + ASSEffect.bord((iEv >= 0) ? 6 : 4) + ASSEffect.blur((iEv >= 0) ? 5 : 3) + @"{\p1}m 0 0 l 1 0 1 1 0 1")); lastt0 = t0; } } } //if (iEv <= 2) { double jumpTime = 0.5; double t0 = kStart - jumpTime; double t1 = t0; double dt = 0.01; Func <double, double> f_y = ti => y - 1100.0 * (0.25 * jumpTime * jumpTime - ((ti - t0) - 0.5 * jumpTime) * ((ti - t0) - 0.5 * jumpTime)); Func <double, double> f_x = ti => x; Func <double, int> f_fs = ti => (int)(1 + Math.Round((ti - kStart + jumpTime) / jumpTime * FontWidth)); if (iEv >= 5 && iEv <= 12) { f_y = ti => y; f_x = ti => x - 100 * (ti - t0) / jumpTime + 100; f_fs = ti => FontWidth; } double d12 = 0.2; if (iEv > 12) { t0 -= d12; t1 = t0; f_fs = ti => (int)(1 + Math.Round((ti - kStart + d12 + jumpTime) / jumpTime * FontWidth)); } for (; t1 <= kStart - ((iEv > 12) ? d12 : 0); t1 += dt) { ass_out.Events.Add( ev.StartReplace(t1 - dt - 0.1).EndReplace(t1 - 0.1).TextReplace( ASSEffect.pos(f_x(t1), f_y(t1)) + ASSEffect.fs(f_fs(t1)) + ASSEffect.c(1, (iEv >= 5) ? "555555" : col1) + ASSEffect.c(3, "FFFFFF") + ke.KText)); ass_out.Events.Add( ev.StartReplace(t1 - dt - 0.1).EndReplace(t1 - dt - 0.1 + 0.4).LayerReplace(5).TextReplace( ASSEffect.pos(f_x(t1), f_y(t1)) + ASSEffect.fs(f_fs(t1)) + ASSEffect.be(1) + ASSEffect.c(1, "FFFFFF") + ASSEffect.c(3, "FFFFFF") + ASSEffect.a(1, "AA") + ASSEffect.a(3, "AA") + ASSEffect.fad(0, 0.3) + ke.KText)); } t1 -= dt + 0.1; double t2 = ev.End + r * 1 - 0.9; if (iEv >= 5) { if (iEv >= 9) { ass_out.Events.Add( ev.StartReplace(kStart - 0.05).EndReplace(t2).LayerReplace(8).TextReplace( ASSEffect.pos(x, y) + ASSEffect.a(3, "44") + ASSEffect.a(1, "FF") + ASSEffect.c(3, col1) + ASSEffect.bord((iEv >= 13) ? 8 : 5) + ASSEffect.blur((iEv >= 13) ? 7 : 4) + ASSEffect.fad(0, 0.3) + ke.KText)); } else { ass_out.Events.Add( ev.StartReplace(kStart - 0.05).EndReplace(t2).LayerReplace(8).TextReplace( ASSEffect.pos(x, y) + ASSEffect.a(3, "44") + ASSEffect.a(1, "FF") + ASSEffect.c(3, "FFFFFF") + ASSEffect.bord(3) + ASSEffect.blur(2) + ASSEffect.fad(0, 0.3) + ke.KText)); } ass_out.Events.Add( ev.StartReplace(kStart - 0.05).EndReplace(kStart + ((iEv >= 13) ? 0.3 : 0.15)).LayerReplace(15).TextReplace( ASSEffect.pos(x, y) + ASSEffect.a(3, "00") + ASSEffect.c(3, "FFFFFF") + ASSEffect.a(1, "00") + ASSEffect.c(1, "FFFFFF") + ASSEffect.bord(5) + ASSEffect.blur(4) + ASSEffect.fad(0, 0.2) + ke.KText)); ass_out.Events.Add( ev.StartReplace(kStart - 0.05).EndReplace(t2).LayerReplace(13).TextReplace( ASSEffect.pos(x, y) + ASSEffect.a(3, "FF") + ASSEffect.a(1, "00") + ASSEffect.c(1, col1) + ke.KText)); } ass_out.Events.Add( ev.StartReplace(t1).EndReplace(t2).TextReplace( ASSEffect.pos(x, y) + ASSEffect.c(1, (iEv >= 5) ? "555555" : col1) + ASSEffect.c(3, "FFFFFF") + ke.KText)); { double ag = Common.RandomDouble(rnd, 0, Math.PI * 2); if (iEv >= 9 && iEv <= 11) { ag = Math.PI * 0.75; } double ra = 100; double x1 = x + ra * Math.Cos(ag); double y1 = y + ra * Math.Sin(ag); bool first = true; for (double t3 = t2; t3 < t2 + 0.4; t3 += 0.02) { double t4 = t3 + 0.5; string cole = Common.scaleColor(col1, "FFFFFF", (t3 - t2) / 0.5); if (iEv <= 3) { cole = "FFFFFF"; } if (iEv >= 9 && iEv <= 11) { cole = "FFFFFF"; } ass_out.Events.Add( ev.StartReplace(t3).EndReplace(t4).LayerReplace(first ? 10 : 5).TextReplace( ASSEffect.move(x, y, x1, y1) + ASSEffect.fad(0, 0.3) + ASSEffect.be(first ? 0 : 1) + ASSEffect.c(1, first ? col1 : cole) + ASSEffect.a(1, first ? "00" : "AA") + ASSEffect.c(3, first ? "FFFFFF" : cole) + ASSEffect.a(3, first ? "00" : "AA") + ke.KText)); first = false; } } } } } for (int iiEv = 23; iiEv <= 45; iiEv++) { break; int iEv = iiEv - 23; if (testEv >= 0 && iEv != testEv) { continue; } ASSEvent ev = ass_in.Events[iiEv]; List <KElement> kelems = ev.SplitK(true); this.MaskStyle = msc; double sw = (iEv % 2 == 0) ? 0 : GetTotalWidth(ev); /// an7 pos int x0 = (iEv % 2 == 0) ? MarginLeft : (int)(PlayResX - MarginRight - sw); int y0 = MarginTop; int kSum = 0; for (int iK = 0; iK < kelems.Count; iK++) { //if (iK > 3) continue; Console.WriteLine("{0} / {1} : {2} / {3}", iiEv + 1, ass_in.Events.Count, iK + 1, kelems.Count); KElement ke = kelems[iK]; double r = (double)iK / (double)(kelems.Count - 1); this.MaskStyle = ms3; Size sz = GetSize(ke.KText); 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; x0 += this.FontSpace + sz.Width; y0 = y0; if (ke.KText.Trim().Length == 0) { continue; } string col1 = "3CD846"; string green = col1; if (iEv == 1) { col1 = "C13BA5"; } if (iEv == 2) { col1 = "3E58A6"; } if (iEv == 3) { col1 = (iK % 2 == 0) ? "D4004D" : "E79805"; } if (iEv == 4) { if (iK <= 12) { col1 = (iK % 2 == 0) ? "D4004D" : "E79805"; } else if (iK <= 13) { col1 = "1FBD3E"; } else { col1 = "C41426"; } } if (iEv == 5) { if (iK >= 10) { col1 = "F1D53C"; } } if (iEv == 6) { if (iK >= 4 && iK <= 5) { col1 = "F1D53C"; } else if (iK >= 10) { col1 = "F25756"; } } if (iEv == 7) { if (iK >= 5) { col1 = "5D477C"; } } if (iEv == 8) { if (iK >= 3 && iK <= 4) { col1 = "5D477C"; } } if (iEv == 9) { col1 = "4399AE"; } if (iEv == 10 || iEv == 11) { col1 = "AE4343"; } if (iEv == 12) { col1 = "4344AE"; } if (iEv == 13) { col1 = (iK % 2 == 0) ? green : "DC49A6"; } if (iEv == 14) { col1 = (iK % 2 == 0) ? green : "C13BA5"; } if (iEv == 15) { col1 = (iK % 2 == 0) ? green : "3E58A6"; } if (iEv == 16) { col1 = (iK % 2 == 0) ? "D4004D" : "E79805"; } if (iEv == 17) { if (iK <= 12) { col1 = (iK % 2 == 0) ? "D4004D" : "E79805"; } else if (iK <= 13) { col1 = "1FBD3E"; } else { col1 = "C41426"; } } if (iEv == 18 || iEv == 19) { col1 = (iK % 2 == 0) ? green : "4B84C7"; } if (iEv == 20) { col1 = (iK % 2 == 0) ? green : "C3577F"; } if (iEv == 21) { col1 = (iK % 2 == 0) ? green : "882DB5"; } if (iEv == 22) { if (iK >= 4 && iK <= 11) { col1 = (iK % 2 == 0) ? "D4004D" : "E79805"; } else if (iK <= 12) { col1 = "1FBD3E"; } else { col1 = "C41426"; } } col1 = ASSColor.HtmlToASS(col1); { double jumpTime = 0.5; double t0 = kStart - jumpTime; double t1 = t0; double dt = 0.01; Func <double, double> f_y = ti => y; Func <double, double> f_x = ti => x - 100 * (ti - t0) / jumpTime + 100; Func <double, int> f_fs = ti => FontWidth; for (; t1 <= kStart; t1 += dt) { ass_out.Events.Add( ev.StartReplace(t1 - dt - 0.1).EndReplace(t1 - 0.1).TextReplace( ASSEffect.pos(f_x(t1), f_y(t1)) + ASSEffect.fs(f_fs(t1)) + ASSEffect.c(1, col1) + ASSEffect.c(3, "FFFFFF") + ke.KText)); ass_out.Events.Add( ev.StartReplace(t1 - dt - 0.1).EndReplace(t1 - dt - 0.1 + 0.4).LayerReplace(5).TextReplace( ASSEffect.pos(f_x(t1), f_y(t1)) + ASSEffect.fs(f_fs(t1)) + ASSEffect.be(1) + ASSEffect.c(1, "FFFFFF") + ASSEffect.c(3, "FFFFFF") + ASSEffect.a(1, "AA") + ASSEffect.a(3, "AA") + ASSEffect.fad(0, 0.3) + ke.KText)); } t1 -= dt + 0.1; double t2 = ev.End + r * 1 - 0.9; ass_out.Events.Add( ev.StartReplace(t1).EndReplace(t2).TextReplace( ASSEffect.pos(x, y) + ASSEffect.c(1, col1) + ASSEffect.c(3, "FFFFFF") + ke.KText)); { double ag = Common.RandomDouble(rnd, 0, Math.PI * 2); if (iEv >= 9 && iEv <= 11) { ag = Math.PI * 1.25; } double ra = 100; double x1 = x + ra * Math.Cos(ag); double y1 = y + ra * Math.Sin(ag); bool first = true; for (double t3 = t2; t3 < t2 + 0.4; t3 += 0.02) { double t4 = t3 + 0.5; string cole = Common.scaleColor(col1, "FFFFFF", (t3 - t2) / 0.5); if (iEv <= 3) { cole = "FFFFFF"; } if (iEv >= 9 && iEv <= 11) { cole = "FFFFFF"; } ass_out.Events.Add( ev.StartReplace(t3).EndReplace(t4).LayerReplace(first ? 10 : 5).TextReplace( ASSEffect.move(x, y, x1, y1) + ASSEffect.fad(0, 0.3) + ASSEffect.be(first ? 0 : 1) + ASSEffect.c(1, first ? col1 : cole) + ASSEffect.a(1, first ? "00" : "AA") + ASSEffect.c(3, first ? "FFFFFF" : cole) + ASSEffect.a(3, first ? "00" : "AA") + ke.KText)); first = false; } } } } } ass_out.SaveFile(OutFileName); Console.WriteLine("Lines : {0}", ass_out.Events.Count); }