diff options
author | sr55 <[email protected]> | 2018-05-06 19:41:30 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2018-05-06 19:41:30 +0100 |
commit | 369c1bb661d0ef1dd3fcd43379294519cb479765 (patch) | |
tree | 42abaeb60bad86fec270713844df08571c2a7cca /win/CS/HandBrake.ApplicationServices/Interop | |
parent | c14555897d3f3742c4e035c2d6653336dd2b9165 (diff) |
WinGui: Remove references to System.Drawing from Alpha.ApplicationServices. The WPF project now has a conversion utility to take the raw byte[] to convert to bitmapimage.
Diffstat (limited to 'win/CS/HandBrake.ApplicationServices/Interop')
3 files changed, 30 insertions, 30 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs index e398edda2..d8f432fc4 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs @@ -12,9 +12,6 @@ namespace HandBrake.ApplicationServices.Interop using System;
using System.Collections.Generic;
using System.Diagnostics;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
@@ -27,9 +24,7 @@ namespace HandBrake.ApplicationServices.Interop using HandBrake.ApplicationServices.Interop.Interfaces;
using HandBrake.ApplicationServices.Interop.Json.Encode;
using HandBrake.ApplicationServices.Interop.Json.Scan;
- using HandBrake.ApplicationServices.Interop.Json.Shared;
using HandBrake.ApplicationServices.Interop.Json.State;
- using HandBrake.ApplicationServices.Interop.Model;
using HandBrake.ApplicationServices.Interop.Model.Encoding;
using HandBrake.ApplicationServices.Interop.Model.Preview;
using HandBrake.ApplicationServices.Services.Logging;
@@ -38,8 +33,6 @@ namespace HandBrake.ApplicationServices.Interop using Newtonsoft.Json;
- using Size = HandBrake.ApplicationServices.Interop.Model.Size;
-
/// <summary>
/// A wrapper for a HandBrake instance.
/// </summary>
@@ -287,7 +280,7 @@ namespace HandBrake.ApplicationServices.Interop /// An image with the requested preview.
/// </returns>
[HandleProcessCorruptedStateExceptions]
- public Bitmap GetPreview(PreviewSettings settings, int previewNumber, bool deinterlace)
+ public RawPreviewData GetPreview(PreviewSettings settings, int previewNumber, bool deinterlace)
{
SourceTitle title = this.Titles.TitleList.FirstOrDefault(t => t.Index == settings.TitleNumber);
@@ -323,25 +316,7 @@ namespace HandBrake.ApplicationServices.Interop byte[] managedBuffer = new byte[imageBufferSize];
Marshal.Copy(image.plane[0].data, managedBuffer, 0, imageBufferSize);
- var bitmap = new Bitmap(image.width, image.height);
-
- BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, image.width, image.height), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
-
- IntPtr ptr = bitmapData.Scan0; // Pointer to the first pixel.
- for (int i = 0; i < image.height; i++)
- {
- try
- {
- Marshal.Copy(managedBuffer, i * stride_width, ptr, stride_width);
- ptr = IntPtr.Add(ptr, image.width * 4);
- }
- catch (Exception exc)
- {
- Debug.WriteLine(exc); // In theory, this will allow a partial image display if this happens. TODO add better logging of this.
- }
- }
-
- bitmap.UnlockBits(bitmapData);
+ RawPreviewData preview = new RawPreviewData(managedBuffer, stride_width, stride_height, image.width, image.height);
// Close the image so we don't leak memory.
IntPtr nativeJobPtrPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));
@@ -349,7 +324,7 @@ namespace HandBrake.ApplicationServices.Interop HBFunctions.hb_image_close(nativeJobPtrPtr);
Marshal.FreeHGlobal(nativeJobPtrPtr);
- return bitmap;
+ return preview;
}
/// <summary>
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Interfaces/IHandBrakeInstance.cs b/win/CS/HandBrake.ApplicationServices/Interop/Interfaces/IHandBrakeInstance.cs index 5080c20c2..3f61499b9 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/Interfaces/IHandBrakeInstance.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/Interfaces/IHandBrakeInstance.cs @@ -10,7 +10,6 @@ namespace HandBrake.ApplicationServices.Interop.Interfaces
{
using System;
- using System.Drawing;
using HandBrake.ApplicationServices.Interop.EventArgs;
using HandBrake.ApplicationServices.Interop.Json.Encode;
@@ -103,7 +102,7 @@ namespace HandBrake.ApplicationServices.Interop.Interfaces /// <returns>
/// An image with the requested preview.
/// </returns>
- Bitmap GetPreview(PreviewSettings job, int previewNumber, bool deinterlace);
+ RawPreviewData GetPreview(PreviewSettings job, int previewNumber, bool deinterlace);
/// <summary>
/// Pauses the current encode.
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Model/Preview/RawPreviewData.cs b/win/CS/HandBrake.ApplicationServices/Interop/Model/Preview/RawPreviewData.cs new file mode 100644 index 000000000..2da2dc52d --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Interop/Model/Preview/RawPreviewData.cs @@ -0,0 +1,26 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="RawPreviewData.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.ApplicationServices.Interop.Model.Preview +{ + public class RawPreviewData + { + public RawPreviewData(byte[] rawBitmapData, int strideWidth, int strideHeight, int width, int height) + { + this.RawBitmapData = rawBitmapData; + this.StrideWidth = strideWidth; + this.StrideHeight = strideHeight; + this.Width = width; + this.Height = height; + } + + public byte[] RawBitmapData { get; } + public int StrideWidth { get; } + public int StrideHeight { get; } + public int Width { get; } + public int Height { get; } + } +} |