mirror of
https://github.com/greenshot/greenshot
synced 2025-08-22 06:23:24 -07:00
Step by step improving of the functionality, now added Jpeg XR via the WmpFileFormatHandler which uses WPF.
This commit is contained in:
parent
2997671698
commit
e1c70aadb9
16 changed files with 330 additions and 329 deletions
|
@ -166,7 +166,7 @@ namespace Greenshot.Base.Controls
|
||||||
// if the filename contains a valid extension, which is the same like the selected filter item's extension, the filename is okay
|
// if the filename contains a valid extension, which is the same like the selected filter item's extension, the filename is okay
|
||||||
if (fn.EndsWith(Extension, StringComparison.CurrentCultureIgnoreCase)) return fn;
|
if (fn.EndsWith(Extension, StringComparison.CurrentCultureIgnoreCase)) return fn;
|
||||||
// otherwise we just add the selected filter item's extension
|
// otherwise we just add the selected filter item's extension
|
||||||
else return fn + "." + Extension;
|
return fn + "." + Extension;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,7 +65,8 @@ namespace Greenshot.Base.Core
|
||||||
//private static readonly string FORMAT_HTML = "HTML Format";
|
//private static readonly string FORMAT_HTML = "HTML Format";
|
||||||
|
|
||||||
// Template for the HTML Text on the clipboard
|
// Template for the HTML Text on the clipboard
|
||||||
// see: https://msdn.microsoft.com/en-us/library/ms649015%28v=vs.85%29.aspx
|
// see: https://msdn.microsoft.com/en-us/library/ms649015%28v=v
|
||||||
|
// s.85%29.aspx
|
||||||
// or: https://msdn.microsoft.com/en-us/library/Aa767917.aspx
|
// or: https://msdn.microsoft.com/en-us/library/Aa767917.aspx
|
||||||
private const string HtmlClipboardString = @"Version:0.9
|
private const string HtmlClipboardString = @"Version:0.9
|
||||||
StartHTML:<<<<<<<1
|
StartHTML:<<<<<<<1
|
||||||
|
|
36
src/Greenshot.Base/Core/Enums/ExifOrientations.cs
Normal file
36
src/Greenshot.Base/Core/Enums/ExifOrientations.cs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
|
||||||
|
*
|
||||||
|
* For more information see: https://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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Greenshot.Base.Core.Enums
|
||||||
|
{
|
||||||
|
internal enum ExifOrientations : byte
|
||||||
|
{
|
||||||
|
Unknown = 0,
|
||||||
|
TopLeft = 1,
|
||||||
|
TopRight = 2,
|
||||||
|
BottomRight = 3,
|
||||||
|
BottomLeft = 4,
|
||||||
|
LeftTop = 5,
|
||||||
|
RightTop = 6,
|
||||||
|
RightBottom = 7,
|
||||||
|
LeftBottom = 8,
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,27 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.IO;
|
|
||||||
using Greenshot.Base.Interfaces;
|
|
||||||
using Greenshot.Base.Interfaces.Drawing;
|
|
||||||
|
|
||||||
namespace Greenshot.Base.Core.FileFormatHandlers
|
|
||||||
{
|
|
||||||
public abstract class AbstractFileFormatHandler
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Make sure we handle the input extension always the same, by "normalizing" it
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="extension">string</param>
|
|
||||||
/// <returns>string</returns>
|
|
||||||
protected string NormalizeExtension(string extension)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(extension))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
extension = extension.ToLowerInvariant();
|
|
||||||
return !extension.StartsWith(".") ? $".{extension}" : extension;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -26,28 +26,26 @@ using System.Drawing.Drawing2D;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using Greenshot.Base.Core.Enums;
|
||||||
using Greenshot.Base.Core.FileFormatHandlers;
|
using Greenshot.Base.Core.FileFormatHandlers;
|
||||||
using Greenshot.Base.Effects;
|
using Greenshot.Base.Effects;
|
||||||
using Greenshot.Base.IniFile;
|
using Greenshot.Base.IniFile;
|
||||||
using Greenshot.Base.Interfaces;
|
using Greenshot.Base.Interfaces;
|
||||||
using Greenshot.Base.UnmanagedHelpers;
|
using Greenshot.Base.UnmanagedHelpers;
|
||||||
using log4net;
|
using log4net;
|
||||||
|
using Brush = System.Drawing.Brush;
|
||||||
|
using Color = System.Drawing.Color;
|
||||||
|
using Matrix = System.Drawing.Drawing2D.Matrix;
|
||||||
|
using Pen = System.Drawing.Pen;
|
||||||
|
using PixelFormat = System.Drawing.Imaging.PixelFormat;
|
||||||
|
using Point = System.Drawing.Point;
|
||||||
|
using Size = System.Drawing.Size;
|
||||||
|
|
||||||
namespace Greenshot.Base.Core
|
namespace Greenshot.Base.Core
|
||||||
{
|
{
|
||||||
internal enum ExifOrientations : byte
|
|
||||||
{
|
|
||||||
Unknown = 0,
|
|
||||||
TopLeft = 1,
|
|
||||||
TopRight = 2,
|
|
||||||
BottomRight = 3,
|
|
||||||
BottomLeft = 4,
|
|
||||||
LeftTop = 5,
|
|
||||||
RightTop = 6,
|
|
||||||
RightBottom = 7,
|
|
||||||
LeftBottom = 8,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Description of ImageHelper.
|
/// Description of ImageHelper.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1570,7 +1568,7 @@ namespace Greenshot.Base.Core
|
||||||
nPercentW = nPercentH;
|
nPercentW = nPercentH;
|
||||||
if (canvasUseNewSize)
|
if (canvasUseNewSize)
|
||||||
{
|
{
|
||||||
destX = Math.Max(0, Convert.ToInt32((newWidth - sourceImage.Width * nPercentW) / 2));
|
destX = Math.Max(0, System.Convert.ToInt32((newWidth - sourceImage.Width * nPercentW) / 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((int) nPercentH == 1)
|
else if ((int) nPercentH == 1)
|
||||||
|
@ -1578,7 +1576,7 @@ namespace Greenshot.Base.Core
|
||||||
nPercentH = nPercentW;
|
nPercentH = nPercentW;
|
||||||
if (canvasUseNewSize)
|
if (canvasUseNewSize)
|
||||||
{
|
{
|
||||||
destY = Math.Max(0, Convert.ToInt32((newHeight - sourceImage.Height * nPercentH) / 2));
|
destY = Math.Max(0, System.Convert.ToInt32((newHeight - sourceImage.Height * nPercentH) / 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((int) nPercentH != 0 && nPercentH < nPercentW)
|
else if ((int) nPercentH != 0 && nPercentH < nPercentW)
|
||||||
|
@ -1586,7 +1584,7 @@ namespace Greenshot.Base.Core
|
||||||
nPercentW = nPercentH;
|
nPercentW = nPercentH;
|
||||||
if (canvasUseNewSize)
|
if (canvasUseNewSize)
|
||||||
{
|
{
|
||||||
destX = Math.Max(0, Convert.ToInt32((newWidth - sourceImage.Width * nPercentW) / 2));
|
destX = Math.Max(0, System.Convert.ToInt32((newWidth - sourceImage.Width * nPercentW) / 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1594,7 +1592,7 @@ namespace Greenshot.Base.Core
|
||||||
nPercentH = nPercentW;
|
nPercentH = nPercentW;
|
||||||
if (canvasUseNewSize)
|
if (canvasUseNewSize)
|
||||||
{
|
{
|
||||||
destY = Math.Max(0, Convert.ToInt32((newHeight - sourceImage.Height * nPercentH) / 2));
|
destY = Math.Max(0, System.Convert.ToInt32((newHeight - sourceImage.Height * nPercentH) / 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1739,16 +1737,97 @@ namespace Greenshot.Base.Core
|
||||||
{
|
{
|
||||||
var bitmap = CreateEmptyLike(image, Color.Transparent);
|
var bitmap = CreateEmptyLike(image, Color.Transparent);
|
||||||
|
|
||||||
using var gfx = Graphics.FromImage(bitmap);
|
using var graphics = Graphics.FromImage(bitmap);
|
||||||
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
|
|
||||||
gfx.TranslateTransform((float)bitmap.Width / 2, (float)bitmap.Height / 2);
|
graphics.TranslateTransform((float)bitmap.Width / 2, (float)bitmap.Height / 2);
|
||||||
gfx.RotateTransform(rotationAngle);
|
graphics.RotateTransform(rotationAngle);
|
||||||
gfx.TranslateTransform(-(float)bitmap.Width / 2, -(float)bitmap.Height / 2);
|
graphics.TranslateTransform(-(float)bitmap.Width / 2, -(float)bitmap.Height / 2);
|
||||||
|
|
||||||
gfx.DrawImage(image, new Point(0, 0));
|
graphics.DrawImage(image, new Point(0, 0));
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Map a System.Drawing.Imaging.PixelFormat to a System.Windows.Media.PixelFormat
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pixelFormat">System.Drawing.Imaging.PixelFormat</param>
|
||||||
|
/// <returns>System.Windows.Media.PixelFormat</returns>
|
||||||
|
/// <exception cref="NotSupportedException"></exception>
|
||||||
|
public static System.Windows.Media.PixelFormat Map(this PixelFormat pixelFormat) =>
|
||||||
|
pixelFormat switch
|
||||||
|
{
|
||||||
|
PixelFormat.Format32bppArgb => PixelFormats.Bgra32,
|
||||||
|
PixelFormat.Format24bppRgb => PixelFormats.Bgr24,
|
||||||
|
PixelFormat.Format32bppRgb => PixelFormats.Bgr32,
|
||||||
|
_ => throw new NotSupportedException($"Can't map {pixelFormat}.")
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Map a System.Windows.Media.PixelFormat to a System.Drawing.Imaging.PixelFormat
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pixelFormat">System.Windows.Media.PixelFormat</param>
|
||||||
|
/// <returns>System.Drawing.Imaging.PixelFormat</returns>
|
||||||
|
/// <exception cref="NotSupportedException"></exception>
|
||||||
|
public static PixelFormat Map(this System.Windows.Media.PixelFormat pixelFormat)
|
||||||
|
{
|
||||||
|
if (pixelFormat == PixelFormats.Bgra32)
|
||||||
|
{
|
||||||
|
return PixelFormat.Format32bppArgb;
|
||||||
|
}
|
||||||
|
if (pixelFormat == PixelFormats.Bgr24)
|
||||||
|
{
|
||||||
|
return PixelFormat.Format24bppRgb;
|
||||||
|
}
|
||||||
|
if (pixelFormat == PixelFormats.Bgr32)
|
||||||
|
{
|
||||||
|
return PixelFormat.Format32bppRgb;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NotSupportedException($"Can't map {pixelFormat}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert a Bitmap to a BitmapSource
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bitmap">Bitmap</param>
|
||||||
|
/// <returns>BitmapSource</returns>
|
||||||
|
public static BitmapSource ToBitmapSource(this Bitmap bitmap)
|
||||||
|
{
|
||||||
|
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
||||||
|
|
||||||
|
BitmapSource bitmapSource;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bitmapSource = BitmapSource.Create(
|
||||||
|
bitmapData.Width, bitmapData.Height,
|
||||||
|
bitmap.HorizontalResolution, bitmap.VerticalResolution,
|
||||||
|
bitmap.PixelFormat.Map(), null,
|
||||||
|
bitmapData.Scan0, bitmapData.Stride * bitmapData.Height, bitmapData.Stride);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
bitmap.UnlockBits(bitmapData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitmapSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert a BitmapSource to a Bitmap
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="bitmapSource">BitmapSource</param>
|
||||||
|
/// <returns>Bitmap</returns>
|
||||||
|
public static Bitmap ToBitmap(this BitmapSource bitmapSource)
|
||||||
|
{
|
||||||
|
var pixelFormat = bitmapSource.Format.Map();
|
||||||
|
|
||||||
|
Bitmap bitmap = new Bitmap(bitmapSource.PixelWidth, bitmapSource.PixelHeight, pixelFormat);
|
||||||
|
BitmapData data = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, pixelFormat);
|
||||||
|
bitmapSource.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
|
||||||
|
bitmap.UnlockBits(data);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -64,6 +64,16 @@ namespace Greenshot.Editor.Drawing
|
||||||
return newImage;
|
return newImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
_metafile?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
public override bool HasDefaultSize => true;
|
public override bool HasDefaultSize => true;
|
||||||
|
|
||||||
public override Size DefaultSize => new Size(_metafile.Width, _metafile.Height);
|
public override Size DefaultSize => new Size(_metafile.Width, _metafile.Height);
|
||||||
|
|
|
@ -28,12 +28,19 @@ namespace Greenshot.Editor
|
||||||
{
|
{
|
||||||
public static void Initialize()
|
public static void Initialize()
|
||||||
{
|
{
|
||||||
FileFormatHandlerRegistry.FileFormatHandlers.Add(new SvgFileFormatHandler());
|
// All generic things, like gif, png, jpg etc.
|
||||||
FileFormatHandlerRegistry.FileFormatHandlers.Add(new DefaultFileFormatHandler());
|
FileFormatHandlerRegistry.FileFormatHandlers.Add(new DefaultFileFormatHandler());
|
||||||
FileFormatHandlerRegistry.FileFormatHandlers.Add(new DibFileFormatHandler());
|
|
||||||
FileFormatHandlerRegistry.FileFormatHandlers.Add(new GreenshotFileFormatHandler());
|
FileFormatHandlerRegistry.FileFormatHandlers.Add(new GreenshotFileFormatHandler());
|
||||||
|
// For .svg support
|
||||||
|
FileFormatHandlerRegistry.FileFormatHandlers.Add(new SvgFileFormatHandler());
|
||||||
|
// For clipboard support
|
||||||
|
FileFormatHandlerRegistry.FileFormatHandlers.Add(new DibFileFormatHandler());
|
||||||
|
// .ico
|
||||||
FileFormatHandlerRegistry.FileFormatHandlers.Add(new IconFileFormatHandler());
|
FileFormatHandlerRegistry.FileFormatHandlers.Add(new IconFileFormatHandler());
|
||||||
|
// EMF & WMF
|
||||||
FileFormatHandlerRegistry.FileFormatHandlers.Add(new MetaFileFormatHandler());
|
FileFormatHandlerRegistry.FileFormatHandlers.Add(new MetaFileFormatHandler());
|
||||||
|
// JPG XR
|
||||||
|
FileFormatHandlerRegistry.FileFormatHandlers.Add(new WmpFileFormatHandler());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using Greenshot.Base.Interfaces;
|
||||||
|
using Greenshot.Base.Interfaces.Drawing;
|
||||||
|
using Greenshot.Editor.Drawing;
|
||||||
|
|
||||||
|
namespace Greenshot.Editor.FileFormatHandlers
|
||||||
|
{
|
||||||
|
public abstract class AbstractFileFormatHandler : IFileFormatHandler
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Make sure we handle the input extension always the same, by "normalizing" it
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="extension">string</param>
|
||||||
|
/// <returns>string</returns>
|
||||||
|
protected string NormalizeExtension(string extension)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(extension))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
extension = extension.ToLowerInvariant();
|
||||||
|
return !extension.StartsWith(".") ? $".{extension}" : extension;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract string[] OurExtensions { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public virtual IEnumerable<string> SupportedExtensions(FileFormatHandlerActions fileFormatHandlerAction)
|
||||||
|
{
|
||||||
|
return OurExtensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public virtual bool Supports(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
||||||
|
{
|
||||||
|
return OurExtensions.Contains(NormalizeExtension(extension));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public virtual int PriorityFor(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
||||||
|
{
|
||||||
|
return int.MaxValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension);
|
||||||
|
public abstract bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default implementation taking the TryLoadFromStream image and placing it in an ImageContainer
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stream">Stream</param>
|
||||||
|
/// <param name="extension">string</param>
|
||||||
|
/// <param name="drawableContainer">IDrawableContainer out</param>
|
||||||
|
/// <param name="parentSurface">ISurface</param>
|
||||||
|
/// <returns>bool</returns>
|
||||||
|
public virtual bool TryLoadDrawableFromStream(Stream stream, string extension, out IDrawableContainer drawableContainer, ISurface parentSurface = null)
|
||||||
|
{
|
||||||
|
if (TryLoadFromStream(stream, extension, out var bitmap))
|
||||||
|
{
|
||||||
|
var imageContainer = new ImageContainer(parentSurface)
|
||||||
|
{
|
||||||
|
Image = bitmap
|
||||||
|
};
|
||||||
|
drawableContainer = imageContainer;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawableContainer = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,16 +19,11 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using Greenshot.Base.Core;
|
using Greenshot.Base.Core;
|
||||||
using Greenshot.Base.Core.FileFormatHandlers;
|
|
||||||
using Greenshot.Base.Interfaces;
|
using Greenshot.Base.Interfaces;
|
||||||
using Greenshot.Base.Interfaces.Drawing;
|
|
||||||
using Greenshot.Editor.Drawing;
|
|
||||||
|
|
||||||
namespace Greenshot.Editor.FileFormatHandlers
|
namespace Greenshot.Editor.FileFormatHandlers
|
||||||
{
|
{
|
||||||
|
@ -37,28 +32,10 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DefaultFileFormatHandler : AbstractFileFormatHandler, IFileFormatHandler
|
public class DefaultFileFormatHandler : AbstractFileFormatHandler, IFileFormatHandler
|
||||||
{
|
{
|
||||||
private static readonly string [] OurExtensions = { ".png", ".bmp", ".gif", ".jpg", ".jpeg", ".tiff", ".tif" };
|
protected override string[] OurExtensions { get; } = { ".png", ".bmp", ".gif", ".jpg", ".jpeg", ".tiff", ".tif" };
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IEnumerable<string> SupportedExtensions(FileFormatHandlerActions fileFormatHandlerAction)
|
public override bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension)
|
||||||
{
|
|
||||||
return OurExtensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool Supports(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
|
||||||
{
|
|
||||||
return OurExtensions.Contains(NormalizeExtension(extension));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public int PriorityFor(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
|
||||||
{
|
|
||||||
return int.MaxValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension)
|
|
||||||
{
|
{
|
||||||
ImageFormat imageFormat = NormalizeExtension(extension) switch
|
ImageFormat imageFormat = NormalizeExtension(extension) switch
|
||||||
{
|
{
|
||||||
|
@ -81,28 +58,11 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
public override bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
||||||
{
|
{
|
||||||
using var tmpImage = Image.FromStream(stream, true, true);
|
using var tmpImage = Image.FromStream(stream, true, true);
|
||||||
bitmap = ImageHelper.Clone(tmpImage, PixelFormat.Format32bppArgb);
|
bitmap = ImageHelper.Clone(tmpImage, PixelFormat.Format32bppArgb);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool TryLoadDrawableFromStream(Stream stream, string extension, out IDrawableContainer drawableContainer, ISurface surface = null)
|
|
||||||
{
|
|
||||||
if (TryLoadFromStream(stream, extension, out var bitmap))
|
|
||||||
{
|
|
||||||
var imageContainer = new ImageContainer(surface)
|
|
||||||
{
|
|
||||||
Image = bitmap
|
|
||||||
};
|
|
||||||
drawableContainer = imageContainer;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
drawableContainer = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,18 +20,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Greenshot.Base.Core;
|
using Greenshot.Base.Core;
|
||||||
using Greenshot.Base.Core.FileFormatHandlers;
|
|
||||||
using Greenshot.Base.Interfaces;
|
using Greenshot.Base.Interfaces;
|
||||||
using Greenshot.Base.Interfaces.Drawing;
|
|
||||||
using Greenshot.Base.UnmanagedHelpers;
|
using Greenshot.Base.UnmanagedHelpers;
|
||||||
using Greenshot.Editor.Drawing;
|
|
||||||
using log4net;
|
using log4net;
|
||||||
|
|
||||||
namespace Greenshot.Editor.FileFormatHandlers
|
namespace Greenshot.Editor.FileFormatHandlers
|
||||||
|
@ -43,29 +38,10 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
{
|
{
|
||||||
private const double DpiToPelsPerMeter = 39.3701;
|
private const double DpiToPelsPerMeter = 39.3701;
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(DibFileFormatHandler));
|
private static readonly ILog Log = LogManager.GetLogger(typeof(DibFileFormatHandler));
|
||||||
private static readonly string [] OurExtensions = { ".dib", ".format17" };
|
protected override string[] OurExtensions { get; } = { ".dib", ".format17" };
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IEnumerable<string> SupportedExtensions(FileFormatHandlerActions fileFormatHandlerAction)
|
public override bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension)
|
||||||
{
|
|
||||||
return OurExtensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool Supports(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
|
||||||
{
|
|
||||||
extension = NormalizeExtension(extension);
|
|
||||||
return OurExtensions.Contains(extension);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public int PriorityFor(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
|
||||||
{
|
|
||||||
return int.MaxValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension)
|
|
||||||
{
|
{
|
||||||
var dibBytes = ConvertToDib(bitmap);
|
var dibBytes = ConvertToDib(bitmap);
|
||||||
destination.Write(dibBytes, 0, dibBytes.Length);
|
destination.Write(dibBytes, 0, dibBytes.Length);
|
||||||
|
@ -73,7 +49,7 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
public override bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
||||||
{
|
{
|
||||||
byte[] dibBuffer = new byte[stream.Length];
|
byte[] dibBuffer = new byte[stream.Length];
|
||||||
_ = stream.Read(dibBuffer, 0, dibBuffer.Length);
|
_ = stream.Read(dibBuffer, 0, dibBuffer.Length);
|
||||||
|
@ -133,24 +109,6 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool TryLoadDrawableFromStream(Stream stream, string extension, out IDrawableContainer drawableContainer, ISurface surface = null)
|
|
||||||
{
|
|
||||||
if (TryLoadFromStream(stream, extension, out var bitmap))
|
|
||||||
{
|
|
||||||
var imageContainer = new ImageContainer(surface)
|
|
||||||
{
|
|
||||||
Image = bitmap
|
|
||||||
};
|
|
||||||
drawableContainer = imageContainer;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
drawableContainer = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts the Bitmap to a Device Independent Bitmap format of type BITFIELDS.
|
/// Converts the Bitmap to a Device Independent Bitmap format of type BITFIELDS.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -25,18 +25,16 @@ using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Greenshot.Base.Core;
|
using Greenshot.Base.Core;
|
||||||
using Greenshot.Base.Core.FileFormatHandlers;
|
|
||||||
using Greenshot.Base.Interfaces;
|
using Greenshot.Base.Interfaces;
|
||||||
using Greenshot.Base.Interfaces.Drawing;
|
|
||||||
|
|
||||||
namespace Greenshot.Editor.FileFormatHandlers
|
namespace Greenshot.Editor.FileFormatHandlers
|
||||||
{
|
{
|
||||||
public class GreenshotFileFormatHandler : AbstractFileFormatHandler, IFileFormatHandler
|
public class GreenshotFileFormatHandler : AbstractFileFormatHandler, IFileFormatHandler
|
||||||
{
|
{
|
||||||
private static readonly string[] OurExtensions = { ".greenshot" };
|
protected override string[] OurExtensions { get; } = { ".greenshot" };
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IEnumerable<string> SupportedExtensions(FileFormatHandlerActions fileFormatHandlerAction)
|
public override IEnumerable<string> SupportedExtensions(FileFormatHandlerActions fileFormatHandlerAction)
|
||||||
{
|
{
|
||||||
if (fileFormatHandlerAction == FileFormatHandlerActions.LoadDrawableFromStream)
|
if (fileFormatHandlerAction == FileFormatHandlerActions.LoadDrawableFromStream)
|
||||||
{
|
{
|
||||||
|
@ -47,12 +45,8 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool Supports(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
public override bool Supports(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
||||||
{
|
{
|
||||||
if (fileFormatHandlerAction == FileFormatHandlerActions.LoadDrawableFromStream)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (fileFormatHandlerAction == FileFormatHandlerActions.SaveToStream)
|
if (fileFormatHandlerAction == FileFormatHandlerActions.SaveToStream)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -61,29 +55,17 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
return OurExtensions.Contains(NormalizeExtension(extension));
|
return OurExtensions.Contains(NormalizeExtension(extension));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension)
|
||||||
/// <inheritdoc />
|
|
||||||
public int PriorityFor(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
|
||||||
{
|
{
|
||||||
return int.MaxValue;
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension)
|
public override bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
||||||
{
|
|
||||||
// TODO: Implement this
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
|
||||||
{
|
{
|
||||||
var surface = SimpleServiceProvider.Current.GetInstance<Func<ISurface>>().Invoke();
|
var surface = SimpleServiceProvider.Current.GetInstance<Func<ISurface>>().Invoke();
|
||||||
bitmap = (Bitmap)surface.GetImageForExport();
|
bitmap = (Bitmap)surface.GetImageForExport();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryLoadDrawableFromStream(Stream stream, string extension, out IDrawableContainer drawableContainer, ISurface parent = null)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,16 +20,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using Greenshot.Base.Core;
|
using Greenshot.Base.Core;
|
||||||
using Greenshot.Base.Core.FileFormatHandlers;
|
|
||||||
using Greenshot.Base.Interfaces;
|
using Greenshot.Base.Interfaces;
|
||||||
using Greenshot.Base.Interfaces.Drawing;
|
|
||||||
using Greenshot.Editor.Drawing;
|
|
||||||
using log4net;
|
using log4net;
|
||||||
|
|
||||||
namespace Greenshot.Editor.FileFormatHandlers
|
namespace Greenshot.Editor.FileFormatHandlers
|
||||||
|
@ -39,45 +34,18 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class IconFileFormatHandler : AbstractFileFormatHandler, IFileFormatHandler
|
public class IconFileFormatHandler : AbstractFileFormatHandler, IFileFormatHandler
|
||||||
{
|
{
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(ImageHelper));
|
private static readonly ILog Log = LogManager.GetLogger(typeof(IconFileFormatHandler));
|
||||||
|
|
||||||
private static readonly string[] OurExtensions = { ".ico" };
|
protected override string[] OurExtensions { get; } = { ".ico" };
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public IEnumerable<string> SupportedExtensions(FileFormatHandlerActions fileFormatHandlerAction)
|
|
||||||
{
|
|
||||||
if (fileFormatHandlerAction == FileFormatHandlerActions.SaveToStream)
|
|
||||||
{
|
|
||||||
return Enumerable.Empty<string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return OurExtensions;
|
public override bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension)
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool Supports(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
|
||||||
{
|
|
||||||
if (fileFormatHandlerAction == FileFormatHandlerActions.SaveToStream)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return OurExtensions.Contains(NormalizeExtension(extension));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public int PriorityFor(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
|
||||||
{
|
|
||||||
return int.MaxValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension)
|
|
||||||
{
|
{
|
||||||
// TODO: Implement this
|
// TODO: Implement this
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
public override bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
||||||
{
|
{
|
||||||
_ = stream.Seek(0, SeekOrigin.Current);
|
_ = stream.Seek(0, SeekOrigin.Current);
|
||||||
|
|
||||||
|
@ -115,23 +83,6 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool TryLoadDrawableFromStream(Stream stream, string extension, out IDrawableContainer drawableContainer, ISurface surface = null)
|
|
||||||
{
|
|
||||||
if (TryLoadFromStream(stream, extension, out var bitmap))
|
|
||||||
{
|
|
||||||
var imageContainer = new ImageContainer(surface)
|
|
||||||
{
|
|
||||||
Image = bitmap
|
|
||||||
};
|
|
||||||
drawableContainer = imageContainer;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
drawableContainer = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Based on: https://www.codeproject.com/KB/cs/IconExtractor.aspx
|
/// Based on: https://www.codeproject.com/KB/cs/IconExtractor.aspx
|
||||||
/// And a hint from: https://www.codeproject.com/KB/cs/IconLib.aspx
|
/// And a hint from: https://www.codeproject.com/KB/cs/IconLib.aspx
|
||||||
|
|
|
@ -25,7 +25,6 @@ using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Greenshot.Base.Core;
|
using Greenshot.Base.Core;
|
||||||
using Greenshot.Base.Core.FileFormatHandlers;
|
|
||||||
using Greenshot.Base.Interfaces;
|
using Greenshot.Base.Interfaces;
|
||||||
using Greenshot.Base.Interfaces.Drawing;
|
using Greenshot.Base.Interfaces.Drawing;
|
||||||
using Greenshot.Editor.Drawing;
|
using Greenshot.Editor.Drawing;
|
||||||
|
@ -37,10 +36,9 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MetaFileFormatHandler : AbstractFileFormatHandler, IFileFormatHandler
|
public class MetaFileFormatHandler : AbstractFileFormatHandler, IFileFormatHandler
|
||||||
{
|
{
|
||||||
private static readonly string [] OurExtensions = { ".wmf", ".emf" };
|
protected override string[] OurExtensions { get; } = { ".wmf", ".emf" };
|
||||||
|
|
||||||
/// <inheritdoc />
|
public override IEnumerable<string> SupportedExtensions(FileFormatHandlerActions fileFormatHandlerAction)
|
||||||
public IEnumerable<string> SupportedExtensions(FileFormatHandlerActions fileFormatHandlerAction)
|
|
||||||
{
|
{
|
||||||
if (fileFormatHandlerAction == FileFormatHandlerActions.SaveToStream)
|
if (fileFormatHandlerAction == FileFormatHandlerActions.SaveToStream)
|
||||||
{
|
{
|
||||||
|
@ -51,7 +49,7 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool Supports(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
public override bool Supports(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
||||||
{
|
{
|
||||||
if (fileFormatHandlerAction == FileFormatHandlerActions.SaveToStream)
|
if (fileFormatHandlerAction == FileFormatHandlerActions.SaveToStream)
|
||||||
{
|
{
|
||||||
|
@ -62,19 +60,13 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public int PriorityFor(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
public override bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension)
|
||||||
{
|
|
||||||
return int.MaxValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
public override bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -93,7 +85,7 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool TryLoadDrawableFromStream(Stream stream, string extension, out IDrawableContainer drawableContainer, ISurface surface = null)
|
public override bool TryLoadDrawableFromStream(Stream stream, string extension, out IDrawableContainer drawableContainer, ISurface surface = null)
|
||||||
{
|
{
|
||||||
if (Image.FromStream(stream, true, true) is Metafile metaFile)
|
if (Image.FromStream(stream, true, true) is Metafile metaFile)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
/*
|
|
||||||
* Greenshot - a free and open source screenshot tool
|
|
||||||
* Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
|
|
||||||
*
|
|
||||||
* For more information see: https://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 <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using Greenshot.Base.Interfaces;
|
|
||||||
using Greenshot.Base.Interfaces.Drawing;
|
|
||||||
|
|
||||||
namespace Greenshot.Editor.FileFormatHandlers
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// This can be an ImageSharp implementation
|
|
||||||
/// </summary>
|
|
||||||
public class PngFileFormatHandler : IFileFormatHandler
|
|
||||||
{
|
|
||||||
private static readonly string[] OurExtensions = { "png" };
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public IEnumerable<string> SupportedExtensions(FileFormatHandlerActions fileFormatHandlerAction)
|
|
||||||
{
|
|
||||||
if (fileFormatHandlerAction == FileFormatHandlerActions.LoadDrawableFromStream)
|
|
||||||
{
|
|
||||||
return Enumerable.Empty<string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return OurExtensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public bool Supports(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
|
||||||
{
|
|
||||||
if (fileFormatHandlerAction == FileFormatHandlerActions.LoadDrawableFromStream)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return OurExtensions.Contains(extension?.ToLowerInvariant());
|
|
||||||
}
|
|
||||||
/// <inheritdoc />
|
|
||||||
public int PriorityFor(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
|
||||||
{
|
|
||||||
return int.MaxValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
|
||||||
{
|
|
||||||
// TODO: Implement this
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension)
|
|
||||||
{
|
|
||||||
// TODO: Implement this
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryLoadDrawableFromStream(Stream stream, string extension, out IDrawableContainer drawableContainer, ISurface parent)
|
|
||||||
{
|
|
||||||
// TODO: Implement this
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -24,7 +24,6 @@ using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Greenshot.Base.Core.FileFormatHandlers;
|
|
||||||
using Greenshot.Base.Interfaces;
|
using Greenshot.Base.Interfaces;
|
||||||
using Greenshot.Base.Interfaces.Drawing;
|
using Greenshot.Base.Interfaces.Drawing;
|
||||||
using Greenshot.Editor.Drawing;
|
using Greenshot.Editor.Drawing;
|
||||||
|
@ -39,10 +38,10 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
public class SvgFileFormatHandler : AbstractFileFormatHandler, IFileFormatHandler
|
public class SvgFileFormatHandler : AbstractFileFormatHandler, IFileFormatHandler
|
||||||
{
|
{
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(SvgFileFormatHandler));
|
private static readonly ILog Log = LogManager.GetLogger(typeof(SvgFileFormatHandler));
|
||||||
private static readonly string[] OurExtensions = { ".svg" };
|
protected override string[] OurExtensions { get; } = { ".svg" };
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IEnumerable<string> SupportedExtensions(FileFormatHandlerActions fileFormatHandlerAction)
|
public override IEnumerable<string> SupportedExtensions(FileFormatHandlerActions fileFormatHandlerAction)
|
||||||
{
|
{
|
||||||
if (fileFormatHandlerAction == FileFormatHandlerActions.SaveToStream)
|
if (fileFormatHandlerAction == FileFormatHandlerActions.SaveToStream)
|
||||||
{
|
{
|
||||||
|
@ -53,7 +52,7 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool Supports(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
public override bool Supports(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
||||||
{
|
{
|
||||||
if (fileFormatHandlerAction == FileFormatHandlerActions.SaveToStream)
|
if (fileFormatHandlerAction == FileFormatHandlerActions.SaveToStream)
|
||||||
{
|
{
|
||||||
|
@ -62,13 +61,8 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
|
|
||||||
return OurExtensions.Contains(NormalizeExtension(extension));
|
return OurExtensions.Contains(NormalizeExtension(extension));
|
||||||
}
|
}
|
||||||
/// <inheritdoc />
|
|
||||||
public int PriorityFor(FileFormatHandlerActions fileFormatHandlerAction, string extension)
|
|
||||||
{
|
|
||||||
return int.MaxValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
public override bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
||||||
{
|
{
|
||||||
var svgDocument = SvgDocument.Open<SvgDocument>(stream);
|
var svgDocument = SvgDocument.Open<SvgDocument>(stream);
|
||||||
|
|
||||||
|
@ -85,13 +79,13 @@ namespace Greenshot.Editor.FileFormatHandlers
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension)
|
public override bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension)
|
||||||
{
|
{
|
||||||
// TODO: Implement this
|
// TODO: Implement this
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryLoadDrawableFromStream(Stream stream, string extension, out IDrawableContainer drawableContainer, ISurface parent = null)
|
public override bool TryLoadDrawableFromStream(Stream stream, string extension, out IDrawableContainer drawableContainer, ISurface parent = null)
|
||||||
{
|
{
|
||||||
var svgDocument = SvgDocument.Open<SvgDocument>(stream);
|
var svgDocument = SvgDocument.Open<SvgDocument>(stream);
|
||||||
if (svgDocument == null)
|
if (svgDocument == null)
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* Greenshot - a free and open source screenshot tool
|
||||||
|
* Copyright (C) 2007-2021 Thomas Braun, Jens Klingen, Robin Krom
|
||||||
|
*
|
||||||
|
* For more information see: https://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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using Greenshot.Base.Interfaces;
|
||||||
|
using Greenshot.Base.Core;
|
||||||
|
|
||||||
|
namespace Greenshot.Editor.FileFormatHandlers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This is the default .NET bitmap file format handler
|
||||||
|
/// </summary>
|
||||||
|
public class WmpFileFormatHandler : AbstractFileFormatHandler, IFileFormatHandler
|
||||||
|
{
|
||||||
|
protected override string[] OurExtensions { get; } = { ".jxr", ".wdp", ".wmp" };
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool TrySaveToStream(Bitmap bitmap, Stream destination, string extension)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var bitmapSource = bitmap.ToBitmapSource();
|
||||||
|
var bitmapFrame = BitmapFrame.Create(bitmapSource);
|
||||||
|
var jpegXrEncoder = new WmpBitmapEncoder();
|
||||||
|
jpegXrEncoder.Frames.Add(bitmapFrame);
|
||||||
|
// TODO: Support supplying a quality
|
||||||
|
//jpegXrEncoder.ImageQualityLevel = quality / 100f;
|
||||||
|
jpegXrEncoder.Save(destination);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override bool TryLoadFromStream(Stream stream, string extension, out Bitmap bitmap)
|
||||||
|
{
|
||||||
|
var decoder = new WmpBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
|
||||||
|
var bitmapSource = decoder.Frames[0];
|
||||||
|
bitmap = bitmapSource.ToBitmap();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue