public static ImageSource Decode(byte[] data, TgaHeader tgaHeader, int size)
        {
            var imageDataOffset = RgbBufferDecoder.GetImageDataOffset(tgaHeader);

            var numberOfPixels = RgbBufferDecoder.GetStride(tgaHeader) * tgaHeader.Height;
            var imageBuffer    = data.Skip(imageDataOffset).Take(numberOfPixels).ToArray();

            return(RgbBufferDecoder.Decode(tgaHeader, imageBuffer, size));
        }
        private static byte[] GetImageBuffer(byte[] data, TgaHeader tgaHeader)
        {
            var imageDataOffset = RgbBufferDecoder.GetImageDataOffset(tgaHeader);
            var bytesPerPixel   = RgbBufferDecoder.GetBytesPerPixel(tgaHeader);
            var pixelsToDecode  = tgaHeader.Width * tgaHeader.Height;

            var outBuffer = new byte[pixelsToDecode * bytesPerPixel];


            for (int i = 0, inOffset = imageDataOffset, outOffset = 0; i < pixelsToDecode;)
            {
                var header     = data[inOffset++];
                var pixelCount = GetPixelCount(header);

                if (IsRle(header))
                {
                    for (int count = 0; count < pixelCount; count++)
                    {
                        Array.Copy(data, inOffset, outBuffer, outOffset, bytesPerPixel);
                        outOffset += bytesPerPixel;
                    }

                    inOffset += bytesPerPixel;
                }
                else
                {
                    var pixelsBytesLength = pixelCount * bytesPerPixel;
                    Array.Copy(data, inOffset, outBuffer, outOffset, pixelsBytesLength);

                    inOffset  += pixelsBytesLength;
                    outOffset += pixelsBytesLength;
                }
                i += pixelCount;
            }

            return(outBuffer);
        }
        public static ImageSource Decode(byte[] data, TgaHeader tgaHeader, int size)
        {
            var imageBuffer = GetImageBuffer(data, tgaHeader);

            return(RgbBufferDecoder.Decode(tgaHeader, imageBuffer, size));
        }