mirror of
https://github.com/greenshot/greenshot
synced 2025-07-31 04:00:13 -07:00
Merge remote-tracking branch 'remotes/origin/master' into release/1.2.9
This commit is contained in:
commit
0323705513
276 changed files with 5382 additions and 3666 deletions
|
@ -53,7 +53,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
/// <param name="graphics"></param>
|
||||
/// <returns>SafeDeviceContextHandle</returns>
|
||||
public static SafeDeviceContextHandle GetSafeDeviceContext(this Graphics graphics) {
|
||||
return SafeDeviceContextHandle.fromGraphics(graphics);
|
||||
return SafeDeviceContextHandle.FromGraphics(graphics);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
/// </summary>
|
||||
public abstract class SafeObjectHandle : SafeHandleZeroOrMinusOneIsInvalid {
|
||||
[DllImport("gdi32", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DeleteObject(IntPtr hObject);
|
||||
|
||||
protected SafeObjectHandle(bool ownsHandle) : base(ownsHandle) {
|
||||
|
@ -76,8 +77,14 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
/// A hbitmap SafeHandle implementation
|
||||
/// </summary>
|
||||
public class SafeHBitmapHandle : SafeObjectHandle {
|
||||
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
[SecurityCritical]
|
||||
private SafeHBitmapHandle() : base(true) {
|
||||
public SafeHBitmapHandle() : base(true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
|
@ -90,8 +97,12 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
/// A hRegion SafeHandle implementation
|
||||
/// </summary>
|
||||
public class SafeRegionHandle : SafeObjectHandle {
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
[SecurityCritical]
|
||||
private SafeRegionHandle() : base(true) {
|
||||
public SafeRegionHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
|
@ -104,8 +115,12 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
/// A dibsection SafeHandle implementation
|
||||
/// </summary>
|
||||
public class SafeDibSectionHandle : SafeObjectHandle {
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
[SecurityCritical]
|
||||
private SafeDibSectionHandle() : base(true) {
|
||||
public SafeDibSectionHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
|
@ -122,20 +137,23 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
[DllImport("gdi32", SetLastError = true)]
|
||||
private static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
|
||||
|
||||
private SafeHandle hdc;
|
||||
|
||||
private readonly SafeHandle _hdc;
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
[SecurityCritical]
|
||||
private SafeSelectObjectHandle() : base(true) {
|
||||
public SafeSelectObjectHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public SafeSelectObjectHandle(SafeDCHandle hdc, SafeHandle newHandle) : base(true) {
|
||||
this.hdc = hdc;
|
||||
_hdc = hdc;
|
||||
SetHandle(SelectObject(hdc.DangerousGetHandle(), newHandle.DangerousGetHandle()));
|
||||
}
|
||||
|
||||
protected override bool ReleaseHandle() {
|
||||
SelectObject(hdc.DangerousGetHandle(), handle);
|
||||
SelectObject(_hdc.DangerousGetHandle(), handle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -149,10 +167,15 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
/// </summary>
|
||||
public class SafeCompatibleDCHandle : SafeDCHandle {
|
||||
[DllImport("gdi32", SetLastError = true)]
|
||||
private static extern bool DeleteDC(IntPtr hDC);
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool DeleteDC(IntPtr hDC);
|
||||
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
[SecurityCritical]
|
||||
private SafeCompatibleDCHandle() : base(true) {
|
||||
public SafeCompatibleDCHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
|
@ -173,20 +196,24 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
/// A DeviceContext SafeHandle implementation
|
||||
/// </summary>
|
||||
public class SafeDeviceContextHandle : SafeDCHandle {
|
||||
private Graphics graphics = null;
|
||||
|
||||
private readonly Graphics _graphics;
|
||||
|
||||
/// <summary>
|
||||
/// Needed for marshalling return values
|
||||
/// </summary>
|
||||
[SecurityCritical]
|
||||
private SafeDeviceContextHandle() : base(true) {
|
||||
public SafeDeviceContextHandle() : base(true)
|
||||
{
|
||||
}
|
||||
|
||||
[SecurityCritical]
|
||||
public SafeDeviceContextHandle(Graphics graphics, IntPtr preexistingHandle) : base(true) {
|
||||
this.graphics = graphics;
|
||||
_graphics = graphics;
|
||||
SetHandle(preexistingHandle);
|
||||
}
|
||||
|
||||
protected override bool ReleaseHandle() {
|
||||
graphics.ReleaseHdc(handle);
|
||||
_graphics.ReleaseHdc(handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -194,7 +221,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
return new SafeSelectObjectHandle(this, newHandle);
|
||||
}
|
||||
|
||||
public static SafeDeviceContextHandle fromGraphics(Graphics graphics) {
|
||||
public static SafeDeviceContextHandle FromGraphics(Graphics graphics) {
|
||||
return new SafeDeviceContextHandle(graphics, graphics.GetHdc());
|
||||
}
|
||||
}
|
||||
|
@ -219,41 +246,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
public static extern uint GetPixel(SafeHandle hdc, int nXPos, int nYPos);
|
||||
[DllImport("gdi32", SetLastError=true)]
|
||||
public static extern int GetDeviceCaps(SafeHandle hdc, DeviceCaps nIndex);
|
||||
|
||||
/// <summary>
|
||||
/// StretchBlt extension for the graphics object
|
||||
/// Doesn't work?
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
/// <param name="source"></param>
|
||||
public static void StretchBlt(this Graphics target, Bitmap sourceBitmap, Rectangle source, Rectangle destination) {
|
||||
using (SafeDeviceContextHandle targetDC = target.GetSafeDeviceContext()) {
|
||||
using (SafeCompatibleDCHandle safeCompatibleDCHandle = CreateCompatibleDC(targetDC)) {
|
||||
using (SafeHBitmapHandle hBitmapHandle = new SafeHBitmapHandle(sourceBitmap.GetHbitmap())) {
|
||||
using (safeCompatibleDCHandle.SelectObject(hBitmapHandle)) {
|
||||
StretchBlt(targetDC, destination.X, destination.Y, destination.Width, destination.Height, safeCompatibleDCHandle, source.Left, source.Top, source.Width, source.Height, CopyPixelOperation.SourceCopy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bitblt extension for the graphics object
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
/// <param name="source"></param>
|
||||
public static void BitBlt(this Graphics target, Bitmap sourceBitmap, Rectangle source, Point destination, CopyPixelOperation rop) {
|
||||
using (SafeDeviceContextHandle targetDC = target.GetSafeDeviceContext()) {
|
||||
using (SafeCompatibleDCHandle safeCompatibleDCHandle = CreateCompatibleDC(targetDC)) {
|
||||
using (SafeHBitmapHandle hBitmapHandle = new SafeHBitmapHandle(sourceBitmap.GetHbitmap())) {
|
||||
using (safeCompatibleDCHandle.SelectObject(hBitmapHandle)) {
|
||||
BitBlt(targetDC, destination.X, destination.Y, source.Width, source.Height, safeCompatibleDCHandle, source.Left, source.Top, rop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
|
@ -378,10 +370,12 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
bV5BlueMask = (uint)255;
|
||||
bV5AlphaMask = (uint)255 << 24;
|
||||
bV5CSType = 1934772034; // sRGB
|
||||
bV5Endpoints = new CIEXYZTRIPLE();
|
||||
bV5Endpoints.ciexyzBlue = new CIEXYZ(0);
|
||||
bV5Endpoints.ciexyzGreen = new CIEXYZ(0);
|
||||
bV5Endpoints.ciexyzRed = new CIEXYZ(0);
|
||||
bV5Endpoints = new CIEXYZTRIPLE
|
||||
{
|
||||
ciexyzBlue = new CIEXYZ(0),
|
||||
ciexyzGreen = new CIEXYZ(0),
|
||||
ciexyzRed = new CIEXYZ(0)
|
||||
};
|
||||
bV5GammaRed = 0;
|
||||
bV5GammaGreen = 0;
|
||||
bV5GammaBlue = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue