//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
namespace ImageSharp.Formats.Jpg
{
using System;
using System.Runtime.CompilerServices;
///
/// Encapsulates exception thrower methods for the Jpeg Encoder
///
internal static class DecoderThrowHelper
{
///
/// Throws an exception that belongs to the given
///
/// The
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowExceptionForErrorCode(this DecoderErrorCode errorCode)
{
switch (errorCode)
{
case DecoderErrorCode.NoError:
throw new ArgumentException("ThrowExceptionForErrorCode() called with NoError!", nameof(errorCode));
case DecoderErrorCode.MissingFF00:
throw new MissingFF00Exception();
case DecoderErrorCode.UnexpectedEndOfStream:
throw new EOFException();
default:
throw new ArgumentOutOfRangeException(nameof(errorCode), errorCode, null);
}
}
///
/// Throws an exception if the given defines an error.
///
/// The
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void EnsureNoError(this DecoderErrorCode errorCode)
{
if (errorCode != DecoderErrorCode.NoError)
{
ThrowExceptionForErrorCode(errorCode);
}
}
///
/// Encapsulates methods throwing different flavours of -s.
///
public static class ThrowImageFormatException
{
///
/// Throws "Fill called when unread bytes exist."
///
[MethodImpl(MethodImplOptions.NoInlining)]
public static void FillCalledWhenUnreadBytesExist()
{
throw new ImageFormatException("Fill called when unread bytes exist.");
}
}
}
}