|
| 1 | +// Copyright (c) Six Labors and contributors. |
| 2 | +// Licensed under the Apache License, Version 2.0. |
| 3 | + |
| 4 | +using System; |
| 5 | + |
| 6 | +using SixLabors.ImageSharp.Metadata; |
| 7 | +using SixLabors.ImageSharp.PixelFormats; |
| 8 | +using SixLabors.Memory; |
| 9 | +using SixLabors.Primitives; |
| 10 | + |
| 11 | +namespace SixLabors.ImageSharp |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Represents a pixel-agnostic image frame containing all pixel data and <see cref="ImageFrameMetadata"/>. |
| 15 | + /// In case of animated formats like gif, it contains the single frame in a animation. |
| 16 | + /// In all other cases it is the only frame of the image. |
| 17 | + /// </summary> |
| 18 | + public abstract partial class ImageFrame : IDisposable |
| 19 | + { |
| 20 | + /// <summary> |
| 21 | + /// Initializes a new instance of the <see cref="ImageFrame"/> class. |
| 22 | + /// </summary> |
| 23 | + /// <param name="configuration">The <see cref="Configuration"/>.</param> |
| 24 | + /// <param name="width">The width.</param> |
| 25 | + /// <param name="height">The height.</param> |
| 26 | + /// <param name="metadata">The <see cref="ImageFrameMetadata"/>.</param> |
| 27 | + protected ImageFrame(Configuration configuration, int width, int height, ImageFrameMetadata metadata) |
| 28 | + { |
| 29 | + Guard.NotNull(configuration, nameof(configuration)); |
| 30 | + Guard.NotNull(metadata, nameof(metadata)); |
| 31 | + |
| 32 | + this.Configuration = configuration; |
| 33 | + this.MemoryAllocator = configuration.MemoryAllocator; |
| 34 | + this.Width = width; |
| 35 | + this.Height = height; |
| 36 | + this.Metadata = metadata; |
| 37 | + } |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Gets the <see cref="MemoryAllocator" /> to use for buffer allocations. |
| 41 | + /// </summary> |
| 42 | + public MemoryAllocator MemoryAllocator { get; } |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Gets the <see cref="Configuration"/> instance associated with this <see cref="ImageFrame{TPixel}"/>. |
| 46 | + /// </summary> |
| 47 | + internal Configuration Configuration { get; } |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Gets the width. |
| 51 | + /// </summary> |
| 52 | + public int Width { get; private set; } |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// Gets the height. |
| 56 | + /// </summary> |
| 57 | + public int Height { get; private set; } |
| 58 | + |
| 59 | + /// <summary> |
| 60 | + /// Gets the metadata of the frame. |
| 61 | + /// </summary> |
| 62 | + public ImageFrameMetadata Metadata { get; } |
| 63 | + |
| 64 | + /// <summary> |
| 65 | + /// Gets the size of the frame. |
| 66 | + /// </summary> |
| 67 | + /// <returns>The <see cref="Size"/></returns> |
| 68 | + public Size Size() => new Size(this.Width, this.Height); |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Gets the bounds of the frame. |
| 72 | + /// </summary> |
| 73 | + /// <returns>The <see cref="Rectangle"/></returns> |
| 74 | + public Rectangle Bounds() => new Rectangle(0, 0, this.Width, this.Height); |
| 75 | + |
| 76 | + /// <inheritdoc /> |
| 77 | + public abstract void Dispose(); |
| 78 | + |
| 79 | + internal abstract void CopyPixelsTo<TDestinationPixel>(Span<TDestinationPixel> destination) |
| 80 | + where TDestinationPixel : struct, IPixel<TDestinationPixel>; |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// Updates the size of the image frame. |
| 84 | + /// </summary> |
| 85 | + internal void UpdateSize(Size size) |
| 86 | + { |
| 87 | + this.Width = size.Width; |
| 88 | + this.Height = size.Height; |
| 89 | + } |
| 90 | + } |
| 91 | +} |
0 commit comments