Browse Source

Merge branch 'master' of https://github.com/SixLabors/ImageSharp into tiff-codec

pull/1570/head
James Jackson-South 8 years ago
parent
commit
74b8a5bd81
  1. 2
      ImageSharp.ruleset
  2. 49
      README.md
  3. 4
      build/icons/imagesharp-logo-128.png
  4. 4
      build/icons/imagesharp-logo-256.png
  5. 4
      build/icons/imagesharp-logo-32.png
  6. 4
      build/icons/imagesharp-logo-512.png
  7. 4
      build/icons/imagesharp-logo-64.png
  8. 3
      build/icons/imagesharp-logo-heading.png
  9. 4
      build/icons/imagesharp-logo.png
  10. 2
      build/icons/imagesharp-logo.svg
  11. 149
      features.md
  12. 3
      input/about.md
  13. 2
      src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
  14. 3
      src/ImageSharp.Drawing/Primitives/Region.cs
  15. 14
      src/ImageSharp.Drawing/Primitives/ShapePath.cs
  16. 7
      src/ImageSharp.Drawing/Primitives/ShapeRegion.cs
  17. 12
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs
  18. 2
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/Brushes.cs
  19. 4
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/IBrush.cs
  20. 8
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs
  21. 31
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs
  22. 26
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs
  23. 5
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs
  24. 60
      src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs
  25. 65
      src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs
  26. 48
      src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs
  27. 43
      src/ImageSharp.Drawing/Processing/Drawing/DrawPathCollectionExtensions.cs
  28. 48
      src/ImageSharp.Drawing/Processing/Drawing/DrawPathExtensions.cs
  29. 50
      src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs
  30. 62
      src/ImageSharp.Drawing/Processing/Drawing/DrawRectangleExtensions.cs
  31. 35
      src/ImageSharp.Drawing/Processing/Drawing/FillPathBuilderExtensions.cs
  32. 35
      src/ImageSharp.Drawing/Processing/Drawing/FillPathCollectionExtensions.cs
  33. 36
      src/ImageSharp.Drawing/Processing/Drawing/FillPathExtensions.cs
  34. 37
      src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs
  35. 38
      src/ImageSharp.Drawing/Processing/Drawing/FillRectangleExtensions.cs
  36. 92
      src/ImageSharp.Drawing/Processing/Drawing/FillRegionExtensions.cs
  37. 10
      src/ImageSharp.Drawing/Processing/Drawing/Pens/IPen.cs
  38. 15
      src/ImageSharp.Drawing/Processing/Drawing/Pens/Pens.cs
  39. 19
      src/ImageSharp.Drawing/Processing/Drawing/Pens/Pen{TPixel}.cs
  40. 155
      src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs
  41. 14
      src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs
  42. 17
      src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs
  43. 57
      src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.Path.cs
  44. 59
      src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs
  45. 7
      src/ImageSharp.Drawing/Processing/Text/TextGraphicsOptions.cs
  46. 96
      src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs
  47. 2
      src/ImageSharp/Advanced/AdvancedImageExtensions.cs
  48. 3
      src/ImageSharp/Advanced/IPixelSource.cs
  49. 2
      src/ImageSharp/ColorSpaces/Hsv.cs
  50. 2
      src/ImageSharp/ColorSpaces/Rgb.cs
  51. 2
      src/ImageSharp/Common/Extensions/Vector4Extensions.cs
  52. 5
      src/ImageSharp/Configuration.cs
  53. 5
      src/ImageSharp/Formats/Gif/GifEncoder.cs
  54. 13
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  55. 10
      src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs
  56. 6
      src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs
  57. 2
      src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs
  58. 2
      src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegColorSpace.cs
  59. 3
      src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs
  60. 6
      src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs
  61. 1
      src/ImageSharp/Formats/Jpeg/JpegEncoder.cs
  62. 7
      src/ImageSharp/Formats/Png/IPngEncoderOptions.cs
  63. 4
      src/ImageSharp/Formats/Png/PngDecoder.cs
  64. 2
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  65. 3
      src/ImageSharp/Formats/Png/PngEncoder.cs
  66. 11
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  67. 61
      src/ImageSharp/Helpers/ImageExtensions.cs
  68. 0
      src/ImageSharp/IImage.cs
  69. 0
      src/ImageSharp/IImageFrameCollection.cs
  70. 0
      src/ImageSharp/IImageInfo.cs
  71. 0
      src/ImageSharp/Image.Decode.cs
  72. 0
      src/ImageSharp/Image.FromBytes.cs
  73. 0
      src/ImageSharp/Image.FromFile.cs
  74. 0
      src/ImageSharp/Image.FromStream.cs
  75. 0
      src/ImageSharp/Image.LoadPixelData.cs
  76. 0
      src/ImageSharp/ImageExtensions.cs
  77. 0
      src/ImageSharp/ImageFrame.LoadPixelData.cs
  78. 7
      src/ImageSharp/ImageFrameCollection.cs
  79. 18
      src/ImageSharp/ImageFrame{TPixel}.cs
  80. 0
      src/ImageSharp/ImageInfo.cs
  81. 27
      src/ImageSharp/ImageInfoExtensions.cs
  82. 5
      src/ImageSharp/ImageSharp.csproj
  83. 10
      src/ImageSharp/Image{TPixel}.cs
  84. 4
      src/ImageSharp/Memory/ArrayPoolMemoryManager.CommonFactoryMethods.cs
  85. 173
      src/ImageSharp/Memory/Fast2DArray{T}.cs
  86. 2
      src/ImageSharp/MetaData/ImageMetaData.cs
  87. 8
      src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs
  88. 18
      src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs
  89. 0
      src/ImageSharp/PixelAccessorExtensions.cs
  90. 0
      src/ImageSharp/PixelAccessor{TPixel}.cs
  91. 5
      src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs
  92. 5
      src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt
  93. 6
      src/ImageSharp/PixelFormats/PixelBlenderMode.cs
  94. 6
      src/ImageSharp/PixelFormats/Rgba32.Definitions.cs
  95. 3
      src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs
  96. 4
      src/ImageSharp/PixelFormats/Rgba32.cs
  97. 215
      src/ImageSharp/Primitives/DenseMatrix{T}.cs
  98. 30
      src/ImageSharp/Primitives/ValueSize.cs
  99. 30
      src/ImageSharp/Processing/Binarization/BinaryDiffuseExtensions.cs
  100. 30
      src/ImageSharp/Processing/Binarization/BinaryDitherExtensions.cs

2
ImageSharp.ruleset

@ -7,5 +7,7 @@
temp remove the header requirement as stylecop is currently failing to read the stylecop.json file from 'dotnet build'
<Rule Id="SA1636" Action="None" />-->
<Rule Id="SA1633" Action="None" />
<!--1.1.0-beta6 incorrectly throws a wobbler here for multiline matrices-->
<Rule Id="SA1500" Action="None" />
</Rules>
</RuleSet>

49
README.md

@ -4,31 +4,32 @@
ImageSharp
<br>
<br>
<a href="https://raw.githubusercontent.com/SixLabors/ImageSharp/master/APACHE-2.0-LICENSE.txt"><img src="https://camo.githubusercontent.com/8f54547853cfad57acfc8e06e6008cc296cda34d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865253230322d626c75652e737667" alt="GitHub license" data-canonical-src="https://img.shields.io/badge/license-Apache%202-blue.svg" style="max-width:100%;"></a>
<a href="https://gitter.im/ImageSharp/General?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge&amp;utm_content=badge"><img src="https://camo.githubusercontent.com/da2edb525cde1455a622c58c0effc3a90b9a181c/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667" alt="Gitter" data-canonical-src="https://badges.gitter.im/Join%20Chat.svg" style="max-width:100%;"></a>
<a href="https://twitter.com/intent/tweet?hashtags=imagesharp,dotnet,oss&amp;text=ImageSharp.+A+new+cross-platform+2D+graphics+API+in+C%23&amp;url=https%3a%2f%2fgithub.com%2fSixLabors%2fImageSharp&amp;via=sixlabors"><img src="https://camo.githubusercontent.com/aed174887b7d1f0a0877dd0a68c3872bc54d2fff/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c2f68747470732f6769746875622e636f6d2f5369784c61626f72732f496d61676553686172702e7376673f7374796c653d736f6369616c" alt="Twitter" data-canonical-src="https://img.shields.io/twitter/url/https/github.com/SixLabors/ImageSharp.svg?style=social" style="max-width:100%;"></a>
<a href="#backers"><img src="https://camo.githubusercontent.com/c9af371c98b22cb92323a385a267a1215c454663/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f696d61676573686172702f6261636b6572732f62616467652e737667" alt="OpenCollective" data-canonical-src="https://opencollective.com/imagesharp/backers/badge.svg" style="max-width:100%;"></a>
<a href="#sponsors"><img src="https://camo.githubusercontent.com/5a9ae612f8e7fb5207f51a605f025770bfa9a80e/68747470733a2f2f6f70656e636f6c6c6563746976652e636f6d2f696d61676573686172702f73706f6e736f72732f62616467652e737667" alt="OpenCollective" data-canonical-src="https://opencollective.com/imagesharp/sponsors/badge.svg" style="max-width:100%;"></a>
<a href="https://raw.githubusercontent.com/SixLabors/ImageSharp/master/LICENSE"><img src="https://img.shields.io/badge/license-Apache%202-blue.svg" alt="GitHub license" data-canonical-src="https://img.shields.io/badge/license-Apache%202-blue.svg" style="max-width:100%;"></a>
<a href="https://gitter.im/ImageSharp/General?utm_source=badge&amp;utm_medium=badge&amp;utm_campaign=pr-badge&amp;utm_content=badge"><img src="https://badges.gitter.im/Join%20Chat.svg" alt="Gitter" data-canonical-src="https://badges.gitter.im/Join%20Chat.svg" style="max-width:100%;"></a>
<a href="https://twitter.com/intent/tweet?hashtags=imagesharp,dotnet,oss&amp;text=ImageSharp.+A+new+cross-platform+2D+graphics+API+in+C%23&amp;url=https%3a%2f%2fgithub.com%2fSixLabors%2fImageSharp&amp;via=sixlabors"><img src="https://img.shields.io/twitter/url/http/shields.io.svg?style=flat&logo=twitter" alt="Twitter" data-canonical-src="https://img.shields.io/twitter/url/http/shields.io.svg?style=flat&logo=twitter" style="max-width:100%;"></a>
<a href="#backers"><img src="https://opencollective.com/imagesharp/backers/badge.svg" alt="OpenCollective" data-canonical-src="https://opencollective.com/imagesharp/backers/badge.svg" style="max-width:100%;"></a>
<a href="#sponsors"><img src="https://opencollective.com/imagesharp/sponsors/badge.svg" alt="OpenCollective" data-canonical-src="https://opencollective.com/imagesharp/sponsors/badge.svg" style="max-width:100%;"></a>
</h1>
### **ImageSharp** is a new, fully featured, fully managed, cross-platform, 2D graphics API.
Without the use of `System.Drawing` we have been able to develop something much more flexible, easier to code against, and much, much less prone to memory leaks. Gone are system-wide process-locks; ImageSharp images are thread-safe and fully supported in web environments.
Designed to democratize image processing, ImageSharp brings you an incredibly powerful yet beautifully simple API.
Built against .Net Standard 1.1 ImageSharp can be used in device, cloud, and embedded/IoT scenarios.
### Questions?
Compared to `System.Drawing` we have been able to develop something much more flexible, easier to code against, and much, much less prone to memory leaks. Gone are system-wide process-locks; ImageSharp images are thread-safe and fully supported in web environments.
Do you have questions? We are happy to help! Please [join our gitter channel](https://gitter.im/ImageSharp/General), or ask them on [stackoverflow](https://stackoverflow.com) using the `ImageSharp` tag.
Built against .Net Standard 1.1 ImageSharp can be used in device, cloud, and embedded/IoT scenarios.
### Installation
Install stable releases via Nuget;evelopment releases are available via MyGet.
| Package Name | Release (NuGet) | Nightly (MyGet) |
|--------------------------------|-----------------|-----------------|
| `SixLabors.ImageSharp` | [![NuGet](https://img.shields.io/nuget/v/SixLabors.ImageSharp.svg)](https://www.nuget.org/packages/SixLabors.ImageSharp/) | [![MyGet](https://img.shields.io/myget/sixlabors/v/SixLabors.ImageSharp.svg)](https://www.myget.org/feed/sixlabors/package/nuget/SixLabors.ImageSharp) |
| `SixLabors.ImageSharp.Drawing` | [![NuGet](https://img.shields.io/nuget/v/SixLabors.ImageSharp.Drawing.svg)](https://www.nuget.org/packages/SixLabors.ImageSharp.Drawing/) | [![MyGet](https://img.shields.io/myget/sixlabors/v/SixLabors.ImageSharp.Drawing.svg)](https://www.myget.org/feed/sixlabors/package/nuget/SixLabors.ImageSharp.Drawing) |
### Packages
The **ImageSharp** library is made up of multiple packages:
- **SixLabors.ImageSharp**
- Contains the generic `Image<TPixel>` class, PixelFormats, Primitives, Configuration, and other core functionality.
@ -48,31 +49,37 @@ The **ImageSharp** library is made up of multiple packages:
|**Linux/Mac**|[![Build Status](https://travis-ci.org/SixLabors/ImageSharp.svg)](https://travis-ci.org/SixLabors/ImageSharp)|[![Code coverage](https://codecov.io/gh/SixLabors/ImageSharp/branch/master/graph/badge.svg)](https://codecov.io/gh/SixLabors/ImageSharp)|
|**Windows** |[![Build Status](https://ci.appveyor.com/api/projects/status/m9pn907xdah3ca39/branch/master?svg=true)](https://ci.appveyor.com/project/six-labors/imagesharp/branch/master)|[![Code coverage](https://codecov.io/gh/SixLabors/ImageSharp/branch/master/graph/badge.svg)](https://codecov.io/gh/SixLabors/ImageSharp)|
### Features
### Questions?
There's plenty there and more coming. Check out the [current features](features.md)!
Do you have questions? We are happy to help! Please [join our gitter channel](https://gitter.im/ImageSharp/General), or ask them on [stackoverflow](https://stackoverflow.com) using the `ImageSharp` tag.
### API
Here's an example of the code required to resize an image using the default Bicubic resampler then turn the colors into their grayscale equivalent using the BT709 standard matrix.
API documentation is available at [https://sixlabors.github.io/docs/](https://sixlabors.github.io/docs/)
Our API is designed to be simple to consume. Here's an example of the code required to resize an image using the default Bicubic resampler then turn the colors into their grayscale equivalent using the BT709 standard matrix.
On platforms supporting netstandard 1.3+
```csharp
// Image.Load(string path) is a shortcut for our default type. Other pixel formats use Image.Load<TPixel>(string path))
// Image.Load(string path) is a shortcut for our default type.
// Other pixel formats use Image.Load<TPixel>(string path))
using (Image<Rgba32> image = Image.Load("foo.jpg"))
{
image.Mutate(x => x
.Resize(image.Width / 2, image.Height / 2)
.Grayscale());
image.Save("bar.jpg"); // automatic encoder selected based on extension.
image.Save("bar.jpg"); // Automatic encoder selected based on extension.
}
```
on netstandard 1.1 - 1.2
On netstandard 1.1 - 1.2
```csharp
// Image.Load(Stream stream) is a shortcut for our default type. Other pixel formats use Image.Load<TPixel>(Stream stream))
// Image.Load(Stream stream) is a shortcut for our default type.
// Other pixel formats use Image.Load<TPixel>(Stream stream))
using (FileStream stream = File.OpenRead("foo.jpg"))
using (FileStream output = File.OpenWrite("bar.jpg"))
using (Image<Rgba32> image = Image.Load<Rgba32>(stream))
using (Image<Rgba32> image = Image.Load(stream))
{
image.Mutate(x => x
.Resize(image.Width / 2, image.Height / 2)
@ -81,7 +88,7 @@ using (Image<Rgba32> image = Image.Load<Rgba32>(stream))
}
```
Setting individual pixel values can be perfomed as follows:
Setting individual pixel values can be performed as follows:
```csharp
// Individual pixels
@ -93,9 +100,7 @@ using (Image<Rgba32> image = new Image<Rgba32>(400, 400))
`Rgba32` is our default PixelFormat, equivalent to `System.Drawing Color`. For advanced pixel format usage there are multiple [PixelFormat implementations](https://github.com/SixLabors/ImageSharp/tree/master/src/ImageSharp/PixelFormats) available allowing developers to implement their own color models in the same manner as Microsoft XNA Game Studio and MonoGame.
All in all this should allow image processing to be much more accessible to developers which has always been my goal from the start.
**Check out [this blog post](https://sixlabors.com/blog/announcing-imagesharp-beta-1/) or our [Samples Repository](https://github.com/SixLabors/Samples/tree/master/ImageSharp) for more examples!**
**Check out this [blog post](https://sixlabors.com/blog/announcing-imagesharp-beta-1/) or our [Samples Repository](https://github.com/SixLabors/Samples/tree/master/ImageSharp) for more examples!**
### Manual build

4
build/icons/imagesharp-logo-128.png

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e0f7d4c9396d4c7fe8173057c44cc2c0ecc24e52b52ce67c97dd11a7ac6e79ed
size 8113
oid sha256:148a268c589b628f5d0b5af0e86911a0b393c35b8b25233c71553657c88e0b96
size 7568

4
build/icons/imagesharp-logo-256.png

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7583dab9f399b7b9a7f69fc87086caa439249a705b058d6bfbd88238cfd95d4e
size 16613
oid sha256:7e4b2ff72aef1979500cd130c28490a00be116bb833bc96ca30c85dc0596099c
size 15413

4
build/icons/imagesharp-logo-32.png

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c2b4b7ede0bf2fb4a9d028c9c4e930ab092b8c45689dd288ed1e419b5207048b
size 1904
oid sha256:021c12313afbdc65f58bfea8c7b436d5c2102513bb63d9e64ee2b61a1344c56a
size 1799

4
build/icons/imagesharp-logo-512.png

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:cd9c567ef861075fcaef709577e87017b5834556df5fc6ff51c4ded8972568a8
size 35069
oid sha256:3ae54ae0035df1f8f1459081e2f1d5cceda6f88cca6ec015d8c0209bf0d34edf
size 32534

4
build/icons/imagesharp-logo-64.png

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:28a0995e02d0535a13d08997d36cc7b4df95760f9499396b209ad2c7d73ccef6
size 3962
oid sha256:92896854265693f28f9a503b9093cb2c9a4a9b329f310732efdd9c6f6c3761bc
size 3736

3
build/icons/imagesharp-logo-heading.png

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9480cb9ac66963e717b7e89666375e8bb23183e456067fd7d445ffb3c182b425
size 11390

4
build/icons/imagesharp-logo.png

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:cd9c567ef861075fcaef709577e87017b5834556df5fc6ff51c4ded8972568a8
size 35069
oid sha256:3ae54ae0035df1f8f1459081e2f1d5cceda6f88cca6ec015d8c0209bf0d34edf
size 32534

2
build/icons/imagesharp-logo.svg

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

149
features.md

@ -1,149 +0,0 @@
# Features
### What works so far/ What is planned?
We've achieved a lot so far and hope to do a lot more in the future. We're always looking for help so please pitch in!
- **Encoding/decoding of image formats (plugable).**
- [x] Jpeg (Includes Subsampling. Progressive writing required)
- [x] Bmp (Read: 32bit, 24bit, 16 bit. Write: 32bit, 24bit just now)
- [x] Png (Read: Rgb, Rgba, Grayscale, Grayscale + alpha, Palette. Write: Rgb, Rgba, Grayscale, Grayscale + alpha, Palette) Supports interlaced decoding
- [x] Gif (Includes animated)
- [ ] Tiff (Help needed)
- **Metadata**
- [x] EXIF Read/Write (Jpeg just now)
- [ ] ICC (In Progress)
- **Quantizers (IQuantizer with alpha channel support, dithering, and thresholding)**
- [x] Octree
- [x] Xiaolin Wu
- [x] Palette
- **DIthering (Error diffusion and Ordered)**
- [x] Atkinson
- [x] Burks
- [x] FloydSteinburg
- [x] JarvisJudiceNinke
- [x] Sieera2
- [x] Sierra3
- [x] SerraLite
- [x] Bayer
- [x] Ordered
- **Basic color structs with implicit operators.**
- [x] Bgra32
- [x] CIE Lab
- [x] CIE XYZ
- [x] CMYK
- [x] HSV
- [x] HSL
- [x] YCbCr
- **IPackedPixel representations of color models. Compatible with Microsoft XNA Game Studio and MonoGame IPackedVector\<TPacked\>.**
- [x] Alpha8
- [x] Argb32
- [x] Bgr565
- [x] Bgra444
- [x] Bgra565
- [x] Byte4
- [x] HalfSingle
- [x] HalfVector2
- [x] HalfVector4
- [x] NormalizedByte2
- [x] NormalizedByte4
- [x] NormalizedShort2
- [x] NormalizedShort4
- [x] Rg32
- [x] Rgba1010102
- [x] Rgba32 - 32bit color in RGBA order - Our default pixel format.
- [x] Rgba64
- [x] RgbaVector
- [x] Short2
- [x] Short4
- **Basic shape primitives.**
- [x] Rectangle
- [x] Size
- [x] Point
- [x] Ellipse
- **Resampling algorithms. (Optional gamma correction, resize modes, Performance improvements?)**
- [x] Box
- [x] Bicubic
- [x] Lanczos2
- [x] Lanczos3
- [x] Lanczos5
- [x] Lanczos8
- [x] MitchelNetravali
- [x] Nearest Neighbour
- [x] Robidoux
- [x] Robidoux Sharp
- [x] Spline
- [x] Triangle
- [x] Welch
- **Padding**
- [x] Pad
- [x] ResizeMode.Pad
- [x] ResizeMode.BoxPad
- **Cropping**
- [x] Rectangular Crop
- [ ] Elliptical Crop
- [x] Entropy Crop
- [x] ResizeMode.Crop
- **Rotation/Skew**
- [x] Flip (90, 270, FlipType etc)
- [x] Rotate by angle and center point (Expandable canvas).
- [x] Skew by x/y angles and center point (Expandable canvas).
- **ColorMatrix operations (Uses Matrix4x4)**
- [x] BlackWhite
- [x] Grayscale BT709
- [x] Grayscale BT601
- [x] Hue
- [x] Saturation
- [x] Lomograph
- [x] Polaroid
- [x] Kodachrome
- [x] Sepia
- [x] Achromatomaly
- [x] Achromatopsia
- [x] Deuteranomaly
- [x] Deuteranopia
- [x] Protanomaly
- [x] Protanopia
- [x] Tritanomaly
- [x] Tritanopia
- **Edge Detection**
- [x] Kayyali
- [x] Kirsch
- [x] Laplacian3X3
- [x] Laplacian5X5
- [x] LaplacianOfGaussian
- [x] Prewitt
- [x] RobertsCross
- [x] Robinson
- [x] Scharr
- [x] Sobel
- **Blurring/Sharpening**
- [x] Gaussian blur
- [x] Gaussian sharpening
- [x] Box Blur
- **Filters**
- [x] Alpha
- [x] Contrast
- [x] Invert
- [x] BackgroundColor
- [x] Brightness
- [x] Pixelate
- [ ] Mask
- [x] Oil Painting
- [x] Vignette
- [x] Glow
- [x] Threshold
- **Drawing**
- [x] Image brush
- [x] Pattern brush
- [x] Solid brush
- [X] Hatch brush (Partial copy of System.Drawing brushes)
- [x] Pen (Solid, Dash, Custom)
- [x] Line drawing
- [x] Complex Polygons (Fill, draw)
- [x] DrawImage
- [ ] Gradient brush (Need help)
- **DrawingText**
- [ ] DrawString (In-progress. Single variant support just now, no italic,bold)
- Other stuff I haven't thought of.

3
input/about.md

@ -1,3 +0,0 @@
Title: About This Project
---
This project is awesome!

2
src/ImageSharp.Drawing/ImageSharp.Drawing.csproj

@ -46,7 +46,7 @@
</ItemGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>..\..\ImageSharp.ruleset</CodeAnalysisRuleSet>
<RootNamespace>SixLabors.ImageSharp.Drawing</RootNamespace>
<RootNamespace>SixLabors.ImageSharp</RootNamespace>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

3
src/ImageSharp.Drawing/Region.cs → src/ImageSharp.Drawing/Primitives/Region.cs

@ -1,10 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Drawing
namespace SixLabors.ImageSharp.Primitives
{
/// <summary>
/// Represents a region of an image.

14
src/ImageSharp.Drawing/Paths/ShapePath.cs → src/ImageSharp.Drawing/Primitives/ShapePath.cs

@ -1,14 +1,10 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Buffers;
using System.Numerics;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Processing.Drawing.Pens;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp.Drawing
namespace SixLabors.ImageSharp.Primitives
{
/// <summary>
/// A mapping between a <see cref="IPath"/> and a region.
@ -20,10 +16,10 @@ namespace SixLabors.ImageSharp.Drawing
/// </summary>
/// <param name="shape">The shape.</param>
/// <param name="pen">The pen to apply to the shape.</param>
// SixLabors.shape willbe moving to a Span/ReadOnlySpan based API shortly use ToArray for now.
public ShapePath(IPath shape, Pens.IPen pen)
// TODO: SixLabors.shape will be moving to a Span/ReadOnlySpan based API shortly use ToArray for now.
public ShapePath(IPath shape, IPen pen)
: base(shape.GenerateOutline(pen.StrokeWidth, pen.StrokePattern.ToArray()))
{
}
}
}
}

7
src/ImageSharp.Drawing/Paths/ShapeRegion.cs → src/ImageSharp.Drawing/Primitives/ShapeRegion.cs

@ -2,13 +2,10 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Buffers;
using System.Numerics;
using SixLabors.ImageSharp.Memory;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp.Drawing
namespace SixLabors.ImageSharp.Primitives
{
/// <summary>
/// A mapping between a <see cref="IPath"/> and a region.
@ -48,7 +45,7 @@ namespace SixLabors.ImageSharp.Drawing
var end = new PointF(this.Bounds.Right + 1, y);
// TODO: This is a temporary workaround because of the lack of Span<T> API-s on IPath. We should use MemoryManager.Allocate() here!
PointF[] innerBuffer = new PointF[buffer.Length];
var innerBuffer = new PointF[buffer.Length];
int count = this.Shape.FindIntersections(start, end, innerBuffer, 0);
for (int i = 0; i < count; i++)

12
src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs → src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs

@ -6,7 +6,7 @@ using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Drawing.Brushes.Processors
namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
{
/// <summary>
/// primitive that converts a point in to a color for discovering the fill color based on an implementation
@ -31,12 +31,12 @@ namespace SixLabors.ImageSharp.Drawing.Brushes.Processors
}
/// <summary>
/// Gets the blendder
/// Gets the blender
/// </summary>
internal PixelBlender<TPixel> Blender { get; }
/// <summary>
/// Gets the destinaion
/// Gets the destination
/// </summary>
protected ImageFrame<TPixel> Target { get; }
@ -48,8 +48,8 @@ namespace SixLabors.ImageSharp.Drawing.Brushes.Processors
/// <summary>
/// Gets the color for a single pixel.
/// </summary>
/// <param name="x">The x cordinate.</param>
/// <param name="y">The y cordinate.</param>
/// <param name="x">The x coordinate.</param>
/// <param name="y">The y coordinate.</param>
/// <returns>The a <typeparamref name="TPixel"/> that should be applied to the pixel.</returns>
internal abstract TPixel this[int x, int y] { get; }
@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes.Processors
public abstract void Dispose();
/// <summary>
/// Applies the opactiy weighting for each pixel in a scanline to the target based on the pattern contained in the brush.
/// Applies the opacity weighting for each pixel in a scanline to the target based on the pattern contained in the brush.
/// </summary>
/// <param name="scanline">The a collection of opacity values between 0 and 1 to be merged with the brushed color value before being applied to the target.</param>
/// <param name="x">The x position in the target pixel space that the start of the scanline data corresponds to.</param>

2
src/ImageSharp.Drawing/Brushes/Brushes.cs → src/ImageSharp.Drawing/Processing/Drawing/Brushes/Brushes.cs

@ -3,7 +3,7 @@
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Drawing.Brushes
namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
{
/// <summary>
/// A collection of methods for creating generic brushes.

4
src/ImageSharp.Drawing/Brushes/IBrush.cs → src/ImageSharp.Drawing/Processing/Drawing/Brushes/IBrush.cs

@ -1,12 +1,10 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing.Brushes.Processors;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Drawing.Brushes
namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
{
/// <summary>
/// Brush represents a logical configuration of a brush which can be used to source pixel colors

8
src/ImageSharp.Drawing/Brushes/ImageBrush{TPixel}.cs → src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs

@ -3,13 +3,11 @@
using System;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Drawing.Brushes.Processors;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Drawing.Brushes
namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
{
/// <summary>
/// Provides an implementation of an image brush for painting images within areas.
@ -43,9 +41,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
/// <inheritdoc />
public BrushApplicator<TPixel> CreateApplicator(ImageFrame<TPixel> source, RectangleF region, GraphicsOptions options)
{
return new ImageBrushApplicator(source, this.image, region, options);
}
=> new ImageBrushApplicator(source, this.image, region, options);
/// <summary>
/// The image brush applicator.

31
src/ImageSharp.Drawing/Brushes/PatternBrush{TPixel}.cs → src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs

@ -4,13 +4,12 @@
using System;
using System.Numerics;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Drawing.Brushes.Processors;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Drawing.Brushes
namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
{
/// <summary>
/// Provides an implementation of a pattern brush for painting patterns.
@ -40,8 +39,8 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
/// <summary>
/// The pattern.
/// </summary>
private readonly Fast2DArray<TPixel> pattern;
private readonly Fast2DArray<Vector4> patternVector;
private readonly DenseMatrix<TPixel> pattern;
private readonly DenseMatrix<Vector4> patternVector;
/// <summary>
/// Initializes a new instance of the <see cref="PatternBrush{TPixel}"/> class.
@ -50,7 +49,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
/// <param name="backColor">Color of the back.</param>
/// <param name="pattern">The pattern.</param>
public PatternBrush(TPixel foreColor, TPixel backColor, bool[,] pattern)
: this(foreColor, backColor, new Fast2DArray<bool>(pattern))
: this(foreColor, backColor, new DenseMatrix<bool>(pattern))
{
}
@ -60,12 +59,12 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
/// <param name="foreColor">Color of the fore.</param>
/// <param name="backColor">Color of the back.</param>
/// <param name="pattern">The pattern.</param>
internal PatternBrush(TPixel foreColor, TPixel backColor, Fast2DArray<bool> pattern)
internal PatternBrush(TPixel foreColor, TPixel backColor, DenseMatrix<bool> pattern)
{
var foreColorVector = foreColor.ToVector4();
var backColorVector = backColor.ToVector4();
this.pattern = new Fast2DArray<TPixel>(pattern.Width, pattern.Height);
this.patternVector = new Fast2DArray<Vector4>(pattern.Width, pattern.Height);
this.pattern = new DenseMatrix<TPixel>(pattern.Columns, pattern.Rows);
this.patternVector = new DenseMatrix<Vector4>(pattern.Columns, pattern.Rows);
for (int i = 0; i < pattern.Data.Length; i++)
{
if (pattern.Data[i])
@ -105,8 +104,8 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
/// <summary>
/// The pattern.
/// </summary>
private readonly Fast2DArray<TPixel> pattern;
private readonly Fast2DArray<Vector4> patternVector;
private readonly DenseMatrix<TPixel> pattern;
private readonly DenseMatrix<Vector4> patternVector;
/// <summary>
/// Initializes a new instance of the <see cref="PatternBrushApplicator" /> class.
@ -115,7 +114,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
/// <param name="pattern">The pattern.</param>
/// <param name="patternVector">The patternVector.</param>
/// <param name="options">The options</param>
public PatternBrushApplicator(ImageFrame<TPixel> source, Fast2DArray<TPixel> pattern, Fast2DArray<Vector4> patternVector, GraphicsOptions options)
public PatternBrushApplicator(ImageFrame<TPixel> source, DenseMatrix<TPixel> pattern, DenseMatrix<Vector4> patternVector, GraphicsOptions options)
: base(source, options)
{
this.pattern = pattern;
@ -134,8 +133,8 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
{
get
{
x = x % this.pattern.Width;
y = y % this.pattern.Height;
x = x % this.pattern.Columns;
y = y % this.pattern.Rows;
// 2d array index at row/column
return this.pattern[y, x];
@ -151,7 +150,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
/// <inheritdoc />
internal override void Apply(Span<float> scanline, int x, int y)
{
int patternY = y % this.pattern.Height;
int patternY = y % this.pattern.Rows;
MemoryManager memoryManager = this.Target.MemoryManager;
using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length))
@ -164,7 +163,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
{
amountSpan[i] = (scanline[i] * this.Options.BlendPercentage).Clamp(0, 1);
int patternX = (x + i) % this.pattern.Width;
int patternX = (x + i) % this.pattern.Columns;
overlaySpan[i] = this.pattern[patternY, patternX];
}

26
src/ImageSharp.Drawing/Brushes/RecolorBrush{TPixel}.cs → src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs

@ -4,13 +4,11 @@
using System;
using System.Numerics;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Drawing.Brushes.Processors;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Drawing.Brushes
namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
{
/// <summary>
/// Provides an implementation of a brush that can recolor an image
@ -23,21 +21,18 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
/// Initializes a new instance of the <see cref="RecolorBrush{TPixel}" /> class.
/// </summary>
/// <param name="sourceColor">Color of the source.</param>
/// <param name="targeTPixel">Color of the target.</param>
/// <param name="targetColor">Color of the target.</param>
/// <param name="threshold">The threshold as a value between 0 and 1.</param>
public RecolorBrush(TPixel sourceColor, TPixel targeTPixel, float threshold)
public RecolorBrush(TPixel sourceColor, TPixel targetColor, float threshold)
{
this.SourceColor = sourceColor;
this.Threshold = threshold;
this.TargeTPixel = targeTPixel;
this.TargetColor = targetColor;
}
/// <summary>
/// Gets the threshold.
/// </summary>
/// <value>
/// The threshold.
/// </value>
public float Threshold { get; }
/// <summary>
@ -51,15 +46,12 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
/// <summary>
/// Gets the target color.
/// </summary>
/// <value>
/// The color of the target.
/// </value>
public TPixel TargeTPixel { get; }
public TPixel TargetColor { get; }
/// <inheritdoc />
public BrushApplicator<TPixel> CreateApplicator(ImageFrame<TPixel> source, RectangleF region, GraphicsOptions options)
{
return new RecolorBrushApplicator(source, this.SourceColor, this.TargeTPixel, this.Threshold, options);
return new RecolorBrushApplicator(source, this.SourceColor, this.TargetColor, this.Threshold, options);
}
/// <summary>
@ -99,7 +91,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
this.targetColor = targetColor.ToVector4();
this.targetColorPixel = targetColor;
// Lets hack a min max extreams for a color space by letting the IPackedPixel clamp our values to something in the correct spaces :)
// Lets hack a min max extremes for a color space by letting the IPackedPixel clamp our values to something in the correct spaces :)
var maxColor = default(TPixel);
maxColor.PackFromVector4(new Vector4(float.MaxValue));
var minColor = default(TPixel);
@ -158,8 +150,8 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
int offsetX = x + i;
// no doubt this one can be optermised further but I can't imagine its
// actually being used and can probably be removed/interalised for now
// No doubt this one can be optimized further but I can't imagine its
// actually being used and can probably be removed/internalized for now
overlaySpan[i] = this[offsetX, y];
}

5
src/ImageSharp.Drawing/Brushes/SolidBrush{TPixel}.cs → src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs

@ -2,15 +2,12 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Drawing.Brushes.Processors;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Drawing.Brushes
namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
{
/// <summary>
/// Provides an implementation of a solid brush for painting solid color areas.

60
src/ImageSharp.Drawing/Paths/DrawBeziers.cs → src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs

@ -1,23 +1,21 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.ImageSharp.Processing.Drawing.Pens;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Drawing
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of Bezier paths to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class DrawBezierExtensions
{
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -27,13 +25,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawBeziers<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), new Path(new CubicBezierLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), new Path(new CubicBezierLineSegment(points)), options);
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -42,13 +38,11 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawBeziers<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), new Path(new CubicBezierLineSegment(points)));
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), new Path(new CubicBezierLineSegment(points)));
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -57,13 +51,11 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawBeziers<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawBeziers(new SolidBrush<TPixel>(color), thickness, points);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawBeziers(new SolidBrush<TPixel>(color), thickness, points);
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -73,13 +65,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawBeziers<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawBeziers(new SolidBrush<TPixel>(color), thickness, points, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawBeziers(new SolidBrush<TPixel>(color), thickness, points, options);
/// <summary>
/// Draws the provided Points as an open Bezier path with the supplied pen
/// Draws the provided points as an open Bezier path with the supplied pen
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -88,13 +78,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawBeziers<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new Path(new CubicBezierLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, new Path(new CubicBezierLineSegment(points)), options);
/// <summary>
/// Draws the provided Points as an open Bezier path with the supplied pen
/// Draws the provided points as an open Bezier path with the supplied pen
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -102,9 +90,7 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawBeziers<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new Path(new CubicBezierLineSegment(points)));
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, new Path(new CubicBezierLineSegment(points)));
}
}

65
src/ImageSharp.Drawing/DrawImage.cs → src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs

@ -1,33 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Drawing
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of images to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class DrawImageExtensions
{
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, Point location, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, options));
return source;
}
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
/// </summary>
@ -38,11 +22,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Blend<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, float opacity)
where TPixel : struct, IPixel<TPixel>
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlendPercentage = opacity;
return DrawImage(source, image, Point.Empty, options);
}
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, opacity));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
@ -55,12 +35,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Blend<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, PixelBlenderMode blender, float opacity)
where TPixel : struct, IPixel<TPixel>
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlendPercentage = opacity;
options.BlenderMode = blender;
return DrawImage(source, image, Point.Empty, options);
}
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, opacity, blender));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
@ -73,7 +48,7 @@ namespace SixLabors.ImageSharp
public static IImageProcessingContext<TPixel> Blend<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return DrawImage(source, image, Point.Empty, options);
return source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, options));
}
/// <summary>
@ -87,11 +62,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, float opacity, Point location)
where TPixel : struct, IPixel<TPixel>
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlendPercentage = opacity;
return source.DrawImage(image, location, options);
}
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, opacity));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
@ -105,11 +76,19 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, PixelBlenderMode blender, float opacity, Point location)
where TPixel : struct, IPixel<TPixel>
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlenderMode = blender;
options.BlendPercentage = opacity;
return source.DrawImage(image, location, options);
}
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, opacity, blender));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="options">The options containing the blend mode and opacity.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, Point location, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, options));
}
}

48
src/ImageSharp.Drawing/Paths/DrawLines.cs → src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs

@ -1,20 +1,18 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.ImageSharp.Processing.Drawing.Pens;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Drawing
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of lines to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class DrawLineExtensions
{
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
@ -27,10 +25,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), new Path(new LinearLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), new Path(new LinearLineSegment(points)), options);
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
@ -42,10 +38,8 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), new Path(new LinearLineSegment(points)));
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), new Path(new LinearLineSegment(points)));
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
@ -57,10 +51,8 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawLines(new SolidBrush<TPixel>(color), thickness, points);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawLines(new SolidBrush<TPixel>(color), thickness, points);
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
@ -73,10 +65,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawLines(new SolidBrush<TPixel>(color), thickness, points, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawLines(new SolidBrush<TPixel>(color), thickness, points, options);
/// <summary>
/// Draws the provided Points as an open Linear path with the supplied pen
@ -88,10 +78,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new Path(new LinearLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, new Path(new LinearLineSegment(points)), options);
/// <summary>
/// Draws the provided Points as an open Linear path with the supplied pen
@ -102,9 +90,7 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new Path(new LinearLineSegment(points)));
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, new Path(new LinearLineSegment(points)));
}
}

43
src/ImageSharp.Drawing/Paths/DrawPathCollection.cs → src/ImageSharp.Drawing/Processing/Drawing/DrawPathCollectionExtensions.cs

@ -1,18 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.ImageSharp.Processing.Drawing.Pens;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Drawing
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of collections of polygon outlines to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class DrawPathCollectionExtensions
{
/// <summary>
/// Draws the outline of the polygon with the provided pen.
@ -43,10 +42,8 @@ namespace SixLabors.ImageSharp
/// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, IPathCollection paths)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, paths, GraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, paths, GraphicsOptions.Default);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -59,10 +56,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, IPathCollection paths, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), paths, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), paths, options);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -74,10 +69,8 @@ namespace SixLabors.ImageSharp
/// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, IPathCollection paths)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), paths);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), paths);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -90,10 +83,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, IPathCollection paths, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new SolidBrush<TPixel>(color), thickness, paths, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new SolidBrush<TPixel>(color), thickness, paths, options);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -105,9 +96,7 @@ namespace SixLabors.ImageSharp
/// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, IPathCollection paths)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new SolidBrush<TPixel>(color), thickness, paths);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new SolidBrush<TPixel>(color), thickness, paths);
}
}
}

48
src/ImageSharp.Drawing/Paths/DrawPath.cs → src/ImageSharp.Drawing/Processing/Drawing/DrawPathExtensions.cs

@ -1,18 +1,18 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.ImageSharp.Processing.Drawing.Pens;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Drawing
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of polygon outlines to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class DrawPathExtensions
{
/// <summary>
/// Draws the outline of the polygon with the provided pen.
@ -24,10 +24,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(pen.StrokeFill, new ShapePath(path, pen), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(pen.StrokeFill, new ShapePath(path, pen), options);
/// <summary>
/// Draws the outline of the polygon with the provided pen.
@ -38,10 +36,8 @@ namespace SixLabors.ImageSharp
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, path, GraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, path, GraphicsOptions.Default);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -54,10 +50,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), path, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), path, options);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -69,10 +63,8 @@ namespace SixLabors.ImageSharp
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), path);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), path);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -85,10 +77,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new SolidBrush<TPixel>(color), thickness, path, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new SolidBrush<TPixel>(color), thickness, path, options);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -100,9 +90,7 @@ namespace SixLabors.ImageSharp
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new SolidBrush<TPixel>(color), thickness, path);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new SolidBrush<TPixel>(color), thickness, path);
}
}

50
src/ImageSharp.Drawing/Paths/DrawPolygon.cs → src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs

@ -1,20 +1,18 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.ImageSharp.Processing.Drawing.Pens;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Drawing
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of closed linear polygons to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class DrawPolygonExtensions
{
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
@ -27,10 +25,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), new Polygon(new LinearLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), new Polygon(new LinearLineSegment(points)), options);
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
@ -42,10 +38,8 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), new Polygon(new LinearLineSegment(points)));
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), new Polygon(new LinearLineSegment(points)));
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
@ -57,10 +51,8 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawPolygon(new SolidBrush<TPixel>(color), thickness, points);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawPolygon(new SolidBrush<TPixel>(color), thickness, points);
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
@ -73,10 +65,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawPolygon(new SolidBrush<TPixel>(color), thickness, points, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawPolygon(new SolidBrush<TPixel>(color), thickness, points, options);
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen.
@ -87,10 +77,8 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default);
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen.
@ -102,9 +90,7 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, new Polygon(new LinearLineSegment(points)), options);
}
}
}

62
src/ImageSharp.Drawing/Paths/DrawRectangle.cs → src/ImageSharp.Drawing/Processing/Drawing/DrawRectangleExtensions.cs

@ -1,21 +1,21 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.ImageSharp.Processing.Drawing.Pens;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Drawing
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of rectangles to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class DrawRectangleExtensions
{
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// Draws the outline of the rectangle with the provided pen.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -24,13 +24,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, RectangleF shape, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, new RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options);
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// Draws the outline of the rectangle with the provided pen.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -38,13 +36,11 @@ namespace SixLabors.ImageSharp
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, RectangleF shape)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, shape, GraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, shape, GraphicsOptions.Default);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// Draws the outline of the rectangle with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -54,13 +50,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, RectangleF shape, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), shape, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), shape, options);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// Draws the outline of the rectangle with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -69,13 +63,11 @@ namespace SixLabors.ImageSharp
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, RectangleF shape)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), shape);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), shape);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// Draws the outline of the rectangle with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -85,13 +77,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new SolidBrush<TPixel>(color), thickness, shape, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new SolidBrush<TPixel>(color), thickness, shape, options);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// Draws the outline of the rectangle with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -100,9 +90,7 @@ namespace SixLabors.ImageSharp
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, RectangleF shape)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new SolidBrush<TPixel>(color), thickness, shape);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new SolidBrush<TPixel>(color), thickness, shape);
}
}
}

35
src/ImageSharp.Drawing/Paths/FillPathBuilder.cs → src/ImageSharp.Drawing/Processing/Drawing/FillPathBuilderExtensions.cs

@ -2,20 +2,19 @@
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Drawing
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the filling of polygons with various brushes to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class FillPathBuilderExtensions
{
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -41,13 +40,11 @@ namespace SixLabors.ImageSharp
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, Action<PathBuilder> path)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, path, GraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(brush, path, GraphicsOptions.Default);
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -56,13 +53,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Action<PathBuilder> path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), path, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), path, options);
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -70,9 +65,7 @@ namespace SixLabors.ImageSharp
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Action<PathBuilder> path)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), path);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), path);
}
}
}

35
src/ImageSharp.Drawing/Paths/FillPathCollection.cs → src/ImageSharp.Drawing/Processing/Drawing/FillPathCollectionExtensions.cs

@ -1,20 +1,19 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Drawing
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the filling of collections of polygon outlines to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class FillPathCollectionExtensions
{
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -42,13 +41,11 @@ namespace SixLabors.ImageSharp
/// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, IPathCollection paths)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, paths, GraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(brush, paths, GraphicsOptions.Default);
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -57,13 +54,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, IPathCollection paths, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), paths, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), paths, options);
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -71,9 +66,7 @@ namespace SixLabors.ImageSharp
/// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, IPathCollection paths)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), paths);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), paths);
}
}
}

36
src/ImageSharp.Drawing/Paths/FillPaths.cs → src/ImageSharp.Drawing/Processing/Drawing/FillPathExtensions.cs

@ -1,17 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Drawing
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the filling of polygon outlines to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class FillPathExtensions
{
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
@ -23,10 +23,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new ShapeRegion(path), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(brush, new ShapeRegion(path), options);
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.
@ -37,10 +35,8 @@ namespace SixLabors.ImageSharp
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default);
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
@ -52,10 +48,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), path, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), path, options);
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
@ -66,9 +60,7 @@ namespace SixLabors.ImageSharp
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), path);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), path);
}
}
}

37
src/ImageSharp.Drawing/Paths/FillPolygon.cs → src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs

@ -1,20 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Drawing
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the filling of closed linear polygons to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class FillPolygonExtensions
{
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
@ -26,10 +23,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> FillPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(brush, new Polygon(new LinearLineSegment(points)), options);
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
@ -40,10 +35,8 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> FillPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new Polygon(new LinearLineSegment(points)));
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(brush, new Polygon(new LinearLineSegment(points)));
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
@ -55,10 +48,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> FillPolygon<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), new Polygon(new LinearLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), new Polygon(new LinearLineSegment(points)), options);
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
@ -69,9 +60,7 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> FillPolygon<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), new Polygon(new LinearLineSegment(points)));
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), new Polygon(new LinearLineSegment(points)));
}
}
}

38
src/ImageSharp.Drawing/Paths/FillRectangle.cs → src/ImageSharp.Drawing/Processing/Drawing/FillRectangleExtensions.cs

@ -1,20 +1,20 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Drawing
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the filling of rectangles to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class FillRectangleExtensions
{
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// Flood fills the image in the shape of the provided rectangle with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -24,12 +24,10 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, RectangleF shape, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options);
}
=> source.Fill(brush, new RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options);
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// Flood fills the image in the shape of the provided rectangle with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -38,12 +36,10 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, RectangleF shape)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height));
}
=> source.Fill(brush, new RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height));
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// Flood fills the image in the shape of the provided rectangle with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -52,13 +48,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, RectangleF shape, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), shape, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), shape, options);
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// Flood fills the image in the shape of the provided rectangle with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -67,8 +61,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, RectangleF shape)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), shape);
}
=> source.Fill(new SolidBrush<TPixel>(color), shape);
}
}
}

92
src/ImageSharp.Drawing/FillRegion.cs → src/ImageSharp.Drawing/Processing/Drawing/FillRegionExtensions.cs

@ -1,32 +1,18 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.ImageSharp.Processing.Drawing.Processors;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Drawing
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the filling of regions with various brushes to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class FillRegionExtensions
{
/// <summary>
/// Flood fills the image with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The details how to fill the region of interest.</param>
/// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.ApplyProcessor(new FillProcessor<TPixel>(brush, options));
}
/// <summary>
/// Flood fills the image with the specified brush.
/// </summary>
@ -36,9 +22,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, GraphicsOptions.Default);
}
=> source.Fill(brush, GraphicsOptions.Default);
/// <summary>
/// Flood fills the image with the specified color.
@ -49,9 +33,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color));
}
=> source.Fill(new SolidBrush<TPixel>(color));
/// <summary>
/// Flood fills the image with in the region with the specified brush.
@ -60,27 +42,23 @@ namespace SixLabors.ImageSharp
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param>
/// <param name="region">The region.</param>
/// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, Region region, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.ApplyProcessor(new FillRegionProcessor<TPixel>(brush, region, options));
}
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, Region region)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(brush, region, GraphicsOptions.Default);
/// <summary>
/// Flood fills the image with in the region with the specified brush.
/// Flood fills the image with in the region with the specified color.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param>
/// <param name="color">The color.</param>
/// <param name="region">The region.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, Region region)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, region, GraphicsOptions.Default);
}
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Region region, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), region, options);
/// <summary>
/// Flood fills the image with in the region with the specified color.
@ -89,26 +67,34 @@ namespace SixLabors.ImageSharp
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param>
/// <param name="region">The region.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Region region, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), region, options);
}
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Region region)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), region);
/// <summary>
/// Flood fills the image with in the region with the specified color.
/// Flood fills the image with in the region with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param>
/// <param name="brush">The brush.</param>
/// <param name="region">The region.</param>
/// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Region region)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), region);
}
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, Region region, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new FillRegionProcessor<TPixel>(brush, region, options));
/// <summary>
/// Flood fills the image with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The details how to fill the region of interest.</param>
/// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new FillProcessor<TPixel>(brush, options));
}
}
}

10
src/ImageSharp.Drawing/Pens/IPen.cs → src/ImageSharp.Drawing/Processing/Drawing/Pens/IPen.cs

@ -1,11 +1,11 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Processors;
using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
namespace SixLabors.ImageSharp.Drawing.Pens
namespace SixLabors.ImageSharp.Processing.Drawing.Pens
{
/// <summary>
/// Interface representing a Pen
@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Drawing.Pens
}
/// <summary>
/// Iterface represting the pattern and size of the stroke to apply with a Pen.
/// Interface representing the pattern and size of the stroke to apply with a Pen.
/// </summary>
public interface IPen
{
@ -33,6 +33,6 @@ namespace SixLabors.ImageSharp.Drawing.Pens
/// <summary>
/// Gets the stoke pattern.
/// </summary>
System.ReadOnlySpan<float> StrokePattern { get; }
ReadOnlySpan<float> StrokePattern { get; }
}
}

15
src/ImageSharp.Drawing/Pens/Pens.cs → src/ImageSharp.Drawing/Processing/Drawing/Pens/Pens.cs

@ -1,20 +1,21 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
namespace SixLabors.ImageSharp.Drawing.Pens
namespace SixLabors.ImageSharp.Processing.Drawing.Pens
{
/// <summary>
/// Common Pen styles
/// Contains a collection of common Pen styles
/// </summary>
public static class Pens
{
private static readonly float[] DashDotPattern = new[] { 3f, 1f, 1f, 1f };
private static readonly float[] DashDotDotPattern = new[] { 3f, 1f, 1f, 1f, 1f, 1f };
private static readonly float[] DottedPattern = new[] { 1f, 1f };
private static readonly float[] DashedPattern = new[] { 3f, 1f };
private static readonly float[] DashDotPattern = { 3f, 1f, 1f, 1f };
private static readonly float[] DashDotDotPattern = { 3f, 1f, 1f, 1f, 1f, 1f };
private static readonly float[] DottedPattern = { 1f, 1f };
private static readonly float[] DashedPattern = { 3f, 1f };
internal static readonly float[] EmptyPattern = new float[0];
/// <summary>
/// Create a solid pen with out any drawing patterns

19
src/ImageSharp.Drawing/Pens/Pen{TPixel}.cs → src/ImageSharp.Drawing/Processing/Drawing/Pens/Pen{TPixel}.cs

@ -2,12 +2,10 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
namespace SixLabors.ImageSharp.Drawing.Pens
namespace SixLabors.ImageSharp.Processing.Drawing.Pens
{
/// <summary>
/// Provides a pen that can apply a pattern to a line with a set brush and thickness
@ -19,16 +17,15 @@ namespace SixLabors.ImageSharp.Drawing.Pens
/// section 1 will be width long (making a square) and will be filled by the brush
/// section 2 will be width * 2 long and will be empty
/// section 3 will be width/2 long and will be filled
/// the the pattern will imidiatly repeat without gap.
/// the the pattern will immediately repeat without gap.
/// </remarks>
public class Pen<TPixel> : IPen<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private static readonly float[] EmptyPattern = new float[0];
private readonly float[] pattern;
/// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TPixel}"/> class.
/// Initializes a new instance of the <see cref="Drawing.Pens.Pen{TPixel}"/> class.
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
@ -39,7 +36,7 @@ namespace SixLabors.ImageSharp.Drawing.Pens
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TPixel}"/> class.
/// Initializes a new instance of the <see cref="Drawing.Pens.Pen{TPixel}"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
@ -52,7 +49,7 @@ namespace SixLabors.ImageSharp.Drawing.Pens
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TPixel}"/> class.
/// Initializes a new instance of the <see cref="Drawing.Pens.Pen{TPixel}"/> class.
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
@ -62,12 +59,12 @@ namespace SixLabors.ImageSharp.Drawing.Pens
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TPixel}"/> class.
/// Initializes a new instance of the <see cref="Drawing.Pens.Pen{TPixel}"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
public Pen(IBrush<TPixel> brush, float width)
: this(brush, width, EmptyPattern)
: this(brush, width, Pens.EmptyPattern)
{
}

155
src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs

@ -0,0 +1,155 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Processing.Drawing.Processors
{
/// <summary>
/// Combines two images together by blending the pixels.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class DrawImageProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
public DrawImageProcessor(Image<TPixel> image, float opacity)
: this(image, Point.Empty, opacity)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="options">
/// The options containing the opacity of the image to blend and blending mode.
/// Opacity must be between 0 and 1.
/// </param>
public DrawImageProcessor(Image<TPixel> image, GraphicsOptions options)
: this(image, Point.Empty, options)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
public DrawImageProcessor(Image<TPixel> image, Point location, float opacity)
: this(image, location, opacity, GraphicsOptions.Default.BlenderMode)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="options">
/// The options containing the opacity of the image to blend and blending mode.
/// Opacity must be between 0 and 1.
/// </param>
public DrawImageProcessor(Image<TPixel> image, Point location, GraphicsOptions options)
: this(image, location, options.BlendPercentage, options.BlenderMode)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
/// <param name="blenderMode">The blending mode to use when drawing the image.</param>
public DrawImageProcessor(Image<TPixel> image, float opacity, PixelBlenderMode blenderMode)
: this(image, Point.Empty, opacity, blenderMode)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
/// <param name="blenderMode">The blending mode to use when drawing the image.</param>
public DrawImageProcessor(Image<TPixel> image, Point location, float opacity, PixelBlenderMode blenderMode)
{
Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));
this.Image = image;
this.Opacity = opacity;
this.Blender = PixelOperations<TPixel>.Instance.GetPixelBlender(blenderMode);
this.Location = location;
}
/// <summary>
/// Gets the image to blend
/// </summary>
public Image<TPixel> Image { get; }
/// <summary>
/// Gets the opacity of the image to blend
/// </summary>
public float Opacity { get; }
/// <summary>
/// Gets the pixel blender
/// </summary>
public PixelBlender<TPixel> Blender { get; }
/// <summary>
/// Gets the location to draw the blended image
/// </summary>
public Point Location { get; }
/// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{
Image<TPixel> targetImage = this.Image;
PixelBlender<TPixel> blender = this.Blender;
int locationY = this.Location.Y;
// Align start/end positions.
Rectangle bounds = targetImage.Bounds();
int minX = Math.Max(this.Location.X, sourceRectangle.X);
int maxX = Math.Min(this.Location.X + bounds.Width, sourceRectangle.Width);
int targetX = minX - this.Location.X;
int minY = Math.Max(this.Location.Y, sourceRectangle.Y);
int maxY = Math.Min(this.Location.Y + bounds.Height, sourceRectangle.Bottom);
int width = maxX - minX;
MemoryManager memoryManager = this.Image.GetConfiguration().MemoryManager;
using (IBuffer<float> amount = memoryManager.Allocate<float>(width))
{
amount.Span.Fill(this.Opacity);
Parallel.For(
minY,
maxY,
configuration.ParallelOptions,
y =>
{
Span<TPixel> background = source.GetPixelRowSpan(y).Slice(minX, width);
Span<TPixel> foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width);
blender.Blend(memoryManager, background, background, foreground, amount.Span);
});
}
}
}
}

14
src/ImageSharp.Drawing/Processors/FillProcessor.cs → src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs

@ -2,21 +2,17 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Brushes.Processors;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Drawing.Processors
namespace SixLabors.ImageSharp.Processing.Drawing.Processors
{
/// <summary>
/// Using the bursh as a source of pixels colors blends the brush color with source.
/// Using the brush as a source of pixels colors blends the brush color with source.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class FillProcessor<TPixel> : ImageProcessor<TPixel>
@ -40,7 +36,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors
}
/// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;

17
src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs → src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs

@ -2,24 +2,21 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Buffers;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Brushes.Processors;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Drawing.Processors
namespace SixLabors.ImageSharp.Processing.Drawing.Processors
{
/// <summary>
/// Usinf a brsuh and a shape fills shape with contents of brush the
/// Using a brush and a shape fills shape with contents of brush the
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <seealso cref="ImageSharp.Processing.ImageProcessor{TPixel}" />
/// <seealso cref="ImageProcessor{TPixel}" />
internal class FillRegionProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
@ -58,7 +55,7 @@ namespace SixLabors.ImageSharp.Drawing.Processors
public GraphicsOptions Options { get; }
/// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{
Region region = this.Region;
Rectangle rect = region.Bounds;

57
src/ImageSharp.Drawing/Text/DrawText.Path.cs → src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.Path.cs

@ -1,20 +1,19 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.Fonts;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.ImageSharp.Processing.Drawing.Pens;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Text
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of text along given paths to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static partial class DrawTextExtensions
{
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -29,10 +28,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, TPixel color, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, color, path, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, color, path, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -48,10 +45,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, Brushes.Solid(color), null, path, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, Brushes.Solid(color), null, path, options);
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -66,10 +61,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, path, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, brush, path, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -85,10 +78,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPath path, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, null, path, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, brush, null, path, options);
/// <summary>
/// Draws the text onto the the image outlined via the pen.
@ -103,10 +94,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IPen<TPixel> pen, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, pen, path, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, pen, path, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image outlined via the pen.
@ -122,10 +111,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IPen<TPixel> pen, IPath path, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, null, pen, path, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, null, pen, path, options);
/// <summary>
/// Draws the text onto the the image filled via the brush then outlined via the pen.
@ -141,10 +128,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPen<TPixel> pen, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, pen, path, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, brush, pen, path, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image filled via the brush then outlined via the pen.
@ -191,4 +176,4 @@ namespace SixLabors.ImageSharp
return source;
}
}
}
}

59
src/ImageSharp.Drawing/Text/DrawText.cs → src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs

@ -1,21 +1,20 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.Fonts;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Drawing;
using SixLabors.ImageSharp.Processing.Drawing.Brushes;
using SixLabors.ImageSharp.Processing.Drawing.Pens;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Text
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of text to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static partial class DrawTextExtensions
{
private static readonly int DefaultTextDpi = 72;
@ -32,10 +31,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, TPixel color, PointF location)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, color, location, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, color, location, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -51,10 +48,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, Brushes.Solid(color), null, location, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, Brushes.Solid(color), null, location, options);
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -69,10 +64,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, PointF location)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, location, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, brush, location, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -88,10 +81,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, PointF location, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, null, location, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, brush, null, location, options);
/// <summary>
/// Draws the text onto the the image outlined via the pen.
@ -106,10 +97,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IPen<TPixel> pen, PointF location)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, pen, location, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, pen, location, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image outlined via the pen.
@ -125,10 +114,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IPen<TPixel> pen, PointF location, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, null, pen, location, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, null, pen, location, options);
/// <summary>
/// Draws the text onto the the image filled via the brush then outlined via the pen.
@ -144,13 +131,11 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPen<TPixel> pen, PointF location)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image filled via the brush then outlined via the pen.
/// Draws the text using the default resolution of <value>72dpi</value> onto the the image filled via the brush then outlined via the pen.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -194,4 +179,4 @@ namespace SixLabors.ImageSharp
return source;
}
}
}
}

7
src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs → src/ImageSharp.Drawing/Processing/Text/TextGraphicsOptions.cs

@ -1,9 +1,10 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.Fonts;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Drawing
namespace SixLabors.ImageSharp.Processing.Text
{
/// <summary>
/// Options for influencing the drawing functions.
@ -29,8 +30,8 @@ namespace SixLabors.ImageSharp.Drawing
private float wrapTextWidth;
private SixLabors.Fonts.HorizontalAlignment? horizontalAlignment;
private SixLabors.Fonts.VerticalAlignment? verticalAlignment;
private HorizontalAlignment? horizontalAlignment;
private VerticalAlignment? verticalAlignment;
/// <summary>
/// Initializes a new instance of the <see cref="TextGraphicsOptions" /> struct.

96
src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs

@ -1,96 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Drawing.Processors
{
/// <summary>
/// Combines two images together by blending the pixels.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
internal class DrawImageProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="options">The opacity of the image to blend. Between 0 and 1.</param>
public DrawImageProcessor(Image<TPixel> image, Point location, GraphicsOptions options)
{
Guard.MustBeBetweenOrEqualTo(options.BlendPercentage, 0, 1, nameof(options.BlendPercentage));
this.Image = image;
this.Opacity = options.BlendPercentage;
this.Blender = PixelOperations<TPixel>.Instance.GetPixelBlender(options.BlenderMode);
this.Location = location;
}
/// <summary>
/// Gets the image to blend
/// </summary>
public Image<TPixel> Image { get; }
/// <summary>
/// Gets the opacity of the image to blend
/// </summary>
public float Opacity { get; }
/// <summary>
/// Gets the pixel blender
/// </summary>
public PixelBlender<TPixel> Blender { get; }
/// <summary>
/// Gets the location to draw the blended image
/// </summary>
public Point Location { get; }
/// <inheritdoc/>
protected override void OnApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
{
Image<TPixel> targetImage = this.Image;
PixelBlender<TPixel> blender = this.Blender;
int locationY = this.Location.Y;
// Align start/end positions.
Rectangle bounds = targetImage.Bounds();
int minX = Math.Max(this.Location.X, sourceRectangle.X);
int maxX = Math.Min(this.Location.X + bounds.Width, sourceRectangle.Width);
int targetX = minX - this.Location.X;
int minY = Math.Max(this.Location.Y, sourceRectangle.Y);
int maxY = Math.Min(this.Location.Y + bounds.Height, sourceRectangle.Bottom);
int width = maxX - minX;
MemoryManager memoryManager = this.Image.GetConfiguration().MemoryManager;
using (IBuffer<float> amount = memoryManager.Allocate<float>(width))
{
amount.Span.Fill(this.Opacity);
Parallel.For(
minY,
maxY,
configuration.ParallelOptions,
y =>
{
Span<TPixel> background = source.GetPixelRowSpan(y).Slice(minX, width);
Span<TPixel> foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width);
blender.Blend(memoryManager, background, background, foreground, amount.Span);
});
}
}
}
}

2
src/ImageSharp/Advanced/AdvancedImageExtensions.cs

@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Advanced
/// <summary>
/// Returns a reference to the 0th element of the Pixel buffer,
/// allowing direct manipulation of pixel data through unsafe operations.
/// The pixel buffer is a contigous memory area containing Width*Height TPixel elements layed out in row-major order.
/// The pixel buffer is a contiguous memory area containing Width*Height TPixel elements laid out in row-major order.
/// </summary>
/// <typeparam name="TPixel">The Pixel format.</typeparam>
/// <param name="source">The source image frame</param>

3
src/ImageSharp/Advanced/IPixelSource.cs

@ -1,10 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.MetaData;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Advanced

2
src/ImageSharp/ColorSpaces/Hsv.cs

@ -6,6 +6,8 @@ using System.ComponentModel;
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.ColorSpaces
{
/// <summary>

2
src/ImageSharp/ColorSpaces/Rgb.cs

@ -6,6 +6,8 @@ using System.ComponentModel;
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.ColorSpaces
{
/// <summary>

2
src/ImageSharp/Common/Extensions/Vector4Extensions.cs

@ -5,6 +5,8 @@ using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
{
/// <summary>

5
src/ImageSharp/Configuration.cs

@ -2,17 +2,18 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Png;
#if !NETSTANDARD1_1
using SixLabors.ImageSharp.IO;
#endif
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Processing;
namespace SixLabors.ImageSharp
{

5
src/ImageSharp/Formats/Gif/GifEncoder.cs

@ -1,14 +1,11 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization;
namespace SixLabors.ImageSharp.Formats.Gif
{

13
src/ImageSharp/Formats/Gif/GifEncoderCore.cs

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Buffers;
using System.IO;
using System.Linq;
using System.Text;
@ -10,7 +9,7 @@ using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.MetaData;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization;
namespace SixLabors.ImageSharp.Formats.Gif
{
@ -106,7 +105,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
var pixelQuantizer = (IQuantizer<TPixel>)this.quantizer;
// Quantize the image returning a palette.
QuantizedImage<TPixel> quantized = pixelQuantizer.Quantize(image.Frames.RootFrame, size);
QuantizedFrame<TPixel> quantized = pixelQuantizer.Quantize(image.Frames.RootFrame, size);
int index = this.GetTransparentIndex(quantized);
@ -154,7 +153,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <returns>
/// The <see cref="int"/>.
/// </returns>
private int GetTransparentIndex<TPixel>(QuantizedImage<TPixel> quantized)
private int GetTransparentIndex<TPixel>(QuantizedFrame<TPixel> quantized)
where TPixel : struct, IPixel<TPixel>
{
// Transparent pixels are much more likely to be found at the end of a palette
@ -347,7 +346,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="ImageFrame{TPixel}"/> to encode.</param>
/// <param name="writer">The writer to write to the stream with.</param>
private void WriteColorTable<TPixel>(QuantizedImage<TPixel> image, EndianBinaryWriter writer)
private void WriteColorTable<TPixel>(QuantizedFrame<TPixel> image, EndianBinaryWriter writer)
where TPixel : struct, IPixel<TPixel>
{
// Grab the palette and write it to the stream.
@ -377,9 +376,9 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// Writes the image pixel data to the stream.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="image">The <see cref="QuantizedImage{TPixel}"/> containing indexed pixels.</param>
/// <param name="image">The <see cref="QuantizedFrame{TPixel}"/> containing indexed pixels.</param>
/// <param name="writer">The stream to write to.</param>
private void WriteImageData<TPixel>(QuantizedImage<TPixel> image, EndianBinaryWriter writer)
private void WriteImageData<TPixel>(QuantizedFrame<TPixel> image, EndianBinaryWriter writer)
where TPixel : struct, IPixel<TPixel>
{
using (var encoder = new LzwEncoder(this.memoryManager, image.Pixels, (byte)this.bitDepth))

10
src/ImageSharp/Formats/Gif/IGifEncoderOptions.cs

@ -1,12 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization;
namespace SixLabors.ImageSharp.Formats.Gif
{
@ -38,6 +34,6 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// <summary>
/// Gets the quantizer for reducing the color count.
/// </summary>
IQuantizer Quantizer { get; }
IQuantizer Quantizer { get; }
}
}
}

6
src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.FromGrayScale.cs

@ -8,10 +8,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters
{
internal abstract partial class JpegColorConverter
{
internal class FromGrayScale : ColorConverters.JpegColorConverter
internal class FromGrayscale : ColorConverters.JpegColorConverter
{
public FromGrayScale()
: base(JpegColorSpace.GrayScale)
public FromGrayscale()
: base(JpegColorSpace.Grayscale)
{
}

2
src/ImageSharp/Formats/Jpeg/Common/Decoder/ColorConverters/JpegColorConverter.cs

@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder.ColorConverters
/// </summary>
private static readonly JpegColorConverter[] Converters =
{
GetYCbCrConverter(), new FromYccK(), new FromCmyk(), new FromGrayScale(), new FromRgb()
GetYCbCrConverter(), new FromYccK(), new FromCmyk(), new FromGrayscale(), new FromRgb()
};
/// <summary>

2
src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegColorSpace.cs

@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder
{
Undefined = 0,
GrayScale,
Grayscale,
Ycck,

3
src/ImageSharp/Formats/Jpeg/Common/Decoder/JpegImagePostProcessor.cs

@ -2,7 +2,6 @@ using System;
using System.Linq;
using System.Numerics;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
@ -116,7 +115,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder
}
/// <summary>
/// Execute one step rocessing <see cref="PixelRowsPerStep"/> pixel rows into 'destination'.
/// Execute one step processing <see cref="PixelRowsPerStep"/> pixel rows into 'destination'.
/// </summary>
/// <typeparam name="TPixel">The pixel type</typeparam>
/// <param name="destination">The destination image.</param>

6
src/ImageSharp/Formats/Jpeg/GolangPort/OrigJpegDecoderCore.cs

@ -640,7 +640,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
switch (remaining)
{
case 6 + (3 * 1): // Grayscale image.
case 6 + (3 * 1): // grayscale image.
this.ComponentCount = 1;
break;
case 6 + (3 * 3): // YCbCr or RGB image.
@ -767,7 +767,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
switch (this.ComponentCount)
{
case 1:
return JpegColorSpace.GrayScale;
return JpegColorSpace.Grayscale;
case 3:
if (!this.isAdobe || this.adobe.ColorTransform == OrigJpegConstants.Adobe.ColorTransformYCbCr)
{
@ -790,7 +790,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.GolangPort
}
throw new ImageFormatException($"Unsupported color mode. Max components 4; found {this.ComponentCount}."
+ "JpegDecoder only supports YCbCr, RGB, YccK, CMYK and Grayscale color spaces.");
+ "JpegDecoder only supports YCbCr, RGB, YccK, CMYK and grayscale color spaces.");
}
private Image<TPixel> PostProcessIntoImage<TPixel>()

1
src/ImageSharp/Formats/Jpeg/JpegEncoder.cs

@ -20,6 +20,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// <summary>
/// Gets or sets the quality, that will be used to encode the image. Quality
/// index must be between 0 and 100 (compression from max to min).
/// Defaults to <value>75</value>.
/// </summary>
public int Quality { get; set; } = 75;

7
src/ImageSharp/Formats/Png/IPngEncoderOptions.cs

@ -1,15 +1,12 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Collections.Generic;
using System.IO;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization;
namespace SixLabors.ImageSharp.Formats.Png
{
/// <summary>
/// The options availible for manipulating the encoder pipeline
/// The options available for manipulating the encoder pipeline
/// </summary>
internal interface IPngEncoderOptions
{

4
src/ImageSharp/Formats/Png/PngDecoder.cs

@ -20,8 +20,8 @@ namespace SixLabors.ImageSharp.Formats.Png
/// <list type="bullet">
/// <item>RGBA (True color) with alpha (8 bit).</item>
/// <item>RGB (True color) without alpha (8 bit).</item>
/// <item>Grayscale with alpha (8 bit).</item>
/// <item>Grayscale without alpha (8 bit).</item>
/// <item>grayscale with alpha (8 bit).</item>
/// <item>grayscale without alpha (8 bit).</item>
/// <item>Palette Index with alpha (8 bit).</item>
/// <item>Palette Index without alpha (8 bit).</item>
/// </list>

2
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp.Formats.Png
private Rgb24 rgb24Trans;
/// <summary>
/// Represents any color in a Grayscale encoded png that should be transparent
/// Represents any color in a grayscale encoded png that should be transparent
/// </summary>
private byte intensityTrans;

3
src/ImageSharp/Formats/Png/PngEncoder.cs

@ -3,9 +3,8 @@
using System.IO;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization;
namespace SixLabors.ImageSharp.Formats.Png
{

11
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Buffers;
using System.IO;
using System.Linq;
using SixLabors.ImageSharp.Advanced;
@ -10,7 +9,7 @@ using SixLabors.ImageSharp.Formats.Png.Filters;
using SixLabors.ImageSharp.Formats.Png.Zlib;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Quantizers;
using SixLabors.ImageSharp.Processing.Quantization;
namespace SixLabors.ImageSharp.Formats.Png
{
@ -308,7 +307,7 @@ namespace SixLabors.ImageSharp.Formats.Png
where TPixel : struct, IPixel<TPixel>
{
// Quantize the image and get the pixels.
QuantizedImage<TPixel> quantized = this.WritePaletteChunk(stream, header, image);
QuantizedFrame<TPixel> quantized = this.WritePaletteChunk(stream, header, image);
this.palettePixelData = quantized.Pixels;
}
@ -498,8 +497,8 @@ namespace SixLabors.ImageSharp.Formats.Png
/// <param name="stream">The <see cref="Stream"/> containing image data.</param>
/// <param name="header">The <see cref="PngHeader"/>.</param>
/// <param name="image">The image to encode.</param>
/// <returns>The <see cref="QuantizedImage{TPixel}"/></returns>
private QuantizedImage<TPixel> WritePaletteChunk<TPixel>(Stream stream, PngHeader header, ImageFrame<TPixel> image)
/// <returns>The <see cref="QuantizedFrame{TPixel}"/></returns>
private QuantizedFrame<TPixel> WritePaletteChunk<TPixel>(Stream stream, PngHeader header, ImageFrame<TPixel> image)
where TPixel : struct, IPixel<TPixel>
{
if (this.paletteSize > 256)
@ -513,7 +512,7 @@ namespace SixLabors.ImageSharp.Formats.Png
}
// Quantize the image returning a palette. This boxing is icky.
QuantizedImage<TPixel> quantized = ((IQuantizer<TPixel>)this.quantizer).Quantize(image, this.paletteSize);
QuantizedFrame<TPixel> quantized = ((IQuantizer<TPixel>)this.quantizer).Quantize(image, this.paletteSize);
// Grab the palette and write it to the stream.
TPixel[] palette = quantized.Palette;

61
src/ImageSharp/Helpers/ImageExtensions.cs

@ -1,61 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Helpers
{
/// <summary>
/// Extension methods over Image{TPixel}
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Gets the bounds of the image.
/// </summary>
/// <typeparam name="TPixel">The Pixel format.</typeparam>
/// <param name="source">The source image</param>
/// <returns>Returns the bounds of the image</returns>
public static Rectangle Bounds<TPixel>(this Image<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> new Rectangle(0, 0, source.Width, source.Height);
/// <summary>
/// Gets the bounds of the image.
/// </summary>
/// <typeparam name="TPixel">The Pixel format.</typeparam>
/// <param name="source">The source image</param>
/// <returns>Returns the bounds of the image</returns>
public static Rectangle Bounds<TPixel>(this ImageFrame<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> new Rectangle(0, 0, source.Width, source.Height);
/// <summary>
/// Gets the size of the image.
/// </summary>
/// <typeparam name="TPixel">The Pixel format.</typeparam>
/// <param name="source">The source image</param>
/// <returns>Returns the bounds of the image</returns>
public static Size Size<TPixel>(this Image<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> new Size(source.Width, source.Height);
/// <summary>
/// Gets the size of the image.
/// </summary>
/// <typeparam name="TPixel">The Pixel format.</typeparam>
/// <param name="source">The source image</param>
/// <returns>Returns the bounds of the image</returns>
public static Size Size<TPixel>(this ImageFrame<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> new Size(source.Width, source.Height);
}
}

0
src/ImageSharp/Image/IImage.cs → src/ImageSharp/IImage.cs

0
src/ImageSharp/Image/IImageFrameCollection.cs → src/ImageSharp/IImageFrameCollection.cs

0
src/ImageSharp/Image/IImageInfo.cs → src/ImageSharp/IImageInfo.cs

0
src/ImageSharp/Image/Image.Decode.cs → src/ImageSharp/Image.Decode.cs

0
src/ImageSharp/Image/Image.FromBytes.cs → src/ImageSharp/Image.FromBytes.cs

0
src/ImageSharp/Image/Image.FromFile.cs → src/ImageSharp/Image.FromFile.cs

0
src/ImageSharp/Image/Image.FromStream.cs → src/ImageSharp/Image.FromStream.cs

0
src/ImageSharp/Image/Image.LoadPixelData.cs → src/ImageSharp/Image.LoadPixelData.cs

0
src/ImageSharp/Image/ImageExtensions.cs → src/ImageSharp/ImageExtensions.cs

0
src/ImageSharp/Image/ImageFrame.LoadPixelData.cs → src/ImageSharp/ImageFrame.LoadPixelData.cs

7
src/ImageSharp/Image/ImageFrameCollection.cs → src/ImageSharp/ImageFrameCollection.cs

@ -10,7 +10,7 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
{
/// <summary>
/// Encapsulates an imaged collection of frames.
/// Encapsulates a collection of frames that make up an image.
/// </summary>
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
internal sealed class ImageFrameCollection<TPixel> : IImageFrameCollection<TPixel>
@ -51,10 +51,7 @@ namespace SixLabors.ImageSharp
public ImageFrame<TPixel> RootFrame => this.frames.Count > 0 ? this.frames[0] : null;
/// <inheritdoc/>
public ImageFrame<TPixel> this[int index]
{
get => this.frames[index];
}
public ImageFrame<TPixel> this[int index] => this.frames[index];
/// <inheritdoc/>
public int IndexOf(ImageFrame<TPixel> frame) => this.frames.IndexOf(frame);

18
src/ImageSharp/Image/ImageFrame{TPixel}.cs → src/ImageSharp/ImageFrame{TPixel}.cs

@ -2,12 +2,10 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Diagnostics;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Helpers;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.MetaData;
using SixLabors.ImageSharp.PixelFormats;
@ -104,7 +102,7 @@ namespace SixLabors.ImageSharp
/// <summary>
/// Gets the meta data of the frame.
/// </summary>
public ImageFrameMetaData MetaData { get; private set; }
public ImageFrameMetaData MetaData { get; }
/// <summary>
/// Gets or sets the pixel at the specified position.
@ -127,6 +125,18 @@ namespace SixLabors.ImageSharp
}
}
/// <summary>
/// Gets the size of the frame.
/// </summary>
/// <returns>The <see cref="Size"/></returns>
public Size Size() => new Size(this.Width, this.Height);
/// <summary>
/// Gets the bounds of the frame.
/// </summary>
/// <returns>The <see cref="Rectangle"/></returns>
public Rectangle Bounds() => new Rectangle(0, 0, this.Width, this.Height);
/// <summary>
/// Gets a reference to the pixel at the specified position.
/// </summary>
@ -168,7 +178,7 @@ namespace SixLabors.ImageSharp
{
if (this.Size() != target.Size())
{
throw new ArgumentException("ImageFrame<T>.CopyTo(): target must be of the same size!", nameof(target));
throw new ArgumentException("ImageFrame<TPixel>.CopyTo(): target must be of the same size!", nameof(target));
}
SpanHelper.Copy(this.GetPixelSpan(), target.Span);

0
src/ImageSharp/Image/ImageInfo.cs → src/ImageSharp/ImageInfo.cs

27
src/ImageSharp/ImageInfoExtensions.cs

@ -0,0 +1,27 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
{
/// <summary>
/// Extension methods that allow the addition of geometry calculating methods to the <see cref="IImageInfo"/> type
/// </summary>
public static class ImageInfoExtensions
{
/// <summary>
/// Gets the bounds of the image.
/// </summary>
/// <param name="info">The image info</param>
/// <returns>The <see cref="Size"/></returns>
public static Size Size(this IImageInfo info) => new Size(info.Width, info.Height);
/// <summary>
/// Gets the bounds of the image.
/// </summary>
/// <param name="info">The image info</param>
/// <returns>The <see cref="Rectangle"/></returns>
public static Rectangle Bounds(this IImageInfo info) => new Rectangle(0, 0, info.Width, info.Height);
}
}

5
src/ImageSharp/ImageSharp.csproj

@ -37,7 +37,7 @@
<ItemGroup>
<PackageReference Include="SixLabors.Core" Version="1.0.0-ci0005" />
<AdditionalFiles Include="..\..\stylecop.json" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004">
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta006">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="System.Buffers" Version="4.4.0" />
@ -126,7 +126,4 @@
<DependentUpon>PorterDuffFunctions.Generated.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="Formats\Jpeg\GolangPort\Utils\" />
</ItemGroup>
</Project>

10
src/ImageSharp/Image/Image{TPixel}.cs → src/ImageSharp/Image{TPixel}.cs

@ -17,11 +17,11 @@ namespace SixLabors.ImageSharp
/// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
public sealed partial class Image<TPixel> : IImage, IConfigurable
public sealed class Image<TPixel> : IImage, IConfigurable
where TPixel : struct, IPixel<TPixel>
{
private Configuration configuration;
private ImageFrameCollection<TPixel> frames;
private readonly Configuration configuration;
private readonly ImageFrameCollection<TPixel> frames;
/// <summary>
/// Initializes a new instance of the <see cref="Image{TPixel}"/> class
@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp
/// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param>
public Image(int width, int height)
: this(null, width, height)
: this(Configuration.Default, width, height)
{
}
@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp
public int Height => this.frames.RootFrame.Height;
/// <inheritdoc/>
public ImageMetaData MetaData { get; private set; } = new ImageMetaData();
public ImageMetaData MetaData { get; }
/// <summary>
/// Gets the frames.

4
src/ImageSharp/Memory/ArrayPoolMemoryManager.CommonFactoryMethods.cs

@ -1,4 +1,6 @@
namespace SixLabors.ImageSharp.Memory
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Memory
{
/// <summary>
/// Contains common factory methods and configuration constants.

173
src/ImageSharp/Memory/Fast2DArray{T}.cs

@ -1,173 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Memory
{
/// <summary>
/// Provides fast access to 2D arrays.
/// </summary>
/// <typeparam name="T">The type of elements in the array.</typeparam>
internal struct Fast2DArray<T>
{
/// <summary>
/// The 1D representation of the 2D array.
/// </summary>
public T[] Data;
/// <summary>
/// Gets the width of the 2D array.
/// </summary>
public int Width;
/// <summary>
/// Gets the height of the 2D array.
/// </summary>
public int Height;
/// <summary>
/// Gets the number of items in the 2D array
/// </summary>
public int Count;
/// <summary>
/// Initializes a new instance of the <see cref="Fast2DArray{T}" /> struct.
/// </summary>
/// <param name="length">The length of each dimension.</param>
public Fast2DArray(int length)
: this(length, length)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Fast2DArray{T}" /> struct.
/// </summary>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
public Fast2DArray(int width, int height)
{
this.Height = height;
this.Width = width;
Guard.MustBeGreaterThan(width, 0, nameof(width));
Guard.MustBeGreaterThan(height, 0, nameof(height));
this.Count = width * height;
this.Data = new T[this.Count];
}
/// <summary>
/// Initializes a new instance of the <see cref="Fast2DArray{T}"/> struct.
/// </summary>
/// <param name="data">The 2D array to provide access to.</param>
public Fast2DArray(T[,] data)
{
Guard.NotNull(data, nameof(data));
this.Height = data.GetLength(0);
this.Width = data.GetLength(1);
Guard.MustBeGreaterThan(this.Width, 0, nameof(this.Width));
Guard.MustBeGreaterThan(this.Height, 0, nameof(this.Height));
this.Count = this.Width * this.Height;
this.Data = new T[this.Count];
for (int y = 0; y < this.Height; y++)
{
for (int x = 0; x < this.Width; x++)
{
this.Data[(y * this.Width) + x] = data[y, x];
}
}
}
/// <summary>
/// Gets or sets the item at the specified position.
/// </summary>
/// <param name="row">The row-coordinate of the item. Must be greater than or equal to zero and less than the height of the array.</param>
/// <param name="column">The column-coordinate of the item. Must be greater than or equal to zero and less than the width of the array.</param>
/// <returns>The <see typeparam="T"/> at the specified position.</returns>
public T this[int row, int column]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
this.CheckCoordinates(row, column);
return this.Data[(row * this.Width) + column];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
this.CheckCoordinates(row, column);
this.Data[(row * this.Width) + column] = value;
}
}
/// <summary>
/// Performs an implicit conversion from a 2D array to a <see cref="Fast2DArray{T}" />.
/// </summary>
/// <param name="data">The source array.</param>
/// <returns>
/// The <see cref="Fast2DArray{T}"/> representation on the source data.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Fast2DArray<T>(T[,] data)
{
return new Fast2DArray<T>(data);
}
/// <summary>
/// Gets a <see cref="Span{T}"/> representing the row beginning from the the first item on that row.
/// </summary>
/// <param name="row">The y-coordinate of the row. Must be greater than or equal to zero and less than the height of the 2D array.</param>
/// <returns>The <see cref="Span{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<T> GetRowSpan(int row)
{
this.CheckCoordinates(row);
return new Span<T>(this.Data, row * this.Width, this.Width);
}
/// <summary>
/// Checks the coordinates to ensure they are within bounds.
/// </summary>
/// <param name="row">The y-coordinate of the item. Must be greater than zero and smaller than the height of the array.</param>
/// <param name="column">The x-coordinate of the item. Must be greater than zero and smaller than the width of the array.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown if the coordinates are not within the bounds of the array.
/// </exception>
[Conditional("DEBUG")]
private void CheckCoordinates(int row, int column)
{
if (row < 0 || row >= this.Height)
{
throw new ArgumentOutOfRangeException(nameof(row), row, $"{row} is outwith the array bounds.");
}
if (column < 0 || column >= this.Width)
{
throw new ArgumentOutOfRangeException(nameof(column), column, $"{column} is outwith the array bounds.");
}
}
/// <summary>
/// Checks the coordinates to ensure they are within bounds.
/// </summary>
/// <param name="row">The y-coordinate of the item. Must be greater than zero and smaller than the height of the array.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown if the coordinates are not within the bounds of the image.
/// </exception>
[Conditional("DEBUG")]
private void CheckCoordinates(int row)
{
if (row < 0 || row >= this.Height)
{
throw new ArgumentOutOfRangeException(nameof(row), row, $"{row} is outwith the array bounds.");
}
}
}
}

2
src/ImageSharp/MetaData/ImageMetaData.cs

@ -2,8 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System.Collections.Generic;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.MetaData.Profiles.Exif;
using SixLabors.ImageSharp.MetaData.Profiles.Icc;

8
src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Matrix.cs

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
{
@ -59,12 +59,12 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <param name="value">The matrix to write</param>
/// <param name="isSingle">True if the values are encoded as Single; false if encoded as Fix16</param>
/// <returns>The number of bytes written</returns>
public int WriteMatrix(Fast2DArray<float> value, bool isSingle)
public int WriteMatrix(DenseMatrix<float> value, bool isSingle)
{
int count = 0;
for (int y = 0; y < value.Height; y++)
for (int y = 0; y < value.Rows; y++)
{
for (int x = 0; x < value.Width; x++)
for (int x = 0; x < value.Columns; x++)
{
if (isSingle)
{

18
src/ImageSharp/MetaData/Profiles/ICC/MultiProcessElements/IccMatrixProcessElement.cs

@ -3,7 +3,8 @@
using System;
using System.Linq;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
{
@ -33,7 +34,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary>
/// Gets the two dimensional matrix with size of Input-Channels x Output-Channels
/// </summary>
public Fast2DArray<float> MatrixIxO { get; }
public DenseMatrix<float> MatrixIxO { get; }
/// <summary>
/// Gets the one dimensional matrix with size of Output-Channels x 1
@ -60,18 +61,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
private bool EqualsMatrix(IccMatrixProcessElement element)
{
for (int x = 0; x < this.MatrixIxO.Width; x++)
{
for (int y = 0; y < this.MatrixIxO.Height; y++)
{
if (this.MatrixIxO[x, y] != element.MatrixIxO[x, y])
{
return false;
}
}
}
return true;
return this.MatrixIxO.Equals(element.MatrixIxO);
}
}
}

0
src/ImageSharp/Image/PixelAccessorExtensions.cs → src/ImageSharp/PixelAccessorExtensions.cs

0
src/ImageSharp/Image/PixelAccessor{TPixel}.cs → src/ImageSharp/PixelAccessor{TPixel}.cs

5
src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.cs

@ -2,19 +2,18 @@
// Licensed under the Apache License, Version 2.0.
// <auto-generated />
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.PixelFormats
{
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats;
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>
public partial struct Rgba32
{
internal partial class PixelOperations : PixelOperations<Rgba32>
internal partial class PixelOperations
{
/// <inheritdoc />

5
src/ImageSharp/PixelFormats/Generated/Rgba32.PixelOperations.Generated.tt

@ -57,19 +57,18 @@
// Licensed under the Apache License, Version 2.0.
// <auto-generated />
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.PixelFormats
{
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats;
/// <content>
/// Provides optimized overrides for bulk operations.
/// </content>
public partial struct Rgba32
{
internal partial class PixelOperations : PixelOperations<Rgba32>
internal partial class PixelOperations
{
<#
GeneratePackFromMethod("Rgb24", "Unsafe.As<Rgba32, Rgb24>(ref dp) = sp; dp.A = 255;");

6
src/ImageSharp/PixelFormats/PixelBlenderMode.cs

@ -1,14 +1,10 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.Text;
namespace SixLabors.ImageSharp.PixelFormats
{
/// <summary>
/// The various blending modes.
/// Enumerates the various blending modes.
/// </summary>
public enum PixelBlenderMode
{

6
src/ImageSharp/PixelFormats/Rgba32.Definitions.cs

@ -1,12 +1,10 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.PixelFormats
{
/// <content>
/// Provides standardized deifinitions for named colors.
/// Provides standardized definitions for named colors.
/// </content>
public partial struct Rgba32
{

3
src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs

@ -6,9 +6,8 @@ using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.PixelFormats
{
/// <content>
/// Provides optimized overrides for bulk operations.

4
src/ImageSharp/PixelFormats/Rgba32.cs

@ -1,13 +1,11 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.PixelFormats
{
/// <summary>
/// Packed pixel type containing four 8-bit unsigned normalized values ranging from 0 to 255.

215
src/ImageSharp/Primitives/DenseMatrix{T}.cs

@ -0,0 +1,215 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Primitives
{
/// <summary>
/// Represents a dense matrix with arbitrary elements.
/// Components that are adjacent in a column of the matrix are adjacent in the storage array.
/// The components are said to be stored in column major order.
/// </summary>
/// <typeparam name="T">The type of elements in the matrix.</typeparam>
public readonly struct DenseMatrix<T> : IEquatable<DenseMatrix<T>>
where T : struct, IEquatable<T>
{
/// <summary>
/// The 1D representation of the dense matrix.
/// </summary>
public readonly T[] Data;
/// <summary>
/// Gets the number of columns in the dense matrix.
/// </summary>
public readonly int Columns;
/// <summary>
/// Gets the number of rows in the dense matrix.
/// </summary>
public readonly int Rows;
/// <summary>
/// Gets the number of items in the array.
/// </summary>
public readonly int Count;
/// <summary>
/// Initializes a new instance of the <see cref=" DenseMatrix{T}" /> struct.
/// </summary>
/// <param name="length">The length of each side in the matrix.</param>
public DenseMatrix(int length)
: this(length, length)
{
}
/// <summary>
/// Initializes a new instance of the <see cref=" DenseMatrix{T}" /> struct.
/// </summary>
/// <param name="columns">The number of columns.</param>
/// <param name="rows">The number of rows.</param>
public DenseMatrix(int columns, int rows)
{
Guard.MustBeGreaterThan(columns, 0, nameof(columns));
Guard.MustBeGreaterThan(rows, 0, nameof(rows));
this.Rows = rows;
this.Columns = columns;
this.Count = columns * rows;
this.Data = new T[this.Columns * this.Rows];
}
/// <summary>
/// Initializes a new instance of the <see cref=" DenseMatrix{T}"/> struct.
/// </summary>
/// <param name="data">The 2D array to provide access to.</param>
public DenseMatrix(T[,] data)
{
Guard.NotNull(data, nameof(data));
int rows = data.GetLength(0);
int columns = data.GetLength(1);
Guard.MustBeGreaterThan(rows, 0, nameof(this.Rows));
Guard.MustBeGreaterThan(columns, 0, nameof(this.Columns));
this.Rows = rows;
this.Columns = columns;
this.Count = this.Columns * this.Rows;
this.Data = new T[this.Columns * this.Rows];
for (int y = 0; y < this.Rows; y++)
{
for (int x = 0; x < this.Columns; x++)
{
ref T value = ref this[y, x];
value = data[y, x];
}
}
}
/// <summary>
/// Gets or sets the item at the specified position.
/// </summary>
/// <param name="row">The row-coordinate of the item. Must be greater than or equal to zero and less than the height of the array.</param>
/// <param name="column">The column-coordinate of the item. Must be greater than or equal to zero and less than the width of the array.</param>
/// <returns>The <see typeparam="T"/> at the specified position.</returns>
public ref T this[int row, int column]
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
this.CheckCoordinates(row, column);
return ref this.Data[(row * this.Columns) + column];
}
}
/// <summary>
/// Performs an implicit conversion from a <see cref="T:T[,]" /> to a <see cref=" DenseMatrix{T}" />.
/// </summary>
/// <param name="data">The source array.</param>
/// <returns>
/// The <see cref="DenseMatrix{T}"/> representation on the source data.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator DenseMatrix<T>(T[,] data) => new DenseMatrix<T>(data);
/// <summary>
/// Performs an implicit conversion from a <see cref="DenseMatrix{T}"/> to a <see cref="T:T[,]" />.
/// </summary>
/// <param name="data">The source array.</param>
/// <returns>
/// The <see cref="T:T[,]"/> representation on the source data.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#pragma warning disable SA1008 // Opening parenthesis should be spaced correctly
public static implicit operator T[,] (DenseMatrix<T> data)
#pragma warning restore SA1008 // Opening parenthesis should be spaced correctly
{
var result = new T[data.Rows, data.Columns];
for (int y = 0; y < data.Rows; y++)
{
for (int x = 0; x < data.Columns; x++)
{
ref T value = ref result[y, x];
value = data[y, x];
}
}
return result;
}
/// <summary>
/// Fills the matrix with the given value
/// </summary>
/// <param name="value">The value to fill each item with</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Fill(T value)
{
for (int i = 0; i < this.Data.Length; i++)
{
this.Data[i] = value;
}
}
/// <summary>
/// Clears the matrix setting each value to the default value for the element type
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Clear() => Array.Clear(this.Data, 0, this.Data.Length);
/// <summary>
/// Checks the coordinates to ensure they are within bounds.
/// </summary>
/// <param name="row">The y-coordinate of the item. Must be greater than zero and smaller than the height of the matrix.</param>
/// <param name="column">The x-coordinate of the item. Must be greater than zero and smaller than the width of the matrix.</param>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown if the coordinates are not within the bounds of the array.
/// </exception>
[Conditional("DEBUG")]
private void CheckCoordinates(int row, int column)
{
if (row < 0 || row >= this.Rows)
{
throw new ArgumentOutOfRangeException(nameof(row), row, $"{row} is outwith the matrix bounds.");
}
if (column < 0 || column >= this.Columns)
{
throw new ArgumentOutOfRangeException(nameof(column), column, $"{column} is outwith the matrix bounds.");
}
}
/// <inheritdoc/>
public bool Equals(DenseMatrix<T> other)
{
if (this.Columns != other.Columns)
{
return false;
}
if (this.Rows != other.Rows)
{
return false;
}
for (int i = 0; i < this.Data.Length; i++)
{
if (!this.Data[i].Equals(other.Data[i]))
{
return false;
}
}
return true;
}
/// <inheritdoc/>
public override bool Equals(object obj) => obj is DenseMatrix<T> matrix && this.Equals(matrix);
/// <inheritdoc/>
public override int GetHashCode() => this.Data.GetHashCode();
}
}

30
src/ImageSharp/Numerics/ValueSize.cs → src/ImageSharp/Primitives/ValueSize.cs

@ -4,7 +4,7 @@
using System;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Primitives
{
/// <summary>
/// Represents a value in relation to a value on the image
@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp
}
/// <summary>
/// The different vlaue types
/// Enumerates the different value types
/// </summary>
public enum ValueSizeType
{
@ -38,12 +38,12 @@ namespace SixLabors.ImageSharp
Absolute,
/// <summary>
/// The value is a percentage of the Images Width
/// The value is a percentage of the image width
/// </summary>
PercentageOfWidth,
/// <summary>
/// The value is a percentage of the Images height
/// The value is a percentage of the images height
/// </summary>
PercentageOfHeight
}
@ -61,9 +61,9 @@ namespace SixLabors.ImageSharp
/// <summary>
/// Implicitly converts a float into an absolute value
/// </summary>
/// <param name="d">the vlaue to use as the absolute figure.</param>
public static implicit operator ValueSize(float d)
=> Absolute(d);
/// <param name="f">the value to use as the absolute figure.</param>
public static implicit operator ValueSize(float f)
=> Absolute(f);
/// <summary>
/// Create a new ValueSize with as a PercentageOfWidth type with value set to percentage.
@ -99,7 +99,7 @@ namespace SixLabors.ImageSharp
/// Calculates the specified size.
/// </summary>
/// <param name="size">The size.</param>
/// <returns>The calucalted value</returns>
/// <returns>The calculated value</returns>
public float Calculate(Size size)
{
switch (this.Type)
@ -120,10 +120,22 @@ namespace SixLabors.ImageSharp
return $"{this.Value} - {this.Type}";
}
/// <inheritdoc/>
public override bool Equals(object obj)
{
return obj is ValueSize size && this.Equals(size);
}
/// <inheritdoc/>
public bool Equals(ValueSize other)
{
return this.Type == other.Type && this.Value == other.Value;
return this.Type == other.Type && this.Value.Equals(other.Value);
}
/// <inheritdoc/>
public override int GetHashCode()
{
return HashHelpers.Combine(this.Value.GetHashCode(), this.Type.GetHashCode());
}
}
}

30
src/ImageSharp/Processing/Binarization/BinaryDiffuse.cs → src/ImageSharp/Processing/Binarization/BinaryDiffuseExtensions.cs

@ -1,17 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.ImageSharp.Processing.Binarization.Processors;
using SixLabors.ImageSharp.Processing.Dithering.ErrorDiffusion;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Binarization
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds binary diffusion extensions to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class BinaryDiffuseExtensions
{
/// <summary>
/// Dithers the image reducing it to two colors using error diffusion.
@ -23,10 +23,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDiffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold));
return source;
}
=> source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold));
/// <summary>
/// Dithers the image reducing it to two colors using error diffusion.
@ -41,10 +38,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDiffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold), rectangle);
return source;
}
=> source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold), rectangle);
/// <summary>
/// Dithers the image reducing it to two colors using error diffusion.
@ -58,10 +52,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDiffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold, TPixel upperColor, TPixel lowerColor)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold, upperColor, lowerColor));
return source;
}
=> source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold, upperColor, lowerColor));
/// <summary>
/// Dithers the image reducing it to two colors using error diffusion.
@ -78,9 +69,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDiffuse<TPixel>(this IImageProcessingContext<TPixel> source, IErrorDiffuser diffuser, float threshold, TPixel upperColor, TPixel lowerColor, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold, upperColor, lowerColor), rectangle);
return source;
}
=> source.ApplyProcessor(new BinaryErrorDiffusionProcessor<TPixel>(diffuser, threshold, upperColor, lowerColor), rectangle);
}
}

30
src/ImageSharp/Processing/Binarization/BinaryDither.cs → src/ImageSharp/Processing/Binarization/BinaryDitherExtensions.cs

@ -1,17 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Dithering;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.ImageSharp.Processing.Binarization.Processors;
using SixLabors.ImageSharp.Processing.Dithering.Ordered;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Binarization
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds binary dithering extensions to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class BinaryDitherExtensions
{
/// <summary>
/// Dithers the image reducing it to two colors using ordered dithering.
@ -22,10 +22,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither));
return source;
}
=> source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither));
/// <summary>
/// Dithers the image reducing it to two colors using ordered dithering.
@ -38,10 +35,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither, TPixel upperColor, TPixel lowerColor)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither, upperColor, lowerColor));
return source;
}
=> source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither, upperColor, lowerColor));
/// <summary>
/// Dithers the image reducing it to two colors using ordered dithering.
@ -55,10 +49,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither), rectangle);
return source;
}
=> source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither), rectangle);
/// <summary>
/// Dithers the image reducing it to two colors using ordered dithering.
@ -74,9 +65,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> BinaryDither<TPixel>(this IImageProcessingContext<TPixel> source, IOrderedDither dither, TPixel upperColor, TPixel lowerColor, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither, upperColor, lowerColor), rectangle);
return source;
}
=> source.ApplyProcessor(new BinaryOrderedDitherProcessor<TPixel>(dither, upperColor, lowerColor), rectangle);
}
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save