summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsr55 <[email protected]>2018-05-06 19:41:30 +0100
committersr55 <[email protected]>2018-05-06 19:41:30 +0100
commit369c1bb661d0ef1dd3fcd43379294519cb479765 (patch)
tree42abaeb60bad86fec270713844df08571c2a7cca
parentc14555897d3f3742c4e035c2d6653336dd2b9165 (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.
-rw-r--r--win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj2
-rw-r--r--win/CS/HandBrake.ApplicationServices/Interop/HandBrakeInstance.cs31
-rw-r--r--win/CS/HandBrake.ApplicationServices/Interop/Interfaces/IHandBrakeInstance.cs3
-rw-r--r--win/CS/HandBrake.ApplicationServices/Interop/Model/Preview/RawPreviewData.cs26
-rw-r--r--win/CS/HandBrakeWPF/Services/Scan/LibScan.cs3
-rw-r--r--win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs30
6 files changed, 63 insertions, 32 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
index 43f64e0c2..a3f7a4b41 100644
--- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
+++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
@@ -43,7 +43,6 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
- <Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
@@ -117,6 +116,7 @@
<Compile Include="Interop\Model\Encoding\DeinterlaceFilter.cs" />
<Compile Include="Interop\Model\Encoding\HBPresetTune.cs" />
<Compile Include="Interop\Model\Encoding\Sharpen.cs" />
+ <Compile Include="Interop\Model\Preview\RawPreviewData.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Interop\Json\Scan\SourceAudioTrack.cs" />
<Compile Include="Interop\Json\Scan\SourceChapter.cs" />
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; }
+ }
+}
diff --git a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs
index 7558bc163..bb2703903 100644
--- a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs
+++ b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs
@@ -207,7 +207,8 @@ namespace HandBrakeWPF.Services.Scan
PixelAspectY = job.PixelAspectY
};
- bitmapImage = BitmapUtilities.ConvertToBitmapImage(this.instance.GetPreview(settings, preview, job.DeinterlaceFilter != DeinterlaceFilter.Off));
+ var bitmapData = this.instance.GetPreview(settings, preview, job.DeinterlaceFilter != DeinterlaceFilter.Off);
+ bitmapImage = BitmapUtilities.ConvertToBitmapImage(BitmapUtilities.ConvertByteArrayToBitmap(bitmapData));
}
catch (AccessViolationException e)
{
diff --git a/win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs b/win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs
index bc0f30061..0f5b64d53 100644
--- a/win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs
+++ b/win/CS/HandBrakeWPF/Utilities/BitmapUtilities.cs
@@ -9,11 +9,16 @@
namespace HandBrakeWPF.Utilities
{
+ using System;
+ using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
+ using System.Runtime.InteropServices;
using System.Windows.Media.Imaging;
+ using HandBrake.ApplicationServices.Interop.Model.Preview;
+
/// <summary>
/// The bitmap utilities.
/// </summary>
@@ -52,5 +57,30 @@ namespace HandBrakeWPF.Utilities
return wpfBitmap;
}
}
+
+ public static Bitmap ConvertByteArrayToBitmap(RawPreviewData previewData)
+ {
+ var bitmap = new Bitmap(previewData.Width, previewData.Height);
+
+ BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, previewData.Width, previewData.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
+
+ IntPtr ptr = bitmapData.Scan0; // Pointer to the first pixel.
+ for (int i = 0; i < previewData.Height; i++)
+ {
+ try
+ {
+ Marshal.Copy(previewData.RawBitmapData, i * previewData.StrideWidth, ptr, previewData.StrideWidth);
+ ptr = IntPtr.Add(ptr, previewData.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);
+
+ return bitmap;
+ }
}
}