@@ -411,41 +411,16 @@ public static long ChannelIndexNoThrow(this Format format, Channel channel)
411
411
return - 1 ;
412
412
}
413
413
414
- private static Dict < ( Type , long ) , Format > s_defaultFormatMap =
415
- new Dict < ( Type , long ) , Format >
416
- {
417
- { ( typeof ( byte ) , 1L ) , Format . Gray } ,
418
- { ( typeof ( byte ) , 2L ) , Format . NormalUV } ,
419
- { ( typeof ( byte ) , 3L ) , Format . BGR } ,
420
- { ( typeof ( byte ) , 4L ) , Format . BGRA } ,
421
-
422
- { ( typeof ( ushort ) , 1L ) , Format . Gray } ,
423
- { ( typeof ( ushort ) , 2L ) , Format . NormalUV } ,
424
- { ( typeof ( ushort ) , 3L ) , Format . RGB } ,
425
- { ( typeof ( ushort ) , 4L ) , Format . RGBA } ,
426
-
427
- { ( typeof ( uint ) , 1L ) , Format . Gray } ,
428
- { ( typeof ( uint ) , 2L ) , Format . NormalUV } ,
429
- { ( typeof ( uint ) , 3L ) , Format . RGB } ,
430
- { ( typeof ( uint ) , 4L ) , Format . RGBA } ,
431
-
432
- { ( typeof ( float ) , 1L ) , Format . Gray } ,
433
- { ( typeof ( float ) , 2L ) , Format . NormalUV } ,
434
- { ( typeof ( float ) , 3L ) , Format . RGB } ,
435
- { ( typeof ( float ) , 4L ) , Format . RGBA } ,
436
-
437
- { ( typeof ( double ) , 1L ) , Format . Gray } ,
438
- { ( typeof ( double ) , 2L ) , Format . NormalUV } ,
439
- { ( typeof ( double ) , 3L ) , Format . RGB } ,
440
- { ( typeof ( double ) , 4L ) , Format . RGBA } ,
441
- } ;
442
-
443
414
public static Format FormatDefaultOf ( this Type type , long channelCount )
444
415
{
445
- if ( s_defaultFormatMap . TryGetValue ( ( type , channelCount ) ,
446
- out Format format ) )
447
- return format ;
448
- throw new ArgumentException ( "no default format for this type and channel count" ) ;
416
+ return channelCount switch
417
+ {
418
+ 1 => Format . Gray ,
419
+ 2 => Format . NormalUV ,
420
+ 3 => ( type == typeof ( byte ) ) ? Format . BGR : Format . RGB ,
421
+ 4 => ( type == typeof ( byte ) ) ? Format . BGRA : Format . RGBA ,
422
+ _ => throw new ArgumentException ( $ "No default format for { type } with { channelCount } channels") ,
423
+ } ;
449
424
}
450
425
451
426
#endregion
0 commit comments