diff --git a/Greenshot.sln b/Greenshot.sln index 47be71a18..1814e9a20 100644 --- a/Greenshot.sln +++ b/Greenshot.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Greenshot", "Greenshot\Greenshot.csproj", "{CD642BF4-D815-4D67-A0B5-C69F0B8231AF}" EndProject @@ -34,6 +34,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotOfficePlugin", "Gr EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotPhotobucketPlugin", "GreenshotPhotobucketPlugin\GreenshotPhotobucketPlugin.csproj", "{9C0ECC4C-7807-4111-916A-4F57BB29788A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreenshotWin10Plugin", "GreenshotWin10Plugin\GreenshotWin10Plugin.csproj", "{9801F62C-540F-4BFE-9211-6405DEDE563B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -177,6 +179,18 @@ Global {9C0ECC4C-7807-4111-916A-4F57BB29788A}.Release|Mixed Platforms.Build.0 = Release|Any CPU {9C0ECC4C-7807-4111-916A-4F57BB29788A}.Release|x86.ActiveCfg = Release|x86 {9C0ECC4C-7807-4111-916A-4F57BB29788A}.Release|x86.Build.0 = Release|x86 + {9801F62C-540F-4BFE-9211-6405DEDE563B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9801F62C-540F-4BFE-9211-6405DEDE563B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9801F62C-540F-4BFE-9211-6405DEDE563B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {9801F62C-540F-4BFE-9211-6405DEDE563B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {9801F62C-540F-4BFE-9211-6405DEDE563B}.Debug|x86.ActiveCfg = Debug|Any CPU + {9801F62C-540F-4BFE-9211-6405DEDE563B}.Debug|x86.Build.0 = Debug|Any CPU + {9801F62C-540F-4BFE-9211-6405DEDE563B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9801F62C-540F-4BFE-9211-6405DEDE563B}.Release|Any CPU.Build.0 = Release|Any CPU + {9801F62C-540F-4BFE-9211-6405DEDE563B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {9801F62C-540F-4BFE-9211-6405DEDE563B}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {9801F62C-540F-4BFE-9211-6405DEDE563B}.Release|x86.ActiveCfg = Release|Any CPU + {9801F62C-540F-4BFE-9211-6405DEDE563B}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/GreenshotWin10Plugin/GreenshotWin10Plugin.csproj b/GreenshotWin10Plugin/GreenshotWin10Plugin.csproj new file mode 100644 index 000000000..9aa9b6a71 --- /dev/null +++ b/GreenshotWin10Plugin/GreenshotWin10Plugin.csproj @@ -0,0 +1,79 @@ + + + + + Debug + AnyCPU + {9801F62C-540F-4BFE-9211-6405DEDE563B} + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + Properties + GreenshotWin10Plugin + GreenshotWin10Plugin + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + False + ..\Greenshot\lib\log4net.dll + + + + + + False + C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.WindowsRuntime.dll + global + + + C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd + + + {5B924697-4DCD-4F98-85F1-105CB84B7341} + GreenshotPlugin + + + + + +mkdir "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)" +copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).dll" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)bin\$(Configuration)\$(ProjectName).pdb" "$(SolutionDir)Greenshot\bin\$(Configuration)\Plugins\$(ProjectName)\" + + + \ No newline at end of file diff --git a/GreenshotWin10Plugin/Properties/AssemblyInfo.cs b/GreenshotWin10Plugin/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..b020ad5f7 --- /dev/null +++ b/GreenshotWin10Plugin/Properties/AssemblyInfo.cs @@ -0,0 +1,31 @@ +using Greenshot.Plugin; +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("GreenshotWin10Plugin")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Greenshot")] +[assembly: AssemblyProduct("GreenshotWin10Plugin")] +[assembly: AssemblyCopyright("Copyright © Greenshot 2007-2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The PluginAttribute describes the "entryType" and if the plugin is configurable +[assembly: Plugin("GreenshotWin10Plugin.Win10Plugin", false)] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("9801f62c-540f-4bfe-9211-6405dede563b")] + +// The assembly version, replaced by build scripts +[assembly: AssemblyVersion("1.2.0.0")] +[assembly: AssemblyInformationalVersion("1.2.0.0")] +[assembly: AssemblyFileVersion("1.2.0.0")] diff --git a/GreenshotWin10Plugin/Win10OcrDestination.cs b/GreenshotWin10Plugin/Win10OcrDestination.cs new file mode 100644 index 000000000..9b2730455 --- /dev/null +++ b/GreenshotWin10Plugin/Win10OcrDestination.cs @@ -0,0 +1,93 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using System; +using System.IO; +using System.Threading.Tasks; +using Windows.Graphics.Imaging; +using Windows.Media.Ocr; +using Greenshot.Plugin; +using GreenshotPlugin.Core; + +namespace GreenshotWin10Plugin +{ + /// + /// This uses the OcrEngine from Windows 10 to perform OCR on the captured image. + /// + public class Win10OcrDestination : AbstractDestination + { + private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(typeof(Win10OcrDestination)); + + public override string Designation { get; } = "OCR"; + public override string Description { get; } = "Windows 10 OCR"; + + public Win10OcrDestination() + { + var languages = OcrEngine.AvailableRecognizerLanguages; + foreach (var language in languages) + { + Log.DebugFormat("Found language {0} {1}", language.NativeName, language.LanguageTag); + } + + } + + /// + /// Run the Windows 10 OCR engine to process the text on the captured image + /// + /// + /// + /// + /// ExportInformation + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) + { + ExportInformation exportInformation = new ExportInformation(Designation, Description); + try + { + var text = Task.Run(async () => + { + var ocrEngine = OcrEngine.TryCreateFromUserProfileLanguages(); + using (var imageStream = new MemoryStream()) + { + ImageOutput.SaveToStream(surface, imageStream, new SurfaceOutputSettings()); + imageStream.Position = 0; + + var decoder = await BitmapDecoder.CreateAsync(imageStream.AsRandomAccessStream()); + var softwareBitmap = await decoder.GetSoftwareBitmapAsync(); + + var ocrResult = await ocrEngine.RecognizeAsync(softwareBitmap); + return ocrResult.Text; + } + }).Result; + ClipboardHelper.SetClipboardData(text); + exportInformation.ExportMade = true; + } + catch (Exception ex) + { + exportInformation.ExportMade = false; + exportInformation.ErrorMessage = ex.Message; + } + + ProcessExport(exportInformation, surface); + return exportInformation; + + } + } +} diff --git a/GreenshotWin10Plugin/Win10Plugin.cs b/GreenshotWin10Plugin/Win10Plugin.cs new file mode 100644 index 000000000..38826a0cf --- /dev/null +++ b/GreenshotWin10Plugin/Win10Plugin.cs @@ -0,0 +1,77 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2016 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on GitHub https://github.com/greenshot/greenshot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using System; +using System.Collections.Generic; +using Greenshot.Plugin; + +namespace GreenshotWin10Plugin +{ + /// + /// This is the Win10Plugin + /// + public class Win10Plugin : IGreenshotPlugin + { + + public void Dispose() + { + Dispose(true); + } + + protected void Dispose(bool disposing) + { + if (disposing) + { + } + } + + public void Configure() + { + throw new NotImplementedException(); + } + + public IEnumerable Destinations() + { + yield return new Win10OcrDestination(); + } + + public IEnumerable Processors() + { + yield break; + } + + /// + /// Implementation of the IGreenshotPlugin.Initialize + /// + /// Use the IGreenshotPluginHost interface to register events + /// My own attributes + /// true if plugin is initialized, false if not (doesn't show) + public bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) + { + return true; + } + + public void Shutdown() + { + } + } + +}