• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

team-charls / charls-dotnet / 18775459846

24 Oct 2025 09:21AM UTC coverage: 94.488% (-0.1%) from 94.625%
18775459846

Pull #61

github

web-flow
Merge 6d689c757 into cc5d89c30
Pull Request #61: Add support for subsampling

1411 of 1546 branches covered (91.27%)

Branch coverage included in aggregate %.

132 of 138 new or added lines in 7 files covered. (95.65%)

2 existing lines in 1 file now uncovered.

3440 of 3588 relevant lines covered (95.88%)

520290.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.21
/src/ThrowHelper.cs
1
// Copyright (c) Team CharLS.
2
// SPDX-License-Identifier: BSD-3-Clause
3

4
using System.Diagnostics.CodeAnalysis;
5
using System.Numerics;
6
using System.Runtime.CompilerServices;
7

8
namespace CharLS.Managed;
9

10
internal static class ThrowHelper
11
{
12
    [DoesNotReturn]
13
    internal static void ThrowArgumentOutOfRangeException(ErrorCode errorCode, string? paramName = null)
14
    {
15
        throw AddErrorCode(new ArgumentOutOfRangeException(paramName, GetErrorMessage(errorCode)), errorCode);
74✔
16
    }
17

18
    [DoesNotReturn]
19
    internal static void ThrowArgumentException(ErrorCode errorCode, string? paramName = null)
20
    {
21
        throw AddErrorCode(new ArgumentException(GetErrorMessage(errorCode), paramName), errorCode);
44✔
22
    }
23

24
    internal static void ThrowArgumentOutOfRangeExceptionIfFalse([DoesNotReturnIf(false)] bool condition, ErrorCode errorCode, string? paramName = null)
25
    {
26
        if (condition)
336✔
27
            return;
328✔
28

29
        ThrowArgumentOutOfRangeException(errorCode, paramName);
8✔
30
    }
×
31

32
    internal static void ThrowIfNegativeOrZero<T>(T value, ErrorCode errorCode, [CallerArgumentExpression(nameof(value))] string? paramName = null)
33
        where T : INumberBase<T>
34
    {
35
        if (T.IsNegative(value) || T.IsZero(value))
7,416✔
36
            ThrowArgumentOutOfRangeException(errorCode, paramName);
12✔
37
    }
7,404✔
38

39
    internal static void ThrowIfOutsideRange<T>(T min, T max, T value, ErrorCode errorCode = ErrorCode.InvalidArgument, [CallerArgumentExpression(nameof(value))] string? paramName = null)
40
        where T : IBinaryInteger<T>
41
    {
42
        if (value < min || value > max)
7,864✔
43
            ThrowArgumentOutOfRangeException(errorCode, paramName);
48✔
44
    }
7,816✔
45

46
    internal static void ThrowInvalidOperationIfFalse([DoesNotReturnIf(false)] bool condition)
47
    {
48
        if (condition)
5,314✔
49
            return;
5,256✔
50

51
        ThrowInvalidOperationException();
58✔
52
    }
×
53

54
    internal static void ThrowArgumentExceptionIfFalse([DoesNotReturnIf(false)] bool value, string? paramName = null, ErrorCode errorCode = ErrorCode.InvalidArgument)
55
    {
56
        if (value)
348✔
57
            return;
330✔
58

59
        ThrowArgumentException(errorCode, paramName);
18✔
60
    }
×
61

62
    [DoesNotReturn]
63
    internal static void ThrowInvalidDataException(ErrorCode errorCode)
64
    {
65
        throw CreateInvalidDataException(errorCode);
130✔
66
    }
67

68
    internal static ArgumentException CreateArgumentException(ErrorCode errorCode)
69
    {
70
        return AddErrorCode(new ArgumentException(GetErrorMessage(errorCode)), errorCode);
2✔
71
    }
72

73
    internal static InvalidDataException CreateInvalidDataException(ErrorCode errorCode)
74
    {
75
        return AddErrorCode(new InvalidDataException(GetErrorMessage(errorCode)), errorCode);
136✔
76
    }
77

78
    internal static InvalidDataException CreateInvalidDataException(ErrorCode errorCode, Exception innerException)
79
    {
80
        return AddErrorCode(new InvalidDataException(GetErrorMessage(errorCode), innerException), errorCode);
4✔
81
    }
82

83
    [DoesNotReturn]
84
    private static void ThrowInvalidOperationException()
85
    {
86
        const ErrorCode errorCode = ErrorCode.InvalidOperation;
87
        throw AddErrorCode(new InvalidOperationException(GetErrorMessage(errorCode)), errorCode);
58✔
88
    }
89

90
    private static T AddErrorCode<T>(T exception, ErrorCode errorCode)
91
        where T : Exception
92
    {
93
        exception.AddErrorCode(errorCode);
318✔
94
        return exception;
318✔
95
    }
96

97
    private static string GetErrorMessage(ErrorCode errorCode)
98
    {
99
        return errorCode switch
318!
100
        {
318✔
101
            ErrorCode.None => string.Empty,
2✔
102
            ErrorCode.CallbackFailed => "Callback function returned a failure",
2✔
103
            ErrorCode.DestinationTooSmall => "The destination buffer is too small to hold all the output",
6✔
104
            ErrorCode.NeedMoreData => "The source is too small, more input data was expected",
4✔
105
            ErrorCode.InvalidData => "Invalid JPEG-LS stream, the encoded bit stream contains a general structural problem",
8✔
106
            ErrorCode.EncodingNotSupported => "Invalid JPEG-LS stream: the JPEG stream is not encoded with the JPEG-LS algorithm",
2✔
107
            ErrorCode.ParameterValueNotSupported => "The JPEG-LS stream is encoded with a parameter value that is not supported by this decoder",
8✔
108
            ErrorCode.ColorTransformNotSupported => "The HP color transform is not supported",
×
109
            ErrorCode.JpegLSPresetExtendedParameterTypeNotSupported => "Unsupported JPEG-LS stream: JPEG-LS preset parameters segment contains a JPEG-LS Extended (ISO/IEC 14495-2) type",
16✔
110
            ErrorCode.JpegMarkerStartByteNotFound => "Invalid JPEG-LS stream: the leading start byte (0xFF) for a JPEG marker was not found",
8✔
111
            ErrorCode.StartOfImageMarkerNotFound => "Invalid JPEG-LS stream: first JPEG marker is not a Start Of Image (SOI) marker",
×
112
            ErrorCode.InvalidSpiffHeader => "Invalid JPEG-LS stream: invalid SPIFF header",
×
113
            ErrorCode.UnknownJpegMarkerFound => "Invalid JPEG-LS stream: an unknown JPEG marker code was found",
×
114
            ErrorCode.UnexpectedStartOfScanMarker => "Invalid JPEG-LS stream: unexpected Start Of Scan (SOS) marker found",
2✔
115
            ErrorCode.InvalidMarkerSegmentSize => "Invalid JPEG-LS stream: segment size of a marker segment is invalid",
26✔
116
            ErrorCode.DuplicateStartOfImageMarker => "Invalid JPEG-LS stream: more then one Start Of Image (SOI) marker",
2✔
117
            ErrorCode.DuplicateStartOfFrameMarker => "Invalid JPEG-LS stream: more then one Start Of Frame (SOF) marker",
2✔
118
            ErrorCode.DuplicateComponentIdInStartOfFrameSegment => "Invalid JPEG-LS stream: duplicate component identifier in the (SOF) segment",
2✔
119
            ErrorCode.UnexpectedEndOfImageMarker => "Invalid JPEG-LS stream: unexpected End Of Image (EOI) marker",
2✔
120
            ErrorCode.InvalidJpegLSPresetParameterType => "Invalid JPEG-LS stream: JPEG-LS preset parameters segment contains an invalid type",
×
121
            ErrorCode.MissingEndOfSpiffDirectory => "Invalid JPEG-LS stream: SPIFF header without End Of Directory (EOD) entry",
2✔
122
            ErrorCode.UnexpectedRestartMarker => "Invalid JPEG-LS stream: restart (RTSm) marker found outside encoded entropy data",
2✔
123
            ErrorCode.RestartMarkerNotFound => "Invalid JPEG-LS stream: missing expected restart (RTSm) marker",
4✔
124
            ErrorCode.EndOfImageMarkerNotFound => "Invalid JPEG-LS stream: missing expected End of Image (EOI) marker",
×
125
            ErrorCode.UnexpectedDefineNumberOfLinesMarker => "Invalid JPEG-LS stream: unexpected Define Number of Lines (DNL) marker",
4✔
126
            ErrorCode.DefineNumberOfLinesMarkerNotFound => "Invalid JPEG-LS stream: missing expected Define Number of Lines (DNL) marker",
4✔
127
            ErrorCode.UnknownComponentId => "Invalid JPEG-LS stream: unknown component ID in scan segment",
×
128
            ErrorCode.AbbreviatedFormatAndSpiffHeaderMismatch => "Invalid JPEG-LS stream: mapping tables without SOF but with spiff header",
2✔
129
            ErrorCode.InvalidParameterWidth => "Invalid JPEG-LS stream: the width (Number of samples per line) is defined invalid or twice",
4✔
130
            ErrorCode.InvalidParameterHeight => "Invalid JPEG-LS stream: the height (Number of lines) is defined invalid or twice",
4✔
131
            ErrorCode.InvalidParameterBitsPerSample => "Invalid JPEG-LS stream: the bit per sample (sample precision) parameter is not in the range [2, 16]",
×
132
            ErrorCode.InvalidParameterComponentCount => "Invalid JPEG-LS stream: component count in the SOF segment is outside the range [1, 255]",
6✔
133
            ErrorCode.InvalidParameterInterleaveMode => "Invalid JPEG-LS stream: interleave mode is outside the range [0, 2] or conflicts with component count",
4✔
134
            ErrorCode.InvalidParameterNearLossless => "Invalid JPEG-LS stream: near-lossless is outside the range [0, min(255, MAXVAL/2)]",
4✔
135
            ErrorCode.InvalidParameterJpegLSPresetParameters => "Invalid JPEG-LS stream: JPEG-LS preset parameters segment contains invalid values",
2✔
136
            ErrorCode.InvalidParameterColorTransformation => "Invalid JPEG-LS stream: Color transformation segment contains invalid values or frame info mismatch",
4✔
137
            ErrorCode.InvalidParameterMappingTableId => "Invalid JPEG-LS stream: mapping table ID outside valid range or duplicate",
4✔
138
            ErrorCode.InvalidParameterMappingTableContinuation => "Invalid JPEG-LS stream: mapping table continuation without matching mapping table specification",
4✔
NEW
139
            ErrorCode.InvalidParameterSamplingFactor => "Invalid JPEG-LS stream: sampling factor outside range [1, 4] or overall sum(h*v) > 10",
×
140
            ErrorCode.InvalidOperation => "Method call is invalid for the current state",
58✔
141
            ErrorCode.InvalidArgument => "Invalid argument",
32✔
142
            ErrorCode.InvalidArgumentHeight => "The height argument is outside the supported range [1, 2147483647]",
8✔
143
            ErrorCode.InvalidArgumentWidth => "The width argument is outside the supported range [1, 2147483647]",
8✔
144
            ErrorCode.InvalidArgumentBitsPerSample => "The bit per sample argument is outside the range [2, 16]",
8✔
145
            ErrorCode.InvalidArgumentComponentCount => "The component count argument is outside the range [1, 255]",
8✔
146
            ErrorCode.InvalidArgumentInterleaveMode => "The interleave mode is not None, Sample, Line or invalid in combination with component count",
10✔
147
            ErrorCode.InvalidArgumentNearLossless => "The near lossless argument is outside the range [0, min(255, MAXVAL/2)]",
4✔
148
            ErrorCode.InvalidArgumentPresetCodingParameters => "The argument for the JPEG-LS preset coding parameters is not valid",
2✔
149
            ErrorCode.InvalidArgumentColorTransformation => "The argument for the color component is not (None, Hp1, Hp2, Hp3) or invalid in combination with component count",
8✔
150
            ErrorCode.InvalidArgumentSize => "The passed size of a buffer is outside the valid range",
14✔
151
            ErrorCode.InvalidArgumentStride => "The stride argument does not match with the frame info and buffer size",
10✔
152
            ErrorCode.InvalidArgumentEncodingOptions => "The encoding options argument has an invalid value",
2✔
153
            _ => string.Empty
×
154
        };
318✔
155
    }
156
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc