ImageResourceLimits Class

Immutable resource limits applied while decoding, processing and encoding images.

public sealed class ImageResourceLimits

Remarks

Every limit must be positive; there is no "zero means unlimited" convention. To effectively disable a limit, set it to the maximum value of its type. Exceeding a limit throws an ImageResourceLimitException; it is never turned into a silently truncated result.

Limits are safety bounds, not a selection mechanism: use ImageDecodeOptions.FrameLimit to deliberately decode only a prefix of an animation. Allocation limits apply to library-controlled buffers within an allocation scope (an image and the operation working on it); they are not a process-wide memory cap.

Constructors

NameDescription
ImageResourceLimits()

ImageResourceLimits()

ImageResourceLimits.cs
public ImageResourceLimits()

No documentation is available.

Properties

NameDescription
DefaultGets the default limits.
MaxEncodedBytesGets the maximum number of encoded bytes read from one input. Defaults to ImageResourceLimits.DefaultMaxEncodedBytes.
MaxFontBytesGets the maximum number of bytes a font keeps in memory: the size of a font file, once decompressed when it is a WOFF or WOFF2 file. Defaults to ImageResourceLimits.DefaultMaxFontBytes.
MaxFontCollectionFacesGets the maximum number of fonts of a font collection (a TTC file). Defaults to ImageResourceLimits.DefaultMaxFontCollectionFaces.
MaxFramePixelsGets the maximum number of pixels of one displayed frame. Defaults to ImageResourceLimits.DefaultMaxFramePixels.
MaxFramesGets the maximum number of frames (displayed frames plus poster frame) processed from one input. Defaults to ImageResourceLimits.DefaultMaxFrames.
MaxGlyphComplexityGets the maximum number of elementary operations spent to produce one glyph: the points of its outline, the components of a composite glyph, the operators of a charstring, the nodes of a color glyph. Defaults to ImageResourceLimits.DefaultMaxGlyphComplexity.
MaxHeightGets the maximum canvas height, in pixels. Defaults to ImageResourceLimits.DefaultMaxDimension.
MaxLiveAllocationBytesGets the maximum number of live library-controlled bytes per allocation scope. Defaults to ImageResourceLimits.DefaultMaxLiveAllocationBytes.
MaxMetadataBytesGets the maximum number of decompressed or retained metadata bytes (profiles, text, EXIF, XMP) per input. Defaults to ImageResourceLimits.DefaultMaxMetadataBytes.
MaxTextGlyphsGets the maximum number of glyphs of a text layout. Defaults to ImageResourceLimits.DefaultMaxTextGlyphs.
MaxTextLengthGets the maximum length of a text that is laid out, in UTF-16 code units. Defaults to ImageResourceLimits.DefaultMaxTextLength.
MaxTextLinesGets the maximum number of lines of a text layout. Defaults to ImageResourceLimits.DefaultMaxTextLines.
MaxTotalPixelsGets the maximum cumulative number of displayed pixels produced while reading one input. Defaults to ImageResourceLimits.DefaultMaxTotalPixels.
MaxWidthGets the maximum canvas width, in pixels. Defaults to ImageResourceLimits.DefaultMaxDimension.

Gets the default limits.

public static ImageResourceLimits Default { get; }

Property value

ImageResourceLimits

MaxEncodedBytes

ImageResourceLimits.cs

Gets the maximum number of encoded bytes read from one input. Defaults to ImageResourceLimits.DefaultMaxEncodedBytes.

public long MaxEncodedBytes { get; init; }

Property value

long

Exceptions

ArgumentOutOfRangeException
The value is not positive.

Remarks

Synchronous TIFF, ICO, CUR and ANI loads from a path or seekable stream charge cumulative reads, including repeated ranges, not the file length. Span, non-seekable and asynchronous loads of these formats charge the whole input once.

Gets the maximum number of bytes a font keeps in memory: the size of a font file, once decompressed when it is a WOFF or WOFF2 file. Defaults to ImageResourceLimits.DefaultMaxFontBytes.

public long MaxFontBytes { get; init; }

Property value

long

Exceptions

ArgumentOutOfRangeException
The value is not positive.

Remarks

The bytes read from the input are bounded by ImageResourceLimits.MaxEncodedBytes, as for an image.

MaxFontCollectionFaces

ImageResourceLimits.cs

Gets the maximum number of fonts of a font collection (a TTC file). Defaults to ImageResourceLimits.DefaultMaxFontCollectionFaces.

public int MaxFontCollectionFaces { get; init; }

Property value

int

Exceptions

ArgumentOutOfRangeException
The value is not positive.

Remarks

Every font of a collection is read when the collection is loaded, and the fonts can share their tables: this limit bounds that work.

Gets the maximum number of pixels of one displayed frame. Defaults to ImageResourceLimits.DefaultMaxFramePixels.

public long MaxFramePixels { get; init; }

Property value

long

Exceptions

ArgumentOutOfRangeException
The value is not positive.

Gets the maximum number of frames (displayed frames plus poster frame) processed from one input. Defaults to ImageResourceLimits.DefaultMaxFrames.

public int MaxFrames { get; init; }

Property value

int

Exceptions

ArgumentOutOfRangeException
The value is not positive.

MaxGlyphComplexity

ImageResourceLimits.cs

Gets the maximum number of elementary operations spent to produce one glyph: the points of its outline, the components of a composite glyph, the operators of a charstring, the nodes of a color glyph. Defaults to ImageResourceLimits.DefaultMaxGlyphComplexity.

public long MaxGlyphComplexity { get; init; }

Property value

long

Exceptions

ArgumentOutOfRangeException
The value is not positive.

Remarks

A font can describe, in a few bytes, a glyph whose outline is exponentially large (glyphs made of glyphs made of glyphs). This limit bounds the work and the memory a hostile font can ask for.

Gets the maximum canvas height, in pixels. Defaults to ImageResourceLimits.DefaultMaxDimension.

public int MaxHeight { get; init; }

Property value

int

Exceptions

ArgumentOutOfRangeException
The value is not positive.

MaxLiveAllocationBytes

ImageResourceLimits.cs

Gets the maximum number of live library-controlled bytes per allocation scope. Defaults to ImageResourceLimits.DefaultMaxLiveAllocationBytes.

public long MaxLiveAllocationBytes { get; init; }

Property value

long

Exceptions

ArgumentOutOfRangeException
The value is not positive.

MaxMetadataBytes

ImageResourceLimits.cs

Gets the maximum number of decompressed or retained metadata bytes (profiles, text, EXIF, XMP) per input. Defaults to ImageResourceLimits.DefaultMaxMetadataBytes.

public long MaxMetadataBytes { get; init; }

Property value

long

Exceptions

ArgumentOutOfRangeException
The value is not positive.

Gets the maximum number of glyphs of a text layout. Defaults to ImageResourceLimits.DefaultMaxTextGlyphs.

public long MaxTextGlyphs { get; init; }

Property value

long

Exceptions

ArgumentOutOfRangeException
The value is not positive.

Remarks

A layout keeps the identifier and the position of each of its glyphs: this limit bounds the memory of a layout and the work of drawing it.

Gets the maximum length of a text that is laid out, in UTF-16 code units. Defaults to ImageResourceLimits.DefaultMaxTextLength.

public long MaxTextLength { get; init; }

Property value

long

Exceptions

ArgumentOutOfRangeException
The value is not positive.

Remarks

The limits of a text layout are those of the configuration its font was loaded with.

Gets the maximum number of lines of a text layout. Defaults to ImageResourceLimits.DefaultMaxTextLines.

public int MaxTextLines { get; init; }

Property value

int

Exceptions

ArgumentOutOfRangeException
The value is not positive.

Remarks

A text that needs more lines is an error; TextLayoutOptions.MaxLines is what cuts a text at a number of lines.

Gets the maximum cumulative number of displayed pixels produced while reading one input. Defaults to ImageResourceLimits.DefaultMaxTotalPixels.

public long MaxTotalPixels { get; init; }

Property value

long

Exceptions

ArgumentOutOfRangeException
The value is not positive.

Gets the maximum canvas width, in pixels. Defaults to ImageResourceLimits.DefaultMaxDimension.

public int MaxWidth { get; init; }

Property value

int

Exceptions

ArgumentOutOfRangeException
The value is not positive.

Constants

NameDescription
DefaultMaxDimensionThe default maximum canvas width and height, in pixels (32,768).
DefaultMaxEncodedBytesThe default maximum number of encoded bytes read from one input (256 MiB).
DefaultMaxFontBytesThe default maximum number of bytes a font keeps in memory (256 MiB).
DefaultMaxFontCollectionFacesThe default maximum number of fonts of a font collection (1,024).
DefaultMaxFramePixelsThe default maximum number of pixels of one displayed frame (100,000,000).
DefaultMaxFramesThe default maximum number of frames processed from one input (1,000).
DefaultMaxGlyphComplexityThe default maximum number of elementary operations to produce one glyph (1,000,000).
DefaultMaxLiveAllocationBytesThe default maximum number of live library-controlled bytes per allocation scope (512 MiB).
DefaultMaxMetadataBytesThe default maximum number of decompressed or retained metadata bytes (16 MiB).
DefaultMaxTextGlyphsThe default maximum number of glyphs of a text layout (1,000,000).
DefaultMaxTextLengthThe default maximum length of a text that is laid out, in UTF-16 code units (1,000,000).
DefaultMaxTextLinesThe default maximum number of lines of a text layout (100,000).
DefaultMaxTotalPixelsThe default maximum cumulative number of displayed pixels produced while reading one input (1,000,000,000).

DefaultMaxDimension

The default maximum canvas width and height, in pixels (32,768).

public const int DefaultMaxDimension = 32768

DefaultMaxEncodedBytes

The default maximum number of encoded bytes read from one input (256 MiB).

public const long DefaultMaxEncodedBytes = 268435456L

DefaultMaxFontBytes

The default maximum number of bytes a font keeps in memory (256 MiB).

public const long DefaultMaxFontBytes = 268435456L

DefaultMaxFontCollectionFaces

The default maximum number of fonts of a font collection (1,024).

public const int DefaultMaxFontCollectionFaces = 1024

DefaultMaxFramePixels

The default maximum number of pixels of one displayed frame (100,000,000).

public const long DefaultMaxFramePixels = 100000000L

DefaultMaxFrames

The default maximum number of frames processed from one input (1,000).

public const int DefaultMaxFrames = 1000

DefaultMaxGlyphComplexity

The default maximum number of elementary operations to produce one glyph (1,000,000).

public const long DefaultMaxGlyphComplexity = 1000000L

DefaultMaxLiveAllocationBytes

The default maximum number of live library-controlled bytes per allocation scope (512 MiB).

public const long DefaultMaxLiveAllocationBytes = 536870912L

DefaultMaxMetadataBytes

The default maximum number of decompressed or retained metadata bytes (16 MiB).

public const long DefaultMaxMetadataBytes = 16777216L

DefaultMaxTextGlyphs

The default maximum number of glyphs of a text layout (1,000,000).

public const long DefaultMaxTextGlyphs = 1000000L

DefaultMaxTextLength

The default maximum length of a text that is laid out, in UTF-16 code units (1,000,000).

public const long DefaultMaxTextLength = 1000000L

DefaultMaxTextLines

The default maximum number of lines of a text layout (100,000).

public const int DefaultMaxTextLines = 100000

DefaultMaxTotalPixels

The default maximum cumulative number of displayed pixels produced while reading one input (1,000,000,000).

public const long DefaultMaxTotalPixels = 1000000000L