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

JaCraig / Archivist / 19323684277

13 Nov 2025 07:18AM UTC coverage: 77.083% (-0.3%) from 77.414%
19323684277

push

github

web-flow
Merge pull request #225 from JaCraig/dependabot/nuget/Archivist.OCR.Tests/dependencies-dcdae679ca

chore: Bump the dependencies group with 1 update

2403 of 3412 branches covered (70.43%)

Branch coverage included in aggregate %.

3184 of 3836 relevant lines covered (83.0%)

5400.53 hits per line

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

73.68
/Archivist/DataTypes/Image.cs
1
using Archivist.BaseClasses;
2
using Archivist.Converters;
3
using Archivist.Enums;
4
using Archivist.Interfaces;
5
using System;
6
using System.Collections.Generic;
7
using System.Linq;
8

9
namespace Archivist.DataTypes
10
{
11
    /// <summary>
12
    /// Image data type.
13
    /// </summary>
14
    /// <seealso cref="FileBaseClass{Image}"/>
15
    /// <seealso cref="IComparable{Image}"/>
16
    /// <seealso cref="IEquatable{Image}"/>
17
    public class Image : FileBaseClass<Image>, IComparable<Image>, IEquatable<Image>
18
    {
19
        /// <summary>
20
        /// Initializes a new instance of the <see cref="Image"/> class.
21
        /// </summary>
22
        public Image()
23
            : this(null)
58,127✔
24
        {
25
        }
58,127✔
26

27
        /// <summary>
28
        /// Initializes a new instance of the <see cref="Image"/> class with the specified converter.
29
        /// </summary>
30
        /// <param name="converter">The converter to use.</param>
31
        public Image(Convertinator? converter)
32
            : base(converter)
58,203✔
33
        {
34
        }
58,203✔
35

36
        /// <summary>
37
        /// Gets or sets the number of bytes per pixel.
38
        /// </summary>
39
        public int BytesPerPixel { get; set; }
116,154✔
40

41
        /// <summary>
42
        /// Gets or sets the data of the image.
43
        /// </summary>
44
        public byte[] Data { get; set; } = Array.Empty<byte>();
174,436✔
45

46
        /// <summary>
47
        /// The description of the image (if using OCR/LLM processor, that information will be
48
        /// stored here).
49
        /// </summary>
50
        public string Description
51
        {
52
            get => Metadata?.GetValueOrDefault(CommonImageMetadataFields.Description) ?? "";
116,148!
53
            set
54
            {
55
                if (Metadata is null)
8!
56
                    return;
×
57
                Metadata[CommonImageMetadataFields.Description] = value ?? "";
8✔
58
            }
8✔
59
        }
60

61
        /// <summary>
62
        /// Gets or sets the height of the image.
63
        /// </summary>
64
        public int Height { get; set; }
116,173✔
65

66
        /// <summary>
67
        /// Gets or sets the type of the image.
68
        /// </summary>
69
        public string ImageType
70
        {
71
            get => Metadata?.GetValueOrDefault(CommonImageMetadataFields.ImageType) ?? "";
116,141!
72
            set
73
            {
74
                if (Metadata is null)
7!
75
                    return;
×
76
                Metadata[CommonImageMetadataFields.ImageType] = value ?? "";
7✔
77
            }
7✔
78
        }
79

80
        /// <summary>
81
        /// Gets or sets the width of the image.
82
        /// </summary>
83
        public int Width { get; set; }
116,201✔
84

85
        /// <summary>
86
        /// Converts the Image to a Calendar.
87
        /// </summary>
88
        /// <param name="file">The Image to convert.</param>
89
        public static implicit operator Calendar?(Image? file)
90
        {
91
            return ImageToAnythingConverter.Convert(file, typeof(Calendar)) as Calendar;
1✔
92
        }
93

94
        /// <summary>
95
        /// Converts the Image to a Card.
96
        /// </summary>
97
        /// <param name="file">The Image to convert.</param>
98
        /// <returns>The Card representation of the Image.</returns>
99
        public static implicit operator Card?(Image? file)
100
        {
101
            return ImageToAnythingConverter.Convert(file, typeof(Card)) as Card;
1✔
102
        }
103

104
        /// <summary>
105
        /// Converts the Image to a Feed.
106
        /// </summary>
107
        /// <param name="file">The Image to convert.</param>
108
        /// <returns>The Feed representation of the Image.</returns>
109
        public static implicit operator Feed?(Image? file)
110
        {
111
            return ImageToAnythingConverter.Convert(file, typeof(Feed)) as Feed;
1✔
112
        }
113

114
        /// <summary>
115
        /// Converts the Image to a structured object.
116
        /// </summary>
117
        /// <param name="file">The Image to convert.</param>
118
        /// <returns>The structured object representation of the Image.</returns>
119
        public static implicit operator StructuredObject?(Image? file)
120
        {
121
            return ImageToAnythingConverter.Convert(file, typeof(StructuredObject)) as StructuredObject;
1✔
122
        }
123

124
        /// <summary>
125
        /// Converts the Image to a table.
126
        /// </summary>
127
        /// <param name="file">The Image to convert.</param>
128
        /// <returns>The table representation of the Image.</returns>
129
        public static implicit operator Table?(Image? file)
130
        {
131
            return ImageToAnythingConverter.Convert(file, typeof(Table)) as Table;
1✔
132
        }
133

134
        /// <summary>
135
        /// Converts the Image to a Tables file.
136
        /// </summary>
137
        /// <param name="file">The Image to convert.</param>
138
        /// <returns>The Tables representation of the Image.</returns>
139
        public static implicit operator Tables?(Image? file)
140
        {
141
            return ImageToAnythingConverter.Convert(file, typeof(Tables)) as Tables;
1✔
142
        }
143

144
        /// <summary>
145
        /// Converts the Image to text.
146
        /// </summary>
147
        /// <param name="file">The Image to convert.</param>
148
        /// <returns>The text representation of the Image.</returns>
149
        public static implicit operator Text?(Image? file)
150
        {
151
            if (file is null)
1!
152
                return null;
1✔
153
            Text? ReturnValue = AnythingToTextConverter.Convert(file);
×
154
            if (ReturnValue is not null)
×
155
                ReturnValue.Title ??= file.Title;
×
156
            return ReturnValue;
×
157
        }
158

159
        /// <summary>
160
        /// Determines whether two Image objects are not equal.
161
        /// </summary>
162
        /// <param name="left">The first Image to compare.</param>
163
        /// <param name="right">The second Image to compare.</param>
164
        /// <returns>True if the Image objects are not equal; otherwise, false.</returns>
165
        public static bool operator !=(Image? left, Image? right)
166
        {
167
            return !(left == right);
6✔
168
        }
169

170
        /// <summary>
171
        /// Determines whether one Image object is less than another Image object.
172
        /// </summary>
173
        /// <param name="left">The first Image to compare.</param>
174
        /// <param name="right">The second Image to compare.</param>
175
        /// <returns>True if the first Image is less than the second Image; otherwise, false.</returns>
176
        public static bool operator <(Image? left, Image? right)
177
        {
178
            return left is null ? right is not null : left.CompareTo(right) < 0;
4✔
179
        }
180

181
        /// <summary>
182
        /// Determines whether one Image object is less than or equal to another Image object.
183
        /// </summary>
184
        /// <param name="left">The first Image to compare.</param>
185
        /// <param name="right">The second Image to compare.</param>
186
        /// <returns>
187
        /// True if the first Image is less than or equal to the second Image; otherwise, false.
188
        /// </returns>
189
        public static bool operator <=(Image? left, Image? right)
190
        {
191
            return left is null || left.CompareTo(right) <= 0;
4✔
192
        }
193

194
        /// <summary>
195
        /// Determines whether two Image objects are equal.
196
        /// </summary>
197
        /// <param name="left">The first Image to compare.</param>
198
        /// <param name="right">The second Image to compare.</param>
199
        /// <returns>True if the Image objects are equal; otherwise, false.</returns>
200
        public static bool operator ==(Image? left, Image? right)
201
        {
202
            if (left is null)
12✔
203
                return right is null;
4✔
204

205
            return left.Equals(right);
8✔
206
        }
207

208
        /// <summary>
209
        /// Determines whether one Image object is greater than another Image object.
210
        /// </summary>
211
        /// <param name="left">The first Image to compare.</param>
212
        /// <param name="right">The second Image to compare.</param>
213
        /// <returns>True if the first Image is greater than the second Image; otherwise, false.</returns>
214
        public static bool operator >(Image? left, Image? right)
215
        {
216
            return left?.CompareTo(right) > 0;
4✔
217
        }
218

219
        /// <summary>
220
        /// Determines whether one Image object is greater than or equal to another Image object.
221
        /// </summary>
222
        /// <param name="left">The first Image to compare.</param>
223
        /// <param name="right">The second Image to compare.</param>
224
        /// <returns>
225
        /// True if the first Image is greater than or equal to the second Image; otherwise, false.
226
        /// </returns>
227
        public static bool operator >=(Image? left, Image? right)
228
        {
229
            return left is null ? right is null : left.CompareTo(right) >= 0;
4✔
230
        }
231

232
        /// <summary>
233
        /// Compares the Image to another Image based on their content.
234
        /// </summary>
235
        /// <param name="other">The other Image to compare.</param>
236
        /// <returns>An integer that indicates the relative order of the Images.</returns>
237
        public override int CompareTo(Image? other)
238
        {
239
            if (other is null || other.Data is null)
13✔
240
                return 1;
5✔
241
            if (Data is null)
8!
242
                return -1;
×
243
            if (Width != other.Width)
8✔
244
                return Width.CompareTo(other.Width);
2✔
245
            if (Height != other.Height)
6!
246
                return Height.CompareTo(other.Height);
×
247
            if (Data.Length != other.Data.Length)
6!
248
                return Data.Length.CompareTo(other.Data.Length);
×
249
            for (var I = 0; I < Data.Length; I++)
20✔
250
            {
251
                if (Data[I] != other.Data[I])
4!
252
                    return Data[I].CompareTo(other.Data[I]);
×
253
            }
254
            return 0;
6✔
255
        }
256

257
        /// <summary>
258
        /// Determines whether the Image is equal to another Image based on their content.
259
        /// </summary>
260
        /// <param name="other">The other Image to compare.</param>
261
        /// <returns>True if the Images are equal; otherwise, false.</returns>
262
        public override bool Equals(Image? other)
263
        {
264
            if (other is null)
14✔
265
                return false;
3✔
266
            if (Width != other.Width)
11✔
267
                return false;
4✔
268
            if (Height != other.Height)
7!
269
                return false;
×
270
            if (Data.Length != other.Data.Length)
7!
271
                return false;
×
272
            return Data.SequenceEqual(other.Data);
7✔
273
        }
274

275
        /// <summary>
276
        /// Determines whether the Image is equal to another object.
277
        /// </summary>
278
        /// <param name="obj">The object to compare.</param>
279
        /// <returns>True if the Image is equal to the object; otherwise, false.</returns>
280
        public override bool Equals(object? obj) => ReferenceEquals(this, obj) || (obj is Image ImageObject && Equals(ImageObject));
6!
281

282
        /// <summary>
283
        /// Gets the content of the Image.
284
        /// </summary>
285
        /// <returns>The content of the Image.</returns>
286
        public override string? GetContent()
287
        {
288
            if (!string.IsNullOrEmpty(Description))
10✔
289
                return Description;
4✔
290
            return $"{Title ?? "Image"}: {ImageType ?? "Unknown Type"}({Width}x{Height})";
6!
291
        }
292

293
        /// <summary>
294
        /// Gets the hash code of the Image based on its content.
295
        /// </summary>
296
        /// <returns>The hash code of the Image.</returns>
297
        public override int GetHashCode() => GetContent()?.GetHashCode(StringComparison.OrdinalIgnoreCase) ?? 0;
6!
298

299
        /// <summary>
300
        /// Converts the Image to the specified object type.
301
        /// </summary>
302
        /// <typeparam name="TFile">The type to convert the Image to.</typeparam>
303
        /// <returns>The converted Image.</returns>
304
        public override TFile? ToFileType<TFile>()
305
            where TFile : default
306
        {
307
            Type FileType = typeof(TFile);
2✔
308
            IGenericFile? ReturnValue;
309
            if (FileType == typeof(Image))
2✔
310
                ReturnValue = (IGenericFile?)this;
1✔
311
            else if (FileType == typeof(Feed))
1!
312
                ReturnValue = (Feed?)this;
×
313
            else if (FileType == typeof(Calendar))
1!
314
                ReturnValue = (Calendar?)this;
×
315
            else if (FileType == typeof(Card))
1!
316
                ReturnValue = (Card?)this;
×
317
            else if (FileType == typeof(Table))
1!
318
                ReturnValue = (Table?)this;
×
319
            else if (FileType == typeof(Tables))
1!
320
                ReturnValue = (Tables?)this;
×
321
            else if (FileType == typeof(Text))
1!
322
                ReturnValue = (Text?)this;
×
323
            else if (FileType == typeof(StructuredObject))
1!
324
                ReturnValue = (StructuredObject?)this;
×
325
            else
326
                ReturnValue = (IGenericFile?)Converter?.Convert(this, typeof(TFile));
1!
327

328
            return (TFile?)ReturnValue;
2✔
329
        }
330
    }
331
}
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