mirror of
https://github.com/greenshot/greenshot
synced 2025-07-14 09:03:44 -07:00
Made resize work, cleaned up code so it should be easier to port the changes to 2.x
This commit is contained in:
parent
5cb877f8c8
commit
aced477cef
8 changed files with 446 additions and 474 deletions
|
@ -68,7 +68,7 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
}
|
||||
|
||||
public override bool hasContextMenu {
|
||||
public override bool HasContextMenu {
|
||||
get {
|
||||
// No context menu for the CropContainer
|
||||
return false;
|
||||
|
|
|
@ -43,10 +43,10 @@ namespace Greenshot.Drawing {
|
|||
/// OnPropertyChanged whenever a public property has been changed.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public abstract class DrawableContainer : AbstractFieldHolderWithChildren, INotifyPropertyChanged, IDrawableContainer {
|
||||
public abstract class DrawableContainer : AbstractFieldHolderWithChildren, IDrawableContainer {
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(DrawableContainer));
|
||||
protected static readonly EditorConfiguration editorConfig = IniConfig.GetIniSection<EditorConfiguration>();
|
||||
private bool _isMadeUndoable = false;
|
||||
protected static readonly EditorConfiguration EditorConfig = IniConfig.GetIniSection<EditorConfiguration>();
|
||||
private bool _isMadeUndoable;
|
||||
|
||||
protected EditStatus _defaultEditMode = EditStatus.DRAWING;
|
||||
public EditStatus DefaultEditMode {
|
||||
|
@ -61,20 +61,22 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing) {
|
||||
if (disposing) {
|
||||
if (_grippers != null) {
|
||||
for (int i = 0; i < _grippers.Length; i++) {
|
||||
if (_grippers[i] != null) {
|
||||
_grippers[i].Dispose();
|
||||
_grippers[i] = null;
|
||||
}
|
||||
}
|
||||
_grippers = null;
|
||||
}
|
||||
|
||||
FieldAggregator aggProps = _parent.FieldAggregator;
|
||||
aggProps.UnbindElement(this);
|
||||
if (!disposing) {
|
||||
return;
|
||||
}
|
||||
if (_grippers != null) {
|
||||
for (int i = 0; i < _grippers.Length; i++) {
|
||||
if (_grippers[i] == null) {
|
||||
continue;
|
||||
}
|
||||
_grippers[i].Dispose();
|
||||
_grippers[i] = null;
|
||||
}
|
||||
_grippers = null;
|
||||
}
|
||||
|
||||
FieldAggregator aggProps = _parent.FieldAggregator;
|
||||
aggProps.UnbindElement(this);
|
||||
}
|
||||
|
||||
~DrawableContainer() {
|
||||
|
@ -82,10 +84,10 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
|
||||
[NonSerialized]
|
||||
private PropertyChangedEventHandler propertyChanged;
|
||||
private PropertyChangedEventHandler _propertyChanged;
|
||||
public event PropertyChangedEventHandler PropertyChanged {
|
||||
add { propertyChanged += value; }
|
||||
remove{ propertyChanged -= value; }
|
||||
add { _propertyChanged += value; }
|
||||
remove{ _propertyChanged -= value; }
|
||||
}
|
||||
|
||||
public List<IFilter> Filters {
|
||||
|
@ -108,7 +110,7 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
[NonSerialized]
|
||||
protected Gripper[] _grippers;
|
||||
private bool layoutSuspended = false;
|
||||
private bool _layoutSuspended;
|
||||
|
||||
[NonSerialized]
|
||||
private Gripper _targetGripper;
|
||||
|
@ -120,7 +122,7 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
|
||||
[NonSerialized]
|
||||
private bool _selected = false;
|
||||
private bool _selected;
|
||||
public bool Selected {
|
||||
get {return _selected;}
|
||||
set {
|
||||
|
@ -141,47 +143,51 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
|
||||
|
||||
private int _left = 0;
|
||||
private int _left;
|
||||
public int Left {
|
||||
get { return _left; }
|
||||
set {
|
||||
if(value != _left) {
|
||||
_left = value;
|
||||
DoLayout();
|
||||
if (value == _left) {
|
||||
return;
|
||||
}
|
||||
_left = value;
|
||||
DoLayout();
|
||||
}
|
||||
}
|
||||
|
||||
private int _top = 0;
|
||||
private int _top;
|
||||
public int Top {
|
||||
get { return _top; }
|
||||
set {
|
||||
if(value != _top) {
|
||||
_top = value;
|
||||
DoLayout();
|
||||
if (value == _top) {
|
||||
return;
|
||||
}
|
||||
_top = value;
|
||||
DoLayout();
|
||||
}
|
||||
}
|
||||
|
||||
private int _width = 0;
|
||||
private int _width;
|
||||
public int Width {
|
||||
get { return _width; }
|
||||
set {
|
||||
if(value != _width) {
|
||||
_width = value;
|
||||
DoLayout();
|
||||
if (value == _width) {
|
||||
return;
|
||||
}
|
||||
_width = value;
|
||||
DoLayout();
|
||||
}
|
||||
}
|
||||
|
||||
private int _height = 0;
|
||||
private int _height;
|
||||
public int Height {
|
||||
get { return _height; }
|
||||
set {
|
||||
if(value != _height) {
|
||||
_height = value;
|
||||
DoLayout();
|
||||
if (value == _height) {
|
||||
return;
|
||||
}
|
||||
_height = value;
|
||||
DoLayout();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,46 +195,50 @@ namespace Greenshot.Drawing {
|
|||
get {
|
||||
return new Point(_left, _top);
|
||||
}
|
||||
set {
|
||||
_left = value.X;
|
||||
_top = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
public Size Size {
|
||||
get {
|
||||
return new Size(_width, _height);
|
||||
}
|
||||
set {
|
||||
_width = value.Width;
|
||||
_height = value.Height;
|
||||
}
|
||||
}
|
||||
|
||||
[NonSerialized]
|
||||
/// <summary>
|
||||
/// will store current bounds of this DrawableContainer before starting a resize
|
||||
/// </summary>
|
||||
// will store current bounds of this DrawableContainer before starting a resize
|
||||
private Rectangle _boundsBeforeResize = Rectangle.Empty;
|
||||
|
||||
[NonSerialized]
|
||||
/// <summary>
|
||||
/// "workbench" rectangle - used for calculatoing bounds during resizing (to be applied to this DrawableContainer afterwards)
|
||||
/// </summary>
|
||||
// "workbench" rectangle - used for calculatoing bounds during resizing (to be applied to this DrawableContainer afterwards)
|
||||
private RectangleF _boundsAfterResize = RectangleF.Empty;
|
||||
|
||||
public Rectangle Bounds {
|
||||
get { return GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); }
|
||||
set {
|
||||
Left = round(value.Left);
|
||||
Top = round(value.Top);
|
||||
Width = round(value.Width);
|
||||
Height = round(value.Height);
|
||||
Left = Round(value.Left);
|
||||
Top = Round(value.Top);
|
||||
Width = Round(value.Width);
|
||||
Height = Round(value.Height);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ApplyBounds(RectangleF newBounds) {
|
||||
Left = round(newBounds.Left);
|
||||
Top = round(newBounds.Top);
|
||||
Width = round(newBounds.Width);
|
||||
Height = round(newBounds.Height);
|
||||
Left = Round(newBounds.Left);
|
||||
Top = Round(newBounds.Top);
|
||||
Width = Round(newBounds.Width);
|
||||
Height = Round(newBounds.Height);
|
||||
}
|
||||
|
||||
public DrawableContainer(Surface parent) {
|
||||
InitializeFields();
|
||||
this._parent = parent;
|
||||
_parent = parent;
|
||||
InitControls();
|
||||
}
|
||||
|
||||
|
@ -240,19 +250,13 @@ namespace Greenshot.Drawing {
|
|||
RemoveChild(filter);
|
||||
}
|
||||
|
||||
private int round(float f) {
|
||||
private static int Round(float f) {
|
||||
if(float.IsPositiveInfinity(f) || f>int.MaxValue/2) return int.MaxValue/2;
|
||||
if (float.IsNegativeInfinity(f) || f<int.MinValue/2) return int.MinValue/2;
|
||||
return (int)Math.Round(f);
|
||||
}
|
||||
|
||||
private int round(double d) {
|
||||
if(Double.IsPositiveInfinity(d) || d>int.MaxValue/2) return int.MaxValue/2;
|
||||
if (Double.IsNegativeInfinity(d) || d<int.MinValue/2) return int.MinValue/2;
|
||||
return (int)Math.Round(d);
|
||||
}
|
||||
|
||||
private bool accountForShadowChange = false;
|
||||
private bool _accountForShadowChange;
|
||||
public virtual Rectangle DrawingBounds {
|
||||
get {
|
||||
foreach(IFilter filter in Filters) {
|
||||
|
@ -268,8 +272,8 @@ namespace Greenshot.Drawing {
|
|||
int offset = lineThickness/2;
|
||||
|
||||
int shadow = 0;
|
||||
if (accountForShadowChange || (HasField(FieldType.SHADOW) && GetFieldValueAsBool(FieldType.SHADOW))){
|
||||
accountForShadowChange = false;
|
||||
if (_accountForShadowChange || (HasField(FieldType.SHADOW) && GetFieldValueAsBool(FieldType.SHADOW))){
|
||||
_accountForShadowChange = false;
|
||||
shadow += 10;
|
||||
}
|
||||
return new Rectangle(Bounds.Left-offset, Bounds.Top-offset, Bounds.Width+lineThickness+shadow, Bounds.Height+lineThickness+shadow);
|
||||
|
@ -335,9 +339,9 @@ namespace Greenshot.Drawing {
|
|||
Parent = _parent,
|
||||
Location = location
|
||||
};
|
||||
_targetGripper.MouseDown += gripperMouseDown;
|
||||
_targetGripper.MouseUp += gripperMouseUp;
|
||||
_targetGripper.MouseMove += gripperMouseMove;
|
||||
_targetGripper.MouseDown += GripperMouseDown;
|
||||
_targetGripper.MouseUp += GripperMouseUp;
|
||||
_targetGripper.MouseMove += GripperMouseMove;
|
||||
if (_parent != null) {
|
||||
_parent.Controls.Add(_targetGripper); // otherwise we'll attach them in switchParent
|
||||
}
|
||||
|
@ -349,9 +353,9 @@ namespace Greenshot.Drawing {
|
|||
for(int i=0; i<_grippers.Length; i++) {
|
||||
_grippers[i] = new Gripper();
|
||||
_grippers[i].Position = i;
|
||||
_grippers[i].MouseDown += gripperMouseDown;
|
||||
_grippers[i].MouseUp += gripperMouseUp;
|
||||
_grippers[i].MouseMove += gripperMouseMove;
|
||||
_grippers[i].MouseDown += GripperMouseDown;
|
||||
_grippers[i].MouseUp += GripperMouseUp;
|
||||
_grippers[i].MouseMove += GripperMouseMove;
|
||||
_grippers[i].Visible = false;
|
||||
_grippers[i].Parent = _parent;
|
||||
}
|
||||
|
@ -365,11 +369,11 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
|
||||
public void SuspendLayout() {
|
||||
layoutSuspended = true;
|
||||
_layoutSuspended = true;
|
||||
}
|
||||
|
||||
public void ResumeLayout() {
|
||||
layoutSuspended = false;
|
||||
_layoutSuspended = false;
|
||||
DoLayout();
|
||||
}
|
||||
|
||||
|
@ -377,9 +381,9 @@ namespace Greenshot.Drawing {
|
|||
if (_grippers == null) {
|
||||
return;
|
||||
}
|
||||
if (!layoutSuspended) {
|
||||
int[] xChoords = new int[]{Left-2,Left+Width/2-2,Left+Width-2};
|
||||
int[] yChoords = new int[]{Top-2,Top+Height/2-2,Top+Height-2};
|
||||
if (!_layoutSuspended) {
|
||||
int[] xChoords = {Left-2,Left+Width/2-2,Left+Width-2};
|
||||
int[] yChoords = {Top-2,Top+Height/2-2,Top+Height-2};
|
||||
|
||||
_grippers[Gripper.POSITION_TOP_LEFT].Left = xChoords[0]; _grippers[Gripper.POSITION_TOP_LEFT].Top = yChoords[0];
|
||||
_grippers[Gripper.POSITION_TOP_CENTER].Left = xChoords[1]; _grippers[Gripper.POSITION_TOP_CENTER].Top = yChoords[0];
|
||||
|
@ -412,11 +416,7 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
}
|
||||
|
||||
int mx;
|
||||
int my;
|
||||
private void gripperMouseDown(object sender, MouseEventArgs e) {
|
||||
mx = e.X;
|
||||
my = e.Y;
|
||||
private void GripperMouseDown(object sender, MouseEventArgs e) {
|
||||
Gripper originatingGripper = (Gripper)sender;
|
||||
if (originatingGripper != _targetGripper) {
|
||||
Status = EditStatus.RESIZING;
|
||||
|
@ -428,7 +428,7 @@ namespace Greenshot.Drawing {
|
|||
_isMadeUndoable = false;
|
||||
}
|
||||
|
||||
private void gripperMouseUp(object sender, MouseEventArgs e) {
|
||||
private void GripperMouseUp(object sender, MouseEventArgs e) {
|
||||
Gripper originatingGripper = (Gripper)sender;
|
||||
if (originatingGripper != _targetGripper) {
|
||||
_boundsBeforeResize = Rectangle.Empty;
|
||||
|
@ -439,7 +439,7 @@ namespace Greenshot.Drawing {
|
|||
Invalidate();
|
||||
}
|
||||
|
||||
private void gripperMouseMove(object sender, MouseEventArgs e) {
|
||||
private void GripperMouseMove(object sender, MouseEventArgs e) {
|
||||
Gripper originatingGripper = (Gripper)sender;
|
||||
int absX = originatingGripper.Left + e.X;
|
||||
int absY = originatingGripper.Top + e.Y;
|
||||
|
@ -473,18 +473,7 @@ namespace Greenshot.Drawing {
|
|||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
private void childLabelMouseMove(object sender, MouseEventArgs e) {
|
||||
if (Status.Equals(EditStatus.RESIZING)) {
|
||||
Invalidate();
|
||||
SuspendLayout();
|
||||
Left += e.X - mx;
|
||||
Top += e.Y - my;
|
||||
ResumeLayout();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool hasFilters {
|
||||
get {
|
||||
return Filters.Count > 0;
|
||||
|
@ -648,7 +637,9 @@ namespace Greenshot.Drawing {
|
|||
InitControls();
|
||||
}
|
||||
_parent = newParent;
|
||||
_parent.Controls.AddRange(_grippers);
|
||||
if (_grippers != null) {
|
||||
_parent.Controls.AddRange(_grippers);
|
||||
}
|
||||
foreach(IFilter filter in Filters) {
|
||||
filter.Parent = this;
|
||||
}
|
||||
|
@ -657,9 +648,9 @@ namespace Greenshot.Drawing {
|
|||
// drawablecontainers are regarded equal if they are of the same type and their bounds are equal. this should be sufficient.
|
||||
public override bool Equals(object obj) {
|
||||
bool ret = false;
|
||||
if (obj != null && GetType().Equals(obj.GetType())) {
|
||||
if (obj != null && GetType() == obj.GetType()) {
|
||||
DrawableContainer other = obj as DrawableContainer;
|
||||
if (_left==other._left && _top==other._top && _width==other._width && _height==other._height) {
|
||||
if (other != null && _left==other._left && _top==other._top && _width==other._width && _height==other._height) {
|
||||
ret = true;
|
||||
}
|
||||
}
|
||||
|
@ -671,8 +662,8 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
|
||||
protected void OnPropertyChanged(string propertyName) {
|
||||
if (propertyChanged != null) {
|
||||
propertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||
if (_propertyChanged != null) {
|
||||
_propertyChanged(this, new PropertyChangedEventArgs(propertyName));
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
|
@ -696,7 +687,7 @@ namespace Greenshot.Drawing {
|
|||
public void HandleFieldChanged(object sender, FieldChangedEventArgs e) {
|
||||
LOG.DebugFormat("Field {0} changed", e.Field.FieldType);
|
||||
if (e.Field.FieldType == FieldType.SHADOW) {
|
||||
accountForShadowChange = true;
|
||||
_accountForShadowChange = true;
|
||||
}
|
||||
Invalidate();
|
||||
}
|
||||
|
@ -712,11 +703,19 @@ namespace Greenshot.Drawing {
|
|||
return;
|
||||
}
|
||||
Point center = new Point(Left + (Width/2), Top + (Height/2));
|
||||
Point[] points = { center };
|
||||
Point[] points;
|
||||
if (TargetGripper != null) {
|
||||
points = new[] {center, TargetGripper.Location};
|
||||
|
||||
} else {
|
||||
points = new[] { center};
|
||||
}
|
||||
matrix.TransformPoints(points);
|
||||
|
||||
Left = points[0].X - (Width / 2);
|
||||
Top = points[0].Y - (Height / 2);
|
||||
Location = new Point(points[0].X - (Width/2), points[0].Y - (Height/2));
|
||||
if (TargetGripper != null) {
|
||||
TargetGripper.Location = points[1];
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Rotate(RotateFlipType rotateFlipType) {
|
||||
|
@ -778,13 +777,13 @@ namespace Greenshot.Drawing {
|
|||
return ScaleHelper.ShapeAngleRoundBehavior.Instance;
|
||||
}
|
||||
|
||||
public virtual bool hasContextMenu {
|
||||
public virtual bool HasContextMenu {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool hasDefaultSize {
|
||||
public virtual bool HasDefaultSize {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -509,7 +509,7 @@ namespace Greenshot.Drawing {
|
|||
bool canReset = false;
|
||||
foreach (var drawableContainer in this) {
|
||||
var container = (DrawableContainer) drawableContainer;
|
||||
if (container.hasDefaultSize) {
|
||||
if (container.HasDefaultSize) {
|
||||
canReset = true;
|
||||
}
|
||||
}
|
||||
|
@ -519,7 +519,7 @@ namespace Greenshot.Drawing {
|
|||
item.Click += delegate {
|
||||
foreach (var drawableContainer in this) {
|
||||
var container = (DrawableContainer) drawableContainer;
|
||||
if (!container.hasDefaultSize) {
|
||||
if (!container.HasDefaultSize) {
|
||||
continue;
|
||||
}
|
||||
Size defaultSize = container.DefaultSize;
|
||||
|
@ -538,7 +538,7 @@ namespace Greenshot.Drawing {
|
|||
bool hasMenu = false;
|
||||
foreach (var drawableContainer in this) {
|
||||
var container = (DrawableContainer) drawableContainer;
|
||||
if (!container.hasContextMenu) {
|
||||
if (!container.HasContextMenu) {
|
||||
continue;
|
||||
}
|
||||
hasMenu = true;
|
||||
|
|
|
@ -58,7 +58,8 @@ namespace Greenshot.Drawing {
|
|||
protected override void InitializeFields() {
|
||||
AddField(GetType(), FieldType.LINE_THICKNESS, 3);
|
||||
AddField(GetType(), FieldType.LINE_COLOR, Color.Red);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void Init() {
|
||||
if (_grippers != null) {
|
||||
|
@ -108,10 +109,10 @@ namespace Greenshot.Drawing {
|
|||
public override bool HandleMouseMove(int mouseX, int mouseY) {
|
||||
Point previousPoint = capturePoints[capturePoints.Count-1];
|
||||
|
||||
if (GeometryHelper.Distance2D(previousPoint.X, previousPoint.Y, mouseX, mouseY) >= (2*editorConfig.FreehandSensitivity)) {
|
||||
if (GeometryHelper.Distance2D(previousPoint.X, previousPoint.Y, mouseX, mouseY) >= (2*EditorConfig.FreehandSensitivity)) {
|
||||
capturePoints.Add(new Point(mouseX, mouseY));
|
||||
}
|
||||
if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) >= editorConfig.FreehandSensitivity) {
|
||||
if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) >= EditorConfig.FreehandSensitivity) {
|
||||
//path.AddCurve(new Point[]{lastMouse, new Point(mouseX, mouseY)});
|
||||
freehandPath.AddLine(lastMouse, new Point(mouseX, mouseY));
|
||||
lastMouse = new Point(mouseX, mouseY);
|
||||
|
@ -127,7 +128,7 @@ namespace Greenshot.Drawing {
|
|||
/// </summary>
|
||||
public override void HandleMouseUp(int mouseX, int mouseY) {
|
||||
// Make sure we don't loose the ending point
|
||||
if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) >= editorConfig.FreehandSensitivity) {
|
||||
if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) >= EditorConfig.FreehandSensitivity) {
|
||||
capturePoints.Add(new Point(mouseX, mouseY));
|
||||
}
|
||||
RecalculatePath();
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
}
|
||||
|
||||
public override bool hasDefaultSize {
|
||||
public override bool HasDefaultSize {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ namespace Greenshot.Drawing {
|
|||
}
|
||||
}
|
||||
|
||||
public override bool hasDefaultSize {
|
||||
public override bool HasDefaultSize {
|
||||
get {
|
||||
return true;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -62,9 +62,9 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
try {
|
||||
// Get the index of the orientation property.
|
||||
int orientation_index = Array.IndexOf(image.PropertyIdList, EXIF_ORIENTATION_ID);
|
||||
int orientationIndex = Array.IndexOf(image.PropertyIdList, EXIF_ORIENTATION_ID);
|
||||
// If there is no such property, return Unknown.
|
||||
if (orientation_index < 0) {
|
||||
if (orientationIndex < 0) {
|
||||
return;
|
||||
}
|
||||
PropertyItem item = image.GetPropertyItem(EXIF_ORIENTATION_ID);
|
||||
|
@ -129,18 +129,18 @@ namespace GreenshotPlugin.Core {
|
|||
int srcWidth=image.Width;
|
||||
int srcHeight=image.Height;
|
||||
if (thumbHeight < 0) {
|
||||
thumbHeight = (int)(thumbWidth * ((float)srcHeight / (float)srcWidth));
|
||||
thumbHeight = (int)(thumbWidth * (srcHeight / (float)srcWidth));
|
||||
}
|
||||
if (thumbWidth < 0) {
|
||||
thumbWidth = (int)(thumbHeight * ((float)srcWidth / (float)srcHeight));
|
||||
thumbWidth = (int)(thumbHeight * (srcWidth / (float)srcHeight));
|
||||
}
|
||||
if (maxWidth > 0 && thumbWidth > maxWidth) {
|
||||
thumbWidth = Math.Min(thumbWidth, maxWidth);
|
||||
thumbHeight = (int)(thumbWidth * ((float)srcHeight / (float)srcWidth));
|
||||
thumbHeight = (int)(thumbWidth * (srcHeight / (float)srcWidth));
|
||||
}
|
||||
if (maxHeight > 0 && thumbHeight > maxHeight) {
|
||||
thumbHeight = Math.Min(thumbHeight, maxHeight);
|
||||
thumbWidth = (int)(thumbHeight * ((float)srcWidth / (float)srcHeight));
|
||||
thumbWidth = (int)(thumbHeight * (srcWidth / (float)srcHeight));
|
||||
}
|
||||
|
||||
Bitmap bmp = new Bitmap(thumbWidth, thumbHeight);
|
||||
|
@ -174,12 +174,13 @@ namespace GreenshotPlugin.Core {
|
|||
LOG.Warn("Can't crop a null/zero size image!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Private helper method for the FindAutoCropRectangle
|
||||
/// </summary>
|
||||
/// <param name="fastBitmap"></param>
|
||||
/// <param name="colorPoint"></param>
|
||||
/// <param name="cropDifference"></param>
|
||||
/// <returns>Rectangle</returns>
|
||||
private static Rectangle FindAutoCropRectangle(IFastBitmap fastBitmap, Point colorPoint, int cropDifference) {
|
||||
Rectangle cropRectangle = Rectangle.Empty;
|
||||
|
@ -194,24 +195,26 @@ namespace GreenshotPlugin.Core {
|
|||
int diffR = Math.Abs(currentColor.R - referenceColor.R);
|
||||
int diffG = Math.Abs(currentColor.G - referenceColor.G);
|
||||
int diffB = Math.Abs(currentColor.B - referenceColor.B);
|
||||
if (((diffR + diffG + diffB) / 3) > cropDifference) {
|
||||
if (x < min.X) min.X = x;
|
||||
if (y < min.Y) min.Y = y;
|
||||
if (x > max.X) max.X = x;
|
||||
if (y > max.Y) max.Y = y;
|
||||
if (((diffR + diffG + diffB)/3) <= cropDifference) {
|
||||
continue;
|
||||
}
|
||||
if (x < min.X) min.X = x;
|
||||
if (y < min.Y) min.Y = y;
|
||||
if (x > max.X) max.X = x;
|
||||
if (y > max.Y) max.Y = y;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int y = 0; y < fastBitmap.Height; y++) {
|
||||
for (int x = 0; x < fastBitmap.Width; x++) {
|
||||
Color currentColor = fastBitmap.GetColorAt(x, y);
|
||||
if (referenceColor.Equals(currentColor)) {
|
||||
if (x < min.X) min.X = x;
|
||||
if (y < min.Y) min.Y = y;
|
||||
if (x > max.X) max.X = x;
|
||||
if (y > max.Y) max.Y = y;
|
||||
if (!referenceColor.Equals(currentColor)) {
|
||||
continue;
|
||||
}
|
||||
if (x < min.X) min.X = x;
|
||||
if (y < min.Y) min.Y = y;
|
||||
if (x > max.X) max.X = x;
|
||||
if (y > max.Y) max.Y = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -228,10 +231,11 @@ namespace GreenshotPlugin.Core {
|
|||
/// Get a rectangle for the image which crops the image of all colors equal to that on 0,0
|
||||
/// </summary>
|
||||
/// <param name="image"></param>
|
||||
/// <param name="cropDifference"></param>
|
||||
/// <returns>Rectangle</returns>
|
||||
public static Rectangle FindAutoCropRectangle(Image image, int cropDifference) {
|
||||
Rectangle cropRectangle = Rectangle.Empty;
|
||||
Rectangle currentRectangle = Rectangle.Empty;
|
||||
Rectangle currentRectangle;
|
||||
List<Point> checkPoints = new List<Point>();
|
||||
// Top Left
|
||||
checkPoints.Add(new Point(0, 0));
|
||||
|
@ -391,20 +395,20 @@ namespace GreenshotPlugin.Core {
|
|||
/// <summary>
|
||||
/// Get the number of icon in the file
|
||||
/// </summary>
|
||||
/// <param name="icon"></param>
|
||||
/// <param name="location">Location of the EXE or DLL</param>
|
||||
/// <returns></returns>
|
||||
public static int CountAssociatedIcons(string location) {
|
||||
IntPtr large = IntPtr.Zero;
|
||||
IntPtr small = IntPtr.Zero;
|
||||
IntPtr large;
|
||||
IntPtr small;
|
||||
return Shell32.ExtractIconEx(location, -1, out large, out small, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply the effect to the bitmap
|
||||
/// </summary>
|
||||
/// <param name="sourceBitmap">Bitmap</param>
|
||||
/// <param name="sourceImage">Bitmap</param>
|
||||
/// <param name="effect">IEffect</param>
|
||||
/// <param name="matrix"></param>
|
||||
/// <returns>Bitmap</returns>
|
||||
public static Image ApplyEffect(Image sourceImage, IEffect effect, Matrix matrix) {
|
||||
List<IEffect> effects = new List<IEffect>();
|
||||
|
@ -415,8 +419,9 @@ namespace GreenshotPlugin.Core {
|
|||
/// <summary>
|
||||
/// Apply the effects in the supplied order to the bitmap
|
||||
/// </summary>
|
||||
/// <param name="sourceBitmap">Bitmap</param>
|
||||
/// <param name="sourceImage">Bitmap</param>
|
||||
/// <param name="effects">List<IEffect></param>
|
||||
/// <param name="matrix"></param>
|
||||
/// <returns>Bitmap</returns>
|
||||
public static Image ApplyEffects(Image sourceImage, List<IEffect> effects, Matrix matrix) {
|
||||
Image currentImage = sourceImage;
|
||||
|
@ -449,8 +454,8 @@ namespace GreenshotPlugin.Core {
|
|||
Image returnImage = CreateEmpty(sourceImage.Width, sourceImage.Height, PixelFormat.Format32bppArgb, Color.Empty, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||
using (GraphicsPath path = new GraphicsPath()) {
|
||||
Random random = new Random();
|
||||
int HorizontalRegions = (int)(sourceImage.Width / horizontalToothRange);
|
||||
int VerticalRegions = (int)(sourceImage.Height / verticalToothRange);
|
||||
int horizontalRegions = sourceImage.Width / horizontalToothRange;
|
||||
int verticalRegions = sourceImage.Height / verticalToothRange;
|
||||
|
||||
// Start
|
||||
Point previousEndingPoint = new Point(0,0);
|
||||
|
@ -458,8 +463,8 @@ namespace GreenshotPlugin.Core {
|
|||
if (edges[0]) {
|
||||
previousEndingPoint = new Point(horizontalToothRange, random.Next(1, toothHeight));
|
||||
// Top
|
||||
for (int i = 0; i < HorizontalRegions; i++) {
|
||||
int x = (int)previousEndingPoint.X + horizontalToothRange;
|
||||
for (int i = 0; i < horizontalRegions; i++) {
|
||||
int x = previousEndingPoint.X + horizontalToothRange;
|
||||
int y = random.Next(1, toothHeight);
|
||||
newEndingPoint = new Point(x, y);
|
||||
path.AddLine(previousEndingPoint, newEndingPoint);
|
||||
|
@ -472,9 +477,9 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
if (edges[1]) {
|
||||
// Right
|
||||
for (int i = 0; i < VerticalRegions; i++) {
|
||||
for (int i = 0; i < verticalRegions; i++) {
|
||||
int x = sourceImage.Width - random.Next(1, toothHeight);
|
||||
int y = (int)previousEndingPoint.Y + verticalToothRange;
|
||||
int y = previousEndingPoint.Y + verticalToothRange;
|
||||
newEndingPoint = new Point(x, y);
|
||||
path.AddLine(previousEndingPoint, newEndingPoint);
|
||||
previousEndingPoint = newEndingPoint;
|
||||
|
@ -486,8 +491,8 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
if (edges[2]) {
|
||||
// Bottom
|
||||
for (int i = 0; i < HorizontalRegions; i++) {
|
||||
int x = (int)previousEndingPoint.X - horizontalToothRange;
|
||||
for (int i = 0; i < horizontalRegions; i++) {
|
||||
int x = previousEndingPoint.X - horizontalToothRange;
|
||||
int y = sourceImage.Height - random.Next(1, toothHeight);
|
||||
newEndingPoint = new Point(x, y);
|
||||
path.AddLine(previousEndingPoint, newEndingPoint);
|
||||
|
@ -500,9 +505,9 @@ namespace GreenshotPlugin.Core {
|
|||
}
|
||||
if (edges[3]) {
|
||||
// Left
|
||||
for (int i = 0; i < VerticalRegions; i++) {
|
||||
for (int i = 0; i < verticalRegions; i++) {
|
||||
int x = random.Next(1, toothHeight);
|
||||
int y = (int)previousEndingPoint.Y - verticalToothRange;
|
||||
int y = previousEndingPoint.Y - verticalToothRange;
|
||||
newEndingPoint = new Point(x, y);
|
||||
path.AddLine(previousEndingPoint, newEndingPoint);
|
||||
previousEndingPoint = newEndingPoint;
|
||||
|
@ -510,7 +515,7 @@ namespace GreenshotPlugin.Core {
|
|||
} else {
|
||||
newEndingPoint = new Point(0, 0);
|
||||
path.AddLine(previousEndingPoint, newEndingPoint);
|
||||
previousEndingPoint = newEndingPoint;
|
||||
//previousEndingPoint = newEndingPoint;
|
||||
}
|
||||
|
||||
path.CloseFigure();
|
||||
|
@ -522,7 +527,7 @@ namespace GreenshotPlugin.Core {
|
|||
graphics.CompositingQuality = CompositingQuality.HighQuality;
|
||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
using (Brush brush = new TextureBrush(sourceImage)) {
|
||||
// Imporant note: If the target wouldn't be at 0,0 we need to translate-transform!!
|
||||
// Important note: If the target wouldn't be at 0,0 we need to translate-transform!!
|
||||
graphics.FillPath(brush, path);
|
||||
}
|
||||
}
|
||||
|
@ -530,24 +535,6 @@ namespace GreenshotPlugin.Core {
|
|||
return returnImage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper Method for the ApplyBlur
|
||||
/// </summary>
|
||||
/// <param name="amount"></param>
|
||||
/// <returns></returns>
|
||||
private static int[] CreateGaussianBlurRow(int amount) {
|
||||
int size = 1 + (amount * 2);
|
||||
int[] weights = new int[size];
|
||||
|
||||
for (int i = 0; i <= amount; ++i) {
|
||||
// 1 + aa - aa + 2ai - ii
|
||||
weights[i] = 16 * (i + 1);
|
||||
weights[weights.Length - i - 1] = weights[i];
|
||||
}
|
||||
|
||||
return weights;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply BoxBlur to the destinationBitmap
|
||||
/// </summary>
|
||||
|
@ -638,7 +625,6 @@ namespace GreenshotPlugin.Core {
|
|||
/// <summary>
|
||||
/// BoxBlurHorizontal is a private helper method for the BoxBlur, only for IFastBitmaps with alpha channel
|
||||
/// </summary>
|
||||
/// <param name="bbbSrc">Source BitmapBuffer</param>
|
||||
/// <param name="targetFastBitmap">Target BitmapBuffer</param>
|
||||
/// <param name="range">Range must be odd!</param>
|
||||
private static void BoxBlurHorizontalAlpha(IFastBitmap targetFastBitmap, int range) {
|
||||
|
@ -694,11 +680,8 @@ namespace GreenshotPlugin.Core {
|
|||
if (targetFastBitmap.hasAlphaChannel) {
|
||||
throw new NotSupportedException("BoxBlurVertical should NOT be called for bitmaps with alpha channel");
|
||||
}
|
||||
int w = targetFastBitmap.Width;
|
||||
int halfRange = range / 2;
|
||||
Color[] newColors = new Color[targetFastBitmap.Height];
|
||||
int oldPixelOffset = -(halfRange + 1) * w;
|
||||
int newPixelOffset = (halfRange) * w;
|
||||
byte[] tmpColor = new byte[4];
|
||||
for (int x = targetFastBitmap.Left; x < targetFastBitmap.Right; x++) {
|
||||
int hits = 0;
|
||||
|
@ -745,11 +728,8 @@ namespace GreenshotPlugin.Core {
|
|||
throw new NotSupportedException("BoxBlurVerticalAlpha should be called for bitmaps with alpha channel");
|
||||
}
|
||||
|
||||
int w = targetFastBitmap.Width;
|
||||
int halfRange = range / 2;
|
||||
Color[] newColors = new Color[targetFastBitmap.Height];
|
||||
int oldPixelOffset = -(halfRange + 1) * w;
|
||||
int newPixelOffset = (halfRange) * w;
|
||||
byte[] tmpColor = new byte[4];
|
||||
for (int x = targetFastBitmap.Left; x < targetFastBitmap.Right; x++) {
|
||||
int hits = 0;
|
||||
|
@ -818,13 +798,14 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="darkness">How dark is the shadow</param>
|
||||
/// <param name="shadowSize">Size of the shadow</param>
|
||||
/// <param name="targetPixelformat">What pixel format must the returning bitmap have</param>
|
||||
/// <param name="offset">How many pixels is the original image moved?</param>
|
||||
/// <param name="shadowOffset"></param>
|
||||
/// <param name="matrix">The transform matrix which describes how the elements need to be transformed to stay at the same location</param>
|
||||
/// <returns>Bitmap with the shadow, is bigger than the sourceBitmap!!</returns>
|
||||
public static Bitmap CreateShadow(Image sourceBitmap, float darkness, int shadowSize, Point shadowOffset, Matrix matrix, PixelFormat targetPixelformat) {
|
||||
Point offset = shadowOffset;
|
||||
offset.X += shadowSize - 1;
|
||||
offset.Y += shadowSize - 1;
|
||||
matrix.Translate(offset.X, offset.Y);
|
||||
matrix.Translate(offset.X, offset.Y, MatrixOrder.Append);
|
||||
// Create a new "clean" image
|
||||
Bitmap returnImage = CreateEmpty(sourceBitmap.Width + (shadowSize * 2), sourceBitmap.Height + (shadowSize * 2), targetPixelformat, Color.Empty, sourceBitmap.HorizontalResolution, sourceBitmap.VerticalResolution);
|
||||
// Make sure the shadow is odd, there is no reason for an even blur!
|
||||
|
@ -865,7 +846,7 @@ namespace GreenshotPlugin.Core {
|
|||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
// draw original with a TextureBrush so we have nice antialiasing!
|
||||
using (Brush textureBrush = new TextureBrush(sourceBitmap, WrapMode.Clamp)) {
|
||||
// We need to do a translate-tranform otherwise the image is wrapped
|
||||
// We need to do a translate-transform otherwise the image is wrapped
|
||||
graphics.TranslateTransform(offset.X, offset.Y);
|
||||
graphics.FillRectangle(textureBrush, 0, 0, sourceBitmap.Width, sourceBitmap.Height);
|
||||
}
|
||||
|
@ -880,7 +861,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <returns>Negative bitmap</returns>
|
||||
public static Bitmap CreateNegative(Image sourceImage) {
|
||||
Bitmap clone = (Bitmap)Clone(sourceImage);
|
||||
ColorMatrix invertMatrix = new ColorMatrix(new float[][] {
|
||||
ColorMatrix invertMatrix = new ColorMatrix(new[] {
|
||||
new float[] {-1, 0, 0, 0, 0},
|
||||
new float[] {0, -1, 0, 0, 0},
|
||||
new float[] {0, 0, -1, 0, 0},
|
||||
|
@ -980,12 +961,12 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="borderSize">Size of the border</param>
|
||||
/// <param name="borderColor">Color of the border</param>
|
||||
/// <param name="targetPixelformat">What pixel format must the returning bitmap have</param>
|
||||
/// <param name="offset">How many pixels is the original image moved?</param>
|
||||
/// <param name="matrix">The transform matrix which describes how the elements need to be transformed to stay at the same location</param>
|
||||
/// <returns>Bitmap with the shadow, is bigger than the sourceBitmap!!</returns>
|
||||
public static Image CreateBorder(Image sourceImage, int borderSize, Color borderColor, PixelFormat targetPixelformat, Matrix matrix) {
|
||||
// "return" the shifted offset, so the caller can e.g. move elements
|
||||
Point offset = new Point(borderSize, borderSize);
|
||||
matrix.Translate(offset.X, offset.Y);
|
||||
matrix.Translate(offset.X, offset.Y, MatrixOrder.Append);
|
||||
|
||||
// Create a new "clean" image
|
||||
Bitmap newImage = CreateEmpty(sourceImage.Width + (borderSize * 2), sourceImage.Height + (borderSize * 2), targetPixelformat, Color.Empty, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||
|
@ -1039,11 +1020,15 @@ namespace GreenshotPlugin.Core {
|
|||
attributes.SetGamma(gamma, ColorAdjustType.Bitmap);
|
||||
return attributes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adjust the brightness, contract or gamma of an image.
|
||||
/// Use the value "1.0f" for no changes.
|
||||
/// </summary>
|
||||
/// <param name="sourceImage">Original bitmap</param>
|
||||
/// <param name="brightness"></param>
|
||||
/// <param name="contrast"></param>
|
||||
/// <param name="gamma"></param>
|
||||
/// <returns>Bitmap with grayscale</returns>
|
||||
public static Image Adjust(Image sourceImage, float brightness, float contrast, float gamma) {
|
||||
//create a blank bitmap the same size as original
|
||||
|
@ -1284,9 +1269,10 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="right"></param>
|
||||
/// <param name="top"></param>
|
||||
/// <param name="bottom"></param>
|
||||
/// <param name="matrix"></param>
|
||||
/// <returns>a new bitmap with the source copied on it</returns>
|
||||
public static Image ResizeCanvas(Image sourceImage, Color backgroundColor, int left, int right, int top, int bottom, Matrix matrix) {
|
||||
matrix.Translate(left, top);
|
||||
matrix.Translate(left, top, MatrixOrder.Append);
|
||||
Bitmap newBitmap = CreateEmpty(sourceImage.Width + left + right, sourceImage.Height + top + bottom, sourceImage.PixelFormat, backgroundColor, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||
using (Graphics graphics = Graphics.FromImage(newBitmap)) {
|
||||
graphics.DrawImageUnscaled(sourceImage, left, top);
|
||||
|
@ -1301,6 +1287,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// <param name="maintainAspectRatio">true to maintain the aspect ratio</param>
|
||||
/// <param name="newWidth"></param>
|
||||
/// <param name="newHeight"></param>
|
||||
/// <param name="matrix"></param>
|
||||
/// <returns></returns>
|
||||
public static Image ResizeImage(Image sourceImage, bool maintainAspectRatio, int newWidth, int newHeight, Matrix matrix) {
|
||||
return ResizeImage(sourceImage, maintainAspectRatio, false, Color.Empty, newWidth, newHeight, matrix);
|
||||
|
@ -1310,7 +1297,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// Count how many times the supplied color exists
|
||||
/// </summary>
|
||||
/// <param name="sourceImage">Image to count the pixels of</param>
|
||||
/// <param name="colorToCount">Color to count/param>
|
||||
/// <param name="colorToCount">Color to count</param>
|
||||
/// <param name="includeAlpha">true if Alpha needs to be checked</param>
|
||||
/// <returns>int with the number of pixels which have colorToCount</returns>
|
||||
public static int CountColor(Image sourceImage, Color colorToCount, bool includeAlpha) {
|
||||
|
@ -1340,9 +1327,11 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
/// <param name="sourceImage">Image to scale</param>
|
||||
/// <param name="maintainAspectRatio">true to maintain the aspect ratio</param>
|
||||
/// <param name="canvasUseNewSize"></param>
|
||||
/// <param name="backgroundColor">The color to fill with, or Color.Empty to take the default depending on the pixel format</param>
|
||||
/// <param name="newWidth">new width</param>
|
||||
/// <param name="newHeight">new height</param>
|
||||
/// <param name="matrix"></param>
|
||||
/// <returns>a new bitmap with the specified size, the source-Image scaled to fit with aspect ratio locked</returns>
|
||||
public static Image ResizeImage(Image sourceImage, bool maintainAspectRatio, bool canvasUseNewSize, Color backgroundColor, int newWidth, int newHeight, Matrix matrix) {
|
||||
int destX = 0;
|
||||
|
@ -1351,8 +1340,8 @@ namespace GreenshotPlugin.Core {
|
|||
float nPercentW = 0;
|
||||
float nPercentH = 0;
|
||||
|
||||
nPercentW = ((float)newWidth / (float)sourceImage.Width);
|
||||
nPercentH = ((float)newHeight / (float)sourceImage.Height);
|
||||
nPercentW = (newWidth / (float)sourceImage.Width);
|
||||
nPercentH = (newHeight / (float)sourceImage.Height);
|
||||
if (maintainAspectRatio) {
|
||||
if (nPercentW == 1) {
|
||||
nPercentW = nPercentH;
|
||||
|
@ -1388,10 +1377,10 @@ namespace GreenshotPlugin.Core {
|
|||
Image newImage = null;
|
||||
if (maintainAspectRatio && canvasUseNewSize) {
|
||||
newImage = CreateEmpty(newWidth, newHeight, sourceImage.PixelFormat, backgroundColor, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||
matrix.Scale(sourceImage.Width / newWidth, sourceImage.Height / newHeight);
|
||||
matrix.Scale((float)newWidth / sourceImage.Width, (float)newHeight / sourceImage.Height);
|
||||
} else {
|
||||
newImage = CreateEmpty(destWidth, destHeight, sourceImage.PixelFormat, backgroundColor, sourceImage.HorizontalResolution, sourceImage.VerticalResolution);
|
||||
matrix.Scale(sourceImage.Width / destWidth, sourceImage.Height / destHeight);
|
||||
matrix.Scale((float)destWidth / sourceImage.Width, (float)destHeight / sourceImage.Height);
|
||||
}
|
||||
|
||||
using (Graphics graphics = Graphics.FromImage(newImage)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue