├── src
├── IgnoredWords.dic
├── RIOTProxy
│ ├── version.rc
│ ├── packages.config
│ ├── resource.h
│ ├── RIOTProxy.vcxproj.filters
│ ├── RIOTProxy.cpp
│ └── RIOTProxy.vcxproj
├── Resources
│ ├── icons
│ │ ├── flame-120.png
│ │ ├── flame-144.png
│ │ ├── flame-192.png
│ │ ├── flame-384.png
│ │ └── flame-96.png
│ └── svg
│ │ ├── Readme.txt
│ │ └── flame.svg
├── Interop
│ ├── NativeConstants.cs
│ ├── SafeMemoryMappedFileHandle.cs
│ ├── SafeMemoryMappedFileView.cs
│ ├── NativeStructs.cs
│ └── SafeNativeMethods.cs
├── RIOTExportConfigToken.cs
├── PluginIconUtil.cs
├── PluginSupportInfo.cs
├── RIOTExportEffect.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── SaveForWebRIOT.sln
├── SaveForWebRIOT.csproj
├── RIOTExportConfigDialog.resx
├── .editorconfig
└── RIOTExportConfigDialog.cs
├── Readme.md
├── License.txt
├── .gitattributes
└── .gitignore
/src/IgnoredWords.dic:
--------------------------------------------------------------------------------
1 | config
2 | hwnd
3 | interop
4 | lpsz
5 | manifestdependency
6 | wil
--------------------------------------------------------------------------------
/src/RIOTProxy/version.rc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0xC0000054/pdn-riot/HEAD/src/RIOTProxy/version.rc
--------------------------------------------------------------------------------
/src/Resources/icons/flame-120.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0xC0000054/pdn-riot/HEAD/src/Resources/icons/flame-120.png
--------------------------------------------------------------------------------
/src/Resources/icons/flame-144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0xC0000054/pdn-riot/HEAD/src/Resources/icons/flame-144.png
--------------------------------------------------------------------------------
/src/Resources/icons/flame-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0xC0000054/pdn-riot/HEAD/src/Resources/icons/flame-192.png
--------------------------------------------------------------------------------
/src/Resources/icons/flame-384.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0xC0000054/pdn-riot/HEAD/src/Resources/icons/flame-384.png
--------------------------------------------------------------------------------
/src/Resources/icons/flame-96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/0xC0000054/pdn-riot/HEAD/src/Resources/icons/flame-96.png
--------------------------------------------------------------------------------
/src/Resources/svg/Readme.txt:
--------------------------------------------------------------------------------
1 | flame.svg: https://uxwing.com/flame-icon/, licensed as free to use any personal and commercial projects without any attribution or credit https://uxwing.com/license/
--------------------------------------------------------------------------------
/src/RIOTProxy/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/RIOTProxy/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by version.rc
4 |
5 | // Next default values for new objects
6 | //
7 | #ifdef APSTUDIO_INVOKED
8 | #ifndef APSTUDIO_READONLY_SYMBOLS
9 | #define _APS_NEXT_RESOURCE_VALUE 101
10 | #define _APS_NEXT_COMMAND_VALUE 40001
11 | #define _APS_NEXT_CONTROL_VALUE 1001
12 | #define _APS_NEXT_SYMED_VALUE 101
13 | #endif
14 | #endif
15 |
--------------------------------------------------------------------------------
/src/Interop/NativeConstants.cs:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////////
2 | //
3 | // RIOT Save for Web Effect Plugin for Paint.NET
4 | //
5 | // This software is provided under the MIT License:
6 | // Copyright (C) 2016-2018, 2021, 2022, 2023, 2024 Nicholas Hayes
7 | //
8 | // See LICENSE.txt for complete licensing and attribution information.
9 | //
10 | /////////////////////////////////////////////////////////////////////////////////
11 |
12 | namespace SaveForWebRIOT.Interop
13 | {
14 | internal static class NativeConstants
15 | {
16 | internal const int BI_RGB = 0;
17 |
18 | internal const uint FILE_MAP_WRITE = 2;
19 |
20 | internal const int INVALID_HANDLE_VALUE = -1;
21 |
22 | internal const uint PAGE_READWRITE = 4;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Interop/SafeMemoryMappedFileHandle.cs:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////////
2 | //
3 | // RIOT Save for Web Effect Plugin for Paint.NET
4 | //
5 | // This software is provided under the MIT License:
6 | // Copyright (C) 2016-2018, 2021, 2022, 2023, 2024 Nicholas Hayes
7 | //
8 | // See LICENSE.txt for complete licensing and attribution information.
9 | //
10 | /////////////////////////////////////////////////////////////////////////////////
11 |
12 | using Microsoft.Win32.SafeHandles;
13 |
14 | namespace SaveForWebRIOT.Interop
15 | {
16 | internal sealed class SafeMemoryMappedFileHandle : SafeHandleZeroOrMinusOneIsInvalid
17 | {
18 | private SafeMemoryMappedFileHandle() : base(true)
19 | {
20 | }
21 |
22 | protected override bool ReleaseHandle() => SafeNativeMethods.CloseHandle(handle);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Interop/SafeMemoryMappedFileView.cs:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////////
2 | //
3 | // RIOT Save for Web Effect Plugin for Paint.NET
4 | //
5 | // This software is provided under the MIT License:
6 | // Copyright (C) 2016-2018, 2021, 2022, 2023, 2024 Nicholas Hayes
7 | //
8 | // See LICENSE.txt for complete licensing and attribution information.
9 | //
10 | /////////////////////////////////////////////////////////////////////////////////
11 |
12 | using Microsoft.Win32.SafeHandles;
13 |
14 | namespace SaveForWebRIOT.Interop
15 | {
16 | internal sealed class SafeMemoryMappedFileView : SafeHandleZeroOrMinusOneIsInvalid
17 | {
18 | private SafeMemoryMappedFileView() : base(true)
19 | {
20 | }
21 |
22 | protected override bool ReleaseHandle() => SafeNativeMethods.UnmapViewOfFile(handle);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/RIOTExportConfigToken.cs:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////////
2 | //
3 | // RIOT Save for Web Effect Plugin for Paint.NET
4 | //
5 | // This software is provided under the MIT License:
6 | // Copyright (C) 2016-2018, 2021, 2022, 2023, 2024 Nicholas Hayes
7 | //
8 | // See LICENSE.txt for complete licensing and attribution information.
9 | //
10 | /////////////////////////////////////////////////////////////////////////////////
11 |
12 | using PaintDotNet.Effects;
13 |
14 | namespace SaveForWebRIOT
15 | {
16 | public sealed class RIOTExportConfigToken : EffectConfigToken
17 | {
18 | public RIOTExportConfigToken()
19 | {
20 | }
21 |
22 | private RIOTExportConfigToken(RIOTExportConfigToken cloneMe)
23 | {
24 | }
25 |
26 | public override object Clone()
27 | {
28 | return new RIOTExportConfigToken(this);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Resources/svg/flame.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | # pdn-riot
2 |
3 | A [Paint.NET](http://www.getpaint.net) Effect plugin that exports the current layer using the [Radical Image Optimization Tool](http://luci.criosweb.ro/riot/).
4 |
5 | ## How to install the plugin
6 |
7 | 1. Exit Paint.NET.
8 | 2. Place the SaveForWebRIOT folder in the Paint.NET Effects folder which is usually located in one the following locations depending on the Paint.NET version you have installed.
9 |
10 | Paint.NET Version | Effects Folder Location
11 | --------|----------
12 | Classic | C:\Program Files\Paint.NET\Effects
13 | Microsoft Store | Documents\paint.net App Files\Effects
14 | Portable | \Effects
15 |
16 | 3. Restart Paint.NET.
17 | 4. The plug-in will now be available as the Save for Web with RIOT menu item in the Tools category of the Paint.NET Effects menu.
18 |
19 | ## License
20 |
21 | This project is licensed under the terms of the MIT License.
22 | See [License.txt](License.txt) for more information.
--------------------------------------------------------------------------------
/License.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016-2018, 2021, 2022, 2023, 2024 Nicholas Hayes
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.
--------------------------------------------------------------------------------
/src/Interop/NativeStructs.cs:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////////
2 | //
3 | // RIOT Save for Web Effect Plugin for Paint.NET
4 | //
5 | // This software is provided under the MIT License:
6 | // Copyright (C) 2016-2018, 2021, 2022, 2023, 2024 Nicholas Hayes
7 | //
8 | // See LICENSE.txt for complete licensing and attribution information.
9 | //
10 | /////////////////////////////////////////////////////////////////////////////////
11 |
12 | using System.Runtime.InteropServices;
13 |
14 | namespace SaveForWebRIOT.Interop
15 | {
16 | internal static class NativeStructs
17 | {
18 | [StructLayout(LayoutKind.Sequential)]
19 | internal struct BITMAPINFOHEADER
20 | {
21 | internal uint biSize;
22 | internal int biWidth;
23 | internal int biHeight;
24 | internal ushort biPlanes;
25 | internal ushort biBitCount;
26 | internal uint biCompression;
27 | internal uint biSizeImage;
28 | internal int biXPelsPerMeter;
29 | internal int biYPelsPerMeter;
30 | internal uint biClrUsed;
31 | internal uint biClrImportant;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/RIOTProxy/RIOTProxy.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 |
31 |
32 | Resource Files
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/PluginIconUtil.cs:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////////
2 | //
3 | // RIOT Save for Web Effect Plugin for Paint.NET
4 | //
5 | // This software is provided under the MIT License:
6 | // Copyright (C) 2016-2018, 2021, 2022, 2023, 2024 Nicholas Hayes
7 | //
8 | // See LICENSE.txt for complete licensing and attribution information.
9 | //
10 | /////////////////////////////////////////////////////////////////////////////////
11 |
12 | using System;
13 |
14 | namespace SaveForWebRIOT
15 | {
16 | internal static class PluginIconUtil
17 | {
18 | private static readonly ValueTuple[] AvailableIcons = new ValueTuple[]
19 | {
20 | (96, "Resources.icons.flame-96.png"),
21 | (120, "Resources.icons.flame-120.png"),
22 | (144, "Resources.icons.flame-144.png"),
23 | (192, "Resources.icons.flame-192.png"),
24 | (384, "Resources.icons.flame-384.png"),
25 | };
26 |
27 | internal static string GetIconResourceNameForDpi(int dpi)
28 | {
29 | for (int i = 0; i < AvailableIcons.Length; i++)
30 | {
31 | ValueTuple icon = AvailableIcons[i];
32 |
33 | if (icon.Item1 >= dpi)
34 | {
35 | return icon.Item2;
36 | }
37 | }
38 |
39 | return "Resources.Icons.flame-384.png";
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/PluginSupportInfo.cs:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////////
2 | //
3 | // RIOT Save for Web Effect Plugin for Paint.NET
4 | //
5 | // This software is provided under the MIT License:
6 | // Copyright (C) 2016-2018, 2021, 2022, 2023, 2024 Nicholas Hayes
7 | //
8 | // See LICENSE.txt for complete licensing and attribution information.
9 | //
10 | /////////////////////////////////////////////////////////////////////////////////
11 |
12 | using PaintDotNet;
13 | using System;
14 | using System.Reflection;
15 |
16 | namespace SaveForWebRIOT
17 | {
18 | public sealed class PluginSupportInfo : IPluginSupportInfo
19 | {
20 | public string Author
21 | {
22 | get
23 | {
24 | return "null54";
25 | }
26 | }
27 |
28 | public string Copyright
29 | {
30 | get
31 | {
32 | return ((AssemblyCopyrightAttribute)typeof(RIOTExportEffect).Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0]).Copyright;
33 | }
34 | }
35 |
36 | public string DisplayName
37 | {
38 | get
39 | {
40 | return RIOTExportEffect.StaticName;
41 | }
42 | }
43 |
44 | public Version Version
45 | {
46 | get
47 | {
48 | return typeof(RIOTExportEffect).Assembly.GetName().Version;
49 | }
50 | }
51 |
52 | public Uri WebsiteUri
53 | {
54 | get
55 | {
56 | return new Uri("https://forums.getpaint.net/topic/107365-save-for-web-with-riot-radical-image-optimization-tool/");
57 | }
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/RIOTExportEffect.cs:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////////
2 | //
3 | // RIOT Save for Web Effect Plugin for Paint.NET
4 | //
5 | // This software is provided under the MIT License:
6 | // Copyright (C) 2016-2018, 2021, 2022, 2023, 2024 Nicholas Hayes
7 | //
8 | // See LICENSE.txt for complete licensing and attribution information.
9 | //
10 | /////////////////////////////////////////////////////////////////////////////////
11 |
12 | using PaintDotNet;
13 | using PaintDotNet.Effects;
14 | using PaintDotNet.Imaging;
15 | using System.Drawing;
16 |
17 | namespace SaveForWebRIOT
18 | {
19 | [PluginSupportInfo(typeof(PluginSupportInfo))]
20 | public sealed class RIOTExportEffect : BitmapEffect
21 | {
22 | public static string StaticName
23 | {
24 | get
25 | {
26 | return "Save for Web with RIOT";
27 | }
28 | }
29 |
30 | public static Bitmap StaticIcon
31 | {
32 | get
33 | {
34 | return new Bitmap(typeof(RIOTExportEffect), PluginIconUtil.GetIconResourceNameForDpi(UIScaleFactor.Current.Dpi));
35 | }
36 | }
37 |
38 | public RIOTExportEffect() : base(StaticName, StaticIcon, "Tools", BitmapEffectOptions.Create() with { IsConfigurable = true })
39 | {
40 | }
41 |
42 | protected override IEffectConfigForm OnCreateConfigForm()
43 | {
44 | return new RIOTExportConfigDialog();
45 | }
46 |
47 | protected override unsafe void OnRender(IBitmapEffectOutput output)
48 | {
49 | using (IBitmapLock dst = output.LockBgra32())
50 | {
51 | Environment.GetSourceBitmapBgra32().CopyPixels(dst.Buffer, dst.BufferStride, dst.BufferSize, output.Bounds);
52 | }
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////////
2 | //
3 | // RIOT Save for Web Effect Plugin for Paint.NET
4 | //
5 | // This software is provided under the MIT License:
6 | // Copyright (C) 2016-2018, 2021, 2022, 2023, 2024 Nicholas Hayes
7 | //
8 | // See LICENSE.txt for complete licensing and attribution information.
9 | //
10 | /////////////////////////////////////////////////////////////////////////////////
11 |
12 | using System.Reflection;
13 | using System.Runtime.InteropServices;
14 | using System.Runtime.Versioning;
15 |
16 | // General Information about an assembly is controlled through the following
17 | // set of attributes. Change these attribute values to modify the information
18 | // associated with an assembly.
19 | [assembly: AssemblyTitle("RIOT Save for Web Effect for Paint.NET")]
20 | [assembly: AssemblyDescription("")]
21 | [assembly: AssemblyConfiguration("")]
22 | [assembly: AssemblyCompany("")]
23 | [assembly: AssemblyProduct("SaveForWebRIOT")]
24 | [assembly: AssemblyCopyright("Copyright © 2024 Nicholas Hayes (aka null54)")]
25 | [assembly: AssemblyTrademark("")]
26 | [assembly: AssemblyCulture("")]
27 |
28 | // Setting ComVisible to false makes the types in this assembly not visible
29 | // to COM components. If you need to access a type in this assembly from
30 | // COM, set the ComVisible attribute to true on that type.
31 | [assembly: ComVisible(false)]
32 |
33 | // The following GUID is for the ID of the typelib if this project is exposed to COM
34 | [assembly: Guid("b1aa7c02-0bbf-43c4-a96a-fcff754394f9")]
35 |
36 | [assembly: SupportedOSPlatform("windows")]
37 |
38 | // Version information for an assembly consists of the following four values:
39 | //
40 | // Major Version
41 | // Minor Version
42 | // Build Number
43 | // Revision
44 | //
45 | // You can specify all the values or you can default the Build and Revision Numbers
46 | // by using the '*' as shown below:
47 | // [assembly: AssemblyVersion("1.0.*")]
48 | [assembly: AssemblyVersion("1.0.12.0")]
49 | [assembly: AssemblyFileVersion("1.0.12.0")]
50 |
--------------------------------------------------------------------------------
/src/SaveForWebRIOT.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.7.34031.279
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SaveForWebRIOT", "SaveForWebRIOT.csproj", "{B1AA7C02-0BBF-43C4-A96A-FCFF754394F9}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C3B1C6E5-9872-4B4F-B054-43C67D1E173C}"
9 | ProjectSection(SolutionItems) = preProject
10 | .editorconfig = .editorconfig
11 | IgnoredWords.dic = IgnoredWords.dic
12 | EndProjectSection
13 | EndProject
14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RIOTProxy", "RIOTProxy\RIOTProxy.vcxproj", "{CDA64D75-EFD9-4676-B740-824D7F4BBF5E}"
15 | EndProject
16 | Global
17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
18 | Debug|Any CPU = Debug|Any CPU
19 | Debug|x64 = Debug|x64
20 | Release|Any CPU = Release|Any CPU
21 | Release|x64 = Release|x64
22 | EndGlobalSection
23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
24 | {B1AA7C02-0BBF-43C4-A96A-FCFF754394F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {B1AA7C02-0BBF-43C4-A96A-FCFF754394F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {B1AA7C02-0BBF-43C4-A96A-FCFF754394F9}.Debug|x64.ActiveCfg = Debug|Any CPU
27 | {B1AA7C02-0BBF-43C4-A96A-FCFF754394F9}.Debug|x64.Build.0 = Debug|Any CPU
28 | {B1AA7C02-0BBF-43C4-A96A-FCFF754394F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {B1AA7C02-0BBF-43C4-A96A-FCFF754394F9}.Release|Any CPU.Build.0 = Release|Any CPU
30 | {B1AA7C02-0BBF-43C4-A96A-FCFF754394F9}.Release|x64.ActiveCfg = Release|Any CPU
31 | {B1AA7C02-0BBF-43C4-A96A-FCFF754394F9}.Release|x64.Build.0 = Release|Any CPU
32 | {CDA64D75-EFD9-4676-B740-824D7F4BBF5E}.Debug|Any CPU.ActiveCfg = Debug|x64
33 | {CDA64D75-EFD9-4676-B740-824D7F4BBF5E}.Debug|Any CPU.Build.0 = Debug|x64
34 | {CDA64D75-EFD9-4676-B740-824D7F4BBF5E}.Debug|x64.ActiveCfg = Debug|x64
35 | {CDA64D75-EFD9-4676-B740-824D7F4BBF5E}.Debug|x64.Build.0 = Debug|x64
36 | {CDA64D75-EFD9-4676-B740-824D7F4BBF5E}.Release|Any CPU.ActiveCfg = Release|x64
37 | {CDA64D75-EFD9-4676-B740-824D7F4BBF5E}.Release|Any CPU.Build.0 = Release|x64
38 | {CDA64D75-EFD9-4676-B740-824D7F4BBF5E}.Release|x64.ActiveCfg = Release|x64
39 | {CDA64D75-EFD9-4676-B740-824D7F4BBF5E}.Release|x64.Build.0 = Release|x64
40 | EndGlobalSection
41 | GlobalSection(SolutionProperties) = preSolution
42 | HideSolutionNode = FALSE
43 | EndGlobalSection
44 | GlobalSection(ExtensibilityGlobals) = postSolution
45 | SolutionGuid = {3DE39A3C-F0AA-42D7-9172-EA70C2D77F7F}
46 | EndGlobalSection
47 | EndGlobal
48 |
--------------------------------------------------------------------------------
/.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
--------------------------------------------------------------------------------
/src/Interop/SafeNativeMethods.cs:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////////
2 | //
3 | // RIOT Save for Web Effect Plugin for Paint.NET
4 | //
5 | // This software is provided under the MIT License:
6 | // Copyright (C) 2016-2018, 2021, 2022, 2023, 2024 Nicholas Hayes
7 | //
8 | // See LICENSE.txt for complete licensing and attribution information.
9 | //
10 | /////////////////////////////////////////////////////////////////////////////////
11 |
12 | using System;
13 | using System.Runtime.InteropServices;
14 |
15 | namespace SaveForWebRIOT.Interop
16 | {
17 | [System.Security.SuppressUnmanagedCodeSecurity]
18 | internal static class SafeNativeMethods
19 | {
20 | [DllImport("RIOT.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
21 | [return: MarshalAs(UnmanagedType.U1)]
22 | internal static extern unsafe bool RIOT_LoadFromDIB_U(void* dib,
23 | IntPtr parentWindowHandle,
24 | [MarshalAs(UnmanagedType.LPWStr)] string fileName,
25 | int flags);
26 |
27 | [DllImport("kernel32.dll", SetLastError = true)]
28 | [return: MarshalAs(UnmanagedType.Bool)]
29 | internal static extern bool CloseHandle(IntPtr hObject);
30 |
31 | [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
32 | internal static extern SafeMemoryMappedFileHandle CreateFileMappingW(IntPtr hFile,
33 | IntPtr lpFileMappingAttributes,
34 | uint flProtect,
35 | uint dwMaximumSizeHigh,
36 | uint dwMaximumSizeLow,
37 | [MarshalAs(UnmanagedType.LPWStr)] string lpName);
38 |
39 | [DllImport("kernel32.dll", SetLastError = true)]
40 | internal static extern unsafe SafeMemoryMappedFileView MapViewOfFile(SafeMemoryMappedFileHandle hFileMappingObject,
41 | uint dwDesiredAccess,
42 | uint dwFileOffsetHigh,
43 | uint dwFileOffsetLow,
44 | UIntPtr dwNumberOfBytesToMap);
45 |
46 | [DllImport("kernel32.dll", SetLastError = true)]
47 | [return: MarshalAs(UnmanagedType.Bool)]
48 | internal static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/SaveForWebRIOT.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | net70-windows
4 | Library
5 | false
6 | true
7 | true
8 | true
9 | true
10 |
11 |
12 | none
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | ResXFileCodeGenerator
37 | Resources.Designer.cs
38 |
39 |
40 |
41 |
42 | D:\Program Files\paint.net\PaintDotNet.Base.dll
43 |
44 |
45 | D:\Program Files\paint.net\PaintDotNet.ComponentModel.dll
46 |
47 |
48 | D:\Program Files\paint.net\PaintDotNet.Core.dll
49 |
50 |
51 | D:\Program Files\paint.net\PaintDotNet.Data.dll
52 |
53 |
54 | D:\Program Files\paint.net\PaintDotNet.Effects.Core.dll
55 |
56 |
57 | D:\Program Files\paint.net\PaintDotNet.Fundamentals.dll
58 |
59 |
60 | D:\Program Files\paint.net\PaintDotNet.ObjectModel.dll
61 |
62 |
63 | D:\Program Files\paint.net\PaintDotNet.Primitives.dll
64 |
65 |
66 | D:\Program Files\paint.net\PaintDotNet.Windows.dll
67 |
68 |
69 | D:\Program Files\paint.net\PaintDotNet.Windows.Core.dll
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | True
82 | True
83 | Resources.resx
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/src/RIOTProxy/RIOTProxy.cpp:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////////
2 | //
3 | // RIOT Save for Web Effect Plugin for Paint.NET
4 | //
5 | // This software is provided under the MIT License:
6 | // Copyright (C) 2016-2018, 2021, 2022, 2023, 2024 Nicholas Hayes
7 | //
8 | // See LICENSE.txt for complete licensing and attribution information.
9 | //
10 | /////////////////////////////////////////////////////////////////////////////////
11 |
12 | #define WIN32_LEAN_AND_MEAN
13 |
14 | #include
15 | #include "wil/resource.h"
16 | #include
17 |
18 | #pragma comment(linker,"\"/manifestdependency:type='win32' \
19 | name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
20 | processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
21 |
22 | namespace
23 | {
24 | enum Status : int
25 | {
26 | STATUS_NO_ERROR = 0,
27 | STATUS_DIB_LOAD_FAILED,
28 | STATUS_OUT_OF_MEMORY,
29 | STATUS_RIOT_DLL_MISSING,
30 | STATUS_RIOT_ENTRY_POINT_NOT_FOUND,
31 | STATUS_RIOT_LOADFROMDIB_FAILED
32 | };
33 |
34 | int GetStatusForWin32Error(DWORD error)
35 | {
36 | switch (error)
37 | {
38 | case ERROR_NOT_ENOUGH_MEMORY:
39 | case ERROR_OUTOFMEMORY:
40 | return STATUS_OUT_OF_MEMORY;
41 | default:
42 | return STATUS_DIB_LOAD_FAILED;
43 | }
44 | }
45 |
46 | bool IsValidCommandLine(LPCWSTR commandLine)
47 | {
48 | // We expect the command line to contain a single argument.
49 | bool valid = commandLine && *commandLine != L'\0';
50 |
51 | if (valid)
52 | {
53 | LPCWSTR pCommandLine = commandLine;
54 |
55 | do
56 | {
57 | const wchar_t value = *pCommandLine;
58 | if (value == L' ' || value == L'\t')
59 | {
60 | // The command line contains multiple arguments.
61 | valid = false;
62 | break;
63 | }
64 |
65 | pCommandLine++;
66 | } while (*pCommandLine != L'\0');
67 | }
68 |
69 | return valid;
70 | }
71 |
72 | typedef bool(__cdecl RIOT_LoadFromDIB_U)(HANDLE hDIB, HWND hwndParent, const wchar_t* fileName, int flags);
73 |
74 | #ifndef NDEBUG
75 | // Adapted from https://stackoverflow.com/a/20387632
76 | bool LaunchDebugger()
77 | {
78 | // Get System directory, typically c:\windows\system32
79 | std::wstring systemDir(MAX_PATH + 1, '\0');
80 | UINT nChars = GetSystemDirectoryW(&systemDir[0], static_cast(systemDir.length()));
81 | if (nChars == 0) return false; // failed to get system directory
82 | systemDir.resize(nChars);
83 |
84 | // Get process ID and create the command line
85 | DWORD pid = GetCurrentProcessId();
86 | std::wostringstream s;
87 | s << systemDir << L"\\vsjitdebugger.exe -p " << pid;
88 | std::wstring cmdLine = s.str();
89 |
90 | // Start debugger process
91 | STARTUPINFOW si;
92 | ZeroMemory(&si, sizeof(si));
93 | si.cb = sizeof(si);
94 |
95 | PROCESS_INFORMATION pi;
96 | ZeroMemory(&pi, sizeof(pi));
97 |
98 | if (!CreateProcessW(NULL, &cmdLine[0], NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) return false;
99 |
100 | // Close debugger process handles to eliminate resource leak
101 | CloseHandle(pi.hThread);
102 | CloseHandle(pi.hProcess);
103 |
104 | // Wait for the debugger to attach
105 | while (!IsDebuggerPresent()) Sleep(100);
106 |
107 | // Stop execution so the debugger can take over
108 | DebugBreak();
109 | return true;
110 | }
111 | #endif // !NDEBUG
112 | }
113 |
114 | int WINAPI wWinMain(
115 | _In_ HINSTANCE hInstance,
116 | _In_opt_ HINSTANCE hPrevInstance,
117 | _In_ LPWSTR lpCmdLine,
118 | _In_ int nShowCmd)
119 | {
120 | #ifndef NDEBUG
121 | LaunchDebugger();
122 | #endif
123 |
124 | if (!IsValidCommandLine(lpCmdLine))
125 | {
126 | return 0;
127 | }
128 |
129 | const wchar_t* const fileMappingName = lpCmdLine;
130 |
131 | wil::unique_handle fileMappingHandle(OpenFileMappingW(FILE_MAP_READ, FALSE, fileMappingName));
132 |
133 | if (!fileMappingHandle)
134 | {
135 | return GetStatusForWin32Error(GetLastError());
136 | }
137 |
138 | wil::unique_mapview_ptr fileMappingView(MapViewOfFile(fileMappingHandle.get(), FILE_MAP_READ, 0, 0, 0));
139 |
140 | if (!fileMappingView)
141 | {
142 | return GetStatusForWin32Error(GetLastError());
143 | }
144 |
145 | wil::unique_hmodule riotDll(LoadLibraryW(L"RIOT.dll"));
146 |
147 | if (!riotDll)
148 | {
149 | return STATUS_RIOT_DLL_MISSING;
150 | }
151 |
152 | RIOT_LoadFromDIB_U* pfnLoadFromDIB = reinterpret_cast(GetProcAddress(riotDll.get(), "RIOT_LoadFromDIB_U"));
153 |
154 | if (!pfnLoadFromDIB)
155 | {
156 | return STATUS_RIOT_ENTRY_POINT_NOT_FOUND;
157 | }
158 |
159 | bool result = pfnLoadFromDIB(fileMappingView.get(), 0, L"", 0);
160 |
161 | return result ? STATUS_NO_ERROR : STATUS_RIOT_LOADFROMDIB_FAILED;
162 | }
163 |
--------------------------------------------------------------------------------
/src/RIOTProxy/RIOTProxy.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | x64
7 |
8 |
9 | Release
10 | x64
11 |
12 |
13 |
14 | 17.0
15 | Win32Proj
16 | {cda64d75-efd9-4676-b740-824d7f4bbf5e}
17 | RIOTProxy
18 | 10.0
19 |
20 |
21 |
22 | Application
23 | true
24 | v143
25 | Unicode
26 |
27 |
28 | Application
29 | false
30 | v143
31 | true
32 | Unicode
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | Level3
49 | true
50 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
51 | true
52 | MultiThreadedDebug
53 |
54 |
55 | Windows
56 | true
57 |
58 |
59 | copy "$(TargetPath)" "D:\Program Files\paint.net\Effects\SaveForWebRIOT" /y
60 |
61 |
62 |
63 |
64 | Level3
65 | true
66 | true
67 | true
68 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
69 | true
70 | MultiThreaded
71 | None
72 |
73 |
74 | Windows
75 | true
76 | true
77 | false
78 |
79 |
80 | copy "$(TargetPath)" "D:\Program Files\paint.net\Effects\SaveForWebRIOT" /y
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/src/RIOTExportConfigDialog.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 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/.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 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # MSTest test Results
33 | [Tt]est[Rr]esult*/
34 | [Bb]uild[Ll]og.*
35 |
36 | # NUNIT
37 | *.VisualState.xml
38 | TestResult.xml
39 |
40 | # Build Results of an ATL Project
41 | [Dd]ebugPS/
42 | [Rr]eleasePS/
43 | dlldata.c
44 |
45 | # .NET Core
46 | project.lock.json
47 | project.fragment.lock.json
48 | artifacts/
49 | **/Properties/launchSettings.json
50 |
51 | *_i.c
52 | *_p.c
53 | *_i.h
54 | *.ilk
55 | *.meta
56 | *.obj
57 | *.pch
58 | *.pdb
59 | *.pgc
60 | *.pgd
61 | *.rsp
62 | *.sbr
63 | *.tlb
64 | *.tli
65 | *.tlh
66 | *.tmp
67 | *.tmp_proj
68 | *.log
69 | *.vspscc
70 | *.vssscc
71 | .builds
72 | *.pidb
73 | *.svclog
74 | *.scc
75 |
76 | # Chutzpah Test files
77 | _Chutzpah*
78 |
79 | # Visual C++ cache files
80 | ipch/
81 | *.aps
82 | *.ncb
83 | *.opendb
84 | *.opensdf
85 | *.sdf
86 | *.cachefile
87 | *.VC.db
88 | *.VC.VC.opendb
89 |
90 | # Visual Studio profiler
91 | *.psess
92 | *.vsp
93 | *.vspx
94 | *.sap
95 |
96 | # TFS 2012 Local Workspace
97 | $tf/
98 |
99 | # Guidance Automation Toolkit
100 | *.gpState
101 |
102 | # ReSharper is a .NET coding add-in
103 | _ReSharper*/
104 | *.[Rr]e[Ss]harper
105 | *.DotSettings.user
106 |
107 | # JustCode is a .NET coding add-in
108 | .JustCode
109 |
110 | # TeamCity is a build add-in
111 | _TeamCity*
112 |
113 | # DotCover is a Code Coverage Tool
114 | *.dotCover
115 |
116 | # Visual Studio code coverage results
117 | *.coverage
118 | *.coveragexml
119 |
120 | # NCrunch
121 | _NCrunch_*
122 | .*crunch*.local.xml
123 | nCrunchTemp_*
124 |
125 | # MightyMoose
126 | *.mm.*
127 | AutoTest.Net/
128 |
129 | # Web workbench (sass)
130 | .sass-cache/
131 |
132 | # Installshield output folder
133 | [Ee]xpress/
134 |
135 | # DocProject is a documentation generator add-in
136 | DocProject/buildhelp/
137 | DocProject/Help/*.HxT
138 | DocProject/Help/*.HxC
139 | DocProject/Help/*.hhc
140 | DocProject/Help/*.hhk
141 | DocProject/Help/*.hhp
142 | DocProject/Help/Html2
143 | DocProject/Help/html
144 |
145 | # Click-Once directory
146 | publish/
147 |
148 | # Publish Web Output
149 | *.[Pp]ublish.xml
150 | *.azurePubxml
151 | # TODO: Comment the next line if you want to checkin your web deploy settings
152 | # but database connection strings (with potential passwords) will be unencrypted
153 | *.pubxml
154 | *.publishproj
155 |
156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
157 | # checkin your Azure Web App publish settings, but sensitive information contained
158 | # in these scripts will be unencrypted
159 | PublishScripts/
160 |
161 | # NuGet Packages
162 | *.nupkg
163 | # The packages folder can be ignored because of Package Restore
164 | **/packages/*
165 | # except build/, which is used as an MSBuild target.
166 | !**/packages/build/
167 | # Uncomment if necessary however generally it will be regenerated when needed
168 | #!**/packages/repositories.config
169 | # NuGet v3's project.json files produces more ignorable files
170 | *.nuget.props
171 | *.nuget.targets
172 |
173 | # Microsoft Azure Build Output
174 | csx/
175 | *.build.csdef
176 |
177 | # Microsoft Azure Emulator
178 | ecf/
179 | rcf/
180 |
181 | # Windows Store app package directories and files
182 | AppPackages/
183 | BundleArtifacts/
184 | Package.StoreAssociation.xml
185 | _pkginfo.txt
186 |
187 | # Visual Studio cache files
188 | # files ending in .cache can be ignored
189 | *.[Cc]ache
190 | # but keep track of directories ending in .cache
191 | !*.[Cc]ache/
192 |
193 | # Others
194 | ClientBin/
195 | ~$*
196 | *~
197 | *.dbmdl
198 | *.dbproj.schemaview
199 | *.jfm
200 | *.pfx
201 | *.publishsettings
202 | orleans.codegen.cs
203 |
204 | # Since there are multiple workflows, uncomment next line to ignore bower_components
205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
206 | #bower_components/
207 |
208 | # RIA/Silverlight projects
209 | Generated_Code/
210 |
211 | # Backup & report files from converting an old project file
212 | # to a newer Visual Studio version. Backup files are not needed,
213 | # because we have git ;-)
214 | _UpgradeReport_Files/
215 | Backup*/
216 | UpgradeLog*.XML
217 | UpgradeLog*.htm
218 |
219 | # SQL Server files
220 | *.mdf
221 | *.ldf
222 | *.ndf
223 |
224 | # Business Intelligence projects
225 | *.rdl.data
226 | *.bim.layout
227 | *.bim_*.settings
228 |
229 | # Microsoft Fakes
230 | FakesAssemblies/
231 |
232 | # GhostDoc plugin setting file
233 | *.GhostDoc.xml
234 |
235 | # Node.js Tools for Visual Studio
236 | .ntvs_analysis.dat
237 | node_modules/
238 |
239 | # Typescript v1 declaration files
240 | typings/
241 |
242 | # Visual Studio 6 build log
243 | *.plg
244 |
245 | # Visual Studio 6 workspace options file
246 | *.opt
247 |
248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
249 | *.vbw
250 |
251 | # Visual Studio LightSwitch build output
252 | **/*.HTMLClient/GeneratedArtifacts
253 | **/*.DesktopClient/GeneratedArtifacts
254 | **/*.DesktopClient/ModelManifest.xml
255 | **/*.Server/GeneratedArtifacts
256 | **/*.Server/ModelManifest.xml
257 | _Pvt_Extensions
258 |
259 | # Paket dependency manager
260 | .paket/paket.exe
261 | paket-files/
262 |
263 | # FAKE - F# Make
264 | .fake/
265 |
266 | # JetBrains Rider
267 | .idea/
268 | *.sln.iml
269 |
270 | # CodeRush
271 | .cr/
272 |
273 | # Python Tools for Visual Studio (PTVS)
274 | __pycache__/
275 | *.pyc
276 |
277 | # Cake - Uncomment if you are using it
278 | # tools/**
279 | # !tools/packages.config
280 |
281 | # Telerik's JustMock configuration file
282 | *.jmconfig
283 |
284 | # BizTalk build output
285 | *.btp.cs
286 | *.btm.cs
287 | *.odx.cs
288 | *.xsd.cs
289 |
--------------------------------------------------------------------------------
/src/Properties/Resources.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 SaveForWebRIOT.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SaveForWebRIOT.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized string similar to ARM64 support requires Windows 11..
65 | ///
66 | internal static string Arm64OSRequirement {
67 | get {
68 | return ResourceManager.GetString("Arm64OSRequirement", resourceCulture);
69 | }
70 | }
71 |
72 | ///
73 | /// Looks up a localized string similar to Unable to load the exported layer..
74 | ///
75 | internal static string DIBLoadFailed {
76 | get {
77 | return ResourceManager.GetString("DIBLoadFailed", resourceCulture);
78 | }
79 | }
80 |
81 | ///
82 | /// Looks up a localized string similar to Out of Memory..
83 | ///
84 | internal static string OutOfMemory {
85 | get {
86 | return ResourceManager.GetString("OutOfMemory", resourceCulture);
87 | }
88 | }
89 |
90 | ///
91 | /// Looks up a localized string similar to RIOT.dll was not found in the Effects folder..
92 | ///
93 | internal static string RIOTDllMissing {
94 | get {
95 | return ResourceManager.GetString("RIOTDllMissing", resourceCulture);
96 | }
97 | }
98 |
99 | ///
100 | /// Looks up a localized string similar to The entry point 'RIOT_LoadFromDIB_U' was not found in RIOT.dll..
101 | ///
102 | internal static string RIOTEntrypointNotFound {
103 | get {
104 | return ResourceManager.GetString("RIOTEntrypointNotFound", resourceCulture);
105 | }
106 | }
107 |
108 | ///
109 | /// Looks up a localized string similar to RIOT_LoadFromDIB_U returned false..
110 | ///
111 | internal static string RIOTLoadFromDIBFailed {
112 | get {
113 | return ResourceManager.GetString("RIOTLoadFromDIBFailed", resourceCulture);
114 | }
115 | }
116 |
117 | ///
118 | /// Looks up a localized string similar to RIOTProxy.exe is not in the Effects folder..
119 | ///
120 | internal static string RIOTProxyNotFound {
121 | get {
122 | return ResourceManager.GetString("RIOTProxyNotFound", resourceCulture);
123 | }
124 | }
125 |
126 | ///
127 | /// Looks up a localized string similar to RIOTProxy.exe returned an unexpected exit code 0x{0:X8}..
128 | ///
129 | internal static string UnknownExitCodeFormat {
130 | get {
131 | return ResourceManager.GetString("UnknownExitCodeFormat", resourceCulture);
132 | }
133 | }
134 |
135 | ///
136 | /// Looks up a localized string similar to The {0} platform is not supported..
137 | ///
138 | internal static string UnsupportedPlatformFormat {
139 | get {
140 | return ResourceManager.GetString("UnsupportedPlatformFormat", resourceCulture);
141 | }
142 | }
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/src/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome:http://EditorConfig.org
2 |
3 | # Top-most EditorConfig file
4 | root = true
5 |
6 | [*]
7 | end_of_line = crlf
8 | vsspell_section_id = 30a86b75973f41d3b6fe30b8f7950859
9 | vsspell_ignored_words_30a86b75973f41d3b6fe30b8f7950859 = File:IgnoredWords.dic
10 |
11 | [*.cs]
12 | indent_size = 4
13 | indent_style = space
14 | insert_final_newline = true
15 | csharp_indent_case_contents = true
16 | csharp_indent_labels = flush_left
17 | csharp_indent_switch_labels = true
18 | csharp_new_line_before_catch = true
19 | csharp_new_line_before_else = true
20 | csharp_new_line_before_finally = true
21 | csharp_new_line_before_members_in_anonymous_types = true
22 | csharp_new_line_before_members_in_object_initializers = true
23 | csharp_new_line_before_open_brace = all
24 | csharp_new_line_between_query_expression_clauses = true
25 | csharp_prefer_braces = true : warning
26 | csharp_prefer_simple_default_expression = true : suggestion
27 | csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async : suggestion
28 | csharp_preserve_single_line_blocks = true
29 | csharp_preserve_single_line_statements = true
30 | csharp_space_after_cast = false
31 | csharp_space_after_colon_in_inheritance_clause = true
32 | csharp_space_after_keywords_in_control_flow_statements = true
33 | csharp_space_around_binary_operators = before_and_after
34 | csharp_space_before_colon_in_inheritance_clause = true
35 | csharp_space_between_method_call_empty_parameter_list_parentheses = false
36 | csharp_space_between_method_call_name_and_opening_parenthesis = false
37 | csharp_space_between_method_call_parameter_list_parentheses = false
38 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
39 | csharp_space_between_method_declaration_parameter_list_parentheses = false
40 | csharp_space_between_parentheses = false
41 | csharp_style_conditional_delegate_call = true : suggestion
42 | csharp_style_deconstructed_variable_declaration = true : suggestion
43 | csharp_style_expression_bodied_accessors = false : silent
44 | csharp_style_expression_bodied_constructors = false : silent
45 | csharp_style_expression_bodied_indexers = false : silent
46 | csharp_style_expression_bodied_methods = false : silent
47 | csharp_style_expression_bodied_operators = false : silent
48 | csharp_style_expression_bodied_properties = false : silent
49 | csharp_style_inlined_variable_declaration = true : suggestion
50 | csharp_style_pattern_local_over_anonymous_function = true : suggestion
51 | csharp_style_pattern_matching_over_as_with_null_check = true : suggestion
52 | csharp_style_pattern_matching_over_is_with_cast_check = true : suggestion
53 | csharp_style_throw_expression = true : suggestion
54 | csharp_style_var_elsewhere = false : silent
55 | csharp_style_var_for_built_in_types = false : silent
56 | csharp_style_var_when_type_is_apparent = false : silent
57 |
58 | [*.{cs,vb}]
59 | dotnet_sort_system_directives_first = false
60 | dotnet_style_coalesce_expression = true : suggestion
61 | dotnet_style_collection_initializer = true : suggestion
62 | dotnet_style_explicit_tuple_names = true : suggestion
63 | dotnet_style_null_propagation = true : suggestion
64 | dotnet_style_object_initializer = true : suggestion
65 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity : silent
66 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity : silent
67 | dotnet_style_parentheses_in_other_operators = never_if_unnecessary : silent
68 | dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity : silent
69 | dotnet_style_predefined_type_for_locals_parameters_members = true : suggestion
70 | dotnet_style_predefined_type_for_member_access = true : suggestion
71 | dotnet_style_prefer_auto_properties = true : silent
72 | dotnet_style_prefer_conditional_expression_over_assignment = true
73 | dotnet_style_prefer_conditional_expression_over_return = true
74 | dotnet_style_prefer_inferred_anonymous_type_member_names = true : suggestion
75 | dotnet_style_prefer_inferred_tuple_names = true : suggestion
76 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true : silent
77 | dotnet_style_qualification_for_event = false : silent
78 | dotnet_style_qualification_for_field = false : silent
79 | dotnet_style_qualification_for_method = false : silent
80 | dotnet_style_qualification_for_property = false : silent
81 | dotnet_style_readonly_field = true : suggestion
82 | dotnet_style_require_accessibility_modifiers = for_non_interface_members : suggestion
83 |
--------------------------------------------------------------------------------
/src/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 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | ARM64 support requires Windows 11.
122 |
123 |
124 | Unable to load the exported layer.
125 |
126 |
127 | Out of Memory.
128 |
129 |
130 | RIOT.dll was not found in the Effects folder.
131 |
132 |
133 | The entry point 'RIOT_LoadFromDIB_U' was not found in RIOT.dll.
134 |
135 |
136 | RIOT_LoadFromDIB_U returned false.
137 |
138 |
139 | RIOTProxy.exe is not in the Effects folder.
140 |
141 |
142 | RIOTProxy.exe returned an unexpected exit code 0x{0:X8}.
143 | {0} is the exit code as a hexidecimal string.
144 |
145 |
146 | The {0} platform is not supported.
147 | {0} is the platform name
148 |
149 |
--------------------------------------------------------------------------------
/src/RIOTExportConfigDialog.cs:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////////
2 | //
3 | // RIOT Save for Web Effect Plugin for Paint.NET
4 | //
5 | // This software is provided under the MIT License:
6 | // Copyright (C) 2016-2018, 2021, 2022, 2023, 2024 Nicholas Hayes
7 | //
8 | // See LICENSE.txt for complete licensing and attribution information.
9 | //
10 | /////////////////////////////////////////////////////////////////////////////////
11 |
12 | using PaintDotNet;
13 | using PaintDotNet.AppModel;
14 | using PaintDotNet.Effects;
15 | using PaintDotNet.Imaging;
16 | using PaintDotNet.Rendering;
17 | using SaveForWebRIOT.Interop;
18 | using SaveForWebRIOT.Properties;
19 | using System;
20 | using System.ComponentModel;
21 | using System.Diagnostics;
22 | using System.Globalization;
23 | using System.IO;
24 | using System.Runtime.InteropServices;
25 | using System.Threading;
26 | using System.Windows.Forms;
27 |
28 | namespace SaveForWebRIOT
29 | {
30 | internal sealed class RIOTExportConfigDialog : EffectConfigForm
31 | {
32 | private Label infoLabel;
33 | private Thread riotWorkerThread;
34 | private static readonly string RiotProxyPath = Path.Combine(Path.GetDirectoryName(typeof(RIOTExportConfigDialog).Assembly.Location), "RIOTProxy.exe");
35 | private static readonly Version Win11OSVersion = new(10, 0, 22000, 0);
36 |
37 | public RIOTExportConfigDialog()
38 | {
39 | InitializeComponent();
40 | Text = RIOTExportEffect.StaticName;
41 | }
42 |
43 | protected override EffectConfigToken OnCreateInitialToken()
44 | {
45 | return new RIOTExportConfigToken();
46 | }
47 |
48 | protected override void OnLayout(LayoutEventArgs le)
49 | {
50 | int hMargin = LogicalToDeviceUnits(8);
51 | int vMargin = LogicalToDeviceUnits(8);
52 |
53 | infoLabel.Location = new System.Drawing.Point(hMargin, vMargin);
54 | infoLabel.Size = TextRenderer.MeasureText(infoLabel.Text,
55 | infoLabel.Font,
56 | new System.Drawing.Size(ClientSize.Width - infoLabel.Left - hMargin, int.MaxValue),
57 | TextFormatFlags.WordBreak);
58 | infoLabel.PerformLayout();
59 |
60 | int clientWidth = infoLabel.Right + hMargin;
61 | int clientHeight = infoLabel.Bottom + vMargin;
62 |
63 | ClientSize = new System.Drawing.Size(clientWidth, clientHeight);
64 |
65 | base.OnLayout(le);
66 | }
67 |
68 | protected override void OnUpdateDialogFromToken(EffectConfigToken token)
69 | {
70 | }
71 |
72 | protected override void OnUpdateTokenFromDialog(EffectConfigToken dstToken)
73 | {
74 | }
75 |
76 | private void InitializeComponent()
77 | {
78 | infoLabel = new System.Windows.Forms.Label();
79 | SuspendLayout();
80 | //
81 | // infoLabel
82 | //
83 | infoLabel.AutoSize = true;
84 | infoLabel.Location = new System.Drawing.Point(13, 13);
85 | infoLabel.Name = "infoLabel";
86 | infoLabel.Size = new System.Drawing.Size(183, 13);
87 | infoLabel.TabIndex = 1;
88 | infoLabel.Text = "RIOT will open in a separate window.";
89 | //
90 | // RIOTExportConfigDialog
91 | //
92 | AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
93 | ClientSize = new System.Drawing.Size(368, 82);
94 | ControlBox = false;
95 | Controls.Add(infoLabel);
96 | FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
97 | Location = new System.Drawing.Point(0, 0);
98 | Name = "RIOTExportConfigDialog";
99 | ShowIcon = false;
100 | Controls.SetChildIndex(infoLabel, 0);
101 | ResumeLayout(false);
102 | PerformLayout();
103 | }
104 |
105 | private void ShowErrorMessage(string message)
106 | {
107 | if (InvokeRequired)
108 | {
109 | Invoke(new Action((string error) => Services.GetService().ShowErrorDialog(this, error, string.Empty)),
110 | message);
111 | }
112 | else
113 | {
114 | Services.GetService().ShowErrorDialog(this, message, string.Empty);
115 | }
116 | }
117 |
118 | private void ShowErrorMessage(Exception exception)
119 | {
120 | if (InvokeRequired)
121 | {
122 | Invoke(new Action((Exception ex) => Services.GetService().ShowErrorDialog(this, ex)),
123 | exception);
124 | }
125 | else
126 | {
127 | Services.GetService().ShowErrorDialog(this, exception);
128 | }
129 | }
130 |
131 | protected override void OnLoaded()
132 | {
133 | if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
134 | {
135 | StartProxyProcessThread();
136 | }
137 | else if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
138 | {
139 | if (System.Environment.OSVersion.Version >= Win11OSVersion)
140 | {
141 | StartProxyProcessThread();
142 | }
143 | else
144 | {
145 | ShowErrorMessage(Resources.Arm64OSRequirement);
146 | CloseForm();
147 | }
148 | }
149 | else
150 | {
151 | ShowErrorMessage(string.Format(CultureInfo.CurrentCulture,
152 | Resources.UnsupportedPlatformFormat,
153 | RuntimeInformation.ProcessArchitecture));
154 | CloseForm();
155 | }
156 | }
157 |
158 | private static unsafe bool HasTransparency(IEffectInputBitmap bitmap)
159 | {
160 | using (IBitmapLock bitmapLock = bitmap.Lock(bitmap.Bounds()))
161 | {
162 | RegionPtr region = bitmapLock.AsRegionPtr();
163 |
164 | foreach (RegionRowPtr row in region.Rows)
165 | {
166 | ColorBgra32* ptr = row.Ptr;
167 | ColorBgra32* endPtr = row.EndPtr;
168 |
169 | while (ptr < endPtr)
170 | {
171 | if (ptr->A != 255)
172 | {
173 | return true;
174 | }
175 |
176 | ptr++;
177 | }
178 | }
179 | }
180 |
181 | return false;
182 | }
183 |
184 | private void CloseForm()
185 | {
186 | DialogResult = DialogResult.Cancel;
187 | Close();
188 | }
189 |
190 | private static DIBInfo GetDibInfo(IEffectInputBitmap bitmap)
191 | {
192 | SizeInt32 size = bitmap.Size;
193 |
194 | int width = size.Width;
195 | int height = size.Height;
196 |
197 | int dibBitsPerPixel = HasTransparency(bitmap) ? 32 : 24;
198 |
199 | int bmiHeaderSize = Marshal.SizeOf(typeof(NativeStructs.BITMAPINFOHEADER));
200 | long dibStride = ((((long)width * dibBitsPerPixel) + 31) & ~31) / 8;
201 | long dibImageDataSize = dibStride * height;
202 |
203 | // 24-bit and 32-bit DIB files do not have a color palette.
204 | long dibSize = bmiHeaderSize + dibImageDataSize;
205 |
206 | return new DIBInfo(bmiHeaderSize, width, height, dibStride, dibBitsPerPixel, dibSize);
207 | }
208 |
209 | private static unsafe void FillDib(IEffectInputBitmap bitmap,
210 | Resolution documentResolution,
211 | DIBInfo info,
212 | void* baseAddress)
213 | {
214 | int bmiHeaderSize = info.BitmapInfoHeaderSize;
215 | int width = info.Width;
216 | int height = info.Height;
217 | long dibStride = info.Stride;
218 | int dibBitsPerPixel = info.BitsPerPixel;
219 |
220 | Vector2Int32 dpi = GetResolutionInDotsPerInch(documentResolution);
221 |
222 | NativeStructs.BITMAPINFOHEADER* bmiHeader = (NativeStructs.BITMAPINFOHEADER*)baseAddress;
223 | bmiHeader->biSize = (uint)bmiHeaderSize;
224 | bmiHeader->biWidth = width;
225 | bmiHeader->biHeight = height;
226 | bmiHeader->biPlanes = 1;
227 | bmiHeader->biBitCount = (ushort)dibBitsPerPixel;
228 | bmiHeader->biCompression = NativeConstants.BI_RGB;
229 | bmiHeader->biSizeImage = 0;
230 | // The RIOT developer documentation states that it expects the biXPelsPerMeter and biYPelsPerMeter
231 | // fields to use dots-per-inch, not dots-per-meter.
232 | bmiHeader->biXPelsPerMeter = dpi.X;
233 | bmiHeader->biYPelsPerMeter = dpi.Y;
234 | bmiHeader->biClrUsed = 0;
235 | bmiHeader->biClrImportant = 0;
236 |
237 | int lastBitmapRow = height - 1;
238 | int dibBytesPerPixel = dibBitsPerPixel / 8;
239 |
240 | byte* dibScan0 = (byte*)baseAddress + bmiHeaderSize;
241 |
242 | using (IBitmapLock bitmapLock = bitmap.Lock(bitmap.Bounds()))
243 | {
244 | RegionPtr region = bitmapLock.AsRegionPtr();
245 | RegionRowPtrCollection rows = region.Rows;
246 |
247 | for (int y = 0; y < height; y++)
248 | {
249 | // Access the surface in the order needed for a bottom-up DIB.
250 | ColorBgra32* src = rows[lastBitmapRow - y].Ptr;
251 | byte* dst = dibScan0 + (y * dibStride);
252 |
253 | for (int x = 0; x < width; x++)
254 | {
255 | switch (dibBitsPerPixel)
256 | {
257 | case 24:
258 | dst[0] = src->B;
259 | dst[1] = src->G;
260 | dst[2] = src->R;
261 | break;
262 | case 32:
263 | dst[0] = src->B;
264 | dst[1] = src->G;
265 | dst[2] = src->R;
266 | dst[3] = src->A;
267 | break;
268 | default:
269 | throw new InvalidOperationException($"Unsupported {nameof(dibBitsPerPixel)} value: {dibBitsPerPixel}.");
270 | }
271 |
272 | src++;
273 | dst += dibBytesPerPixel;
274 | }
275 | }
276 | }
277 |
278 | static Vector2Int32 GetResolutionInDotsPerInch(Resolution resolution)
279 | {
280 | double xDpi;
281 | double yDpi;
282 |
283 | switch (resolution.Units)
284 | {
285 | case MeasurementUnit.Pixel:
286 | xDpi = yDpi = Document.DefaultDpi;
287 | break;
288 | case MeasurementUnit.Inch:
289 | xDpi = resolution.X;
290 | yDpi = resolution.Y;
291 | break;
292 | case MeasurementUnit.Centimeter:
293 | xDpi = Document.DotsPerCmToDotsPerInch(resolution.X);
294 | yDpi = Document.DotsPerCmToDotsPerInch(resolution.Y);
295 | break;
296 | default:
297 | xDpi = yDpi = 0;
298 | break;
299 | }
300 |
301 | return new Vector2Int32((int)Math.Round(xDpi), (int)Math.Round(yDpi));
302 | }
303 | }
304 |
305 | private static unsafe SafeMemoryMappedFileHandle CreateMemoryMappedDib(string name,
306 | DIBInfo info,
307 | IEffectInputBitmap bitmap,
308 | Resolution documentResolution)
309 | {
310 | SafeMemoryMappedFileHandle handle = null;
311 | SafeMemoryMappedFileHandle temp = null;
312 |
313 | try
314 | {
315 | long fileMappingSize = info.TotalDIBSize;
316 |
317 | uint dwMaximumSizeHigh = (uint)(fileMappingSize >> 32);
318 | uint dwMaximumSizeLow = (uint)fileMappingSize;
319 |
320 | temp = SafeNativeMethods.CreateFileMappingW(new IntPtr(NativeConstants.INVALID_HANDLE_VALUE),
321 | IntPtr.Zero,
322 | NativeConstants.PAGE_READWRITE,
323 | dwMaximumSizeHigh,
324 | dwMaximumSizeLow,
325 | name);
326 | if (temp.IsInvalid)
327 | {
328 | throw new Win32Exception();
329 | }
330 |
331 | using (SafeMemoryMappedFileView view = SafeNativeMethods.MapViewOfFile(temp,
332 | NativeConstants.FILE_MAP_WRITE,
333 | 0,
334 | 0,
335 | 0))
336 | {
337 | if (view.IsInvalid)
338 | {
339 | throw new Win32Exception();
340 | }
341 |
342 | FillDib(bitmap, documentResolution, info, view.DangerousGetHandle().ToPointer());
343 | }
344 |
345 | handle = temp;
346 | temp = null;
347 | }
348 | finally
349 | {
350 | temp?.Dispose();
351 | }
352 |
353 | return handle;
354 | }
355 |
356 | private void RunProxyProcess()
357 | {
358 | ErrorInfo errorInfo = null;
359 |
360 | try
361 | {
362 | string fileMappingName = "pdn_" + Guid.NewGuid().ToString();
363 |
364 | IEffectInputBitmap bitmap = Environment.GetSourceBitmapBgra32();
365 | DIBInfo info = GetDibInfo(bitmap);
366 | Resolution documentResolution = Environment.Document.Resolution;
367 |
368 | using (SafeMemoryMappedFileHandle fileMappingHandle = CreateMemoryMappedDib(fileMappingName, info, bitmap, documentResolution))
369 | {
370 | using (Process proc = new())
371 | {
372 | proc.StartInfo = new ProcessStartInfo(RiotProxyPath, fileMappingName);
373 | proc.Start();
374 |
375 | proc.WaitForExit();
376 |
377 | switch (proc.ExitCode)
378 | {
379 | case 0:
380 | // No error.
381 | break;
382 | case 1:
383 | errorInfo = new(Resources.DIBLoadFailed);
384 | break;
385 | case 2:
386 | errorInfo = new(Resources.OutOfMemory);
387 | break;
388 | case 3:
389 | errorInfo = new(Resources.RIOTDllMissing);
390 | break;
391 | case 4:
392 | errorInfo = new(Resources.RIOTEntrypointNotFound);
393 | break;
394 | case 5:
395 | errorInfo = new(Resources.RIOTLoadFromDIBFailed);
396 | break;
397 | default:
398 | errorInfo = new(string.Format(CultureInfo.InvariantCulture,
399 | Resources.UnknownExitCodeFormat,
400 | proc.ExitCode));
401 | break;
402 | }
403 | }
404 | }
405 | }
406 | catch (Exception ex)
407 | {
408 | errorInfo = new(ex);
409 | }
410 |
411 | BeginInvoke(new Action(RiotWorkerThreadFinished), errorInfo);
412 | }
413 |
414 | private void RiotWorkerThreadFinished(ErrorInfo errorInfo)
415 | {
416 | riotWorkerThread.Join();
417 |
418 | if (errorInfo != null)
419 | {
420 | if (errorInfo.Exception != null)
421 | {
422 | ShowErrorMessage(errorInfo.Exception);
423 | }
424 | else if (!string.IsNullOrEmpty(errorInfo.Message))
425 | {
426 | ShowErrorMessage(errorInfo.Message);
427 | }
428 | }
429 |
430 | CloseForm();
431 | }
432 |
433 | private void StartProxyProcessThread()
434 | {
435 | if (File.Exists(RiotProxyPath))
436 | {
437 | riotWorkerThread = new Thread(RunProxyProcess);
438 | riotWorkerThread.Start();
439 | }
440 | else
441 | {
442 | ShowErrorMessage(Resources.RIOTProxyNotFound);
443 | CloseForm();
444 | }
445 | }
446 |
447 | private sealed class DIBInfo
448 | {
449 | public DIBInfo(int bitmapInfoHeaderSize,
450 | int width,
451 | int height,
452 | long stride,
453 | int bitsPerPixel,
454 | long totalDIBSize)
455 | {
456 | BitmapInfoHeaderSize = bitmapInfoHeaderSize;
457 | Width = width;
458 | Height = height;
459 | Stride = stride;
460 | BitsPerPixel = bitsPerPixel;
461 | TotalDIBSize = totalDIBSize;
462 | }
463 |
464 | public int BitmapInfoHeaderSize { get; }
465 |
466 | public int Width { get; }
467 |
468 | public int Height { get; }
469 |
470 | public long Stride { get; }
471 |
472 | public int BitsPerPixel { get; }
473 |
474 | public long TotalDIBSize { get; }
475 | }
476 |
477 | private sealed class ErrorInfo
478 | {
479 | public ErrorInfo(Exception exception)
480 | {
481 | Exception = exception;
482 | Message = string.Empty;
483 | }
484 |
485 | public ErrorInfo(string message)
486 | {
487 | Exception = null;
488 | Message = message;
489 | }
490 |
491 | public Exception Exception { get; }
492 |
493 | public string Message { get; }
494 | }
495 | }
496 | }
497 |
--------------------------------------------------------------------------------