├── .gitattributes
├── .gitignore
├── .gitmodules
├── LICENSE
├── README.md
├── atri-composite.sln
└── atri-composite
├── App.config
├── App.xaml
├── App.xaml.cs
├── BatchExporter.cs
├── Character.cs
├── CharacterProcessor.cs
├── CompoundImage.cs
├── MainWindow.xaml
├── MainWindow.xaml.cs
├── Properties
├── AssemblyInfo.cs
├── Resources.Designer.cs
├── Resources.resx
├── Settings.Designer.cs
└── Settings.settings
├── Utils.cs
├── atri-composite.csproj
├── icon.ico
├── packages.config
└── pbd2json.exe
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | [Aa][Rr][Mm]/
24 | [Aa][Rr][Mm]64/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 | [Ll]og/
29 |
30 | # Visual Studio 2015/2017 cache/options directory
31 | .vs/
32 | # Uncomment if you have tasks that create the project's static files in wwwroot
33 | #wwwroot/
34 |
35 | # Visual Studio 2017 auto generated files
36 | Generated\ Files/
37 |
38 | # MSTest test Results
39 | [Tt]est[Rr]esult*/
40 | [Bb]uild[Ll]og.*
41 |
42 | # NUNIT
43 | *.VisualState.xml
44 | TestResult.xml
45 |
46 | # Build Results of an ATL Project
47 | [Dd]ebugPS/
48 | [Rr]eleasePS/
49 | dlldata.c
50 |
51 | # Benchmark Results
52 | BenchmarkDotNet.Artifacts/
53 |
54 | # .NET Core
55 | project.lock.json
56 | project.fragment.lock.json
57 | artifacts/
58 |
59 | # StyleCop
60 | StyleCopReport.xml
61 |
62 | # Files built by Visual Studio
63 | *_i.c
64 | *_p.c
65 | *_h.h
66 | *.ilk
67 | *.meta
68 | *.obj
69 | *.iobj
70 | *.pch
71 | *.pdb
72 | *.ipdb
73 | *.pgc
74 | *.pgd
75 | *.rsp
76 | *.sbr
77 | *.tlb
78 | *.tli
79 | *.tlh
80 | *.tmp
81 | *.tmp_proj
82 | *_wpftmp.csproj
83 | *.log
84 | *.vspscc
85 | *.vssscc
86 | .builds
87 | *.pidb
88 | *.svclog
89 | *.scc
90 |
91 | # Chutzpah Test files
92 | _Chutzpah*
93 |
94 | # Visual C++ cache files
95 | ipch/
96 | *.aps
97 | *.ncb
98 | *.opendb
99 | *.opensdf
100 | *.sdf
101 | *.cachefile
102 | *.VC.db
103 | *.VC.VC.opendb
104 |
105 | # Visual Studio profiler
106 | *.psess
107 | *.vsp
108 | *.vspx
109 | *.sap
110 |
111 | # Visual Studio Trace Files
112 | *.e2e
113 |
114 | # TFS 2012 Local Workspace
115 | $tf/
116 |
117 | # Guidance Automation Toolkit
118 | *.gpState
119 |
120 | # ReSharper is a .NET coding add-in
121 | _ReSharper*/
122 | *.[Rr]e[Ss]harper
123 | *.DotSettings.user
124 |
125 | # JustCode is a .NET coding add-in
126 | .JustCode
127 |
128 | # TeamCity is a build add-in
129 | _TeamCity*
130 |
131 | # DotCover is a Code Coverage Tool
132 | *.dotCover
133 |
134 | # AxoCover is a Code Coverage Tool
135 | .axoCover/*
136 | !.axoCover/settings.json
137 |
138 | # Visual Studio code coverage results
139 | *.coverage
140 | *.coveragexml
141 |
142 | # NCrunch
143 | _NCrunch_*
144 | .*crunch*.local.xml
145 | nCrunchTemp_*
146 |
147 | # MightyMoose
148 | *.mm.*
149 | AutoTest.Net/
150 |
151 | # Web workbench (sass)
152 | .sass-cache/
153 |
154 | # Installshield output folder
155 | [Ee]xpress/
156 |
157 | # DocProject is a documentation generator add-in
158 | DocProject/buildhelp/
159 | DocProject/Help/*.HxT
160 | DocProject/Help/*.HxC
161 | DocProject/Help/*.hhc
162 | DocProject/Help/*.hhk
163 | DocProject/Help/*.hhp
164 | DocProject/Help/Html2
165 | DocProject/Help/html
166 |
167 | # Click-Once directory
168 | publish/
169 |
170 | # Publish Web Output
171 | *.[Pp]ublish.xml
172 | *.azurePubxml
173 | # Note: Comment the next line if you want to checkin your web deploy settings,
174 | # but database connection strings (with potential passwords) will be unencrypted
175 | *.pubxml
176 | *.publishproj
177 |
178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
179 | # checkin your Azure Web App publish settings, but sensitive information contained
180 | # in these scripts will be unencrypted
181 | PublishScripts/
182 |
183 | # NuGet Packages
184 | *.nupkg
185 | # The packages folder can be ignored because of Package Restore
186 | **/[Pp]ackages/*
187 | # except build/, which is used as an MSBuild target.
188 | !**/[Pp]ackages/build/
189 | # Uncomment if necessary however generally it will be regenerated when needed
190 | #!**/[Pp]ackages/repositories.config
191 | # NuGet v3's project.json files produces more ignorable files
192 | *.nuget.props
193 | *.nuget.targets
194 |
195 | # Microsoft Azure Build Output
196 | csx/
197 | *.build.csdef
198 |
199 | # Microsoft Azure Emulator
200 | ecf/
201 | rcf/
202 |
203 | # Windows Store app package directories and files
204 | AppPackages/
205 | BundleArtifacts/
206 | Package.StoreAssociation.xml
207 | _pkginfo.txt
208 | *.appx
209 |
210 | # Visual Studio cache files
211 | # files ending in .cache can be ignored
212 | *.[Cc]ache
213 | # but keep track of directories ending in .cache
214 | !?*.[Cc]ache/
215 |
216 | # Others
217 | ClientBin/
218 | ~$*
219 | *~
220 | *.dbmdl
221 | *.dbproj.schemaview
222 | *.jfm
223 | *.pfx
224 | *.publishsettings
225 | orleans.codegen.cs
226 |
227 | # Including strong name files can present a security risk
228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
229 | #*.snk
230 |
231 | # Since there are multiple workflows, uncomment next line to ignore bower_components
232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
233 | #bower_components/
234 |
235 | # RIA/Silverlight projects
236 | Generated_Code/
237 |
238 | # Backup & report files from converting an old project file
239 | # to a newer Visual Studio version. Backup files are not needed,
240 | # because we have git ;-)
241 | _UpgradeReport_Files/
242 | Backup*/
243 | UpgradeLog*.XML
244 | UpgradeLog*.htm
245 | ServiceFabricBackup/
246 | *.rptproj.bak
247 |
248 | # SQL Server files
249 | *.mdf
250 | *.ldf
251 | *.ndf
252 |
253 | # Business Intelligence projects
254 | *.rdl.data
255 | *.bim.layout
256 | *.bim_*.settings
257 | *.rptproj.rsuser
258 | *- Backup*.rdl
259 |
260 | # Microsoft Fakes
261 | FakesAssemblies/
262 |
263 | # GhostDoc plugin setting file
264 | *.GhostDoc.xml
265 |
266 | # Node.js Tools for Visual Studio
267 | .ntvs_analysis.dat
268 | node_modules/
269 |
270 | # Visual Studio 6 build log
271 | *.plg
272 |
273 | # Visual Studio 6 workspace options file
274 | *.opt
275 |
276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
277 | *.vbw
278 |
279 | # Visual Studio LightSwitch build output
280 | **/*.HTMLClient/GeneratedArtifacts
281 | **/*.DesktopClient/GeneratedArtifacts
282 | **/*.DesktopClient/ModelManifest.xml
283 | **/*.Server/GeneratedArtifacts
284 | **/*.Server/ModelManifest.xml
285 | _Pvt_Extensions
286 |
287 | # Paket dependency manager
288 | .paket/paket.exe
289 | paket-files/
290 |
291 | # FAKE - F# Make
292 | .fake/
293 |
294 | # JetBrains Rider
295 | .idea/
296 | *.sln.iml
297 |
298 | # CodeRush personal settings
299 | .cr/personal
300 |
301 | # Python Tools for Visual Studio (PTVS)
302 | __pycache__/
303 | *.pyc
304 |
305 | # Cake - Uncomment if you are using it
306 | # tools/**
307 | # !tools/packages.config
308 |
309 | # Tabs Studio
310 | *.tss
311 |
312 | # Telerik's JustMock configuration file
313 | *.jmconfig
314 |
315 | # BizTalk build output
316 | *.btp.cs
317 | *.btm.cs
318 | *.odx.cs
319 | *.xsd.cs
320 |
321 | # OpenCover UI analysis results
322 | OpenCover/
323 |
324 | # Azure Stream Analytics local run output
325 | ASALocalRun/
326 |
327 | # MSBuild Binary and Structured Log
328 | *.binlog
329 |
330 | # NVidia Nsight GPU debugger configuration file
331 | *.nvuser
332 |
333 | # MFractors (Xamarin productivity tool) working folder
334 | .mfractor/
335 |
336 | # Local History for Visual Studio
337 | .localhistory/
338 |
339 | # BeatPulse healthcheck temp database
340 | healthchecksdb
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "FreeMote.Tlg"]
2 | path = FreeMote.Tlg
3 | url = https://github.com/lictex/FreeMote.Tlg
4 | branch = mod
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 lictex_
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # atri-composite
2 |
3 | windows x64 only
4 |
5 | [FreeMote.Tlg](https://github.com/UlyssesWu/FreeMote.Tlg) is used to load tlg images
6 |
7 | ----
8 |
9 | unpack the xp3 archive that contains standing images before using this
10 |
11 | keep unpacked files in the original xp3 directory structure or put them all in the root directory should be both ok
12 | but the filename from the xp3 is somewhat important and must not be changed
13 |
--------------------------------------------------------------------------------
/atri-composite.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.4.33103.184
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "atri-composite", "atri-composite\atri-composite.csproj", "{1B64071D-CEAA-439B-975C-C27364699998}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TlgLib", "FreeMote.Tlg\TlgLib\TlgLib.vcxproj", "{DF6C7BC2-3D99-4AE8-86E5-087BA766A3A8}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Debug|x64 = Debug|x64
14 | Debug|x86 = Debug|x86
15 | Release|Any CPU = Release|Any CPU
16 | Release|x64 = Release|x64
17 | Release|x86 = Release|x86
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {1B64071D-CEAA-439B-975C-C27364699998}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {1B64071D-CEAA-439B-975C-C27364699998}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {1B64071D-CEAA-439B-975C-C27364699998}.Debug|x64.ActiveCfg = Debug|Any CPU
23 | {1B64071D-CEAA-439B-975C-C27364699998}.Debug|x64.Build.0 = Debug|Any CPU
24 | {1B64071D-CEAA-439B-975C-C27364699998}.Debug|x86.ActiveCfg = Debug|Any CPU
25 | {1B64071D-CEAA-439B-975C-C27364699998}.Debug|x86.Build.0 = Debug|Any CPU
26 | {1B64071D-CEAA-439B-975C-C27364699998}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {1B64071D-CEAA-439B-975C-C27364699998}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {1B64071D-CEAA-439B-975C-C27364699998}.Release|x64.ActiveCfg = Release|Any CPU
29 | {1B64071D-CEAA-439B-975C-C27364699998}.Release|x64.Build.0 = Release|Any CPU
30 | {1B64071D-CEAA-439B-975C-C27364699998}.Release|x86.ActiveCfg = Release|Any CPU
31 | {1B64071D-CEAA-439B-975C-C27364699998}.Release|x86.Build.0 = Release|Any CPU
32 | {DF6C7BC2-3D99-4AE8-86E5-087BA766A3A8}.Debug|Any CPU.ActiveCfg = Debug|x64
33 | {DF6C7BC2-3D99-4AE8-86E5-087BA766A3A8}.Debug|Any CPU.Build.0 = Debug|x64
34 | {DF6C7BC2-3D99-4AE8-86E5-087BA766A3A8}.Debug|x64.ActiveCfg = Debug|x64
35 | {DF6C7BC2-3D99-4AE8-86E5-087BA766A3A8}.Debug|x64.Build.0 = Debug|x64
36 | {DF6C7BC2-3D99-4AE8-86E5-087BA766A3A8}.Debug|x86.ActiveCfg = Debug|Win32
37 | {DF6C7BC2-3D99-4AE8-86E5-087BA766A3A8}.Debug|x86.Build.0 = Debug|Win32
38 | {DF6C7BC2-3D99-4AE8-86E5-087BA766A3A8}.Release|Any CPU.ActiveCfg = Release|x64
39 | {DF6C7BC2-3D99-4AE8-86E5-087BA766A3A8}.Release|Any CPU.Build.0 = Release|x64
40 | {DF6C7BC2-3D99-4AE8-86E5-087BA766A3A8}.Release|x64.ActiveCfg = Release|x64
41 | {DF6C7BC2-3D99-4AE8-86E5-087BA766A3A8}.Release|x64.Build.0 = Release|x64
42 | {DF6C7BC2-3D99-4AE8-86E5-087BA766A3A8}.Release|x86.ActiveCfg = Release|Win32
43 | {DF6C7BC2-3D99-4AE8-86E5-087BA766A3A8}.Release|x86.Build.0 = Release|Win32
44 | EndGlobalSection
45 | GlobalSection(SolutionProperties) = preSolution
46 | HideSolutionNode = FALSE
47 | EndGlobalSection
48 | GlobalSection(ExtensibilityGlobals) = postSolution
49 | SolutionGuid = {B8F5E19C-9755-4FB2-B825-041E66B8FB6B}
50 | EndGlobalSection
51 | EndGlobal
52 |
--------------------------------------------------------------------------------
/atri-composite/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/atri-composite/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/atri-composite/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace atri_composite
10 | {
11 | ///
12 | /// App.xaml 的交互逻辑
13 | ///
14 | public partial class App : Application
15 | {
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/atri-composite/BatchExporter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Windows.Media.Imaging;
6 |
7 | namespace atri_composite
8 | {
9 | internal class BatchExporter
10 | {
11 | internal struct Limitation
12 | {
13 | public Character Character;
14 | public Character.Pose Pose;
15 | public string Size;
16 | public Character.Pose.Dress Dress;
17 | public Character.Pose.Dress.Addition Addition;
18 | }
19 |
20 | List Characters { get; }
21 |
22 | string WorkingDirectory { get; }
23 |
24 | string TargetDirectory { get; }
25 |
26 | public BatchExporter(List characters, string workingDirectory, string targetDirectory)
27 | {
28 | Characters = characters;
29 | WorkingDirectory = workingDirectory;
30 | TargetDirectory = targetDirectory;
31 | }
32 |
33 | public int Run(Limitation limit)
34 | {
35 | var errors = EnumerateVariants(limit).AsParallel().WithDegreeOfParallelism(Environment.ProcessorCount * 4).Select(_ =>
36 | {
37 | var (character, pose, dress, size, preset, addition) = _;
38 | var pbdPath = Path.Combine(WorkingDirectory, character.Name, $"{pose.Name}_{size}.pbd");
39 |
40 | // also allow images to be placed in the data root
41 | if (!File.Exists(pbdPath))
42 | {
43 | pbdPath = Path.Combine(Directory.GetParent(Path.GetDirectoryName(pbdPath)).FullName, Path.GetFileName(pbdPath));
44 | }
45 |
46 | var image = new CompoundImage(pbdPath);
47 | var layers = new List();
48 | layers.Add(dress.LayerPath);
49 | layers.Add(addition.LayerPath);
50 | layers.AddRange(preset.Items.Reverse().Select(o => o.Value.LayerPath));
51 |
52 | BitmapSource result;
53 | try
54 | {
55 | result = image.Generate(layers.ToArray()).Crop(true).ToBitmapSource(true);
56 | }
57 | catch (Exception e)
58 | {
59 | return $"{character}_{pose}_{dress}_{size}_{preset}_{addition}: {e.Message}";
60 | }
61 |
62 | var encoder = new PngBitmapEncoder();
63 | encoder.Frames.Add(BitmapFrame.Create(result));
64 | using (var file = File.Create(Path.Combine(TargetDirectory, $"{character}_{pose}_{size}_{dress}_{addition}_{preset}.png")))
65 | encoder.Save(file);
66 | return null;
67 | }).Where(o => o != null).ToList();
68 |
69 | if (errors.Count > 0)
70 | {
71 | using (var file = File.CreateText(Path.Combine(TargetDirectory, $"failed.log")))
72 | errors.ForEach(o => file.WriteLine(o));
73 | }
74 |
75 | return errors.Count;
76 | }
77 |
78 | public IEnumerable<(Character, Character.Pose, Character.Pose.Dress, string, Character.Pose.Preset, Character.Pose.Dress.Addition)> EnumerateVariants(Limitation limit) =>
79 | (limit.Character != null ? new List() { limit.Character } : Characters).SelectMany(character =>
80 | (limit.Pose != null ? new List() { limit.Pose } : character.Poses).SelectMany(pose =>
81 | {
82 | var dresses = limit.Dress != null || limit.Addition != null ? new List() { limit.Dress } : pose.Dresses;
83 | var sizes = limit.Size != null ? new List() { limit.Size } : pose.Sizes;
84 | var presets = pose.Presets;
85 | return dresses.SelectMany(dress =>
86 | sizes.SelectMany(size =>
87 | presets.SelectMany(preset =>
88 | (limit.Addition != null ? new List() { limit.Addition } : dress.Additions).Select(addition =>
89 | (character, pose, dress, size, preset, addition)
90 | ))));
91 | }));
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/atri-composite/Character.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace atri_composite
4 | {
5 | public class Character
6 | {
7 | public string Name { get; set; }
8 |
9 | public List Poses { get; } = new List();
10 |
11 | public override string ToString() => Name;
12 |
13 | public class Pose
14 | {
15 | public string Name { get; set; }
16 |
17 | public List FaceComponents { get; } = new List();
18 |
19 | public List Dresses { get; } = new List();
20 |
21 | public List Presets { get; } = new List();
22 |
23 | public List Sizes { get; } = new List();
24 |
25 | public override string ToString() => Name;
26 |
27 | public class FaceComponent
28 | {
29 | public string Name { get; set; }
30 |
31 | public List Variants { get; } = new List();
32 |
33 | public override string ToString() => Name;
34 |
35 | public class Variant
36 | {
37 | public string Name { get; set; }
38 |
39 | public string LayerPath { get; set; }
40 |
41 | public override string ToString() => Name;
42 | }
43 | }
44 |
45 | public class Dress
46 | {
47 | public string Name { get; set; }
48 |
49 | public string LayerPath { get; set; } = "dummy";
50 |
51 | public List Additions { get; } = new List();
52 |
53 | public override string ToString() => Name;
54 |
55 | public class Addition
56 | {
57 | public string Name { get; set; }
58 |
59 | public string LayerPath { get; set; }
60 |
61 | public override string ToString() => Name;
62 | }
63 | }
64 |
65 | public class Preset
66 | {
67 | public string Name { get; set; }
68 |
69 | public KeyValuePair[] Items { get; set; }
70 |
71 | public override string ToString() => Name;
72 | }
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/atri-composite/CharacterProcessor.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.IO;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Text.RegularExpressions;
6 |
7 | namespace atri_composite
8 | {
9 | public class CharacterProcessor
10 | {
11 | public static List Load(string fgimageDir)
12 | {
13 | var characters = new List();
14 | var standFiles = Directory.GetFiles(fgimageDir, "*.stand");
15 | foreach (var file in standFiles)
16 | {
17 | var character = new Character() { Name = Path.GetFileNameWithoutExtension(file) };
18 | var rtxt = Regex.Matches(File.ReadAllText(file, Encoding.Unicode), "\"filename\"=>\"[a-zA-Z0-9]+\"");
19 | foreach (Match match in rtxt)
20 | {
21 | var m = match.Value;
22 | var name = m.Substring(13, m.Length - 14);
23 |
24 | var pose = ProcessStandInfo(Path.Combine(fgimageDir, name + ".sinfo"));
25 | pose.Sizes.AddRange(GetSizes(Path.Combine(fgimageDir, Path.GetFileNameWithoutExtension(file)), name));
26 | pose.Name = name;
27 | character.Poses.Add(pose);
28 | }
29 | characters.Add(character);
30 | }
31 | return characters;
32 | }
33 |
34 | private static Character.Pose ProcessStandInfo(string sInfoPath)
35 | {
36 | var sInfo = File.ReadAllText(sInfoPath);
37 | var pose = new Character.Pose();
38 |
39 | sInfo.Split('\n').Select(o => o.Trim()).ToList().ForEach(expression =>
40 | {
41 | var blocks = expression.Split('\t').Select(p => p.Trim()).ToList();
42 |
43 | var paramIndex = 0;
44 | switch (blocks[paramIndex++])
45 | {
46 | case "dress":
47 | var dressName = blocks[paramIndex++];
48 | if (!pose.Dresses.Exists(o => o.Name == dressName)) pose.Dresses.Add(new Character.Pose.Dress() { Name = dressName });
49 | var dress = pose.Dresses.First(o => o.Name == dressName);
50 | switch (blocks[paramIndex++])
51 | {
52 | case "base":
53 | dress.LayerPath = blocks[paramIndex++];
54 | break;
55 | case "diff":
56 | dress.Additions.Add(new Character.Pose.Dress.Addition() { Name = blocks[paramIndex++], LayerPath = blocks[paramIndex++] });
57 | break;
58 | }
59 | break;
60 | case "facegroup":
61 | pose.FaceComponents.Add(new Character.Pose.FaceComponent() { Name = blocks[paramIndex++] });
62 | break;
63 | case "fgname":
64 | var fgname = blocks[paramIndex++];
65 | pose.FaceComponents.First(y => fgname.StartsWith(y.Name)).Variants.Add(new Character.Pose.FaceComponent.Variant() { Name = fgname, LayerPath = blocks[paramIndex++] });
66 | break;
67 | case "fgalias":
68 | var fgalias = blocks[paramIndex++];
69 | var items = new List>();
70 | do
71 | {
72 | var k = blocks[paramIndex++]; var v = pose.FaceComponents.FirstOrDefault(p => k.StartsWith(p.Name))?.Variants.FirstOrDefault(p => p.Name == k);
73 |
74 | // seems that ginka contains some invalid facegroup refs
75 | if (v != null)
76 | {
77 | items.Add(new KeyValuePair(k, v));
78 | }
79 | else
80 | {
81 | System.Diagnostics.Trace.TraceWarning($"unknown facegroup: {k}");
82 | }
83 | }
84 | while (paramIndex < blocks.Count);
85 | pose.Presets.Add(new Character.Pose.Preset() { Name = fgalias, Items = items.ToArray() });
86 | break;
87 | }
88 | });
89 | return pose;
90 | }
91 |
92 | private static List GetSizes(string dir, string name)
93 | {
94 | var result = new List();
95 | if (Directory.Exists(dir))
96 | {
97 | result.AddRange(Directory.GetFiles(dir)
98 | .Select(o => Path.GetFileName(o))
99 | .Where(o => Regex.IsMatch(o, $@"{name}_[a-zA-Z0-9]+.pbd$"))
100 | .Select(o => o.Substring(name.Length + 1, o.Length - name.Length - 5))
101 | );
102 | }
103 |
104 | // also allow images to be placed in the data root
105 | result.AddRange(Directory.GetFiles(Directory.GetParent(dir).FullName)
106 | .Select(o => Path.GetFileName(o))
107 | .Where(o => Regex.IsMatch(o, $@"{name}_[a-zA-Z0-9]+.pbd$"))
108 | .Select(o => o.Substring(name.Length + 1, o.Length - name.Length - 5))
109 | );
110 |
111 | return result;
112 | }
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/atri-composite/CompoundImage.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Drawing;
5 | using System.IO;
6 | using System.Linq;
7 |
8 | namespace atri_composite
9 | {
10 | class CompoundImage
11 | {
12 | public List Layers { get; }
13 |
14 | public int Width { get; }
15 |
16 | public int Height { get; }
17 |
18 | public string Name { get; }
19 |
20 | public CompoundImage(string descPath)
21 | {
22 | Name = Path.GetFileNameWithoutExtension(descPath);
23 | var imagePrefix = Path.GetFullPath(descPath);
24 | imagePrefix = imagePrefix.Substring(0, imagePrefix.Length - 4) + "_";
25 |
26 | var jArr = Utils.LoadPBDFile(descPath, true);
27 |
28 | int i = 0;
29 | Width = (int)jArr[i]["width"];
30 | Height = (int)jArr[i]["height"];
31 |
32 | var flatLayers = new List();
33 | for (i++; i < jArr.Count; i++)
34 | {
35 | Layer item = jArr[i].ToObject();
36 | item.Path = imagePrefix + item.LayerID;
37 | if (File.Exists(item.Path + ".png"))
38 | {
39 | item.Path = imagePrefix + item.LayerID + ".png";
40 | }
41 | else
42 | {
43 | item.Path = imagePrefix + item.LayerID + ".tlg";
44 | }
45 | flatLayers.Add(item);
46 | }
47 |
48 | flatLayers.Where(o => o.GroupLayerID != 0).ToList().ForEach(o => flatLayers.First(p => p.LayerID == o.GroupLayerID).Children.Add(o));
49 |
50 | Layers = flatLayers.Where(o => o.GroupLayerID == 0).ToList();
51 | }
52 |
53 | public Layer GetLayer(string query)
54 | {
55 | try
56 | {
57 | var blocks = query.Split('/');
58 | Layer prev;
59 | if (blocks.Length > 1) prev = Layers.First(o => o.LayerType == LayerType.Folder && o.Name == blocks[0]);
60 | else return Layers.First(o => o.LayerType == LayerType.Normal && o.Name == blocks[0]);
61 | for (var i = 1; i < blocks.Length - 1; i++) prev = prev.Children.First(o => o.LayerType == LayerType.Folder && o.Name == blocks[i]);
62 | return prev.Children.First(o => o.LayerType == LayerType.Normal && o.Name == blocks.Last());
63 | }
64 | catch { return null; }
65 | }
66 |
67 | public Bitmap Generate(params string[] layers)
68 | {
69 | var bitmap = new Bitmap(Width, Height);
70 | foreach (var s in layers)
71 | {
72 | if (s == "dummy") continue;
73 | var layer = GetLayer(s);
74 | if (layer == null) throw new ArgumentException();
75 | if (layer.Type != KrBlendMode.ltPsNormal) throw new NotSupportedException();
76 |
77 | Bitmap layerBitmap;
78 | FreeMote.Tlg.TlgLoader tlgLoader = null;
79 | if (layer.Path.EndsWith(".png"))
80 | {
81 | layerBitmap = new Bitmap(layer.Path);
82 | }
83 | else
84 | {
85 | tlgLoader = new FreeMote.Tlg.TlgLoader(File.ReadAllBytes(layer.Path));
86 | layerBitmap = tlgLoader.Bitmap;
87 | }
88 | using (var g = Graphics.FromImage(bitmap))
89 | g.DrawImage(layerBitmap, layer.Left, layer.Top, layer.Width, layer.Height);
90 | layerBitmap.Dispose();
91 | tlgLoader?.Dispose();
92 | }
93 | return bitmap;
94 | }
95 |
96 | public enum KrBlendMode
97 | {
98 | ltBinder = 0,
99 | ltCoverRect = 1,
100 | ltOpaque = 1, // the same as ltCoverRect
101 | ltTransparent = 2, // alpha blend
102 | ltAlpha = 2, // the same as ltTransparent
103 | ltAdditive = 3,
104 | ltSubtractive = 4,
105 | ltMultiplicative = 5,
106 | ltEffect = 6,
107 | ltFilter = 7,
108 | ltDodge = 8,
109 | ltDarken = 9,
110 | ltLighten = 10,
111 | ltScreen = 11,
112 | ltAddAlpha = 12, // additive alpha blend
113 | ltPsNormal = 13,
114 | ltPsAdditive = 14,
115 | ltPsSubtractive = 15,
116 | ltPsMultiplicative = 16,
117 | ltPsScreen = 17,
118 | ltPsOverlay = 18,
119 | ltPsHardLight = 19,
120 | ltPsSoftLight = 20,
121 | ltPsColorDodge = 21,
122 | ltPsColorDodge5 = 22,
123 | ltPsColorBurn = 23,
124 | ltPsLighten = 24,
125 | ltPsDarken = 25,
126 | ltPsDifference = 26,
127 | ltPsDifference5 = 27,
128 | ltPsExclusion = 28
129 | }
130 |
131 | public enum LayerType
132 | {
133 | Normal = 0,
134 | Hidden = 1,
135 | Folder = 2,
136 | Adjust = 3,
137 | Fill = 4
138 | }
139 |
140 | public class Layer
141 | {
142 | public string Path { get; set; }
143 |
144 | [JsonProperty("name")]
145 | public string Name { get; set; }
146 |
147 | [JsonProperty("type")]
148 | public KrBlendMode Type { get; set; }
149 |
150 | [JsonProperty("layer_type")]
151 | public LayerType LayerType { get; set; }
152 |
153 | [JsonProperty("layer_id")]
154 | public int LayerID { get; set; }
155 |
156 | [JsonProperty("group_layer_id")]
157 | public int GroupLayerID { get; set; } = 0;
158 |
159 | [JsonProperty("width")]
160 | public int Width { get; set; }
161 |
162 | [JsonProperty("height")]
163 | public int Height { get; set; }
164 |
165 | [JsonProperty("left")]
166 | public int Left { get; set; }
167 |
168 | [JsonProperty("top")]
169 | public int Top { get; set; }
170 |
171 | [JsonProperty("visible")]
172 | public int Visible { get; set; }
173 |
174 | [JsonProperty("opacity")]
175 | public int Opacity { get; set; }
176 |
177 | public List Children { get; } = new List();
178 | }
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/atri-composite/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
96 |
97 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/atri-composite/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.WindowsAPICodePack.Dialogs;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.ComponentModel;
5 | using System.Globalization;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Runtime.CompilerServices;
9 | using System.Windows;
10 | using System.Windows.Controls;
11 | using System.Windows.Controls.Primitives;
12 | using System.Windows.Data;
13 | using System.Windows.Media.Imaging;
14 |
15 | namespace atri_composite
16 | {
17 | ///
18 | /// MainWindow.xaml 的交互逻辑
19 | ///
20 | public partial class MainWindow : Window, INotifyPropertyChanged
21 | {
22 | public event PropertyChangedEventHandler PropertyChanged;
23 | private void OnPropertyChanged(object _ = null, [CallerMemberName] string name = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
24 |
25 | private BitmapSource _image;
26 | public BitmapSource Image
27 | {
28 | get => _image; set
29 | {
30 | OnPropertyChanged(_image = value);
31 | OnPropertyChanged(null, "ImageSize");
32 | GC.Collect();
33 | }
34 | }
35 | public string ImageSize => Image == null ? "" : $"{Image.PixelWidth}x{Image.PixelHeight}";
36 |
37 | private bool PauseGenerate { get; set; } = false;
38 |
39 | private List _characters;
40 | public List Characters { get => _characters; set => OnPropertyChanged(_characters = value); }
41 |
42 | private Character _selectedCharacter;
43 | public Character SelectedCharacter { get => _selectedCharacter; set => OnPropertyChanged(_selectedCharacter = value); }
44 |
45 | private Character.Pose _selectedPose;
46 | public Character.Pose SelectedPose { get => _selectedPose; set => OnPropertyChanged(_selectedPose = value); }
47 |
48 | private Character.Pose.Dress _selectedDress;
49 | public Character.Pose.Dress SelectedDress { get => _selectedDress; set => OnPropertyChanged(_selectedDress = value); }
50 |
51 | private Character.Pose.Dress.Addition _selectedAddition;
52 | public Character.Pose.Dress.Addition SelectedAddition { get => _selectedAddition; set => OnPropertyChanged(_selectedAddition = value); }
53 |
54 | private string _selectedSize;
55 | public string SelectedSize { get => _selectedSize; set => OnPropertyChanged(_selectedSize = value); }
56 |
57 | private Character.Pose.FaceComponent.Variant[] _selectedFaceComponents;
58 | public Character.Pose.FaceComponent.Variant[] SelectedFaceComponents { get => _selectedFaceComponents; set => OnPropertyChanged(_selectedFaceComponents = value); }
59 |
60 | private string WorkingDirectory { get; }
61 |
62 | public MainWindow()
63 | {
64 | var dialog = new CommonOpenFileDialog()
65 | {
66 | Title = "Locate the fgimage folder",
67 | DefaultDirectory = Environment.CurrentDirectory,
68 | IsFolderPicker = true,
69 | EnsureFileExists = true,
70 | EnsurePathExists = true,
71 | EnsureValidNames = true
72 | };
73 | if (dialog.ShowDialog() != CommonFileDialogResult.Ok) Environment.Exit(0);
74 |
75 | WorkingDirectory = dialog.FileName;
76 | Characters = CharacterProcessor.Load(WorkingDirectory);
77 |
78 | InitializeComponent();
79 | }
80 |
81 | private void ReloadFaceComponents()
82 | {
83 | extraConfigPanel.Children.Clear();
84 | SelectedFaceComponents = null;
85 |
86 | if (SelectedPose == null) return;
87 | SelectedFaceComponents = new Character.Pose.FaceComponent.Variant[SelectedPose.FaceComponents.Count];
88 |
89 | for (int i = 0; i < SelectedPose.FaceComponents.Count; i++)
90 | {
91 | var component = SelectedPose.FaceComponents[i];
92 | var panel = new DockPanel();
93 |
94 | panel.Children.Add(new Label() { Content = component.Name, Width = 70 });
95 |
96 | ComboBox comboBox = new ComboBox()
97 | {
98 | ItemsSource = component.Variants,
99 | VerticalAlignment = VerticalAlignment.Center
100 | };
101 | comboBox.SetBinding(Selector.SelectedItemProperty, new Binding()
102 | {
103 | Path = new PropertyPath($"SelectedFaceComponents[{i}]"),
104 | Source = this,
105 | Mode = BindingMode.TwoWay
106 | });
107 | comboBox.SelectionChanged += OnSelectionChanged;
108 | comboBox.SelectedIndex = 0;
109 | panel.Children.Add(comboBox);
110 |
111 | extraConfigPanel.Children.Add(panel);
112 | }
113 | }
114 |
115 | private void TryBuildImage()
116 | {
117 | if (SelectedCharacter != null && SelectedPose != null && SelectedDress != null && SelectedAddition != null && SelectedSize != null && SelectedFaceComponents != null && !PauseGenerate)
118 | {
119 | var pbdPath = Path.Combine(WorkingDirectory, SelectedCharacter.Name, $"{SelectedPose.Name}_{SelectedSize}.pbd");
120 |
121 | // also allow images to be placed in the data root
122 | if (!File.Exists(pbdPath))
123 | {
124 | pbdPath = Path.Combine(Directory.GetParent(Path.GetDirectoryName(pbdPath)).FullName, Path.GetFileName(pbdPath));
125 | }
126 |
127 | var image = new CompoundImage(pbdPath);
128 | var layers = new List();
129 | layers.Add(SelectedDress.LayerPath);
130 | layers.Add(SelectedAddition.LayerPath);
131 | layers.AddRange(SelectedFaceComponents.Reverse().Select(o => o.LayerPath));
132 |
133 | try
134 | {
135 | Image = image.Generate(layers.ToArray()).Crop(true).ToBitmapSource(true);
136 | }
137 | catch (Exception e)
138 | {
139 | MessageBox.Show(e.Message);
140 | System.Diagnostics.Trace.TraceError(e.Message);
141 | Image = null;
142 | }
143 | }
144 | else Image = null;
145 | }
146 |
147 | private void OnPoseSelectionChanged(object sender, SelectionChangedEventArgs e)
148 | {
149 | ReloadFaceComponents();
150 | TryBuildImage();
151 | }
152 |
153 | private void OnSelectionChanged(object sender, SelectionChangedEventArgs e) => TryBuildImage();
154 |
155 | private void OnFaceSelectionChanged(object sender, SelectionChangedEventArgs e)
156 | {
157 | var key = (sender as ComboBox).SelectedItem;
158 | if (key == null) return;
159 |
160 | PauseGenerate = true;
161 | foreach (var o in SelectedPose.Presets.First(o => o.Name == key.ToString()).Items)
162 | {
163 | var fGroup = SelectedPose.FaceComponents.First(p => o.Key.StartsWith(p.Name));
164 | SelectedFaceComponents[SelectedPose.FaceComponents.IndexOf(fGroup)] = o.Value;
165 | }
166 | SelectedFaceComponents = SelectedFaceComponents;
167 | PauseGenerate = false;
168 |
169 | TryBuildImage();
170 | }
171 |
172 | private void OnExportClick(object sender, RoutedEventArgs e)
173 | {
174 | var dialog = new CommonSaveFileDialog()
175 | {
176 | Title = "Export",
177 | DefaultDirectory = Environment.CurrentDirectory,
178 | EnsurePathExists = true,
179 | EnsureValidNames = true,
180 | DefaultExtension = "png",
181 | AlwaysAppendDefaultExtension = true
182 | };
183 | dialog.Filters.Add(new CommonFileDialogFilter("PNG Image", ".png"));
184 | if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
185 | {
186 | var encoder = new PngBitmapEncoder();
187 | encoder.Frames.Add(BitmapFrame.Create(Image));
188 | using (var file = File.Create(dialog.FileName)) encoder.Save(file);
189 | }
190 | }
191 |
192 | private void OnExtraMenuClick(object sender, RoutedEventArgs e)
193 | {
194 | var button = sender as Button;
195 | ContextMenu contextMenu = button.ContextMenu;
196 | contextMenu.PlacementTarget = button;
197 | contextMenu.IsOpen = true;
198 | e.Handled = true;
199 | }
200 |
201 | private void OnBatchExportClick(object sender, RoutedEventArgs e)
202 | {
203 | var dialog = new CommonOpenFileDialog()
204 | {
205 | Title = "Locate the target folder",
206 | DefaultDirectory = Environment.CurrentDirectory,
207 | IsFolderPicker = true,
208 | EnsureFileExists = true,
209 | EnsurePathExists = true,
210 | EnsureValidNames = true
211 | };
212 | if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
213 | {
214 | var limits = new BatchExporter.Limitation();
215 | foreach (var p in ((sender as FrameworkElement).Tag as string ?? "").Split(',')) switch (p)
216 | {
217 | case "Character": limits.Character = SelectedCharacter; break;
218 | case "Pose": limits.Pose = SelectedPose; break;
219 | case "Size": limits.Size = SelectedSize; break;
220 | case "Dress": limits.Dress = SelectedDress; break;
221 | case "Addition": limits.Addition = SelectedAddition; break;
222 | }
223 |
224 | var exporter = new BatchExporter(Characters, WorkingDirectory, dialog.FileName);
225 | var count = exporter.EnumerateVariants(limits).Count();
226 | var result = MessageBox.Show($"{count} images will be saved to {dialog.FileName}.\nThis may take a long time!\nProceed?", "Notice", MessageBoxButton.YesNo);
227 | if (result == MessageBoxResult.Yes)
228 | {
229 | var errors = exporter.Run(limits);
230 | MessageBox.Show($"{count - errors} images saved. {errors} failed.", "Notice", MessageBoxButton.OK);
231 | }
232 | }
233 | }
234 | }
235 |
236 | public class ObjectNotNullConverter : IValueConverter
237 | {
238 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value != null;
239 |
240 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
241 | }
242 |
243 | public class ToStringConverter : IMultiValueConverter
244 | {
245 | public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
246 | {
247 | return string.Format(parameter as string, values);
248 | }
249 |
250 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
251 | {
252 | throw new NotImplementedException();
253 | }
254 | }
255 | }
256 |
--------------------------------------------------------------------------------
/atri-composite/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // 有关程序集的一般信息由以下
8 | // 控制。更改这些特性值可修改
9 | // 与程序集关联的信息。
10 | [assembly: AssemblyTitle("atri-composite")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("atri-composite")]
15 | [assembly: AssemblyCopyright("Copyright © lictex_")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // 将 ComVisible 设置为 false 会使此程序集中的类型
20 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
21 | //请将此类型的 ComVisible 特性设置为 true。
22 | [assembly: ComVisible(false)]
23 |
24 | //若要开始生成可本地化的应用程序,请设置
25 | //.csproj 文件中的 CultureYouAreCodingWith
26 | //例如,如果您在源文件中使用的是美国英语,
27 | //使用的是美国英语,请将 设置为 en-US。 然后取消
28 | //对以下 NeutralResourceLanguage 特性的注释。 更新
29 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置
36 | //(未在页面中找到资源时使用,
37 | //或应用程序资源字典中找到时使用)
38 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
39 | //(未在页面中找到资源时使用,
40 | //、应用程序或任何主题专用资源字典中找到时使用)
41 | )]
42 |
43 |
44 | // 程序集的版本信息由下列四个值组成:
45 | //
46 | // 主版本
47 | // 次版本
48 | // 生成号
49 | // 修订号
50 | //
51 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
52 | //通过使用 "*",如下所示:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.4.0")]
55 |
--------------------------------------------------------------------------------
/atri-composite/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本: 4.0.30319.42000
5 | //
6 | // 对此文件的更改可能导致不正确的行为,如果
7 | // 重新生成代码,则所做更改将丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace atri_composite.Properties
12 | {
13 |
14 |
15 | ///
16 | /// 强类型资源类,用于查找本地化字符串等。
17 | ///
18 | // 此类是由 StronglyTypedResourceBuilder
19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20 | // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21 | // (以 /str 作为命令选项),或重新生成 VS 项目。
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// 返回此类使用的缓存 ResourceManager 实例。
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("atri_composite.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// 覆盖当前线程的 CurrentUICulture 属性
56 | /// 使用此强类型的资源类的资源查找。
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/atri-composite/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/atri-composite/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace atri_composite.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/atri-composite/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/atri-composite/Utils.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json.Linq;
2 | using System;
3 | using System.Collections.Concurrent;
4 | using System.Diagnostics;
5 | using System.Drawing;
6 | using System.Drawing.Imaging;
7 | using System.IO;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 | using System.Windows.Media.Imaging;
11 |
12 | namespace atri_composite
13 | {
14 | public static class Utils
15 | {
16 | public static BitmapSource ToBitmapSource(this Bitmap bitmap, bool disposeSource = false)
17 | {
18 | IntPtr p = bitmap.GetHbitmap();
19 | try
20 | {
21 | return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
22 | p,
23 | IntPtr.Zero,
24 | System.Windows.Int32Rect.Empty,
25 | BitmapSizeOptions.FromWidthAndHeight(bitmap.Width, bitmap.Height));
26 | }
27 | finally
28 | {
29 | DeleteObject(p);
30 | if (disposeSource) try { bitmap.Dispose(); } catch { }
31 | }
32 | }
33 |
34 | public static Bitmap Crop(this Bitmap bitmap, bool disposeSource = false)
35 | {
36 | if (bitmap.PixelFormat != PixelFormat.Format32bppArgb) throw new NotSupportedException();
37 |
38 | var bitmapData = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.ReadOnly, bitmap.PixelFormat);
39 | var bpp = Image.GetPixelFormatSize(bitmapData.PixelFormat) / 8;
40 |
41 | unsafe byte AlphaAt(int x, int y) => *((byte*)bitmapData.Scan0 + bitmapData.Stride * y + bpp * x + 3);
42 |
43 | int l = -1, t = -1, r = -1, b = -1;
44 | Parallel.Invoke(() =>
45 | {
46 | for (var ln = 0; ln < bitmapData.Width; ln++)
47 | for (var s = 0; s < bitmapData.Height; s++)
48 | if (AlphaAt(ln, s) != 0) { l = ln; return; }
49 | }, () =>
50 | {
51 | for (var ln = 0; ln < bitmapData.Height; ln++)
52 | for (var s = 0; s < bitmapData.Width; s++)
53 | if (AlphaAt(s, ln) != 0) { t = ln; return; }
54 | }, () =>
55 | {
56 | for (var ln = 0; ln < bitmapData.Width; ln++)
57 | for (var s = 0; s < bitmapData.Height; s++)
58 | if (AlphaAt(bitmapData.Width - 1 - ln, s) != 0) { r = ln; return; }
59 | }, () =>
60 | {
61 | for (var ln = 0; ln < bitmapData.Height; ln++)
62 | for (var s = 0; s < bitmapData.Width; s++)
63 | if (AlphaAt(s, bitmapData.Height - 1 - ln) != 0) { b = ln; return; }
64 | });
65 |
66 | bitmap.UnlockBits(bitmapData);
67 |
68 | if (l < 0 || t < 0 || r < 0 || b < 0) throw new ArgumentException();
69 |
70 | var cropBound = new Rectangle(l, t, bitmap.Width - l - r, bitmap.Height - t - b);
71 | var newBitmap = new Bitmap(cropBound.Width, cropBound.Height);
72 | using (var g = Graphics.FromImage(newBitmap)) g.DrawImage(bitmap, new Rectangle(Point.Empty, newBitmap.Size), cropBound, GraphicsUnit.Pixel);
73 |
74 | if (disposeSource) try { bitmap.Dispose(); } catch { }
75 | return newBitmap;
76 | }
77 |
78 | private static readonly ConcurrentDictionary pbdCache = new ConcurrentDictionary();
79 | public static JArray LoadPBDFile(string pbdPath, bool normalize = false)
80 | {
81 | // also allow stands to be placed in the data root
82 | if (!File.Exists(pbdPath))
83 | {
84 | pbdPath = Path.Combine(Directory.GetParent(Path.GetDirectoryName(pbdPath)).FullName, Path.GetFileName(pbdPath));
85 | }
86 |
87 | return pbdCache.GetOrAdd(pbdPath, o =>
88 | {
89 | var proc = Process.Start(new ProcessStartInfo()
90 | {
91 | FileName = "pbd2json.exe",
92 | Arguments = $"\"{pbdPath}\"",
93 | UseShellExecute = false,
94 | RedirectStandardOutput = true,
95 | CreateNoWindow = true
96 | });
97 | var json = proc.StandardOutput.ReadToEnd();
98 | proc.WaitForExit();
99 | return JArray.Parse(normalize ? json.Normalize(NormalizationForm.FormKC) : json);
100 | });
101 | }
102 |
103 | [System.Runtime.InteropServices.DllImport("gdi32.dll")]
104 | private static extern bool DeleteObject(IntPtr hObject);
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/atri-composite/atri-composite.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {1B64071D-CEAA-439B-975C-C27364699998}
8 | WinExe
9 | atri_composite
10 | atri-composite
11 | v4.7.2
12 | 512
13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 4
15 | true
16 | true
17 | publish\
18 | true
19 | Disk
20 | false
21 | Foreground
22 | 7
23 | Days
24 | false
25 | false
26 | true
27 | 0
28 | 1.0.0.%2a
29 | false
30 | false
31 | true
32 |
33 |
34 | x64
35 | true
36 | full
37 | false
38 | bin\Debug\
39 | DEBUG;TRACE
40 | prompt
41 | 4
42 | true
43 |
44 |
45 | x64
46 | pdbonly
47 | true
48 | bin\Release\
49 | TRACE
50 | prompt
51 | 4
52 | true
53 |
54 |
55 | icon.ico
56 |
57 |
58 |
59 | ..\packages\Microsoft.WindowsAPICodePack-Core.1.1.0.0\lib\Microsoft.WindowsAPICodePack.dll
60 |
61 |
62 | ..\packages\Microsoft.WindowsAPICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.Shell.dll
63 |
64 |
65 | ..\packages\Microsoft.WindowsAPICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.ShellExtensions.dll
66 |
67 |
68 | ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | 4.0
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | MSBuild:Compile
89 | Designer
90 |
91 |
92 |
93 |
94 |
95 |
96 | MSBuild:Compile
97 | Designer
98 |
99 |
100 | App.xaml
101 | Code
102 |
103 |
104 |
105 | MainWindow.xaml
106 | Code
107 |
108 |
109 |
110 |
111 | Code
112 |
113 |
114 | True
115 | True
116 | Resources.resx
117 |
118 |
119 | True
120 | Settings.settings
121 | True
122 |
123 |
124 | ResXFileCodeGenerator
125 | Resources.Designer.cs
126 |
127 |
128 |
129 | SettingsSingleFileGenerator
130 | Settings.Designer.cs
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 | False
139 | Microsoft .NET Framework 4.7.2 %28x86 和 x64%29
140 | true
141 |
142 |
143 | False
144 | .NET Framework 3.5 SP1
145 | false
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 | {df6c7bc2-3d99-4ae8-86e5-087ba766a3a8}
154 | TlgLib
155 |
156 |
157 |
158 |
159 | xcopy /y "$(ProjectDir)pbd2json.exe" "$(TargetDir)"
160 |
161 |
--------------------------------------------------------------------------------
/atri-composite/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lictex/atri-composite/e5f68576aa1921307e0ec401909c70bc039c9e11/atri-composite/icon.ico
--------------------------------------------------------------------------------
/atri-composite/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/atri-composite/pbd2json.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lictex/atri-composite/e5f68576aa1921307e0ec401909c70bc039c9e11/atri-composite/pbd2json.exe
--------------------------------------------------------------------------------