< Summary

Class:Imagini.Drawing.Pixels
Assembly:Imagini.2D
File(s):/home/razer/vscode-projects/project-grove/imagini/Imagini.2D/Drawing/Pixels.cs
Covered lines:10
Uncovered lines:7
Coverable lines:17
Total lines:65
Line coverage:58.8% (10 of 17)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
Convert(...)1075%100%
Convert(...)1020%100%

File(s)

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

#LineLine coverage
 1using System.Runtime.InteropServices;
 2using static SDL2.SDL_surface;
 3using static Imagini.ErrorHandler;
 4using System;
 5
 6namespace Imagini.Drawing
 7{
 8    /// <summary>
 9    /// Contains pixel-related utility functions.
 10    /// </summary>
 11    public static class Pixels
 12    {
 13        /// <summary>
 14        /// Copies a block of pixels of one format to another format.
 15        /// </summary>
 16        /// <param name="width">The width of the block to copy, in pixels</param>
 17        /// <param name="height">The height of the block to copy, in pixels</param>
 18        /// <param name="srcStride">The stride (pitch) of the block to copy</param>
 19        /// <param name="dstStride">The stride (pitch) of the destination pixels</param>
 20        /// <param name="src">Source pixel data</param>
 21        /// <param name="dst">Destination pixel data</param>
 22        /// <returns></returns>
 23        public static void Convert<T1, T2>(int width, int height, int srcStride, int dstStride,
 24            ref T1[] src, ref T2[] dst)
 25            where T1 : IColor
 26            where T2 : IColor
 27        {
 128            var srcFormat = src[0].Format;
 129            var dstFormat = dst[0].Format;
 130            var srcHandle = GCHandle.Alloc(src, GCHandleType.Pinned);
 131            var dstHandle = GCHandle.Alloc(dst, GCHandleType.Pinned);
 32            try
 33            {
 034                Convert(width, height, srcStride, dstStride,
 035                    srcFormat, dstFormat,
 036                    srcHandle.AddrOfPinnedObject(), dstHandle.AddrOfPinnedObject());
 137            }
 38            finally
 39            {
 140                srcHandle.Free();
 141                dstHandle.Free();
 142            }
 143        }
 44
 45        /// <summary>
 46        /// Copies a block of pixels of one format to another format.
 47        /// </summary>
 48        /// <param name="width">The width of the block to copy, in pixels</param>
 49        /// <param name="height">The height of the block to copy, in pixels</param>
 50        /// <param name="srcStride">The stride (pitch) of the block to copy</param>
 51        /// <param name="dstStride">The stride (pitch) of the destination pixels</param>
 52        /// <param name="srcFormat">Source pixel format</param>
 53        /// <param name="dstFormat">Destination pixel format</param>
 54        /// <param name="src">Source pixel data</param>
 55        /// <param name="dst">Destination pixel data</param>
 56        public static void Convert(int width, int height, int srcStride, int dstStride,
 57            PixelFormat srcFormat, PixelFormat dstFormat, IntPtr src, IntPtr dst)
 58        {
 059            Try(() => SDL_ConvertPixels(width, height,
 060                (uint)srcFormat, src, srcStride,
 061                (uint)dstFormat, dst, dstStride),
 062                "SDL_ConvertPixels");
 1963        }
 64    }
 65}