< Summary

Class:Imagini.Drawing.PixelFormatExtensions
Assembly:Imagini.2D
File(s):/home/razer/vscode-projects/project-grove/imagini/Imagini.2D/Drawing/PixelFormat.cs
Covered lines:13
Uncovered lines:0
Coverable lines:13
Total lines:258
Line coverage:100% (13 of 13)
Covered branches:4
Total branches:4
Branch coverage:100% (4 of 4)

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
GetPixelType(...)10100%100%
GetComponentType(...)40100%100%
GetLayout(...)10100%100%
IsFourCC(...)10100%100%
IsIndexed(...)10100%100%
IsPacked(...)10100%100%
IsArray(...)10100%100%
HasAlpha(...)10100%100%
GetBytesPerPixel(...)10100%100%
GetBitsPerPixel(...)10100%100%

File(s)

/home/razer/vscode-projects/project-grove/imagini/Imagini.2D/Drawing/PixelFormat.cs

#LineLine coverage
 1using System;
 2
 3using static SDL2.SDL_pixels;
 4
 5namespace Imagini.Drawing
 6{
 7    [Flags]
 8    /// <summary>
 9    /// Describes a pixel format. Entries starting with Format_ define full
 10    /// format specifications, other values are their flags.
 11    /// </summary>
 12    public enum PixelFormat : uint
 13    {
 14        Unknown = 0,
 15        Format_INDEX1LSB = 0x11100100,
 16        Format_INDEX1MSB = 0x11200100,
 17        Format_INDEX4LSB = 0x12100400,
 18        Format_INDEX4MSB = 0x12200400,
 19        Format_INDEX8 = 0x13000801,
 20        Format_RGB332 = 0x14110801,
 21        Format_RGB444 = 0x15120c02,
 22        Format_RGB555 = 0x15130f02,
 23        Format_BGR555 = 0x15530f02,
 24        Format_ARGB4444 = 0x15321002,
 25        Format_RGBA4444 = 0x15421002,
 26        Format_ABGR4444 = 0x15721002,
 27        Format_BGRA4444 = 0x15821002,
 28        Format_ARGB1555 = 0x15331002,
 29        Format_RGBA5551 = 0x15441002,
 30        Format_ABGR1555 = 0x15731002,
 31        Format_BGRA5551 = 0x15841002,
 32        Format_RGB565 = 0x15151002,
 33        Format_BGR565 = 0x15551002,
 34        Format_RGB24 = 0x17101803,
 35        Format_BGR24 = 0x17401803,
 36        Format_RGB888 = 0x16161804,
 37        Format_RGBX8888 = 0x16261804,
 38        Format_BGR888 = 0x16561804,
 39        Format_BGRX8888 = 0x16661804,
 40        Format_ARGB8888 = 0x16362004,
 41        Format_RGBA8888 = 0x16462004,
 42        Format_ABGR8888 = 0x16762004,
 43        Format_BGRA8888 = 0x16862004,
 44        Format_ARGB2101010 = 0x16372004,
 45        Format_YV12 = 0x32315659,
 46        Format_IYUV = 0x56555949,
 47        Format_YUY2 = 0x32595559,
 48        Format_UYVY = 0x59565955,
 49        Format_YVYU = 0x55595659,
 50
 51        Type_Index1 = (1 << 24),
 52        Type_Index4,
 53        Type_Index8,
 54        Type_Packed8,
 55        Type_Packed16,
 56        Type_Packed32,
 57        Type_ArrayU8,
 58        Type_ArrayU16,
 59        Type_ArrayU32,
 60        Type_ArrayF16,
 61        Type_ArrayF32,
 62
 63        /* Bitmap component order */
 64        Order_Bitmap4321 = (1 << 20),
 65        Order_Bitmap1234,
 66
 67        /* Packed component order */
 68        Order_PackedXRGB = (1 << 20),
 69        Order_PackedRGBX,
 70        Order_PackedARGB,
 71        Order_PackedRGBA,
 72        Order_PackedXBGR,
 73        Order_PackedBGRX,
 74        Order_PackedABGR,
 75        Order_PackedBGRA,
 76        /* Array component order */
 77        Order_ArrayRGB = (1 << 20),
 78        Order_ArrayRGBA,
 79        Order_ArrayARGB,
 80        Order_ArrayBGR,
 81        Order_ArrayBGRA,
 82        Order_ArrayABGR,
 83
 84        /* Packed layout */
 85        Layout_Packed332 = (1 << 16),
 86        Layout_Packed4444,
 87        Layout_Packed1555,
 88        Layout_Packed5551,
 89        Layout_Packed565,
 90        Layout_Packed8888,
 91        Layout_Packed2101010,
 92        Layout_Packed1010102
 93    }
 94
 95    /// <summary>
 96    /// Defines pixel type.
 97    /// </summary>
 98    public enum PixelType
 99    {
 100        Unknown,
 101        Index1,
 102        Index4,
 103        Index8,
 104        Packed8,
 105        Packed16,
 106        Packed32,
 107        ArrayU8,
 108        ArrayU16,
 109        ArrayU32,
 110        ArrayF16,
 111        ArrayF32
 112    }
 113
 114    /// <summary>
 115    /// Describes pixel component type.
 116    /// </summary>
 117    public enum PixelComponentType
 118    {
 119        Bitmap,
 120        Packed,
 121        Array
 122    }
 123
 124    /// <summary>
 125    /// Describes bitmap component order.
 126    /// </summary>
 127    public enum PixelBitmapOrder
 128    {
 129        MSB = (1 << 20),
 130        LSB,
 131    }
 132
 133    /// <summary>
 134    /// Describes packed component order.
 135    /// </summary>
 136    public enum PixelPackedOrder
 137    {
 138        XRGB = (1 << 20),
 139        RGBX,
 140        ARGB,
 141        RGBA,
 142        XBGR,
 143        BGRX,
 144        ABGR,
 145        BGRA,
 146    }
 147
 148    /// <summary>
 149    /// Describes array component order.
 150    /// </summary>
 151    public enum PixelArrayOrder
 152    {
 153        RGB = (1 << 20),
 154        RGBA,
 155        ARGB,
 156        BGR,
 157        BGRA,
 158        ABGR,
 159    }
 160
 161    /// <summary>
 162    /// Describes packed pixel layout.
 163    /// </summary>
 164    public enum PixelLayout
 165    {
 166        Default = 0,
 167        Packed332,
 168        Packed4444,
 169        Packed1555,
 170        Packed5551,
 171        Packed565,
 172        Packed8888,
 173        Packed2101010,
 174        Packed1010102
 175    }
 176
 177    /// <summary>
 178    /// Contains various extensions related to <see cref="PixelFormat" />.
 179    /// </summary>
 180    public static class PixelFormatExtensions
 181    {
 182        /// <summary>
 183        /// Returns the pixel type of the specified format.
 184        /// </summary>
 185        public static PixelType GetPixelType(this PixelFormat format) =>
 28186           (PixelType)SDL_PIXELTYPE((uint)format);
 187
 188        /// <summary>
 189        /// Returns the component type.
 190        /// </summary>
 191        public static PixelComponentType GetComponentType(this PixelFormat format)
 192        {
 28193            switch (format.GetPixelType())
 194            {
 195                case PixelType.ArrayF16:
 196                case PixelType.ArrayF32:
 197                case PixelType.ArrayU16:
 198                case PixelType.ArrayU32:
 199                case PixelType.ArrayU8:
 2200                    return PixelComponentType.Array;
 201                case PixelType.Packed8:
 202                case PixelType.Packed16:
 203                case PixelType.Packed32:
 21204                    return PixelComponentType.Packed;
 205                default:
 5206                    return PixelComponentType.Bitmap;
 207            }
 208        }
 209
 210        /// <summary>
 211        /// Returns the pixel layout of the specified format.
 212        /// </summary>
 213        public static PixelLayout GetLayout(this PixelFormat format) =>
 21214            (PixelLayout)SDL_PIXELLAYOUT((uint)format);
 215
 216        /// <summary>
 217        /// Returns true if the specified format is an 4CC format.
 218        /// </summary>
 219        public static bool IsFourCC(this PixelFormat format) =>
 33220            SDL_ISPIXELFORMAT_FOURCC((uint)format);
 221
 222        /// <summary>
 223        /// Returns true if the specified format is an indexed format.
 224        /// </summary>
 225        public static bool IsIndexed(this PixelFormat format) =>
 34226            SDL_ISPIXELFORMAT_INDEXED((uint)format);
 227
 228        /// <summary>
 229        /// Returns true if the specified format is a packed format.
 230        /// </summary>
 231        public static bool IsPacked(this PixelFormat format) =>
 33232            SDL_ISPIXELFORMAT_PACKED((uint)format);
 233
 234        /// <summary>
 235        /// Returns true if the specified format is an array format.
 236        /// </summary>
 237        public static bool IsArray(this PixelFormat format) =>
 33238            SDL_ISPIXELFORMAT_ARRAY((uint)format);
 239
 240        /// <summary>
 241        /// Returns true if the specified format has alpha channel.
 242        /// </summary>
 243        public static bool HasAlpha(this PixelFormat format) =>
 35244            SDL_ISPIXELFORMAT_ALPHA((uint)format);
 245
 246        /// <summary>
 247        /// Returns the number of bytes per pixel for the specified format.
 248        /// </summary>
 249        public static int GetBytesPerPixel(this PixelFormat format) =>
 274250            SDL_BYTESPERPIXEL((uint)format);
 251
 252        /// <summary>
 253        /// Returns the number of bits per pixel for the specified format.
 254        /// </summary>
 255        public static int GetBitsPerPixel(this PixelFormat format) =>
 78256            SDL_BITSPERPIXEL((uint)format);
 257    }
 258}