Creating a branch 1.1 where I will try to make the 1.1.7 build available, this means I need to merge some changes from 2.0 to here.

This commit is contained in:
RKrom 2013-12-04 17:46:02 +01:00
commit a03bc31aef
247 changed files with 6986 additions and 8233 deletions

View file

@ -189,8 +189,10 @@ namespace GreenshotPlugin.Core {
break;
case ToolStripDropDownCloseReason.Keyboard:
// Dispose as the close is clicked
surface.Dispose();
surface = null;
if (!captureDetails.HasDestination("Editor")) {
surface.Dispose();
surface = null;
}
break;
default:
eventArgs.Cancel = true;
@ -209,7 +211,6 @@ namespace GreenshotPlugin.Core {
if (clickedDestination == null) {
return;
}
bool isEditor = "Editor".Equals(clickedDestination.Designation);
menu.Tag = clickedDestination.Designation;
// Export
exportInformation = clickedDestination.ExportCapture(true, surface, captureDetails);
@ -218,8 +219,8 @@ namespace GreenshotPlugin.Core {
// close menu if the destination wasn't the editor
menu.Close();
// Cleanup surface, only if the destination wasn't the editor
if (!isEditor) {
// Cleanup surface, only if there is no editor in the destinations and we didn't export to the editor
if (!captureDetails.HasDestination("Editor") && !"Editor".Equals(clickedDestination.Designation)) {
surface.Dispose();
surface = null;
}
@ -245,9 +246,10 @@ namespace GreenshotPlugin.Core {
closeItem.Click += delegate {
// This menu entry is the close itself, we can dispose the surface
menu.Close();
// Dispose as the close is clicked
surface.Dispose();
surface = null;
if (!captureDetails.HasDestination("Editor")) {
surface.Dispose();
surface = null;
}
};
menu.Items.Add(closeItem);

View file

@ -346,6 +346,7 @@ EndSelection:<<<<<<<4
returnImage = GetImageFormat(currentFormat, dataObject);
}
if (returnImage != null) {
ImageHelper.Orientate(returnImage);
return returnImage;
}
} else {
@ -416,9 +417,6 @@ EndSelection:<<<<<<<4
MemoryStream imageStream = GetFromDataObject(dataObject, format) as MemoryStream;
if (isValidStream(imageStream)) {
try {
using (FileStream fs = new FileStream(@"C:\Localdata\test.png", FileMode.OpenOrCreate)) {
imageStream.WriteTo(fs);
}
imageStream.Seek(0, SeekOrigin.Begin);
using (Image tmpImage = Image.FromStream(imageStream, true, true)) {
if (tmpImage != null) {

View file

@ -246,6 +246,9 @@ namespace GreenshotPlugin.Core {
[IniProperty("LastSaveWithVersion", Description = "Version of Greenshot which created this .ini")]
public string LastSaveWithVersion;
[IniProperty("ProcessEXIFOrientation", Description = "When reading images from files or clipboard, use the EXIF information to correct the orientation", DefaultValue = "True")]
public bool ProcessEXIFOrientation;
// Specifies what THIS build is
public BuildStates BuildState = BuildStates.RELEASE;

View file

@ -31,16 +31,78 @@ using Greenshot.Plugin;
using Greenshot.Core;
namespace GreenshotPlugin.Core {
internal enum ExifOrientations : byte {
Unknown = 0,
TopLeft = 1,
TopRight = 2,
BottomRight = 3,
BottomLeft = 4,
LeftTop = 5,
RightTop = 6,
RightBottom = 7,
LeftBottom = 8,
}
/// <summary>
/// Description of ImageHelper.
/// </summary>
public static class ImageHelper {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ImageHelper));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private const int EXIF_ORIENTATION_ID = 0x0112;
// This delegate makes it possible that a plug-in delivers a quicker Blur implementation
public delegate void BlurDelegate(Bitmap bitmap, int radius);
public static BlurDelegate BlurReplacement;
/// <summary>
/// Make sure the image is orientated correctly
/// </summary>
/// <param name="image"></param>
public static void Orientate(Image image) {
if (!conf.ProcessEXIFOrientation) {
return;
}
try {
// Get the index of the orientation property.
int orientation_index = Array.IndexOf(image.PropertyIdList, EXIF_ORIENTATION_ID);
// If there is no such property, return Unknown.
if (orientation_index < 0) {
return;
}
PropertyItem item = image.GetPropertyItem(EXIF_ORIENTATION_ID);
ExifOrientations orientation = (ExifOrientations)item.Value[0];
// Orient the image.
switch (orientation) {
case ExifOrientations.Unknown:
case ExifOrientations.TopLeft:
break;
case ExifOrientations.TopRight:
image.RotateFlip(RotateFlipType.RotateNoneFlipX);
break;
case ExifOrientations.BottomRight:
image.RotateFlip(RotateFlipType.Rotate180FlipNone);
break;
case ExifOrientations.BottomLeft:
image.RotateFlip(RotateFlipType.RotateNoneFlipY);
break;
case ExifOrientations.LeftTop:
image.RotateFlip(RotateFlipType.Rotate90FlipX);
break;
case ExifOrientations.RightTop:
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
break;
case ExifOrientations.RightBottom:
image.RotateFlip(RotateFlipType.Rotate90FlipY);
break;
case ExifOrientations.LeftBottom:
image.RotateFlip(RotateFlipType.Rotate270FlipNone);
break;
}
// Set the orientation to be normal, as we rotated the image.
item.Value[0] = (byte)ExifOrientations.TopLeft;
image.SetPropertyItem(item);
} catch (Exception orientEx) {
LOG.Warn("Problem orientating the image: ", orientEx);
}
}
/// <summary>
/// Create a thumbnail from an image
@ -247,6 +309,8 @@ namespace GreenshotPlugin.Core {
if (fileImage != null) {
LOG.InfoFormat("Information about file {0}: {1}x{2}-{3} Resolution {4}x{5}", filename, fileImage.Width, fileImage.Height, fileImage.PixelFormat, fileImage.HorizontalResolution, fileImage.VerticalResolution);
}
// Make sure the orientation is set correctly so Greenshot can process the image correctly
ImageHelper.Orientate(fileImage);
return fileImage;
}
@ -746,13 +810,12 @@ namespace GreenshotPlugin.Core {
shadowSize++;
}
bool useGDIBlur = GDIplus.isBlurPossible(shadowSize);
bool useBlurDelegate = BlurReplacement != null;
// Create "mask" for the shadow
ColorMatrix maskMatrix = new ColorMatrix();
maskMatrix.Matrix00 = 0;
maskMatrix.Matrix11 = 0;
maskMatrix.Matrix22 = 0;
if (useGDIBlur || useBlurDelegate) {
if (useGDIBlur) {
maskMatrix.Matrix33 = darkness + 0.1f;
} else {
maskMatrix.Matrix33 = darkness;
@ -761,9 +824,7 @@ namespace GreenshotPlugin.Core {
ApplyColorMatrix((Bitmap)sourceBitmap, Rectangle.Empty, returnImage, shadowRectangle, maskMatrix);
// blur "shadow", apply to whole new image
if (useBlurDelegate) {
BlurReplacement(returnImage, shadowSize+1);
} else if (useGDIBlur) {
if (useGDIBlur) {
// Use GDI Blur
Rectangle newImageRectangle = new Rectangle(0, 0, returnImage.Width, returnImage.Height);
GDIplus.ApplyBlur(returnImage, newImageRectangle, shadowSize+1, false);

View file

@ -104,7 +104,6 @@ namespace GreenshotPlugin.Core {
CurrentLanguage = coreConfig.Language;
if (CurrentLanguage != null && CurrentLanguage != coreConfig.Language) {
coreConfig.Language = CurrentLanguage;
IniConfig.Save();
}
}
@ -113,7 +112,6 @@ namespace GreenshotPlugin.Core {
CurrentLanguage = DEFAULT_LANGUAGE;
if (CurrentLanguage != null) {
coreConfig.Language = CurrentLanguage;
IniConfig.Save();
}
}