mirror of https://github.com/SixLabors/ImageSharp
Browse Source
Former-commit-id: 1c43328c71d549a566fe1c3a655f97c9ce9fad05 Former-commit-id: db8c7b880c3f17b85feb7277477eddc50f6dffb5 Former-commit-id: 405ff7e2dccdc33b5cbf53a07208a57528616c6bpull/1/head
4 changed files with 59 additions and 112 deletions
@ -0,0 +1,41 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Numerics; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace ImageProcessorCore |
||||
|
{ |
||||
|
|
||||
|
public static class ProcessMatrixHelper |
||||
|
{ |
||||
|
public static void CreateNewTarget(ImageBase target, Rectangle sourceRectangle, Matrix3x2 processMatrix) |
||||
|
{ |
||||
|
Matrix3x2 sizeMatrix; |
||||
|
if (Matrix3x2.Invert(processMatrix, out sizeMatrix)) |
||||
|
{ |
||||
|
Rectangle rectangle = ImageMaths.GetBoundingRectangle(sourceRectangle, sizeMatrix); |
||||
|
target.SetPixels(rectangle.Width, rectangle.Height, new float[rectangle.Width*rectangle.Height*4]); |
||||
|
} |
||||
|
} |
||||
|
public static Matrix3x2 Matrix3X2(ImageBase target, ImageBase source, Matrix3x2 processMatrix) |
||||
|
{ |
||||
|
Matrix3x2 translationToTargetCenter = Matrix3x2.CreateTranslation(-target.Width / 2f, -target.Height / 2f); |
||||
|
Matrix3x2 translateToSourceCenter = Matrix3x2.CreateTranslation(source.Width / 2f, source.Height / 2f); |
||||
|
Matrix3x2 apply = (translationToTargetCenter * processMatrix) * translateToSourceCenter; |
||||
|
return apply; |
||||
|
} |
||||
|
|
||||
|
public static void DrawHorizontalData(ImageBase target, ImageBase source, int y, Matrix3x2 apply) |
||||
|
{ |
||||
|
for (int x = 0; x < target.Width; x++) |
||||
|
{ |
||||
|
Point rotated = Point.Rotate(new Point(x, y), apply); |
||||
|
if (source.Bounds.Contains(rotated.X, rotated.Y)) |
||||
|
{ |
||||
|
target[x, y] = source[rotated.X, rotated.Y]; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue