Files
懒得勤快 390092f309 增强与重构图片格式检测器及测试用例
统一各图片格式检测器的Detect(Stream)实现,提升检测准确性和一致性;新增MimeType属性,自动获取MIME类型;扩展GetImageType支持Jpeg2000、JpegXR、Tga等格式,TGA检测逻辑独立为IsTga方法;ImageFormat枚举新增相关格式;TgaDetector检测逻辑统一;新增ImageDetectExtTests,批量测试各格式检测能力并验证一致性,提升测试覆盖率和可靠性。
2026-09-19 21:04:14 +08:00

29 lines
1.1 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Masuit.Tools.Media;
using Masuit.Tools.Mime;
namespace Masuit.Tools.Files.FileDetector.Detectors;
[FormatCategory(FormatCategory.Image)]
internal sealed class BitmapDetector : AbstractSignatureDetector
{
private static readonly SignatureInformation[] BmpSignatureInfo = {
new() { Position = 0, Signature = "BM"u8.ToArray() },
new() { Position = 6, Signature = new byte [] { 0x00, 0x00, 0x00, 0x00 }, Presignature = "BM"u8.ToArray() },
};
public override string Extension => "bmp";
protected override SignatureInformation[] SignatureInformations => BmpSignatureInfo;
public override bool Detect(Stream stream) => stream.GetImageType() == ImageFormat.Bmp;
public override string MimeType => new MimeMapper().GetMimeFromExtension("." + Extension);
public override List<FormatCategory> FormatCategories => GetType().GetCustomAttributes<FormatCategoryAttribute>().Select(a => a.Category).ToList();
public override string ToString() => "Bitmap(BMP) Detector";
}